main

repo: allwinner-dev-team/atag-tools

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
unsigned int v4; // er14
unsigned int v5; // er13
unsigned int v6; // er12
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
int result; // eax
unsigned int v11; // [rsp+0h] [rbp-854h]
unsigned int v12; // [rsp+4h] [rbp-850h]
unsigned int v13; // [rsp+8h] [rbp-84Ch]
int longind; // [rsp+10h] [rbp-844h] BYREF
char *endptr; // [rsp+14h] [rbp-840h] BYREF
char v16[16]; // [rsp+1Ch] [rbp-838h] BYREF
char v17[1008]; // [rsp+2Ch] [rbp-828h] BYREF
char dest[16]; // [rsp+41Ch] [rbp-438h] BYREF
char v19[1008]; // [rsp+42Ch] [rbp-428h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
longind = 0;
memset(v17, 0, sizeof(v17));
v13 = 0;
memset(v19, 0, sizeof(v19));
v11 = 0;
v12 = 0;
*(_OWORD *)v16 = 0LL;
*(_OWORD *)dest = 0LL;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, &shortopts, &long_options_0, &longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v13 = strtol(_bss_start, &endptr, 0);
break;
case 'c':
strcpy(v16, _bss_start);
break;
case 'f':
v5 = strtol(_bss_start, &endptr, 0);
break;
case 'i':
v11 = strtol(_bss_start, &endptr, 0);
break;
case 'o':
strcpy(dest, _bss_start);
break;
case 'p':
v4 = strtol(_bss_start, &endptr, 0);
break;
case 'r':
v3 = strtol(_bss_start, &endptr, 0);
break;
case 's':
v6 = strtol(_bss_start, &endptr, 0);
break;
case 't':
v12 = strtol(_bss_start, &endptr, 0);
break;
default:
continue;
}
}
if ( dest[0] )
{
v8 = fopen(dest, "w");
if ( v8 )
{
v9 = genatags_initialize(0.0);
genatags_core(v9, v5, v4, v3);
if ( v6 && v12 )
genatags_mem(v9, v6, v12);
if ( v11 && v13 )
genatags_initrd(v9, v11, v13);
if ( v16[0] )
genatags_cmdline(v9, v16);
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; // er15
unsigned int v4; // er14
unsigned int v5; // er13
unsigned int v6; // er12
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
int result; // eax
unsigned int v11; // [rsp+0h] [rbp-854h]
unsigned int v12; // [rsp+4h] [rbp-850h]
unsigned int v13; // [rsp+8h] [rbp-84Ch]
int longind; // [rsp+10h] [rbp-844h] BYREF
char *endptr; // [rsp+14h] [rbp-840h] BYREF
char v16[16]; // [rsp+1Ch] [rbp-838h] BYREF
char v17[1008]; // [rsp+2Ch] [rbp-828h] BYREF
char dest[16]; // [rsp+41Ch] [rbp-438h] BYREF
char v19[1008]; // [rsp+42Ch] [rbp-428h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
longind = 0;
memset(v17, 0, sizeof(v17));
v13 = 0;
memset(v19, 0, sizeof(v19));
v11 = 0;
v12 = 0;
*(_OWORD *)v16 = 0LL;
*(_OWORD *)dest = 0LL;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, &shortopts, &long_options_0, &longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v13 = strtol(_bss_start, &endptr, 0);
break;
case 'c':
strcpy(v16, _bss_start);
break;
case 'f':
v5 = strtol(_bss_start, &endptr, 0);
break;
case 'i':
v11 = strtol(_bss_start, &endptr, 0);
break;
case 'o':
strcpy(dest, _bss_start);
break;
case 'p':
v4 = strtol(_bss_start, &endptr, 0);
break;
case 'r':
v3 = strtol(_bss_start, &endptr, 0);
break;
case 's':
v6 = strtol(_bss_start, &endptr, 0);
break;
case 't':
v12 = strtol(_bss_start, &endptr, 0);
break;
default:
continue;
}
}
if ( dest[0] )
{
v8 = fopen(dest, "w");
if ( v8 )
{
v9 = func7(0.0);
func10(v9, v5, v4, v3);
if ( v6 && v12 )
func11(v9, v6, v12);
if ( v11 && v13 )
func12(v9, v11, v13);
if ( v16[0] )
func13(v9, v16);
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: 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; } *

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:
_QWORD *genatags_initialize()
{
void *v0; // rbx
_QWORD *result; // rax

v0 = malloc(0x2800uLL);
result = malloc(0x10uLL);
*result = v0;
result[1] = 10240LL;
return result;
}

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

v0 = malloc(0x2800uLL);
result = malloc(0x10uLL);
*result = v0;
result[1] = 10240LL;
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; } *


