usage

decompiled_code:
int usage()
{
puts("usbdump Copyright (C) 2011 Bert Vermeulen <bert@biot.com>");
return puts("usage: usbdump [-d <vid:pid>] [-u <num lines>] [-b <bus number>]");
}

canonical_decompiled_code:
int func5()
{
puts("usbdump Copyright (C) 2011 Bert Vermeulen <bert@biot.com>");
return puts("usage: usbdump [-d <vid:pid>] [-u <num lines>] [-b <bus number>]");
}

original_code:
void
usage(void)
{
 printf("usbdump Copyright (C) 2011 Bert Vermeulen <bert@biot.com>\n");
 printf("usage: usbdump [-d <vid:pid>] [-u <num lines>] [-b <bus number>]\n");
}

canonical_original_code:
void usage()
{
 printf("usbdump Copyright (C) 2011 Bert Vermeulen <bert@biot.com>\n");
 printf("usage: usbdump [-d <vid:pid>] [-u <num lines>] [-b <bus number>]\n");
}


main

canonical_name: main

repo: walimis/usbdump

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
char *v4; // r12
int v5; // eax
unsigned int v6; // edi
int result; // eax
int v8; // [rsp+8h] [rbp-30h] BYREF
unsigned int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v8 = 0;
v3 = 0LL;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "d:u:b:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'd':
v4 = optarg;
if ( strlen(optarg) == 9 && strspn(v4, "01234567890abcdef:") == 9 )
v3 = (__int64)v4;
else
puts("invalid format for device id (aaaa:bbbb)");
break;
case 'u':
opt_unique_num = strtol(optarg, 0LL, 10);
break;
case 'b':
opt_bus_num = strtol(optarg, 0LL, 10);
break;
}
}
if ( !v3 )
{
v6 = opt_bus_num;
if ( opt_bus_num == -1 )
{
usage();
return 1;
}
goto LABEL_14;
}
v6 = opt_bus_num;
if ( opt_bus_num != -1 )
{
LABEL_14:
v9[0] = v6;
usb_sniff(v6, v8);
return 0;
}
result = find_device(v3, v9, &v8);
if ( result )
{
usb_sniff(v9[0], v8);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
char *v4; // r12
int v5; // eax
unsigned int v6; // edi
int result; // eax
int v8; // [rsp+8h] [rbp-30h] BYREF
unsigned int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v8 = 0;
v3 = 0LL;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "d:u:b:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'd':
v4 = optarg;
if ( strlen(optarg) == 9 && strspn(v4, "01234567890abcdef:") == 9 )
v3 = (__int64)v4;
else
puts("invalid format for device id (aaaa:bbbb)");
break;
case 'u':
opt_unique_num = strtol(optarg, 0LL, 10);
break;
case 'b':
opt_bus_num = strtol(optarg, 0LL, 10);
break;
}
}
if ( !v3 )
{
v6 = opt_bus_num;
if ( opt_bus_num == -1 )
{
func5();
return 1;
}
goto LABEL_14;
}
v6 = opt_bus_num;
if ( opt_bus_num != -1 )
{
LABEL_14:
v9[0] = v6;
func2(v6, v8);
return 0;
}
result = func4(v3, v9, &v8);
if ( result )
{
func2(v9[0], v8);
result = 0;
}
return result;
}

