decompiled_code:
__int64 __fastcall skip_content_headers(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = _("\r\n\r\n");
return (unsigned int)search(a1, a2, v2) + 4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = _("\r\n\r\n");
return (unsigned int)search(a1, a2, v2) + 4;
}

original_code:
int
skip_content_headers(str src, int pos)
{
 return 4 + search(src,pos,_("\r\n\r\n"));
}

canonical_original_code:
int skip_content_headers(struct str_struct *src, int pos)
{
 return 4 + search(src,pos,_("\r\n\r\n"));
}


repo: cthulhuology/Jawas

decompiled_code:
__int64 __fastcall save_contents(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
int v5; // eax
int v6; // er14
__int64 result; // rax

v4 = temp_file();
v5 = open(*(const char **)(v4 + 8), 65, 420LL);
if ( v5 < 0 )
{
log_msg(0LL, "Failed to open file for writing %s", (const char *)v4);
perror("open");
result = v4;
}
else
{
v6 = v5;
if ( write(v5, (const void *)(*(_QWORD *)(a1 + 8) + a2), a3 - a2) < 0 )
log_msg(0LL, "Failed to write to %s", (const char *)v4);
close(v6);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
int v5; // eax
int v6; // er14
__int64 result; // rax

v4 = temp_file();
v5 = open(*(const char **)(v4 + 8), 65, 420LL);
if ( v5 < 0 )
{
log_msg(0LL, "Failed to open file for writing %s", (const char *)v4);
perror("open");
result = v4;
}
else
{
v6 = v5;
if ( write(v5, (const void *)(*(_QWORD *)(a1 + 8) + a2), a3 - a2) < 0 )
log_msg(0LL, "Failed to write to %s", (const char *)v4);
close(v6);
result = v4;
}
return result;
}

original_code:
str
save_contents(str src, int pos, int end)
{
 str filename = temp_file();
 char* fname = filename->data;
 int fd = open(fname,01|0100,0644);
 if (fd < 0 ) {
  log_msg(0,"Failed to open file for writing %s",filename);
  perror("open");
  return filename;
 }
 if (write(fd,&src->data[pos],end - pos) < 0)
  log_msg(0,"Failed to write to %s", filename);
 close(fd);
 return filename;
}

canonical_original_code:
struct str_struct *save_contents(struct str_struct *src, int pos, int end)
{
 struct str_struct *filename = temp_file();
 char *fname = filename->data;
 int fd = open(fname,01|0100,0644);
 if (fd < 0 ) {
  log_msg(0,"Failed to open file for writing %s",filename);
  perror("open");
  return filename;
 }
 if (write(fd,&src->data[pos],end - pos) < 0)
  log_msg(0,"Failed to write to %s", filename);
 close(fd);
 return filename;
}

variable_types:
src
struct str_struct *

variable_types: pos int

variable_types: end int

variable_types: struct str_struct { int length; char *data; char contents[]; } *

variable_types:
fname
char *

variable_types: fd int


decompiled_code:
__int64 __fastcall parse_multipart_body(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // r13
signed int v5; // ebp
__int64 v6; // rdx
int v7; // ebx
__int64 v8; // r14
__int64 v9; // rdi
unsigned int v10; // er15
_BOOL4 v11; // eax
int v12; // edx
signed int v14; // [rsp+8h] [rbp-40h]
int v15; // [rsp+Ch] [rbp-3Ch]

v14 = len(*(_QWORD *)(client[4] + 48LL));
v3 = find_boundary(a2);
if ( v3 )
{
v4 = v3;
v15 = len(v3);
v5 = search(*(_QWORD *)(client[4] + 48LL), *(unsigned int *)(client[4] + 92LL), v4);
if ( v14 > v5 )
{
do
{
while ( 1 )
{
v7 = search(*(_QWORD *)(client[4] + 48LL), (unsigned int)(v5 + 1), v4);
v8 = parse_name(*(_QWORD *)(client[4] + 48LL), v5);
v9 = *(_QWORD *)(client[4] + 48LL);
if ( v8 )
break;
skip_content_headers(v9, v5);
v5 = v15 + v7;
if ( v14 <= v15 + v7 )
return a1;
}
v10 = skip_content_headers(v9, v5);
v11 = found_file(*(_QWORD *)(client[4] + 48LL), v5, v10);
v12 = v7 - 2;
if ( v11 )
v6 = save_contents(*(_QWORD *)(client[4] + 48LL), v10, v12);
else
v6 = from(*(_QWORD *)(client[4] + 48LL), v10, v12 - v10);
a1 = append_header(a1, v8, v6);
v5 = v15 + v7;
}
while ( v14 > v15 + v7 );
}
}
else
{
log_msg(0LL, "multipart/form-data without boundary");
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // r13
signed int v5; // ebp
__int64 v6; // rdx
int v7; // ebx
__int64 v8; // r14
__int64 v9; // rdi
unsigned int v10; // er15
_BOOL4 v11; // eax
int v12; // edx
signed int v14; // [rsp+8h] [rbp-40h]
int v15; // [rsp+Ch] [rbp-3Ch]

v14 = len(*(_QWORD *)(client[4] + 48LL));
v3 = func0(a2);
if ( v3 )
{
v4 = v3;
v15 = len(v3);
v5 = search(*(_QWORD *)(client[4] + 48LL), *(unsigned int *)(client[4] + 92LL), v4);
if ( v14 > v5 )
{
do
{
while ( 1 )
{
v7 = search(*(_QWORD *)(client[4] + 48LL), (unsigned int)(v5 + 1), v4);
v8 = func1(*(_QWORD *)(client[4] + 48LL), v5);
v9 = *(_QWORD *)(client[4] + 48LL);
if ( v8 )
break;
func3(v9, v5);
v5 = v15 + v7;
if ( v14 <= v15 + v7 )
return a1;
}
v10 = func3(v9, v5);
v11 = func2(*(_QWORD *)(client[4] + 48LL), v5, v10);
v12 = v7 - 2;
if ( v11 )
v6 = func4(*(_QWORD *)(client[4] + 48LL), v10, v12);
else
v6 = from(*(_QWORD *)(client[4] + 48LL), v10, v12 - v10);
a1 = append_header(a1, v8, v6);
v5 = v15 + v7;
}
while ( v14 > v15 + v7 );
}
}
else
{
log_msg(0LL, "multipart/form-data without boundary");
}
return a1;
}

original_code:
Headers
parse_multipart_body(Headers headers, str enctype)
{
 str dstname;
 int i, e, n, l = len(client.request->contents);
 str boundary = find_boundary(enctype);
 if (!boundary) {
  log_msg(0,"multipart/form-data without boundary");
  return headers;
 }
 int bl = len(boundary);
 for (i = search(client.request->contents,client.request->body,boundary);
  i < l;
  i = n + bl) {
  n = search(client.request->contents,i+1,boundary);
  str srcname = parse_name(client.request->contents,i);
  if (! srcname) {
   i = skip_content_headers(client.request->contents,i);
   continue;
  }
  e = skip_content_headers(client.request->contents,i);
  dstname = (found_file(client.request->contents,i,e)) ?
   save_contents(client.request->contents,e,n-2):
   from(client.request->contents,e,n-2-e);
  headers = append_header(headers,srcname,dstname);
 }
 return headers;
}

canonical_original_code:
struct headers_struct *parse_multipart_body(struct headers_struct *headers, struct str_struct *enctype)
{
 struct str_struct *dstname;
 int i; int e; int n; int l = len(client.request->contents);
 struct str_struct *boundary = find_boundary(enctype);
 if (!boundary) {
  log_msg(0,"multipart/form-data without boundary");
  return headers;
 }
 int bl = len(boundary);
 for (i = search(client.request->contents,client.request->body,boundary);
  i < l;
  i = n + bl) {
  n = search(client.request->contents,i+1,boundary);
  struct str_struct *srcname = parse_name(client.request->contents,i);
  if (! srcname) {
   i = skip_content_headers(client.request->contents,i);
   continue;
  }
  e = skip_content_headers(client.request->contents,i);
  dstname = (found_file(client.request->contents,i,e)) ?
   save_contents(client.request->contents,e,n-2):
   from(client.request->contents,e,n-2-e);
  headers = append_header(headers,srcname,dstname);
 }
 return headers;
}

variable_types:
headers
struct headers_struct *

variable_types:
enctype
struct str_struct *

variable_types: i int

variable_types: e int

variable_types: n int

variable_types: l int

variable_types: bl int

return_type: struct headers_struct { int nslots; struct headers_data_struct { struct str_struct { int length; char *data; char contents[]; } *key; struct str_struct *value; } slots[250]; } *

user_defined_types: struct headers_struct { int nslots; struct headers_data_struct slots[250]; }

user_defined_types: struct headers_data_struct { struct str_struct *key; struct str_struct *value; }


decompiled_code:
void restart_signal_handler()
{
*(_QWORD *)((char *)&server + 8260) = 0x100000001LL;
}

original_code:
void
restart_signal_handler()
{
 server.done = 1;
 server.restart = 1;
}

return_type: void


decompiled_code:
void alrm_signal_handler()
{
client[1] = 1LL;
}

canonical_decompiled_code:
void func1()
{
client[1] = 1LL;
}

original_code:
void
alrm_signal_handler()
{
 client.alarm = 1;
}


decompiled_code:
void __noreturn gen_signal_handler()
{
server[2065] = 1;
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
server[2065] = 1;
exit(0);
}

original_code:
void
gen_signal_handler()
{
 server.done = 1;
 exit(0);
}


decompiled_code:
__sighandler_t general_signal_handlers()
{
signal(1, (__sighandler_t)restart_signal_handler);
signal(2, (__sighandler_t)gen_signal_handler);
signal(15, (__sighandler_t)gen_signal_handler);
return signal(14, (__sighandler_t)alrm_signal_handler);
}

canonical_decompiled_code:
__sighandler_t func3()
{
signal(1, (__sighandler_t)restart_signal_handler);
signal(2, (__sighandler_t)gen_signal_handler);
signal(15, (__sighandler_t)gen_signal_handler);
return signal(14, (__sighandler_t)alrm_signal_handler);
}

original_code:
void
general_signal_handlers()
{
 signal(1,restart_signal_handler);
 signal(2,gen_signal_handler);
 signal(15,gen_signal_handler);
 signal(14,alrm_signal_handler);
}


decompiled_code:
__int64 dechunk_response()
{
__int64 result; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx

result = is_chunked(*(_QWORD *)(client[5] + 16LL));
if ( (_DWORD)result )
{
v1 = ref(*(_QWORD *)(*(_QWORD *)(client[5] + 24LL) + 8LL), *(unsigned int *)(client[5] + 52LL));
v2 = dechunk(*(_QWORD *)(client[5] + 24LL));
v3 = client[5];
result = append(v1, v2);
*(_QWORD *)(v3 + 24) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx

result = is_chunked(*(_QWORD *)(client[5] + 16LL));
if ( (_DWORD)result )
{
v1 = ref(*(_QWORD *)(*(_QWORD *)(client[5] + 24LL) + 8LL), *(unsigned int *)(client[5] + 52LL));
v2 = dechunk(*(_QWORD *)(client[5] + 24LL));
v3 = client[5];
result = append(v1, v2);
*(_QWORD *)(v3 + 24) = result;
}
return result;
}

original_code:
void
dechunk_response()
{
 if (is_chunked(client.response->headers)) {
  str hed = ref(client.response->contents->data,client.response->body);
  str con = dechunk(client.response->contents);
  client.response->contents = append(hed,con);
 }
}

canonical_original_code:
void dechunk_response()
{
 if (is_chunked(client.response->headers)) {
  struct str_struct *hed = ref(client.response->contents->data,client.response->body);
  struct str_struct *con = dechunk(client.response->contents);
  client.response->contents = append(hed,con);
 }
}

user_defined_types: struct str_struct { int length; char *data; char contents[]; }


decompiled_code:
__int64 process_response()
{
_QWORD *v0; // r12
__int64 v1; // r12
__int64 v2; // rdi
int v3; // eax
__int64 v4; // rdx
int v5; // er12
bool v6; // cc
__int64 v7; // rax
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // rdx

v0 = (_QWORD *)client[5];
v0[3] = read_socket(*v0);
v1 = client[5];
v2 = *(_QWORD *)(v1 + 24);
if ( !v2 )
{
log_msg(0LL, "No response contents on Response <%p>\n", (const void *)client[5]);
return 0xFFFFFFFFLL;
}
if ( !*(_DWORD *)(v1 + 52) )
{
v9 = parse_headers(v2, v1 + 52);
v10 = client[5];
*(_QWORD *)(v1 + 16) = v9;
if ( !*(_QWORD *)(v10 + 16) )
{
log_msg(0LL, "No response headers on Response <%p>\n", (const void *)v10);
return 0xFFFFFFFFLL;
}
result = *(unsigned int *)(v10 + 52);
if ( !(_DWORD)result )
{
*(_DWORD *)(v10 + 56) = 0;
return result;
}
}
v3 = len();
v4 = client[5];
v5 = v3 - *(_DWORD *)(v4 + 52);
v6 = v5 < (int)inbound_content_length(*(_QWORD *)(v4 + 24), *(_QWORD *)(v4 + 16));
v7 = client[5];
if ( v6 )
{
*(_DWORD *)(v7 + 56) = 0;
}
else
{
*(_DWORD *)(v7 + 56) = 1;
dechunk_response();
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
_QWORD *v0; // r12
__int64 v1; // r12
__int64 v2; // rdi
int v3; // eax
__int64 v4; // rdx
int v5; // er12
bool v6; // cc
__int64 v7; // rax
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // rdx

v0 = (_QWORD *)client[5];
v0[3] = read_socket(*v0);
v1 = client[5];
v2 = *(_QWORD *)(v1 + 24);
if ( !v2 )
{
log_msg(0LL, "No response contents on Response <%p>\n", (const void *)client[5]);
return 0xFFFFFFFFLL;
}
if ( !*(_DWORD *)(v1 + 52) )
{
v9 = parse_headers(v2, v1 + 52);
v10 = client[5];
*(_QWORD *)(v1 + 16) = v9;
if ( !*(_QWORD *)(v10 + 16) )
{
log_msg(0LL, "No response headers on Response <%p>\n", (const void *)v10);
return 0xFFFFFFFFLL;
}
result = *(unsigned int *)(v10 + 52);
if ( !(_DWORD)result )
{
*(_DWORD *)(v10 + 56) = 0;
return result;
}
}
v3 = len();
v4 = client[5];
v5 = v3 - *(_DWORD *)(v4 + 52);
v6 = v5 < (int)inbound_content_length(*(_QWORD *)(v4 + 24), *(_QWORD *)(v4 + 16));
v7 = client[5];
if ( v6 )
{
*(_DWORD *)(v7 + 56) = 0;
}
else
{
*(_DWORD *)(v7 + 56) = 1;
func1();
}
return 0LL;
}

original_code:
int
process_response()
{
 client.response->contents = read_socket(client.response->socket);
 if (! client.response->contents) {
  log_msg(0,"No response contents on Response <%p>\n",client.response);
  return -1;
 }
 if (! client.response->body) {
  client.response->headers = parse_headers(client.response->contents,&client.response->body);
  if (! client.response->headers) {
   log_msg(0,"No response headers on Response <%p>\n",client.response);
   return -1;
  }
 }
 client.response->done = client.response->body &&
  (len(client.response->contents) - client.response->body) >= inbound_content_length(client.response->contents,client.response->headers);
 if (client.response->done) dechunk_response();
 return 0;
}

return_type: int


decompiled_code:
_BOOL8 begin_response()
{
__int64 v0; // rdi
__int64 v1; // rdx
_BOOL8 result; // rax
__int64 v3; // rbx

v0 = *(_QWORD *)(client[5] + 16LL);
if ( !v0 )
{
log_msg(0LL, "Missing headers, adding new ones");
v3 = client[5];
*(_QWORD *)(v3 + 16) = new_headers();
v0 = *(_QWORD *)(client[5] + 16LL);
}
connection(v0, "close");
transfer_encoding(*(_QWORD *)(client[5] + 16LL), "chunked");
server_name(*(_QWORD *)(client[5] + 16LL), "Jawas/1.0");
v1 = client[5];
result = 1LL;
if ( !*(_QWORD *)(v1 + 24) )
result = *(_QWORD *)(v1 + 32) != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 func3()
{
__int64 v0; // rdi
__int64 v1; // rdx
_BOOL8 result; // rax
__int64 v3; // rbx

v0 = *(_QWORD *)(client[5] + 16LL);
if ( !v0 )
{
log_msg(0LL, "Missing headers, adding new ones");
v3 = client[5];
*(_QWORD *)(v3 + 16) = new_headers();
v0 = *(_QWORD *)(client[5] + 16LL);
}
connection(v0, "close");
transfer_encoding(*(_QWORD *)(client[5] + 16LL), "chunked");
server_name(*(_QWORD *)(client[5] + 16LL), "Jawas/1.0");
v1 = client[5];
result = 1LL;
if ( !*(_QWORD *)(v1 + 24) )
result = *(_QWORD *)(v1 + 32) != 0LL;
return result;
}

original_code:
int
begin_response()
{
 if (!client.response->headers) {
  log_msg(0,"Missing headers, adding new ones");
  client.response->headers = new_headers();
 }
 connection(client.response->headers,"close");
 transfer_encoding(client.response->headers,"chunked");
 server_name(client.response->headers,"Jawas/1.0");
 return client.response->contents || client.response->raw_contents;
}


decompiled_code:
__int64 end_response()
{
write_chunk(*(_QWORD *)client[5], 0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
write_chunk(*(_QWORD *)client[5], 0LL, 0LL);
return 0LL;
}

original_code:
int
end_response()
{
 write_chunk(client.response->socket,((void *)0),0);
 return 0;
}


decompiled_code:
_QWORD *new_region()
{
__int64 v0; // rbx
size_t v1; // rbx
_QWORD *result; // rax

v0 = sysconf(30);
if ( memory )
{
munmap(memory, *(_QWORD *)memory);
memory = 0LL;
}
v1 = 10000 * v0;
result = mmap(0LL, v1, 3, 34, -1, 0LL);
memory = result;
if ( result == (_QWORD *)-1LL )
{
perror("mmap");
fwrite("Failed to allocate memory\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
*result = v1;
result[1] = v1 - 24;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
__int64 v0; // rbx
size_t v1; // rbx
_QWORD *result; // rax

v0 = sysconf(30);
if ( memory )
{
munmap(memory, *(_QWORD *)memory);
memory = 0LL;
}
v1 = 10000 * v0;
result = mmap(0LL, v1, 3, 34, -1, 0LL);
memory = result;
if ( result == (_QWORD *)-1LL )
{
perror("mmap");
fwrite("Failed to allocate memory\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
*result = v1;
result[1] = v1 - 24;
result[2] = 0LL;
return result;
}

original_code:
void
new_region()
{
 size_t page_size = sysconf(_SC_PAGESIZE);
 if (memory) {
  munmap(memory,memory->size);
  memory = ((void *)0);
 }
 memory = (Region)mmap(((void *)0),page_size*10000,0x1|0x2,0x02|0x20,-1,0);
 if (memory == ((void *) -1)) {
  perror("mmap");
  fprintf(stderr, "Failed to allocate memory\n");
  exit(0);
 }
 memory->size = page_size * 10000;
 memory->allocated = memory->size - sizeof(struct region_struct);
 memory->offset = 0;
}

canonical_original_code:
void new_region()
{
 unsigned long page_size = sysconf(_SC_PAGESIZE);
 if (memory) {
  munmap(memory,memory->size);
  memory = ((void *)0);
 }
 memory = (struct region_struct *)mmap(((void *)0),page_size*10000,0x1|0x2,0x02|0x20,-1,0);
 if (memory == ((void *) -1)) {
  perror("mmap");
  fprintf(stderr, "Failed to allocate memory\n");
  exit(0);
 }
 memory->size = page_size * 10000;
 memory->allocated = memory->size - sizeof(struct region_struct);
 memory->offset = 0;
}

user_defined_types: struct region_struct { unsigned long size; unsigned long allocated; unsigned long offset; char data[]; }


advance

decompiled_code:
__int64 __fastcall advance(__int64 a1)
{
__int64 result; // rax

result = a1;
*((_QWORD *)memory + 2) += a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

result = a1;
*((_QWORD *)memory + 2) += a1;
return result;
}

original_code:
size_t
advance(size_t length)
{
 memory->offset += length;
 return length;
}

canonical_original_code:
unsigned long advance(unsigned long length)
{
 memory->offset += length;
 return length;
}

variable_types:
length
unsigned long

return_type: unsigned long


reserve

decompiled_code:
__int64 __fastcall reserve(__int64 a1)
{
__int64 v1; // r8

advance(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // r8

func1(a1);
return v1;
}

original_code:
char*
reserve(size_t length)
{
 char* retval = &memory->data[memory->offset];
 advance(length);
 return retval;
}

canonical_original_code:
char *reserve(unsigned long length)
{
 char *retval = &memory->data[memory->offset];
 advance(length);
 return retval;
}

variable_types:
retval
char *

return_type: char *


decompiled_code:
_BOOL8 __fastcall is_chunked(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
_BOOL8 result; // rax
__int64 v4; // rax

v1 = _(Transfer_Encoding_MSG);
v2 = find_header(a1, v1);
result = 0LL;
if ( v2 )
{
v4 = _("chunked");
result = (unsigned int)icmp(v2, v4) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
_BOOL8 result; // rax
__int64 v4; // rax

v1 = _(Transfer_Encoding_MSG);
v2 = find_header(a1, v1);
result = 0LL;
if ( v2 )
{
v4 = _("chunked");
result = (unsigned int)icmp(v2, v4) != 0;
}
return result;
}

original_code:
int
is_chunked(Headers headers)
{
 str enc = find_header(headers, _(Transfer_Encoding_MSG));
  return enc && icmp(enc,_("chunked"));
}

canonical_original_code:
int is_chunked(struct headers_struct *headers)
{
 struct str_struct *enc = find_header(headers, _(Transfer_Encoding_MSG));
  return enc && icmp(enc,_("chunked"));
}

variable_types: struct headers_struct { int nslots; struct headers_data_struct { struct str_struct { int length; char *data; char contents[]; } *key; struct str_struct *value; } slots[250]; } *


decompiled_code:
__int64 __fastcall chunked_length(__int64 a1)
{
unsigned int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rbp
int v4; // ebx

v1 = 0;
v2 = skip_headers(a1, 0LL);
do
{
v3 = read_line(a1, v2);
v4 = v2 + len(v3) + 2;
v2 = str_hex(v3) + v4;
v1 += str_hex(v3);
}
while ( (unsigned int)len(v3) );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rbp
int v4; // ebx

v1 = 0;
v2 = skip_headers(a1, 0LL);
do
{
v3 = read_line(a1, v2);
v4 = v2 + len(v3) + 2;
v2 = str_hex(v3) + v4;
v1 += str_hex(v3);
}
while ( (unsigned int)len(v3) );
return v1;
}

original_code:
int
chunked_length(str src)
{
 int total = 0;
 str line;
 int pos = skip_headers(src,0);
 do {
  line = read_line(src,pos);
  pos += len(line) + 2;
  pos += str_hex(line);
  total += str_hex(line);
 } while (len(line) != 0);
 return total;
}

canonical_original_code:
int chunked_length(struct str_struct *src)
{
 int total = 0;
 struct str_struct *line;
 int pos = skip_headers(src,0);
 do {
  line = read_line(src,pos);
  pos += len(line) + 2;
  pos += str_hex(line);
  total += str_hex(line);
 } while (len(line) != 0);
 return total;
}

variable_types: total int


decompiled_code:
__int64 __fastcall inbound_content_length(__int64 a1, __int64 a2)
{
__int64 v4; // rsi
__int64 v5; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
if ( is_chunked(a2) )
return chunked_length(a1);
v4 = _("Content-Length");
v5 = find_header(a2, v4);
return str_int(v5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v4; // rsi
__int64 v5; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
if ( func0(a2) )
return func1(a1);
v4 = _("Content-Length");
v5 = find_header(a2, v4);
return str_int(v5);
}

original_code:
int
inbound_content_length(str src, Headers headers)
{
 if (!src || !headers) return 0;
 return is_chunked(headers) ?
  chunked_length(src) :
  str_int(find_header(headers, _("Content-Length")));
}

canonical_original_code:
int inbound_content_length(struct str_struct *src, struct headers_struct *headers)
{
 if (!src || !headers) return 0;
 return is_chunked(headers) ?
  chunked_length(src) :
  str_int(find_header(headers, _("Content-Length")));
}

variable_types: struct headers_struct { int nslots; struct headers_data_struct { struct str_struct *key; struct str_struct *value; } slots[250]; } *


decompiled_code:
__int64 __fastcall outbound_content_length(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
return len(a1);
result = 0LL;
if ( a2 )
result = *(unsigned int *)(a2 + 56);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
return len(a1);
result = 0LL;
if ( a2 )
result = *(unsigned int *)(a2 + 56);
return result;
}

original_code:
int
outbound_content_length(str src, File fc)
{
 return src ? len(src) : fc ? fc->st.st_size : 0;
}

canonical_original_code:
int outbound_content_length(struct str_struct *src, struct file_cache_struct *fc)
{
 return src ? len(src) : fc ? fc->st.st_size : 0;
}

variable_types: struct file_cache_struct { struct file_cache_struct *next; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; struct parsed_struct { enum { TEXT=1, SCRIPT=2, EMIT=3 } kind; int offset; int length; } *parsed; struct mime_struct { struct { int len; char *data; } ending; struct { int len; char *data; } type; int (*handler)(struct file_cache_struct *); } *mime; char *data; int fd; struct str_struct name; } *

user_defined_types: struct file_cache_struct { struct file_cache_struct *next; struct stat st; struct parsed_struct *parsed; struct mime_struct *mime; char *data; int fd; struct str_struct name; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void restart_child()
{
unsigned int v0; // er12
unsigned int v1; // eax

v0 = child;
v1 = getpid();
fprintf(stderr, "process %d got restart child %d\n", v1, v0);
kill(child, 1);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // er12
unsigned int v1; // eax

v0 = child;
v1 = getpid();
fprintf(stderr, "process %d got restart child %d\n", v1, v0);
kill(child, 1);
}

original_code:
void restart_child(int sig) {
 fprintf(stderr,"process %d got restart child %d\n", getpid(), child);
 kill(child,1);
}

variable_types: sig int


decompiled_code:
void __noreturn kill_all()
{
unsigned int v0; // eax

v0 = getpid();
fprintf(stderr, "process %d got killall\n", v0);
murder = 1;
done = 1;
kill(0, 15);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
unsigned int v0; // eax

v0 = getpid();
fprintf(stderr, "process %d got killall\n", v0);
murder = 1;
done = 1;
kill(0, 15);
exit(0);
}

original_code:
void kill_all(int sig) {
 fprintf(stderr,"process %d got killall\n", getpid());
 murder = 1;
 done = 1;
 kill(0,15);
 exit(0);
}


decompiled_code:
int kill_child()
{
unsigned int v0; // er12
unsigned int v1; // eax

v0 = child;
v1 = getpid();
fprintf(stderr, "process %d got kill child %d\n", v1, v0);
murder = 1;
return kill(child, 15);
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // er12
unsigned int v1; // eax

v0 = child;
v1 = getpid();
fprintf(stderr, "process %d got kill child %d\n", v1, v0);
murder = 1;
return kill(child, 15);
}

original_code:
void kill_child(int sig) {
 fprintf(stderr,"process %d got kill child %d\n", getpid(), child);
 murder = 1;
 kill(child,15);
}


demon

decompiled_code:
__pid_t __fastcall demon(int a1)
{
__pid_t result; // eax
int v2; // ebp
unsigned int v3; // eax
size_t v4; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

while ( 1 )
{
if ( murder )
{
kill(child, 15);
if ( done )
goto LABEL_16;
}
else if ( done )
{
goto LABEL_16;
}
result = child;
if ( !a1 )
{
if ( !child )
return result;
goto LABEL_5;
}
child = fork();
if ( child )
LABEL_16:
exit(0);
result = fork();
child = result;
if ( !result )
return result;
LABEL_5:
v2 = open("jawas.pid", 577, 384LL);
if ( v2 <= 0 )
{
perror("open");
}
else
{
v3 = getpid();
snprintf(v5, 0x10uLL, "%i\n", v3);
v4 = strlen(v5);
if ( write(v2, v5, v4) < 0 )
fwrite("Failed to write pid", 1uLL, 0x13uLL, stderr);
close(v2);
}
signal(3, (__sighandler_t)kill_all);
signal(15, (__sighandler_t)kill_all);
signal(1, (__sighandler_t)restart_child);
while ( !waitpid(child, &child_status, 1) )
{
if ( murder )
kill_child();
sleep(1u);
}
}
}

canonical_decompiled_code:
__pid_t __fastcall func3(int a1)
{
__pid_t result; // eax
int v2; // ebp
unsigned int v3; // eax
size_t v4; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

while ( 1 )
{
if ( murder )
{
kill(child, 15);
if ( done )
goto LABEL_16;
}
else if ( done )
{
goto LABEL_16;
}
result = child;
if ( !a1 )
{
if ( !child )
return result;
goto LABEL_5;
}
child = fork();
if ( child )
LABEL_16:
exit(0);
result = fork();
child = result;
if ( !result )
return result;
LABEL_5:
v2 = open("jawas.pid", 577, 384LL);
if ( v2 <= 0 )
{
perror("open");
}
else
{
v3 = getpid();
snprintf(v5, 0x10uLL, "%i\n", v3);
v4 = strlen(v5);
if ( write(v2, v5, v4) < 0 )
fwrite("Failed to write pid", 1uLL, 0x13uLL, stderr);
close(v2);
}
signal(3, (__sighandler_t)kill_all);
signal(15, (__sighandler_t)kill_all);
signal(1, (__sighandler_t)restart_child);
while ( !waitpid(child, &child_status, 1) )
{
if ( murder )
func2();
sleep(1u);
}
}
}

original_code:
void
demon(int detach)
{
restart:
 if (murder) kill(child,15);
 if (done) exit(0);
 if (detach) {
  child = fork();
  if (child != 0) exit(0);
  child = fork();
 }
 if (child == 0) return;
 char pid[17];
 int pidfd = open("jawas.pid",0100|01|01000,0600);
 if (pidfd > 0) {
  snprintf(&pid[0],16,"%i\n",getpid());
  if (write(pidfd,pid,strlen(pid)) < 0)
   fprintf(stderr,"Failed to write pid");
  close(pidfd);
 } else perror("open");
 signal(3,kill_all);
 signal(15,kill_all);
 signal(1,restart_child);
 while (!waitpid(child,&child_status,1)) {
  if (murder) kill_child(15);
  sleep(1);
 }
 goto restart;
}

variable_types: detach int

variable_types:
pid
char [17]

variable_types: pidfd int


decompiled_code:
__int64 __fastcall monitor_socket(__int64 a1)
{
return ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD, _QWORD))add_event)(server, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD, _QWORD))add_event)(server, a1, 0LL, 0LL);
}

original_code:
void
monitor_socket(uint64_t f)
{
 add_event(server.kq, f, READ, NONE);
}

canonical_original_code:
void monitor_socket(unsigned long f)
{
 add_event(server.kq, f, READ, NONE);
}

variable_types:
f
unsigned long


decompiled_code:
__int64 __fastcall add_read_socket(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 0;
return ((__int64 (__fastcall *)(__int64, __int64, _QWORD, __int64))add_event)(v2, a1, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 0;
return ((__int64 (__fastcall *)(__int64, __int64, _QWORD, __int64))add_event)(v2, a1, 0LL, 1LL);
}

original_code:
void
add_read_socket(uint64_t f)
{
 client.event = READ;
 add_event(client.kq, f, READ, ONESHOT);
}

canonical_original_code:
void add_read_socket(unsigned long f)
{
 client.event = READ;
 add_event(client.kq, f, READ, ONESHOT);
}


decompiled_code:
__int64 __fastcall add_write_socket(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 1;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 1LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 1;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 1LL, 1LL);
}

original_code:
void
add_write_socket(uint64_t f)
{
 client.event = WRITE;
 add_event(client.kq, f, WRITE, ONESHOT);
}

canonical_original_code:
void add_write_socket(unsigned long f)
{
 client.event = WRITE;
 add_event(client.kq, f, WRITE, ONESHOT);
}


decompiled_code:
__int64 __fastcall add_req_socket(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 3;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 3LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 3;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 3LL, 1LL);
}

original_code:
void
add_req_socket(uint64_t f)
{
 client.event = REQ;
 add_event(client.kq, f, REQ, ONESHOT);
}

canonical_original_code:
void add_req_socket(unsigned long f)
{
 client.event = REQ;
 add_event(client.kq, f, REQ, ONESHOT);
}


decompiled_code:
__int64 __fastcall add_resp_socket(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 2;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 2LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rdi

v2 = client;
*((_DWORD *)&client + 4) = 2;
return ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))add_event)(v2, a1, 2LL, 1LL);
}

original_code:
void
add_resp_socket(uint64_t f)
{
 client.event = RESP;
 add_event(client.kq, f, RESP, ONESHOT);
}

canonical_original_code:
void add_resp_socket(unsigned long f)
{
 client.event = RESP;
 add_event(client.kq, f, RESP, ONESHOT);
}


decompiled_code:
__int64 __fastcall add_file_monitor(__int64 a1, __int64 a2)
{
inotify_add_watch(server[1], *(const char **)(a2 + 8), 0x202u);
return ((__int64 (__fastcall *)(_QWORD, _QWORD, __int64, __int64))add_event)(server[0], server[1], 4LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
inotify_add_watch(server[1], *(const char **)(a2 + 8), 0x202u);
return ((__int64 (__fastcall *)(_QWORD, _QWORD, __int64, __int64))add_event)(server[0], server[1], 4LL, 1LL);
}

original_code:
void
add_file_monitor(uint64_t f, str filename)
{
 inotify_add_watch(server.in,filename->data, 0x00000002 | 0x00000200);
 add_event(server.kq, server.in, NODE, ONESHOT);
}

canonical_original_code:
void add_file_monitor(unsigned long f, struct str_struct *filename)
{
 inotify_add_watch(server.in,filename->data, 0x00000002 | 0x00000200);
 add_event(server.kq, server.in, NODE, ONESHOT);
}

variable_types: struct str_struct { int length; char *data; char contents[]; } *


decompiled_code:
void add_pid_monitor()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void
add_pid_monitor(pid_t p)
{
}

canonical_original_code:
void add_pid_monitor(int p)
{
}

variable_types: p int


decompiled_code:
__int64 __fastcall find_status_code(int a1)
{
int *v1; // rdx
int v2; // eax
unsigned int v3; // er8

if ( !stati )
{
while ( 1 )
LABEL_7:
;
}
LABEL_2:
v1 = (int *)&unk_1D8;
v2 = stati;
v3 = 0;
while ( a1 != v2 )
{
v2 = *v1;
v1 += 6;
++v3;
if ( !v2 )
{
a1 = 500;
if ( !stati )
goto LABEL_7;
goto LABEL_2;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int *v1; // rdx
int v2; // eax
unsigned int v3; // er8

if ( !stati )
{
while ( 1 )
LABEL_7:
;
}
LABEL_2:
v1 = (int *)&unk_1D8;
v2 = stati;
v3 = 0;
while ( a1 != v2 )
{
v2 = *v1;
v1 += 6;
++v3;
if ( !v2 )
{
a1 = 500;
if ( !stati )
goto LABEL_7;
goto LABEL_2;
}
}
return v3;
}

original_code:
int
find_status_code(int code)
{
 for (int i = 0; stati[i].code; ++i)
  if (stati[i].code == code)
   return i;
 return find_status_code(500);
}

variable_types: code int

variable_types: i int


decompiled_code:
__int64 __fastcall status_line(int a1)
{
__int64 v1; // rbx
int *v2; // rbp

v1 = (int)find_status_code(a1);
v2 = &stati[6 * v1];
if ( !v2[1] )
v2[1] = strlen(*((const char **)v2 + 1));
return _("%c %c", "HTTP/1.1", (&off_1C8)[3 * v1]);
}

original_code:
str
status_line(int code)
{
 int i = find_status_code(code);
 if (stati[i].len == 0)
  stati[i].len = strlen(stati[i].reason);
 return _("%c %c",http_version,stati[i].reason);
}

canonical_original_code:
struct str_struct *status_line(int code)
{
 int i = find_status_code(code);
 if (stati[i].len == 0)
  stati[i].len = strlen(stati[i].reason);
 return _("%c %c",http_version,stati[i].reason);
}

return_type: struct str_struct { int length; char *data; char contents[]; } *


decompiled_code:
__int64 __fastcall error_handler(unsigned int a1)
{
__int64 v2; // rdi
const char *v3; // r13
const char *v4; // rax
__int64 v5; // rax
__int64 v6; // rbp
__int64 *v7; // rax
__int64 v8; // rdi
unsigned int v9; // ebx

v2 = qword_1D0[3 * (int)find_status_code(a1)];
if ( v2 )
{
v3 = (const char *)copy(v2, 0LL);
v4 = (const char *)ref("errors", 6LL);
v5 = _("%s/%s%s", *((const char **)&server + 7), v4, v3);
v6 = load(v5);
send_status(**((_QWORD **)&client + 5), a1);
send_headers(**((_QWORD **)&client + 5), *(_QWORD *)(*((_QWORD *)&client + 5) + 16LL));
if ( v6 )
{
v7 = (__int64 *)*((_QWORD *)&client + 5);
v8 = *v7;
v7[4] = v6;
v9 = *(_DWORD *)(v8 + 40);
if ( !v9 )
{
do
{
if ( (int)v9 >= *(_QWORD *)(v6 + 56) )
break;
v9 += send_raw_contents(v8, v6, v9, 1LL);
v8 = **((_QWORD **)&client + 5);
}
while ( !*(_DWORD *)(v8 + 40) );
}
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v2; // rdi
const char *v3; // r13
const char *v4; // rax
__int64 v5; // rax
__int64 v6; // rbp
__int64 *v7; // rax
__int64 v8; // rdi
unsigned int v9; // ebx

v2 = qword_1D0[3 * (int)func0(a1)];
if ( v2 )
{
v3 = (const char *)copy(v2, 0LL);
v4 = (const char *)ref("errors", 6LL);
v5 = _("%s/%s%s", *((const char **)&server + 7), v4, v3);
v6 = load(v5);
func2(**((_QWORD **)&client + 5), a1);
send_headers(**((_QWORD **)&client + 5), *(_QWORD *)(*((_QWORD *)&client + 5) + 16LL));
if ( v6 )
{
v7 = (__int64 *)*((_QWORD *)&client + 5);
v8 = *v7;
v7[4] = v6;
v9 = *(_DWORD *)(v8 + 40);
if ( !v9 )
{
do
{
if ( (int)v9 >= *(_QWORD *)(v6 + 56) )
break;
v9 += send_raw_contents(v8, v6, v9, 1LL);
v8 = **((_QWORD **)&client + 5);
}
while ( !*(_DWORD *)(v8 + 40) );
}
}
}
return a1;
}

original_code:
int
error_handler(int code)
{
 int total = 0;
 int i = find_status_code(code);
 if (! stati[i].filename) return code;
 File fc = load(_("%s/%s%s",server.cwd,ref("errors",6),copy(stati[i].filename,0)));
 send_status(client.response->socket,code);
 send_headers(client.response->socket,client.response->headers);
 if (! fc) return code;
 client.response->raw_contents = fc;
 while (!client.response->socket->closed && total < fc->st.st_size)
  total += send_raw_contents(client.response->socket,fc,total,1);
 return code;
}

canonical_original_code:
int error_handler(int code)
{
 int total = 0;
 int i = find_status_code(code);
 if (! stati[i].filename) return code;
 struct file_cache_struct *fc = load(_("%s/%s%s",server.cwd,ref("errors",6),copy(stati[i].filename,0)));
 send_status(client.response->socket,code);
 send_headers(client.response->socket,client.response->headers);
 if (! fc) return code;
 client.response->raw_contents = fc;
 while (!client.response->socket->closed && total < fc->st.st_size)
  total += send_raw_contents(client.response->socket,fc,total,1);
 return code;
}

variable_types: struct file_cache_struct { struct file_cache_struct *next; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; struct parsed_struct { enum { TEXT=1, SCRIPT=2, EMIT=3 } kind; int offset; int length; } *parsed; struct mime_struct { struct { int len; char *data; } ending; struct { int len; char *data; } type; int (*handler)(struct file_cache_struct *); } *mime; char *data; int fd; struct str_struct { int length; char *data; char contents[]; } name; } *


decompiled_code:
void log_start()
{
openlog("jawas", 11, 176);
}

canonical_decompiled_code:
void func0()
{
openlog("jawas", 11, 176);
}


decompiled_code:
void log_msg(unsigned int a1, __int64 a2, ...)
{
__int64 v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= (int)a1 && a1 <= 4 )
{
va_start(va, a2);
v2 = new_str(a2, va);
syslog(log_msgs[a1], *(const char **)(v2 + 8));
}
}

canonical_decompiled_code:
void func1(unsigned int a1, __int64 a2, ...)
{
__int64 v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= (int)a1 && a1 <= 4 )
{
va_start(va, a2);
v2 = new_str(a2, va);
syslog(log_msgs[a1], *(const char **)(v2 + 8));
}
}

original_code:
void
log_msg(int lvl, char* fmt, ...)
{
 va_list args;
 if (lvl < 0 || lvl > log_level || lvl > max_log_lvl) return;
 __builtin_va_start(args,fmt);
 str msg = new_str(fmt,args);
 syslog(log_msgs[lvl],msg->data);
 __builtin_va_end(args);
}

canonical_original_code:
void log_msg(int lvl, char *fmt, ...)
{
 __builtin_va_list args;
 if (lvl < 0 || lvl > log_level || lvl > max_log_lvl) return;
 __builtin_va_start(args,fmt);
 struct str_struct *msg = new_str(fmt,args);
 syslog(log_msgs[lvl],msg->data);
 __builtin_va_end(args);
}

variable_types: lvl int

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall img_handler(__int64 a1)
{
time_t v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
const char *v6; // rax
const char *v7; // rbx
__int64 v8; // r12
int v9; // eax
__int64 v10; // r13
const char *v11; // rax
int v12; // eax
const char *v13; // rax
__int64 *v14; // rax
__int64 v15; // rdi
unsigned int v16; // ebx

cache_control(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), "max-age=86400, public");
v2 = time(0LL);
v3 = Date(v2);
date_field(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), *(_QWORD *)(v3 + 8));
v4 = Expires();
expires(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), *(_QWORD *)(v4 + 8));
send_status(**((_QWORD **)&client + 5), 200LL);
send_headers(**((_QWORD **)&client + 5), *(_QWORD *)(*((_QWORD *)&client + 5) + 16LL));
v5 = _("Range");
v6 = (const char *)find_header(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)&client + 5) + 8LL) + 16LL), v5);
if ( v6 )
{
v7 = v6;
log_msg(3LL, "Ranges: %s", v6);
v8 = (unsigned int)find(v7, 0LL, "0123456789", 10LL);
v9 = find(v7, v8, "-", 1LL);
v10 = v9;
v11 = (const char *)ref(*((_QWORD *)v7 + 1) + (int)v8, (unsigned int)(v9 - v8));
log_msg(3LL, "Start range: %s", v11);
v12 = len(v7);
v13 = (const char *)ref(*((_QWORD *)v7 + 1) + v10 + 1, (unsigned int)(v12 - v10));
log_msg(3LL, "End range: %s", v13);
}
v14 = (__int64 *)*((_QWORD *)&client + 5);
v15 = *v14;
v16 = *(_DWORD *)(*v14 + 40);
if ( !v16 )
{
do
{
if ( (int)v16 >= *(_QWORD *)(a1 + 56) )
break;
v16 += send_raw_contents(v15, a1, v16, 1LL);
v15 = **((_QWORD **)&client + 5);
}
while ( !*(_DWORD *)(v15 + 40) );
}
return 200LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
time_t v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
const char *v6; // rax
const char *v7; // rbx
__int64 v8; // r12
int v9; // eax
__int64 v10; // r13
const char *v11; // rax
int v12; // eax
const char *v13; // rax
__int64 *v14; // rax
__int64 v15; // rdi
unsigned int v16; // ebx

cache_control(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), "max-age=86400, public");
v2 = time(0LL);
v3 = Date(v2);
date_field(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), *(_QWORD *)(v3 + 8));
v4 = Expires();
expires(*(_QWORD *)(*((_QWORD *)&client + 5) + 16LL), *(_QWORD *)(v4 + 8));
send_status(**((_QWORD **)&client + 5), 200LL);
send_headers(**((_QWORD **)&client + 5), *(_QWORD *)(*((_QWORD *)&client + 5) + 16LL));
v5 = _("Range");
v6 = (const char *)find_header(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)&client + 5) + 8LL) + 16LL), v5);
if ( v6 )
{
v7 = v6;
log_msg(3LL, "Ranges: %s", v6);
v8 = (unsigned int)find(v7, 0LL, "0123456789", 10LL);
v9 = find(v7, v8, "-", 1LL);
v10 = v9;
v11 = (const char *)ref(*((_QWORD *)v7 + 1) + (int)v8, (unsigned int)(v9 - v8));
log_msg(3LL, "Start range: %s", v11);
v12 = len(v7);
v13 = (const char *)ref(*((_QWORD *)v7 + 1) + v10 + 1, (unsigned int)(v12 - v10));
log_msg(3LL, "End range: %s", v13);
}
v14 = (__int64 *)*((_QWORD *)&client + 5);
v15 = *v14;
v16 = *(_DWORD *)(*v14 + 40);
if ( !v16 )
{
do
{
if ( (int)v16 >= *(_QWORD *)(a1 + 56) )
break;
v16 += send_raw_contents(v15, a1, v16, 1LL);
v15 = **((_QWORD **)&client + 5);
}
while ( !*(_DWORD *)(v15 + 40) );
}
return 200LL;
}

