decompiled_code:
__int64 __fastcall get_mask_string(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
char v5; // dl
__int64 v6; // rdi

result = a3 + 1;
v5 = *(_BYTE *)(a1 + result);
if ( v5 )
{
result = 0LL;
v6 = a3 + a1;
do
{
*(_BYTE *)(a2 + result) = v5;
*(_BYTE *)(a2 + result++ + 1) = 0;
v5 = *(_BYTE *)(v6 + result + 1);
}
while ( v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
char v5; // dl
__int64 v6; // rdi

result = a3 + 1;
v5 = *(_BYTE *)(a1 + result);
if ( v5 )
{
result = 0LL;
v6 = a3 + a1;
do
{
*(_BYTE *)(a2 + result) = v5;
*(_BYTE *)(a2 + result++ + 1) = 0;
v5 = *(_BYTE *)(v6 + result + 1);
}
while ( v5 );
}
return result;
}

original_code:
void get_mask_string(char * input, char * destination, int slashPosition) {
    for (int i = slashPosition + 1, j = 0; input[i] != 0; i++, j++) {
        destination[j] = input[i];
        destination[j + 1] = 0;
    }
}

canonical_original_code:
void get_mask_string(char *input, char *destination, int slashPosition) {
    for (int i = slashPosition + 1; int j = 0; input[i] != 0; i++, j++) {
        destination[j] = input[i];
        destination[j + 1] = 0;
    }
}

variable_types: j int


repo: allisonmachado/network-calc

decompiled_code:
int __fastcall print_ip_address(unsigned __int8 *a1)
{
unsigned __int8 *i; // rbx

printf("%d", a1[3]);
for ( i = a1 + 2; ; --i )
{
putchar(46);
printf("%d", *i);
if ( i == a1 )
break;
}
return putchar(32);
}

canonical_decompiled_code:
int __fastcall func15(unsigned __int8 *a1)
{
unsigned __int8 *i; // rbx

printf("%d", a1[3]);
for ( i = a1 + 2; ; --i )
{
putchar(46);
printf("%d", *i);
if ( i == a1 )
break;
}
return putchar(32);
}

original_code:
void print_ip_address(int * number_addr)
{
    unsigned char * raw_ptr;
    int i, aux_int;
    raw_ptr = (unsigned char *) number_addr;
    for (i = 3; i > -1; i--)
    {
        aux_int = raw_ptr[i];
        printf("%d", aux_int);
        if(i != 0)
            printf(".");
    }
    printf(" ");
}

canonical_original_code:
void print_ip_address(int *number_addr)
{
    unsigned char *raw_ptr;
    int i; int aux_int;
    raw_ptr = (unsigned char *) number_addr;
    for (i = 3; i > -1; i--)
    {
        aux_int = raw_ptr[i];
        printf("%d", aux_int);
        if(i != 0)
            printf(".");
    }
    printf(" ");
}

variable_types: i int

return_type: void


decompiled_code:
int __fastcall binary_print(int a1)
{
int v1; // er12
unsigned int v2; // er13
int result; // eax
unsigned int v4; // ebx
int v5; // ebp

v1 = 24;
v2 = -16777216;
do
{
v4 = (v2 & a1) >> v1;
putchar(32);
v5 = 8;
do
{
if ( (v4 & 0x80u) == 0 )
result = putchar(48);
else
result = putchar(49);
LOBYTE(v4) = 2 * v4;
--v5;
}
while ( v5 );
v2 >>= 8;
v1 -= 8;
}
while ( v1 != -8 );
return result;
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
int v1; // er12
unsigned int v2; // er13
int result; // eax
unsigned int v4; // ebx
int v5; // ebp

v1 = 24;
v2 = -16777216;
do
{
v4 = (v2 & a1) >> v1;
putchar(32);
v5 = 8;
do
{
if ( (v4 & 0x80u) == 0 )
result = putchar(48);
else
result = putchar(49);
LOBYTE(v4) = 2 * v4;
--v5;
}
while ( v5 );
v2 >>= 8;
v1 -= 8;
}
while ( v1 != -8 );
return result;
}

original_code:
void binary_print(unsigned int number)
{
    unsigned int mask = 0xff000000;
    unsigned int shift = 24;
    unsigned int byte, byte_iterator, bit_iterator;
    for(byte_iterator = 0; byte_iterator < 4; byte_iterator++)
    {
        byte = (number & mask) >> shift;
        printf(" ");
        for(bit_iterator = 0; bit_iterator < 8; bit_iterator++)
        {
            if(byte & 128)
                printf("1");
            else
                printf("0");
            byte <<= 1;
        }
        mask >>= 8;
        shift -= 8;
    }
}

canonical_original_code:
void binary_print(unsigned int number)
{
    unsigned int mask = 0xff000000;
    unsigned int shift = 24;
    unsigned int byte; unsigned int byte_iterator; unsigned int bit_iterator;
    for(byte_iterator = 0; byte_iterator < 4; byte_iterator++)
    {
        byte = (number & mask) >> shift;
        printf(" ");
        for(bit_iterator = 0; bit_iterator < 8; bit_iterator++)
        {
            if(byte & 128)
                printf("1");
            else
                printf("0");
            byte <<= 1;
        }
        mask >>= 8;
        shift -= 8;
    }
}

variable_types:
number
unsigned int

variable_types:
mask
unsigned int

variable_types:
shift
unsigned int

variable_types:
byte
unsigned int


decompiled_code:
__int64 __fastcall handle_input(const char *a1)
{
__int64 result; // rax
unsigned int v2; // ebx
int v3; // er12
unsigned int v4; // ebx
int v5; // ecx

ip_number = atoi(a1) << 24;
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v2 = 1;
v3 = 16;
do
{
if ( (_BYTE)result == 46 )
{
ip_number += atoi(&a1[v2]) << v3;
v3 -= 8;
}
LOBYTE(result) = a1[v2++];
}
while ( (_BYTE)result );
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v4 = 1;
do
{
if ( (_BYTE)result == 47 )
number_of_mask_bits += atoi(&a1[v4]);
result = (unsigned __int8)a1[v4++];
}
while ( (_BYTE)result );
}
}
if ( (unsigned int)(31 - number_of_mask_bits) <= 0x1E )
{
LODWORD(result) = mask_number;
v5 = 31;
do
result = (unsigned int)((1 << v5--) + result);
while ( v5 != 31 - number_of_mask_bits );
mask_number = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
__int64 result; // rax
unsigned int v2; // ebx
int v3; // er12
unsigned int v4; // ebx
int v5; // ecx

ip_number = atoi(a1) << 24;
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v2 = 1;
v3 = 16;
do
{
if ( (_BYTE)result == 46 )
{
ip_number += atoi(&a1[v2]) << v3;
v3 -= 8;
}
LOBYTE(result) = a1[v2++];
}
while ( (_BYTE)result );
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v4 = 1;
do
{
if ( (_BYTE)result == 47 )
number_of_mask_bits += atoi(&a1[v4]);
result = (unsigned __int8)a1[v4++];
}
while ( (_BYTE)result );
}
}
if ( (unsigned int)(31 - number_of_mask_bits) <= 0x1E )
{
LODWORD(result) = mask_number;
v5 = 31;
do
result = (unsigned int)((1 << v5--) + result);
while ( v5 != 31 - number_of_mask_bits );
mask_number = result;
}
return result;
}

original_code:
void handle_input(char * string)
{
    unsigned int i, shift, temp = 0;
    shift = 24;
    ip_number = (atoi(&string[0]) << shift);
    shift -= 8;
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 46)
        {
            ip_number += (atoi(&string[i + 1]) << shift);
            shift -= 8;
        }
    }
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 47)
        {
            number_of_mask_bits += atoi(&string[i + 1]);
        }
    }
    for(i = 31; i > (31 - number_of_mask_bits); i--)
    {
        temp = (1 << i);
        mask_number += temp;
    }
}

canonical_original_code:
void handle_input(char *string)
{
    unsigned int i; unsigned int shift; unsigned int temp = 0;
    shift = 24;
    ip_number = (atoi(&string[0]) << shift);
    shift -= 8;
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 46)
        {
            ip_number += (atoi(&string[i + 1]) << shift);
            shift -= 8;
        }
    }
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 47)
        {
            number_of_mask_bits += atoi(&string[i + 1]);
        }
    }
    for(i = 31; i > (31 - number_of_mask_bits); i--)
    {
        temp = (1 << i);
        mask_number += temp;
    }
}

variable_types:
string
char *

variable_types:
i
unsigned int