original_code:
int
main(int argc, char **argv)
{
 int opt, bus, address = 0;
 char *device, *entry;
 device = ((void *)0);
 while ((opt = getopt(argc, argv, "d:u:b:")) != -1) {
  switch (opt) {
  case 'd':
   if (strlen(optarg) != 9
       || strspn(optarg, "01234567890abcdef:") != 9)
    printf("invalid format for device id (aaaa:bbbb)\n");
   else
    device = optarg;
   break;
  case 'u':
   opt_unique_num = strtol(optarg, ((void *)0), 10);
   break;
  case 'b':
   opt_bus_num = strtol(optarg, ((void *)0), 10);
   break;
  }
 }
 if (!device && opt_bus_num == -1) {
  usage();
  return 1;
 }
 if (opt_bus_num != -1) {
  bus = opt_bus_num;
  usb_sniff(bus, address);
 } else if (find_device(device, &bus, &address)) {
  usb_sniff(bus, address);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int opt; int bus; int address = 0;
 char *device; char *entry;
 device = ((void *)0);
 while ((opt = getopt(argc, argv, "d:u:b:")) != -1) {
  switch (opt) {
  case 'd':
   if (strlen(optarg) != 9
       || strspn(optarg, "01234567890abcdef:") != 9)
    printf("invalid format for device id (aaaa:bbbb)\n");
   else
    device = optarg;
   break;
  case 'u':
   opt_unique_num = strtol(optarg, ((void *)0), 10);
   break;
  case 'b':
   opt_bus_num = strtol(optarg, ((void *)0), 10);
   break;
  }
 }
 if (!device && opt_bus_num == -1) {
  usage();
  return 1;
 }
 if (opt_bus_num != -1) {
  bus = opt_bus_num;
  usb_sniff(bus, address);
 } else if (find_device(device, &bus, &address)) {
  usb_sniff(bus, address);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: bus int

variable_types: address int

variable_types:
device
char *

variable_types:
entry
char *

return_type: int


repo: wallymathieu/bbcode-c

decompiled_code:
__int64 __fastcall bbcode_q_find_last(__int64 a1, int a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er13

if ( a2 < 0 )
return (unsigned int)-1;
v4 = a2;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(a1 + 8 * v4), a3) )
break;
if ( (int)--v4 < 0 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er13

if ( a2 < 0 )
return (unsigned int)-1;
v4 = a2;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(a1 + 8 * v4), a3) )
break;
if ( (int)--v4 < 0 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int bbcode_q_find_last(const char* queue[], const int length, const char* element)
{
    int i;
    for(i = length; i>=0;i--)
    {if (!strcmp(queue[i],element)) return i;}
    return -1;
}

canonical_original_code:
int bbcode_q_find_last(char *queue[], int length, char *element)
{
    int i;
    for(i = length; i>=0;i--)
    {if (!strcmp(queue[i],element)) return i;}
    return -1;
}

variable_types:
queue
char *[]

variable_types: length int

variable_types:
element
char *

variable_types: i int


decompiled_code:
__int64 __fastcall bbcode_q_add(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 result; // rax

LODWORD(result) = *a2 + 1;
*a2 = result;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 result; // rax

LODWORD(result) = *a2 + 1;
*a2 = result;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a3;
return result;
}

original_code:
void bbcode_q_add(const char* queue[], int* index, const char* element)
{
    queue[++(*index)]=element;
}

canonical_original_code:
void bbcode_q_add(char *queue[], int *index, char *element)
{
    queue[++(*index)]=element;
}

variable_types:
index
int *

return_type: void


decompiled_code:
__int64 __fastcall bbcode_find_tag_index(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp((const char *)*(&BBTAGS + v1), s2) )
break;
if ( ++v1 == 5 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp((const char *)*(&BBTAGS + v1), s2) )
break;
if ( ++v1 == 5 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int bbcode_find_tag_index(const char* tag)
{
    int i;
    for(i = 0;i<NUM_BBTAGS;i++) {if (!strcmp(BBTAGS[i],tag)) return i;}
    return -1;
}

canonical_original_code:
int bbcode_find_tag_index(char *tag)
{
    int i;
    for(i = 0;i<NUM_BBTAGS;i++) {if (!strcmp(BBTAGS[i],tag)) return i;}
    return -1;
}

variable_types:
tag
char *


decompiled_code:
__int64 __fastcall bbcode_get_htmltag(char *a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = bbcode_find_tag_index(a1);
v2 = 0LL;
if ( v1 >= 0 )
v2 = (__int64)*(&HTMLTAGS + v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = func2(a1);
v2 = 0LL;
if ( v1 >= 0 )
v2 = (__int64)*(&HTMLTAGS + v1);
return v2;
}

original_code:
char* bbcode_get_htmltag(const char* tag)
{
    int idx = bbcode_find_tag_index(tag);
    if (idx>=0)
        return HTMLTAGS[idx];
    return ((void *)0);
}

canonical_original_code:
char *bbcode_get_htmltag(char *tag)
{
    int idx = bbcode_find_tag_index(tag);
    if (idx>=0)
        return HTMLTAGS[idx];
    return ((void *)0);
}

variable_types: idx int

return_type: char *


decompiled_code:
__int64 __fastcall bbcode_find_color_index(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp(COLORNAMES[v1], s2) )
break;
if ( ++v1 == 18 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp(COLORNAMES[v1], s2) )
break;
if ( ++v1 == 18 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int bbcode_find_color_index(const char* attr)
{
    int i;
    for(i = 0;i<NUM_COLORS;i++) {if (!strcmp(COLORNAMES[i],attr)) return i;}
    return -1;
}

canonical_original_code:
int bbcode_find_color_index(char *attr)
{
    int i;
    for(i = 0;i<NUM_COLORS;i++) {if (!strcmp(COLORNAMES[i],attr)) return i;}
    return -1;
}

variable_types:
attr
char *


decompiled_code:
char *__fastcall bbcode_get_colorcode(char *a1)
{
int v1; // eax
char *v2; // rdx

v1 = bbcode_find_color_index(a1);
v2 = 0LL;
if ( v1 >= 0 )
v2 = COLORCODES[v1];
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *a1)
{
int v1; // eax
char *v2; // rdx

v1 = func4(a1);
v2 = 0LL;
if ( v1 >= 0 )
v2 = COLORCODES[v1];
return v2;
}

original_code:
char* bbcode_get_colorcode(const char* attr)
{
    int idx = bbcode_find_color_index(attr);
    if (idx>=0)
        return COLORCODES[idx];
    return ((void *)0);
}

canonical_original_code:
char *bbcode_get_colorcode(char *attr)
{
    int idx = bbcode_find_color_index(attr);
    if (idx>=0)
        return COLORCODES[idx];
    return ((void *)0);
}


require

decompiled_code:
void __fastcall require(int a1, const char *a2)
{
if ( !a1 )
{
printf("Fail message: %s\n", a2);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func6(int a1, const char *a2)
{
if ( !a1 )
{
printf("Fail message: %s\n", a2);
exit(1);
}
}

original_code:
void require(int val, char* txt)
{
    if (!val)
    {
        printf("Fail message: %s\n",txt);
        exit(1);
    }
}

canonical_original_code:
void require(int val, char *txt)
{
    if (!val)
    {
        printf("Fail message: %s\n",txt);
        exit(1);
    }
}

variable_types: val int

variable_types:
txt
char *


decompiled_code:
__int64 __fastcall bbcode_get_attribute_type(char *s2)
{
int v1; // ecx
__int64 result; // rax
char *v3; // rdx
char *v4; // rsi
char v5; // cl
char *v6; // rcx
bool v7; // r8

v1 = strlen(s2);
result = 3LL;
if ( v1 )
{
if ( *s2 == 35 )
{
result = 0LL;
if ( v1 == 6 )
{
v6 = s2;
LOBYTE(result) = 1;
do
{
v7 = 1;
if ( (unsigned __int8)((*v6 & 0xDF) - 65) > 0x19u )
v7 = (unsigned int)(*v6 - 48) <= 9;
LOBYTE(result) = v7 & result;
++v6;
}
while ( v6 != s2 + 6 );
result = (unsigned __int8)result;
}
}
else
{
if ( v1 <= 0 )
goto LABEL_7;
v3 = s2;
v4 = &s2[v1 - 1 + 1];
v5 = 1;
do
v5 &= (unsigned __int8)((*v3++ & 0xDF) - 65) <= 0x19u;
while ( v3 != v4 );
result = 0LL;
if ( v5 )
LABEL_7:
result = 2 * (unsigned int)((int)bbcode_find_color_index(s2) >= 0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
int v1; // ecx
__int64 result; // rax
char *v3; // rdx
char *v4; // rsi
char v5; // cl
char *v6; // rcx
bool v7; // r8

v1 = strlen(s2);
result = 3LL;
if ( v1 )
{
if ( *s2 == 35 )
{
result = 0LL;
if ( v1 == 6 )
{
v6 = s2;
LOBYTE(result) = 1;
do
{
v7 = 1;
if ( (unsigned __int8)((*v6 & 0xDF) - 65) > 0x19u )
v7 = (unsigned int)(*v6 - 48) <= 9;
LOBYTE(result) = v7 & result;
++v6;
}
while ( v6 != s2 + 6 );
result = (unsigned __int8)result;
}
}
else
{
if ( v1 <= 0 )
goto LABEL_7;
v3 = s2;
v4 = &s2[v1 - 1 + 1];
v5 = 1;
do
v5 &= (unsigned __int8)((*v3++ & 0xDF) - 65) <= 0x19u;
while ( v3 != v4 );
result = 0LL;
if ( v5 )
LABEL_7:
result = 2 * (unsigned int)((int)func4(s2) >= 0);
}
}
return result;
}

original_code:
enum bbcode_attribute_type bbcode_get_attribute_type(const char* attr)
{
    int attr_len = strlen(attr);
    if (attr_len == 0) return empty;
    if (attr[0] == '#')
    {
        if (attr_len != 6)
            return invalid;
        _Bool allLettersAndDigits = 1;
        int i;
        for (i = 0; i < attr_len; i++)
        {
            int val = attr[i];
            allLettersAndDigits &= ((val>='a'&&val<='z')||(val>='A'&&val<='Z')||(val>='0'&&val<='9'));
        }
        if (!allLettersAndDigits) return invalid;
        return colorcode;
    }
    else
    {
        _Bool allLetters = 1;
        int i;
        for (i = 0; i < attr_len; i++)
        {
            int val = attr[i];
            allLetters &= ((val>='a'&&val<='z')||(val>='A'&&val<='Z'));
        }
        if (!allLetters) return invalid;
        int coloridx = bbcode_find_color_index(attr);
        if (coloridx < 0) return invalid;
        return colorname;
    }
}

canonical_original_code:
enum bbcode_attribute_type bbcode_get_attribute_type(char *attr)
{
    int attr_len = strlen(attr);
    if (attr_len == 0) return empty;
    if (attr[0] == '#')
    {
        if (attr_len != 6)
            return invalid;
        _Bool allLettersAndDigits = 1;
        int i;
        for (i = 0; i < attr_len; i++)
        {
            int val = attr[i];
            allLettersAndDigits &= ((val>='a'&&val<='z')||(val>='A'&&val<='Z')||(val>='0'&&val<='9'));
        }
        if (!allLettersAndDigits) return invalid;
        return colorcode;
    }
    else
    {
        _Bool allLetters = 1;
        int i;
        for (i = 0; i < attr_len; i++)
        {
            int val = attr[i];
            allLetters &= ((val>='a'&&val<='z')||(val>='A'&&val<='Z'));
        }
        if (!allLetters) return invalid;
        int coloridx = bbcode_find_color_index(attr);
        if (coloridx < 0) return invalid;
        return colorname;
    }
}

variable_types: coloridx int

return_type: enum bbcode_attribute_type { invalid=0, colorcode=1, colorname=2, empty=3 }


decompiled_code:
size_t __fastcall bbcode_render_attribute(char *dest, const char *a2, char *a3, int a4)
{
size_t result; // rax

result = (unsigned int)a4;
if ( !strcmp(a2, "color") )
{
if ( a4 == 2 )
{
result = bbcode_find_color_index(a3);
if ( (result & 0x80000000) == 0LL )
{
strcat(dest, " style=\"color:#");
strcat(dest, COLORCODES[(int)result]);
result = strlen(dest);
strcpy(&dest[result], "\" ");
}
}
else
{
if ( a4 <= 2 )
{
if ( !a4 )
exit(1);
if ( a4 == 1 )
{
strcat(dest, " style=\"color:");
strcat(dest, a3);
result = strlen(dest);
strcpy(&dest[result], "\" ");
return result;
}
LABEL_12:
printf(" Type: '%d'\n", (unsigned int)a4);
exit(1);
}
if ( a4 != 3 )
goto LABEL_12;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(char *dest, const char *a2, char *a3, int a4)
{
size_t result; // rax

result = (unsigned int)a4;
if ( !strcmp(a2, "color") )
{
if ( a4 == 2 )
{
result = func4(a3);
if ( (result & 0x80000000) == 0LL )
{
strcat(dest, " style=\"color:#");
strcat(dest, COLORCODES[(int)result]);
result = strlen(dest);
strcpy(&dest[result], "\" ");
}
}
else
{
if ( a4 <= 2 )
{
if ( !a4 )
exit(1);
if ( a4 == 1 )
{
strcat(dest, " style=\"color:");
strcat(dest, a3);
result = strlen(dest);
strcpy(&dest[result], "\" ");
return result;
}
LABEL_12:
printf(" Type: '%d'\n", (unsigned int)a4);
exit(1);
}
if ( a4 != 3 )
goto LABEL_12;
}
}
return result;
}

original_code:
void bbcode_render_attribute(char* output, const char* tag, const char* attr, const int type)
{
    if (!strcmp(tag, "color"))
    {
        switch (type)
        {
            case invalid: exit(1);
            case colorcode:
            {
                strcat(output," style=\"color:");
                strcat(output,attr);
                strcat(output,"\" ");
                break;
            }
            case colorname:
            {
                int coloridx = bbcode_find_color_index(attr);
                if (coloridx < 0)
                    break;
                strcat(output," style=\"color:#");
                strcat(output,COLORCODES[coloridx]);
                strcat(output,"\" ");
            }
            case empty: break;
            default:
                printf("  Type: '%d'\n",type);
                exit(1);
        }
    }
}

canonical_original_code:
void bbcode_render_attribute(char *output, char *tag, char *attr, int type)
{
    if (!strcmp(tag, "color"))
    {
        switch (type)
        {
            case invalid: exit(1);
            case colorcode:
            {
                strcat(output," style=\"color:");
                strcat(output,attr);
                strcat(output,"\" ");
                break;
            }
            case colorname:
            {
                int coloridx = bbcode_find_color_index(attr);
                if (coloridx < 0)
                    break;
                strcat(output," style=\"color:#");
                strcat(output,COLORCODES[coloridx]);
                strcat(output,"\" ");
            }
            case empty: break;
            default:
                printf("  Type: '%d'\n",type);
                exit(1);
        }
    }
}

variable_types:
output
char *

variable_types: type int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return (unsigned __int8)bbcode_testfixture("test_bbcode.txt", argv, envp) ^ 1;
}

original_code:
int main (int argc, const char * argv[]) {
  if (!bbcode_testfixture("test_bbcode.txt")){
    return 1;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if (!bbcode_testfixture("test_bbcode.txt")){
    return 1;
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall test_replace(unsigned int a1, __int64 a2, const char *a3)
{
const char *v4; // rbx
int v5; // edx
__int64 result; // rax

v4 = (const char *)bbcode_replace(a2);
v5 = strcmp(v4, a3);
result = 1LL;
if ( v5 )
{
printf("TEST %d: '%s'\nEXPT %d: '%s'\n", a1, v4, a1, a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, const char *a3)
{
const char *v4; // rbx
int v5; // edx
__int64 result; // rax

v4 = (const char *)bbcode_replace(a2);
v5 = strcmp(v4, a3);
result = 1LL;
if ( v5 )
{
printf("TEST %d: '%s'\nEXPT %d: '%s'\n", a1, v4, a1, a3);
result = 0LL;
}
return result;
}

original_code:
_Bool test_replace(int num,char* val,char* exp)
{
  char* repl = bbcode_replace(val);
  if (strcmp(repl,exp))
  {
    printf("TEST %d: '%s'\nEXPT %d: '%s'\n", num, repl, num, exp);
    return 0;
  }
  return 1;
}

canonical_original_code:
_Bool test_replace(int num, char *val, char *exp)
{
  char *repl = bbcode_replace(val);
  if (strcmp(repl,exp))
  {
    printf("TEST %d: '%s'\nEXPT %d: '%s'\n", num, repl, num, exp);
    return 0;
  }
  return 1;
}

variable_types: num int

variable_types:
val
char *

variable_types:
exp
char *

variable_types:
repl
char *


decompiled_code:
__int64 test_bbcode2()
{
const char *v0; // rax

v0 = (const char *)bbcode_get_htmltag("code");
printf("tag: %s\n", v0);
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
const char *v0; // rax

v0 = (const char *)bbcode_get_htmltag("code");
printf("tag: %s\n", v0);
return 1LL;
}

original_code:
_Bool test_bbcode2()
{
  printf("tag: %s\n",bbcode_get_htmltag("code"));
  return 1;
}


decompiled_code:
__int64 __fastcall bbcode_testfixture(const char *a1)
{
int v1; // ebx

v1 = test_bbcode1(a1);
return v1 & (unsigned int)test_bbcode2();
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
int v1; // ebx

v1 = func2(a1);
return v1 & (unsigned int)func3();
}

original_code:
_Bool bbcode_testfixture(char* file)
{
  _Bool retval = 1;
  retval&=test_bbcode1(file);
  retval&=test_bbcode2();
  return retval;
}

canonical_original_code:
_Bool bbcode_testfixture(char *file)
{
  _Bool retval = 1;
  retval&=test_bbcode1(file);
  retval&=test_bbcode2();
  return retval;
}

variable_types:
file
char *


repo: wangbaishi/tos

decompiled_code:
__int64 __fastcall read_data(_WORD *a1)
{
_WORD *v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = inword(496LL);
*v1++ = result;
}
while ( v1 != a1 + 256 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_WORD *a1)
{
_WORD *v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = inword(496LL);
*v1++ = result;
}
while ( v1 != a1 + 256 );
return result;
}

original_code:
void read_data(char *buffer)
{
 int i;
 unsigned short *temp;
 temp=(unsigned short *)buffer;
 for(i=0;i<256;i++)
 {
  temp[i]=inword(0x1f0);
 }
}

variable_types:
buffer
char *

variable_types: i int

variable_types:
temp
unsigned short *


decompiled_code:
__int64 __fastcall init_opreation(unsigned int a1, int a2)
{
__int64 result; // rax

outbyte(502LL, 64LL);
outbyte(498LL, 0LL);
outbyte(499LL, HIBYTE(a1));
outbyte(500LL, 0LL);
outbyte(501LL, 0LL);
outbyte(498LL, 1LL);
outbyte(499LL, (unsigned __int8)a1);
outbyte(500LL, BYTE1(a1));
outbyte(501LL, BYTE2(a1));
if ( a2 )
result = outbyte(503LL, 52LL);
else
result = outbyte(503LL, 36LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
__int64 result; // rax

outbyte(502LL, 64LL);
outbyte(498LL, 0LL);
outbyte(499LL, HIBYTE(a1));
outbyte(500LL, 0LL);
outbyte(501LL, 0LL);
outbyte(498LL, 1LL);
outbyte(499LL, (unsigned __int8)a1);
outbyte(500LL, BYTE1(a1));
outbyte(501LL, BYTE2(a1));
if ( a2 )
result = outbyte(503LL, 52LL);
else
result = outbyte(503LL, 36LL);
return result;
}

original_code:
void init_opreation(unsigned int addr,int flag)
{
 unsigned char temp;
 unsigned short count=1;
 outbyte(0x1f6,0x40);
 temp=(unsigned char)(count>>8);
 outbyte(0x1f2,temp);
 temp=(unsigned char)(addr>>24);
 outbyte(0x1f3,temp);
 outbyte(0x1f4,0);
 outbyte(0x1f5,0);
 temp=(unsigned char)count;
 outbyte(0x1f2,temp);
 temp=(unsigned char)addr;
 outbyte(0x1f3,temp);
 temp=(unsigned char)(addr>>8);
 outbyte(0x1f4,temp);
 temp=(unsigned char)(addr>>16);
 outbyte(0x1f5,temp);
 if(flag==0)
 {
  outbyte(0x1f7,0x24);
 }
 else{
  outbyte(0x1f7,0x34);
 }
}

canonical_original_code:
void init_opreation(unsigned int addr, int flag)
{
 unsigned char temp;
 unsigned short count = 1;
 outbyte(0x1f6,0x40);
 temp=(unsigned char)(count>>8);
 outbyte(0x1f2,temp);
 temp=(unsigned char)(addr>>24);
 outbyte(0x1f3,temp);
 outbyte(0x1f4,0);
 outbyte(0x1f5,0);
 temp=(unsigned char)count;
 outbyte(0x1f2,temp);
 temp=(unsigned char)addr;
 outbyte(0x1f3,temp);
 temp=(unsigned char)(addr>>8);
 outbyte(0x1f4,temp);
 temp=(unsigned char)(addr>>16);
 outbyte(0x1f5,temp);
 if(flag==0)
 {
  outbyte(0x1f7,0x24);
 }
 else{
  outbyte(0x1f7,0x34);
 }
}

variable_types:
addr
unsigned int

variable_types: flag int

variable_types:
temp
unsigned char

variable_types:
count
unsigned short


decompiled_code:
__int64 check_flags()
{
int v0; // ebx
char v1; // al
unsigned int v2; // edx

v0 = 4;
do
{
v1 = inbyte(503LL);
--v0;
}
while ( v0 );
for ( ; v1 < 0; v1 = inbyte(503LL) )
;
v2 = 1;
if ( (v1 & 8) == 0 )
{
while ( (inbyte(503LL) & 0x80u) != 0LL )
;
v2 = -1;
}
return v2;
}

original_code:
int check_flags(void)
{
 int i;
 unsigned char temp;
 for(i=0;i<4;i++){
  temp=inbyte(0x1f7);
 }
 while(temp&0x80){
  temp=inbyte(0x1f7);
 }
 if(temp&8){
  return 1;
 }
 while((temp=inbyte(0x1f7))&0x80);
 if(temp&0x21){
  return -1;
 }
}

canonical_original_code:
int check_flags()
{
 int i;
 unsigned char temp;
 for(i=0;i<4;i++){
  temp=inbyte(0x1f7);
 }
 while(temp&0x80){
  temp=inbyte(0x1f7);
 }
 if(temp&8){
  return 1;
 }
 while((temp=inbyte(0x1f7))&0x80);
 if(temp&0x21){
  return -1;
 }
}


Bread

decompiled_code:
__int64 __fastcall Bread(unsigned int a1, _WORD *a2)
{
__int64 result; // rax

init_opreation(a1, 0);
result = check_flags();
if ( (_DWORD)result == 1 )
result = read_data(a2);
return result;
}

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

func1(a1, 0);
result = func2();
if ( (_DWORD)result == 1 )
result = func0(a2);
return result;
}

original_code:
void Bread(unsigned int addr,char *buffer)
{
 int flag;
 init_opreation(addr,0);
 flag=check_flags();
 if(flag==1){
  read_data(buffer);
 }
 else{
 }
}

canonical_original_code:
void Bread(unsigned int addr, char *buffer)
{
 int flag;
 init_opreation(addr,0);
 flag=check_flags();
 if(flag==1){
  read_data(buffer);
 }
 else{
 }
}


decompiled_code:
__int64 __fastcall write_data(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbx

v1 = a1;
do
outword(496LL, *v1++);
while ( v1 != a1 + 256 );
return outbyte(503LL, 231LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbx

v1 = a1;
do
outword(496LL, *v1++);
while ( v1 != a1 + 256 );
return outbyte(503LL, 231LL);
}

original_code:
void write_data(char *b)
{
 unsigned short *temp;
 int i,j;
 temp=(unsigned short *)b;
 for(i=0;i<256;i++){
  outword(0x1f0,temp[i]);
  for(j=0;j<10;j++);
 }
 outbyte(0x1f7,0xe7);
}

canonical_original_code:
void write_data(char *b)
{
 unsigned short *temp;
 int i; int j;
 temp=(unsigned short *)b;
 for(i=0;i<256;i++){
  outword(0x1f0,temp[i]);
  for(j=0;j<10;j++);
 }
 outbyte(0x1f7,0xe7);
}

variable_types:
b
char *

variable_types: j int


Bwrite

decompiled_code:
__int64 __fastcall Bwrite(unsigned int a1, unsigned __int16 *a2)
{
__int64 result; // rax

init_opreation(a1, 1);
result = check_flags();
if ( (_DWORD)result == 1 )
result = write_data(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned __int16 *a2)
{
__int64 result; // rax

func1(a1, 1);
result = func2();
if ( (_DWORD)result == 1 )
result = func4(a2);
return result;
}

original_code:
void Bwrite(unsigned int addr,char *buffer)
{
 int flag;
 init_opreation(addr,1);
 flag=check_flags();
 if(flag==1){
  write_data(buffer);
 }
 else{
 }
}

canonical_original_code:
void Bwrite(unsigned int addr, char *buffer)
{
 int flag;
 init_opreation(addr,1);
 flag=check_flags();
 if(flag==1){
  write_data(buffer);
 }
 else{
 }
}


copyd

decompiled_code:
__int64 __fastcall copyd(__int64 a1, int a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v5; // rdi

result = a2;
v5 = a2 + a1;
if ( a4 > 0 )
{
for ( result = 0LL; result != a4; ++result )
*(_BYTE *)(a3 + result) = *(_BYTE *)(v5 + result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v5; // rdi

result = a2;
v5 = a2 + a1;
if ( a4 > 0 )
{
for ( result = 0LL; result != a4; ++result )
*(_BYTE *)(a3 + result) = *(_BYTE *)(v5 + result);
}
return result;
}

original_code:
void copyd(char *source,int offset,char *dest,int count)
{
 int i;
 char *true_source;
 true_source=source+offset;
 for(i=0;i<count;i++){
  *(dest++)=*(true_source++);
 }
}

canonical_original_code:
void copyd(char *source, int offset, char *dest, int count)
{
 int i;
 char *true_source;
 true_source=source+offset;
 for(i=0;i<count;i++){
  *(dest++)=*(true_source++);
 }
}

variable_types:
source
char *

variable_types: offset int

variable_types:
dest
char *

variable_types: count int


repo: wangguibao/programmingwithposixthreads

decompiled_code:
void *__fastcall thread_routine(void *a1)
{
return a1;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
return a1;
}

original_code:
void *thread_routine(void *arg)
{
    return arg;
}

variable_types:
arg
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
char *v6; // rax
char *v7; // rax
void *v8; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = pthread_create(newthread, 0LL, thread_routine, 0LL);
if ( v3 )
{
v6 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "pthread_create() error", "lifecycle.c", 17LL, v6);
abort();
}
v4 = pthread_join(newthread[0], &v8);
if ( v4 )
{
v7 = strerror(v4);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "pthread_join() error", "lifecycle.c", 22LL, v7);
abort();
}
return v8 != 0LL;
}

original_code:
int main(int argc, char **argv)
{
    pthread_t thread_id;
    void *thread_result;
    int status;
    status = pthread_create(&thread_id, ((void *)0), thread_routine, ((void *)0));
    if (status != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "pthread_create() error", "lifecycle.c", 17, strerror (status)); abort (); } while (0);
    }
    status = pthread_join(thread_id, &thread_result);
    if (status != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "pthread_join() error", "lifecycle.c", 22, strerror (status)); abort (); } while (0);
    }
    return !(thread_result == ((void *)0));
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long thread_id;
    void *thread_result;
    int status;
    status = pthread_create(&thread_id, ((void *)0), thread_routine, ((void *)0));
    if (status != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "pthread_create() error", "lifecycle.c", 17, strerror (status)); abort (); } while (0);
    }
    status = pthread_join(thread_id, &thread_result);
    if (status != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "pthread_join() error", "lifecycle.c", 22, strerror (status)); abort (); } while (0);
    }
    return !(thread_result == ((void *)0));
}

variable_types: argc int

variable_types:
argv
char **

variable_types: status int


decompiled_code:
void *__fastcall counter_thread(void *a1)
{
char *v1; // rax
int v2; // eax
int v3; // eax
__int64 v4; // rax
__int64 v5; // rcx
char *v6; // rax

while ( time(0LL) < end_time )
{
v3 = pthread_mutex_lock(&mutex);
if ( v3 )
{
v1 = strerror(v3);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Lock mutex", "trylock.c", 27LL, v1);
abort();
}
v4 = counter + 1;
do
v5 = v4++;
while ( v4 != counter + 10000001 );
counter = v5;
v2 = pthread_mutex_unlock(&mutex);
if ( v2 )
{
v6 = strerror(v2);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 35LL, v6);
abort();
}
sleep(1u);
}
printf("Counter is %#lx\n", counter);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
char *v1; // rax
int v2; // eax
int v3; // eax
__int64 v4; // rax
__int64 v5; // rcx
char *v6; // rax

while ( time(0LL) < end_time )
{
v3 = pthread_mutex_lock(&mutex);
if ( v3 )
{
v1 = strerror(v3);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Lock mutex", "trylock.c", 27LL, v1);
abort();
}
v4 = counter + 1;
do
v5 = v4++;
while ( v4 != counter + 10000001 );
counter = v5;
v2 = pthread_mutex_unlock(&mutex);
if ( v2 )
{
v6 = strerror(v2);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 35LL, v6);
abort();
}
sleep(1u);
}
printf("Counter is %#lx\n", counter);
return 0LL;
}

original_code:
void *counter_thread(void *arg)
{
    int status;
    int spin;
    while (time(((void *)0)) < end_time) {
 if ((status = pthread_mutex_lock(&mutex)) != 0) {
     do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "trylock.c", 27, strerror (status)); abort (); } while (0);
 }
 for (spin = 0; spin < 10000000; spin++) {
     counter++;
 }
 if ((status = pthread_mutex_unlock(&mutex)) != 0) {
     do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 35, strerror (status)); abort (); } while (0);
 }
 sleep(1);
    }
    printf("Counter is %#lx\n", counter);
    return ((void *)0);
}

variable_types: spin int


decompiled_code:
void *__fastcall monitor_thread(void *a1)
{
unsigned int v1; // ebx
char *v2; // rax
int v3; // eax
int v4; // eax
char *v5; // rax

v1 = 0;
while ( time(0LL) < end_time )
{
sleep(3u);
v3 = pthread_mutex_trylock(&mutex);
if ( v3 == 16 )
{
++v1;
}
else
{
if ( v3 )
{
v2 = strerror(v3);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Trylock", "trylock.c", 62LL, v2);
abort();
}
printf("Counter is %ld\n", counter / 10000000);
v4 = pthread_mutex_unlock(&mutex);
if ( v4 )
{
v5 = strerror(v4);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 66LL, v5);
abort();
}
}
}
printf("Monitor thread missed update %d times\n", v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
unsigned int v1; // ebx
char *v2; // rax
int v3; // eax
int v4; // eax
char *v5; // rax

v1 = 0;
while ( time(0LL) < end_time )
{
sleep(3u);
v3 = pthread_mutex_trylock(&mutex);
if ( v3 == 16 )
{
++v1;
}
else
{
if ( v3 )
{
v2 = strerror(v3);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Trylock", "trylock.c", 62LL, v2);
abort();
}
printf("Counter is %ld\n", counter / 10000000);
v4 = pthread_mutex_unlock(&mutex);
if ( v4 )
{
v5 = strerror(v4);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 66LL, v5);
abort();
}
}
}
printf("Monitor thread missed update %d times\n", v1);
return 0LL;
}

original_code:
void *monitor_thread(void *arg)
{
    int status;
    int misses = 0;
    while (time(((void *)0)) < end_time) {
 sleep(3);
 status = pthread_mutex_trylock(&mutex);
 if (status != 16) {
     if (status != 0) {
  do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Trylock", "trylock.c", 62, strerror (status)); abort (); } while (0);
     }
     printf("Counter is %ld\n", counter/10000000);
     if ((status = pthread_mutex_unlock(&mutex)) != 0) {
  do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "trylock.c", 66, strerror (status)); abort (); } while (0);
     }
 }
 else {
     misses++;
 }
    }
    printf("Monitor thread missed update %d times\n", misses);
    return ((void *)0);
}