original_code:
int
img_handler(File fc)
{
 int total = 0;
 cache_control(client.response->headers,"max-age=86400, public");
 date_field(client.response->headers,Date(time(((void *)0)))->data);
 expires(client.response->headers,Expires()->data);
 send_status(client.response->socket,200);
 send_headers(client.response->socket,client.response->headers);
 str range = find_header(client.response->request->headers,_("Range"));
 if (range) {
  log_msg(3,"Ranges: %s",range);
  int start = find(range,0,"0123456789",10);
  int dash = find(range,start,"-",1);
  log_msg(3,"Start range: %s",ref(range->data+start,dash-start));
  log_msg(3,"End range: %s",ref(range->data+dash+1,len(range)-dash));
 }
 while (! client.response->socket->closed && total < fc->st.st_size)
  total += send_raw_contents(client.response->socket,fc,total,1);
 return 200;
}

canonical_original_code:
int img_handler(struct file_cache_struct *fc)
{
 int total = 0;
 cache_control(client.response->headers,"max-age=86400, public");
 date_field(client.response->headers,Date(time(((void *)0)))->data);
 expires(client.response->headers,Expires()->data);
 send_status(client.response->socket,200);
 send_headers(client.response->socket,client.response->headers);
 struct str_struct *range = find_header(client.response->request->headers,_("Range"));
 if (range) {
  log_msg(3,"Ranges: %s",range);
  int start = find(range,0,"0123456789",10);
  int dash = find(range,start,"-",1);
  log_msg(3,"Start range: %s",ref(range->data+start,dash-start));
  log_msg(3,"End range: %s",ref(range->data+dash+1,len(range)-dash));
 }
 while (! client.response->socket->closed && total < fc->st.st_size)
  total += send_raw_contents(client.response->socket,fc,total,1);
 return 200;
}