variable_types:
temp
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // ebp
int v5; // eax
int v6; // er12
double v7; // xmm0_8
char v9[4]; // [rsp+Dh] [rbp-4Bh] BYREF
char cp[15]; // [rsp+11h] [rbp-47h] BYREF
int v11; // [rsp+20h] [rbp-38h] BYREF
int v12; // [rsp+24h] [rbp-34h] BYREF
int v13; // [rsp+28h] [rbp-30h] BYREF
int v14[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v14[0] = 0;
v13 = 0;
v12 = 0;
v11 = 0;
if ( argc <= 1 )
usage(*argv, "You must provide a valid ip/mask");
v3 = (char *)argv[1];
v4 = get_input_size(v3);
if ( v4 > 18 )
usage(*argv, "You must provide a valid ip/mask");
if ( (unsigned int)get_number_of_slashes(v3) != 1 )
usage(*argv, "You must provide a valid ip/mask");
v5 = get_slash_position(v3);
v6 = v5;
if ( !v5 || v4 - 1 == v5 )
usage(*argv, "You must provide a valid ip/mask");
get_ip_string((__int64)v3, (__int64)cp, v5);
if ( !is_valid_ip_address(cp) )
usage(*argv, "You must provide a valid ip/mask");
get_mask_string((__int64)argv[1], (__int64)v9, v6);
if ( !is_valid_mask(v9) )
usage(*argv, "You must provide a valid ip/mask");
putchar(10);
printf("Entry: %s\n", argv[1]);
putchar(10);
handle_input(argv[1]);
v14[0] = ip_number & mask_number;
v13 = (ip_number & mask_number) + ~mask_number;
v12 = (ip_number & mask_number) + 1;
v11 = v13 - 1;
printf("Network address: ");
putchar(9);
binary_print(v14[0]);
putchar(9);
print_ip_address((unsigned __int8 *)v14);
putchar(10);
printf("Netmask: ");
putchar(9);
binary_print(mask_number);
putchar(9);
print_ip_address((unsigned __int8 *)&mask_number);
printf("(%d bits)", (unsigned int)number_of_mask_bits);
putchar(10);
printf("Broadcast addr: ");
putchar(9);
binary_print(v13);
putchar(9);
print_ip_address((unsigned __int8 *)&v13);
putchar(10);
printf("Min Host value: ");
putchar(9);
binary_print(v12);
putchar(9);
print_ip_address((unsigned __int8 *)&v12);
putchar(10);
printf("Max Host value: ");
putchar(9);
binary_print(v11);
putchar(9);
print_ip_address((unsigned __int8 *)&v11);
putchar(10);
putchar(10);
v7 = pow(2.0, (double)(32 - number_of_mask_bits));
printf("The possible number of hosts on this network is %d.\n", (unsigned int)((int)v7 - 2));
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // ebp
int v5; // eax
int v6; // er12
double v7; // xmm0_8
char v9[4]; // [rsp+Dh] [rbp-4Bh] BYREF
char cp[15]; // [rsp+11h] [rbp-47h] BYREF
int v11; // [rsp+20h] [rbp-38h] BYREF
int v12; // [rsp+24h] [rbp-34h] BYREF
int v13; // [rsp+28h] [rbp-30h] BYREF
int v14[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v14[0] = 0;
v13 = 0;
v12 = 0;
v11 = 0;
if ( argc <= 1 )
func7(*argv, "You must provide a valid ip/mask");
v3 = (char *)argv[1];
v4 = func8(v3);
if ( v4 > 18 )
func7(*argv, "You must provide a valid ip/mask");
if ( (unsigned int)func9(v3) != 1 )
func7(*argv, "You must provide a valid ip/mask");
v5 = func10(v3);
v6 = v5;
if ( !v5 || v4 - 1 == v5 )
func7(*argv, "You must provide a valid ip/mask");
func13((__int64)v3, (__int64)cp, v5);
if ( !func11(cp) )
func7(*argv, "You must provide a valid ip/mask");
func14((__int64)argv[1], (__int64)v9, v6);
if ( !func12(v9) )
func7(*argv, "You must provide a valid ip/mask");
putchar(10);
printf("Entry: %s\n", argv[1]);
putchar(10);
func17(argv[1]);
v14[0] = ip_number & mask_number;
v13 = (ip_number & mask_number) + ~mask_number;
v12 = (ip_number & mask_number) + 1;
v11 = v13 - 1;
printf("Network address: ");
putchar(9);
func16(v14[0]);
putchar(9);
func15((unsigned __int8 *)v14);
putchar(10);
printf("Netmask: ");
putchar(9);
func16(mask_number);
putchar(9);
func15((unsigned __int8 *)&mask_number);
printf("(%d bits)", (unsigned int)number_of_mask_bits);
putchar(10);
printf("Broadcast addr: ");
putchar(9);
func16(v13);
putchar(9);
func15((unsigned __int8 *)&v13);
putchar(10);
printf("Min Host value: ");
putchar(9);
func16(v12);
putchar(9);
func15((unsigned __int8 *)&v12);
putchar(10);
printf("Max Host value: ");
putchar(9);
func16(v11);
putchar(9);
func15((unsigned __int8 *)&v11);
putchar(10);
putchar(10);
v7 = pow(2.0, (double)(32 - number_of_mask_bits));
printf("The possible number of hosts on this network is %d.\n", (unsigned int)((int)v7 - 2));
putchar(10);
return 0;
}

original_code:
int main(int argc, char ** argv)
{
    unsigned int network_address = 0;
    unsigned int broadcast = 0;
    unsigned int host_min = 0;
    unsigned int host_max = 0;
    double number_of_hosts_bits = 0;
    char ip_string[15];
    char mask_string[4];
    if(argc < 2)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int inputSize = get_input_size(argv[1]);
    if (inputSize > 18)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int numberOfSlashes = get_number_of_slashes(argv[1]);
    if (numberOfSlashes != 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int slashPosition = get_slash_position(argv[1]);
    if (slashPosition == 0 || slashPosition == inputSize - 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_ip_string(argv[1], ip_string, slashPosition);
    if (!is_valid_ip_address(ip_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_mask_string(argv[1], mask_string, slashPosition);
    if (!is_valid_mask(mask_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    printf("\n");
    printf("Entry: %s\n", argv[1]);
    printf("\n");
    handle_input(argv[1]);
    network_address = ip_number & mask_number;
    broadcast = ~(mask_number);
    broadcast = broadcast + network_address;
    host_min = network_address + 1;
    host_max = broadcast - 1;
    printf("Network address: ");
    printf("\t");
    binary_print(network_address);
    printf("\t");
    print_ip_address(&network_address);
    printf("\n");
    printf("Netmask:          ");
    printf("\t");
    binary_print(mask_number);
    printf("\t");
    print_ip_address(&mask_number);
    printf("(%d bits)", number_of_mask_bits);
    printf("\n");
    printf("Broadcast addr:   ");
    printf("\t");
    binary_print(broadcast);
    printf("\t");
    print_ip_address(&broadcast);
    printf("\n");
    printf("Min Host value:   ");
    printf("\t");
    binary_print(host_min);
    printf("\t");
    print_ip_address(&host_min);
    printf("\n");
    printf("Max Host value:   ");
    printf("\t");
    binary_print(host_max);
    printf("\t");
    print_ip_address(&host_max);
    printf("\n");
    printf("\n");
    number_of_hosts_bits = 32 - number_of_mask_bits;
    printf("The possible number of hosts on this network is %d.\n", (int)pow(2, number_of_hosts_bits) - 2);
    printf("\n");
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned int network_address = 0;
    unsigned int broadcast = 0;
    unsigned int host_min = 0;
    unsigned int host_max = 0;
    double number_of_hosts_bits = 0;
    char ip_string[15];
    char mask_string[4];
    if(argc < 2)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int inputSize = get_input_size(argv[1]);
    if (inputSize > 18)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int numberOfSlashes = get_number_of_slashes(argv[1]);
    if (numberOfSlashes != 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int slashPosition = get_slash_position(argv[1]);
    if (slashPosition == 0 || slashPosition == inputSize - 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_ip_string(argv[1], ip_string, slashPosition);
    if (!is_valid_ip_address(ip_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_mask_string(argv[1], mask_string, slashPosition);
    if (!is_valid_mask(mask_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    printf("\n");
    printf("Entry: %s\n", argv[1]);
    printf("\n");
    handle_input(argv[1]);
    network_address = ip_number & mask_number;
    broadcast = ~(mask_number);
    broadcast = broadcast + network_address;
    host_min = network_address + 1;
    host_max = broadcast - 1;
    printf("Network address: ");
    printf("\t");
    binary_print(network_address);
    printf("\t");
    print_ip_address(&network_address);
    printf("\n");
    printf("Netmask:          ");
    printf("\t");
    binary_print(mask_number);
    printf("\t");
    print_ip_address(&mask_number);
    printf("(%d bits)", number_of_mask_bits);
    printf("\n");
    printf("Broadcast addr:   ");
    printf("\t");
    binary_print(broadcast);
    printf("\t");
    print_ip_address(&broadcast);
    printf("\n");
    printf("Min Host value:   ");
    printf("\t");
    binary_print(host_min);
    printf("\t");
    print_ip_address(&host_min);
    printf("\n");
    printf("Max Host value:   ");
    printf("\t");
    binary_print(host_max);
    printf("\t");
    print_ip_address(&host_max);
    printf("\n");
    printf("\n");
    number_of_hosts_bits = 32 - number_of_mask_bits;
    printf("The possible number of hosts on this network is %d.\n", (int)pow(2, number_of_hosts_bits) - 2);
    printf("\n");
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
broadcast
unsigned int

variable_types: inputSize int

variable_types: numberOfSlashes int

variable_types: slashPosition int

return_type: int


repo: allwinner-dev-team/atag-tools

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
unsigned int v4; // er12
unsigned int v5; // er15
unsigned int v6; // er13
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
int result; // eax
unsigned int v11; // [rsp+4h] [rbp-864h]
unsigned int v12; // [rsp+8h] [rbp-860h]
unsigned int v13; // [rsp+Ch] [rbp-85Ch]
char *endptr; // [rsp+18h] [rbp-850h] BYREF
char filename[8]; // [rsp+20h] [rbp-848h] BYREF
__int64 v16; // [rsp+28h] [rbp-840h]
char v17[1008]; // [rsp+30h] [rbp-838h] BYREF
char dest[8]; // [rsp+420h] [rbp-448h] BYREF
__int64 v19; // [rsp+428h] [rbp-440h]
char v20[1008]; // [rsp+430h] [rbp-438h] BYREF
int longind[15]; // [rsp+82Ch] [rbp-3Ch] BYREF

longind[0] = 0;
*(_QWORD *)dest = 0LL;
v19 = 0LL;
memset(v20, 0, sizeof(v20));
*(_QWORD *)filename = 0LL;
v16 = 0LL;
memset(v17, 0, sizeof(v17));
v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
v13 = 0;
v12 = 0;
v11 = 0;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, &shortopts, &long_options_0, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v3 = strtol(_bss_start, &endptr, 0);
break;
case 'c':
strcpy(dest, _bss_start);
break;
case 'f':
v11 = strtol(_bss_start, &endptr, 0);
break;
case 'i':
v4 = strtol(_bss_start, &endptr, 0);
break;
case 'o':
strcpy(filename, _bss_start);
break;
case 'p':
v12 = strtol(_bss_start, &endptr, 0);
break;
case 'r':
v13 = strtol(_bss_start, &endptr, 0);
break;
case 's':
v6 = strtol(_bss_start, &endptr, 0);
break;
case 't':
v5 = strtol(_bss_start, &endptr, 0);
break;
default:
continue;
}
}
if ( filename[0] )
{
v8 = fopen(filename, "w");
if ( v8 )
{
v9 = genatags_initialize();
genatags_core(v9, v11, v12, v13);
if ( v6 && v5 )
genatags_mem(v9, v6, v5);
if ( v4 && v3 )
genatags_initrd(v9, v4, v3);
if ( dest[0] )
genatags_cmdline(v9, dest);
genatags_none(v9);
genatags_dump(v9, v8);
fclose(v8);
result = 0;
}
else
{
fwrite("ERROR: could not open output file\n", 1uLL, 0x22uLL, stderr);
result = 2;
}
}
else
{
fwrite("ERROR: no output file specified\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
unsigned int v4; // er12
unsigned int v5; // er15
unsigned int v6; // er13
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
int result; // eax
unsigned int v11; // [rsp+4h] [rbp-864h]
unsigned int v12; // [rsp+8h] [rbp-860h]
unsigned int v13; // [rsp+Ch] [rbp-85Ch]
char *endptr; // [rsp+18h] [rbp-850h] BYREF
char filename[8]; // [rsp+20h] [rbp-848h] BYREF
__int64 v16; // [rsp+28h] [rbp-840h]
char v17[1008]; // [rsp+30h] [rbp-838h] BYREF
char dest[8]; // [rsp+420h] [rbp-448h] BYREF
__int64 v19; // [rsp+428h] [rbp-440h]
char v20[1008]; // [rsp+430h] [rbp-438h] BYREF
int longind[15]; // [rsp+82Ch] [rbp-3Ch] BYREF

longind[0] = 0;
*(_QWORD *)dest = 0LL;
v19 = 0LL;
memset(v20, 0, sizeof(v20));
*(_QWORD *)filename = 0LL;
v16 = 0LL;
memset(v17, 0, sizeof(v17));
v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
v13 = 0;
v12 = 0;
v11 = 0;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, &shortopts, &long_options_0, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v3 = strtol(_bss_start, &endptr, 0);
break;
case 'c':
strcpy(dest, _bss_start);
break;
case 'f':
v11 = strtol(_bss_start, &endptr, 0);
break;
case 'i':
v4 = strtol(_bss_start, &endptr, 0);
break;
case 'o':
strcpy(filename, _bss_start);
break;
case 'p':
v12 = strtol(_bss_start, &endptr, 0);
break;
case 'r':
v13 = strtol(_bss_start, &endptr, 0);
break;
case 's':
v6 = strtol(_bss_start, &endptr, 0);
break;
case 't':
v5 = strtol(_bss_start, &endptr, 0);
break;
default:
continue;
}
}
if ( filename[0] )
{
v8 = fopen(filename, "w");
if ( v8 )
{
v9 = func7();
func10(v9, v11, v12, v13);
if ( v6 && v5 )
func11(v9, v6, v5);
if ( v4 && v3 )
func12(v9, v4, v3);
if ( dest[0] )
func13(v9, dest);
func14(v9);
func9(v9, v8);
fclose(v8);
result = 0;
}
else
{
fwrite("ERROR: could not open output file\n", 1uLL, 0x22uLL, stderr);
result = 2;
}
}
else
{
fwrite("ERROR: no output file specified\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv)
{
    struct tag * atag;
    char *progname = *argv;
    int f = open(*++argv, 00);
    if (f == -1) {
        printf("%s binary_atag_data_file\n", progname);
        exit(1);
    }
    int cnt = read(f, atag_buf, 10000);
    printf("read %d bytes from %s in buffer of size 10000\n", cnt, *argv);
    argc = 0;
    atag = (struct tag*) atag_buf;
    while (atag->hdr.tag != 0x00000000) {
        printf("%04d - %04d:%08x", argc, atag->hdr.size, atag->hdr.tag);
        switch (atag->hdr.tag) {
            case 0x00000000: printf(" END ATAG\n");
                            break;
            case 0x414f4d50:printf(" OMAP table (%d bytes)\n", atag->hdr.size << 2);
                            dump_omap((struct omap_tag *) &(atag->u));
                            break;
            case 0x54410001: printf(" ATAG CORE");
                            printf(" flags=%08x", atag->u.core.flags);
                            printf(" pagesize=%08x", atag->u.core.pagesize);
                            printf(" rootdev=%08x", atag->u.core.rootdev);
                            printf("\n");
                            break;
            case 0x54410002: printf(" ATAG MEM");
                            printf(" size=%08x", atag->u.mem.size);
                            printf(" start=%08x", atag->u.mem.start);
                            printf("\n");
                            break;
            case 0x54410003: printf(" ATAG VIDEOTEXT");
                            printf(" x=%02x", atag->u.videotext.x);
                            printf(" y=%02x", atag->u.videotext.y);
                            printf(" video_page=%04x", atag->u.videotext.video_page);
                            printf(" video_mode=%02x", atag->u.videotext.video_mode);
                            printf(" video_cols=%02x", atag->u.videotext.video_cols);
                            printf(" video_ega_bx=%04x", atag->u.videotext.video_ega_bx);
                            printf(" video_lines=%02x", atag->u.videotext.video_lines);
                            printf(" video_isvga=%02x", atag->u.videotext.video_isvga);
                            printf(" video_points=%04x", atag->u.videotext.video_points);
                            printf("\n");
                            break;
            case 0x54410004: printf(" ATAG RAMDISK");
                            printf(" flags=%08x", atag->u.ramdisk.flags);
                            printf(" size=%08x", atag->u.ramdisk.size);
                            printf(" start=%08x", atag->u.ramdisk.start);
                            printf("\n");
                            break;
            case 0x54420005: printf(" ATAG INITRD2");
                            printf(" start=%08x", atag->u.initrd.start);
                            printf(" size=%08x", atag->u.initrd.size);
                            printf("\n");
                            break;
            case 0x54410006: printf(" ATAG SERIAL");
                            printf(" low=%08x", atag->u.serialnr.low);
                            printf(" high=%08x", atag->u.serialnr.high);
                            printf("\n");
                            break;
            case 0x54410007: printf(" ATAG REVISION");
                            printf(" revision=%08x", atag->u.revision.rev);
                            printf("\n");
                            break;
            case 0x54410008: printf(" ATAG VIDEOLFB");
                            printf(" lfb_width=%04x", atag->u.videolfb.lfb_width);
                            printf(" lfb_height=%04x", atag->u.videolfb.lfb_height);
                            printf(" lfb_depth=%04x", atag->u.videolfb.lfb_depth);
                            printf(" lfb_linelength=%04x", atag->u.videolfb.lfb_linelength);
                            printf(" lfb_base=%08x", atag->u.videolfb.lfb_base);
                            printf(" lfb_size=%08x", atag->u.videolfb.lfb_size);
                            printf(" red_size=%02x", atag->u.videolfb.red_size);
                            printf(" res_pos=%02x", atag->u.videolfb.red_pos);
                            printf(" green_size=%02x", atag->u.videolfb.green_size);
                            printf(" green_pos=%02x", atag->u.videolfb.green_pos);
                            printf(" blue_size=%02x", atag->u.videolfb.blue_size);
                            printf(" blue_pos=%02x", atag->u.videolfb.blue_pos);
                            printf(" rsvd_size=%02x", atag->u.videolfb.rsvd_size);
                            printf(" rsvd_pos=%02x", atag->u.videolfb.rsvd_pos);
                            printf("\n");
                            break;
            case 0x54410009:
                            printf(" ATAG CMDLINE");
                            printf(" %s", atag->u.cmdline.cmdline);
                            printf("\n");
                            break;
            default: printf("unknown tag\n");
        }
        argc += atag->hdr.size<<2;
        atag = ((struct tag *)((u32 *)(atag) + (atag)->hdr.size));
    }
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct tag *atag;
    char *progname = *argv;
    int f = open(*++argv, 00);
    if (f == -1) {
        printf("%s binary_atag_data_file\n", progname);
        exit(1);
    }
    int cnt = read(f, atag_buf, 10000);
    printf("read %d bytes from %s in buffer of size 10000\n", cnt, *argv);
    argc = 0;
    atag = (struct tag *) atag_buf;
    while (atag->hdr.tag != 0x00000000) {
        printf("%04d - %04d:%08x", argc, atag->hdr.size, atag->hdr.tag);
        switch (atag->hdr.tag) {
            case 0x00000000: printf(" END ATAG\n");
                            break;
            case 0x414f4d50:printf(" OMAP table (%d bytes)\n", atag->hdr.size << 2);
                            dump_omap((struct omap_tag *) &(atag->u));
                            break;
            case 0x54410001: printf(" ATAG CORE");
                            printf(" flags=%08x", atag->u.core.flags);
                            printf(" pagesize=%08x", atag->u.core.pagesize);
                            printf(" rootdev=%08x", atag->u.core.rootdev);
                            printf("\n");
                            break;
            case 0x54410002: printf(" ATAG MEM");
                            printf(" size=%08x", atag->u.mem.size);
                            printf(" start=%08x", atag->u.mem.start);
                            printf("\n");
                            break;
            case 0x54410003: printf(" ATAG VIDEOTEXT");
                            printf(" x=%02x", atag->u.videotext.x);
                            printf(" y=%02x", atag->u.videotext.y);
                            printf(" video_page=%04x", atag->u.videotext.video_page);
                            printf(" video_mode=%02x", atag->u.videotext.video_mode);
                            printf(" video_cols=%02x", atag->u.videotext.video_cols);
                            printf(" video_ega_bx=%04x", atag->u.videotext.video_ega_bx);
                            printf(" video_lines=%02x", atag->u.videotext.video_lines);
                            printf(" video_isvga=%02x", atag->u.videotext.video_isvga);
                            printf(" video_points=%04x", atag->u.videotext.video_points);
                            printf("\n");
                            break;
            case 0x54410004: printf(" ATAG RAMDISK");
                            printf(" flags=%08x", atag->u.ramdisk.flags);
                            printf(" size=%08x", atag->u.ramdisk.size);
                            printf(" start=%08x", atag->u.ramdisk.start);
                            printf("\n");
                            break;
            case 0x54420005: printf(" ATAG INITRD2");
                            printf(" start=%08x", atag->u.initrd.start);
                            printf(" size=%08x", atag->u.initrd.size);
                            printf("\n");
                            break;
            case 0x54410006: printf(" ATAG SERIAL");
                            printf(" low=%08x", atag->u.serialnr.low);
                            printf(" high=%08x", atag->u.serialnr.high);
                            printf("\n");
                            break;
            case 0x54410007: printf(" ATAG REVISION");
                            printf(" revision=%08x", atag->u.revision.rev);
                            printf("\n");
                            break;
            case 0x54410008: printf(" ATAG VIDEOLFB");
                            printf(" lfb_width=%04x", atag->u.videolfb.lfb_width);
                            printf(" lfb_height=%04x", atag->u.videolfb.lfb_height);
                            printf(" lfb_depth=%04x", atag->u.videolfb.lfb_depth);
                            printf(" lfb_linelength=%04x", atag->u.videolfb.lfb_linelength);
                            printf(" lfb_base=%08x", atag->u.videolfb.lfb_base);
                            printf(" lfb_size=%08x", atag->u.videolfb.lfb_size);
                            printf(" red_size=%02x", atag->u.videolfb.red_size);
                            printf(" res_pos=%02x", atag->u.videolfb.red_pos);
                            printf(" green_size=%02x", atag->u.videolfb.green_size);
                            printf(" green_pos=%02x", atag->u.videolfb.green_pos);
                            printf(" blue_size=%02x", atag->u.videolfb.blue_size);
                            printf(" blue_pos=%02x", atag->u.videolfb.blue_pos);
                            printf(" rsvd_size=%02x", atag->u.videolfb.rsvd_size);
                            printf(" rsvd_pos=%02x", atag->u.videolfb.rsvd_pos);
                            printf("\n");
                            break;
            case 0x54410009:
                            printf(" ATAG CMDLINE");
                            printf(" %s", atag->u.cmdline.cmdline);
                            printf("\n");
                            break;
            default: printf("unknown tag\n");
        }
        argc += atag->hdr.size<<2;
        atag = ((struct tag *)((unsigned int *)(atag) + (atag)->hdr.size));
    }
    exit(0);
}

variable_types: struct tag { struct tag_header { unsigned int size; unsigned int tag; } hdr; union { struct tag_core { unsigned int flags; unsigned int pagesize; unsigned int rootdev; } core; struct tag_mem32 { unsigned int size; unsigned int start; } mem; struct tag_videotext { unsigned char x; unsigned char y; unsigned short video_page; unsigned char video_mode; unsigned char video_cols; unsigned short video_ega_bx; unsigned char video_lines; unsigned char video_isvga; unsigned short video_points; } videotext; struct tag_ramdisk { unsigned int flags; unsigned int size; unsigned int start; } ramdisk; struct tag_initrd { unsigned int start; unsigned int size; } initrd; struct tag_serialnr { unsigned int low; unsigned int high; } serialnr; struct tag_revision { unsigned int rev; } revision; struct tag_videolfb { unsigned short lfb_width; unsigned short lfb_height; unsigned short lfb_depth; unsigned short lfb_linelength; unsigned int lfb_base; unsigned int lfb_size; unsigned char red_size; unsigned char red_pos; unsigned char green_size; unsigned char green_pos; unsigned char blue_size; unsigned char blue_pos; unsigned char rsvd_size; unsigned char rsvd_pos; } videolfb; struct tag_cmdline { char cmdline[1]; } cmdline; struct tag_acorn { unsigned int memc_control_reg; unsigned int vram_pages; unsigned char sounddefault; unsigned char adfsdrives; } acorn; struct tag_omap { unsigned char data[]; } omap; struct tag_memclk { unsigned int fmemclk; } memclk; } u; } *

variable_types:
progname
char *

variable_types: f int

variable_types: cnt int

user_defined_types: struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem; struct tag_videotext videotext; struct tag_ramdisk ramdisk; struct tag_initrd initrd; struct tag_serialnr serialnr; struct tag_revision revision; struct tag_videolfb videolfb; struct tag_cmdline cmdline; struct tag_acorn acorn; struct tag_omap omap; struct tag_memclk memclk; } u; }

user_defined_types: struct omap_tag { struct omap_tag_header hdr; union { struct omap_clock_config clock; struct omap_serial_console_config serial_console; struct omap_sti_console_config sti_console; struct omap_usb_config usb; struct omap_lcd_config lcd; struct omap_fbmem_config fbmem; struct omap_gpio_switch_config gpio_switch; struct omap_uart_config uart; struct omap_tea5761_config tea5761; struct omap_partition_config partition; struct omap_flash_part_str_config flash_part_str; struct omap_boot_reason_config boot_reason; struct omap_version_config version; struct omap_bluetooth_config bluetooth; struct omap_wlan_cx3110x_config wlan_cx3110x; struct omap_cbus_config cbus; struct omap_em_asic_bb5_config em_asic_bb5; } u; }

user_defined_types: struct omap_tag_header { unsigned short tag; unsigned short size; }

user_defined_types: struct omap_clock_config { unsigned char system_clock_type; }

user_defined_types: struct omap_serial_console_config { unsigned char console_uart; unsigned int console_speed; }

user_defined_types: struct omap_sti_console_config { unsigned int enable; unsigned char channel; }

user_defined_types: struct omap_usb_config { unsigned int register_host; unsigned int register_dev; unsigned char otg; unsigned char hmc_mode; unsigned char rwc; unsigned char pins[3]; }

user_defined_types: struct omap_lcd_config { char panel_name[16]; char ctrl_name[16]; short nreset_gpio; unsigned char data_lines; }

user_defined_types: struct omap_fbmem_config { unsigned int start; unsigned int size; }

user_defined_types: struct omap_gpio_switch_config { char name[12]; unsigned short gpio; unsigned char flags; unsigned char type; unsigned int key_code; }

user_defined_types: struct omap_uart_config { unsigned int enabled_uarts; }

user_defined_types: struct omap_tea5761_config { unsigned short enable_gpio; }

user_defined_types: struct omap_partition_config { char name[16]; unsigned int size; unsigned int offset; unsigned int mask_flags; }

user_defined_types: struct omap_flash_part_str_config { char part_table[]; }

user_defined_types: struct omap_boot_reason_config { char reason_str[12]; }

user_defined_types: struct omap_version_config { char component[12]; char version[12]; }

user_defined_types: struct omap_bluetooth_config { unsigned char chip_type; unsigned char bt_wakeup_gpio; unsigned char host_wakeup_gpio; unsigned char reset_gpio; unsigned char bt_uart; unsigned char bd_addr[6]; unsigned char bt_sysclk; }

user_defined_types: struct omap_wlan_cx3110x_config { unsigned char chip_type; unsigned char reserverd; short power_gpio; short irq_gpio; short spi_cs_gpio; }

user_defined_types: struct omap_cbus_config { short clk_gpio; short dat_gpio; short sel_gpio; }

user_defined_types: struct omap_em_asic_bb5_config { short retu_irq_gpio; short tahvo_irq_gpio; }


decompiled_code:
_DWORD *genatags_initialize()
{
void *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x2800uLL);
result = malloc(0x10uLL);
*(_QWORD *)result = v0;
result[2] = 10240;
result[3] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func7()
{
void *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x2800uLL);
result = malloc(0x10uLL);
*(_QWORD *)result = v0;
result[2] = 10240;
result[3] = 0;
return result;
}

original_code:
genatags *genatags_initialize(void)
{
    void *mem = malloc(10240);
    genatags *atags = malloc(sizeof(genatags));
    atags->mem = mem;
    atags->size = 10240;
    atags->used = 0;
    return atags;
}

canonical_original_code:
struct genatags *genatags_initialize()
{
    void *mem = malloc(10240);
    struct genatags *atags = malloc(sizeof(genatags));
    atags->mem = mem;
    atags->size = 10240;
    atags->used = 0;
    return atags;
}

variable_types:
mem
void *

variable_types: struct genatags { void *mem; unsigned int size; unsigned int used; } *


original_code:
struct tag *genatags_add(genatags *atags, int size)
{
    struct tag *ptr;
    size <<= 2;
    if(atags->used + size >= atags->size)
    {
        atags->mem = realloc(atags->mem,
            atags->size + 10240);
        atags->size += 10240;
    }
    ptr = (struct tag *)((char *)atags->mem + atags->used);
    atags->used += size;
    return ptr;
}

canonical_original_code:
struct tag *genatags_add(struct genatags *atags, int size)
{
    struct tag *ptr;
    size <<= 2;
    if(atags->used + size >= atags->size)
    {
        atags->mem = realloc(atags->mem,
            atags->size + 10240);
        atags->size += 10240;
    }
    ptr = (struct tag *)((char *)atags->mem + atags->used);
    atags->used += size;
    return ptr;
}

variable_types: size int

return_type: struct tag { struct tag_header { unsigned int size; unsigned int tag; } hdr; union { struct tag_core { unsigned int flags; unsigned int pagesize; unsigned int rootdev; } core; struct tag_mem32 { unsigned int size; unsigned int start; } mem; struct tag_videotext { unsigned char x; unsigned char y; unsigned short video_page; unsigned char video_mode; unsigned char video_cols; unsigned short video_ega_bx; unsigned char video_lines; unsigned char video_isvga; unsigned short video_points; } videotext; struct tag_ramdisk { unsigned int flags; unsigned int size; unsigned int start; } ramdisk; struct tag_initrd { unsigned int start; unsigned int size; } initrd; struct tag_serialnr { unsigned int low; unsigned int high; } serialnr; struct tag_revision { unsigned int rev; } revision; struct tag_videolfb { unsigned short lfb_width; unsigned short lfb_height; unsigned short lfb_depth; unsigned short lfb_linelength; unsigned int lfb_base; unsigned int lfb_size; unsigned char red_size; unsigned char red_pos; unsigned char green_size; unsigned char green_pos; unsigned char blue_size; unsigned char blue_pos; unsigned char rsvd_size; unsigned char rsvd_pos; } videolfb; struct tag_cmdline { char cmdline[1]; } cmdline; struct tag_acorn { unsigned int memc_control_reg; unsigned int vram_pages; unsigned char sounddefault; unsigned char adfsdrives; } acorn; struct tag_omap { unsigned char data[]; } omap; struct tag_memclk { unsigned int fmemclk; } memclk; } u; } *

user_defined_types: struct genatags { void *mem; unsigned int size; unsigned int used; }

user_defined_types: struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem; struct tag_videotext videotext; struct tag_ramdisk ramdisk; struct tag_initrd initrd; struct tag_serialnr serialnr; struct tag_revision revision; struct tag_videolfb videolfb; struct tag_cmdline cmdline; struct tag_acorn acorn; struct tag_omap omap; struct tag_memclk memclk; } u; }


original_code:
int genatags_core(genatags *atags, u32 flags, u32 pagesize, u32 rootdev)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_core)) >> 2));
    ptag->hdr.tag = 0x54410001;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_core)) >> 2);
    ptag->u.core.flags = flags;
    ptag->u.core.pagesize = pagesize;
    ptag->u.core.rootdev = rootdev;
    return 0;
}

canonical_original_code:
int genatags_core(struct genatags *atags, unsigned int flags, unsigned int pagesize, unsigned int rootdev)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_core)) >> 2));
    ptag->hdr.tag = 0x54410001;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_core)) >> 2);
    ptag->u.core.flags = flags;
    ptag->u.core.pagesize = pagesize;
    ptag->u.core.rootdev = rootdev;
    return 0;
}