variable_types: misses int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

end_time = time(0LL) + 60;
v3 = pthread_create(newthread, 0LL, counter_thread, 0LL);
if ( v3 )
{
v8 = strerror(v3);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Create counter thread", "trylock.c", 87LL, v8);
abort();
}
v4 = pthread_create(&th, 0LL, monitor_thread, 0LL);
if ( v4 )
{
v9 = strerror(v4);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Create monitor thread", "trylock.c", 92LL, v9);
abort();
}
v5 = pthread_join(newthread[0], 0LL);
if ( v5 )
{
v10 = strerror(v5);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Join couter thread", "trylock.c", 96LL, v10);
abort();
}
v6 = pthread_join(th, 0LL);
if ( v6 )
{
v11 = strerror(v6);
fprintf(_bss_start, "%s at \"%s\":%d: %s\n", "Join monitor thread", "trylock.c", 100LL, v11);
abort();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int status;
    pthread_t counter_thread_id;
    pthread_t monitor_thread_id;
    end_time = time(((void *)0)) + 60;
    if ((status = pthread_create(&counter_thread_id, ((void *)0),
     counter_thread, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create counter thread", "trylock.c", 87, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_create(&monitor_thread_id, ((void *)0),
     monitor_thread, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create monitor thread", "trylock.c", 92, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_join(counter_thread_id, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Join couter thread", "trylock.c", 96, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_join(monitor_thread_id, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Join monitor thread", "trylock.c", 100, strerror (status)); abort (); } while (0);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int status;
    unsigned long counter_thread_id;
    unsigned long monitor_thread_id;
    end_time = time(((void *)0)) + 60;
    if ((status = pthread_create(&counter_thread_id, ((void *)0),
     counter_thread, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create counter thread", "trylock.c", 87, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_create(&monitor_thread_id, ((void *)0),
     monitor_thread, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create monitor thread", "trylock.c", 92, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_join(counter_thread_id, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Join couter thread", "trylock.c", 96, strerror (status)); abort (); } while (0);
    }
    if ((status = pthread_join(monitor_thread_id, ((void *)0))) != 0) {
 do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Join monitor thread", "trylock.c", 100, strerror (status)); abort (); } while (0);
    }
    return 0;
}


decompiled_code:
void *__fastcall wait_thread(void *a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
char *v5; // rax
char *v6; // rax
char *v7; // rax

sleep(hibernation);
v1 = pthread_mutex_lock(&data);
if ( v1 )
{
v5 = strerror(v1);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 33LL, v5);
abort();
}
dword_404118 = 1;
v2 = pthread_cond_signal(&cond);
if ( v2 )
{
v6 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Signal condition", "cond.c", 39LL, v6);
abort();
}
v3 = pthread_mutex_unlock(&data);
if ( v3 )
{
v7 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 44LL, v7);
abort();
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
char *v5; // rax
char *v6; // rax
char *v7; // rax

sleep(hibernation);
v1 = pthread_mutex_lock(&data);
if ( v1 )
{
v5 = strerror(v1);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 33LL, v5);
abort();
}
dword_404118 = 1;
v2 = pthread_cond_signal(&cond);
if ( v2 )
{
v6 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Signal condition", "cond.c", 39LL, v6);
abort();
}
v3 = pthread_mutex_unlock(&data);
if ( v3 )
{
v7 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 44LL, v7);
abort();
}
return 0LL;
}

original_code:
void *wait_thread(void *arg)
{
    int status;
    sleep(hibernation);
    status = pthread_mutex_lock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 33, strerror (status)); abort (); } while (0);
    }
    data.value = 1;
    status = pthread_cond_signal(&data.cond);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Signal condition", "cond.c", 39, strerror (status)); abort (); } while (0);
    }
    status = pthread_mutex_unlock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 44, strerror (status)); abort (); } while (0);
    }
    return ((void *)0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // eax
char *v6; // rax
char *v7; // rax
char *v8; // rax
int v9; // eax
char *v11; // rax
struct timespec v12; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

if ( argc > 1 )
hibernation = atoi(argv[1]);
v3 = pthread_create(newthread, 0LL, wait_thread, 0LL);
if ( v3 )
{
v7 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Create wait thread", "cond.c", 71LL, v7);
abort();
}
v12.tv_sec = time(0LL) + 2;
v12.tv_nsec = 0LL;
v4 = pthread_mutex_lock(&data);
if ( v4 )
{
v8 = strerror(v4);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 84LL, v8);
abort();
}
while ( !*((_DWORD *)&data + 22) )
{
v5 = pthread_cond_timedwait(&cond, &data, &v12);
if ( v5 == 110 )
{
puts("Condition wait timed out");
if ( !dword_404118 )
goto LABEL_12;
break;
}
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "cond.c", 95LL, v6);
abort();
}
}
puts("Condition was signaled.");
LABEL_12:
v9 = pthread_mutex_unlock(&data);
if ( v9 )
{
v11 = strerror(v9);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 105LL, v11);
abort();
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int status;
    pthread_t wait_thread_id;
    struct timespec timeout;
    if (argc > 1) {
        hibernation = atoi(argv[1]);
    }
    status = pthread_create(&wait_thread_id, ((void *)0), wait_thread, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create wait thread", "cond.c", 71, strerror (status)); abort (); } while (0);
    }
    timeout.tv_sec = time(((void *)0)) + 2;
    timeout.tv_nsec = 0;
    status = pthread_mutex_lock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 84, strerror (status)); abort (); } while (0);
    }
    while (data.value == 0) {
        status = pthread_cond_timedwait(
                &data.cond, &data.mutex, &timeout);
        if (status == 110) {
            printf("Condition wait timed out\n");
            break;
        }
        else if (status != 0) {
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "cond.c", 95, strerror (status)); abort (); } while (0);
        }
    }
    if (data.value != 0) {
        printf("Condition was signaled.\n");
    }
    status = pthread_mutex_unlock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 105, strerror (status)); abort (); } while (0);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int status;
    unsigned long wait_thread_id;
    struct timespec timeout;
    if (argc > 1) {
        hibernation = atoi(argv[1]);
    }
    status = pthread_create(&wait_thread_id, ((void *)0), wait_thread, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create wait thread", "cond.c", 71, strerror (status)); abort (); } while (0);
    }
    timeout.tv_sec = time(((void *)0)) + 2;
    timeout.tv_nsec = 0;
    status = pthread_mutex_lock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "cond.c", 84, strerror (status)); abort (); } while (0);
    }
    while (data.value == 0) {
        status = pthread_cond_timedwait(
                &data.cond, &data.mutex, &timeout);
        if (status == 110) {
            printf("Condition wait timed out\n");
            break;
        }
        else if (status != 0) {
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "cond.c", 95, strerror (status)); abort (); } while (0);
        }
    }
    if (data.value != 0) {
        printf("Condition was signaled.\n");
    }
    status = pthread_mutex_unlock(&data.mutex);
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "cond.c", 105, strerror (status)); abort (); } while (0);
    }
    return 0;
}