variable_types: start int

variable_types: dash int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: struct parsed_struct { enum { TEXT=1, SCRIPT=2, EMIT=3 } kind; int offset; int length; }

user_defined_types: struct mime_struct { struct { int len; char *data; } ending; struct { int len; char *data; } type; int (*handler)(struct file_cache_struct *); }


decompiled_code:
__int64 __fastcall is_directory(__int64 a1)
{
void *v1; // rcx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(*(const char **)(a1 + 8), &v3) )
{
log_msg(0LL, "Failed to stat file %s", (const char *)a1);
result = 0LL;
}
else
{
v1 = &unk_2B7;
if ( (v3.st_mode & 0x4000) == 0 )
v1 = &unk_2BB;
log_msg(3LL, "Is %s a Directory? %c", (const char *)a1, v1);
result = v3.st_mode & 0x4000;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
void *v1; // rcx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(*(const char **)(a1 + 8), &v3) )
{
log_msg(0LL, "Failed to stat file %s", (const char *)a1);
result = 0LL;
}
else
{
v1 = &unk_2B7;
if ( (v3.st_mode & 0x4000) == 0 )
v1 = &unk_2BB;
log_msg(3LL, "Is %s a Directory? %c", (const char *)a1, v1);
result = v3.st_mode & 0x4000;
}
return result;
}

original_code:
int
is_directory(str filename)
{
 struct stat st;
 if (stat(filename->data,&st)) {
  log_msg(0,"Failed to stat file %s",filename);
  return 0;
 }
 log_msg(3,"Is %s a Directory? %c",filename,st.st_mode & 0040000 ? "yes": "no");
 return st.st_mode & 0040000;
}

canonical_original_code:
int is_directory(struct str_struct *filename)
{
 struct stat st;
 if (stat(filename->data,&st)) {
  log_msg(0,"Failed to stat file %s",filename);
  return 0;
 }
 log_msg(3,"Is %s a Directory? %c",filename,st.st_mode & 0040000 ? "yes": "no");
 return st.st_mode & 0040000;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall is_file(__int64 a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( !stat(*(const char **)(a1 + 8), &v2) )
return v2.st_mode & 0xA000;
log_msg(0LL, "Failed to stat file %s", (const char *)a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( !stat(*(const char **)(a1 + 8), &v2) )
return v2.st_mode & 0xA000;
log_msg(0LL, "Failed to stat file %s", (const char *)a1);
return 0LL;
}

original_code:
int
is_file(str filename)
{
 struct stat st;
 if (stat(filename->data,&st)) {
  log_msg(0,"Failed to stat file %s",filename);
  return 0;
 }
 return st.st_mode & (0100000|0120000);
}

canonical_original_code:
int is_file(struct str_struct *filename)
{
 struct stat st;
 if (stat(filename->data,&st)) {
  log_msg(0,"Failed to stat file %s",filename);
  return 0;
 }
 return st.st_mode & (0100000|0120000);
}


decompiled_code:
__int64 __fastcall deauth_path(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
const char *v6; // rax
__int64 v7; // rax
const char *v8; // rax
__int64 v9; // r14
__int64 v10; // rax
const char *v11; // rcx

v2 = (int)len(a2);
v3 = _("%s/%s%s", *((const char **)&server + 7), a1, (const char *)a2);
if ( (unsigned int)is_directory(v3)
|| (v4 = _("%s/%s%s", *((const char **)&server + 7), a1, (const char *)a2), (unsigned int)is_file(v4))
|| (v5 = 1LL, v2 <= 1) )
{
LABEL_9:
v11 = (const char *)a2;
}
else
{
while ( 1 )
{
if ( (unsigned __int8)at(a2, (unsigned int)v5) == 47 )
{
v6 = (const char *)ref(v5 + *(_QWORD *)(a2 + 8), (unsigned int)(v2 - v5));
v7 = _("%s/%s%s", *((const char **)&server + 7), a1, v6);
if ( (unsigned int)is_directory(v7) )
break;
}
if ( v2 == ++v5 )
goto LABEL_9;
}
v8 = (const char *)ref(*(_QWORD *)(a2 + 8) + 1LL, (unsigned int)(v5 - 1));
log_msg(3LL, "Found auth token [%s]", v8);
v9 = ref(*(_QWORD *)(a2 + 8) + 1LL, (unsigned int)(v5 - 1));
v10 = _("Token");
append_header(*(_QWORD *)(client[4] + 16LL), v10, v9);
v11 = (const char *)ref(*(_QWORD *)(a2 + 8) + v5, (unsigned int)(v2 - v5));
}
return _("%s/%s%s", *((const char **)&server + 7), a1, v11);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
const char *v6; // rax
__int64 v7; // rax
const char *v8; // rax
__int64 v9; // r14
__int64 v10; // rax
const char *v11; // rcx

v2 = (int)len(a2);
v3 = _("%s/%s%s", *((const char **)&server + 7), a1, (const char *)a2);
if ( (unsigned int)func0(v3)
|| (v4 = _("%s/%s%s", *((const char **)&server + 7), a1, (const char *)a2), (unsigned int)func1(v4))
|| (v5 = 1LL, v2 <= 1) )
{
LABEL_9:
v11 = (const char *)a2;
}
else
{
while ( 1 )
{
if ( (unsigned __int8)at(a2, (unsigned int)v5) == 47 )
{
v6 = (const char *)ref(v5 + *(_QWORD *)(a2 + 8), (unsigned int)(v2 - v5));
v7 = _("%s/%s%s", *((const char **)&server + 7), a1, v6);
if ( (unsigned int)func0(v7) )
break;
}
if ( v2 == ++v5 )
goto LABEL_9;
}
v8 = (const char *)ref(*(_QWORD *)(a2 + 8) + 1LL, (unsigned int)(v5 - 1));
log_msg(3LL, "Found auth token [%s]", v8);
v9 = ref(*(_QWORD *)(a2 + 8) + 1LL, (unsigned int)(v5 - 1));
v10 = _("Token");
append_header(*(_QWORD *)(client[4] + 16LL), v10, v9);
v11 = (const char *)ref(*(_QWORD *)(a2 + 8) + v5, (unsigned int)(v2 - v5));
}
return _("%s/%s%s", *((const char **)&server + 7), a1, v11);
}

original_code:
str
deauth_path(str host, str filename)
{
 size_t l = len(filename);
 if (is_directory(_("%s/%s%s",server.cwd,host,filename)) || is_file(_("%s/%s%s",server.cwd,host,filename)))
  return _("%s/%s%s",server.cwd,host,filename);
 for (int i = 1; i < l; ++i) {
  if (at(filename,i) == '/' && is_directory(_("%s/%s%s",server.cwd,host,ref(filename->data+i,l-i)))) {
   log_msg(3,"Found auth token [%s]",ref(filename->data+1,i-1));
   append_header(client.request->headers,_("Token"),ref(filename->data+1,i-1));
   return _("%s/%s%s",server.cwd,host,ref(filename->data+i,l-i));
  }
 }
 return _("%s/%s%s",server.cwd,host,filename);
}

canonical_original_code:
struct str_struct *deauth_path(struct str_struct *host, struct str_struct *filename)
{
 unsigned long l = len(filename);
 if (is_directory(_("%s/%s%s",server.cwd,host,filename)) || is_file(_("%s/%s%s",server.cwd,host,filename)))
  return _("%s/%s%s",server.cwd,host,filename);
 for (int i = 1; i < l; ++i) {
  if (at(filename,i) == '/' && is_directory(_("%s/%s%s",server.cwd,host,ref(filename->data+i,l-i)))) {
   log_msg(3,"Found auth token [%s]",ref(filename->data+1,i-1));
   append_header(client.request->headers,_("Token"),ref(filename->data+1,i-1));
   return _("%s/%s%s",server.cwd,host,ref(filename->data+i,l-i));
  }
 }
 return _("%s/%s%s",server.cwd,host,filename);
}

variable_types:
host
struct str_struct *

variable_types:
filename
struct str_struct *

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall get_index(const char *a1)
{
const char *v1; // r12
const char **v2; // rbx
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // rax

v1 = "index.html";
v2 = (const char **)off_368;
do
{
v5 = _("%s%c", a1, v1);
result = load(v5);
if ( result )
break;
v3 = _("%s/%c", a1, v1);
result = load(v3);
if ( result )
break;
v1 = *v2++;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
const char *v1; // r12
const char **v2; // rbx
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // rax

v1 = "index.html";
v2 = (const char **)off_368;
do
{
v5 = _("%s%c", a1, v1);
result = load(v5);
if ( result )
break;
v3 = _("%s/%c", a1, v1);
result = load(v3);
if ( result )
break;
v1 = *v2++;
}
while ( v1 );
return result;
}

original_code:
File
get_index(str filename)
{
 File retval = ((void *)0);
 for (int i = 0; indexes[i]; ++i) {
  str index_path = _("%s%c",filename,indexes[i]);
  if ((retval = load(index_path))) return retval;
  index_path = _("%s/%c",filename,indexes[i]);
  if ((retval = load(index_path))) return retval;
 }
 return ((void *)0);
}

canonical_original_code:
struct file_cache_struct *get_index(struct str_struct *filename)
{
 struct file_cache_struct *retval = ((void *)0);
 for (int i = 0; indexes[i]; ++i) {
  struct str_struct *index_path = _("%s%c",filename,indexes[i]);
  if ((retval = load(index_path))) return retval;
  index_path = _("%s/%c",filename,indexes[i]);
  if ((retval = load(index_path))) return retval;
 }
 return ((void *)0);
}

return_type: struct file_cache_struct { struct file_cache_struct *next; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; struct parsed_struct { enum { TEXT=1, SCRIPT=2, EMIT=3 } kind; int offset; int length; } *parsed; struct mime_struct { struct { int len; char *data; } ending; struct { int len; char *data; } type; int (*handler)(struct file_cache_struct *); } *mime; char *data; int fd; struct str_struct { int length; char *data; char contents[]; } name; } *


decompiled_code:
int *__fastcall lookup_mimetype(const char *a1)
{
int v1; // ebx
__int64 v2; // rcx
int v3; // eax
int v4; // eax
const char *v5; // r13
int *i; // r12
int v8; // ebx

v1 = strlen(a1);
log_msg(3LL, "Local: %c", a1);
v2 = v1 - 1;
if ( v1 - 1 > 0 )
{
while ( 1 )
{
v3 = v2;
if ( a1[v2 - 1] == 46 )
break;
v3 = --v2;
if ( !v2 )
{
v2 = v3;
break;
}
}
v8 = v1 - v3;
}
else
{
v8 = 1;
}
v4 = mime_types;
v5 = &a1[v2];
for ( i = &mime_types; v4; i += 10 )
{
if ( v4 == v8 && !strncmp(*((const char **)i + 1), v5, v8) )
break;
v4 = i[10];
}
log_msg(3LL, "Mime: %c (%c)", *((_QWORD *)i + 3), v5);
return i;
}

canonical_decompiled_code:
int *__fastcall func0(const char *a1)
{
int v1; // ebx
__int64 v2; // rcx
int v3; // eax
int v4; // eax
const char *v5; // r13
int *i; // r12
int v8; // ebx

v1 = strlen(a1);
log_msg(3LL, "Local: %c", a1);
v2 = v1 - 1;
if ( v1 - 1 > 0 )
{
while ( 1 )
{
v3 = v2;
if ( a1[v2 - 1] == 46 )
break;
v3 = --v2;
if ( !v2 )
{
v2 = v3;
break;
}
}
v8 = v1 - v3;
}
else
{
v8 = 1;
}
v4 = mime_types;
v5 = &a1[v2];
for ( i = &mime_types; v4; i += 10 )
{
if ( v4 == v8 && !strncmp(*((const char **)i + 1), v5, v8) )
break;
v4 = i[10];
}
log_msg(3LL, "Mime: %c (%c)", *((_QWORD *)i + 3), v5);
return i;
}

original_code:
MimeTypes*
lookup_mimetype(char* filename)
{
 MimeTypes* mt;
 int i,l = strlen(filename);
 log_msg(3,"Local: %c",filename);
 for (i = l - 1; i > 0; --i)
  if (filename[i-1] == '.') break;
 l -= i;
 for (mt = mime_types; mt->ending.len; ++mt)
  if (l == mt->ending.len && !strncmp(mt->ending.data,&filename[i],l))
   break;
 log_msg(3,"Mime: %c (%c)",mt->type.data,&filename[i]);
 return mt;
}

canonical_original_code:
struct mime_struct *lookup_mimetype(char *filename)
{
 struct mime_struct *mt;
 int i; int l = strlen(filename);
 log_msg(3,"Local: %c",filename);
 for (i = l - 1; i > 0; --i)
  if (filename[i-1] == '.') break;
 l -= i;
 for (mt = mime_types; mt->ending.len; ++mt)
  if (l == mt->ending.len && !strncmp(mt->ending.data,&filename[i],l))
   break;
 log_msg(3,"Mime: %c (%c)",mt->type.data,&filename[i]);
 return mt;
}

variable_types:
filename
char *

variable_types: struct mime_struct { struct { int len; char *data; } ending; struct { int len; char *data; } type; int (*handler)(struct file_cache_struct { struct file_cache_struct *next; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; struct parsed_struct { enum { TEXT=1, SCRIPT=2, EMIT=3 } kind; int offset; int length; } *parsed; struct mime_struct *mime; char *data; int fd; struct str_struct { int length; char *data; char contents[]; } name; } *); } *

variable_types: l int


decompiled_code:
__int64 __fastcall mimetype_handler(__int64 a1)
{
int *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = *(int **)(a1 + 160);
if ( !v1 )
{
v1 = lookup_mimetype(*(const char **)(a1 + 192));
*(_QWORD *)(a1 + 160) = v1;
}
content_type(*(_QWORD *)(client[5] + 16LL), *((_QWORD *)v1 + 3));
result = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(a1 + 160) + 32LL))(a1);
}
else
{
log_msg(0LL, "File not found 404");
result = error_handler(404LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = *(int **)(a1 + 160);
if ( !v1 )
{
v1 = func0(*(const char **)(a1 + 192));
*(_QWORD *)(a1 + 160) = v1;
}
content_type(*(_QWORD *)(client[5] + 16LL), *((_QWORD *)v1 + 3));
result = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(a1 + 160) + 32LL))(a1);
}
else
{
log_msg(0LL, "File not found 404");
result = error_handler(404LL);
}
return result;
}

