decompiled_code:
__int64 __fastcall adc_chunk_offset(char *a1)
{
int v1; // eax
__int16 v2; // dx
__int64 v3; // rcx

v1 = adc_chunk_type(*a1);
if ( v1 == 2 )
return ((v2 << 8) & 0x300) + (unsigned int)*(unsigned __int8 *)(v3 + 1);
if ( v1 == 3 )
return *(unsigned __int8 *)(v3 + 2) + (*(unsigned __int8 *)(v3 + 1) << 8);
return (unsigned int)-(v1 != 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
int v1; // eax
__int16 v2; // dx
__int64 v3; // rcx

v1 = func0(*a1);
if ( v1 == 2 )
return ((v2 << 8) & 0x300) + (unsigned int)*(unsigned __int8 *)(v3 + 1);
if ( v1 == 3 )
return *(unsigned __int8 *)(v3 + 2) + (*(unsigned __int8 *)(v3 + 1) << 8);
return (unsigned int)-(v1 != 1);
}

original_code:
int adc_chunk_offset(unsigned char *chunk_start)
{
 unsigned char *c = chunk_start;
 switch (adc_chunk_type(*c)) {
 case 0x01:
  return 0;
 case 0x02:
  return ((((unsigned char)*c & 0x03)) << 8) + (unsigned char)*(c + 1);
 case 0x03:
  return (((unsigned char)*(c + 1)) << 8) + (unsigned char)*(c + 2);
 }
 return -1;
}

variable_types:
c
unsigned char *


original_code:
int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, int *bytes_written)
{
 if (in_size == 0)
  return 0;
 short output_full = 0;
 unsigned char *inp = input;
 unsigned char *outp = output;
 int chunk_type;
 int chunk_size;
 int offset;
 int i;
 while (inp - input < in_size) {
  chunk_type = adc_chunk_type(*inp);
  switch (chunk_type) {
  case 0x01:
   chunk_size = adc_chunk_size(*inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   memcpy(outp, inp + 1, chunk_size);
   inp += chunk_size + 1;
   outp += chunk_size;
   break;
  case 0x02:
   chunk_size = adc_chunk_size(*inp);
   offset = adc_chunk_offset(inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   if (offset == 0) {
    memset(outp, *(outp - offset - 1), chunk_size);
    outp += chunk_size;
    inp += 2;
   } else {
    for (i = 0; i < chunk_size; i++) {
     memcpy(outp, outp - offset - 1, 1);
     outp++;
    }
    inp += 2;
   }
   break;
  case 0x03:
   chunk_size = adc_chunk_size(*inp);
   offset = adc_chunk_offset(inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   if (offset == 0) {
    memset(outp, *(outp - offset - 1), chunk_size);
    outp += chunk_size;
    inp += 3;
   } else {
    for (i = 0; i < chunk_size; i++) {
     memcpy(outp, outp - offset - 1, 1);
     outp++;
    }
    inp += 3;
   }
   break;
  }
  if (output_full)
   break;
 }
 *bytes_written = outp - output;
 return inp - input;
}

variable_types:
input
unsigned char *

variable_types:
output
unsigned char *

variable_types:
inp
unsigned char *

variable_types:
outp
unsigned char *

variable_types: offset int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall is_base64(unsigned __int8 a1)
{
unsigned __int64 v1; // r8

LODWORD(v1) = 1;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
{
LODWORD(v1) = 0;
if ( a1 <= 0x3Du )
v1 = (0x23FF880000000000uLL >> a1) & 1;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
unsigned __int64 v1; // r8

LODWORD(v1) = 1;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
{
LODWORD(v1) = 0;
if ( a1 <= 0x3Du )
v1 = (0x23FF880000000000uLL >> a1) & 1;
}
return (unsigned int)v1;
}

variable_types: c char

return_type: short


decompiled_code:
unsigned __int8 *__fastcall cleanup_base64(unsigned __int8 *a1, int a2)
{
unsigned __int8 v3; // di
__int16 v4; // ax
unsigned __int8 *v5; // r9
unsigned __int8 *result; // rax
unsigned __int8 *v7; // r10

if ( a2 )
{
do
{
v3 = *a1;
v4 = is_base64(*a1);
*v5 = v3;
result = &v5[-(v4 == 0) + 1];
}
while ( v7 != a1 );
*result = 0;
}
else
{
result = a1;
*a1 = 0;
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(unsigned __int8 *a1, int a2)
{
unsigned __int8 v3; // di
__int16 v4; // ax
unsigned __int8 *v5; // r9
unsigned __int8 *result; // rax
unsigned __int8 *v7; // r10

if ( a2 )
{
do
{
v3 = *a1;
v4 = func0(*a1);
*v5 = v3;
result = &v5[-(v4 == 0) + 1];
}
while ( v7 != a1 );
*result = 0;
}
else
{
result = a1;
*a1 = 0;
}
return result;
}

original_code:
void cleanup_base64(char *inp, const unsigned int size)
{
 char *tinp1, *tinp2;
 unsigned int i;
 tinp1 = inp;
 tinp2 = inp;
 for (i = 0; i < size; i++) {
  if (is_base64(*tinp2)) {
   *tinp1++ = *tinp2++;
  } else {
   *tinp1 = *tinp2++;
  }
 }
 *(tinp1) = 0;
}

canonical_original_code:
void cleanup_base64(char *inp, unsigned int size)
{
 char *tinp1; char *tinp2;
 unsigned int i;
 tinp1 = inp;
 tinp2 = inp;
 for (i = 0; i < size; i++) {
  if (is_base64(*tinp2)) {
   *tinp1++ = *tinp2++;
  } else {
   *tinp1 = *tinp2++;
  }
 }
 *(tinp1) = 0;
}

variable_types:
inp
char *

variable_types:
size
unsigned int

variable_types:
i
unsigned int

return_type: void


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

result = (unsigned int)(a1 - 65);
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 71);
}
else if ( (unsigned __int8)(a1 - 48) <= 9u )
{
result = (unsigned int)(a1 + 4);
}
else if ( (_BYTE)a1 == 43 )
{
result = 62LL;
}
else
{
result = 63LL;
if ( (_BYTE)a1 == 61 )
result = 0LL;
}
}
return result;
}

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

result = (unsigned int)(a1 - 65);
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 71);
}
else if ( (unsigned __int8)(a1 - 48) <= 9u )
{
result = (unsigned int)(a1 + 4);
}
else if ( (_BYTE)a1 == 43 )
{
result = 62LL;
}
else
{
result = 63LL;
if ( (_BYTE)a1 == 61 )
result = 0LL;
}
}
return result;
}

original_code:
unsigned char decode_base64_char(const char c)
{
 if (c >= 'A' && c <= 'Z')
  return c - 'A';
 if (c >= 'a' && c <= 'z')
  return c - 'a' + 26;
 if (c >= '0' && c <= '9')
  return c - '0' + 52;
 if (c == '+')
  return 62;
 if (c == '=')
  return 0;
 return 63;
}

canonical_original_code:
unsigned char decode_base64_char(char c)
{
 if (c >= 'A' && c <= 'Z')
  return c - 'A';
 if (c >= 'a' && c <= 'z')
  return c - 'a' + 26;
 if (c >= '0' && c <= '9')
  return c - '0' + 52;
 if (c == '+')
  return 62;
 if (c == '=')
  return 0;
 return 63;
}

return_type: unsigned char


original_code:
void decode_base64(const char *inp, unsigned int isize,
          char *out, unsigned int *osize)
{
 char *tinp = (char *)inp;
 char *tout;
 unsigned int i;
 *osize = isize / 4 * 3;
 if (inp != out) {
  tout = (char *)malloc(*osize);
  out = tout;
 } else {
  tout = tinp;
 }
 for (i = 0; i < (isize >> 2); i++) {
  *tout = decode_base64_char(*tinp++) << 2;
  *tout++ |= decode_base64_char(*tinp) >> 4;
  *tout = decode_base64_char(*tinp++) << 4;
  *tout++ |= decode_base64_char(*tinp) >> 2;
  *tout = decode_base64_char(*tinp++) << 6;
  *tout++ |= decode_base64_char(*tinp++);
 }
 if (*(tinp - 1) == '=')
  (*osize)--;
 if (*(tinp - 2) == '=')
  (*osize)--;
}

canonical_original_code:
void decode_base64(char *inp, unsigned int isize, char *out, unsigned int *osize)
{
 char *tinp = (char *)inp;
 char *tout;
 unsigned int i;
 *osize = isize / 4 * 3;
 if (inp != out) {
  tout = (char *)malloc(*osize);
  out = tout;
 } else {
  tout = tinp;
 }
 for (i = 0; i < (isize >> 2); i++) {
  *tout = decode_base64_char(*tinp++) << 2;
  *tout++ |= decode_base64_char(*tinp) >> 4;
  *tout = decode_base64_char(*tinp++) << 4;
  *tout++ |= decode_base64_char(*tinp) >> 2;
  *tout = decode_base64_char(*tinp++) << 6;
  *tout++ |= decode_base64_char(*tinp++);
 }
 if (*(tinp - 1) == '=')
  (*osize)--;
 if (*(tinp - 2) == '=')
  (*osize)--;
}

variable_types:
isize
unsigned int

variable_types:
out
char *

variable_types:
osize
unsigned int *

variable_types:
tinp
char *

variable_types:
tout
char *


repo: lemenkov/grubby