decompiled_code:
char *__fastcall genatags_add(char **a1, int a2)
{
__int64 v3; // rax
unsigned int v4; // ecx
char *v5; // rdi
unsigned int v6; // edx
char *result; // rax
char *v8; // rax
char *v9; // rdi
__int64 v10; // rax
int v11; // edx

v3 = *((unsigned int *)a1 + 3);
v4 = *((_DWORD *)a1 + 2);
v5 = *a1;
v6 = v3 + 4 * a2;
if ( v6 >= v4 )
{
v8 = (char *)realloc(v5, v4 + 10240);
*((_DWORD *)a1 + 2) += 10240;
*a1 = v8;
v9 = v8;
v10 = *((unsigned int *)a1 + 3);
v11 = 4 * a2 + v10;
result = &v9[v10];
*((_DWORD *)a1 + 3) = v11;
}
else
{
*((_DWORD *)a1 + 3) = v6;
result = &v5[v3];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char **a1, int a2)
{
__int64 v3; // rax
unsigned int v4; // ecx
char *v5; // rdi
unsigned int v6; // edx
char *result; // rax
char *v8; // rax
char *v9; // rdi
__int64 v10; // rax
int v11; // edx

v3 = *((unsigned int *)a1 + 3);
v4 = *((_DWORD *)a1 + 2);
v5 = *a1;
v6 = v3 + 4 * a2;
if ( v6 >= v4 )
{
v8 = (char *)realloc(v5, v4 + 10240);
*((_DWORD *)a1 + 2) += 10240;
*a1 = v8;
v9 = v8;
v10 = *((unsigned int *)a1 + 3);
v11 = 4 * a2 + v10;
result = &v9[v10];
*((_DWORD *)a1 + 3) = v11;
}
else
{
*((_DWORD *)a1 + 3) = v6;
result = &v5[v3];
}
return result;
}

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

return_type: 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; }


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