original_code:
int
mimetype_handler(File fc)
{
 if (!fc) {
  log_msg(0,"File not found 404");
  return error_handler(404);
 }
 if (!fc->mime) fc->mime = lookup_mimetype(fc->name.data);
 content_type(client.response->headers, fc->mime->type.data);
 return fc->mime->handler(fc);
}

canonical_original_code:
int mimetype_handler(struct file_cache_struct *fc)
{
 if (!fc) {
  log_msg(0,"File not found 404");
  return error_handler(404);
 }
 if (!fc->mime) fc->mime = lookup_mimetype(fc->name.data);
 content_type(client.response->headers, fc->mime->type.data);
 return fc->mime->handler(fc);
}


decompiled_code:
_BOOL8 __fastcall parseable_file(__int64 a1)
{
__int64 v1; // rax
int *v3; // rax
bool v4; // zf

v1 = *(_QWORD *)(a1 + 160);
if ( v1 )
return *(_QWORD *)(v1 + 32) == (_QWORD)&lws_handler;
v3 = lookup_mimetype(*(const char **)(a1 + 192));
v4 = *((_QWORD *)v3 + 4) == (_QWORD)&lws_handler;
*(_QWORD *)(a1 + 160) = v3;
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
int *v3; // rax
bool v4; // zf

v1 = *(_QWORD *)(a1 + 160);
if ( v1 )
return *(_QWORD *)(v1 + 32) == (_QWORD)&lws_handler;
v3 = func0(*(const char **)(a1 + 192));
v4 = *((_QWORD *)v3 + 4) == (_QWORD)&lws_handler;
*(_QWORD *)(a1 + 160) = v3;
return v4;
}