variable_types:
argv
char *[]

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


decompiled_code:
void *__fastcall lock_forward(void *a1)
{
int v1; // er13
int v2; // eax
int i; // ebx
int v4; // eax
char *v5; // rax
int v6; // eax
unsigned int v7; // er12
pthread_mutex_t *v8; // rbp
int v9; // eax
char *v10; // rax
char *v11; // rax

v1 = 10;
while ( 2 )
{
v7 = 0;
for ( i = 0; i <= 2; ++i )
{
while ( 1 )
{
while ( !i )
{
v2 = pthread_mutex_lock(&mutex);
i = v2;
if ( v2 )
{
v5 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 46LL, v5);
abort();
}
v4 = yield_flag;
if ( yield_flag )
goto LABEL_15;
i = 1;
}
if ( backoff )
v6 = pthread_mutex_trylock(&mutex + i);
else
v6 = pthread_mutex_lock(&mutex + i);
if ( v6 != 16 )
{
if ( v6 )
{
v11 = strerror(v6);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 68LL, v11);
abort();
}
LABEL_23:
v4 = yield_flag;
if ( !yield_flag )
goto LABEL_17;
break;
}
++v7;
if ( i < 0 )
goto LABEL_23;
v8 = &mutex + i;
do
{
v9 = pthread_mutex_unlock(v8);
if ( v9 )
{
v10 = strerror(v9);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 62LL, v10);
abort();
}
--i;
--v8;
}
while ( i != -1 );
v4 = yield_flag;
if ( yield_flag )
break;
i = yield_flag;
}
LABEL_15:
if ( v4 <= 0 )
sleep(1u);
else
sched_yield();
LABEL_17:
;
}
printf("lock forward got all locks. %d backoffs\n", v7);
pthread_mutex_unlock(&stru_404130);
pthread_mutex_unlock(&stru_404108);
pthread_mutex_unlock(&mutex);
sched_yield();
if ( --v1 )
continue;
return 0LL;
}
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // er13
int v2; // eax
int i; // ebx
int v4; // eax
char *v5; // rax
int v6; // eax
unsigned int v7; // er12
pthread_mutex_t *v8; // rbp
int v9; // eax
char *v10; // rax
char *v11; // rax