v4 = genatags_add(a1, 4);
*(_QWORD *)v4 = 0x5441000200000004LL;
*((_DWORD *)v4 + 2) = a2;
*((_DWORD *)v4 + 3) = a3;
return 0LL;
}

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(char **a1, int a2, int a3)
{
char *v4; // rax

v4 = genatags_add(a1, 4);
*(_QWORD *)v4 = 0x5442000500000004LL;
*((_DWORD *)v4 + 3) = a2;
*((_DWORD *)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(char **a1, const char *a2)
{
int v2; // ebx
char *v3; // rax

v2 = (strlen(a2) >> 2) + 3;
v3 = genatags_add(a1, v2);
*(_DWORD *)v3 = v2;
*((_DWORD *)v3 + 1) = 1413545993;
strcpy(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(char **a1)
{
*(_QWORD *)genatags_add(a1, 2) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(char **a1)
{
*(_QWORD *)func8(a1, 2) = 0LL;
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;
}


canonical_name: main

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
__int64 v10; // rax
__int64 v11; // rsi

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_10:
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 )
goto LABEL_23;
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_9;
case 0x54410002u:
printf(" ATAG MEM");
printf(" size=%08x", *((unsigned int *)v7 + 2));
v11 = *((unsigned int *)v7 + 3);
goto LABEL_19;
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_9;
case 0x54410004u:
printf(" ATAG RAMDISK");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
v11 = *((unsigned int *)v7 + 4);
LABEL_19:
printf(" start=%08x", v11);
putchar(10);
goto LABEL_9;
case 0x54410006u:
printf(" ATAG SERIAL");
printf(" low=%08x", *((unsigned int *)v7 + 2));
printf(" high=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_9;
case 0x54410007u:
printf(" ATAG REVISION");
printf(" revision=%08x", *((unsigned int *)v7 + 2));
putchar(10);
goto LABEL_9;
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_9;
case 0x54410009u:
printf(" ATAG CMDLINE");
printf(" %s", v7 + 8);
putchar(10);
goto LABEL_9;
default:
goto LABEL_23;
}
}
if ( !v9 )
{
puts(" END ATAG");
goto LABEL_9;
}
if ( v9 != 1095716176 )
{
LABEL_23:
puts("unknown tag");
goto LABEL_9;
}
printf(" OMAP table (%d bytes)\n", (unsigned int)(4 * *(_DWORD *)v7));
dump_omap(v7 + 8);
}
LABEL_9:
v10 = *(unsigned int *)v7;
v7 += 4 * v10;
v8 += 4 * v10;
v6 = *((unsigned int *)v7 + 1);
if ( !(_DWORD)v6 )
goto LABEL_10;
}
}

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
__int64 v10; // rax
__int64 v11; // rsi

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_10:
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 )
goto LABEL_23;
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_9;
case 0x54410002u:
printf(" ATAG MEM");
printf(" size=%08x", *((unsigned int *)v7 + 2));
v11 = *((unsigned int *)v7 + 3);
goto LABEL_19;
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_9;
case 0x54410004u:
printf(" ATAG RAMDISK");
printf(" flags=%08x", *((unsigned int *)v7 + 2));
printf(" size=%08x", *((unsigned int *)v7 + 3));
v11 = *((unsigned int *)v7 + 4);
LABEL_19:
printf(" start=%08x", v11);
putchar(10);
goto LABEL_9;
case 0x54410006u:
printf(" ATAG SERIAL");
printf(" low=%08x", *((unsigned int *)v7 + 2));
printf(" high=%08x", *((unsigned int *)v7 + 3));
putchar(10);
goto LABEL_9;
case 0x54410007u:
printf(" ATAG REVISION");
printf(" revision=%08x", *((unsigned int *)v7 + 2));
putchar(10);
goto LABEL_9;
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_9;
case 0x54410009u:
printf(" ATAG CMDLINE");
printf(" %s", v7 + 8);
putchar(10);
goto LABEL_9;
default:
goto LABEL_23;
}
}
if ( !v9 )
{
puts(" END ATAG");
goto LABEL_9;
}
if ( v9 != 1095716176 )
{
LABEL_23:
puts("unknown tag");
goto LABEL_9;
}
printf(" OMAP table (%d bytes)\n", (unsigned int)(4 * *(_DWORD *)v7));
func7(v7 + 8);
}
LABEL_9:
v10 = *(unsigned int *)v7;
v7 += 4 * v10;
v8 += 4 * v10;
v6 = *((unsigned int *)v7 + 1);
if ( !(_DWORD)v6 )
goto LABEL_10;
}
}

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