original_code:
int
parseable_file(File fc)
{
 if (!fc->mime) fc->mime = lookup_mimetype(fc->name.data);
 return fc->mime->handler == lws_handler;
}

canonical_original_code:
int parseable_file(struct file_cache_struct *fc)
{
 if (!fc->mime) fc->mime = lookup_mimetype(fc->name.data);
 return fc->mime->handler == lws_handler;
}


lFactorial

repo: cthunman/probziez

decompiled_code:
__int64 __fastcall lFactorial(__int64 a1)
{
__int64 result; // rax

for ( result = 1LL; a1; --a1 )
result *= a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

for ( result = 1LL; a1; --a1 )
result *= a1;
return result;
}

original_code:
unsigned long long lFactorial(unsigned long long x) {
 unsigned long long product;
 product = 1;
 while (x > 0) {
  product *= x;
  --x;
 }
 return product;
}

variable_types:
x
unsigned long long

variable_types:
product
unsigned long long

return_type: unsigned long long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbp
int v4; // er13
int v5; // ebx
int v6; // edx
int v7; // eax
int v8; // edx

v3 = (int *)malloc(0x10uLL);
readInt(v3, argv);
readInt(v3 + 1, argv);
readInt(v3 + 2, argv);
readInt(v3 + 3, argv);
v4 = *v3;
nChooseK((double)*v3, (double)v3[1]);
v5 = v3[3];
v6 = (int)ceil((double)v5 / (double)v3[2]);
if ( v5 >= v6 )
{
v7 = v6;
do
{
nChooseK((double)v5, (double)v7);
nChooseK((double)(v4 - v5), (double)v8);
}
while ( v5 >= v7 );
}
printf("%lu\n", 8LL);
printf("%lu\n", 8LL);
printf("%lu\n", 8LL);
printf("%lu\n", 8LL);
free(v3);
return 0;
}

original_code:
int main() {
 int count;
 int* inputArray = (int*) malloc(4 * sizeof(int));
 long winsNeeded;
 long possibleWinningCombos = 0;
 long possibleCombos = 0;
 for (count = 0; count < 4; count++) {
  readInt(&inputArray[count]);
 }
 possibleCombos = nChooseK(inputArray[0], inputArray[1]);
 winsNeeded = ceil((double) inputArray[3] / inputArray[2]);
 for (count = winsNeeded; count < inputArray[3] + 1; count++) {
  possibleWinningCombos +=
   (nChooseK(inputArray[3], count) *
    nChooseK(inputArray[0] - inputArray[3], inputArray[1] - count));
 }
 printf("%lu\n", sizeof(double));
 printf("%lu\n", sizeof(unsigned long));
 printf("%lu\n", sizeof(long));
 printf("%lu\n", sizeof(unsigned long long));
 free(inputArray);
}