variable_types:
flags
unsigned int

variable_types:
pagesize
unsigned int

variable_types:
rootdev
unsigned int

user_defined_types: struct tag_header { unsigned int size; unsigned int tag; }

user_defined_types: struct tag_core { unsigned int flags; unsigned int pagesize; unsigned int rootdev; }

user_defined_types: struct tag_mem32 { unsigned int size; unsigned int start; }

user_defined_types: struct tag_videotext { unsigned char x; unsigned char y; unsigned short video_page; unsigned char video_mode; unsigned char video_cols; unsigned short video_ega_bx; unsigned char video_lines; unsigned char video_isvga; unsigned short video_points; }

user_defined_types: struct tag_ramdisk { unsigned int flags; unsigned int size; unsigned int start; }

user_defined_types: struct tag_initrd { unsigned int start; unsigned int size; }

user_defined_types: struct tag_serialnr { unsigned int low; unsigned int high; }

user_defined_types: struct tag_revision { unsigned int rev; }

user_defined_types: struct tag_videolfb { unsigned short lfb_width; unsigned short lfb_height; unsigned short lfb_depth; unsigned short lfb_linelength; unsigned int lfb_base; unsigned int lfb_size; unsigned char red_size; unsigned char red_pos; unsigned char green_size; unsigned char green_pos; unsigned char blue_size; unsigned char blue_pos; unsigned char rsvd_size; unsigned char rsvd_pos; }