v1 = 10;
while ( 2 )
{
v7 = 0;
for ( i = 0; i <= 2; ++i )
{
while ( 1 )
{
while ( !i )
{
v2 = pthread_mutex_lock(&mutex);
i = v2;
if ( v2 )
{
v5 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 46LL, v5);
abort();
}
v4 = yield_flag;
if ( yield_flag )
goto LABEL_15;
i = 1;
}
if ( backoff )
v6 = pthread_mutex_trylock(&mutex + i);
else
v6 = pthread_mutex_lock(&mutex + i);
if ( v6 != 16 )
{
if ( v6 )
{
v11 = strerror(v6);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 68LL, v11);
abort();
}
LABEL_23:
v4 = yield_flag;
if ( !yield_flag )
goto LABEL_17;
break;
}
++v7;
if ( i < 0 )
goto LABEL_23;
v8 = &mutex + i;
do
{
v9 = pthread_mutex_unlock(v8);
if ( v9 )
{
v10 = strerror(v9);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 62LL, v10);
abort();
}
--i;
--v8;
}
while ( i != -1 );
v4 = yield_flag;
if ( yield_flag )
break;
i = yield_flag;
}
LABEL_15:
if ( v4 <= 0 )
sleep(1u);
else
sched_yield();
LABEL_17:
;
}
printf("lock forward got all locks. %d backoffs\n", v7);
pthread_mutex_unlock(&stru_404130);
pthread_mutex_unlock(&stru_404108);
pthread_mutex_unlock(&mutex);
sched_yield();
if ( --v1 )
continue;
return 0LL;
}
}

original_code:
void *lock_forward(void *arg)
{
    int i, iterate, backoffs;
    int status;
    for (iterate = 0; iterate < 10; iterate++) {
        backoffs = 0;
        for (i = 0; i < 3; i++) {
            if (i == 0) {
                status = pthread_mutex_lock(&mutex[i]);
                if (status != 0) {
                    do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 46, strerror (status)); abort (); } while (0);
                }
            }
            else {
                if (backoff) {
                    status = pthread_mutex_trylock(&mutex[i]);
                }
                else {
                    status = pthread_mutex_lock(&mutex[i]);
                }
                if (status == 16) {
                    backoffs++;
                    ;
                    for (; i >= 0; i--) {
                        status = pthread_mutex_unlock(&mutex[i]);
                        if (status != 0) {
                            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 62, strerror (status)); abort (); } while (0);
                        }
                    }
                }
                else {
                    if (status != 0) {
                        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 68, strerror (status)); abort (); } while (0);
                    }
                    ;
                }
            }
            if (yield_flag) {
                if (yield_flag > 0) {
                    sched_yield();
                }
                else {
                    sleep(1);
                }
            }
        }
        printf("lock forward got all locks. %d backoffs\n", backoffs);
        pthread_mutex_unlock(&mutex[2]);
        pthread_mutex_unlock(&mutex[1]);
        pthread_mutex_unlock(&mutex[0]);
        sched_yield();
    }
    return ((void *)0);
}

canonical_original_code:
void *lock_forward(void *arg)
{
    int i; int iterate; int backoffs;
    int status;
    for (iterate = 0; iterate < 10; iterate++) {
        backoffs = 0;
        for (i = 0; i < 3; i++) {
            if (i == 0) {
                status = pthread_mutex_lock(&mutex[i]);
                if (status != 0) {
                    do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 46, strerror (status)); abort (); } while (0);
                }
            }
            else {
                if (backoff) {
                    status = pthread_mutex_trylock(&mutex[i]);
                }
                else {
                    status = pthread_mutex_lock(&mutex[i]);
                }
                if (status == 16) {
                    backoffs++;
                    ;
                    for (; i >= 0; i--) {
                        status = pthread_mutex_unlock(&mutex[i]);
                        if (status != 0) {
                            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 62, strerror (status)); abort (); } while (0);
                        }
                    }
                }
                else {
                    if (status != 0) {
                        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 68, strerror (status)); abort (); } while (0);
                    }
                    ;
                }
            }
            if (yield_flag) {
                if (yield_flag > 0) {
                    sched_yield();
                }
                else {
                    sleep(1);
                }
            }
        }
        printf("lock forward got all locks. %d backoffs\n", backoffs);
        pthread_mutex_unlock(&mutex[2]);
        pthread_mutex_unlock(&mutex[1]);
        pthread_mutex_unlock(&mutex[0]);
        sched_yield();
    }
    return ((void *)0);
}

variable_types: i int

variable_types: iterate int

variable_types: backoffs int


decompiled_code:
void *__fastcall lock_backward(void *a1)
{
int v1; // er13
int v2; // eax
int v3; // eax
int i; // ebx
char *v5; // rax
int v6; // eax
unsigned int v7; // er12
pthread_mutex_t *v8; // rbp
int v9; // eax
char *v10; // rax
char *v11; // rax

v1 = 10;
while ( 2 )
{
v7 = 0;
for ( i = 2; i >= 0; --i )
{
while ( 1 )
{
while ( i == 2 )
{
v2 = pthread_mutex_lock(&stru_404130);
if ( v2 )
{
v5 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 113LL, v5);
abort();
}
v3 = yield_flag;
if ( yield_flag )
goto LABEL_23;
i = 1;
}
if ( backoff )
v6 = pthread_mutex_trylock(&mutex + i);
else
v6 = pthread_mutex_lock(&mutex + i);
if ( v6 != 16 )
{
if ( v6 )
{
v11 = strerror(v6);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 135LL, v11);
abort();
}
LABEL_22:
v3 = yield_flag;
if ( !yield_flag )
goto LABEL_16;
break;
}
++v7;
if ( i > 2 )
goto LABEL_22;
v8 = &mutex + i;
do
{
v9 = pthread_mutex_unlock(v8);
if ( v9 )
{
v10 = strerror(v9);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 129LL, v10);
abort();
}
++i;
++v8;
}
while ( i != 3 );
v3 = yield_flag;
if ( yield_flag )
break;
i = 2;
}
LABEL_23:
if ( v3 <= 0 )
sleep(1u);
else
sched_yield();
LABEL_16:
;
}
printf("lock backword got all locks. %d backoffs\n", v7);
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(&stru_404108);
pthread_mutex_unlock(&stru_404130);
sched_yield();
if ( --v1 )
continue;
return 0LL;
}
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // er13
int v2; // eax
int v3; // eax
int i; // ebx
char *v5; // rax
int v6; // eax
unsigned int v7; // er12
pthread_mutex_t *v8; // rbp
int v9; // eax
char *v10; // rax
char *v11; // rax

v1 = 10;
while ( 2 )
{
v7 = 0;
for ( i = 2; i >= 0; --i )
{
while ( 1 )
{
while ( i == 2 )
{
v2 = pthread_mutex_lock(&stru_404130);
if ( v2 )
{
v5 = strerror(v2);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 113LL, v5);
abort();
}
v3 = yield_flag;
if ( yield_flag )
goto LABEL_23;
i = 1;
}
if ( backoff )
v6 = pthread_mutex_trylock(&mutex + i);
else
v6 = pthread_mutex_lock(&mutex + i);
if ( v6 != 16 )
{
if ( v6 )
{
v11 = strerror(v6);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 135LL, v11);
abort();
}
LABEL_22:
v3 = yield_flag;
if ( !yield_flag )
goto LABEL_16;
break;
}
++v7;
if ( i > 2 )
goto LABEL_22;
v8 = &mutex + i;
do
{
v9 = pthread_mutex_unlock(v8);
if ( v9 )
{
v10 = strerror(v9);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 129LL, v10);
abort();
}
++i;
++v8;
}
while ( i != 3 );
v3 = yield_flag;
if ( yield_flag )
break;
i = 2;
}
LABEL_23:
if ( v3 <= 0 )
sleep(1u);
else
sched_yield();
LABEL_16:
;
}
printf("lock backword got all locks. %d backoffs\n", v7);
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(&stru_404108);
pthread_mutex_unlock(&stru_404130);
sched_yield();
if ( --v1 )
continue;
return 0LL;
}
}

original_code:
void *lock_backward(void *arg)
{
    int i, iterate, backoffs;
    int status;
    for (iterate = 0; iterate < 10; iterate++) {
        backoffs = 0;
        for (i = 2; i >= 0; i--) {
            if (i == 2) {
                status = pthread_mutex_lock(&mutex[i]);
                if (status != 0) {
                    do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 113, strerror (status)); abort (); } while (0);
                }
            }
            else {
                if (backoff) {
                    status = pthread_mutex_trylock(&mutex[i]);
                }
                else {
                    status = pthread_mutex_lock(&mutex[i]);
                }
                if (status == 16) {
                    backoffs++;
                    ;
                    for (; i < 3; i++) {
                        status = pthread_mutex_unlock(&mutex[i]);
                        if (status != 0) {
                            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 129, strerror (status)); abort (); } while (0);
                        }
                    }
                }
                else {
                    if (status != 0) {
                        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 135, strerror (status)); abort (); } while (0);
                    }
                    ;
                }
            }
            if (yield_flag) {
                if (yield_flag > 0) {
                    sched_yield();
                }
                else {
                    sleep(1);
                }
            }
        }
        printf("lock backword got all locks. %d backoffs\n", backoffs);
        pthread_mutex_unlock(&mutex[0]);
        pthread_mutex_unlock(&mutex[1]);
        pthread_mutex_unlock(&mutex[2]);
        sched_yield();
    }
    return ((void *)0);
}