canonical_original_code:
int main() {
 int count;
 int *inputArray = (int*) malloc(4 * sizeof(int));
 long winsNeeded;
 long possibleWinningCombos = 0;
 long possibleCombos = 0;
 for (count = 0; count < 4; count++) {
  readInt(&inputArray[count]);
 }
 possibleCombos = nChooseK(inputArray[0], inputArray[1]);
 winsNeeded = ceil((double) inputArray[3] / inputArray[2]);
 for (count = winsNeeded; count < inputArray[3] + 1; count++) {
  possibleWinningCombos +=
   (nChooseK(inputArray[3], count) *
    nChooseK(inputArray[0] - inputArray[3], inputArray[1] - count));
 }
 printf("%lu\n", sizeof(double));
 printf("%lu\n", sizeof(unsigned long));
 printf("%lu\n", sizeof(long));
 printf("%lu\n", sizeof(unsigned long long));
 free(inputArray);
}

variable_types: count int

variable_types:
inputArray
int *

variable_types: winsNeeded long

variable_types: possibleWinningCombos long

variable_types: possibleCombos long


repo: ctm/executor

decompiled_code:
__int64 __fastcall read_long(unsigned int *a1)
{
return (int)_byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return (int)_byteswap_ulong(*a1);
}

original_code:
long
read_long (const unsigned char *p)
{
  return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}

variable_types:
p
unsigned char *

return_type: long


decompiled_code:
__int16 __fastcall read_short(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func1(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

original_code:
short
read_short (const unsigned char *p)
{
  return (p[0] << 8) | p[1];
}

canonical_original_code:
short read_short(unsigned char *p)
{
  return (p[0] << 8) | p[1];
}

return_type: short


original_code:
static int
call_p (const char *opcode)
{
  return (!strncmp (opcode, "bsr", 3)
   || !strncmp (opcode, "jsr", 3));
}

canonical_original_code:
static int call_p(char *opcode)
{
  return (!strncmp (opcode, "bsr", 3)
   || !strncmp (opcode, "jsr", 3));
}

variable_types:
opcode
char *


decompiled_code:
void *__fastcall add_labels(void *ptr, __int64 a2, int a3)
{
__int64 v5; // r15
char v6; // r13
_BYTE *v7; // r12
_BYTE *v8; // r14
__int64 v9; // r12
char *v10; // rax
char *v11; // r12
size_t v12; // rax
char *v13; // rbx
char *v14; // rax
const char *v15; // rax
const char *v16; // r14
char *v17; // rdi
char *v18; // rax
char v19; // al
size_t v20; // rax
char *v21; // rax
char *v22; // r14
char *v23; // rbp
_BYTE *v24; // rax
_BYTE *v25; // r8
char *v26; // rbx
unsigned __int8 *v27; // rdx
unsigned int i; // er14
__int16 *v29; // rdx
size_t v30; // rax
size_t v32; // rax
__int16 *v33; // r13
char *v34; // rax
void *v35; // rsi
char **v36; // rbx
__int64 v37; // rdi
char *v38; // rdx
char *v40; // [rsp+8h] [rbp-1070h]
char *v41; // [rsp+10h] [rbp-1068h]
_BYTE *v42; // [rsp+18h] [rbp-1060h]
char s[32]; // [rsp+20h] [rbp-1058h] BYREF
char v44[1024]; // [rsp+40h] [rbp-1038h] BYREF
unsigned __int8 v45[1024]; // [rsp+440h] [rbp-C38h] BYREF
char src[1024]; // [rsp+840h] [rbp-838h] BYREF
char v47[1080]; // [rsp+C40h] [rbp-438h] BYREF

if ( !ptr )
return 0LL;
if ( !branch_hash_0 )
{
v35 = &unk_7E4;
v36 = off_990;
branch_hash_0 = hash_new();
v37 = branch_hash_0;
v38 = (char *)&unk_7E4;
while ( 1 )
{
hash_insert(v37, v35, v38);
if ( v36 == (char **)&unk_DF0 )
break;
v37 = branch_hash_0;
v38 = v36[1];
v36 += 2;
v35 = *(v36 - 2);
}
}
v5 = hash_new();
sprintf(s, "0x%lx", a2);
hash_insert(v5, s, "_main");
v6 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v7 = ptr;
do
{
if ( extract_field(v7, 1LL, v45)
&& hash_lookup(branch_hash_0, v45)
&& extract_field(v7, 2LL, src)
&& extract_branch_target((const char *)v45, src)
&& !extract_field(v7, 3LL, v47) )
{
v33 = aFl;
if ( !call_p(v45) )
v33 = &aFl[1];
v34 = extract_branch_target((const char *)v45, src);
hash_insert(v5, v34, v33);
}
v7 = next_line(v7);
}
while ( *v7 );
v6 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v8 = ptr;
v9 = 0LL;
do
{
while ( 1 )
{
if ( extract_field(v8, 0LL, v44) )
{
v10 = (char *)hash_lookup(v5, v44);
if ( v10 )
{
if ( !v10[1] )
break;
}
}
v8 = next_line(v8);
if ( !*v8 )
goto LABEL_18;
}
sprintf(s, "%c%lu_", (unsigned int)*v10, v9++);
hash_remove(v5, v44);
hash_insert(v5, v44, s);
v8 = next_line(v8);
}
while ( *v8 );
LABEL_18:
v6 = *(_BYTE *)ptr;
}
}
v11 = (char *)ptr;
v12 = strlen((const char *)ptr);
v40 = (char *)malloc(2 * v12 + 100);
v13 = v40;
while ( v6 )
{
while ( extract_field(v11, 1LL, v45) )
{
if ( !hash_lookup(branch_hash_0, v45) )
break;
if ( !extract_field(v11, 2LL, src) )
break;
if ( !extract_branch_target((const char *)v45, src) )
break;
if ( extract_field(v11, 3LL, v47) )
break;
v14 = extract_branch_target((const char *)v45, src);
v15 = (const char *)hash_lookup(v5, v14);
v16 = v15;
if ( !v15 || !*v15 || !v15[1] )
break;
if ( !extract_field(v11, 0LL, v44) )
LABEL_73:
add_labels_cold();
sprintf(v13, "%s %s ", v44, (const char *)v45);
v17 = &v13[strlen(v13)];
if ( src[0] == 100 )
v17 = strncpy(v17, src, 3uLL) + 3;
v18 = stpcpy(v17, v16);
*v18 = 10;
v13 = v18 + 1;
v11 = next_line(v11);
if ( !*v11 )
goto LABEL_40;
}
v19 = *v11;
if ( *v11 )
{
if ( v19 != 10 )
{
while ( 1 )
{
++v11;
*v13++ = v19;
v19 = *v11;
if ( *v11 == 10 )
break;
if ( !v19 )
goto LABEL_72;
}
}
*v13 = 10;
v6 = *++v11;
++v13;
}
else
{
LABEL_72:
v6 = *v11;
}
}
LABEL_40:
*v13 = 0;
free(ptr);
v20 = strlen(v40);
v21 = (char *)malloc(2 * v20 + 100);
v41 = v21;
if ( *v40 )
{
v22 = v21;
v23 = v40;
while ( 1 )
{
if ( !extract_field(v23, 0LL, v44) )
goto LABEL_73;
v24 = (_BYTE *)hash_lookup(v5, v44);
v25 = v24;
if ( v24 )
{
if ( *v24 == 70 )
*v22++ = 10;
if ( a3 )
{
v42 = v24;
sprintf(v22, "%s\t", v44);
v32 = strlen(v22);
v25 = v42;
v22 += v32;
}
sprintf(v22, "%s:", v25);
}
else
{
v26 = v22;
if ( !a3 )
goto LABEL_50;
sprintf(v22, "%s\t", v44);
}
v26 = &v22[strlen(v22)];
LABEL_50:
if ( extract_field(v23, 1LL, v45) )
{
v27 = (unsigned __int8 *)hash_lookup(branch_hash_0, v45);
if ( !v27 )
v27 = v45;
sprintf(v26, "\t%s", v27);
v26 += strlen(v26);
}
for ( i = 2; extract_field(v23, i, src); ++i )
{
v29 = &aFl[3];
if ( i == 2 )
v29 = &aFl[2];
sprintf(v26, "%s%s", v29, src);
v26 += strlen(v26);
}
*v26 = 10;
v22 = v26 + 1;
v23 = next_line(v23);
if ( !*v23 )
goto LABEL_60;
}
}
v22 = v21;
LABEL_60:
*v22 = 0;
free(v40);
hash_free(v5);
v30 = strlen(v41);
return realloc(v41, v30 + 1);
}

canonical_decompiled_code:
void *__fastcall func2(void *ptr, __int64 a2, int a3)
{
__int64 v5; // r15
char v6; // r13
_BYTE *v7; // r12
_BYTE *v8; // r14
__int64 v9; // r12
char *v10; // rax
char *v11; // r12
size_t v12; // rax
char *v13; // rbx
char *v14; // rax
const char *v15; // rax
const char *v16; // r14
char *v17; // rdi
char *v18; // rax
char v19; // al
size_t v20; // rax
char *v21; // rax
char *v22; // r14
char *v23; // rbp
_BYTE *v24; // rax
_BYTE *v25; // r8
char *v26; // rbx
unsigned __int8 *v27; // rdx
unsigned int i; // er14
__int16 *v29; // rdx
size_t v30; // rax
size_t v32; // rax
__int16 *v33; // r13
char *v34; // rax
void *v35; // rsi
char **v36; // rbx
__int64 v37; // rdi
char *v38; // rdx
char *v40; // [rsp+8h] [rbp-1070h]
char *v41; // [rsp+10h] [rbp-1068h]
_BYTE *v42; // [rsp+18h] [rbp-1060h]
char s[32]; // [rsp+20h] [rbp-1058h] BYREF
char v44[1024]; // [rsp+40h] [rbp-1038h] BYREF
unsigned __int8 v45[1024]; // [rsp+440h] [rbp-C38h] BYREF
char src[1024]; // [rsp+840h] [rbp-838h] BYREF
char v47[1080]; // [rsp+C40h] [rbp-438h] BYREF

if ( !ptr )
return 0LL;
if ( !branch_hash_0 )
{
v35 = &unk_7E4;
v36 = off_990;
branch_hash_0 = hash_new();
v37 = branch_hash_0;
v38 = (char *)&unk_7E4;
while ( 1 )
{
hash_insert(v37, v35, v38);
if ( v36 == (char **)&unk_DF0 )
break;
v37 = branch_hash_0;
v38 = v36[1];
v36 += 2;
v35 = *(v36 - 2);
}
}
v5 = hash_new();
sprintf(s, "0x%lx", a2);
hash_insert(v5, s, "_main");
v6 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v7 = ptr;
do
{
if ( extract_field(v7, 1LL, v45)
&& hash_lookup(branch_hash_0, v45)
&& extract_field(v7, 2LL, src)
&& func1((const char *)v45, src)
&& !extract_field(v7, 3LL, v47) )
{
v33 = aFl;
if ( !func0(v45) )
v33 = &aFl[1];
v34 = func1((const char *)v45, src);
hash_insert(v5, v34, v33);
}
v7 = next_line(v7);
}
while ( *v7 );
v6 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v8 = ptr;
v9 = 0LL;
do
{
while ( 1 )
{
if ( extract_field(v8, 0LL, v44) )
{
v10 = (char *)hash_lookup(v5, v44);
if ( v10 )
{
if ( !v10[1] )
break;
}
}
v8 = next_line(v8);
if ( !*v8 )
goto LABEL_18;
}
sprintf(s, "%c%lu_", (unsigned int)*v10, v9++);
hash_remove(v5, v44);
hash_insert(v5, v44, s);
v8 = next_line(v8);
}
while ( *v8 );
LABEL_18:
v6 = *(_BYTE *)ptr;
}
}
v11 = (char *)ptr;
v12 = strlen((const char *)ptr);
v40 = (char *)malloc(2 * v12 + 100);
v13 = v40;
while ( v6 )
{
while ( extract_field(v11, 1LL, v45) )
{
if ( !hash_lookup(branch_hash_0, v45) )
break;
if ( !extract_field(v11, 2LL, src) )
break;
if ( !func1((const char *)v45, src) )
break;
if ( extract_field(v11, 3LL, v47) )
break;
v14 = func1((const char *)v45, src);
v15 = (const char *)hash_lookup(v5, v14);
v16 = v15;
if ( !v15 || !*v15 || !v15[1] )
break;
if ( !extract_field(v11, 0LL, v44) )
LABEL_73:
func3();
sprintf(v13, "%s %s ", v44, (const char *)v45);
v17 = &v13[strlen(v13)];
if ( src[0] == 100 )
v17 = strncpy(v17, src, 3uLL) + 3;
v18 = stpcpy(v17, v16);
*v18 = 10;
v13 = v18 + 1;
v11 = next_line(v11);
if ( !*v11 )
goto LABEL_40;
}
v19 = *v11;
if ( *v11 )
{
if ( v19 != 10 )
{
while ( 1 )
{
++v11;
*v13++ = v19;
v19 = *v11;
if ( *v11 == 10 )
break;
if ( !v19 )
goto LABEL_72;
}
}
*v13 = 10;
v6 = *++v11;
++v13;
}
else
{
LABEL_72:
v6 = *v11;
}
}
LABEL_40:
*v13 = 0;
free(ptr);
v20 = strlen(v40);
v21 = (char *)malloc(2 * v20 + 100);
v41 = v21;
if ( *v40 )
{
v22 = v21;
v23 = v40;
while ( 1 )
{
if ( !extract_field(v23, 0LL, v44) )
goto LABEL_73;
v24 = (_BYTE *)hash_lookup(v5, v44);
v25 = v24;
if ( v24 )
{
if ( *v24 == 70 )
*v22++ = 10;
if ( a3 )
{
v42 = v24;
sprintf(v22, "%s\t", v44);
v32 = strlen(v22);
v25 = v42;
v22 += v32;
}
sprintf(v22, "%s:", v25);
}
else
{
v26 = v22;
if ( !a3 )
goto LABEL_50;
sprintf(v22, "%s\t", v44);
}
v26 = &v22[strlen(v22)];
LABEL_50:
if ( extract_field(v23, 1LL, v45) )
{
v27 = (unsigned __int8 *)hash_lookup(branch_hash_0, v45);
if ( !v27 )
v27 = v45;
sprintf(v26, "\t%s", v27);
v26 += strlen(v26);
}
for ( i = 2; extract_field(v23, i, src); ++i )
{
v29 = &aFl[3];
if ( i == 2 )
v29 = &aFl[2];
sprintf(v26, "%s%s", v29, src);
v26 += strlen(v26);
}
*v26 = 10;
v22 = v26 + 1;
v23 = next_line(v23);
if ( !*v23 )
goto LABEL_60;
}
}
v22 = v21;
LABEL_60:
*v22 = 0;
free(v40);
hash_free(v5);
v30 = strlen(v41);
return realloc(v41, v30 + 1);
}