user_defined_types: struct tag_acorn { unsigned int memc_control_reg; unsigned int vram_pages; unsigned char sounddefault; unsigned char adfsdrives; }

user_defined_types: struct tag_omap { unsigned char data[]; }

user_defined_types: struct tag_memclk { unsigned int fmemclk; }


original_code:
int genatags_mem(genatags *atags, u32 size, u32 start)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_mem32)) >> 2));
    ptag->hdr.tag = 0x54410002;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_mem32)) >> 2);
    ptag->u.mem.size = size;
    ptag->u.mem.start = start;
    return 0;
}

canonical_original_code:
int genatags_mem(struct genatags *atags, unsigned int size, unsigned int start)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_mem32)) >> 2));
    ptag->hdr.tag = 0x54410002;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_mem32)) >> 2);
    ptag->u.mem.size = size;
    ptag->u.mem.start = start;
    return 0;
}

variable_types:
size
unsigned int

variable_types:
start
unsigned int


decompiled_code:
__int64 __fastcall genatags_initrd(__int64 a1, int a2, int a3)
{
_DWORD *v4; // rax

v4 = (_DWORD *)genatags_add(a1, 4);
v4[1] = 1413611525;
*v4 = 4;
v4[3] = a2;
v4[2] = a3;
return 0LL;
}

original_code:
int genatags_initrd(genatags *atags, u32 size, u32 start)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_initrd)) >> 2));
    ptag->hdr.tag = 0x54420005;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_initrd)) >> 2);
    ptag->u.initrd.size = size;
    ptag->u.initrd.start = start;
    return 0;
}

canonical_original_code:
int genatags_initrd(struct genatags *atags, unsigned int size, unsigned int start)
{
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_initrd)) >> 2));
    ptag->hdr.tag = 0x54420005;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_initrd)) >> 2);
    ptag->u.initrd.size = size;
    ptag->u.initrd.start = start;
    return 0;
}


decompiled_code:
__int64 __fastcall genatags_cmdline(__int64 a1, const char *a2)
{
int v2; // ebx
__int64 v3; // rax

v2 = (strlen(a2) >> 2) + 3;
v3 = genatags_add(a1, v2);
*(_DWORD *)(v3 + 4) = 1413545993;
*(_DWORD *)v3 = v2;
strcpy((char *)(v3 + 8), a2);
return 0LL;
}

original_code:
int genatags_cmdline(genatags *atags, char *cmdline)
{
    int length = (strlen(cmdline) >> 2) + 1;
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_cmdline)) >> 2) + length);
    ptag->hdr.tag = 0x54410009;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_cmdline)) >> 2) + length;
    strcpy(ptag->u.cmdline.cmdline, cmdline);
    return 0;
}

canonical_original_code:
int genatags_cmdline(struct genatags *atags, char *cmdline)
{
    int length = (strlen(cmdline) >> 2) + 1;
    struct tag *ptag = genatags_add(atags, ((sizeof(struct tag_header) + sizeof(struct tag_cmdline)) >> 2) + length);
    ptag->hdr.tag = 0x54410009;
    ptag->hdr.size = ((sizeof(struct tag_header) + sizeof(struct tag_cmdline)) >> 2) + length;
    strcpy(ptag->u.cmdline.cmdline, cmdline);
    return 0;
}

variable_types:
cmdline
char *

variable_types: length int


decompiled_code:
__int64 __fastcall genatags_none(__int64 a1)
{
_DWORD *v1; // rax

v1 = (_DWORD *)genatags_add(a1, 2);
v1[1] = 0;
*v1 = 0;
return 0LL;
}

original_code:
int genatags_none(genatags *atags)
{
    struct tag *ptag = genatags_add(atags, sizeof(struct tag_header) >> 2);
    ptag->hdr.tag = 0x00000000;
    ptag->hdr.size = 0;
    return 0;
}

canonical_original_code:
int genatags_none(struct genatags *atags)
{
    struct tag *ptag = genatags_add(atags, sizeof(struct tag_header) >> 2);
    ptag->hdr.tag = 0x00000000;
    ptag->hdr.size = 0;
    return 0;
}