decompiled_code:
__int64 __fastcall dump_omap(const char *a1)
{
unsigned __int16 v1; // ax
unsigned int v2; // er12
const char *v3; // rbx
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // rdx
unsigned __int16 v7; // ax
__int64 v8; // rbp
__int64 v9; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned __int16 v1; // ax
unsigned int v2; // er12
const char *v3; // rbx
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // rdx
unsigned __int16 v7; // ax
__int64 v8; // rbp
__int64 v9; // rsi

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


repo: altoor/IPoEM

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rbp
FILE *v5; // r12
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(&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; // r12
__int64 v4; // rbp
FILE *v5; // r12
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(&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: argc int

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: i int

variable_types: retval int


dump

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

v1 = g_node_depth() - 1;
if ( v1 )
{
v2 = v1;
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() - 1;
if ( v1 )
{
v2 = v1;
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 *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
__int64 v4; // rbp
int v5; // eax
int *v6; // r12
int *v7; // rbx
__int64 v8; // rdx
int v10; // eax
fd_set readfds; // [rsp+10h] [rbp-8B8h] BYREF
int buf; // [rsp+90h] [rbp-838h] BYREF
char v13; // [rsp+94h] [rbp-834h]

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
__int64 v4; // rbp
int v5; // eax
int *v6; // r12
int *v7; // rbx
__int64 v8; // rdx
int v10; // eax
fd_set readfds; // [rsp+10h] [rbp-8B8h] BYREF
int buf; // [rsp+90h] [rbp-838h] BYREF
char v13; // [rsp+94h] [rbp-834h]

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


decompiled_code:
__int64 __fastcall tun_alloc(char *src)
{
int v1; // er12
int v2; // eax
int v4; // edi
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 >= 0 )
{
v7 = 0LL;
v6 = 0LL;
v5 = 0LL;
LOWORD(v6) = 4098;
if ( src && *src )
strncpy((char *)&v5, src, 0x10uLL);
v2 = ioctl(v1, 0x400454CAuLL, &v5);
if ( v2 < 0 )
{
v4 = v1;
v1 = v2;
close(v4);
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
int v1; // er12
int v2; // eax
int v4; // edi
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 >= 0 )
{
v7 = 0LL;
v6 = 0LL;
v5 = 0LL;
LOWORD(v6) = 4098;
if ( src && *src )
strncpy((char *)&v5, src, 0x10uLL);
v2 = ioctl(v1, 0x400454CAuLL, &v5);
if ( v2 < 0 )
{
v4 = v1;
v1 = v2;
close(v4);
}
}
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; }


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:
// attributes: thunk
void nourriture_delete(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

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

return_type: void


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

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

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

result = strcpy(a1, a2);
*((_DWORD *)result + 128) = 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:
// attributes: thunk
void variable_etat_delete(void *ptr)
{
free(ptr);
}

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; // er12

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; // er12

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; // r12

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; // r12

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:
int gestion_prod()
{
int result; // eax
time_t v1; // rbx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // eax

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:
result = cycle_1;
if ( cycle_1 > 0 )
{
cycle_1 = 0;
goto LABEL_5;
}
LABEL_13:
if ( verrou_digestion != 1 )
goto LABEL_14;
goto LABEL_18;
}
v1 = variable_etat_obtenir_temps(nourriture_ingurgite);
if ( difftime(t1_3, v1) == 0.0 )
{
result = ++cycle_1;
goto LABEL_13;
}
cycle_1 = 1;
t1_3 = v1;
LABEL_5:
result = cycle_1;
if ( verrou_digestion != 1 )
goto LABEL_6;
LABEL_18:
++cycle_digestion_0;
LABEL_14:
if ( result <= 1 )
{
LABEL_6:
if ( cycle_digestion_0 > 3 )
{
result = puts("EVACUATION");
--proprete;
verrou_digestion = 0;
poid_dejection = 0;
cycle_digestion_0 = 0;
}
return result;
}
puts("DIGESTION");
v2 = variable_etat_obtenir_valeur(nourriture_ingurgite);
verrou_ingurgitation = 0;
ancien_4 = 0;
v3 = v2;
v4 = v2 + 3;
if ( v3 >= 0 )
v4 = v3;
v5 = v4 >> 2;
poid += v5;
poid_dejection += v5;
result = variable_etat_initialiser(nourriture_ingurgite, 0LL);
verrou_digestion = 1;
cycle_digestion_0 = 0;
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
time_t v1; // rbx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // eax

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:
result = cycle_1;
if ( cycle_1 > 0 )
{
cycle_1 = 0;
goto LABEL_5;
}
LABEL_13:
if ( verrou_digestion != 1 )
goto LABEL_14;
goto LABEL_18;
}
v1 = variable_etat_obtenir_temps(nourriture_ingurgite);
if ( difftime(t1_3, v1) == 0.0 )
{
result = ++cycle_1;
goto LABEL_13;
}
cycle_1 = 1;
t1_3 = v1;
LABEL_5:
result = cycle_1;
if ( verrou_digestion != 1 )
goto LABEL_6;
LABEL_18:
++cycle_digestion_0;
LABEL_14:
if ( result <= 1 )
{
LABEL_6:
if ( cycle_digestion_0 > 3 )
{
result = puts("EVACUATION");
--proprete;
verrou_digestion = 0;
poid_dejection = 0;
cycle_digestion_0 = 0;
}
return result;
}
puts("DIGESTION");
v2 = variable_etat_obtenir_valeur(nourriture_ingurgite);
verrou_ingurgitation = 0;
ancien_4 = 0;
v3 = v2;
v4 = v2 + 3;
if ( v3 >= 0 )
v4 = v3;
v5 = v4 >> 2;
poid += v5;
poid_dejection += v5;
result = variable_etat_initialiser(nourriture_ingurgite, 0LL);
verrou_digestion = 1;
cycle_digestion_0 = 0;
return result;
}

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; // rbp
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; // rbp
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:
// attributes: thunk
void fonctionnalite_delete(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

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:
// attributes: thunk
void liste_delete(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func2(void *ptr)
{
free(ptr);
}

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


decompiled_code:
void __fastcall liste_modifier_valeur(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void liste_modifier_valeur(liste * obj, void * valeur)
{
  obj->valeur = valeur;
}

canonical_original_code:
void liste_modifier_valeur(struct liste *obj, void *valeur)
{
  obj->valeur = valeur;
}

variable_types:
valeur
void *

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


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

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

original_code:
void * liste_obtenir_valeur(liste * obj)
{
  return obj->valeur;
}

canonical_original_code:
void *liste_obtenir_valeur(struct liste *obj)
{
  return obj->valeur;
}

return_type: void *


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

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

original_code:
liste * liste_obtenir_suivant(liste * obj)
{
  return obj->suivant;
}

canonical_original_code:
struct liste *liste_obtenir_suivant(struct liste *obj)
{
  return obj->suivant;
}

variable_types:
obj
struct liste *


original_code:
void manger_gout(char * chaine, int gout)
{
  if(gout > 8)
    strcpy(chaine, ">8");
  else if(gout > 6)
    strcpy(chaine, ">6");
  else if(gout > 4)
    strcpy(chaine, ">4");
  else if(gout > 2)
    strcpy(chaine, ">2");
  else if(gout > 0)
    strcpy(chaine, ">0");
  else if(gout > -2)
    strcpy(chaine, ">-2");
  else if(gout > -4)
    strcpy(chaine, ">-4");
  else if(gout > -6)
    strcpy(chaine, ">-6");
  else if(gout > -8)
    strcpy(chaine, ">-8");
  else if(gout > -10)
    strcpy(chaine, ">-10");
}

canonical_original_code:
void manger_gout(char *chaine, int gout)
{
  if(gout > 8)
    strcpy(chaine, ">8");
  else if(gout > 6)
    strcpy(chaine, ">6");
  else if(gout > 4)
    strcpy(chaine, ">4");
  else if(gout > 2)
    strcpy(chaine, ">2");
  else if(gout > 0)
    strcpy(chaine, ">0");
  else if(gout > -2)
    strcpy(chaine, ">-2");
  else if(gout > -4)
    strcpy(chaine, ">-4");
  else if(gout > -6)
    strcpy(chaine, ">-6");
  else if(gout > -8)
    strcpy(chaine, ">-8");
  else if(gout > -10)
    strcpy(chaine, ">-10");
}

variable_types:
chaine
char *


decompiled_code:
__int64 __fastcall serv_chaine(__int64 a1, __int64 a2, int a3)
{
_BYTE *v3; // rbp

v3 = (_BYTE *)(a2 + a3);
*v3 = 10;
v3[1] = 0;
if ( a3 + 1 != (unsigned int)writen(a1, a2, (unsigned int)(a3 + 1)) )
err_dump("serveur_chaine : erreur lors de l'appel de writen");
*v3 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
_BYTE *v3; // rbp

v3 = (_BYTE *)(a2 + a3);
*v3 = 10;
v3[1] = 0;
if ( a3 + 1 != (unsigned int)writen(a1, a2, (unsigned int)(a3 + 1)) )
err_dump("serveur_chaine : erreur lors de l'appel de writen");
*v3 = 0;
return 0LL;
}

original_code:
int serv_chaine(int sockfd, char * chaine,int taille)
{
  chaine[taille] = '\n';
  chaine[taille + 1] = 0;
  if(writen(sockfd, chaine, (taille + 1)) != (taille + 1))
    err_dump("serveur_chaine : erreur lors de l'appel de writen");
  chaine[taille] = 0;
  return 0;
}

canonical_original_code:
int serv_chaine(int sockfd, char *chaine, int taille)
{
  chaine[taille] = '\n';
  chaine[taille + 1] = 0;
  if(writen(sockfd, chaine, (taille + 1)) != (taille + 1))
    err_dump("serveur_chaine : erreur lors de l'appel de writen");
  chaine[taille] = 0;
  return 0;
}

variable_types: sockfd int

variable_types: taille int


original_code:
int recup_arguments(char arguments[12][512], char * chaine_env, int longueur)
{
  int i;
  int nb_arguments = 0;
  int j = 0;
  for(i = 0; i < longueur; i++){
    if(chaine_env[i] == 32){
      arguments[nb_arguments][j] = 0;
      nb_arguments ++;
      j = 0;
    }
    else{
      arguments[nb_arguments][j] = chaine_env[i];
      j ++;
    }
  }
  arguments[nb_arguments][j] = 0;
  for(i = (nb_arguments + 1); i < 12; i++)
    arguments[i][0] = 0;
  return nb_arguments + 1;
}

canonical_original_code:
int recup_arguments(char arguments[12][512], char *chaine_env, int longueur)
{
  int i;
  int nb_arguments = 0;
  int j = 0;
  for(i = 0; i < longueur; i++){
    if(chaine_env[i] == 32){
      arguments[nb_arguments][j] = 0;
      nb_arguments ++;
      j = 0;
    }
    else{
      arguments[nb_arguments][j] = chaine_env[i];
      j ++;
    }
  }
  arguments[nb_arguments][j] = 0;
  for(i = (nb_arguments + 1); i < 12; i++)
    arguments[i][0] = 0;
  return nb_arguments + 1;
}

variable_types:
arguments
char [12][512]

variable_types: longueur int

variable_types: i int

variable_types: j int


readline

decompiled_code:
__int64 __fastcall readline(int fd, _BYTE *a2, int a3)
{
unsigned int v5; // er12
int v6; // eax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v5 = 1;
}
else
{
v5 = 1;
while ( 1 )
{
v6 = read(fd, buf, 1uLL);
if ( v6 != 1 )
break;
if ( buf[0] != 10 )
{
++v5;
*a2++ = buf[0];
if ( a3 != v5 )
continue;
}
goto LABEL_8;
}
if ( v6 )
return (unsigned int)-1;
if ( v5 == 1 )
return 0;
}
LABEL_8:
*a2 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, _BYTE *a2, int a3)
{
unsigned int v5; // er12
int v6; // eax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v5 = 1;
}
else
{
v5 = 1;
while ( 1 )
{
v6 = read(fd, buf, 1uLL);
if ( v6 != 1 )
break;
if ( buf[0] != 10 )
{
++v5;
*a2++ = buf[0];
if ( a3 != v5 )
continue;
}
goto LABEL_8;
}
if ( v6 )
return (unsigned int)-1;
if ( v5 == 1 )
return 0;
}
LABEL_8:
*a2 = 0;
return v5;
}

original_code:
int readline(int fd, char * ptr, int maxlen)
{
  int n, rc;
  char c;
  for (n = 1; n < maxlen; n++) {
    if ( (rc = read(fd, &c, 1)) == 1) {
      if (c == '\n')
 break;
      *ptr++ = c;
    }
    else if (rc == 0) {
      if (n == 1)
 return(0);
      else
 break;
    }
    else
      return(-1);
  }
  *ptr = 0;
  return(n);
}

canonical_original_code:
int readline(int fd, char *ptr, int maxlen)
{
  int n; int rc;
  char c;
  for (n = 1; n < maxlen; n++) {
    if ( (rc = read(fd, &c, 1)) == 1) {
      if (c == '\n')
 break;
      *ptr++ = c;
    }
    else if (rc == 0) {
      if (n == 1)
 return(0);
      else
 break;
    }
    else
      return(-1);
  }
  *ptr = 0;
  return(n);
}

variable_types: fd int

variable_types:
ptr
char *

variable_types: maxlen int

variable_types: n int

variable_types: rc int

variable_types: c char


writen

decompiled_code:
__int64 __fastcall writen(int fd, void *buf, int a3)
{
int v4; // er12
int v5; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v4 = a3;
v5 = a3;
do
{
LODWORD(result) = write(fd, buf, v5);
if ( (int)result <= 0 )
return (unsigned int)result;
v5 -= result;
buf = (char *)buf + (int)result;
}
while ( v5 > 0 );
return (unsigned int)(v4 - v5);
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, void *buf, int a3)
{
int v4; // er12
int v5; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v4 = a3;
v5 = a3;
do
{
LODWORD(result) = write(fd, buf, v5);
if ( (int)result <= 0 )
return (unsigned int)result;
v5 -= result;
buf = (char *)buf + (int)result;
}
while ( v5 > 0 );
return (unsigned int)(v4 - v5);
}

original_code:
int writen(int fd, char * ptr, int nbytes)
{
  int nleft, nwritten;
  nleft = nbytes;
  while (nleft > 0) {
    nwritten = write(fd, ptr, nleft);
    if (nwritten <= 0)
      return(nwritten);
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(nbytes - nleft);
}

canonical_original_code:
int writen(int fd, char *ptr, int nbytes)
{
  int nleft; int nwritten;
  nleft = nbytes;
  while (nleft > 0) {
    nwritten = write(fd, ptr, nleft);
    if (nwritten <= 0)
      return(nwritten);
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(nbytes - nleft);
}

variable_types: nbytes int

variable_types: nleft int

variable_types: nwritten int


decompiled_code:
void __fastcall __noreturn err_dump(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void err_dump(char * p)
{
  fprintf(stderr,"%s\n",p);
  exit(1);
}

canonical_original_code:
void err_dump(char *p)
{
  fprintf(stderr,"%s\n",p);
  exit(1);
}

variable_types:
p
char *


strrstr

decompiled_code:
const char *__fastcall strrstr(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
size_t v4; // rbx
char *v5; // rax
const char *v6; // r12

v2 = strlen(s);
v3 = strlen(s2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = strrchr(s, s2[v3 - 1]);
v6 = v5;
if ( !v5 )
return v6;
v6 = &v5[-v4 + 1];
if ( s <= v6 )
{
while ( strncmp(v6, s2, v4) )
{
if ( s > --v6 )
return 0LL;
}
return v6;
}
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func1(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
size_t v4; // rbx
char *v5; // rax
const char *v6; // r12

v2 = strlen(s);
v3 = strlen(s2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = strrchr(s, s2[v3 - 1]);
v6 = v5;
if ( !v5 )
return v6;
v6 = &v5[-v4 + 1];
if ( s <= v6 )
{
while ( strncmp(v6, s2, v4) )
{
if ( s > --v6 )
return 0LL;
}
return v6;
}
return 0LL;
}

original_code:
char *strrstr(const char* str1, const char *str2)
{
 size_t str1len = strlen(str1);
 size_t str2len = strlen(str2);
 if (str2len > str1len)
  return ((void *)0);
 char *pos = strrchr(str1, str2[str2len-1]);
 if (pos)
  pos -= (str2len - 1);
 while ( pos && pos >= str1 )
 {
  if ( !strncmp(pos, str2, str2len) )
   return pos;
  --pos;
 }
 return ((void *)0);
}

canonical_original_code:
char *strrstr(char *str1, char *str2)
{
 unsigned long str1len = strlen(str1);
 unsigned long str2len = strlen(str2);
 if (str2len > str1len)
  return ((void *)0);
 char *pos = strrchr(str1, str2[str2len-1]);
 if (pos)
  pos -= (str2len - 1);
 while ( pos && pos >= str1 )
 {
  if ( !strncmp(pos, str2, str2len) )
   return pos;
  --pos;
 }
 return ((void *)0);
}

variable_types:
pos
char *


delProteinMap

decompiled_code:
__int64 __fastcall delProteinMap(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
++v2;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
++v2;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
return 0LL;
}

original_code:
char **delProteinMap(char** proteinMap, int peptideCount){
 for(int i=0; i<peptideCount; ++i){
  if(proteinMap[i]){
   free(proteinMap[i]);
   proteinMap[i] = ((void *)0);
  }
 }
 free(proteinMap);
 proteinMap = ((void *)0);
 return proteinMap;
}

canonical_original_code:
char **delProteinMap(char **proteinMap, int peptideCount){
 for(int i = 0; i<peptideCount; ++i){
  if(proteinMap[i]){
   free(proteinMap[i]);
   proteinMap[i] = ((void *)0);
  }
 }
 free(proteinMap);
 proteinMap = ((void *)0);
 return proteinMap;
}

variable_types:
proteinMap
char **

variable_types: peptideCount int

return_type: char **


linfunc

original_code:
int linfunc(int m, int n, double *p, double *dy, double **dvec, void *vars){
 int i;
 struct vars_struct *v = (struct vars_struct *) vars;
 double *x, *y, *ey, f;
 x = v->x;
 y = v->y;
 ey = v->ey;
 for (i=0; i<m; i++) {
  f = p[0] - p[1]*x[i];
  dy[i] = (y[i] - f)/ey[i];
 }
  return 0;
}

canonical_original_code:
int linfunc(int m, int n, double *p, double *dy, double **dvec, void *vars){
 int i;
 struct vars_struct *v = (struct vars_struct *) vars;
 double *x; double *y; double *ey; double f;
 x = v->x;
 y = v->y;
 ey = v->ey;
 for (i=0; i<m; i++) {
  f = p[0] - p[1]*x[i];
  dy[i] = (y[i] - f)/ey[i];
 }
  return 0;
}

variable_types: m int

variable_types:
p
double *

variable_types:
dy
double *

variable_types:
dvec
double **

variable_types:
vars
void *

variable_types: struct vars_struct { double *x; double *y; double *ey; } *

variable_types:
x
double *

variable_types:
y
double *

variable_types:
ey
double *

variable_types: f double


fit

original_code:
int fit(double *x, double *y, int n, double *p){
  int i;
 double *ey = (double *)malloc(n * sizeof(double));
 for (i=0; i<n; i++){
  ey[i] = 1;
 }
 int status;
 struct vars_struct v;
 v.x = x;
 v.y = y;
 v.ey = ey;
 status = mpfit(linfunc, n, 2, p, 0, 0, (void *) &v, 0);
  return status;
}

variable_types: n int

variable_types: i int

variable_types: status int

variable_types: struct vars_struct { double *x; double *y; double *ey; }


leastSquares

original_code:
double **leastSquares(double **rt, double *median, int peptideCount,
 int fileCount){
 double **params = new2Darray(fileCount, 2);
 int i,j;
 for(i=0; i<fileCount; ++i){
  double *x = (double*)malloc(peptideCount*sizeof(double) );
  double *y = (double*)malloc(peptideCount*sizeof(double) );
  for(j=0; j<2; ++j){
   params[i][j] = 1;
  }
  int n = 0;
  for(j=0; j<peptideCount; ++j){
   if(rt[j][i] != 0 && median[j] != 0
     && fabs(rt[j][i] - median[j]) < alignWindow){
    y[n] = rt[j][i];
    x[n] = median[j];
    n++;
   }
  }
  fit(x, y, n, params[i]);
  free(x);
  free(y);
 }
 return params;
}

canonical_original_code:
double **leastSquares(double **rt, double *median, int peptideCount, int fileCount){
 double **params = new2Darray(fileCount, 2);
 int i; int j;
 for(i=0; i<fileCount; ++i){
  double *x = (double*)malloc(peptideCount*sizeof(double) );
  double *y = (double*)malloc(peptideCount*sizeof(double) );
  for(j=0; j<2; ++j){
   params[i][j] = 1;
  }
  int n = 0;
  for(j=0; j<peptideCount; ++j){
   if(rt[j][i] != 0 && median[j] != 0
     && fabs(rt[j][i] - median[j]) < alignWindow){
    y[n] = rt[j][i];
    x[n] = median[j];
    n++;
   }
  }
  fit(x, y, n, params[i]);
  free(x);
  free(y);
 }
 return params;
}

variable_types:
rt
double **

variable_types:
median
double *

variable_types: fileCount int

variable_types:
params
double **

variable_types: j int

return_type: double **


align

original_code:
void align(double **ms2rt, double **ms1rt, double *ms2median,
 double *ms1median, double **ms2params, double **ms1params,
 int peptideCount, int fileCount){
 int i, j;
 for(i = 0; i < peptideCount; ++i){
  for(j = 0; j < fileCount; ++j){
   if(ms2rt[i][j] == 0){
    if(fabs(ms2median[i] - ms1median[i]) < alignWindow &&
     ms1median[i] > 0){
     ms2rt[i][j] = ms1params[j][0] -
      ms1params[j][1]*ms1median[i];
    }else{
     ms2rt[i][j] = ms2params[j][0] -
      ms2params[j][1]*ms2median[i];
    }
   }else if(fabs(ms2rt[i][j] - ms1rt[i][j]) < alignWindow &&
    ms1rt[i][j] > 0){
    ms2rt[i][j] = ms1rt[i][j];
   }
  }
 }
 return;
}

canonical_original_code:
void align(double **ms2rt, double **ms1rt, double *ms2median, double *ms1median, double **ms2params, double **ms1params, int peptideCount, int fileCount){
 int i; int j;
 for(i = 0; i < peptideCount; ++i){
  for(j = 0; j < fileCount; ++j){
   if(ms2rt[i][j] == 0){
    if(fabs(ms2median[i] - ms1median[i]) < alignWindow &&
     ms1median[i] > 0){
     ms2rt[i][j] = ms1params[j][0] -
      ms1params[j][1]*ms1median[i];
    }else{
     ms2rt[i][j] = ms2params[j][0] -
      ms2params[j][1]*ms2median[i];
    }
   }else if(fabs(ms2rt[i][j] - ms1rt[i][j]) < alignWindow &&
    ms1rt[i][j] > 0){
    ms2rt[i][j] = ms1rt[i][j];
   }
  }
 }
 return;
}

variable_types: peptideCount int