canonical_original_code:
void *lock_backward(void *arg)
{
    int i; int iterate; int backoffs;
    int status;
    for (iterate = 0; iterate < 10; iterate++) {
        backoffs = 0;
        for (i = 2; i >= 0; i--) {
            if (i == 2) {
                status = pthread_mutex_lock(&mutex[i]);
                if (status != 0) {
                    do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "First lock", "backoff.c", 113, strerror (status)); abort (); } while (0);
                }
            }
            else {
                if (backoff) {
                    status = pthread_mutex_trylock(&mutex[i]);
                }
                else {
                    status = pthread_mutex_lock(&mutex[i]);
                }
                if (status == 16) {
                    backoffs++;
                    ;
                    for (; i < 3; i++) {
                        status = pthread_mutex_unlock(&mutex[i]);
                        if (status != 0) {
                            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Backoff", "backoff.c", 129, strerror (status)); abort (); } while (0);
                        }
                    }
                }
                else {
                    if (status != 0) {
                        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "backoff.c", 135, strerror (status)); abort (); } while (0);
                    }
                    ;
                }
            }
            if (yield_flag) {
                if (yield_flag > 0) {
                    sched_yield();
                }
                else {
                    sleep(1);
                }
            }
        }
        printf("lock backword got all locks. %d backoffs\n", backoffs);
        pthread_mutex_unlock(&mutex[0]);
        pthread_mutex_unlock(&mutex[1]);
        pthread_mutex_unlock(&mutex[2]);
        sched_yield();
    }
    return ((void *)0);
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
char *v5; // rax
char *v6; // rax
pthread_t v7; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc > 1 )
backoff = atoi(argv[1]);
if ( argc > 2 )
yield_flag = atoi(argv[2]);
v3 = pthread_create(newthread, 0LL, lock_forward, 0LL);
if ( !v3 )
{
v4 = pthread_create(&v7, 0LL, lock_backward, 0LL);
if ( !v4 )
pthread_exit(0LL);
v6 = strerror(v4);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Create backword", "backoff.c", 199LL, v6);
abort();
}
v5 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Create forward", "backoff.c", 195LL, v5);
abort();
}

original_code:
int main(int argc, char **argv)
{
    pthread_t forward, backword;
    int status;
    if (argc > 1) {
        backoff = atoi(argv[1]);
    }
    if (argc > 2) {
        yield_flag = atoi(argv[2]);
    }
    status = pthread_create(&forward, ((void *)0), lock_forward, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create forward", "backoff.c", 195, strerror (status)); abort (); } while (0);
    }
    status = pthread_create(&backword, ((void *)0), lock_backward, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create backword", "backoff.c", 199, strerror (status)); abort (); } while (0);
    }
    pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long forward; unsigned long backword;
    int status;
    if (argc > 1) {
        backoff = atoi(argv[1]);
    }
    if (argc > 2) {
        yield_flag = atoi(argv[2]);
    }
    status = pthread_create(&forward, ((void *)0), lock_forward, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create forward", "backoff.c", 195, strerror (status)); abort (); } while (0);
    }
    status = pthread_create(&backword, ((void *)0), lock_backward, ((void *)0));
    if (status != 0) {
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create backword", "backoff.c", 199, strerror (status)); abort (); } while (0);
    }
    pthread_exit(((void *)0));
}

variable_types:
forward
unsigned long

variable_types:
backword
unsigned long


repo: wangkendy/thesis

decompiled_code:
void sigchld_handler()
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

canonical_decompiled_code:
void func7()
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

original_code:
void sigchld_handler(int sig)
{
    while (waitpid(-1, 0, 1) > 0)
        ;
    return;
}