original_code:
char *
add_labels (char *code, unsigned long entry_point, int keep_addrs_p)
{
  static hash_table_t *branch_hash = ((void *)0);
  char *s, *d, *new, *final, buf[32];
  hash_table_t *label_hash;
  unsigned long label_num;
  char addr[1024], opcode[1024], operand[1024], junk[1024];
  const char *label;
  if (code == ((void *)0))
    return ((void *)0);
  if (branch_hash == ((void *)0))
    {
      int i;
      branch_hash = hash_new ();
      for (i = 0; i < sizeof branches / sizeof branches[0]; i++)
 hash_insert (branch_hash, branches[i].orig_name,
       branches[i].canon_name);
    }
  label_hash = hash_new ();
  sprintf (buf, "0x%lx", entry_point);
  hash_insert (label_hash, buf, "_main");
  for (s = code; *s != '\0'; s = next_line (s))
    {
      if (extract_field (s, 1, opcode)
   && hash_lookup (branch_hash, opcode)
   && extract_field (s, 2, operand)
   && extract_branch_target (opcode, operand)
   && !extract_field (s, 3, junk))
 {
   hash_insert (label_hash, extract_branch_target (opcode, operand),
         call_p (opcode) ? "F" : "L");
 }
    }
  for (s = code, label_num = 0; *s != '\0'; s = next_line (s))
    {
      if (extract_field (s, 0, addr))
 {
   const char *s = hash_lookup (label_hash, addr);
   if (s != ((void *)0) && s[1] == '\0')
     {
       sprintf (buf, "%c%lu_", s[0], label_num++);
       hash_remove (label_hash, addr);
       hash_insert (label_hash, addr, buf);
     }
 }
    }
  new = (char *)malloc (100 + strlen (code) * 2);
  for (s = code, d = new; *s != '\0'; )
    {
      int changed_p;
      changed_p = 0;
      if (extract_field (s, 1, opcode)
   && hash_lookup (branch_hash, opcode)
   && extract_field (s, 2, operand)
   && extract_branch_target (opcode, operand)
   && !extract_field (s, 3, junk))
 {
   label = hash_lookup (label_hash,
          extract_branch_target (opcode, operand));
   if (label != ((void *)0) && label[0] != '\0' && label[1] != '\0')
     {
       if (!extract_field (s, 0, addr))
  abort ();
       sprintf (d, "%s %s ", addr, opcode);
       d += strlen (d);
       if (operand[0] == 'd')
  {
    strncpy (d, operand, 3);
    d += 3;
  }
       strcpy (d, label);
       d += strlen (d);
       *d++ = '\n';
       s = next_line (s);
       changed_p = 1;
     }
 }
      if (!changed_p)
 {
   while (*s != '\n' && *s != '\0')
     *d++ = *s++;
   if (*s == '\n')
     *d++ = *s++;
 }
    }
  *d = '\0';
  free (code);
  final = (char *)malloc (100 + strlen (new) * 2);
  for (s = new, d = final; *s != '\0'; s = next_line (s))
    {
      int f;
      if (!extract_field (s, 0, addr))
 abort ();
      label = hash_lookup (label_hash, addr);
      if (label != ((void *)0) && label[0] == 'F')
 *d++ = '\n';
      if (keep_addrs_p)
 {
   sprintf (d, "%s\t", addr);
   d += strlen (d);
 }
      if (label != ((void *)0))
 {
   sprintf (d, "%s:", label);
   d += strlen (d);
 }
      if (extract_field (s, 1, opcode))
 {
   const char *canon_opcode;
   canon_opcode = hash_lookup (branch_hash, opcode);
   sprintf (d, "\t%s", canon_opcode ? canon_opcode : opcode);
   d += strlen (d);
 }
      for (f = 2; extract_field (s, f, operand); f++)
 {
   sprintf (d, "%s%s", (f == 2) ? "\t" : " ", operand);
   d += strlen (d);
 }
      *d++ = '\n';
    }
  *d = '\0';
  free (new);
  hash_free (label_hash);
  return (char *)realloc (final, strlen (final) + 1);
}

canonical_original_code:
char *add_labels(char *code, unsigned long entry_point, int keep_addrs_p)
{
  static struct hash_table_t *branch_hash = ((void *)0);
  char *s; char *d; char *new; char *final; char buf[32];
  struct hash_table_t *label_hash;
  unsigned long label_num;
  char addr[1024]; char opcode[1024]; char operand[1024]; char junk[1024];
  char *label;
  if (code == ((void *)0))
    return ((void *)0);
  if (branch_hash == ((void *)0))
    {
      int i;
      branch_hash = hash_new ();
      for (i = 0; i < sizeof branches / sizeof branches[0]; i++)
 hash_insert (branch_hash, branches[i].orig_name,
       branches[i].canon_name);
    }
  label_hash = hash_new ();
  sprintf (buf, "0x%lx", entry_point);
  hash_insert (label_hash, buf, "_main");
  for (s = code; *s != '\0'; s = next_line (s))
    {
      if (extract_field (s, 1, opcode)
   && hash_lookup (branch_hash, opcode)
   && extract_field (s, 2, operand)
   && extract_branch_target (opcode, operand)
   && !extract_field (s, 3, junk))
 {
   hash_insert (label_hash, extract_branch_target (opcode, operand),
         call_p (opcode) ? "F" : "L");
 }
    }
  for (s = code, label_num = 0; *s != '\0'; s = next_line (s))
    {
      if (extract_field (s, 0, addr))
 {
   char *s = hash_lookup (label_hash, addr);
   if (s != ((void *)0) && s[1] == '\0')
     {
       sprintf (buf, "%c%lu_", s[0], label_num++);
       hash_remove (label_hash, addr);
       hash_insert (label_hash, addr, buf);
     }
 }
    }
  new = (char *)malloc (100 + strlen (code) * 2);
  for (s = code, d = new; *s != '\0'; )
    {
      int changed_p;
      changed_p = 0;
      if (extract_field (s, 1, opcode)
   && hash_lookup (branch_hash, opcode)
   && extract_field (s, 2, operand)
   && extract_branch_target (opcode, operand)
   && !extract_field (s, 3, junk))
 {
   label = hash_lookup (label_hash,
          extract_branch_target (opcode, operand));
   if (label != ((void *)0) && label[0] != '\0' && label[1] != '\0')
     {
       if (!extract_field (s, 0, addr))
  abort ();
       sprintf (d, "%s %s ", addr, opcode);
       d += strlen (d);
       if (operand[0] == 'd')
  {
    strncpy (d, operand, 3);
    d += 3;
  }
       strcpy (d, label);
       d += strlen (d);
       *d++ = '\n';
       s = next_line (s);
       changed_p = 1;
     }
 }
      if (!changed_p)
 {
   while (*s != '\n' && *s != '\0')
     *d++ = *s++;
   if (*s == '\n')
     *d++ = *s++;
 }
    }
  *d = '\0';
  free (code);
  final = (char *)malloc (100 + strlen (new) * 2);
  for (s = new, d = final; *s != '\0'; s = next_line (s))
    {
      int f;
      if (!extract_field (s, 0, addr))
 abort ();
      label = hash_lookup (label_hash, addr);
      if (label != ((void *)0) && label[0] == 'F')
 *d++ = '\n';
      if (keep_addrs_p)
 {
   sprintf (d, "%s\t", addr);
   d += strlen (d);
 }
      if (label != ((void *)0))
 {
   sprintf (d, "%s:", label);
   d += strlen (d);
 }
      if (extract_field (s, 1, opcode))
 {
   char *canon_opcode;
   canon_opcode = hash_lookup (branch_hash, opcode);
   sprintf (d, "\t%s", canon_opcode ? canon_opcode : opcode);
   d += strlen (d);
 }
      for (f = 2; extract_field (s, f, operand); f++)
 {
   sprintf (d, "%s%s", (f == 2) ? "\t" : " ", operand);
   d += strlen (d);
 }
      *d++ = '\n';
    }
  *d = '\0';
  free (new);
  hash_free (label_hash);
  return (char *)realloc (final, strlen (final) + 1);
}

variable_types:
code
char *

variable_types: struct hash_table_t { struct _hash_elt_t { struct _hash_elt_t *next; char *key; char *value; } *bucket[-1]; } *

variable_types:
s
char *

variable_types:
d
char *

variable_types:
new
char *

variable_types:
final
char *

variable_types:
buf
char [32]

variable_types:
addr
char [1024]

variable_types:
opcode
char [1024]

variable_types:
operand
char [1024]

variable_types:
junk
char [1024]

variable_types:
label
char *

variable_types: i int

variable_types: f int

user_defined_types: struct hash_table_t { struct _hash_elt_t *bucket[-1]; }


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
__int16 v1; // dx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
++a1;
LOWORD(result) = v1 + 33 * result;
v1 = (char)*a1;
}
while ( *a1 );
result &= 0x7FFu;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int16 v1; // dx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
++a1;
LOWORD(result) = v1 + 33 * result;
v1 = (char)*a1;
}
while ( *a1 );
result &= 0x7FFu;
}
return result;
}

original_code:
static inline unsigned
hash (const char *s)
{
  unsigned n;
  for (n = 0; *s; s++)
    n = (n * 33) + *s;
  return n % (1UL << 11);
}

canonical_original_code:
static inline unsigned int hash(char *s)
{
  unsigned int n;
  for (n = 0; *s; s++)
    n = (n * 33) + *s;
  return n % (1UL << 11);
}

variable_types:
n
unsigned int

return_type: unsigned int


decompiled_code:
void *hash_new()
{
return calloc(0x4000uLL, 1uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(0x4000uLL, 1uLL);
}

original_code:
hash_table_t *
hash_new ()
{
  hash_table_t *h;
  h = (hash_table_t *)malloc (sizeof *h);
  memset (h, 0, sizeof *h);
  return h;
}

canonical_original_code:
struct hash_table_t *hash_new()
{
  struct hash_table_t *h;
  h = (struct hash_table_t *)malloc (sizeof *h);
  memset (h, 0, sizeof *h);
  return h;
}

return_type: struct hash_table_t { struct _hash_elt_t { struct _hash_elt_t *next; char *key; char *value; } *bucket[-1]; } *


decompiled_code:
void __fastcall hash_free(void *ptr)
{
void ***v1; // r12
void **v2; // rbx
void **v3; // rbp

v1 = (void ***)ptr;
do
{
v2 = *v1;
while ( v2 )
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3[2]);
free(v3);
}
++v1;
}
while ( v1 != (void ***)((char *)ptr + 0x4000) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void ***v1; // r12
void **v2; // rbx
void **v3; // rbp

v1 = (void ***)ptr;
do
{
v2 = *v1;
while ( v2 )
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3[2]);
free(v3);
}
++v1;
}
while ( v1 != (void ***)((char *)ptr + 0x4000) );
free(ptr);
}

original_code:
void
hash_free (hash_table_t *h)
{
  hash_elt_t *e, *next;
  int i;
  for (i = 0; i < (1UL << 11); i++)
    {
      for (e = h->bucket[i]; e != ((void *)0); e = next)
 {
   next = e->next;
   free (e->key);
   free (e->value);
   free (e);
 }
    }
  free (h);
}

canonical_original_code:
void hash_free(struct hash_table_t *h)
{
  struct _hash_elt_t *e; struct _hash_elt_t *next;
  int i;
  for (i = 0; i < (1UL << 11); i++)
    {
      for (e = h->bucket[i]; e != ((void *)0); e = next)
 {
   next = e->next;
   free (e->key);
   free (e->value);
   free (e);
 }
    }
  free (h);
}

variable_types: struct _hash_elt_t { struct _hash_elt_t *next; char *key; char *value; } *