decompiled_code:
__int64 __fastcall dump_omap(const char *a1)
{
unsigned __int16 v1; // ax
const char *v2; // rbx
unsigned int v3; // er12
unsigned int v5; // ebp
unsigned __int16 v6; // ax
unsigned int i; // ebp

v1 = *((_WORD *)a1 + 1);
if ( v1 )
{
v2 = a1;
v3 = 0;
while ( 1 )
{
v5 = v1;
printf(" %04d - ", v3);
if ( !*(_WORD *)v2 )
{
printf("0000 OMAP TABLE END");
return 0LL;
}
printf("%04x:%04x ", v5, *(unsigned __int16 *)v2);
v6 = *(_WORD *)v2;
if ( *(_WORD *)v2 == 20231 )
{
printf("UART: enabled uarts (bitmask) %08x", *((unsigned int *)v2 + 1));
}
else if ( v6 > 0x4F07u )
{
switch ( v6 )
{
case 0x4F80u:
printf("BOOTREASON: %-12s", v2 + 4);
break;
case 0x4F82u:
printf("VERSION: %-12s = %-12s", v2 + 4, v2 + 16);
break;
case 0x4F0Bu:
printf("PARTITION: %-16s :", v2 + 4);
printf(" size=%08x", *((unsigned int *)v2 + 5));
printf(" offset=%08x", *((unsigned int *)v2 + 6));
printf(" mask=%08x", *((unsigned int *)v2 + 7));
break;
default:
LABEL_19:
for ( i = 0; *((unsigned __int16 *)v2 + 1) > i; printf(" %02x", (unsigned __int8)v2[i++ + 4]) )
;
break;
}
}
else
{
switch ( v6 )
{
case 0x4F05u:
printf("LCD: panel=%s controller=%s", v2 + 4, v2 + 20);
printf(" nreset_gpio=%04x", (unsigned int)*((__int16 *)v2 + 18));
printf(" data_lines=%04x", *((unsigned __int8 *)v2 + 38));
break;
case 0x4F06u:
printf("GPIO SWITCH: %-12s :", v2 + 4);
printf(" gpio=%04x", *((unsigned __int16 *)v2 + 8));
printf(" flags=%02x", v2[18] & 0xF);
printf(" type=%02x", (unsigned __int8)v2[18] >> 4);
printf(" keycode=%08x", *((_DWORD *)v2 + 5) & 0xFFFFFF);
break;
case 0x4E02u:
printf("WLAN CX3110X:");
printf(" chip_type=%02x", *((unsigned __int8 *)v2 + 4));
printf(" power_gpio=%04x", (unsigned int)*((__int16 *)v2 + 3));
printf(" irq_gpio=%04x", (unsigned int)*((__int16 *)v2 + 4));
printf(" spi_cs_gpio=%04x", (unsigned int)*((__int16 *)v2 + 5));
break;
default:
goto LABEL_19;
}
}
putchar(10);
v3 += *((unsigned __int16 *)v2 + 1) + 4;
v2 += *((unsigned __int16 *)v2 + 1) + 4;
v1 = *((_WORD *)v2 + 1);
if ( !v1 )
return 1LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned __int16 v1; // ax
const char *v2; // rbx
unsigned int v3; // er12
unsigned int v5; // ebp
unsigned __int16 v6; // ax
unsigned int i; // ebp

v1 = *((_WORD *)a1 + 1);
if ( v1 )
{
v2 = a1;
v3 = 0;
while ( 1 )
{
v5 = v1;
printf(" %04d - ", v3);
if ( !*(_WORD *)v2 )
{
printf("0000 OMAP TABLE END");
return 0LL;
}
printf("%04x:%04x ", v5, *(unsigned __int16 *)v2);
v6 = *(_WORD *)v2;
if ( *(_WORD *)v2 == 20231 )
{
printf("UART: enabled uarts (bitmask) %08x", *((unsigned int *)v2 + 1));
}
else if ( v6 > 0x4F07u )
{
switch ( v6 )
{
case 0x4F80u:
printf("BOOTREASON: %-12s", v2 + 4);
break;
case 0x4F82u:
printf("VERSION: %-12s = %-12s", v2 + 4, v2 + 16);
break;
case 0x4F0Bu:
printf("PARTITION: %-16s :", v2 + 4);
printf(" size=%08x", *((unsigned int *)v2 + 5));
printf(" offset=%08x", *((unsigned int *)v2 + 6));
printf(" mask=%08x", *((unsigned int *)v2 + 7));
break;
default:
LABEL_19:
for ( i = 0; *((unsigned __int16 *)v2 + 1) > i; printf(" %02x", (unsigned __int8)v2[i++ + 4]) )
;
break;
}
}
else
{
switch ( v6 )
{
case 0x4F05u:
printf("LCD: panel=%s controller=%s", v2 + 4, v2 + 20);
printf(" nreset_gpio=%04x", (unsigned int)*((__int16 *)v2 + 18));
printf(" data_lines=%04x", *((unsigned __int8 *)v2 + 38));
break;
case 0x4F06u:
printf("GPIO SWITCH: %-12s :", v2 + 4);
printf(" gpio=%04x", *((unsigned __int16 *)v2 + 8));
printf(" flags=%02x", v2[18] & 0xF);
printf(" type=%02x", (unsigned __int8)v2[18] >> 4);
printf(" keycode=%08x", *((_DWORD *)v2 + 5) & 0xFFFFFF);
break;
case 0x4E02u:
printf("WLAN CX3110X:");
printf(" chip_type=%02x", *((unsigned __int8 *)v2 + 4));
printf(" power_gpio=%04x", (unsigned int)*((__int16 *)v2 + 3));
printf(" irq_gpio=%04x", (unsigned int)*((__int16 *)v2 + 4));
printf(" spi_cs_gpio=%04x", (unsigned int)*((__int16 *)v2 + 5));
break;
default:
goto LABEL_19;
}
}
putchar(10);
v3 += *((unsigned __int16 *)v2 + 1) + 4;
v2 += *((unsigned __int16 *)v2 + 1) + 4;
v1 = *((_WORD *)v2 + 1);
if ( !v1 )
return 1LL;
}
}
return 1LL;
}

original_code:
int dump_omap(struct omap_tag * omap_tag)
{
    unsigned k;
    unsigned i = 0;
    while (omap_tag->hdr.size) {
        unsigned int size = omap_tag->hdr.size;
        printf("       %04d - ", i);
        if (omap_tag->hdr.tag == 0) {
            printf("0000      OMAP TABLE END");
            return 0;
        }
        else
            printf("%04x:%04x ", size, omap_tag->hdr.tag);
        switch (omap_tag->hdr.tag) {
            case 0x4f82:
                         printf("VERSION:      %-12s = %-12s", omap_tag->u.version.component, omap_tag->u.version.version);
                         break;
            case 0x4f80:
                         printf("BOOTREASON:   %-12s", omap_tag->u.boot_reason.reason_str);
                         break;
            case 0x4f0b:
                         printf("PARTITION:    %-16s :", omap_tag->u.partition.name);
                         printf(" size=%08x", omap_tag->u.partition.size);
                         printf(" offset=%08x", omap_tag->u.partition.offset);
                         printf(" mask=%08x", omap_tag->u.partition.mask_flags);
                         break;
            case 0x4f07:
                         printf("UART: enabled uarts (bitmask) %08x", omap_tag->u.uart.enabled_uarts);
                         break;
            case 0x4f06:
                         printf("GPIO SWITCH:  %-12s :", omap_tag->u.gpio_switch.name);
                         printf(" gpio=%04x", omap_tag->u.gpio_switch.gpio);
                         printf(" flags=%02x", omap_tag->u.gpio_switch.flags);
                         printf(" type=%02x", omap_tag->u.gpio_switch.type);
                         printf(" keycode=%08x", omap_tag->u.gpio_switch.key_code);
                         break;
            case 0x4f05:
                         printf("LCD:          panel=%s controller=%s", omap_tag->u.lcd.panel_name, omap_tag->u.lcd.ctrl_name);
                         printf(" nreset_gpio=%04x", omap_tag->u.lcd.nreset_gpio);
                         printf(" data_lines=%04x", omap_tag->u.lcd.data_lines);
                         break;
            case 0x4e02:
                         printf("WLAN CX3110X:");
                         printf(" chip_type=%02x", omap_tag->u.wlan_cx3110x.chip_type);
                         printf(" power_gpio=%04x", omap_tag->u.wlan_cx3110x.power_gpio);
                         printf(" irq_gpio=%04x", omap_tag->u.wlan_cx3110x.irq_gpio);
                         printf(" spi_cs_gpio=%04x", omap_tag->u.wlan_cx3110x.spi_cs_gpio);
                         break;
            case 0x4f01:
            case 0x4f03:
            case 0x4f04:
            case 0x4f08:
            case 0x4f09:
            case 0x4f0a:
            case 0x4f10:
            case 0x4f11:
            case 0x4f81:
            case 0x4e01:
            case 0x4e03:
            case 0x4e04:
            default: for (k = 0; k < omap_tag->hdr.size; k++)
                             printf(" %02x", *((unsigned char *) (&omap_tag->u) + k));
                         break;
        }
        printf("\n");
        i += omap_tag->hdr.size + sizeof(struct omap_tag_header);
        omap_tag = ((struct omap_tag *)((char *)(omap_tag) + (omap_tag)->hdr.size + sizeof(struct omap_tag_header)));
    }
    return 1;
}

canonical_original_code:
int dump_omap(struct omap_tag *omap_tag)
{
    unsigned int k;
    unsigned int i = 0;
    while (omap_tag->hdr.size) {
        unsigned int size = omap_tag->hdr.size;
        printf("       %04d - ", i);
        if (omap_tag->hdr.tag == 0) {
            printf("0000      OMAP TABLE END");
            return 0;
        }
        else
            printf("%04x:%04x ", size, omap_tag->hdr.tag);
        switch (omap_tag->hdr.tag) {
            case 0x4f82:
                         printf("VERSION:      %-12s = %-12s", omap_tag->u.version.component, omap_tag->u.version.version);
                         break;
            case 0x4f80:
                         printf("BOOTREASON:   %-12s", omap_tag->u.boot_reason.reason_str);
                         break;
            case 0x4f0b:
                         printf("PARTITION:    %-16s :", omap_tag->u.partition.name);
                         printf(" size=%08x", omap_tag->u.partition.size);
                         printf(" offset=%08x", omap_tag->u.partition.offset);
                         printf(" mask=%08x", omap_tag->u.partition.mask_flags);
                         break;
            case 0x4f07:
                         printf("UART: enabled uarts (bitmask) %08x", omap_tag->u.uart.enabled_uarts);
                         break;
            case 0x4f06:
                         printf("GPIO SWITCH:  %-12s :", omap_tag->u.gpio_switch.name);
                         printf(" gpio=%04x", omap_tag->u.gpio_switch.gpio);
                         printf(" flags=%02x", omap_tag->u.gpio_switch.flags);
                         printf(" type=%02x", omap_tag->u.gpio_switch.type);
                         printf(" keycode=%08x", omap_tag->u.gpio_switch.key_code);
                         break;
            case 0x4f05:
                         printf("LCD:          panel=%s controller=%s", omap_tag->u.lcd.panel_name, omap_tag->u.lcd.ctrl_name);
                         printf(" nreset_gpio=%04x", omap_tag->u.lcd.nreset_gpio);
                         printf(" data_lines=%04x", omap_tag->u.lcd.data_lines);
                         break;
            case 0x4e02:
                         printf("WLAN CX3110X:");
                         printf(" chip_type=%02x", omap_tag->u.wlan_cx3110x.chip_type);
                         printf(" power_gpio=%04x", omap_tag->u.wlan_cx3110x.power_gpio);
                         printf(" irq_gpio=%04x", omap_tag->u.wlan_cx3110x.irq_gpio);
                         printf(" spi_cs_gpio=%04x", omap_tag->u.wlan_cx3110x.spi_cs_gpio);
                         break;
            case 0x4f01:
            case 0x4f03:
            case 0x4f04:
            case 0x4f08:
            case 0x4f09:
            case 0x4f0a:
            case 0x4f10:
            case 0x4f11:
            case 0x4f81:
            case 0x4e01:
            case 0x4e03:
            case 0x4e04:
            default: for (k = 0; k < omap_tag->hdr.size; k++)
                             printf(" %02x", *((unsigned char *) (&omap_tag->u) + k));
                         break;
        }
        printf("\n");
        i += omap_tag->hdr.size + sizeof(struct omap_tag_header);
        omap_tag = ((struct omap_tag *)((char *)(omap_tag) + (omap_tag)->hdr.size + sizeof(struct omap_tag_header)));
    }
    return 1;
}

variable_types: struct omap_tag { struct omap_tag_header { unsigned short tag; unsigned short size; } hdr; union { struct omap_clock_config { unsigned char system_clock_type; } clock; struct omap_serial_console_config { unsigned char console_uart; unsigned int console_speed; } serial_console; struct omap_sti_console_config { unsigned int enable; unsigned char channel; } sti_console; struct omap_usb_config { unsigned int register_host; unsigned int register_dev; unsigned char otg; unsigned char hmc_mode; unsigned char rwc; unsigned char pins[3]; } usb; struct omap_lcd_config { char panel_name[16]; char ctrl_name[16]; short nreset_gpio; unsigned char data_lines; } lcd; struct omap_fbmem_config { unsigned int start; unsigned int size; } fbmem; struct omap_gpio_switch_config { char name[12]; unsigned short gpio; unsigned char flags; unsigned char type; unsigned int key_code; } gpio_switch; struct omap_uart_config { unsigned int enabled_uarts; } uart; struct omap_tea5761_config { unsigned short enable_gpio; } tea5761; struct omap_partition_config { char name[16]; unsigned int size; unsigned int offset; unsigned int mask_flags; } partition; struct omap_flash_part_str_config { char part_table[]; } flash_part_str; struct omap_boot_reason_config { char reason_str[12]; } boot_reason; struct omap_version_config { char component[12]; char version[12]; } version; struct omap_bluetooth_config { unsigned char chip_type; unsigned char bt_wakeup_gpio; unsigned char host_wakeup_gpio; unsigned char reset_gpio; unsigned char bt_uart; unsigned char bd_addr[6]; unsigned char bt_sysclk; } bluetooth; struct omap_wlan_cx3110x_config { unsigned char chip_type; unsigned char reserverd; short power_gpio; short irq_gpio; short spi_cs_gpio; } wlan_cx3110x; struct omap_cbus_config { short clk_gpio; short dat_gpio; short sel_gpio; } cbus; struct omap_em_asic_bb5_config { short retu_irq_gpio; short tahvo_irq_gpio; } em_asic_bb5; } u; } *

variable_types:
k
unsigned int

variable_types:
i
unsigned int

user_defined_types: struct omap_tag { struct omap_tag_header hdr; union { struct omap_clock_config clock; struct omap_serial_console_config serial_console; struct omap_sti_console_config sti_console; struct omap_usb_config usb; struct omap_lcd_config lcd; struct omap_fbmem_config fbmem; struct omap_gpio_switch_config gpio_switch; struct omap_uart_config uart; struct omap_tea5761_config tea5761; struct omap_partition_config partition; struct omap_flash_part_str_config flash_part_str; struct omap_boot_reason_config boot_reason; struct omap_version_config version; struct omap_bluetooth_config bluetooth; struct omap_wlan_cx3110x_config wlan_cx3110x; struct omap_cbus_config cbus; struct omap_em_asic_bb5_config em_asic_bb5; } u; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
ssize_t v5; // rax
__int64 v6; // rcx
const char *v7; // rbx
unsigned int v8; // ebp
unsigned int v9; // eax

v3 = *argv;
v4 = open(argv[1], 0, envp);
if ( v4 == -1 )
{
printf("%s binary_atag_data_file\n", v3);
exit(1);
}
v5 = read(v4, &atag_buf, 0x2710uLL);
printf("read %d bytes from %s in buffer of size 10000\n", v5, argv[1]);
v6 = (unsigned int)dword_404084;
if ( !dword_404084 )
LABEL_24:
exit(0);
v7 = (const char *)&atag_buf;
v8 = 0;
while ( 1 )
{
printf("%04d - %04d:%08x", v8, *(unsigned int *)v7, v6);
v9 = *((_DWORD *)v7 + 1);
if ( v9 > 0x54410009 )
{
if ( v9 != 1413611525 )
{
LABEL_23:
puts("unknown tag");
goto LABEL_11;
}
printf(" ATAG INITRD2");
printf(" start=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
putchar(10);
}
else
{
if ( v9 > 0x54410000 )
{
switch ( v9 )
{
case 0x54410001u:
printf(" ATAG CORE");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" pagesize=%08x", *((unsigned int *)v7 + 3));
printf(" rootdev=%08x", *((unsigned int *)v7 + 4));
putchar(10);
goto LABEL_11;
case 0x54410002u:
printf(" ATAG MEM");
printf(" size=%08x", *((unsigned int *)v7 + 2));
printf(" start=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_11;
case 0x54410003u:
printf(" ATAG VIDEOTEXT");
printf(" x=%02x", *((unsigned __int8 *)v7 + 8));
printf(" y=%02x", *((unsigned __int8 *)v7 + 9));
printf(" video_page=%04x", *((unsigned __int16 *)v7 + 5));
printf(" video_mode=%02x", *((unsigned __int8 *)v7 + 12));
printf(" video_cols=%02x", *((unsigned __int8 *)v7 + 13));
printf(" video_ega_bx=%04x", *((unsigned __int16 *)v7 + 7));
printf(" video_lines=%02x", *((unsigned __int8 *)v7 + 16));
printf(" video_isvga=%02x", *((unsigned __int8 *)v7 + 17));
printf(" video_points=%04x", *((unsigned __int16 *)v7 + 9));
putchar(10);
goto LABEL_11;
case 0x54410004u:
printf(" ATAG RAMDISK");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
printf(" start=%08x", *((unsigned int *)v7 + 4));
putchar(10);
goto LABEL_11;
case 0x54410006u:
printf(" ATAG SERIAL");
printf(" low=%08x", *((unsigned int *)v7 + 2));
printf(" high=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_11;
case 0x54410007u:
printf(" ATAG REVISION");
printf(" revision=%08x", *((unsigned int *)v7 + 2));
putchar(10);
goto LABEL_11;
case 0x54410008u:
printf(" ATAG VIDEOLFB");
printf(" lfb_width=%04x", *((unsigned __int16 *)v7 + 4));
printf(" lfb_height=%04x", *((unsigned __int16 *)v7 + 5));
printf(" lfb_depth=%04x", *((unsigned __int16 *)v7 + 6));
printf(" lfb_linelength=%04x", *((unsigned __int16 *)v7 + 7));
printf(" lfb_base=%08x", *((unsigned int *)v7 + 4));
printf(" lfb_size=%08x", *((unsigned int *)v7 + 5));
printf(" red_size=%02x", *((unsigned __int8 *)v7 + 24));
printf(" res_pos=%02x", *((unsigned __int8 *)v7 + 25));
printf(" green_size=%02x", *((unsigned __int8 *)v7 + 26));
printf(" green_pos=%02x", *((unsigned __int8 *)v7 + 27));
printf(" blue_size=%02x", *((unsigned __int8 *)v7 + 28));
printf(" blue_pos=%02x", *((unsigned __int8 *)v7 + 29));
printf(" rsvd_size=%02x", *((unsigned __int8 *)v7 + 30));
printf(" rsvd_pos=%02x", *((unsigned __int8 *)v7 + 31));
putchar(10);
goto LABEL_11;
case 0x54410009u:
printf(" ATAG CMDLINE");
printf(" %s", v7 + 8);
putchar(10);
goto LABEL_11;
default:
goto LABEL_23;
}
}
if ( v9 )
{
if ( v9 != 1095716176 )
goto LABEL_23;
printf(" OMAP table (%d bytes)\n", (unsigned int)(4 * *(_DWORD *)v7));
dump_omap(v7 + 8);
}
else
{
puts(" END ATAG");
}
}
LABEL_11:
v8 += 4 * *(_DWORD *)v7;
v7 += 4 * *(unsigned int *)v7;
v6 = *((unsigned int *)v7 + 1);
if ( !(_DWORD)v6 )
goto LABEL_24;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
ssize_t v5; // rax
__int64 v6; // rcx
const char *v7; // rbx
unsigned int v8; // ebp
unsigned int v9; // eax

v3 = *argv;
v4 = open(argv[1], 0, envp);
if ( v4 == -1 )
{
printf("%s binary_atag_data_file\n", v3);
exit(1);
}
v5 = read(v4, &atag_buf, 0x2710uLL);
printf("read %d bytes from %s in buffer of size 10000\n", v5, argv[1]);
v6 = (unsigned int)dword_404084;
if ( !dword_404084 )
LABEL_24:
exit(0);
v7 = (const char *)&atag_buf;
v8 = 0;
while ( 1 )
{
printf("%04d - %04d:%08x", v8, *(unsigned int *)v7, v6);
v9 = *((_DWORD *)v7 + 1);
if ( v9 > 0x54410009 )
{
if ( v9 != 1413611525 )
{
LABEL_23:
puts("unknown tag");
goto LABEL_11;
}
printf(" ATAG INITRD2");
printf(" start=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
putchar(10);
}
else
{
if ( v9 > 0x54410000 )
{
switch ( v9 )
{
case 0x54410001u:
printf(" ATAG CORE");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" pagesize=%08x", *((unsigned int *)v7 + 3));
printf(" rootdev=%08x", *((unsigned int *)v7 + 4));
putchar(10);
goto LABEL_11;
case 0x54410002u:
printf(" ATAG MEM");
printf(" size=%08x", *((unsigned int *)v7 + 2));
printf(" start=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_11;
case 0x54410003u:
printf(" ATAG VIDEOTEXT");
printf(" x=%02x", *((unsigned __int8 *)v7 + 8));
printf(" y=%02x", *((unsigned __int8 *)v7 + 9));
printf(" video_page=%04x", *((unsigned __int16 *)v7 + 5));
printf(" video_mode=%02x", *((unsigned __int8 *)v7 + 12));
printf(" video_cols=%02x", *((unsigned __int8 *)v7 + 13));
printf(" video_ega_bx=%04x", *((unsigned __int16 *)v7 + 7));
printf(" video_lines=%02x", *((unsigned __int8 *)v7 + 16));
printf(" video_isvga=%02x", *((unsigned __int8 *)v7 + 17));
printf(" video_points=%04x", *((unsigned __int16 *)v7 + 9));
putchar(10);
goto LABEL_11;
case 0x54410004u:
printf(" ATAG RAMDISK");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
printf(" start=%08x", *((unsigned int *)v7 + 4));
putchar(10);
goto LABEL_11;
case 0x54410006u:
printf(" ATAG SERIAL");
printf(" low=%08x", *((unsigned int *)v7 + 2));
printf(" high=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_11;
case 0x54410007u:
printf(" ATAG REVISION");
printf(" revision=%08x", *((unsigned int *)v7 + 2));
putchar(10);
goto LABEL_11;
case 0x54410008u:
printf(" ATAG VIDEOLFB");
printf(" lfb_width=%04x", *((unsigned __int16 *)v7 + 4));
printf(" lfb_height=%04x", *((unsigned __int16 *)v7 + 5));
printf(" lfb_depth=%04x", *((unsigned __int16 *)v7 + 6));
printf(" lfb_linelength=%04x", *((unsigned __int16 *)v7 + 7));
printf(" lfb_base=%08x", *((unsigned int *)v7 + 4));
printf(" lfb_size=%08x", *((unsigned int *)v7 + 5));
printf(" red_size=%02x", *((unsigned __int8 *)v7 + 24));
printf(" res_pos=%02x", *((unsigned __int8 *)v7 + 25));
printf(" green_size=%02x", *((unsigned __int8 *)v7 + 26));
printf(" green_pos=%02x", *((unsigned __int8 *)v7 + 27));
printf(" blue_size=%02x", *((unsigned __int8 *)v7 + 28));
printf(" blue_pos=%02x", *((unsigned __int8 *)v7 + 29));
printf(" rsvd_size=%02x", *((unsigned __int8 *)v7 + 30));
printf(" rsvd_pos=%02x", *((unsigned __int8 *)v7 + 31));
putchar(10);
goto LABEL_11;
case 0x54410009u:
printf(" ATAG CMDLINE");
printf(" %s", v7 + 8);
putchar(10);
goto LABEL_11;
default:
goto LABEL_23;
}
}
if ( v9 )
{
if ( v9 != 1095716176 )
goto LABEL_23;
printf(" OMAP table (%d bytes)\n", (unsigned int)(4 * *(_DWORD *)v7));
func7(v7 + 8);
}
else
{
puts(" END ATAG");
}
}
LABEL_11:
v8 += 4 * *(_DWORD *)v7;
v7 += 4 * *(unsigned int *)v7;
v6 = *((unsigned int *)v7 + 1);
if ( !(_DWORD)v6 )
goto LABEL_24;
}
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct tag { struct tag_header { unsigned int size; unsigned int tag; } hdr; union { struct tag_core { unsigned int flags; unsigned int pagesize; unsigned int rootdev; } core; struct tag_mem32 { unsigned int size; unsigned int start; } mem; struct tag_videotext { unsigned char x; unsigned char y; unsigned short video_page; unsigned char video_mode; unsigned char video_cols; unsigned short video_ega_bx; unsigned char video_lines; unsigned char video_isvga; unsigned short video_points; } videotext; struct tag_ramdisk { unsigned int flags; unsigned int size; unsigned int start; } ramdisk; struct tag_initrd { unsigned int start; unsigned int size; } initrd; struct tag_serialnr { unsigned int low; unsigned int high; } serialnr; struct tag_revision { unsigned int rev; } revision; struct tag_videolfb { unsigned short lfb_width; unsigned short lfb_height; unsigned short lfb_depth; unsigned short lfb_linelength; unsigned int lfb_base; unsigned int lfb_size; unsigned char red_size; unsigned char red_pos; unsigned char green_size; unsigned char green_pos; unsigned char blue_size; unsigned char blue_pos; unsigned char rsvd_size; unsigned char rsvd_pos; } videolfb; struct tag_cmdline { char cmdline[1]; } cmdline; struct tag_acorn { unsigned int memc_control_reg; unsigned int vram_pages; unsigned char sounddefault; unsigned char adfsdrives; } acorn; struct tag_omap { unsigned char data[]; } omap; struct tag_memclk { unsigned int fmemclk; } memclk; } u; } *

user_defined_types: struct omap_tag_header { unsigned short tag; unsigned short size; }

user_defined_types: struct omap_clock_config { unsigned char system_clock_type; }

user_defined_types: struct omap_serial_console_config { unsigned char console_uart; unsigned int console_speed; }

user_defined_types: struct omap_sti_console_config { unsigned int enable; unsigned char channel; }

user_defined_types: struct omap_usb_config { unsigned int register_host; unsigned int register_dev; unsigned char otg; unsigned char hmc_mode; unsigned char rwc; unsigned char pins[3]; }

user_defined_types: struct omap_lcd_config { char panel_name[16]; char ctrl_name[16]; short nreset_gpio; unsigned char data_lines; }

user_defined_types: struct omap_fbmem_config { unsigned int start; unsigned int size; }

user_defined_types: struct omap_gpio_switch_config { char name[12]; unsigned short gpio; unsigned char flags; unsigned char type; unsigned int key_code; }

user_defined_types: struct omap_uart_config { unsigned int enabled_uarts; }

user_defined_types: struct omap_tea5761_config { unsigned short enable_gpio; }

user_defined_types: struct omap_partition_config { char name[16]; unsigned int size; unsigned int offset; unsigned int mask_flags; }

user_defined_types: struct omap_flash_part_str_config { char part_table[]; }

user_defined_types: struct omap_boot_reason_config { char reason_str[12]; }

user_defined_types: struct omap_version_config { char component[12]; char version[12]; }

user_defined_types: struct omap_bluetooth_config { unsigned char chip_type; unsigned char bt_wakeup_gpio; unsigned char host_wakeup_gpio; unsigned char reset_gpio; unsigned char bt_uart; unsigned char bd_addr[6]; unsigned char bt_sysclk; }

user_defined_types: struct omap_wlan_cx3110x_config { unsigned char chip_type; unsigned char reserverd; short power_gpio; short irq_gpio; short spi_cs_gpio; }

user_defined_types: struct omap_cbus_config { short clk_gpio; short dat_gpio; short sel_gpio; }


dump

repo: altoor/IPoEM

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

v1 = g_node_depth();
v2 = v1 - 1;
if ( v1 != 1 )
{
do
{
putchar(32);
--v2;
}
while ( v2 );
}
puts(*a1);
return 0LL;
}

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

v1 = g_node_depth();
v2 = v1 - 1;
if ( v1 != 1 )
{
do
{
putchar(32);
--v2;
}
while ( v2 );
}
puts(*a1);
return 0LL;
}

original_code:
gboolean dump(GNode *node, gpointer data)
{
    int i = g_node_depth(node);
    while (--i) printf(" ");
    printf("%s\n", (char*) node->data);
    return((0));
}

canonical_original_code:
int dump(struct _GNode *node, void *data)
{
    int i = g_node_depth(node);
    while (--i) printf(" ");
    printf("%s\n", (char *) node->data);
    return((0));
}

variable_types: struct _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; } *

variable_types:
data
void *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
__int64 v4; // rbx
FILE *v5; // rbp
int result; // eax
__int64 v7; // [rsp+0h] [rbp-1F8h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s <file.yml>\n", *argv);
result = 1;
}
else
{
v3 = argv[1];
v4 = g_node_new();
v5 = fopen(v3, "rb");
yaml_parser_initialize();
yaml_parser_set_input_file();
process_layer((__int64)&v7, v4);
yaml_parser_delete();
fclose(v5);
puts("Results iteration:");
g_node_traverse();
g_node_destroy();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
__int64 v4; // rbx
FILE *v5; // rbp
int result; // eax
__int64 v7; // [rsp+0h] [rbp-1F8h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s <file.yml>\n", *argv);
result = 1;
}
else
{
v3 = argv[1];
v4 = g_node_new();
v5 = fopen(v3, "rb");
yaml_parser_initialize();
yaml_parser_set_input_file();
func8((__int64)&v7, v4);
yaml_parser_delete();
fclose(v5);
puts("Results iteration:");
g_node_traverse();
g_node_destroy();
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 fd_set rfds;
 int fd = tun_alloc(argv[1]);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 for (;;) {
  char buf[2048];
  int i, retval = select(fd + 1, &rfds, ((void *)0), ((void *)0), ((void *)0));
  if ((retval < 0) && ((*__errno_location ()) != 4))
   break;
  if (((((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   retval = read(0, buf, 2048);
   if (retval > 0)
    write(fd, buf, retval);
  }
  if (((((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   retval = read(fd, buf, 2048);
   if (retval < 0)
    continue;
   if (!strcmp(buf, "exit"))
    break;
   for (i=0; i<retval; ++i)
    fprintf(stdout, "%02hhx", buf[i]);
   fprintf(stdout, "\n");
  }
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct fd_set rfds;
 int fd = tun_alloc(argv[1]);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 for (;;) {
  char buf[2048];
  int i; int retval = select(fd + 1, &rfds, ((void *)0), ((void *)0), ((void *)0));
  if ((retval < 0) && ((*__errno_location ()) != 4))
   break;
  if (((((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   retval = read(0, buf, 2048);
   if (retval > 0)
    write(fd, buf, retval);
  }
  if (((((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   retval = read(fd, buf, 2048);
   if (retval < 0)
    continue;
   if (!strcmp(buf, "exit"))
    break;
   for (i=0; i<retval; ++i)
    fprintf(stdout, "%02hhx", buf[i]);
   fprintf(stdout, "\n");
  }
 }
 close(fd);
 return 0;
}

variable_types:
argv
char *[]

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

variable_types: fd int

variable_types:
buf
char [2048]

variable_types: retval int


decompiled_code:
__int64 __fastcall tun_alloc(char *src)
{
int v1; // ebx
int v2; // ebp
__int64 v4[9]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/dev/net/tun", 2);
if ( v1 >= 0 )
{
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 4098LL;
v4[3] = 0LL;
v4[4] = 0LL;
if ( src && *src )
strncpy((char *)v4, src, 0x10uLL);
v2 = ioctl(v1, 0x400454CAuLL, v4);
if ( v2 < 0 )
{
close(v1);
v1 = v2;
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
int v1; // ebx
int v2; // ebp
__int64 v4[9]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/dev/net/tun", 2);
if ( v1 >= 0 )
{
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 4098LL;
v4[3] = 0LL;
v4[4] = 0LL;
if ( src && *src )
strncpy((char *)v4, src, 0x10uLL);
v2 = ioctl(v1, 0x400454CAuLL, v4);
if ( v2 < 0 )
{
close(v1);
v1 = v2;
}
}
return (unsigned int)v1;
}

original_code:
int tun_alloc(char *dev)
{
 struct ifreq ifr;
 int fd, err;
 if ((fd = open("/dev/net/tun", 02)) < 0)
  return fd;
 memset(&ifr, 0, sizeof(ifr));
 ifr.ifr_ifru.ifru_flags = 0x0002| 0x1000;
 if (dev && *dev)
  strncpy(ifr.ifr_ifrn.ifrn_name, dev, 16);
 if ((err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0) {
  close(fd);
  return err;
 }
 return fd;
}

canonical_original_code:
int tun_alloc(char *dev)
{
 struct ifreq ifr;
 int fd; int err;
 if ((fd = open("/dev/net/tun", 02)) < 0)
  return fd;
 memset(&ifr, 0, sizeof(ifr));
 ifr.ifr_ifru.ifru_flags = 0x0002| 0x1000;
 if (dev && *dev)
  strncpy(ifr.ifr_ifrn.ifrn_name, dev, 16);
 if ((err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0) {
  close(fd);
  return err;
 }
 return fd;
}

variable_types:
dev
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types: err int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 v4; // r13
int v6; // eax
int v7; // eax
char *v8; // rbx
char *v9; // r14
char v10[2048]; // [rsp+0h] [rbp-8A8h] BYREF
fd_set readfds; // [rsp+800h] [rbp-A8h] BYREF

v3 = tun_alloc((char *)argv[1]);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
v4 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v4;
while ( select(v3 + 1, &readfds, 0LL, 0LL, 0LL) >= 0 || *__errno_location() == 4 )
{
if ( (readfds.fds_bits[0] & 1) != 0 )
{
v6 = read(0, v10, 0x800uLL);
if ( v6 > 0 )
write(v3, v10, v6);
}
if ( (readfds.fds_bits[v3 / 64] & v4) != 0 )
{
v7 = read(v3, v10, 0x800uLL);
if ( v7 >= 0 )
{
if ( !strcmp(v10, "exit") )
break;
if ( v7 > 0 )
{
v8 = v10;
v9 = &v10[v7 - 1 + 1];
do
fprintf(_bss_start, "%02hhx", (unsigned int)*v8++);
while ( v8 != v9 );
}
fputc(10, _bss_start);
}
}
}
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 v4; // r13
int v6; // eax
int v7; // eax
char *v8; // rbx
char *v9; // r14
char v10[2048]; // [rsp+0h] [rbp-8A8h] BYREF
fd_set readfds; // [rsp+800h] [rbp-A8h] BYREF

v3 = func7((char *)argv[1]);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
v4 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v4;
while ( select(v3 + 1, &readfds, 0LL, 0LL, 0LL) >= 0 || *__errno_location() == 4 )
{
if ( (readfds.fds_bits[0] & 1) != 0 )
{
v6 = read(0, v10, 0x800uLL);
if ( v6 > 0 )
write(v3, v10, v6);
}
if ( (readfds.fds_bits[v3 / 64] & v4) != 0 )
{
v7 = read(v3, v10, 0x800uLL);
if ( v7 >= 0 )
{
if ( !strcmp(v10, "exit") )
break;
if ( v7 > 0 )
{
v8 = v10;
v9 = &v10[v7 - 1 + 1];
do
fprintf(_bss_start, "%02hhx", (unsigned int)*v8++);
while ( v8 != v9 );
}
fputc(10, _bss_start);
}
}
}
close(v3);
return 0;
}


repo: altor/tamagochi

decompiled_code:
void *nourriture_make()
{
return malloc(0x208uLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x208uLL);
}

original_code:
nourriture * nourriture_make()
{
  return malloc(sizeof(struct nourriture));
}

canonical_original_code:
struct nourriture *nourriture_make()
{
  return malloc(sizeof(struct nourriture));
}

return_type: struct nourriture { char nom[512]; int nutriment; int gout; } *


decompiled_code:
void __fastcall nourriture_delete(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void nourriture_delete(nourriture * obj)
{
  free(obj);
}

canonical_original_code:
void nourriture_delete(struct nourriture *obj)
{
  free(obj);
}

variable_types: struct nourriture { char nom[512]; int nutriment; int gout; } *


decompiled_code:
char *__fastcall nourriture_init(__int64 a1, const char *a2, int a3)
{
char *result; // rax

result = strcpy((char *)a1, a2);
*(_DWORD *)(a1 + 512) = a3;
return result;
}

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

result = strcpy((char *)a1, a2);
*(_DWORD *)(a1 + 512) = a3;
return result;
}

original_code:
void nourriture_init(nourriture * obj,char * nom, int nutriment)
{
  strcpy(obj->nom, nom);
  obj->nutriment = nutriment;
}

canonical_original_code:
void nourriture_init(struct nourriture *obj, char *nom, int nutriment)
{
  strcpy(obj->nom, nom);
  obj->nutriment = nutriment;
}

variable_types:
nom
char *

variable_types: nutriment int

user_defined_types: struct nourriture { char nom[512]; int nutriment; int gout; }


decompiled_code:
void __fastcall nourriture_modifier_gout(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 516) = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 516) = a2;
}

original_code:
void nourriture_modifier_gout(nourriture * obj, int gout)
{
  obj->gout = gout;
}

canonical_original_code:
void nourriture_modifier_gout(struct nourriture *obj, int gout)
{
  obj->gout = gout;
}

variable_types: gout int


decompiled_code:
__int64 __fastcall nourriture_obtenir_gout(__int64 a1)
{
return *(unsigned int *)(a1 + 516);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 516);
}

original_code:
int nourriture_obtenir_gout(nourriture * obj)
{
  return obj->gout;
}

canonical_original_code:
int nourriture_obtenir_gout(struct nourriture *obj)
{
  return obj->gout;
}


decompiled_code:
__int64 __fastcall nourriture_obtenir_nutriment(__int64 a1)
{
return *(unsigned int *)(a1 + 512);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 512);
}

original_code:
int nourriture_obtenir_nutriment(nourriture * obj)
{
  return obj->nutriment;
}

canonical_original_code:
int nourriture_obtenir_nutriment(struct nourriture *obj)
{
  return obj->nutriment;
}


decompiled_code:
__int64 __fastcall nourriture_obtenir_nom(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return a1;
}

original_code:
char * nourriture_obtenir_nom(nourriture * obj)
{
  return obj->nom;
}

canonical_original_code:
char *nourriture_obtenir_nom(struct nourriture *obj)
{
  return obj->nom;
}

return_type: char *


decompiled_code:
void *variable_etat_make()
{
return malloc(0x10uLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x10uLL);
}

original_code:
variable_etat * variable_etat_make()
{
  return malloc(sizeof(struct variable_etat));
}

canonical_original_code:
struct variable_etat *variable_etat_make()
{
  return malloc(sizeof(struct variable_etat));
}

return_type: struct variable_etat { int valeur; long temps; } *


decompiled_code:
void __fastcall variable_etat_delete(void *a1)
{
free(a1);
}

original_code:
void variable_etat_delete(variable_etat * obj)
{
  free(obj);
}

canonical_original_code:
void variable_etat_delete(struct variable_etat *obj)
{
  free(obj);
}

variable_types: struct variable_etat { int valeur; long temps; } *


decompiled_code:
time_t __fastcall variable_etat_initialiser(__int64 a1, int a2)
{
time_t result; // rax

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

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

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

original_code:
void variable_etat_initialiser(variable_etat * obj, int valeur)
{
  obj->valeur = valeur;
  obj->temps = time(((void *)0));
}

canonical_original_code:
void variable_etat_initialiser(struct variable_etat *obj, int valeur)
{
  obj->valeur = valeur;
  obj->temps = time(((void *)0));
}

variable_types: valeur int

user_defined_types: struct variable_etat { int valeur; long temps; }


decompiled_code:
int __fastcall variable_etat_ajouter_valeur(_DWORD *a1, int a2)
{
while ( pthread_mutex_lock(&mutex_etat) )
;
*a1 += a2;
return pthread_mutex_unlock(&mutex_etat);
}

canonical_decompiled_code:
int __fastcall func3(_DWORD *a1, int a2)
{
while ( pthread_mutex_lock(&mutex_etat) )
;
*a1 += a2;
return pthread_mutex_unlock(&mutex_etat);
}

original_code:
void variable_etat_ajouter_valeur(variable_etat * obj, int valeur)
{
  while(pthread_mutex_lock(&mutex_etat));
  obj->valeur += valeur;
  pthread_mutex_unlock(&mutex_etat);
}

canonical_original_code:
void variable_etat_ajouter_valeur(struct variable_etat *obj, int valeur)
{
  while(pthread_mutex_lock(&mutex_etat));
  obj->valeur += valeur;
  pthread_mutex_unlock(&mutex_etat);
}


decompiled_code:
int __fastcall variable_etat_actualiser_temps(__int64 a1)
{
while ( pthread_mutex_lock(&mutex_etat) )
;
*(_QWORD *)(a1 + 8) = time(0LL);
return pthread_mutex_unlock(&mutex_etat);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
while ( pthread_mutex_lock(&mutex_etat) )
;
*(_QWORD *)(a1 + 8) = time(0LL);
return pthread_mutex_unlock(&mutex_etat);
}

original_code:
void variable_etat_actualiser_temps(variable_etat * obj)
{
  while(pthread_mutex_lock(&mutex_etat));
  obj->temps = time(((void *)0));
  pthread_mutex_unlock(&mutex_etat);
}

canonical_original_code:
void variable_etat_actualiser_temps(struct variable_etat *obj)
{
  while(pthread_mutex_lock(&mutex_etat));
  obj->temps = time(((void *)0));
  pthread_mutex_unlock(&mutex_etat);
}


decompiled_code:
__int64 __fastcall variable_etat_obtenir_valeur(unsigned int *a1)
{
unsigned int v1; // ebx

while ( pthread_mutex_lock(&mutex_etat) )
;
v1 = *a1;
pthread_mutex_unlock(&mutex_etat);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
unsigned int v1; // ebx

while ( pthread_mutex_lock(&mutex_etat) )
;
v1 = *a1;
pthread_mutex_unlock(&mutex_etat);
return v1;
}

original_code:
int variable_etat_obtenir_valeur(variable_etat * obj)
{
  int val;
  while(pthread_mutex_lock(&mutex_etat));
  val = obj->valeur;
  pthread_mutex_unlock(&mutex_etat);
  return val;
}

canonical_original_code:
int variable_etat_obtenir_valeur(struct variable_etat *obj)
{
  int val;
  while(pthread_mutex_lock(&mutex_etat));
  val = obj->valeur;
  pthread_mutex_unlock(&mutex_etat);
  return val;
}

variable_types: val int


decompiled_code:
__int64 __fastcall variable_etat_obtenir_temps(__int64 a1)
{
__int64 v1; // rbx

while ( pthread_mutex_lock(&mutex_etat) )
;
v1 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock(&mutex_etat);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx

while ( pthread_mutex_lock(&mutex_etat) )
;
v1 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock(&mutex_etat);
return v1;
}

original_code:
time_t variable_etat_obtenir_temps(variable_etat * obj)
{
  time_t temps;
  while(pthread_mutex_lock(&mutex_etat));
  temps = obj->temps;
  pthread_mutex_unlock(&mutex_etat);
  return temps;
}

canonical_original_code:
long variable_etat_obtenir_temps(struct variable_etat *obj)
{
  long temps;
  while(pthread_mutex_lock(&mutex_etat));
  temps = obj->temps;
  pthread_mutex_unlock(&mutex_etat);
  return temps;
}

variable_types: temps long

return_type: long


decompiled_code:
int compteur_cycle()
{
return printf("%d\n", (unsigned int)++cycle_5);
}

canonical_decompiled_code:
int func0()
{
return printf("%d\n", (unsigned int)++cycle_5);
}

original_code:
void compteur_cycle(void)
{
  static int cycle = 0;
  cycle++;
  printf("%d\n",cycle);
}

canonical_original_code:
void compteur_cycle()
{
  static int cycle = 0;
  cycle++;
  printf("%d\n",cycle);
}

variable_types: cycle int


decompiled_code:
void gestion_prod()
{
time_t v0; // rbx
int v1; // edx

if ( !ancien_4 )
{
if ( !verrou_ingurgitation )
goto LABEL_3;
ancien_4 = 1;
t1_3 = variable_etat_obtenir_temps(nourriture_ingurgite);
}
if ( !verrou_ingurgitation )
{
LABEL_3:
if ( cycle_1 > 0 )
{
cycle_1 = 0;
goto LABEL_5;
}
LABEL_12:
if ( verrou_digestion != 1 )
goto LABEL_14;
goto LABEL_13;
}
v0 = variable_etat_obtenir_temps(nourriture_ingurgite);
if ( difftime(t1_3, v0) == 0.0 )
{
++cycle_1;
goto LABEL_12;
}
cycle_1 = 1;
t1_3 = v0;
LABEL_5:
if ( verrou_digestion != 1 )
goto LABEL_6;
LABEL_13:
++cycle_digestion_0;
LABEL_14:
if ( cycle_1 > 1 )
{
puts("DIGESTION");
v1 = variable_etat_obtenir_valeur(nourriture_ingurgite);
verrou_ingurgitation = 0;
ancien_4 = 0;
poid += v1 / 4;
poid_dejection += v1 / 4;
variable_etat_initialiser(nourriture_ingurgite, 0LL);
verrou_digestion = 1;
cycle_digestion_0 = 0;
return;
}
LABEL_6:
if ( cycle_digestion_0 > 3 )
{
puts("EVACUATION");
verrou_digestion = 0;
poid_dejection = 0;
--proprete;
cycle_digestion_0 = 0;
}
}

canonical_decompiled_code:
void func1()
{
time_t v0; // rbx
int v1; // edx

if ( !ancien_4 )
{
if ( !verrou_ingurgitation )
goto LABEL_3;
ancien_4 = 1;
t1_3 = variable_etat_obtenir_temps(nourriture_ingurgite);
}
if ( !verrou_ingurgitation )
{
LABEL_3:
if ( cycle_1 > 0 )
{
cycle_1 = 0;
goto LABEL_5;
}
LABEL_12:
if ( verrou_digestion != 1 )
goto LABEL_14;
goto LABEL_13;
}
v0 = variable_etat_obtenir_temps(nourriture_ingurgite);
if ( difftime(t1_3, v0) == 0.0 )
{
++cycle_1;
goto LABEL_12;
}
cycle_1 = 1;
t1_3 = v0;
LABEL_5:
if ( verrou_digestion != 1 )
goto LABEL_6;
LABEL_13:
++cycle_digestion_0;
LABEL_14:
if ( cycle_1 > 1 )
{
puts("DIGESTION");
v1 = variable_etat_obtenir_valeur(nourriture_ingurgite);
verrou_ingurgitation = 0;
ancien_4 = 0;
poid += v1 / 4;
poid_dejection += v1 / 4;
variable_etat_initialiser(nourriture_ingurgite, 0LL);
verrou_digestion = 1;
cycle_digestion_0 = 0;
return;
}
LABEL_6:
if ( cycle_digestion_0 > 3 )
{
puts("EVACUATION");
verrou_digestion = 0;
poid_dejection = 0;
--proprete;
cycle_digestion_0 = 0;
}
}

original_code:
void gestion_prod(void)
{
  static int cycle = 0,
    ancien = 0,
    cycle_digestion = 0;
  static time_t t1, t2;
  int restes;
  if(!ancien && verrou_ingurgitation){
    ancien = 1;
    t1 = variable_etat_obtenir_temps(nourriture_ingurgite);
  }
  if(verrou_ingurgitation){
    t2 = variable_etat_obtenir_temps(nourriture_ingurgite);
    if(difftime(t1, t2) != 0){
 cycle = 1;
 t1 = t2;
      }
    else
      cycle ++;
  }
  else if(cycle > 0)
    cycle = 0;
  if(verrou_digestion == 1)
    cycle_digestion ++;
  if(cycle >= (((24 / 4) /3)) )
      {
  printf("DIGESTION\n");
 restes = variable_etat_obtenir_valeur(nourriture_ingurgite);
 verrou_ingurgitation = 0;
 ancien = 0;
 poid += (restes / 4);
 poid_dejection += (restes / 4);
 variable_etat_initialiser(nourriture_ingurgite, 0);
 verrou_digestion = 1;
 cycle_digestion = 0;
      }
  if(cycle_digestion >= ((24 / 4) - ((24 / 4) /3))){
    printf("EVACUATION\n");
    verrou_digestion = 0;
    poid_dejection = 0;
    proprete --;
    cycle_digestion = 0;
  }
}

canonical_original_code:
void gestion_prod()
{
  static int cycle = 0; static int ancien = 0; static int cycle_digestion = 0;
  static long t1; static long t2;
  int restes;
  if(!ancien && verrou_ingurgitation){
    ancien = 1;
    t1 = variable_etat_obtenir_temps(nourriture_ingurgite);
  }
  if(verrou_ingurgitation){
    t2 = variable_etat_obtenir_temps(nourriture_ingurgite);
    if(difftime(t1, t2) != 0){
 cycle = 1;
 t1 = t2;
      }
    else
      cycle ++;
  }
  else if(cycle > 0)
    cycle = 0;
  if(verrou_digestion == 1)
    cycle_digestion ++;
  if(cycle >= (((24 / 4) /3)) )
      {
  printf("DIGESTION\n");
 restes = variable_etat_obtenir_valeur(nourriture_ingurgite);
 verrou_ingurgitation = 0;
 ancien = 0;
 poid += (restes / 4);
 poid_dejection += (restes / 4);
 variable_etat_initialiser(nourriture_ingurgite, 0);
 verrou_digestion = 1;
 cycle_digestion = 0;
      }
  if(cycle_digestion >= ((24 / 4) - ((24 / 4) /3))){
    printf("EVACUATION\n");
    verrou_digestion = 0;
    poid_dejection = 0;
    proprete --;
    cycle_digestion = 0;
  }
}

variable_types: ancien int

variable_types: restes int


decompiled_code:
__int64 gestion_poid()
{
__int64 result; // rax
double v1; // xmm0_8

result = (unsigned int)poid;
if ( poid > 1 )
{
v1 = (double)poid - 2.5;
result = (unsigned int)(int)v1;
poid = (int)v1;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
double v1; // xmm0_8

result = (unsigned int)poid;
if ( poid > 1 )
{
v1 = (double)poid - 2.5;
result = (unsigned int)(int)v1;
poid = (int)v1;
}
return result;
}

original_code:
void gestion_poid(void)
{
  if(poid > (5 / 4))
    poid -= 2.5;
}

canonical_original_code:
void gestion_poid()
{
  if(poid > (5 / 4))
    poid -= 2.5;
}


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

result = variable_etat_obtenir_valeur(niv_faim);
if ( (int)result <= 0 || (result = variable_etat_obtenir_valeur(humeur), (int)result <= 0) )
alive = 0;
return result;
}

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

result = variable_etat_obtenir_valeur(niv_faim);
if ( (int)result <= 0 || (result = variable_etat_obtenir_valeur(humeur), (int)result <= 0) )
alive = 0;
return result;
}

original_code:
void gestion_etat(void)
{
  if(variable_etat_obtenir_valeur(niv_faim) <= 0 || variable_etat_obtenir_valeur(humeur) <= 0)
    alive = 0;
}

canonical_original_code:
void gestion_etat()
{
  if(variable_etat_obtenir_valeur(niv_faim) <= 0 || variable_etat_obtenir_valeur(humeur) <= 0)
    alive = 0;
}


decompiled_code:
void gestion_faim()
{
time_t v0; // rbx
time_t v1; // rax

v0 = variable_etat_obtenir_temps(niv_faim);
v1 = time(0LL);
if ( difftime(v1, v0) >= 6.0 )
{
variable_etat_ajouter_valeur(niv_faim, 0xFFFFFFFFLL);
variable_etat_actualiser_temps(niv_faim);
}
}

canonical_decompiled_code:
void func4()
{
time_t v0; // rbx
time_t v1; // rax

v0 = variable_etat_obtenir_temps(niv_faim);
v1 = time(0LL);
if ( difftime(v1, v0) >= 6.0 )
{
variable_etat_ajouter_valeur(niv_faim, 0xFFFFFFFFLL);
variable_etat_actualiser_temps(niv_faim);
}
}

original_code:
void gestion_faim(void)
{
  if((difftime(time(((void *)0)), variable_etat_obtenir_temps(niv_faim))/1) >= (24 / 4)){
    variable_etat_ajouter_valeur(niv_faim, -1);
    variable_etat_actualiser_temps(niv_faim);
    }
}

canonical_original_code:
void gestion_faim()
{
  if((difftime(time(((void *)0)), variable_etat_obtenir_temps(niv_faim))/1) >= (24 / 4)){
    variable_etat_ajouter_valeur(niv_faim, -1);
    variable_etat_actualiser_temps(niv_faim);
    }
}


decompiled_code:
void *fonctionnalite_make()
{
return malloc(0x10uLL);
}

original_code:
fonctionnalite * fonctionnalite_make()
{
  return malloc(sizeof(fonctionnalite));
}

canonical_original_code:
struct fonctionnalite *fonctionnalite_make()
{
  return malloc(sizeof(fonctionnalite));
}

return_type: struct fonctionnalite { int cycle; void (*PF)(); } *


decompiled_code:
void __fastcall fonctionnalite_delete(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void fonctionnalite_delete(fonctionnalite * obj)
{
  free(obj);
}

canonical_original_code:
void fonctionnalite_delete(struct fonctionnalite *obj)
{
  free(obj);
}

variable_types: struct fonctionnalite { int cycle; void (*PF)(); } *


decompiled_code:
void __fastcall fonctionnalite_init(__int64 a1, int a2, __int64 a3)
{
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2, __int64 a3)
{
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
}

original_code:
void fonctionnalite_init(fonctionnalite * obj, int cycle, PFfonctionnalite PF)
{
  obj->cycle = cycle;
  obj->PF = PF;
}

canonical_original_code:
void fonctionnalite_init(struct fonctionnalite *obj, int cycle, void (*PF)())
{
  obj->cycle = cycle;
  obj->PF = PF;
}

variable_types:
PF
void (*)()

user_defined_types: struct fonctionnalite { int cycle; void (*PF)(); }


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

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

original_code:
int fonctionnalite_obtenir_cycle(fonctionnalite * obj)
{
  return obj->cycle;
}

canonical_original_code:
int fonctionnalite_obtenir_cycle(struct fonctionnalite *obj)
{
  return obj->cycle;
}


decompiled_code:
__int64 __fastcall fonctionnalite_obtenir_PF(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
PFfonctionnalite fonctionnalite_obtenir_PF(fonctionnalite * obj)
{
  return obj->PF;
}

canonical_original_code:
void (*fonctionnalite_obtenir_PF(struct fonctionnalite *obj))()
{
  return obj->PF;
}


decompiled_code:
void *liste_make()
{
return malloc(0x10uLL);
}

original_code:
liste * liste_make()
{
  return malloc(sizeof(liste));
}

canonical_original_code:
struct liste *liste_make()
{
  return malloc(sizeof(liste));
}

return_type: struct liste { struct liste *suivant; void *valeur; } *


decompiled_code:
void __fastcall liste_delete(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
void liste_delete(liste * obj)
{
  free(obj);
}

canonical_original_code:
void liste_delete(struct liste *obj)
{
  free(obj);
}

variable_types: struct liste { struct liste *suivant; void *valeur; } *