variable_types: sig int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // ebp
int v5; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
if ( argc != 2 )
{
fprintf(_bss_start, "usage: %s <port>\n", *argv);
exit(0);
}
v3 = atoi(argv[1]);
signal(17, (__sighandler_t)sigchld_handler);
v4 = open_listenfd(v3);
while ( 1 )
{
v5 = accept(v4, &v6, addr_len);
if ( !fork() )
break;
close(v5);
}
close(v4);
echo(v5);
close(v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // ebp
int v5; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
if ( argc != 2 )
{
fprintf(_bss_start, "usage: %s <port>\n", *argv);
exit(0);
}
v3 = atoi(argv[1]);
signal(17, (__sighandler_t)sigchld_handler);
v4 = func10(v3);
while ( 1 )
{
v5 = accept(v4, &v6, addr_len);
if ( !fork() )
break;
close(v5);
}
close(v4);
func11(v5);
close(v5);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    int listenfd, connfd, port;
    socklen_t client_len = sizeof(struct sockaddr_in);
    struct sockaddr_in client_addr;
    if (argc != 2) {
        fprintf(stderr, "usage: %s <port>\n", argv[0]);
        exit(0);
    }
    port = atoi(argv[1]);
    signal(17, sigchld_handler);
    listenfd = open_listenfd(port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr*)&client_addr, &client_len);
        if (fork() == 0) {
            close(listenfd);
            echo(connfd);
            close(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int listenfd; int connfd; int port;
    unsigned int client_len = sizeof(struct sockaddr_in);
    struct sockaddr_in client_addr;
    if (argc != 2) {
        fprintf(stderr, "usage: %s <port>\n", argv[0]);
        exit(0);
    }
    port = atoi(argv[1]);
    signal(17, sigchld_handler);
    listenfd = open_listenfd(port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr *)&client_addr, &client_len);
        if (fork() == 0) {
            close(listenfd);
            echo(connfd);
            close(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

variable_types: listenfd int

variable_types: connfd int

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


service

decompiled_code:
void *__fastcall service(void *a1)
{
int v1; // ebp
pthread_t v2; // rax

v1 = *(_DWORD *)a1;
v2 = pthread_self();
pthread_detach(v2);
free(a1);
echo(v1);
close(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebp
pthread_t v2; // rax

v1 = *(_DWORD *)a1;
v2 = pthread_self();
pthread_detach(v2);
free(a1);
func11(v1);
close(v1);
return 0LL;
}

original_code:
void *service(void *vargp)
{
    int connfd = *((int*)vargp);
    pthread_detach(pthread_self());
    free(vargp);
    echo(connfd);
    close(connfd);
    return ((void *)0);
}

variable_types:
vargp
void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
_DWORD *v5; // rbx
size_t stacksize[7]; // [rsp+Ch] [rbp-7Ch] BYREF
pthread_t newthread; // [rsp+48h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+6Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
pthread_attr_init((pthread_attr_t *)((char *)stacksize + 4));
LODWORD(stacksize[0]) = 0x100000;
pthread_attr_setstacksize((pthread_attr_t *)((char *)stacksize + 4), 0x100000uLL);
pthread_attr_getstacksize((const pthread_attr_t *)((char *)stacksize + 4), stacksize);
printf("stack size :%d\n", LODWORD(stacksize[0]));
if ( argc != 2 )
{
fprintf(stderr, "usage: %s <port>\n", *argv);
exit(0);
}
v3 = atoi(argv[1]);
v4 = open_listenfd(v3);
while ( 1 )
{
v5 = malloc(4uLL);
*v5 = accept(v4, &addr, addr_len);
pthread_create(&newthread, (const pthread_attr_t *)((char *)stacksize + 4), service, v5);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
_DWORD *v5; // rbx
size_t stacksize[7]; // [rsp+Ch] [rbp-7Ch] BYREF
pthread_t newthread; // [rsp+48h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+6Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
pthread_attr_init((pthread_attr_t *)((char *)stacksize + 4));
LODWORD(stacksize[0]) = 0x100000;
pthread_attr_setstacksize((pthread_attr_t *)((char *)stacksize + 4), 0x100000uLL);
pthread_attr_getstacksize((const pthread_attr_t *)((char *)stacksize + 4), stacksize);
printf("stack size :%d\n", LODWORD(stacksize[0]));
if ( argc != 2 )
{
fprintf(stderr, "usage: %s <port>\n", *argv);
exit(0);
}
v3 = atoi(argv[1]);
v4 = func10(v3);
while ( 1 )
{
v5 = malloc(4uLL);
*v5 = accept(v4, &addr, addr_len);
pthread_create(&newthread, (const pthread_attr_t *)((char *)stacksize + 4), service, v5);
}
}

original_code:
int main(int argc, char **argv)
{
    int listenfd, *connfdp, port;
    socklen_t clientlen = sizeof(struct sockaddr_in);
    struct sockaddr_in client_addr;
    pthread_t tid;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    unsigned int size = 0;
    size = 1024 * 1024;
    pthread_attr_setstacksize(&attr,size);
    pthread_attr_getstacksize(&attr,&size);
    printf("stack size :%d\n",size);
    if (argc != 2) {
        fprintf(stderr, "usage: %s <port>\n", argv[0]);
        exit(0);
    }
    port = atoi(argv[1]);
    listenfd = open_listenfd(port);
    while (1) {
        connfdp = malloc(sizeof(int));
        *connfdp = accept(listenfd, (struct sockaddr*)&client_addr, &clientlen);
        pthread_create(&tid, &attr, service, connfdp);
    }
}

canonical_original_code:
int main(int argc, char **argv)
{
    int listenfd; int *connfdp; int port;
    unsigned int clientlen = sizeof(struct sockaddr_in);
    struct sockaddr_in client_addr;
    unsigned long tid;
    union pthread_attr_t attr;
    pthread_attr_init(&attr);
    unsigned int size = 0;
    size = 1024 * 1024;
    pthread_attr_setstacksize(&attr,size);
    pthread_attr_getstacksize(&attr,&size);
    printf("stack size :%d\n",size);
    if (argc != 2) {
        fprintf(stderr, "usage: %s <port>\n", argv[0]);
        exit(0);
    }
    port = atoi(argv[1]);
    listenfd = open_listenfd(port);
    while (1) {
        connfdp = malloc(sizeof(int));
        *connfdp = accept(listenfd, (struct sockaddr *)&client_addr, &clientlen);
        pthread_create(&tid, &attr, service, connfdp);
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
connfdp
int *

variable_types:
clientlen
unsigned int

variable_types:
tid
unsigned long

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
size
unsigned int


maxargs

repo: wangxinalex/compiler

original_code:
int maxargs(A_stm prog, int *max){
 int args = 0;
 if(prog->kind == A_compoundStm){
  maxargs(prog->u.compound.stm1, max);
  maxargs(prog->u.compound.stm2, max);
 }else if(prog->kind == A_assignStm){
  if(prog->u.assign.exp->kind == A_eseqExp){
   A_stm ex_prog = prog->u.assign.exp->u.eseq.stm;
   maxargs(ex_prog, max);
  }
 }else if(prog->kind == A_printStm){
  A_expList list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   args++;
   if(list->u.pair.head->kind == A_eseqExp){
    A_stm ex_prog = list->u.pair.head->u.eseq.stm;
    maxargs(ex_prog, max);
   }
   list = list->u.pair.tail;
  }
  if(++args > *max){
   *max = args;
  }
 }
 return 0;
}

canonical_original_code:
int maxargs(struct A_stm_ *prog, int *max){
 int args = 0;
 if(prog->kind == A_compoundStm){
  maxargs(prog->u.compound.stm1, max);
  maxargs(prog->u.compound.stm2, max);
 }else if(prog->kind == A_assignStm){
  if(prog->u.assign.exp->kind == A_eseqExp){
   struct A_stm_ *ex_prog = prog->u.assign.exp->u.eseq.stm;
   maxargs(ex_prog, max);
  }
 }else if(prog->kind == A_printStm){
  struct A_expList_ *list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   args++;
   if(list->u.pair.head->kind == A_eseqExp){
    struct A_stm_ *ex_prog = list->u.pair.head->u.eseq.stm;
    maxargs(ex_prog, max);
   }
   list = list->u.pair.tail;
  }
  if(++args > *max){
   *max = args;
  }
 }
 return 0;
}

variable_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *

variable_types:
max
int *

variable_types: args int

variable_types: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *

user_defined_types: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; }


lookup

decompiled_code:
__int64 __fastcall lookup(char *s2, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
{
LABEL_4:
printf("[Error] Identifier %s does not exist!\n\n", s2);
exit(-1);
}
while ( strcmp(*(const char **)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_4;
}
return *(unsigned int *)(v2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
{
LABEL_4:
printf("[Error] Identifier %s does not exist!\n\n", s2);
exit(-1);
}
while ( strcmp(*(const char **)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_4;
}
return *(unsigned int *)(v2 + 8);
}

original_code:
int lookup(string s, A_table t){
 while(t != ((void *)0)){
  if(strcmp(t->id, s)==0){
   return t->value;
  }
  t = t->tail;
 }
 printf("[Error] Identifier %s does not exist!\n\n",s);
 exit(-1);
}

canonical_original_code:
int lookup(char *s, struct A_table_ *t){
 while(t != ((void *)0)){
  if(strcmp(t->id, s)==0){
   return t->value;
  }
  t = t->tail;
 }
 printf("[Error] Identifier %s does not exist!\n\n",s);
 exit(-1);
}

variable_types:
s
char *

variable_types: struct A_table_ { char *id; int value; struct A_table_ *tail; } *


decompiled_code:
int __fastcall print_table(__int64 a1)
{
__int64 v1; // r15
const char *v3; // rsi
const char *v4; // r14
const char **v5; // rbx
int v6; // ebp
int v7; // [rsp+Ch] [rbp-35Ch]
__int64 v8[107]; // [rsp+10h] [rbp-358h] BYREF

v1 = a1;
puts("\n Id:Value ");
puts("[^_^] Now dump Variable");
v7 = 0;
if ( a1 )
{
do
{
if ( v7 <= 0 )
goto LABEL_3;
v4 = *(const char **)v1;
v5 = (const char **)v8;
v6 = 0;
do
{
if ( !strcmp(*v5, v4) )
v6 = 1;
++v5;
}
while ( v5 != (const char **)&v8[(unsigned int)(v7 - 1) + 1] );
if ( !v6 )
{
LABEL_3:
v3 = *(const char **)v1;
v8[v7] = *(_QWORD *)v1;
printf(" %s=%d \n", v3, *(unsigned int *)(v1 + 8));
++v7;
}
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // r15
const char *v3; // rsi
const char *v4; // r14
const char **v5; // rbx
int v6; // ebp
int v7; // [rsp+Ch] [rbp-35Ch]
__int64 v8[107]; // [rsp+10h] [rbp-358h] BYREF

v1 = a1;
puts("\n Id:Value ");
puts("[^_^] Now dump Variable");
v7 = 0;
if ( a1 )
{
do
{
if ( v7 <= 0 )
goto LABEL_3;
v4 = *(const char **)v1;
v5 = (const char **)v8;
v6 = 0;
do
{
if ( !strcmp(*v5, v4) )
v6 = 1;
++v5;
}
while ( v5 != (const char **)&v8[(unsigned int)(v7 - 1) + 1] );
if ( !v6 )
{
LABEL_3:
v3 = *(const char **)v1;
v8[v7] = *(_QWORD *)v1;
printf(" %s=%d \n", v3, *(unsigned int *)(v1 + 8));
++v7;
}
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void print_table(A_table t){
 printf("\n        Id:Value     \n");
 printf("[^_^] Now dump Variable\n");
 int index = 0, i = 0;
 string s_list[100];
 int is_dup = 0;
 while(t != ((void *)0)){
  is_dup = 0;
  for(i = 0; i < index; i++){
   if(strcmp(s_list[i], t->id)==0){
    is_dup = 1;
   }
  }
  if(is_dup == 0){
   s_list[index++] = t->id;
   printf("         %s=%d        \n", t->id, t->value);
  }
  t = t->tail;
 }
 printf("\n");
}

canonical_original_code:
void print_table(struct A_table_ *t){
 printf("\n        Id:Value     \n");
 printf("[^_^] Now dump Variable\n");
 int index = 0; int i = 0;
 char *s_list[100];
 int is_dup = 0;
 while(t != ((void *)0)){
  is_dup = 0;
  for(i = 0; i < index; i++){
   if(strcmp(s_list[i], t->id)==0){
    is_dup = 1;
   }
  }
  if(is_dup == 0){
   s_list[index++] = t->id;
   printf("         %s=%d        \n", t->id, t->value);
  }
  t = t->tail;
 }
 printf("\n");
}

variable_types: index int

variable_types: i int

user_defined_types: struct A_table_ { char *id; int value; struct A_table_ *tail; }


calculate

decompiled_code:
__int64 __fastcall calculate(int a1, int a2, unsigned int a3)
{
unsigned int v4; // edi
__int64 result; // rax

if ( a3 == 2 )
return (unsigned int)(a2 * a1);
if ( a3 > 2 )
{
if ( a3 == 3 )
{
if ( !a2 )
{
puts("[Error] divisor cannot be zero!\n");
exit(-2);
}
result = (unsigned int)(a1 / a2);
}
else
{
result = 0LL;
}
}
else
{
v4 = a1 - a2;
result = (unsigned int)(a2 + a1);
if ( a3 )
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, unsigned int a3)
{
unsigned int v4; // edi
__int64 result; // rax

if ( a3 == 2 )
return (unsigned int)(a2 * a1);
if ( a3 > 2 )
{
if ( a3 == 3 )
{
if ( !a2 )
{
puts("[Error] divisor cannot be zero!\n");
exit(-2);
}
result = (unsigned int)(a1 / a2);
}
else
{
result = 0LL;
}
}
else
{
v4 = a1 - a2;
result = (unsigned int)(a2 + a1);
if ( a3 )
result = v4;
}
return result;
}

original_code:
int calculate(int left, int right, A_binop op){
 int result;
 switch(op){
  case A_plus:
   result = left + right; break;
  case A_minus:
   result = left - right; break;
  case A_times:
   result = left * right; break;
  case A_div:
   if(right == 0){
    printf("[Error] divisor cannot be zero!\n\n");
    exit(-2);
   }
   result = left / right; break;
  default:
   result = 0;
 }
 return result;
}

canonical_original_code:
int calculate(int left, int right, enum A_binop op){
 int result;
 switch(op){
  case A_plus:
   result = left + right; break;
  case A_minus:
   result = left - right; break;
  case A_times:
   result = left * right; break;
  case A_div:
   if(right == 0){
    printf("[Error] divisor cannot be zero!\n\n");
    exit(-2);
   }
   result = left / right; break;
  default:
   result = 0;
 }
 return result;
}

variable_types: left int

variable_types: right int

variable_types: enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 }

variable_types: result int


interpExp

decompiled_code:
__int64 __fastcall interpExp(char **a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax
int v4; // er12
int v5; // eax

v2 = *(unsigned int *)a1;
switch ( (_DWORD)v2 )
{
case 1:
return *((unsigned int *)a1 + 2);
case 0:
return (unsigned int)lookup(a1[1], a2);
case 2:
v4 = interpExp(a1[1]);
v5 = interpExp(a1[3]);
result = (unsigned int)calculate(v4, v5, *((_DWORD *)a1 + 4));
break;
default:
result = 0LL;
if ( (_DWORD)v2 == 3 )
{
interpStm(a1[1], a2, v2, 0LL);
result = interpExp(a1[2]);
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char **a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax
int v4; // er12
int v5; // eax

v2 = *(unsigned int *)a1;
switch ( (_DWORD)v2 )
{
case 1:
return *((unsigned int *)a1 + 2);
case 0:
return (unsigned int)func1(a1[1], a2);
case 2:
v4 = func4(a1[1]);
v5 = func4(a1[3]);
result = (unsigned int)func3(v4, v5, *((_DWORD *)a1 + 4));
break;
default:
result = 0LL;
if ( (_DWORD)v2 == 3 )
{
func5(a1[1], a2, v2, 0LL);
result = func4(a1[2]);
}
break;
}
return result;
}

original_code:
struct IntAndTable interpExp( A_exp exp, A_table table){
 struct IntAndTable iat;
 if(exp->kind == A_numExp){
  iat.i = exp->u.num;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_idExp){
  int val = lookup(exp->u.id, table);
  iat.i = val;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_opExp){
  struct IntAndTable left_iat, right_iat, final_iat;
  left_iat = interpExp(exp->u.op.left, table);
  right_iat = interpExp(exp->u.op.right, left_iat.t);
  final_iat.i = calculate(left_iat.i, right_iat.i, exp->u.op.oper);
  final_iat.t = right_iat.t;
  return final_iat;
 }else if(exp->kind == A_eseqExp){
  iat.t = interpStm(exp->u.eseq.stm, table);
  iat = interpExp(exp->u.eseq.exp, iat.t);
  return iat;
 }
 return iat;
}

canonical_original_code:
struct IntAndTable interpExp(struct A_exp_ *exp, struct A_table_ *table){
 struct IntAndTable iat;
 if(exp->kind == A_numExp){
  iat.i = exp->u.num;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_idExp){
  int val = lookup(exp->u.id, table);
  iat.i = val;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_opExp){
  struct IntAndTable left_iat; struct IntAndTable right_iat; struct IntAndTable final_iat;
  left_iat = interpExp(exp->u.op.left, table);
  right_iat = interpExp(exp->u.op.right, left_iat.t);
  final_iat.i = calculate(left_iat.i, right_iat.i, exp->u.op.oper);
  final_iat.t = right_iat.t;
  return final_iat;
 }else if(exp->kind == A_eseqExp){
  iat.t = interpStm(exp->u.eseq.stm, table);
  iat = interpExp(exp->u.eseq.exp, iat.t);
  return iat;
 }
 return iat;
}

variable_types: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *

variable_types:
table
struct A_table_ *

variable_types: struct IntAndTable { int i; struct A_table_ { char *id; int value; struct A_table_ *tail; } *t; }

variable_types: val int

user_defined_types: struct IntAndTable { int i; struct A_table_ *t; }

user_defined_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; }


interpStm

original_code:
A_table interpStm(A_stm prog, A_table table){
 if(prog->kind == A_compoundStm){
  table = interpStm(prog->u.compound.stm1, table);
  table = interpStm(prog->u.compound.stm2, table);
 }else if(prog->kind == A_assignStm){
  struct IntAndTable int_and_table =
   interpExp( prog->u.assign.exp, table);
  table = (A_table)Table(prog->u.assign.id, int_and_table.i, int_and_table.t);
 }else if(prog->kind == A_printStm){
  A_expList list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   if(list->u.pair.head->kind == A_eseqExp){
    A_stm ex_prog = list->u.pair.head->u.eseq.stm;
    interpStm(ex_prog, table);
   }
   list = list->u.pair.tail;
  }
  if(list->u.last->kind == A_eseqExp){
   interpStm(list->u.last->u.eseq.stm, table);
  }
 }
 return table;
}

canonical_original_code:
struct A_table_ *interpStm(struct A_stm_ *prog, struct A_table_ *table){
 if(prog->kind == A_compoundStm){
  table = interpStm(prog->u.compound.stm1, table);
  table = interpStm(prog->u.compound.stm2, table);
 }else if(prog->kind == A_assignStm){
  struct IntAndTable int_and_table = interpExp( prog->u.assign.exp, table);
  table = (struct A_table_ *)Table(prog->u.assign.id, int_and_table.i, int_and_table.t);
 }else if(prog->kind == A_printStm){
  struct A_expList_ *list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   if(list->u.pair.head->kind == A_eseqExp){
    struct A_stm_ *ex_prog = list->u.pair.head->u.eseq.stm;
    interpStm(ex_prog, table);
   }
   list = list->u.pair.tail;
  }
  if(list->u.last->kind == A_eseqExp){
   interpStm(list->u.last->u.eseq.stm, table);
  }
 }
 return table;
}

return_type: struct A_table_ { char *id; int value; struct A_table_ *tail; } *

user_defined_types: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; }

user_defined_types: enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdi
int *v7; // rbx
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rax
int v12[3]; // [rsp+Ch] [rbp-Ch] BYREF

v12[0] = 0;
v3 = (int *)right_prog(argc, argv, envp);
maxargs(v3, v12);
puts(">> Right Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v12[0]);
v6 = interpStm((char ***)v3, 0LL, v4, v5);
print_table(v6);
v12[0] = 0;
v7 = (int *)error_prog();
maxargs(v7, v12);
puts(">> Error Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v12[0]);
v10 = interpStm((char ***)v7, 0LL, v8, v9);
print_table(v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdi
int *v7; // rbx
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rax
int v12[3]; // [rsp+Ch] [rbp-Ch] BYREF

v12[0] = 0;
v3 = (int *)right_prog(argc, argv, envp);
func0(v3, v12);
puts(">> Right Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v12[0]);
v6 = func5((char ***)v3, 0LL, v4, v5);
func2(v6);
v12[0] = 0;
v7 = (int *)error_prog();
func0(v7, v12);
puts(">> Error Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v12[0]);
v10 = func5((char ***)v7, 0LL, v8, v9);
func2(v10);
return 0;
}

original_code:
int main(){
 int max_args = 0;
 A_table global_table = ((void *)0);
 A_stm right_stm = right_prog();
 maxargs(right_stm, &max_args);
 printf(">> Right Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(right_stm, global_table);
 print_table(global_table);
 max_args = 0;
 global_table = ((void *)0);
 A_stm error_stm = error_prog();
 maxargs(error_stm, &max_args);
 printf(">> Error Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(error_stm, global_table);
 print_table(global_table);
   return 0;
}

canonical_original_code:
int main(){
 int max_args = 0;
 struct A_table_ *global_table = ((void *)0);
 struct A_stm_ *right_stm = right_prog();
 maxargs(right_stm, &max_args);
 printf(">> Right Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(right_stm, global_table);
 print_table(global_table);
 max_args = 0;
 global_table = ((void *)0);
 struct A_stm_ *error_stm = error_prog();
 maxargs(error_stm, &max_args);
 printf(">> Error Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(error_stm, global_table);
 print_table(global_table);
   return 0;
}


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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_stm A_CompoundStm(A_stm stm1, A_stm stm2) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_compoundStm; s->u.compound.stm1=stm1; s->u.compound.stm2=stm2;
  return s;
}

canonical_original_code:
struct A_stm_ *A_CompoundStm(struct A_stm_ *stm1, struct A_stm_ *stm2) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_compoundStm; s->u.compound.stm1=stm1; s->u.compound.stm2=stm2;
  return s;
}

return_type: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_stm A_AssignStm(string id, A_exp exp) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_assignStm; s->u.assign.id=id; s->u.assign.exp=exp;
  return s;
}

canonical_original_code:
struct A_stm_ *A_AssignStm(char *id, struct A_exp_ *exp) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_assignStm; s->u.assign.id=id; s->u.assign.exp=exp;
  return s;
}

variable_types:
id
char *

variable_types:
exp
struct A_exp_ *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_stm A_PrintStm(A_expList exps) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_printStm; s->u.print.exps=exps;
  return s;
}

canonical_original_code:
struct A_stm_ *A_PrintStm(struct A_expList_ *exps) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_printStm; s->u.print.exps=exps;
  return s;
}

variable_types:
exps
struct A_expList_ *

variable_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *


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

result = checked_malloc(32LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(32LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_exp A_IdExp(string id) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_idExp; e->u.id=id;
  return e;
}

canonical_original_code:
struct A_exp_ *A_IdExp(char *id) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_idExp; e->u.id=id;
  return e;
}

return_type: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *


decompiled_code:
__int64 __fastcall A_OpExp(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = checked_malloc(32LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = a2;
*(_QWORD *)(result + 24) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = checked_malloc(32LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = a2;
*(_QWORD *)(result + 24) = a3;
return result;
}

original_code:
A_exp A_OpExp(A_exp left, A_binop oper, A_exp right) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_opExp; e->u.op.left=left; e->u.op.oper=oper; e->u.op.right=right;
  return e;
}

canonical_original_code:
struct A_exp_ *A_OpExp(struct A_exp_ *left, enum A_binop oper, struct A_exp_ *right) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_opExp; e->u.op.left=left; e->u.op.oper=oper; e->u.op.right=right;
  return e;
}

variable_types:
left
struct A_exp_ *

variable_types:
right
struct A_exp_ *


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

result = checked_malloc(32LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(32LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_exp A_EseqExp(A_stm stm, A_exp exp) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_eseqExp; e->u.eseq.stm=stm; e->u.eseq.exp=exp;
  return e;
}

canonical_original_code:
struct A_exp_ *A_EseqExp(struct A_stm_ *stm, struct A_exp_ *exp) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_eseqExp; e->u.eseq.stm=stm; e->u.eseq.exp=exp;
  return e;
}

variable_types:
stm
struct A_stm_ *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_expList A_PairExpList(A_exp head, A_expList tail) {
  A_expList e = checked_malloc(sizeof *e);
  e->kind=A_pairExpList; e->u.pair.head=head; e->u.pair.tail=tail;
  return e;
}

canonical_original_code:
struct A_expList_ *A_PairExpList(struct A_exp_ *head, struct A_expList_ *tail) {
  struct A_expList_ *e = checked_malloc(sizeof *e);
  e->kind=A_pairExpList; e->u.pair.head=head; e->u.pair.tail=tail;
  return e;
}

variable_types:
head
struct A_exp_ *

variable_types:
tail
struct A_expList_ *

variable_types: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_expList A_LastExpList(A_exp last) {
  A_expList e = checked_malloc(sizeof *e);
  e->kind=A_lastExpList; e->u.last=last;
  return e;
}

canonical_original_code:
struct A_expList_ *A_LastExpList(struct A_exp_ *last) {
  struct A_expList_ *e = checked_malloc(sizeof *e);
  e->kind=A_lastExpList; e->u.last=last;
  return e;
}

variable_types:
last
struct A_exp_ *

return_type: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *


Table

decompiled_code:
__int64 __fastcall Table(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = checked_malloc(24LL);
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = checked_malloc(24LL);
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
return result;
}

original_code:
A_table Table(string id, int value, A_table tail){
 A_table t = checked_malloc(sizeof *t);
 t->id = id;
 t->value = value;
 t->tail = tail;
 return t;
}

canonical_original_code:
struct A_table_ *Table(char *id, int value, struct A_table_ *tail){
 struct A_table_ *t = checked_malloc(sizeof *t);
 t->id = id;
 t->value = value;
 t->tail = tail;
 return t;
}

variable_types: value int

variable_types:
tail
struct A_table_ *

variable_types: struct A_table_ { char *id; int value; struct A_table_ *tail; } *


decompiled_code:
void *__fastcall checked_malloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("\nRan out of memory!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("\nRan out of memory!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *checked_malloc(int len)
{void *p = malloc(len);
 if (!p) {
    fprintf(stderr,"\nRan out of memory!\n");
    exit(1);
 }
 return p;
}

variable_types: len int

variable_types:
p
void *


String

decompiled_code:
char *__fastcall String(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)checked_malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
string String(char *s)
{string p = checked_malloc(strlen(s)+1);
 strcpy(p,s);
 return p;
}

canonical_original_code:
char *String(char *s)
{char *p = checked_malloc(strlen(s)+1);
 strcpy(p,s);
 return p;
}

variable_types:
s
char *

variable_types:
p
char *


prog

decompiled_code:
__int64 prog()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rbx
__int64 v16; // rbp
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax

v0 = A_IdExp(&unk_44F);
v1 = A_LastExpList(v0);
v2 = A_PrintStm(v1);
v3 = A_IdExp(&unk_451);
v4 = A_NumExp(10LL);
v5 = A_OpExp(v4, 2LL, v3);
v6 = A_NumExp(1LL);
v7 = A_IdExp(&unk_451);
v8 = A_OpExp(v7, 1LL, v6);
v9 = A_LastExpList(v8);
v10 = A_IdExp(&unk_451);
v11 = A_PairExpList(v10, v9);
v12 = A_PrintStm(v11);
v13 = A_EseqExp(v12, v5);
v14 = A_AssignStm(&unk_44F, v13);
v15 = A_CompoundStm(v14, v2);
v16 = A_NumExp(3LL);
v17 = A_NumExp(5LL);
v18 = A_OpExp(v17, 0LL, v16);
v19 = A_AssignStm(&unk_451, v18);
return A_CompoundStm(v19, v15);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rbx
__int64 v16; // rbp
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax

v0 = A_IdExp(&unk_44F);
v1 = A_LastExpList(v0);
v2 = A_PrintStm(v1);
v3 = A_IdExp(&unk_451);
v4 = A_NumExp(10LL);
v5 = A_OpExp(v4, 2LL, v3);
v6 = A_NumExp(1LL);
v7 = A_IdExp(&unk_451);
v8 = A_OpExp(v7, 1LL, v6);
v9 = A_LastExpList(v8);
v10 = A_IdExp(&unk_451);
v11 = A_PairExpList(v10, v9);
v12 = A_PrintStm(v11);
v13 = A_EseqExp(v12, v5);
v14 = A_AssignStm(&unk_44F, v13);
v15 = A_CompoundStm(v14, v2);
v16 = A_NumExp(3LL);
v17 = A_NumExp(5LL);
v18 = A_OpExp(v17, 0LL, v16);
v19 = A_AssignStm(&unk_451, v18);
return A_CompoundStm(v19, v15);
}

original_code:
A_stm prog(void) {
return
 A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_NumExp(3))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b")))));
}

canonical_original_code:
struct A_stm_ *prog() {
return
 A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_NumExp(3))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b")))));
}