decompiled_code:
void __fastcall hash_remove(__int64 a1, char *a2)
{
unsigned int v2; // eax
__int64 v3; // r8
_QWORD *v4; // rbx
_QWORD **v5; // r13
char *v6; // rbp
_QWORD **v7; // rdi

v2 = hash(a2);
v4 = *(_QWORD **)(v3 + 8LL * v2);
v5 = (_QWORD **)(v3 + 8LL * v2);
if ( v4 )
{
while ( 1 )
{
v6 = (char *)v4[1];
if ( !strcmp(v6, a2) )
break;
v5 = (_QWORD **)v4;
v4 = (_QWORD *)*v4;
if ( !v4 )
goto LABEL_6;
}
free(v6);
free((void *)(*v5)[2]);
v7 = (_QWORD **)*v5;
*v5 = (_QWORD *)**v5;
free(v7);
}
else
{
LABEL_6:
fwrite("Failed to remove elt from hash table!\n", 1uLL, 0x26uLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, char *a2)
{
unsigned int v2; // eax
__int64 v3; // r8
_QWORD *v4; // rbx
_QWORD **v5; // r13
char *v6; // rbp
_QWORD **v7; // rdi

v2 = func0(a2);
v4 = *(_QWORD **)(v3 + 8LL * v2);
v5 = (_QWORD **)(v3 + 8LL * v2);
if ( v4 )
{
while ( 1 )
{
v6 = (char *)v4[1];
if ( !strcmp(v6, a2) )
break;
v5 = (_QWORD **)v4;
v4 = (_QWORD *)*v4;
if ( !v4 )
goto LABEL_6;
}
free(v6);
free((void *)(*v5)[2]);
v7 = (_QWORD **)*v5;
*v5 = (_QWORD *)**v5;
free(v7);
}
else
{
LABEL_6:
fwrite("Failed to remove elt from hash table!\n", 1uLL, 0x26uLL, stderr);
}
}

original_code:
void
hash_remove (hash_table_t *h, const char *key)
{
  hash_elt_t **e;
  for (e = &h->bucket[hash (key)]; (*e) != ((void *)0); e = &(*e)->next)
    {
      if (!strcmp ((*e)->key, key))
 {
   hash_elt_t *old;
   free ((*e)->key);
   free ((*e)->value);
   old = *e;
   *e = (*e)->next;
   free (old);
   return;
 }
    }
  fprintf (stderr, "Failed to remove elt from hash table!\n");
}

canonical_original_code:
void hash_remove(struct hash_table_t *h, char *key)
{
  struct _hash_elt_t **e;
  for (e = &h->bucket[hash (key)]; (*e) != ((void *)0); e = &(*e)->next)
    {
      if (!strcmp ((*e)->key, key))
 {
   struct _hash_elt_t *old;
   free ((*e)->key);
   free ((*e)->value);
   old = *e;
   *e = (*e)->next;
   free (old);
   return;
 }
    }
  fprintf (stderr, "Failed to remove elt from hash table!\n");
}

variable_types:
key
char *

variable_types: struct _hash_elt_t { struct _hash_elt_t *next; char *key; char *value; } **


repo: cugfeng/Browser

original_code:
NPError
NPP_SetWindow(NPP instance, NPWindow* window) {
  InstanceData* instanceData = (InstanceData*)(instance->pdata);
  instanceData->window = *window;
  return (0 + 0);
}

canonical_original_code:
short NPP_SetWindow(struct _NPP *instance, struct _NPWindow *window) {
  struct InstanceData *instanceData = (InstanceData*)(instance->pdata);
  instanceData->window = *window;
  return (0 + 0);
}

variable_types: struct _NPWindow { void *window; int x; int y; unsigned int width; unsigned int height; struct _NPRect { unsigned short top; unsigned short left; unsigned short bottom; unsigned short right; } clipRect; void *ws_info; enum NPWindowType { NPWindowTypeWindow=1, NPWindowTypeDrawable=2 } type; } *

variable_types: struct InstanceData { struct _NPP { void *pdata; void *ndata; } *npp; struct _NPWindow { void *window; int x; int y; unsigned int width; unsigned int height; struct _NPRect { unsigned short top; unsigned short left; unsigned short bottom; unsigned short right; } clipRect; void *ws_info; enum NPWindowType { NPWindowTypeWindow=1, NPWindowTypeDrawable=2 } type; } window; } *

user_defined_types: struct _NPWindow { void *window; int x; int y; unsigned int width; unsigned int height; struct _NPRect clipRect; void *ws_info; enum NPWindowType type; }

user_defined_types: struct InstanceData { struct _NPP *npp; struct _NPWindow window; }


decompiled_code:
__int64 NPP_NewStream()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code:
NPError
NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype) {
  return (0 + 1);
}

canonical_original_code:
short NPP_NewStream(struct _NPP *instance, char *type, struct _NPStream *stream, unsigned char seekable, unsigned short *stype) {
  return (0 + 1);
}

variable_types: struct _NPP { void *pdata; void *ndata; } *

variable_types:
type
char *

variable_types: struct _NPStream { void *pdata; void *ndata; char *url; unsigned int end; unsigned int lastmodified; void *notifyData; char *headers; } *

variable_types:
seekable
unsigned char

variable_types:
stype
unsigned short *


decompiled_code:
__int64 NPP_DestroyStream()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 1LL;
}

original_code:
NPError
NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) {
  return (0 + 1);
}

canonical_original_code:
short NPP_DestroyStream(struct _NPP *instance, struct _NPStream *stream, short reason) {
  return (0 + 1);
}

variable_types: reason short

user_defined_types: struct _NPP { void *pdata; void *ndata; }

user_defined_types: struct _NPStream { void *pdata; void *ndata; char *url; unsigned int end; unsigned int lastmodified; void *notifyData; char *headers; }


decompiled_code:
__int64 NPP_WriteReady()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
int32_t
NPP_WriteReady(NPP instance, NPStream* stream) {
  return 0;
}

canonical_original_code:
int NPP_WriteReady(struct _NPP *instance, struct _NPStream *stream) {
  return 0;
}


decompiled_code:
__int64 NPP_Write()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0LL;
}

original_code:
int32_t
NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer) {
  return 0;
}

canonical_original_code:
int NPP_Write(struct _NPP *instance, struct _NPStream *stream, int offset, int len, void *buffer) {
  return 0;
}

variable_types: offset int

variable_types: len int

variable_types:
buffer
void *


decompiled_code:
void NPP_StreamAsFile()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void
NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) {
}

canonical_original_code:
void NPP_StreamAsFile(struct _NPP *instance, struct _NPStream *stream, char *fname) {
}

variable_types:
fname
char *


decompiled_code:
void NPP_Print()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void
NPP_Print(NPP instance, NPPrint* platformPrint) {
}

canonical_original_code:
void NPP_Print(struct _NPP *instance, struct _NPPrint *platformPrint) {
}

variable_types: struct _NPPrint { unsigned short mode; union { struct _NPFullPrint { unsigned char pluginPrinted; unsigned char printOne; void *platformPrint; } fullPrint; struct _NPEmbedPrint { struct _NPWindow { void *window; int x; int y; unsigned int width; unsigned int height; struct _NPRect { unsigned short top; unsigned short left; unsigned short bottom; unsigned short right; } clipRect; void *ws_info; enum NPWindowType { NPWindowTypeWindow=1, NPWindowTypeDrawable=2 } type; } window; void *platformPrint; } embedPrint; } print; } *

user_defined_types: struct _NPPrint { unsigned short mode; union { struct _NPFullPrint fullPrint; struct _NPEmbedPrint embedPrint; } print; }

user_defined_types: struct _NPEmbedPrint { struct _NPWindow window; void *platformPrint; }


decompiled_code:
void NPP_URLNotify()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void
NPP_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData) {
}

canonical_original_code:
void NPP_URLNotify(struct _NPP *instance, char *URL, short reason, void *notifyData) {
}

variable_types:
URL
char *

variable_types:
notifyData
void *


decompiled_code:
__int64 __fastcall NPP_New(__int64 a1, _QWORD *a2)
{
char *v2; // rax
__int64 result; // rax
char v4[9]; // [rsp+Fh] [rbp-9h] BYREF

v4[0] = 0;
(*(void (__fastcall **)(_QWORD *, __int64, char *))(sBrowserFuncs + 136))(a2, 17LL, v4);
if ( v4[0] )
{
(*(void (__fastcall **)(_QWORD *, __int64, _QWORD))(sBrowserFuncs + 144))(a2, 3LL, 0LL);
v2 = (char *)malloc(0x38uLL);
if ( v2 )
{
*(_QWORD *)v2 = a2;
*a2 = v2;
*(_OWORD *)(v2 + 8) = 0LL;
*(_OWORD *)(v2 + 24) = 0LL;
*(_OWORD *)(v2 + 40) = 0LL;
result = 0LL;
}
else
{
result = 5LL;
}
}
else
{
puts("Windowless mode not supported by the browser");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _QWORD *a2)
{
char *v2; // rax
__int64 result; // rax
char v4[9]; // [rsp+Fh] [rbp-9h] BYREF

v4[0] = 0;
(*(void (__fastcall **)(_QWORD *, __int64, char *))(sBrowserFuncs + 136))(a2, 17LL, v4);
if ( v4[0] )
{
(*(void (__fastcall **)(_QWORD *, __int64, _QWORD))(sBrowserFuncs + 144))(a2, 3LL, 0LL);
v2 = (char *)malloc(0x38uLL);
if ( v2 )
{
*(_QWORD *)v2 = a2;
*a2 = v2;
*(_OWORD *)(v2 + 8) = 0LL;
*(_OWORD *)(v2 + 24) = 0LL;
*(_OWORD *)(v2 + 40) = 0LL;
result = 0LL;
}
else
{
result = 5LL;
}
}
else
{
puts("Windowless mode not supported by the browser");
result = 1LL;
}
return result;
}

original_code:
NPError
NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved) {
  NPBool browserSupportsWindowless = 0;
  sBrowserFuncs->getvalue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
  if (!browserSupportsWindowless) {
    printf("Windowless mode not supported by the browser\n");
    return (0 + 1);
  }
  sBrowserFuncs->setvalue(instance, NPPVpluginWindowBool, (void*)0);
  InstanceData* instanceData = (InstanceData*)malloc(sizeof(InstanceData));
  if (!instanceData)
    return (0 + 5);
  memset(instanceData, 0, sizeof(InstanceData));
  instanceData->npp = instance;
  instance->pdata = instanceData;
  return (0 + 0);
}

canonical_original_code:
short NPP_New(char *pluginType, struct _NPP *instance, unsigned short mode, short argc, char *argn[], char *argv[], struct _NPSavedData *saved) {
  unsigned char browserSupportsWindowless = 0;
  sBrowserFuncs->getvalue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
  if (!browserSupportsWindowless) {
    printf("Windowless mode not supported by the browser\n");
    return (0 + 1);
  }
  sBrowserFuncs->setvalue(instance, NPPVpluginWindowBool, (void *)0);
  struct InstanceData *instanceData = (InstanceData*)malloc(sizeof(InstanceData));
  if (!instanceData)
    return (0 + 5);
  memset(instanceData, 0, sizeof(InstanceData));
  instanceData->npp = instance;
  instance->pdata = instanceData;
  return (0 + 0);
}

variable_types:
pluginType
char *

variable_types:
mode
unsigned short

variable_types: argc short

variable_types:
argn
char *[]

variable_types:
argv
char *[]

variable_types: struct _NPSavedData { int len; void *buf; } *

variable_types:
browserSupportsWindowless
unsigned char

user_defined_types: struct _NPRect { unsigned short top; unsigned short left; unsigned short bottom; unsigned short right; }

user_defined_types: enum NPWindowType { NPWindowTypeWindow=1, NPWindowTypeDrawable=2 }


decompiled_code:
__int64 __fastcall NPP_Destroy(void **a1)
{
free(*a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(void **a1)
{
free(*a1);
return 0LL;
}

original_code:
NPError
NPP_Destroy(NPP instance, NPSavedData** save) {
  InstanceData* instanceData = (InstanceData*)(instance->pdata);
  free(instanceData);
  return (0 + 0);
}

canonical_original_code:
short NPP_Destroy(struct _NPP *instance, struct _NPSavedData **save) {
  struct InstanceData *instanceData = (InstanceData*)(instance->pdata);
  free(instanceData);
  return (0 + 0);
}

variable_types: struct _NPSavedData { int len; void *buf; } **

variable_types: struct InstanceData { struct _NPP { void *pdata; void *ndata; } *npp; struct _NPWindow { void *window; int x; int y; unsigned int width; unsigned int height; struct _NPRect { unsigned short top; unsigned short left; unsigned short bottom; unsigned short right; } clipRect; void *ws_info; enum NPWindowType { NPWindowTypeWindow=1, NPWindowTypeDrawable=2 } type; } window; } *


decompiled_code:
// attributes: thunk
__int64 NPP_SetValue()
{
return NPP_GetValue_localalias();
}

canonical_decompiled_code:
__int64 func17()
{
return func14();
}

original_code:
NPError
NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
  return (0 + 1);
}

canonical_original_code:
short NPP_SetValue(struct _NPP *instance, enum NPNVariable variable, void *value) {
  return (0 + 1);
}

variable_types: struct _NPP { void *pdata; void *ndata; } *

variable_types: enum NPNVariable { NPNVxDisplay=1, NPNVxtAppContext=2, NPNVnetscapeWindow=3, NPNVjavascriptEnabledBool=4, NPNVasdEnabledBool=5, NPNVisOfflineBool=6, NPNVserviceManager=expr, NPNVDOMElement=expr, NPNVDOMWindow=expr, NPNVToolkit=expr, NPNVSupportsXEmbedBool=14, NPNVWindowNPObject=15, NPNVPluginElementNPObject=16, NPNVSupportsWindowless=17, NPNVprivateModeBool=18, NPNVsupportsAdvancedKeyHandling=21, NPNVdocumentOrigin=22, NPNVpluginDrawingModel=1000, NPNVsupportsAsyncBitmapSurfaceBool=2007 }

variable_types:
value
void *