decompiled_code:
__int64 open_log()
{
unsigned int v0; // er12
int v2; // eax
int *v3; // rax
int v4; // edi
int v5; // ebp
int *v6; // rbx

v0 = 0;
if ( log_fd >= 0 )
return v0;
v2 = open("/var/log/grubby", 525378, 384LL);
log_fd = v2;
v0 = v2;
if ( v2 < 0 )
return v0;
f = (__int64)fdopen(v2, "a+");
if ( !f )
{
v3 = _errno_location();
v4 = v0;
v0 = -1;
v5 = *v3;
v6 = v3;
close(v4);
log_fd = -1;
*v6 = v5;
return v0;
}
setbuf((FILE *)f, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
int v2; // eax
int *v3; // rax
int v4; // edi
int v5; // ebp
int *v6; // rbx

v0 = 0;
if ( log_fd >= 0 )
return v0;
v2 = open("/var/log/grubby", 525378, 384LL);
log_fd = v2;
v0 = v2;
if ( v2 < 0 )
return v0;
f = (__int64)fdopen(v2, "a+");
if ( !f )
{
v3 = _errno_location();
v4 = v0;
v0 = -1;
v5 = *v3;
v6 = v3;
close(v4);
log_fd = -1;
*v6 = v5;
return v0;
}
setbuf((FILE *)f, 0LL);
return 0LL;
}

original_code:
static int
open_log(void)
{
 if (log_fd > -1)
  return 0;
 log_fd = open("/var/log/grubby", 02|02000|0100|02000000, 0600);
 if (log_fd < 0)
  return log_fd;
 f = fdopen(log_fd, "a+");
 if (f == ((void *)0)) {
  typeof((*__errno_location ())) saved_errno = (*__errno_location ());
  close(log_fd);
  log_fd = -1;
  (*__errno_location ()) = saved_errno;
  return -1;
 }
 setbuf(f, ((void *)0));
 return 0;
}

canonical_original_code:
static int open_log()
{
 if (log_fd > -1)
  return 0;
 log_fd = open("/var/log/grubby", 02|02000|0100|02000000, 0600);
 if (log_fd < 0)
  return log_fd;
 f = fdopen(log_fd, "a+");
 if (f == ((void *)0)) {
  typeof((*__errno_location ())) saved_errno = (*__errno_location ());
  close(log_fd);
  log_fd = -1;
  (*__errno_location ()) = saved_errno;
  return -1;
 }
 setbuf(f, ((void *)0));
 return 0;
}


check

repo: lennartblanco/zdc

decompiled_code:
int __fastcall check(const char *a1)
{
int result; // eax

result = printf("%s [ok]\n", a1);
++passed;
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = printf("%s [ok]\n", a1);
++passed;
return result;
}

original_code:
void check(char *function_called)
{
    printf("%s [ok]\n", function_called);
    passed += 1;
}


decompiled_code:
int __fastcall check_cond(const char *a1, char a2)
{
int result; // eax

printf("%s ", a1);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, char a2)
{
int result; // eax

printf("%s ", a1);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void check_cond(char *function_called, _Bool cond)
{
    printf("%s ", function_called);
    if (cond)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
int __fastcall check_int(const char *a1, unsigned int a2, int a3)
{
int result; // eax

printf("%s = %d", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, unsigned int a2, int a3)
{
int result; // eax

printf("%s = %d", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_int(char *function_called, int res, int expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res int


decompiled_code:
int __fastcall check_uint(const char *a1, unsigned int a2, int a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, unsigned int a2, int a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_uint(char *function_called, unsigned res, unsigned expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

canonical_original_code:
void check_uint(char *function_called, unsigned int res, unsigned int expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned int


decompiled_code:
int __fastcall check_short(const char *a1, __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_short(char *function_called, short res, short expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res short


decompiled_code:
int __fastcall check_ushort(const char *a1, unsigned __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_ushort(char *function_called,
             unsigned short res,
             unsigned short expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned short


decompiled_code:
int __fastcall check_byte(const char *a1, char a2, char a3)
{
int result; // eax

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, char a2, char a3)
{
int result; // eax

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_byte(char *function_called, char res, char expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res char


decompiled_code:
int __fastcall check_ubyte(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_ubyte(char *function_called,
            unsigned char res,
            unsigned char expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned char


decompiled_code:
int __fastcall check_bool(__int64 a1, char a2, char a3)
{
const char *v4; // rdx
int result; // eax

v4 = "true";
if ( !a2 )
v4 = "false";
printf("%s = %s", a1, v4);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, char a2, char a3)
{
const char *v4; // rdx
int result; // eax

v4 = "true";
if ( !a2 )
v4 = "false";
printf("%s = %s", a1, v4);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_bool(char *function_called, _Bool res, _Bool expected_res)
{
    printf("%s = %s", function_called, res ? "true" : "false");
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
int __fastcall check_char(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = ", a1);
if ( (a2 & 0x80u) != 0 || iscntrl(a2) )
{
printf("%u", a2);
if ( a2 != a3 )
{
LABEL_4:
result = puts(" unexpected result!");
++failed;
return result;
}
}
else
{
printf("'%c'", a2);
if ( a2 != a3 )
goto LABEL_4;
}
result = puts(" [ok]");
++passed;
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = ", a1);
if ( (a2 & 0x80u) != 0 || iscntrl(a2) )
{
printf("%u", a2);
if ( a2 != a3 )
{
LABEL_4:
result = puts(" unexpected result!");
++failed;
return result;
}
}
else
{
printf("'%c'", a2);
if ( a2 != a3 )
goto LABEL_4;
}
result = puts(" [ok]");
++passed;
return result;
}

original_code:
void
check_char(char *function_called,
           unsigned char res,
           unsigned char expected_res)
{
    printf("%s = ", function_called);
    if (isascii(res) != 0 && iscntrl(res) == 0)
    {
      printf("'%c'", res);
    }
    else
    {
      printf("%u", res);
    }
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
int __fastcall check_pointer(const char *a1, const void *a2, const void *a3)
{
int result; // eax

printf("%s = %p", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, const void *a2, const void *a3)
{
int result; // eax

printf("%s = %p", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_pointer(char *function_called, void *res, void *expected_res)
{
    printf("%s = %p", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
void *


decompiled_code:
int __fastcall check_non_null_ptr(const char *a1, const void *a2)
{
int result; // eax

printf("%s = %p", a1, a2);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, const void *a2)
{
int result; // eax

printf("%s = %p", a1, a2);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_non_null_ptr(char *function_called, void *res)
{
    printf("%s = %p", function_called, res);
    if (res != ((void *)0))
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
void __noreturn check_exit()
{
printf("passed: %d failed: %d\n", (unsigned int)passed, (unsigned int)failed);
if ( failed )
exit(-1);
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("passed: %d failed: %d\n", (unsigned int)passed, (unsigned int)failed);
if ( failed )
exit(-1);
exit(0);
}

original_code:
void
check_exit()
{
    printf("passed: %d failed: %d\n", passed, failed);
    if (failed != 0)
    {
        exit(-1);
    }
    exit(0);
}


decompiled_code:
bool __fastcall ir_is_struct_literal(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = ir_struct_literal_get_type();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = func2();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

original_code:
_Bool
ir_is_struct_literal(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (obj); GType __t = (ir_struct_literal_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool ir_is_struct_literal(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) (obj); unsigned long __t = (ir_struct_literal_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

variable_types:
obj
void *

variable_types: struct _GTypeInstance { struct _GTypeClass { unsigned long g_type; } *g_class; } *

user_defined_types: struct _GTypeInstance { struct _GTypeClass *g_class; }


decompiled_code:
__int64 __fastcall g_type_from_instance(__int64 a1)
{
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return **(_QWORD **)a1;
}

original_code:
GType
g_type_from_instance(void *obj)
{
    return ((((GTypeClass*) (((GTypeInstance*) (obj))->g_class))->g_type));
}

canonical_original_code:
unsigned long g_type_from_instance(void *obj)
{
    return ((((struct _GTypeClass *) (((struct _GTypeInstance *) (obj))->g_class))->g_type));
}

return_type: unsigned long

user_defined_types: struct _GTypeClass { unsigned long g_type; }


decompiled_code:
bool __fastcall g_is_object(__int64 a1)
{
return (unsigned int)g_type_check_instance_is_fundamentally_a(a1, 80LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return (unsigned int)g_type_check_instance_is_fundamentally_a(a1, 80LL) != 0;
}

original_code:
_Bool
g_is_object(void *obj)
{
    return (((g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ((obj)), (((GType) ((20) << (2))))))));
}

canonical_original_code:
_Bool g_is_object(void *obj)
{
    return (((g_type_check_instance_is_fundamentally_a ((struct _GTypeInstance *) ((obj)), (((GType) ((20) << (2))))))));
}


decompiled_code:
__int64 sym_table_error_quark()
{
return g_quark_from_static_string("zdc-sym-table-error-quark");
}

canonical_decompiled_code:
__int64 func0()
{
return g_quark_from_static_string("zdc-sym-table-error-quark");
}

original_code:
static GQuark
sym_table_error_quark(void)
{
    return g_quark_from_static_string ("zdc-sym-table-error-quark");
}

canonical_original_code:
static unsigned int sym_table_error_quark()
{
    return g_quark_from_static_string ("zdc-sym-table-error-quark");
}

return_type: unsigned int


decompiled_code:
bool __fastcall dt_is_basic(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = dt_basic_get_type();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = func1();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

original_code:
_Bool
dt_is_basic(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((obj)); GType __t = (dt_basic_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool dt_is_basic(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) ((obj)); unsigned long __t = (dt_basic_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}


decompiled_code:
bool __fastcall ir_is_array_literal(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = ir_array_literal_get_type();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

original_code:
_Bool
ir_is_array_literal(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((obj)); GType __t = (ir_array_literal_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool ir_is_array_literal(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) ((obj)); unsigned long __t = (ir_array_literal_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}


decompiled_code:
bool __fastcall dt_is_enum(_QWORD *a1)
{
__int64 v1; // rsi
bool result; // al

v1 = dt_enum_get_type();
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v1) )
result = (unsigned int)g_type_check_instance_is_a(a1, v1) != 0;
}
return result;
}

original_code:
_Bool
dt_is_enum(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((obj)); GType __t = (dt_enum_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool dt_is_enum(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) ((obj)); unsigned long __t = (dt_enum_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}


decompiled_code:
__int64 ir_linkage_attr_get_type()
{
__int64 result; // rax

result = linkage_attr_type_11;
if ( !linkage_attr_type_11 )
{
result = g_enum_register_static("IrLinkageAttrType", &linkage_attr_10);
linkage_attr_type_11 = result;
}
return result;
}

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

result = linkage_attr_type_11;
if ( !linkage_attr_type_11 )
{
result = g_enum_register_static("IrLinkageAttrType", &linkage_attr_10);
linkage_attr_type_11 = result;
}
return result;
}

original_code:
static GType
ir_linkage_attr_get_type(void)
{
  static GType linkage_attr_type = 0;
  static GEnumValue linkage_attr[] =
  {
      {ir_d_linkage, "D", "D linkage"},
      {ir_c_linkage, "C", "C linkage"},
      {0, ((void *)0), ((void *)0)}
  };
  if (linkage_attr_type == 0)
  {
      linkage_attr_type =
          g_enum_register_static("IrLinkageAttrType", linkage_attr);
  }
  return linkage_attr_type;
}

canonical_original_code:
static unsigned long ir_linkage_attr_get_type()
{
  static unsigned long linkage_attr_type = 0;
  static struct _GEnumValue linkage_attr[] = {
      {ir_d_linkage, "D", "D linkage"},
      {ir_c_linkage, "C", "C linkage"},
      {0, ((void *)0), ((void *)0)}
  };
  if (linkage_attr_type == 0)
  {
      linkage_attr_type =
          g_enum_register_static("IrLinkageAttrType", linkage_attr);
  }
  return linkage_attr_type;
}

variable_types: struct _GEnumValue { int value; char *value_name; char *value_nick; } []


decompiled_code:
bool __fastcall iml_is_variable(_QWORD *a1, __int64 a2)
{
__int64 v2; // rsi
bool result; // al

v2 = iml_variable_get_type((__int64)a1, a2);
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v2) )
result = (unsigned int)g_type_check_instance_is_a(a1, v2) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 v2; // rsi
bool result; // al

v2 = func1((__int64)a1, a2);
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v2) )
result = (unsigned int)g_type_check_instance_is_a(a1, v2) != 0;
}
return result;
}

original_code:
_Bool
iml_is_variable(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((obj)); GType __t = (iml_variable_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool iml_is_variable(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) ((obj)); unsigned long __t = (iml_variable_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}


decompiled_code:
bool __fastcall iml_is_constant(_QWORD *a1, __int64 a2)
{
__int64 v2; // rsi
bool result; // al

v2 = iml_constant_get_type((__int64)a1, a2);
result = 0;
if ( a1 )
{
if ( !*a1 || (result = 1, *(_QWORD *)*a1 != v2) )
result = (unsigned int)g_type_check_instance_is_a(a1, v2) != 0;
}
return result;
}

original_code:
_Bool
iml_is_constant(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((obj)); GType __t = (iml_constant_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool iml_is_constant(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) ((obj)); unsigned long __t = (iml_constant_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}


decompiled_code:
__int64 __fastcall left_strip_index(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( v1 == 32 || v1 == 9 )
{
v1 = a1[++result];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( v1 == 32 || v1 == 9 )
{
v1 = a1[++result];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
static int left_strip_index(char const *s) {
 int i;
 for (i = 0; s[i]; ++i)
  if (!((s[i]) == ' ' || (s[i]) == '\t'))
   return i;
 return -1;
}

canonical_original_code:
static int left_strip_index(char *s) {
 int i;
 for (i = 0; s[i]; ++i)
  if (!((s[i]) == ' ' || (s[i]) == '\t'))
   return i;
 return -1;
}

variable_types:
s
char *

variable_types: i int


decompiled_code:
char *__fastcall hp_get_tweakable_var(char *s2, int a2)
{
char *i; // r12

for ( i = hp_tweakable_vars; i; i = (char *)*((_QWORD *)i + 34) )
{
if ( !strcmp(i, s2) && *((_DWORD *)i + 64) == a2 )
break;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func9(char *s2, int a2)
{
char *i; // r12

for ( i = hp_tweakable_vars; i; i = (char *)*((_QWORD *)i + 34) )
{
if ( !strcmp(i, s2) && *((_DWORD *)i + 64) == a2 )
break;
}
return i;
}

original_code:
static hp_vars_list_t *hp_get_tweakable_var(char const *path, hp_id_t id) {
 ;
 hp_vars_list_t *o;
 for (o = hp_tweakable_vars; o; o = o->next) {
  ;
  if (!strcmp(o->path, path)
   && o->id == id)
   return o;
 }
 ;
 return ((void *)0);
}

canonical_original_code:
static struct hp_vars_list_s *hp_get_tweakable_var(char *path, unsigned int id) {
 ;
 struct hp_vars_list_s *o;
 for (o = hp_tweakable_vars; o; o = o->next) {
  ;
  if (!strcmp(o->path, path)
   && o->id == id)
   return o;
 }
 ;
 return ((void *)0);
}

variable_types:
path
char *

variable_types:
id
unsigned int

variable_types: struct hp_vars_list_s { char path[256]; unsigned int id; struct hp_value_s { enum eType { TYPE_UNKNOWN=-1, TYPE_INT=0, TYPE_FLOAT=1 } type; union { int integer; float floating_integer; } value; } value; struct hp_vars_list_s *next; } *

user_defined_types: struct hp_vars_list_s { char path[256]; unsigned int id; struct hp_value_s value; struct hp_vars_list_s *next; }

user_defined_types: struct hp_value_s { enum eType type; union { int integer; float floating_integer; } value; }


decompiled_code:
char *__fastcall hp_get_tweakable_file(char *s2)
{
char *i; // r12

for ( i = hp_tweakable_files; i; i = (char *)*((_QWORD *)i + 33) )
{
if ( !strcmp(i, s2) )
break;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func10(char *s2)
{
char *i; // r12

for ( i = hp_tweakable_files; i; i = (char *)*((_QWORD *)i + 33) )
{
if ( !strcmp(i, s2) )
break;
}
return i;
}

original_code:
static hp_files_list_t *hp_get_tweakable_file(char const *path) {
 hp_files_list_t *o;
 for (o = hp_tweakable_files; o; o = o->next)
  if (!strcmp(o->path, path))
   return o;
 return ((void *)0);
}

canonical_original_code:
static struct hp_files_list_s *hp_get_tweakable_file(char *path) {
 struct hp_files_list_s *o;
 for (o = hp_tweakable_files; o; o = o->next)
  if (!strcmp(o->path, path))
   return o;
 return ((void *)0);
}

variable_types: struct hp_files_list_s { char path[256]; unsigned int mod_timestamp; struct hp_files_list_s *next; } *


decompiled_code:
__int64 __fastcall get_modification_time(char *a1)
{
bool v1; // sf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)stat(a1, &v3) < 0;
result = 0LL;
if ( !v1 )
result = LODWORD(v3.st_mtim.tv_sec);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
bool v1; // sf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)func23(a1, &v3) < 0;
result = 0LL;
if ( !v1 )
result = LODWORD(v3.st_mtim.tv_sec);
return result;
}

original_code:
static unsigned int get_modification_time(char const *path) {
 struct stat st;
 if (stat(path, &st) < 0)
  return 0;
 return st.st_mtim.tv_sec;
}

canonical_original_code:
static unsigned int get_modification_time(char *path) {
 struct stat st;
 if (stat(path, &st) < 0)
  return 0;
 return st.st_mtim.tv_sec;
}

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]; }

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:
char *__fastcall hp_reg_file(char *src)
{
char *v1; // r12
char *v3; // rax
char *v4; // rax

v1 = hp_get_tweakable_file(src);
if ( v1 )
return v1;
v3 = (char *)malloc(0x110uLL);
v1 = v3;
if ( !v3 )
return v1;
strncpy(v3, src, 0x100uLL);
*((_DWORD *)v1 + 64) = get_modification_time(src);
v4 = hp_tweakable_files;
hp_tweakable_files = v1;
*((_QWORD *)v1 + 33) = v4;
return v1;
}

canonical_decompiled_code:
char *__fastcall func12(char *src)
{
char *v1; // r12
char *v3; // rax
char *v4; // rax

v1 = func10(src);
if ( v1 )
return v1;
v3 = (char *)malloc(0x110uLL);
v1 = v3;
if ( !v3 )
return v1;
strncpy(v3, src, 0x100uLL);
*((_DWORD *)v1 + 64) = func11(src);
v4 = hp_tweakable_files;
hp_tweakable_files = v1;
*((_QWORD *)v1 + 33) = v4;
return v1;
}

original_code:
static hp_files_list_t *hp_reg_file(char const *path) {
 hp_files_list_t *new = hp_get_tweakable_file(path);
 if (new)
  return new;
 if (!(new = malloc(sizeof(hp_files_list_t))))
  return ((void *)0);
 strncpy(new->path, path, 256);
 new->mod_timestamp = get_modification_time(path);
 new->next = hp_tweakable_files;
 hp_tweakable_files = new;
 ;
 return new;
}

canonical_original_code:
static struct hp_files_list_s *hp_reg_file(char *path) {
 struct hp_files_list_s *new = hp_get_tweakable_file(path);
 if (new)
  return new;
 if (!(new = malloc(sizeof(hp_files_list_t))))
  return ((void *)0);
 strncpy(new->path, path, 256);
 new->mod_timestamp = get_modification_time(path);
 new->next = hp_tweakable_files;
 hp_tweakable_files = new;
 ;
 return new;
}

return_type: struct hp_files_list_s { char path[256]; unsigned int mod_timestamp; struct hp_files_list_s *next; } *


decompiled_code:
char *__fastcall hp_reg_val(char *src, int a2, int a3, _DWORD *a4)
{
char *v6; // rax
char *v7; // r8
char *v8; // rax

v6 = (char *)malloc(0x118uLL);
v7 = v6;
if ( v6 )
{
v7 = strncpy(v6, src, 0x100uLL);
*((_DWORD *)v7 + 64) = a2;
*((_DWORD *)v7 + 65) = a3;
*((_DWORD *)v7 + 66) = *a4;
v8 = hp_tweakable_vars;
hp_tweakable_vars = v7;
*((_QWORD *)v7 + 34) = v8;
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func13(char *src, int a2, int a3, _DWORD *a4)
{
char *v6; // rax
char *v7; // r8
char *v8; // rax

v6 = (char *)malloc(0x118uLL);
v7 = v6;
if ( v6 )
{
v7 = strncpy(v6, src, 0x100uLL);
*((_DWORD *)v7 + 64) = a2;
*((_DWORD *)v7 + 65) = a3;
*((_DWORD *)v7 + 66) = *a4;
v8 = hp_tweakable_vars;
hp_tweakable_vars = v7;
*((_QWORD *)v7 + 34) = v8;
}
return v7;
}

original_code:
static hp_vars_list_t *hp_reg_val(char const *path, hp_id_t id, eType type, void *value) {
 hp_vars_list_t *new;
 if (!(new = malloc(sizeof(hp_vars_list_t))))
  return ((void *)0);
 strncpy(new->path, path, 256);
 new->id = id;
 new->value.type = type;
 if (type == TYPE_INT)
  memcpy(&new->value.value.integer, value, sizeof(int));
 else if (type == TYPE_FLOAT)
  memcpy(&new->value.value.floating_integer, value, sizeof(float));
 else {
  ;
  free(new);
  return ((void *)0);
 }
 ;
 new->next = hp_tweakable_vars;
 hp_tweakable_vars = new;
 return new;
}

canonical_original_code:
static struct hp_vars_list_s *hp_reg_val(char *path, unsigned int id, enum eType type, void *value) {
 struct hp_vars_list_s *new;
 if (!(new = malloc(sizeof(hp_vars_list_t))))
  return ((void *)0);
 strncpy(new->path, path, 256);
 new->id = id;
 new->value.type = type;
 if (type == TYPE_INT)
  memcpy(&new->value.value.integer, value, sizeof(int));
 else if (type == TYPE_FLOAT)
  memcpy(&new->value.value.floating_integer, value, sizeof(float));
 else {
  ;
  free(new);
  return ((void *)0);
 }
 ;
 new->next = hp_tweakable_vars;
 hp_tweakable_vars = new;
 return new;
}

variable_types:
value
void *

return_type: struct hp_vars_list_s { char path[256]; unsigned int id; struct hp_value_s { enum eType { TYPE_UNKNOWN=-1, TYPE_INT=0, TYPE_FLOAT=1 } type; union { int integer; float floating_integer; } value; } value; struct hp_vars_list_s *next; } *


decompiled_code:
unsigned __int64 __fastcall hp_value_from_str(unsigned int a1, const char *a2)
{
__int64 v2; // rax
__m128i v4; // xmm1

if ( !a1 )
{
LODWORD(v2) = atoi(a2);
return (v2 << 32) | a1;
}
v2 = 0LL;
if ( a1 != 1 )
return (v2 << 32) | a1;
v4 = 0LL;
*(float *)v4.m128i_i32 = atof(a2);
return ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v4) << 32) | 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(unsigned int a1, const char *a2)
{
__int64 v2; // rax
__m128i v4; // xmm1

if ( !a1 )
{
LODWORD(v2) = atoi(a2);
return (v2 << 32) | a1;
}
v2 = 0LL;
if ( a1 != 1 )
return (v2 << 32) | a1;
v4 = 0LL;
*(float *)v4.m128i_i32 = atof(a2);
return ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v4) << 32) | 1;
}

original_code:
static hp_value_t hp_value_from_str(eType type, char *s) {
 hp_value_t value;
 value.type = type;
 if (type == TYPE_INT)
  value.value.integer = atoi(s);
 else if (type == TYPE_FLOAT)
  value.value.floating_integer = (float)atof(s);
 else
  value.value.integer = 0;
 return value;
}

canonical_original_code:
static struct hp_value_s hp_value_from_str(enum eType type, char *s) {
 struct hp_value_s value;
 value.type = type;
 if (type == TYPE_INT)
  value.value.integer = atoi(s);
 else if (type == TYPE_FLOAT)
  value.value.floating_integer = (float)atof(s);
 else
  value.value.integer = 0;
 return value;
}

variable_types: struct hp_value_s { enum eType { TYPE_UNKNOWN=-1, TYPE_INT=0, TYPE_FLOAT=1 } type; union { int integer; float floating_integer; } value; }


decompiled_code:
char *__fastcall hp_get_tweakable_int(char *src, int a2, int a3)
{
char *v3; // rbx
char *result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a3;
v3 = hp_get_tweakable_var(src, a2);
if ( hp_reg_file(src) && (v3 || (v3 = hp_reg_val(src, a2, 0, v5)) != 0LL) )
result = v3 + 264;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func17(char *src, int a2, int a3)
{
char *v3; // rbx
char *result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a3;
v3 = func9(src, a2);
if ( func12(src) && (v3 || (v3 = func13(src, a2, 0, v5)) != 0LL) )
result = v3 + 264;
else
result = 0LL;
return result;
}

original_code:
int *hp_get_tweakable_int(char const *path, hp_id_t id, int value) {
 hp_vars_list_t *var = hp_get_tweakable_var(path, id);
 if (!hp_reg_file(path)) {
  ;
  return ((void *)0);
 }
 if (!var) {
  ;
  var = hp_reg_val(path, id, TYPE_INT, &value);
 }
 return (var ? &var->value.value.integer : ((void *)0));
}

canonical_original_code:
int *hp_get_tweakable_int(char *path, unsigned int id, int value) {
 struct hp_vars_list_s *var = hp_get_tweakable_var(path, id);
 if (!hp_reg_file(path)) {
  ;
  return ((void *)0);
 }
 if (!var) {
  ;
  var = hp_reg_val(path, id, TYPE_INT, &value);
 }
 return (var ? &var->value.value.integer : ((void *)0));
}

variable_types: value int

return_type: int *

user_defined_types: enum eType { TYPE_UNKNOWN=-1, TYPE_INT=0, TYPE_FLOAT=1 }


decompiled_code:
char *__fastcall hp_get_tweakable_float(char *src, int a2, float a3)
{
char *v3; // rbx
char *result; // rax
float v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a3;
v3 = hp_get_tweakable_var(src, a2);
if ( hp_reg_file(src) && (v3 || (v3 = hp_reg_val(src, a2, 1, v5)) != 0LL) )
result = v3 + 264;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func18(char *src, int a2, float a3)
{
char *v3; // rbx
char *result; // rax
float v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a3;
v3 = func9(src, a2);
if ( func12(src) && (v3 || (v3 = func13(src, a2, 1, v5)) != 0LL) )
result = v3 + 264;
else
result = 0LL;
return result;
}

original_code:
float *hp_get_tweakable_float(char const *path, hp_id_t id, float value) {
 hp_vars_list_t *var = hp_get_tweakable_var(path, id);
 if (!hp_reg_file(path)) {
  ;
  return ((void *)0);
 }
 if (!var) {
  ;
  var = hp_reg_val(path, id, TYPE_FLOAT, &value);
 }
 return (var ? &var->value.value.floating_integer : ((void *)0));
}

canonical_original_code:
float *hp_get_tweakable_float(char *path, unsigned int id, float value) {
 struct hp_vars_list_s *var = hp_get_tweakable_var(path, id);
 if (!hp_reg_file(path)) {
  ;
  return ((void *)0);
 }
 if (!var) {
  ;
  var = hp_reg_val(path, id, TYPE_FLOAT, &value);
 }
 return (var ? &var->value.value.floating_integer : ((void *)0));
}

variable_types: value float

return_type: float *


decompiled_code:
__int64 hp_refresh_tweakable_vars()
{
unsigned int v0; // er12
char *i; // rbx
int v2; // eax

v0 = 0;
for ( i = hp_tweakable_files; i; v0 -= (v2 == 0) - 1 )
{
v2 = hp_refresh_file(i);
i = (char *)*((_QWORD *)i + 33);
}
return v0;
}

canonical_decompiled_code:
__int64 func19()
{
unsigned int v0; // er12
char *i; // rbx
int v2; // eax

v0 = 0;
for ( i = hp_tweakable_files; i; v0 -= (v2 == 0) - 1 )
{
v2 = func16(i);
i = (char *)*((_QWORD *)i + 33);
}
return v0;
}

original_code:
unsigned int hp_refresh_tweakable_vars() {
 hp_files_list_t *file;
 unsigned int nb_errors = 0;
 for (file = hp_tweakable_files; file; file = file->next)
  if (hp_refresh_file(file))
   ++nb_errors;
 return nb_errors;
}

canonical_original_code:
unsigned int hp_refresh_tweakable_vars() {
 struct hp_files_list_s *file;
 unsigned int nb_errors = 0;
 for (file = hp_tweakable_files; file; file = file->next)
  if (hp_refresh_file(file))
   ++nb_errors;
 return nb_errors;
}

user_defined_types: struct hp_files_list_s { char path[256]; unsigned int mod_timestamp; struct hp_files_list_s *next; }


decompiled_code:
__int64 __fastcall hp_refresh_tweakable_file(char *a1)
{
char *v1; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = hp_get_tweakable_file(a1);
if ( v1 )
result = hp_refresh_file(v1);
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(char *a1)
{
char *v1; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = func10(a1);
if ( v1 )
result = func16(v1);
else
result = 1LL;
return result;
}

original_code:
int hp_refresh_tweakable_file(char const *path) {
 hp_files_list_t *file;
 if (!path)
  return -1;
 if (!(file = hp_get_tweakable_file(path)))
  return 1;
 return hp_refresh_file(file);
}

canonical_original_code:
int hp_refresh_tweakable_file(char *path) {
 struct hp_files_list_s *file;
 if (!path)
  return -1;
 if (!(file = hp_get_tweakable_file(path)))
  return 1;
 return hp_refresh_file(file);
}


repo: leo-bogert/accuraterip-checksum

decompiled_code:
bool __fastcall check_fileformat(_DWORD *a1)
{
bool result; // al

result = 0;
if ( a1[3] == 2 && (a1[4] & 0x10002) == 65538 )
result = a1[2] == 44100;
return result;
}

canonical_decompiled_code:
bool __fastcall func7(_DWORD *a1)
{
bool result; // al

result = 0;
if ( a1[3] == 2 && (a1[4] & 0x10002) == 65538 )
result = a1[2] == 44100;
return result;
}

original_code:
_Bool check_fileformat(const SF_INFO* sfinfo) {
 if(sfinfo->channels != 2) return 0;
 if((sfinfo->format & SF_FORMAT_TYPEMASK & SF_FORMAT_WAV) != SF_FORMAT_WAV) return 0;
 if((sfinfo->format & SF_FORMAT_SUBMASK & SF_FORMAT_PCM_16) != SF_FORMAT_PCM_16) return 0;
 if(sfinfo->samplerate != 44100) return 0;
 return 1;
}

canonical_original_code:
_Bool check_fileformat(struct SF_INFO *sfinfo) {
 if(sfinfo->channels != 2) return 0;
 if((sfinfo->format & SF_FORMAT_TYPEMASK & SF_FORMAT_WAV) != SF_FORMAT_WAV) return 0;
 if((sfinfo->format & SF_FORMAT_SUBMASK & SF_FORMAT_PCM_16) != SF_FORMAT_PCM_16) return 0;
 if(sfinfo->samplerate != 44100) return 0;
 return 1;
}

variable_types: struct SF_INFO { long frames; int samplerate; int channels; int format; int sections; int seekable; } *


decompiled_code:
__int64 __fastcall get_full_audiodata_size(__int64 a1)
{
return 2 * *(_QWORD *)a1 * *(int *)(a1 + 12);
}

original_code:
size_t get_full_audiodata_size(const SF_INFO* sfinfo) {
 return sfinfo->frames * sfinfo->channels * (16 / 8);
}

canonical_original_code:
unsigned long get_full_audiodata_size(struct SF_INFO *sfinfo) {
 return sfinfo->frames * sfinfo->channels * (16 / 8);
}

user_defined_types: struct SF_INFO { long frames; int samplerate; int channels; int format; int sections; int seekable; }


decompiled_code:
__int64 __fastcall compute_v1_checksum(__int64 a1, int a2, int a3, int a4)
{
unsigned int v5; // ecx
unsigned __int64 v6; // rsi
unsigned int v8; // edi
__int64 v9; // rax
unsigned int v10; // er8
__int64 v11; // rsi

v5 = 0;
v6 = (unsigned __int64)a2 >> 2;
if ( a3 == 1 )
v5 = 2940;
v8 = v6 - 2940;
if ( a3 != a4 )
v8 = v6;
if ( (int)v6 <= 0 )
return 0LL;
v9 = 1LL;
v10 = 0;
v11 = (unsigned int)(v6 - 1) + 2LL;
do
{
if ( v5 <= (unsigned int)v9 && v8 >= (unsigned int)v9 )
v10 += *(_DWORD *)(a1 + 4 * v9 - 4) * v9;
++v9;
}
while ( v9 != v11 );
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3, int a4)
{
unsigned int v5; // ecx
unsigned __int64 v6; // rsi
unsigned int v8; // edi
__int64 v9; // rax
unsigned int v10; // er8
__int64 v11; // rsi

v5 = 0;
v6 = (unsigned __int64)a2 >> 2;
if ( a3 == 1 )
v5 = 2940;
v8 = v6 - 2940;
if ( a3 != a4 )
v8 = v6;
if ( (int)v6 <= 0 )
return 0LL;
v9 = 1LL;
v10 = 0;
v11 = (unsigned int)(v6 - 1) + 2LL;
do
{
if ( v5 <= (unsigned int)v9 && v8 >= (unsigned int)v9 )
v10 += *(_DWORD *)(a1 + 4 * v9 - 4) * v9;
++v9;
}
while ( v9 != v11 );
return v10;
}

original_code:
uint32_t compute_v1_checksum(const uint32_t* audio_data, const size_t audio_data_size, const int track_number, const int total_tracks) {
 const uint32_t *pAudioData = audio_data;
 int DataSize = audio_data_size;
 int TrackNumber = track_number;
 int AudioTrackCount = total_tracks;
 uint32_t AR_CRC = 0, AR_CRCPosMulti = 1;
 uint32_t AR_CRCPosCheckFrom = 0;
 uint32_t AR_CRCPosCheckTo = DataSize / sizeof(uint32_t);
 if (TrackNumber == 1)
  AR_CRCPosCheckFrom+= ((2352 * 5) / sizeof(uint32_t));
 if (TrackNumber == AudioTrackCount)
  AR_CRCPosCheckTo-=((2352 * 5) / sizeof(uint32_t));
 int DataDWORDSize = DataSize / sizeof(uint32_t);
 for (int i = 0; i < DataDWORDSize; i++)
 {
  if (AR_CRCPosMulti >= AR_CRCPosCheckFrom && AR_CRCPosMulti <= AR_CRCPosCheckTo)
   AR_CRC+=(AR_CRCPosMulti * pAudioData[i]);
  AR_CRCPosMulti++;
 }
 return AR_CRC;
}

canonical_original_code:
unsigned int compute_v1_checksum(unsigned int *audio_data, unsigned long audio_data_size, int track_number, int total_tracks) {
 unsigned int *pAudioData = audio_data;
 int DataSize = audio_data_size;
 int TrackNumber = track_number;
 int AudioTrackCount = total_tracks;
 unsigned int AR_CRC = 0; unsigned int AR_CRCPosMulti = 1;
 unsigned int AR_CRCPosCheckFrom = 0;
 unsigned int AR_CRCPosCheckTo = DataSize / sizeof(uint32_t);
 if (TrackNumber == 1)
  AR_CRCPosCheckFrom+= ((2352 * 5) / sizeof(unsigned int));
 if (TrackNumber == AudioTrackCount)
  AR_CRCPosCheckTo-=((2352 * 5) / sizeof(unsigned int));
 int DataDWORDSize = DataSize / sizeof(uint32_t);
 for (int i = 0; i < DataDWORDSize; i++)
 {
  if (AR_CRCPosMulti >= AR_CRCPosCheckFrom && AR_CRCPosMulti <= AR_CRCPosCheckTo)
   AR_CRC+=(AR_CRCPosMulti * pAudioData[i]);
  AR_CRCPosMulti++;
 }
 return AR_CRC;
}

variable_types:
pAudioData
unsigned int *

variable_types: DataSize int

variable_types: TrackNumber int

variable_types: AudioTrackCount int

variable_types: DataDWORDSize int


decompiled_code:
__int64 __fastcall compute_v2_checksum(__int64 a1, int a2, int a3, int a4)
{
unsigned int v5; // ecx
unsigned __int64 v6; // rsi
unsigned int v8; // edi
__int64 v9; // rax
unsigned int v10; // er8
__int64 v11; // rsi
__int64 v12; // rdx

v5 = 0;
v6 = (unsigned __int64)a2 >> 2;
if ( a3 == 1 )
v5 = 2940;
v8 = v6 - 2940;
if ( a3 != a4 )
v8 = v6;
if ( (int)v6 <= 0 )
return 0LL;
v9 = 1LL;
v10 = 0;
v11 = (unsigned int)(v6 - 1) + 2LL;
do
{
if ( v5 <= (unsigned int)v9 && v8 >= (unsigned int)v9 )
{
v12 = v9 * *(unsigned int *)(a1 + 4 * v9 - 4);
v10 += HIDWORD(v12) + v12;
}
++v9;
}
while ( v9 != v11 );
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3, int a4)
{
unsigned int v5; // ecx
unsigned __int64 v6; // rsi
unsigned int v8; // edi
__int64 v9; // rax
unsigned int v10; // er8
__int64 v11; // rsi
__int64 v12; // rdx

v5 = 0;
v6 = (unsigned __int64)a2 >> 2;
if ( a3 == 1 )
v5 = 2940;
v8 = v6 - 2940;
if ( a3 != a4 )
v8 = v6;
if ( (int)v6 <= 0 )
return 0LL;
v9 = 1LL;
v10 = 0;
v11 = (unsigned int)(v6 - 1) + 2LL;
do
{
if ( v5 <= (unsigned int)v9 && v8 >= (unsigned int)v9 )
{
v12 = v9 * *(unsigned int *)(a1 + 4 * v9 - 4);
v10 += HIDWORD(v12) + v12;
}
++v9;
}
while ( v9 != v11 );
return v10;
}

original_code:
uint32_t compute_v2_checksum(const uint32_t* audio_data, const size_t audio_data_size, const int track_number, const int total_tracks) {
 const uint32_t *pAudioData = audio_data;
 int DataSize = audio_data_size;
 int TrackNumber = track_number;
 int AudioTrackCount = total_tracks;
 uint32_t AR_CRCPosCheckFrom = 0;
 uint32_t AR_CRCPosCheckTo = DataSize / sizeof(uint32_t);
 if (TrackNumber == 1)
  AR_CRCPosCheckFrom+= ((2352 * 5) / sizeof(uint32_t));
 if (TrackNumber == AudioTrackCount)
  AR_CRCPosCheckTo-=((2352 * 5) / sizeof(uint32_t));
 int DataDWORDSize = DataSize / sizeof(uint32_t);
    uint32_t AC_CRCNEW = 0;
 uint32_t MulBy = 1;
 for (int i = 0; i < DataDWORDSize; i++)
 {
  if (MulBy >= AR_CRCPosCheckFrom && MulBy <= AR_CRCPosCheckTo)
  {
   uint32_t Value = pAudioData[i];
   uint64_t CalcCRCNEW = (uint64_t)Value * (uint64_t)MulBy;
   uint32_t LOCalcCRCNEW = (uint32_t)(CalcCRCNEW & (uint64_t)0xFFFFFFFF);
   uint32_t HICalcCRCNEW = (uint32_t)(CalcCRCNEW / (uint64_t)0x100000000);
   AC_CRCNEW+=HICalcCRCNEW;
   AC_CRCNEW+=LOCalcCRCNEW;
  }
        MulBy++;
 }
 return AC_CRCNEW;
}

canonical_original_code:
unsigned int compute_v2_checksum(unsigned int *audio_data, unsigned long audio_data_size, int track_number, int total_tracks) {
 unsigned int *pAudioData = audio_data;
 int DataSize = audio_data_size;
 int TrackNumber = track_number;
 int AudioTrackCount = total_tracks;
 unsigned int AR_CRCPosCheckFrom = 0;
 unsigned int AR_CRCPosCheckTo = DataSize / sizeof(uint32_t);
 if (TrackNumber == 1)
  AR_CRCPosCheckFrom+= ((2352 * 5) / sizeof(unsigned int));
 if (TrackNumber == AudioTrackCount)
  AR_CRCPosCheckTo-=((2352 * 5) / sizeof(unsigned int));
 int DataDWORDSize = DataSize / sizeof(uint32_t);
    unsigned int AC_CRCNEW = 0;
 unsigned int MulBy = 1;
 for (int i = 0; i < DataDWORDSize; i++)
 {
  if (MulBy >= AR_CRCPosCheckFrom && MulBy <= AR_CRCPosCheckTo)
  {
   unsigned int Value = pAudioData[i];
   unsigned long CalcCRCNEW = (uint64_t)Value * (uint64_t)MulBy;
   unsigned int LOCalcCRCNEW = (uint32_t)(CalcCRCNEW & (uint64_t)0xFFFFFFFF);
   unsigned int HICalcCRCNEW = (uint32_t)(CalcCRCNEW / (uint64_t)0x100000000);
   AC_CRCNEW+=HICalcCRCNEW;
   AC_CRCNEW+=LOCalcCRCNEW;
  }
        MulBy++;
 }
 return AC_CRCNEW;
}

variable_types:
MulBy
unsigned int

variable_types:
Value
unsigned int

variable_types:
CalcCRCNEW
unsigned long

variable_types:
LOCalcCRCNEW
unsigned int

variable_types:
HICalcCRCNEW
unsigned int


decompiled_code:
size_t print_syntax_to_stderr()
{
return fwrite(
"Syntax: accuraterip-checksum [--version / --accuraterip-v1 / --accuraterip-v2 (default)] filename track_numbe"
"r total_tracks\n",
1uLL,
0x7CuLL,
_bss_start);
}

canonical_decompiled_code:
size_t func12()
{
return fwrite(
"Syntax: accuraterip-checksum [--version / --accuraterip-v1 / --accuraterip-v2 (default)] filename track_numbe"
"r total_tracks\n",
1uLL,
0x7CuLL,
_bss_start);
}

original_code:
void print_syntax_to_stderr() {
 fprintf(stderr, "Syntax: accuraterip-checksum [--version / --accuraterip-v1 / --accuraterip-v2 (default)] filename track_number total_tracks\n");
}


repo: leobispo/kermit

decompiled_code:
__int64 __fastcall print_usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s [options]\n"
"Kermit Server Implementation\n"
"Options:\n"
"\t-p --port=<port>\n"
"\t-s --server\n"
"\t-c --client=<server_address>\n"
"\t-d --directory=<directory>\n"
"\t-D --daemon\n",
a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
fprintf(
stderr,
"Usage: %s [options]\n"
"Kermit Server Implementation\n"
"Options:\n"
"\t-p --port=<port>\n"
"\t-s --server\n"
"\t-c --client=<server_address>\n"
"\t-d --directory=<directory>\n"
"\t-D --daemon\n",
a1);
return 1LL;
}

original_code:
static int
print_usage(const char * const app_name)
{
  fprintf(stderr, "Usage: %s [options]\n"
    "Kermit Server Implementation\n"
    "Options:\n"
    "\t-p --port=<port>\n"
    "\t-s --server\n"
    "\t-c --client=<server_address>\n"
    "\t-d --directory=<directory>\n"
    "\t-D --daemon\n",
    app_name
  );
  return 1;
}

canonical_original_code:
static int print_usage(char *app_name)
{
  fprintf(stderr, "Usage: %s [options]\n"
    "Kermit Server Implementation\n"
    "Options:\n"
    "\t-p --port=<port>\n"
    "\t-s --server\n"
    "\t-c --client=<server_address>\n"
    "\t-d --directory=<directory>\n"
    "\t-D --daemon\n",
    app_name
  );
  return 1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r15
char *v4; // r14
char *v5; // r13
char v6; // r12
int v7; // eax
int v9; // eax
unsigned __int16 v10; // [rsp+Ch] [rbp-FCh]
int v11; // [rsp+Ch] [rbp-FCh]
struct option longopts; // [rsp+10h] [rbp-F8h] BYREF
const char *v13; // [rsp+30h] [rbp-D8h]
int v14; // [rsp+38h] [rbp-D0h]
__int64 v15; // [rsp+40h] [rbp-C8h]
int v16; // [rsp+48h] [rbp-C0h]
const char *v17; // [rsp+50h] [rbp-B8h]
int v18; // [rsp+58h] [rbp-B0h]
__int64 v19; // [rsp+60h] [rbp-A8h]
int v20; // [rsp+68h] [rbp-A0h]
const char *v21; // [rsp+70h] [rbp-98h]
int v22; // [rsp+78h] [rbp-90h]
__int64 v23; // [rsp+80h] [rbp-88h]
int v24; // [rsp+88h] [rbp-80h]
const char *v25; // [rsp+90h] [rbp-78h]
int v26; // [rsp+98h] [rbp-70h]
__int64 v27; // [rsp+A0h] [rbp-68h]
int v28; // [rsp+A8h] [rbp-60h]
__int64 v29; // [rsp+B0h] [rbp-58h]
int v30; // [rsp+B8h] [rbp-50h]
__int64 v31; // [rsp+C0h] [rbp-48h]
int v32; // [rsp+C8h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
longopts.name = "port";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 112;
v13 = "directory";
v14 = 1;
v15 = 0LL;
v16 = 100;
v17 = "client";
v18 = 1;
v19 = 0LL;
v20 = 99;
v21 = "daemon";
v22 = 0;
v23 = 0LL;
v24 = 68;
v25 = "server";
v26 = 0;
v27 = 0LL;
v28 = 115;
v29 = 0LL;
v30 = 0;
v31 = 0LL;
v32 = 0;
v10 = 0;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, "p:d:c:Ds", &longopts, 0LL);
if ( v7 == -1 )
break;
if ( v7 == 100 )
{
v4 = strdup(optarg);
}
else if ( v7 > 100 )
{
if ( v7 == 112 )
{
v10 = atoi(optarg);
}
else
{
if ( v7 != 115 )
return print_usage(*argv);
v6 = 1;
}
}
else if ( v7 == 68 )
{
v3 = 1;
}
else
{
if ( v7 != 99 )
return print_usage(*argv);
v5 = strdup(optarg);
}
}
if ( !v10 )
return print_usage(*argv);
if ( !v5 )
{
if ( v4 && v6 )
{
v9 = start_server(v4, v10, v3);
goto LABEL_19;
}
LABEL_23:
v9 = print_usage(*argv);
goto LABEL_19;
}
if ( v6 )
goto LABEL_23;
v9 = start_client(v5, v10);
LABEL_19:
v11 = v9;
free(v4);
free(v5);
return v11;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r15
char *v4; // r14
char *v5; // r13
char v6; // r12
int v7; // eax
int v9; // eax
unsigned __int16 v10; // [rsp+Ch] [rbp-FCh]
int v11; // [rsp+Ch] [rbp-FCh]
struct option longopts; // [rsp+10h] [rbp-F8h] BYREF
const char *v13; // [rsp+30h] [rbp-D8h]
int v14; // [rsp+38h] [rbp-D0h]
__int64 v15; // [rsp+40h] [rbp-C8h]
int v16; // [rsp+48h] [rbp-C0h]
const char *v17; // [rsp+50h] [rbp-B8h]
int v18; // [rsp+58h] [rbp-B0h]
__int64 v19; // [rsp+60h] [rbp-A8h]
int v20; // [rsp+68h] [rbp-A0h]
const char *v21; // [rsp+70h] [rbp-98h]
int v22; // [rsp+78h] [rbp-90h]
__int64 v23; // [rsp+80h] [rbp-88h]
int v24; // [rsp+88h] [rbp-80h]
const char *v25; // [rsp+90h] [rbp-78h]
int v26; // [rsp+98h] [rbp-70h]
__int64 v27; // [rsp+A0h] [rbp-68h]
int v28; // [rsp+A8h] [rbp-60h]
__int64 v29; // [rsp+B0h] [rbp-58h]
int v30; // [rsp+B8h] [rbp-50h]
__int64 v31; // [rsp+C0h] [rbp-48h]
int v32; // [rsp+C8h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
longopts.name = "port";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 112;
v13 = "directory";
v14 = 1;
v15 = 0LL;
v16 = 100;
v17 = "client";
v18 = 1;
v19 = 0LL;
v20 = 99;
v21 = "daemon";
v22 = 0;
v23 = 0LL;
v24 = 68;
v25 = "server";
v26 = 0;
v27 = 0LL;
v28 = 115;
v29 = 0LL;
v30 = 0;
v31 = 0LL;
v32 = 0;
v10 = 0;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, "p:d:c:Ds", &longopts, 0LL);
if ( v7 == -1 )
break;
if ( v7 == 100 )
{
v4 = strdup(optarg);
}
else if ( v7 > 100 )
{
if ( v7 == 112 )
{
v10 = atoi(optarg);
}
else
{
if ( v7 != 115 )
return func0(*argv);
v6 = 1;
}
}
else if ( v7 == 68 )
{
v3 = 1;
}
else
{
if ( v7 != 99 )
return func0(*argv);
v5 = strdup(optarg);
}
}
if ( !v10 )
return func0(*argv);
if ( !v5 )
{
if ( v4 && v6 )
{
v9 = start_server(v4, v10, v3);
goto LABEL_19;
}
LABEL_23:
v9 = func0(*argv);
goto LABEL_19;
}
if ( v6 )
goto LABEL_23;
v9 = start_client(v5, v10);
LABEL_19:
v11 = v9;
free(v4);
free(v5);
return v11;
}

original_code:
int main(int argc, char **argv)
{
  int ret = 0;
  uint16_t port = 0;
  char *directory = ((void *)0);
  _Bool is_daemon = 0;
  char *server_addr = ((void *)0);
  _Bool is_server = 0;
  struct option opts[] = {
    { "port" , 1, 0, 'p' },
    { "directory", 1, 0, 'd' },
    { "client" , 1, 0, 'c' },
    { "daemon" , 0, 0, 'D' },
    { "server" , 0, 0, 's' },
    { ((void *)0) , 0, 0, 0 }
  };
  int opt;
  while ((opt = getopt_long(argc, argv, "p:d:c:Ds", opts, ((void *)0))) != -1) {
    switch(opt) {
      case 'p':
        port = atoi(optarg);
      break;
      case 'd':
        directory = strdup(optarg);
      break;
      case 'c':
        server_addr = strdup(optarg);
      break;
      case 's':
        is_server = 1;
      break;
      case 'D':
        is_daemon = 1;
      break;
      default:
        return print_usage(argv[0]);
    }
  }
  if (port == 0)
    return print_usage(argv[0]);
  if (server_addr && is_server)
    ret = print_usage(argv[0]);
  else if (server_addr)
    ret = start_client(server_addr, port);
  else if (is_server && directory)
    ret = start_server(directory, port, is_daemon);
  else
    ret = print_usage(argv[0]);
  free(directory);
  free(server_addr);
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int ret = 0;
  unsigned short port = 0;
  char *directory = ((void *)0);
  _Bool is_daemon = 0;
  char *server_addr = ((void *)0);
  _Bool is_server = 0;
  struct option opts[] = {
    { "port" , 1, 0, 'p' },
    { "directory", 1, 0, 'd' },
    { "client" , 1, 0, 'c' },
    { "daemon" , 0, 0, 'D' },
    { "server" , 0, 0, 's' },
    { ((void *)0) , 0, 0, 0 }
  };
  int opt;
  while ((opt = getopt_long(argc, argv, "p:d:c:Ds", opts, ((void *)0))) != -1) {
    switch(opt) {
      case 'p':
        port = atoi(optarg);
      break;
      case 'd':
        directory = strdup(optarg);
      break;
      case 'c':
        server_addr = strdup(optarg);
      break;
      case 's':
        is_server = 1;
      break;
      case 'D':
        is_daemon = 1;
      break;
      default:
        return print_usage(argv[0]);
    }
  }
  if (port == 0)
    return print_usage(argv[0]);
  if (server_addr && is_server)
    ret = print_usage(argv[0]);
  else if (server_addr)
    ret = start_client(server_addr, port);
  else if (is_server && directory)
    ret = start_server(directory, port, is_daemon);
  else
    ret = print_usage(argv[0]);
  free(directory);
  free(server_addr);
  return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ret int

variable_types:
port
unsigned short

variable_types:
directory
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: opt int


decompiled_code:
__int64 __fastcall calculate_crc(_BYTE *a1, char a2)
{
__int64 v2; // r8
__int64 result; // rax
char v4; // cl
unsigned int v5; // esi
bool v6; // sf

if ( !a2 )
return 0LL;
v2 = (__int64)&a1[(unsigned __int8)(a2 - 1) + 1];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *a1 ^ result;
v4 = 8;
do
{
v5 = 2 * result;
v6 = (result & 0x80u) != 0LL;
result = (2 * (_DWORD)result) ^ 7u;
if ( !v6 )
result = v5;
--v4;
}
while ( v4 );
++a1;
}
while ( a1 != (_BYTE *)v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2)
{
__int64 v2; // r8
__int64 result; // rax
char v4; // cl
unsigned int v5; // esi
bool v6; // sf

if ( !a2 )
return 0LL;
v2 = (__int64)&a1[(unsigned __int8)(a2 - 1) + 1];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *a1 ^ result;
v4 = 8;
do
{
v5 = 2 * result;
v6 = (result & 0x80u) != 0LL;
result = (2 * (_DWORD)result) ^ 7u;
if ( !v6 )
result = v5;
--v4;
}
while ( v4 );
++a1;
}
while ( a1 != (_BYTE *)v2 );
return result;
}

original_code:
static uint8_t
calculate_crc(const uint8_t *payload, uint8_t size)
{
  uint8_t remainder = 0x00;
  uint8_t byte, bit;
  for (byte = 0; byte < size; ++byte) {
    remainder ^= payload[byte];
    for (bit = 8; bit > 0 ; --bit) {
      if (remainder & 0x80)
        remainder = (remainder << 1) ^ 0x07;
      else
        remainder <<= 1;
      remainder = remainder & 0xFF;
    }
  }
  return remainder;
}

canonical_original_code:
static unsigned char calculate_crc(unsigned char *payload, unsigned char size)
{
  unsigned char remainder = 0x00;
  unsigned char byte; unsigned char bit;
  for (byte = 0; byte < size; ++byte) {
    remainder ^= payload[byte];
    for (bit = 8; bit > 0 ; --bit) {
      if (remainder & 0x80)
        remainder = (remainder << 1) ^ 0x07;
      else
        remainder <<= 1;
      remainder = remainder & 0xFF;
    }
  }
  return remainder;
}

variable_types:
payload
unsigned char *

variable_types:
size
unsigned char

variable_types:
remainder
unsigned char

variable_types:
byte
unsigned char

variable_types:
bit
unsigned char


decompiled_code:
void __fastcall register_decode_callback(unsigned __int8 a1, __int64 (__fastcall *a2)())
{
cmd_callbacks[a1] = a2;
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int8 a1, __int64 (__fastcall *a2)())
{
cmd_callbacks[a1] = a2;
}

original_code:
void
register_decode_callback(uint8_t cmd, void (*callback)(void *, uint8_t, const uint8_t * const, uint8_t))
{
  _cmd_callbacks[cmd].callback = callback;
}

canonical_original_code:
void register_decode_callback(unsigned char cmd, void (*callback)(void *, unsigned char, unsigned char *, unsigned char))
{
  _cmd_callbacks[cmd].callback = callback;
}

variable_types:
cmd
unsigned char

variable_types: void (*)(void *, unsigned char, unsigned char *, unsigned char)


original_code:
uint8_t
encode_msg(uint8_t *ret, uint8_t size, uint8_t sequence, uint8_t type, const uint8_t * const payload)
{
  struct header *h = (struct header *) ret;
  uint8_t s = 0x1e;
  h->mark = s;
  h->size = size;
  h->sequence = sequence;
  h->type = type;
  (*(uint16_t *) ret) = ntohs(*((uint16_t *) ret));
  memcpy(ret + 2, payload, size);
  ret[2 + size] = calculate_crc(payload, size);
  return size + 3;
}

canonical_original_code:
unsigned char encode_msg(unsigned char *ret, unsigned char size, unsigned char sequence, unsigned char type, unsigned char *payload)
{
  struct header *h = (struct header *) ret;
  unsigned char s = 0x1e;
  h->mark = s;
  h->size = size;
  h->sequence = sequence;
  h->type = type;
  (*(unsigned short *) ret) = ntohs(*((unsigned short *) ret));
  memcpy(ret + 2, payload, size);
  ret[2 + size] = calculate_crc(payload, size);
  return size + 3;
}

variable_types:
ret
unsigned char *

variable_types:
sequence
unsigned char

variable_types:
type
unsigned char

variable_types: struct header { unsigned short type; unsigned short sequence; unsigned short size; unsigned short mark; } *

variable_types:
s
unsigned char


decompiled_code:
__int64 __fastcall decode_msg(__int64 a1, __int64 a2)
{
uint16_t v2; // ax
unsigned int v3; // er12
char v4; // al
char v5; // r11
int v6; // er9

v2 = ntohs(*(_WORD *)a2);
*(_WORD *)a2 = v2;
if ( (HIBYTE(v2) & 0xFC) == 120 )
{
v3 = 1;
if ( (*(_BYTE *)a2 & 0xF) == 7 )
return v3;
v4 = calculate_crc((_BYTE *)(a2 + 2), (v2 >> 6) & 0xF);
if ( v4 == *(_BYTE *)(a2 + v6 + 2) )
{
cmd_callbacks[v5 & 0xF]();
return v3;
}
}
v3 = 0;
if ( cmd_error_callback )
cmd_error_callback(a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
uint16_t v2; // ax
unsigned int v3; // er12
char v4; // al
char v5; // r11
int v6; // er9

v2 = ntohs(*(_WORD *)a2);
*(_WORD *)a2 = v2;
if ( (HIBYTE(v2) & 0xFC) == 120 )
{
v3 = 1;
if ( (*(_BYTE *)a2 & 0xF) == 7 )
return v3;
v4 = func0((_BYTE *)(a2 + 2), (v2 >> 6) & 0xF);
if ( v4 == *(_BYTE *)(a2 + v6 + 2) )
{
cmd_callbacks[v5 & 0xF]();
return v3;
}
}
v3 = 0;
if ( cmd_error_callback )
cmd_error_callback(a1);
return v3;
}

original_code:
_Bool
decode_msg(void *ctx, const uint8_t * const msg)
{
  uint8_t crc;
  (*(uint16_t *) msg) = ntohs(*((uint16_t *) msg));
  struct header *h = (struct header *) msg;
  if (h->mark != 0x1e) {
    if (_cmd_error_callback)
      _cmd_error_callback(ctx);
    return 0;
  }
  if (h->type == 0x7)
    return 1;
  crc = msg[2 + h->size];
  const uint8_t * payload = msg + 2;
  uint8_t sequence = h->sequence;
  if (calculate_crc(payload, h->size) == crc) {
    _cmd_callbacks[h->type].callback(ctx, sequence, payload, h->size);
    return 1;
  }
  if (_cmd_error_callback)
    _cmd_error_callback(ctx);
  return 0;
}

canonical_original_code:
_Bool decode_msg(void *ctx, unsigned char *msg)
{
  unsigned char crc;
  (*(unsigned short *) msg) = ntohs(*((unsigned short *) msg));
  struct header *h = (struct header *) msg;
  if (h->mark != 0x1e) {
    if (_cmd_error_callback)
      _cmd_error_callback(ctx);
    return 0;
  }
  if (h->type == 0x7)
    return 1;
  crc = msg[2 + h->size];
  unsigned char *payload = msg + 2;
  unsigned char sequence = h->sequence;
  if (calculate_crc(payload, h->size) == crc) {
    _cmd_callbacks[h->type].callback(ctx, sequence, payload, h->size);
    return 1;
  }
  if (_cmd_error_callback)
    _cmd_error_callback(ctx);
  return 0;
}

variable_types:
ctx
void *

variable_types:
msg
unsigned char *

variable_types:
crc
unsigned char

user_defined_types: struct header { unsigned short type; unsigned short sequence; unsigned short size; unsigned short mark; }


decompiled_code:
__int64 __fastcall decode_msg_size_by_header(uint16_t a1)
{
uint16_t v1; // ax
__int64 result; // rax

v1 = ntohs(a1);
if ( (HIBYTE(v1) & 0xFC) == 120 )
result = ((v1 >> 6) & 0xF) + 3LL;
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(uint16_t a1)
{
uint16_t v1; // ax
__int64 result; // rax

v1 = ntohs(a1);
if ( (HIBYTE(v1) & 0xFC) == 120 )
result = ((v1 >> 6) & 0xF) + 3LL;
else
result = -1LL;
return result;
}

original_code:
ssize_t
decode_msg_size_by_header(uint16_t _header)
{
  _header = ntohs(_header);
  struct header *h = (struct header *) &_header;
  if (h->mark != 0x1e)
    return -1;
  return 3 + h->size;
}

canonical_original_code:
long decode_msg_size_by_header(unsigned short _header)
{
  _header = ntohs(_header);
  struct header *h = (struct header *) &_header;
  if (h->mark != 0x1e)
    return -1;
  return 3 + h->size;
}

return_type: long


repo: leonshao/network

decompiled_code:
unsigned int sigchld_handler()
{
__pid_t v0; // eax
int v1; // edi
char *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v0 = waitpid(-1, stat_loc, 0);
if ( v0 <= 0 )
break;
printf("Child process %d is reaped, status: %d\n", (unsigned int)v0, (unsigned int)stat_loc[0]);
}
v1 = *_errno_location();
if ( v1 != 10 )
{
v2 = strerror(v1);
fprintf(stdout, "waitpid error, %s", v2);
exit(0);
}
return sleep(2u);
}

canonical_decompiled_code:
unsigned int func0()
{
__pid_t v0; // eax
int v1; // edi
char *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v0 = waitpid(-1, stat_loc, 0);
if ( v0 <= 0 )
break;
printf("Child process %d is reaped, status: %d\n", (unsigned int)v0, (unsigned int)stat_loc[0]);
}
v1 = *_errno_location();
if ( v1 != 10 )
{
v2 = strerror(v1);
fprintf(stdout, "waitpid error, %s", v2);
exit(0);
}
return sleep(2u);
}

original_code:
void sigchld_handler(int sig) {
 pid_t pid;
 int status;
 while ((pid = waitpid(-1, &status, 0)) > 0) {
  printf("Child process %d is reaped, status: %d\n", (int)pid, status);
 }
 if ((*__errno_location ()) != 10) {
  fprintf(stdout, "waitpid error, %s", strerror((*__errno_location ())));
  exit(0);
 }
 sleep(2);
 return;
}

canonical_original_code:
void sigchld_handler(int sig) {
 int pid;
 int status;
 while ((pid = waitpid(-1, &status, 0)) > 0) {
  printf("Child process %d is reaped, status: %d\n", (int)pid, status);
 }
 if ((*__errno_location ()) != 10) {
  fprintf(stdout, "waitpid error, %s", strerror((*__errno_location ())));
  exit(0);
 }
 sleep(2);
 return;
}

variable_types: sig int

variable_types: pid int

variable_types: status int


decompiled_code:
int sigpipe_handler()
{
return puts("write to closed conn");
}

canonical_decompiled_code:
int func1()
{
return puts("write to closed conn");
}

original_code:
void sigpipe_handler(int sig) {
 printf("write to closed conn\n");
}


decompiled_code:
int __fastcall print_header_200(__int64 a1)
{
__m128i v1; // xmm0

v1 = _mm_load_si128((const __m128i *)&LC4);
*(_WORD *)(a1 + 16) = 10;
*(__m128i *)a1 = v1;
return sprintf((char *)a1, "%sServer: My Web Server\r\n", (const char *)a1);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__m128i v1; // xmm0

v1 = _mm_load_si128((const __m128i *)&LC4);
*(_WORD *)(a1 + 16) = 10;
*(__m128i *)a1 = v1;
return sprintf((char *)a1, "%sServer: My Web Server\r\n", (const char *)a1);
}

original_code:
void print_header_200(char *buf) {
 sprintf(buf, "HTTP/1.1 200 OK\r\n");
 sprintf(buf, "%sServer: My Web Server\r\n", buf);
}

variable_types:
buf
char *


decompiled_code:
// attributes: thunk
__int64 read_req_header()
{
return io_print_buf();
}

canonical_decompiled_code:
__int64 func3()
{
return io_print_buf();
}

original_code:
void read_req_header(io_t *io_buf) {
 io_print_buf(io_buf);
 return;
}

canonical_original_code:
void read_req_header(struct io_t *io_buf) {
 io_print_buf(io_buf);
 return;
}

variable_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; } *


decompiled_code:
__int64 __fastcall error_to_client(unsigned int a1, const char *a2, const char *a3, const char *a4, const char *a5)
{
size_t v8; // r12
size_t v9; // rax
__int128 v11[512]; // [rsp+0h] [rbp-4028h] BYREF
char s[8232]; // [rsp+2000h] [rbp-2028h] BYREF

v11[0] = (__int128)_mm_load_si128((const __m128i *)&LC12);
v11[1] = (__int128)_mm_load_si128((const __m128i *)&LC13);
sprintf((char *)v11, "%s\r\n", (const char *)v11);
sprintf((char *)v11, "%s%s: %s\r\n", (const char *)v11, a3, a4);
sprintf((char *)v11, "%s
%s: %s\r\n", (const char *)v11, a5, a2);
sprintf((char *)v11, "%s
The Tiny Web Server\r\n", (const char *)v11);
v8 = strlen((const char *)v11);
sprintf(s, "HTTP/1.1 %s %s\r\n", a3, a4);
sprintf(s, "%sContent-type: text/html\r\n", s);
sprintf(s, "%sContent-length: %d\r\n\r\n", s, (unsigned int)v8);
v9 = strlen(s);
io_writen(a1, s, v9);
return io_writen(a1, v11, v8);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const char *a2, const char *a3, const char *a4, const char *a5)
{
size_t v8; // r12
size_t v9; // rax
__int128 v11[512]; // [rsp+0h] [rbp-4028h] BYREF
char s[8232]; // [rsp+2000h] [rbp-2028h] BYREF

v11[0] = (__int128)_mm_load_si128((const __m128i *)&LC12);
v11[1] = (__int128)_mm_load_si128((const __m128i *)&LC13);
sprintf((char *)v11, "%s\r\n", (const char *)v11);
sprintf((char *)v11, "%s%s: %s\r\n", (const char *)v11, a3, a4);
sprintf((char *)v11, "%s
%s: %s\r\n", (const char *)v11, a5, a2);
sprintf((char *)v11, "%s
The Tiny Web Server\r\n", (const char *)v11);
v8 = strlen((const char *)v11);
sprintf(s, "HTTP/1.1 %s %s\r\n", a3, a4);
sprintf(s, "%sContent-type: text/html\r\n", s);
sprintf(s, "%sContent-length: %d\r\n\r\n", s, (unsigned int)v8);
v9 = strlen(s);
io_writen(a1, s, v9);
return io_writen(a1, v11, v8);
}

original_code:
void error_to_client(int connfd, char *cause, char *errnum, char *shortmsg, char *longmsg){
 char body[8192], buf[8192];
 int body_size = 0;
 sprintf(body, "<title>Tiny Error</title>");
 sprintf(body, "%s\r\n", body);
 sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
 sprintf(body, "%s
%s: %s\r\n", body, longmsg, cause);
 sprintf(body, "%s
The Tiny Web Server\r\n", body);
 body_size = (int)strlen(body);
 sprintf(buf, "HTTP/1.1 %s %s\r\n", errnum, shortmsg);
 sprintf(buf, "%sContent-type: text/html\r\n", buf);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, body_size);
 io_writen(connfd, buf, strlen(buf));
 io_writen(connfd, body, body_size);
}

canonical_original_code:
void error_to_client(int connfd, char *cause, char *errnum, char *shortmsg, char *longmsg){
 char body[8192]; char buf[8192];
 int body_size = 0;
 sprintf(body, "<title>Tiny Error</title>");
 sprintf(body, "%s\r\n", body);
 sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
 sprintf(body, "%s
%s: %s\r\n", body, longmsg, cause);
 sprintf(body, "%s
The Tiny Web Server\r\n", body);
 body_size = (int)strlen(body);
 sprintf(buf, "HTTP/1.1 %s %s\r\n", errnum, shortmsg);
 sprintf(buf, "%sContent-type: text/html\r\n", buf);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, body_size);
 io_writen(connfd, buf, strlen(buf));
 io_writen(connfd, body, body_size);
}

variable_types: connfd int

variable_types:
cause
char *

variable_types:
errnum
char *

variable_types:
shortmsg
char *

variable_types:
longmsg
char *

variable_types:
body
char [8192]

variable_types:
buf
char [8192]


decompiled_code:
__int64 __fastcall get_post_content(__int64 a1, __int64 a2)
{
int v2; // ebx
char *v3; // rax
__int16 v5; // [rsp+0h] [rbp-2018h] BYREF
char v6; // [rsp+2h] [rbp-2016h]

v2 = 0;
io_readlineb(a1, &v5, 0x2000LL);
while ( v5 != 2573 || v6 )
{
v3 = strchr((const char *)&v5, 32);
if ( v3 )
v2 = atoi(v3 + 1);
io_readlineb(a1, &v5, 0x2000LL);
}
return io_readnb(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
int v2; // ebx
char *v3; // rax
__int16 v5; // [rsp+0h] [rbp-2018h] BYREF
char v6; // [rsp+2h] [rbp-2016h]

v2 = 0;
io_readlineb(a1, &v5, 0x2000LL);
while ( v5 != 2573 || v6 )
{
v3 = strchr((const char *)&v5, 32);
if ( v3 )
v2 = atoi(v3 + 1);
io_readlineb(a1, &v5, 0x2000LL);
}
return io_readnb(a1, a2, v2);
}

original_code:
void get_post_content(io_t *io_buf, char *cgi_args) {
 char buf[8192];
 char *ptr;
 int content_len = 0;
 io_readlineb(io_buf, buf, 8192);
 while (strcmp(buf, "\r\n")) {
  ptr = strchr(buf, ' ');
  if (ptr) {
   content_len = atoi(ptr + 1);
  }
  io_readlineb(io_buf, buf, 8192);
 }
 io_readnb(io_buf, cgi_args, content_len);
}

canonical_original_code:
void get_post_content(struct io_t *io_buf, char *cgi_args) {
 char buf[8192];
 char *ptr;
 int content_len = 0;
 io_readlineb(io_buf, buf, 8192);
 while (strcmp(buf, "\r\n")) {
  ptr = strchr(buf, ' ');
  if (ptr) {
   content_len = atoi(ptr + 1);
  }
  io_readlineb(io_buf, buf, 8192);
 }
 io_readnb(io_buf, cgi_args, content_len);
}

variable_types:
ptr
char *

user_defined_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; }


decompiled_code:
__int64 __fastcall parse_uri(char *src, __int64 a2, _BYTE *a3, char *a4)
{
char *v6; // r8
__int64 result; // rax
char *v8; // rax
char *v9; // r14
char *v10; // rbx
size_t v11; // r8

v6 = strstr(src, "header");
result = 2LL;
if ( !v6 )
{
if ( strstr(src, "cgi-bin") )
{
v8 = index(src, 63);
v9 = v8;
if ( v8 )
{
strcpy(a4, v8 + 1);
*v9 = 0;
}
else
{
get_post_content(a2, (__int64)a4);
}
*a3 = 46;
strcpy(a3 + 1, src);
result = 0LL;
}
else
{
*a4 = 0;
*a3 = 46;
v10 = stpcpy(a3 + 1, src);
v11 = strlen(src);
result = 1LL;
if ( src[v11 - 1] == 47 )
strcpy(v10, "home.html");
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, __int64 a2, _BYTE *a3, char *a4)
{
char *v6; // r8
__int64 result; // rax
char *v8; // rax
char *v9; // r14
char *v10; // rbx
size_t v11; // r8

v6 = strstr(src, "header");
result = 2LL;
if ( !v6 )
{
if ( strstr(src, "cgi-bin") )
{
v8 = index(src, 63);
v9 = v8;
if ( v8 )
{
strcpy(a4, v8 + 1);
*v9 = 0;
}
else
{
func5(a2, (__int64)a4);
}
*a3 = 46;
strcpy(a3 + 1, src);
result = 0LL;
}
else
{
*a4 = 0;
*a3 = 46;
v10 = stpcpy(a3 + 1, src);
v11 = strlen(src);
result = 1LL;
if ( src[v11 - 1] == 47 )
strcpy(v10, "home.html");
}
}
return result;
}

original_code:
int parse_uri(char *uri, io_t *io_buf, char *filename, char *cgi_args) {
 char * ptr;
 if (strstr(uri, "header")) {
  return 2;
 }
 else if (!strstr(uri, "cgi-bin")) {
  strcpy(cgi_args, "");
  strcpy(filename, ".");
  strcat(filename, uri);
  if (uri[strlen(uri)-1] == '/')
   strcat(filename, "home.html");
  return 1;
 }
 else {
  ptr = index(uri, '?');
  if (ptr) {
   strcpy(cgi_args, ptr+1);
   *ptr = '\0';
  }
  else {
   get_post_content(io_buf, cgi_args);
  }
  strcpy(filename, ".");
  strcat(filename, uri);
  return 0;
 }
}

canonical_original_code:
int parse_uri(char *uri, struct io_t *io_buf, char *filename, char *cgi_args) {
 char *ptr;
 if (strstr(uri, "header")) {
  return 2;
 }
 else if (!strstr(uri, "cgi-bin")) {
  strcpy(cgi_args, "");
  strcpy(filename, ".");
  strcat(filename, uri);
  if (uri[strlen(uri)-1] == '/')
   strcat(filename, "home.html");
  return 1;
 }
 else {
  ptr = index(uri, '?');
  if (ptr) {
   strcpy(cgi_args, ptr+1);
   *ptr = '\0';
  }
  else {
   get_post_content(io_buf, cgi_args);
  }
  strcpy(filename, ".");
  strcat(filename, uri);
  return 0;
 }
}

variable_types:
uri
char *

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall get_file_type(char *haystack, char *a2)
{
__int64 result; // rax

if ( strstr(haystack, ".html") )
{
result = 0x6D74682F74786574LL;
strcpy(a2, "text/html");
}
else if ( strstr(haystack, ".jpg") )
{
result = 0x706A2F6567616D69LL;
strcpy(a2, "image/jpeg");
}
else if ( strstr(haystack, ".gif") )
{
result = 0x69672F6567616D69LL;
strcpy(a2, "image/gif");
}
else
{
strcpy(a2, "text/plain");
result = 28265LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *haystack, char *a2)
{
__int64 result; // rax

if ( strstr(haystack, ".html") )
{
result = 0x6D74682F74786574LL;
strcpy(a2, "text/html");
}
else if ( strstr(haystack, ".jpg") )
{
result = 0x706A2F6567616D69LL;
strcpy(a2, "image/jpeg");
}
else if ( strstr(haystack, ".gif") )
{
result = 0x69672F6567616D69LL;
strcpy(a2, "image/gif");
}
else
{
strcpy(a2, "text/plain");
result = 28265LL;
}
return result;
}

original_code:
void get_file_type(char *filename, char *filetype) {
 if (strstr(filename, ".html"))
  strcpy(filetype, "text/html");
 else if (strstr(filename, ".jpg"))
  strcpy(filetype, "image/jpeg");
 else if (strstr(filename, ".gif"))
  strcpy(filetype, "image/gif");
 else
  strcpy(filetype, "text/plain");
}

variable_types:
filetype
char *


decompiled_code:
int __fastcall serve_static(unsigned int a1, char *a2, int a3)
{
size_t v3; // r12
size_t v4; // rax
unsigned int v5; // er13
void *v6; // rbp
char v8[8192]; // [rsp+0h] [rbp-4028h] BYREF
char v9[8232]; // [rsp+2000h] [rbp-2028h] BYREF

v3 = a3;
get_file_type(a2, v9);
print_header_200((__int64)v8);
sprintf(v8, "%sContent-type: %s\r\n", v8, v9);
sprintf(v8, "%sContent-length: %d\r\n\r\n", v8, (unsigned int)v3);
v4 = strlen(v8);
io_writen(a1, v8, v4);
v5 = open(a2, 0, 0LL);
v6 = malloc(v3);
io_readn(v5, v6, v3);
io_writen(a1, v6, v3);
free(v6);
return close(v5);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, char *a2, int a3)
{
size_t v3; // r12
size_t v4; // rax
unsigned int v5; // er13
void *v6; // rbp
char v8[8192]; // [rsp+0h] [rbp-4028h] BYREF
char v9[8232]; // [rsp+2000h] [rbp-2028h] BYREF

v3 = a3;
func7(a2, v9);
func2((__int64)v8);
sprintf(v8, "%sContent-type: %s\r\n", v8, v9);
sprintf(v8, "%sContent-length: %d\r\n\r\n", v8, (unsigned int)v3);
v4 = strlen(v8);
io_writen(a1, v8, v4);
v5 = open(a2, 0, 0LL);
v6 = malloc(v3);
io_readn(v5, v6, v3);
io_writen(a1, v6, v3);
free(v6);
return close(v5);
}

original_code:
void serve_static(int connfd, char *filename, int filesize) {
 char buf[8192], filetype[8192];
 char * srcp;
 int filefd;
 get_file_type(filename, filetype);
 print_header_200(buf);
 sprintf(buf, "%sContent-type: %s\r\n", buf, filetype);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, filesize);
 io_writen(connfd, buf, strlen(buf));
 filefd = open(filename, 00, 0);
 srcp = malloc(filesize);
 io_readn(filefd, srcp, filesize);
 io_writen(connfd, srcp, filesize);
 free(srcp);
 close(filefd);
}

canonical_original_code:
void serve_static(int connfd, char *filename, int filesize) {
 char buf[8192]; char filetype[8192];
 char *srcp;
 int filefd;
 get_file_type(filename, filetype);
 print_header_200(buf);
 sprintf(buf, "%sContent-type: %s\r\n", buf, filetype);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, filesize);
 io_writen(connfd, buf, strlen(buf));
 filefd = open(filename, 00, 0);
 srcp = malloc(filesize);
 io_readn(filefd, srcp, filesize);
 io_writen(connfd, srcp, filesize);
 free(srcp);
 close(filefd);
}

variable_types: filesize int

variable_types:
filetype
char [8192]

variable_types:
srcp
char *

variable_types: filefd int


decompiled_code:
__pid_t __fastcall serve_dynamic(int fd, char *path, char *value)
{
size_t v4; // rax
__pid_t result; // eax
char *argv; // [rsp+8h] [rbp-2020h] BYREF
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

argv = 0LL;
print_header_200((__int64)s);
v4 = strlen(s);
io_writen((unsigned int)fd, s, v4);
result = fork();
if ( !result )
{
setenv("QUERY_STRING", value, 1);
dup2(fd, 1);
result = execve(path, &argv, _environ);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func9(int fd, char *path, char *value)
{
size_t v4; // rax
__pid_t result; // eax
char *argv; // [rsp+8h] [rbp-2020h] BYREF
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

argv = 0LL;
func2((__int64)s);
v4 = strlen(s);
io_writen((unsigned int)fd, s, v4);
result = fork();
if ( !result )
{
setenv("QUERY_STRING", value, 1);
dup2(fd, 1);
result = execve(path, &argv, _environ);
}
return result;
}

original_code:
void serve_dynamic(int connfd, char *filename, char *cgi_args) {
 char buf[8192], *emptylist[] = { ((void *)0) };
 print_header_200(buf);
 io_writen(connfd, buf, strlen(buf));
 if (fork() == 0) {
  setenv("QUERY_STRING", cgi_args, 1);
  dup2(connfd, 1);
  execve(filename, emptylist, __environ);
 }
}

canonical_original_code:
void serve_dynamic(int connfd, char *filename, char *cgi_args) {
 char buf[8192]; char *emptylist[] = { ((void *)0) };
 print_header_200(buf);
 io_writen(connfd, buf, strlen(buf));
 if (fork() == 0) {
  setenv("QUERY_STRING", cgi_args, 1);
  dup2(connfd, 1);
  execve(filename, emptylist, __environ);
 }
}

variable_types:
emptylist
char *[]


decompiled_code:
__int64 __fastcall serve_header(unsigned int a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // rcx
char *v4; // rax
unsigned int v5; // ebx
size_t v6; // rax
size_t v7; // rax
char v9[8192]; // [rsp+0h] [rbp-4018h] BYREF
char s[8216]; // [rsp+2000h] [rbp-2018h] BYREF

v2 = (const char *)(a2 + 16);
s[0] = 0;
while ( 1 )
{
v4 = strchr(v2, 10);
if ( !v4 )
break;
*v4 = 0;
v3 = v2;
v2 = v4 + 1;
sprintf(s, "%s<p>%s", s, v3);
}
v5 = strlen(s);
print_header_200((__int64)v9);
sprintf(v9, "%sContent-type: text/html\r\n", v9);
sprintf(v9, "%sContent-length: %d\r\n\r\n", v9, v5);
v6 = strlen(v9);
io_writen(a1, v9, v6);
v7 = strlen(s);
return io_writen(a1, s, v7);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // rcx
char *v4; // rax
unsigned int v5; // ebx
size_t v6; // rax
size_t v7; // rax
char v9[8192]; // [rsp+0h] [rbp-4018h] BYREF
char s[8216]; // [rsp+2000h] [rbp-2018h] BYREF

v2 = (const char *)(a2 + 16);
s[0] = 0;
while ( 1 )
{
v4 = strchr(v2, 10);
if ( !v4 )
break;
*v4 = 0;
v3 = v2;
v2 = v4 + 1;
sprintf(s, "%s<p>%s", s, v3);
}
v5 = strlen(s);
func2((__int64)v9);
sprintf(v9, "%sContent-type: text/html\r\n", v9);
sprintf(v9, "%sContent-length: %d\r\n\r\n", v9, v5);
v6 = strlen(v9);
io_writen(a1, v9, v6);
v7 = strlen(s);
return io_writen(a1, s, v7);
}

original_code:
void serve_header(int connfd, io_t *io_buf) {
 char buf[8192], content[8192];
 char *ptr_end, *ptr_start = io_buf->io_buf;
 int header_size = 0;
 content[0] = 0;
 while((ptr_end = strchr(ptr_start, '\n')) != ((void *)0)) {
  *ptr_end = 0;
  sprintf(content, "%s<p>%s", content, ptr_start);
  ptr_start = ptr_end + 1;
 }
 header_size = strlen(content);
 print_header_200(buf);
 sprintf(buf, "%sContent-type: text/html\r\n", buf);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, header_size);
 io_writen(connfd, buf, strlen(buf));
 io_writen(connfd, content, strlen(content));
}

canonical_original_code:
void serve_header(int connfd, struct io_t *io_buf) {
 char buf[8192]; char content[8192];
 char *ptr_end; char *ptr_start = io_buf->io_buf;
 int header_size = 0;
 content[0] = 0;
 while((ptr_end = strchr(ptr_start, '\n')) != ((void *)0)) {
  *ptr_end = 0;
  sprintf(content, "%s<p>%s", content, ptr_start);
  ptr_start = ptr_end + 1;
 }
 header_size = strlen(content);
 print_header_200(buf);
 sprintf(buf, "%sContent-type: text/html\r\n", buf);
 sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, header_size);
 io_writen(connfd, buf, strlen(buf));
 io_writen(connfd, content, strlen(content));
}

variable_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; } *

variable_types:
content
char [8192]


decompiled_code:
int __fastcall check_req(__int64 a1, __int64 a2)
{
int result; // eax

_isoc99_sscanf(a1, "%s %s %s", a2 + 1024, a2, a2 + 1034);
result = strcasecmp((const char *)(a2 + 1024), "POST");
if ( result )
result = -(strcasecmp((const char *)(a2 + 1024), "GET") != 0);
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, __int64 a2)
{
int result; // eax

_isoc99_sscanf(a1, "%s %s %s", a2 + 1024, a2, a2 + 1034);
result = strcasecmp((const char *)(a2 + 1024), "POST");
if ( result )
result = -(strcasecmp((const char *)(a2 + 1024), "GET") != 0);
return result;
}

original_code:
int check_req(char * req_line, req_line_t * req_line_ptr) {
 char * method_p = (char *)&req_line_ptr->method;
 char * uri_p = (char *)&req_line_ptr->uri;
 char * version_p = (char *)&req_line_ptr->version;
 sscanf(req_line, "%s %s %s", method_p, uri_p, version_p);
 if (!strcasecmp(method_p, "POST")) {
 }
 else if (strcasecmp(method_p, "GET")) {
  return -1;
 }
 return 0;
}

canonical_original_code:
int check_req(char *req_line, struct req_line_t *req_line_ptr) {
 char *method_p = (char *)&req_line_ptr->method;
 char *uri_p = (char *)&req_line_ptr->uri;
 char *version_p = (char *)&req_line_ptr->version;
 sscanf(req_line, "%s %s %s", method_p, uri_p, version_p);
 if (!strcasecmp(method_p, "POST")) {
 }
 else if (strcasecmp(method_p, "GET")) {
  return -1;
 }
 return 0;
}

variable_types: struct req_line_t { char uri[1024]; char method[10]; char version[10]; } *


decompiled_code:
int __fastcall print_req(const char *a1)
{
return printf("%s %s %s\n", a1 + 1024, a1, a1 + 1034);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
return printf("%s %s %s\n", a1 + 1024, a1, a1 + 1034);
}

original_code:
void print_req(req_line_t * req_ptr) {
 printf("%s %s %s\n", req_ptr->method, req_ptr->uri, req_ptr->version);
}

canonical_original_code:
void print_req(struct req_line_t *req_ptr) {
 printf("%s %s %s\n", req_ptr->method, req_ptr->uri, req_ptr->version);
}

user_defined_types: struct req_line_t { char uri[1024]; char method[10]; char version[10]; }


decompiled_code:
int __fastcall process_req(int fd)
{
int result; // eax
const char *v2; // r8
struct stat v3; // [rsp+0h] [rbp-84C8h] BYREF
char src[1024]; // [rsp+90h] [rbp-8438h] BYREF
char v5[32]; // [rsp+490h] [rbp-8038h] BYREF
char v6[8192]; // [rsp+4B0h] [rbp-8018h] BYREF
char file[8192]; // [rsp+24B0h] [rbp-6018h] BYREF
char value[8192]; // [rsp+44B0h] [rbp-4018h] BYREF
char v9[8216]; // [rsp+64B0h] [rbp-2018h] BYREF

io_initbuf(v9, (unsigned int)fd);
io_readlineb(v9, v6, 0x2000LL);
if ( check_req((__int64)v6, (__int64)src) )
return error_to_client(fd, v5, "501", "Not Implemented", "Server does not implement this method");
result = parse_uri(src, (__int64)v9, file, value);
switch ( result )
{
case 1:
if ( !stat(file, &v3) )
{
if ( (v3.st_mode & 0xF100) == 33024 )
return serve_static(fd, file, v3.st_size);
v2 = "File can't read";
return error_to_client(fd, file, "403", "Forbidden", v2);
}
return error_to_client(fd, file, "404", "Not Found", "File not found");
case 2:
return serve_header(fd, (__int64)v9);
case 0:
if ( !stat(file, &v3) )
{
v2 = "CGI program can't run";
if ( (v3.st_mode & 0xF040) == 32832 )
return serve_dynamic(fd, file, value);
return error_to_client(fd, file, "403", "Forbidden", v2);
}
return error_to_client(fd, file, "404", "Not Found", "File not found");
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(int fd)
{
int result; // eax
const char *v2; // r8
struct stat v3; // [rsp+0h] [rbp-84C8h] BYREF
char src[1024]; // [rsp+90h] [rbp-8438h] BYREF
char v5[32]; // [rsp+490h] [rbp-8038h] BYREF
char v6[8192]; // [rsp+4B0h] [rbp-8018h] BYREF
char file[8192]; // [rsp+24B0h] [rbp-6018h] BYREF
char value[8192]; // [rsp+44B0h] [rbp-4018h] BYREF
char v9[8216]; // [rsp+64B0h] [rbp-2018h] BYREF

io_initbuf(v9, (unsigned int)fd);
io_readlineb(v9, v6, 0x2000LL);
if ( func11((__int64)v6, (__int64)src) )
return func4(fd, v5, "501", "Not Implemented", "Server does not implement this method");
result = func6(src, (__int64)v9, file, value);
switch ( result )
{
case 1:
if ( !stat(file, &v3) )
{
if ( (v3.st_mode & 0xF100) == 33024 )
return func8(fd, file, v3.st_size);
v2 = "File can't read";
return func4(fd, file, "403", "Forbidden", v2);
}
return func4(fd, file, "404", "Not Found", "File not found");
case 2:
return func10(fd, (__int64)v9);
case 0:
if ( !stat(file, &v3) )
{
v2 = "CGI program can't run";
if ( (v3.st_mode & 0xF040) == 32832 )
return func9(fd, file, value);
return func4(fd, file, "403", "Forbidden", v2);
}
return func4(fd, file, "404", "Not Found", "File not found");
}
return result;
}

original_code:
void process_req(int connfd) {
 int req_type;
 io_t io_buf;
 req_line_t req_line;
 char buf[8192];
 char filename[8192], cgi_args[8192];
 struct stat file_stat;
 io_initbuf(&io_buf, connfd);
 io_readlineb(&io_buf, buf, 8192);
 if (check_req((char *)&buf, &req_line)) {
  error_to_client(connfd, (char *)&(req_line.method), "501", "Not Implemented",
    "Server does not implement this method");
  return;
 }
 req_type = parse_uri((char *)&req_line.uri, &io_buf, filename, cgi_args);
 switch(req_type) {
 case 0:
  if (stat(filename, &file_stat)) {
   error_to_client(connfd, filename, "404", "Not Found",
     "File not found");
   return;
  }
  if (!(((((file_stat.st_mode)) & 0170000) == (0100000))) || !(0100 & file_stat.st_mode)) {
   error_to_client(connfd, filename, "403", "Forbidden",
     "CGI program can't run");
   return;
  }
  serve_dynamic(connfd, filename, cgi_args);
  break;
 case 1:
  if (stat(filename, &file_stat)) {
   error_to_client(connfd, filename, "404", "Not Found",
     "File not found");
   return;
  }
  if (!(((((file_stat.st_mode)) & 0170000) == (0100000))) || !(0400 & file_stat.st_mode)) {
   error_to_client(connfd, filename, "403", "Forbidden",
     "File can't read");
   return;
  }
  serve_static(connfd, filename, file_stat.st_size);
  break;
 case 2:
  serve_header(connfd, &io_buf);
  break;
 }
}

canonical_original_code:
void process_req(int connfd) {
 int req_type;
 struct io_t io_buf;
 struct req_line_t req_line;
 char buf[8192];
 char filename[8192]; char cgi_args[8192];
 struct stat file_stat;
 io_initbuf(&io_buf, connfd);
 io_readlineb(&io_buf, buf, 8192);
 if (check_req((char *)&buf, &req_line)) {
  error_to_client(connfd, (char *)&(req_line.method), "501", "Not Implemented",
    "Server does not implement this method");
  return;
 }
 req_type = parse_uri((char *)&req_line.uri, &io_buf, filename, cgi_args);
 switch(req_type) {
 case 0:
  if (stat(filename, &file_stat)) {
   error_to_client(connfd, filename, "404", "Not Found",
     "File not found");
   return;
  }
  if (!(((((file_stat.st_mode)) & 0170000) == (0100000))) || !(0100 & file_stat.st_mode)) {
   error_to_client(connfd, filename, "403", "Forbidden",
     "CGI program can't run");
   return;
  }
  serve_dynamic(connfd, filename, cgi_args);
  break;
 case 1:
  if (stat(filename, &file_stat)) {
   error_to_client(connfd, filename, "404", "Not Found",
     "File not found");
   return;
  }
  if (!(((((file_stat.st_mode)) & 0170000) == (0100000))) || !(0400 & file_stat.st_mode)) {
   error_to_client(connfd, filename, "403", "Forbidden",
     "File can't read");
   return;
  }
  serve_static(connfd, filename, file_stat.st_size);
  break;
 case 2:
  serve_header(connfd, &io_buf);
  break;
 }
}

variable_types: connfd int

variable_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; }

variable_types: struct req_line_t { char uri[1024]; char method[10]; char version[10]; }

variable_types:
filename
char [8192]

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:
char *__fastcall get_arg_value(const char *a1)
{
char *v1; // rax

v1 = strchr(a1, 61);
return &v1[-(v1 == 0LL) + 1];
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *v1; // rax

v1 = strchr(a1, 61);
return &v1[-(v1 == 0LL) + 1];
}

original_code:
char * get_arg_value(char * arg) {
 char * ptr = ((void *)0);
 if ((ptr = strchr(arg, '=')) != ((void *)0)) {
  return ptr + 1;
 }
 return ((void *)0);
}

canonical_original_code:
char *get_arg_value(char *arg) {
 char *ptr = ((void *)0);
 if ((ptr = strchr(arg, '=')) != ((void *)0)) {
  return ptr + 1;
 }
 return ((void *)0);
}

variable_types:
arg
char *

variable_types:
ptr
char *

return_type: char *