original_code:
int module_free(module_t * module)
{
    int i, j;
    for (i = 0; i < module->num_samples; i++) {
        if (module->samples[i].data)
                free(module->samples[i].data);
    }
    free(module->samples);
    module->samples = 0;
    for (i = 0; i < module->num_instruments; i++) {
        if (module->instruments[i].volume_envelope.nodes)
            free(module->instruments[i].volume_envelope.nodes);
        if (module->instruments[i].pan_envelope.nodes)
            free(module->instruments[i].pan_envelope.nodes);
        if (module->instruments[i].pitch_envelope.nodes)
            free(module->instruments[i].pitch_envelope.nodes);
    }
    if (module->instruments) {
        free(module->instruments);
        module->instruments = 0;
    }
    for (i = 0; i < module->num_patterns; i++) {
        if (module->patterns[i].rows) {
            for (j = 0; j < module->patterns[i].num_rows; j++)
                free(module->patterns[i].rows[j].data);
            free(module->patterns[i].rows);
        }
    }
    free(module->patterns);
    module->patterns = 0;
    if (module->song_message)
        free(module->song_message);
    module->song_message = 0;
    return 0;
}

canonical_original_code:
int module_free(struct module_t *module)
{
    int i; int j;
    for (i = 0; i < module->num_samples; i++) {
        if (module->samples[i].data)
                free(module->samples[i].data);
    }
    free(module->samples);
    module->samples = 0;
    for (i = 0; i < module->num_instruments; i++) {
        if (module->instruments[i].volume_envelope.nodes)
            free(module->instruments[i].volume_envelope.nodes);
        if (module->instruments[i].pan_envelope.nodes)
            free(module->instruments[i].pan_envelope.nodes);
        if (module->instruments[i].pitch_envelope.nodes)
            free(module->instruments[i].pitch_envelope.nodes);
    }
    if (module->instruments) {
        free(module->instruments);
        module->instruments = 0;
    }
    for (i = 0; i < module->num_patterns; i++) {
        if (module->patterns[i].rows) {
            for (j = 0; j < module->patterns[i].num_rows; j++)
                free(module->patterns[i].rows[j].data);
            free(module->patterns[i].rows);
        }
    }
    free(module->patterns);
    module->patterns = 0;
    if (module->song_message)
        free(module->song_message);
    module->song_message = 0;
    return 0;
}

variable_types: struct module_t { char song_title[21]; struct module_info_t { char default_file_extension[8]; char description[64]; union { struct { char signature[8]; } flags_mod; struct { unsigned char st2vibrato; unsigned char st2tempo; unsigned char amigaslides; unsigned char amigalimits; unsigned char st30volumeslides; unsigned short st3_version; unsigned char default_panning; unsigned char mono; } flags_s3m; struct { unsigned char version_major; unsigned char version_minor; } flags_stm; struct { unsigned char stereo; unsigned char use_instruments; unsigned char linear_slides; unsigned char old_effects; unsigned char g_effect_link_memory; unsigned short created_with; unsigned short compatible_with; } flags_it; }; } module_info; enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 } module_type; unsigned short num_channels; unsigned short num_samples; unsigned short num_instruments; unsigned short num_patterns; unsigned short num_orders; unsigned char orders[256]; struct module_sample_t { struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } header; short *data; } *samples; struct module_instrument_t { char name[26]; unsigned char new_note_action; unsigned char duplicate_check_type; unsigned char duplicate_check_action; unsigned char fadeout; char pitch_pan_separation; unsigned char pitch_pan_center; unsigned char default_pan; unsigned char random_volume_variation; unsigned char random_panning_variation; unsigned char note_sample_table[240]; struct module_instrument_envelope_t { unsigned char flags; unsigned char num_nodes; unsigned char loop_start; unsigned char loop_end; unsigned char susloop_start; unsigned char susloop_end; struct module_instrument_envelope_node_t { unsigned char value; unsigned short tick; } *nodes; } volume_envelope; struct module_instrument_envelope_t pan_envelope; struct module_instrument_envelope_t pitch_envelope; } *instruments; struct module_pattern_t { unsigned short num_rows; struct module_pattern_row_t { struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; } *data; } *rows; } *patterns; unsigned char initial_speed; unsigned char initial_bpm; unsigned char initial_master_volume; unsigned char mix_volume; unsigned char initial_panning[64]; unsigned char channel_volume[64]; unsigned char panning_separation; char *song_message; } *

variable_types: j int


repo: vlohacks/misc

decompiled_code:
__int64 __fastcall sample_from_s8(char a1)
{
return (unsigned int)(a1 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (unsigned int)(a1 << 8);
}

original_code: static inline sample_t sample_from_s8(int8_t s) { return (sample_t)s << 8; }

canonical_original_code: static inline short sample_from_s8(char s) { return (short)s << 8; }

variable_types: s char

return_type: short


original_code:
int loader_mtm_check(io_handle_t * h)
{
    char signature[3];
    size_t saved_pos;
    memset(signature, 0, 3);
    saved_pos = h->tell(h);
    h->seek(h, 0, io_seek_set);
    h->read(signature, 1, 3, h);
    h->seek(h, saved_pos, io_seek_set);
    if (memcmp(signature, "MTM", 3))
        return 0;
    return 1;
}

canonical_original_code:
int loader_mtm_check(struct io_handle_t *h)
{
    char signature[3];
    unsigned long saved_pos;
    memset(signature, 0, 3);
    saved_pos = h->tell(h);
    h->seek(h, 0, io_seek_set);
    h->read(signature, 1, 3, h);
    h->seek(h, saved_pos, io_seek_set);
    if (memcmp(signature, "MTM", 3))
        return 0;
    return 1;
}

variable_types: struct io_handle_t { void *native_handle; unsigned long (*read)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); unsigned long (*write)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); int (*seek)(struct io_handle_t *handle, unsigned long n, enum io_seek_direction_t { io_seek_set=0, io_seek_end=1, io_seek_cur=2 } direction); unsigned long (*tell)(struct io_handle_t *handle); int (*feof)(struct io_handle_t *handle); } *

variable_types:
signature
char [3]

return_type: int

user_defined_types: struct io_handle_t { void *native_handle; unsigned long (*read)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); unsigned long (*write)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); int (*seek)(struct io_handle_t *handle, unsigned long n, enum io_seek_direction_t direction); unsigned long (*tell)(struct io_handle_t *handle); int (*feof)(struct io_handle_t *handle); }


decompiled_code:
__int64 __fastcall tri_mesh_free(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
return 0LL;
}

original_code:
int tri_mesh_free(tri_mesh_t * mesh)
{
    free (mesh->vertices);
    free (mesh);
    return 0;
}

canonical_original_code:
int tri_mesh_free(struct tri_mesh_s *mesh)
{
    free (mesh->vertices);
    free (mesh);
    return 0;
}

variable_types: struct tri_mesh_s { unsigned int todo1; unsigned int num_vertices; struct tri_vec_t { int x; int y; int z; } *vertices; struct tri_mesh_s **sub_meshes; } *

user_defined_types: struct tri_mesh_s { unsigned int todo1; unsigned int num_vertices; struct tri_vec_t *vertices; struct tri_mesh_s **sub_meshes; }


repo: vmj/gmbar

decompiled_code:
__int64 __fastcall parse_meminfo_field(__int64 a1, unsigned int a2, const char *a3, _DWORD *a4)
{
__int64 v7; // rbx
__int64 v8; // rax
char *v9; // rbx
const unsigned __int16 *v10; // rdx

*a4 = 0;
v7 = a1;
while ( 1 )
{
v8 = memstr(v7, a3, a2);
v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
if ( a1 == v8 )
break;
if ( *(_BYTE *)(v8 - 1) == 10 )
break;
v7 = v8 + 1;
if ( !a2 )
break;
--a2;
}
v9 = (char *)(strlen(a3) + v7);
v10 = *_ctype_b_loc();
while ( (v10[*v9] & 0x800) == 0 )
++v9;
*a4 = parse_unsigned_int(v9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, const char *a3, _DWORD *a4)
{
__int64 v7; // rbx
__int64 v8; // rax
char *v9; // rbx
const unsigned __int16 *v10; // rdx

*a4 = 0;
v7 = a1;
while ( 1 )
{
v8 = memstr(v7, a3, a2);
v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
if ( a1 == v8 )
break;
if ( *(_BYTE *)(v8 - 1) == 10 )
break;
v7 = v8 + 1;
if ( !a2 )
break;
--a2;
}
v9 = (char *)(strlen(a3) + v7);
v10 = *_ctype_b_loc();
while ( (v10[*v9] & 0x800) == 0 )
++v9;
*a4 = func1(v9);
return 0LL;
}

original_code:
static int
parse_meminfo_field(const char* meminfo,
                    const unsigned int size,
                    const char* field,
                    unsigned int *value)
{
        const char* p = meminfo;
        unsigned int len = size;
        *value = 0;
        do
        {
                p = memstr(p, field, len);
                if (!p)
                {
                        return -1;
                }
        } while (p != meminfo && p[-1] != '\n' && p++ && len--);
        p += strlen(field);
        while (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit))
                p++;
        *value = parse_unsigned_int(p);
        return 0;
}

canonical_original_code:
static int parse_meminfo_field(char *meminfo, unsigned int size, char *field, unsigned int *value)
{
        char *p = meminfo;
        unsigned int len = size;
        *value = 0;
        do
        {
                p = memstr(p, field, len);
                if (!p)
                {
                        return -1;
                }
        } while (p != meminfo && p[-1] != '\n' && p++ && len--);
        p += strlen(field);
        while (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit))
                p++;
        *value = parse_unsigned_int(p);
        return 0;
}

variable_types:
meminfo
char *

variable_types:
size
unsigned int

variable_types:
field
char *

variable_types:
value
unsigned int *

variable_types:
p
char *

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall parse_meminfo(__int64 a1, unsigned int a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // ebx
unsigned int v12; // eax
unsigned int v13; // eax
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v9 = parse_meminfo_field(a1, a2, "MemTotal", a3);
if ( v9 )
{
v11 = v9;
log_error("Error parsing MemTotal: %d", v9);
}
else
{
v10 = parse_meminfo_field(a1, a2, "MemFree", v16);
v11 = v10;
if ( v10 )
{
log_error("Error parsing MemFree: %d", v10);
}
else
{
v12 = parse_meminfo_field(a1, a2, "Buffers", a5);
v11 = v12;
if ( v12 )
{
log_error("Error parsing Buffers: %d", v12);
}
else
{
v13 = parse_meminfo_field(a1, a2, "Cached", a6);
v11 = v13;
if ( v13 )
log_error("Error parsing Cached: %d", v13);
else
*a4 = *a3 - v16[0];
}
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // ebx
unsigned int v12; // eax
unsigned int v13; // eax
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v9 = func2(a1, a2, "MemTotal", a3);
if ( v9 )
{
v11 = v9;
log_error("Error parsing MemTotal: %d", v9);
}
else
{
v10 = func2(a1, a2, "MemFree", v16);
v11 = v10;
if ( v10 )
{
log_error("Error parsing MemFree: %d", v10);
}
else
{
v12 = func2(a1, a2, "Buffers", a5);
v11 = v12;
if ( v12 )
{
log_error("Error parsing Buffers: %d", v12);
}
else
{
v13 = func2(a1, a2, "Cached", a6);
v11 = v13;
if ( v13 )
log_error("Error parsing Cached: %d", v13);
else
*a4 = *a3 - v16[0];
}
}
}
return v11;
}

original_code:
static int
parse_meminfo(const char* meminfo,
              const unsigned int size,
              unsigned int *total,
              unsigned int *used,
              unsigned int *buffers,
              unsigned int *cached)
{
        int err = 0;
        unsigned int free;
        err = parse_meminfo_field(meminfo, size, "MemTotal", total);
        if (err)
        {
                log_error("Error parsing MemTotal: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "MemFree", &free);
        if (err)
        {
                log_error("Error parsing MemFree: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "Buffers", buffers);
        if (err)
        {
                log_error("Error parsing Buffers: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "Cached", cached);
        if (err)
        {
                log_error("Error parsing Cached: %d", err);
                return err;
        }
        *used = *total - free;
        return err;
}

canonical_original_code:
static int parse_meminfo(char *meminfo, unsigned int size, unsigned int *total, unsigned int *used, unsigned int *buffers, unsigned int *cached)
{
        int err = 0;
        unsigned int free;
        err = parse_meminfo_field(meminfo, size, "MemTotal", total);
        if (err)
        {
                log_error("Error parsing MemTotal: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "MemFree", &free);
        if (err)
        {
                log_error("Error parsing MemFree: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "Buffers", buffers);
        if (err)
        {
                log_error("Error parsing Buffers: %d", err);
                return err;
        }
        err = parse_meminfo_field(meminfo, size, "Cached", cached);
        if (err)
        {
                log_error("Error parsing Cached: %d", err);
                return err;
        }
        *used = *total - free;
        return err;
}

variable_types:
total
unsigned int *

variable_types:
used
unsigned int *

variable_types:
buffers
unsigned int *

variable_types:
cached
unsigned int *

variable_types: err int

variable_types:
free
unsigned int


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

*a5 = 0;
*a4 = 0;
*a3 = 0;
*a2 = 0;
*(_DWORD *)(a1 + 8) = 0;
result = readfile("/proc/meminfo", a1, a1 + 8, a1 + 12);
if ( !(_DWORD)result )
result = parse_meminfo(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), a2, a3, a4, a5);
return result;
}

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

*a5 = 0;
*a4 = 0;
*a3 = 0;
*a2 = 0;
*(_DWORD *)(a1 + 8) = 0;
result = readfile("/proc/meminfo", a1, a1 + 8, a1 + 12);
if ( !(_DWORD)result )
result = func3(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), a2, a3, a4, a5);
return result;
}

original_code:
static int
get_meminfo(buffer* meminfo,
            unsigned int *total,
            unsigned int *used,
            unsigned int *buffers,
            unsigned int *cached)
{
        int err = 0;
        *total = *used = *buffers = *cached = 0;
        meminfo->len = 0;
        err = readfile("/proc/meminfo", &meminfo->buf, &meminfo->len, &meminfo->max);
        if (err)
        {
                return err;
        }
        err = parse_meminfo(meminfo->buf, meminfo->len, total, used, buffers, cached);
        return err;
}

canonical_original_code:
static int get_meminfo(struct buffer *meminfo, unsigned int *total, unsigned int *used, unsigned int *buffers, unsigned int *cached)
{
        int err = 0;
        *total = *used = *buffers = *cached = 0;
        meminfo->len = 0;
        err = readfile("/proc/meminfo", &meminfo->buf, &meminfo->len, &meminfo->max);
        if (err)
        {
                return err;
        }
        err = parse_meminfo(meminfo->buf, meminfo->len, total, used, buffers, cached);
        return err;
}

variable_types: struct buffer { char *buf; unsigned int len; unsigned int max; } *


decompiled_code:
__int64 __fastcall parse_unsigned_int(char *a1)
{
const unsigned __int16 *v2; // rsi
unsigned int i; // edx
char v4; // al

v2 = *_ctype_b_loc();
for ( i = 0; ; i = v4 + 10 * i - 48 )
{
v4 = *a1;
if ( (v2[*a1] & 0x800) == 0 )
break;
++a1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
const unsigned __int16 *v2; // rsi
unsigned int i; // edx
char v4; // al

v2 = *_ctype_b_loc();
for ( i = 0; ; i = v4 + 10 * i - 48 )
{
v4 = *a1;
if ( (v2[*a1] & 0x800) == 0 )
break;
++a1;
}
return i;
}

original_code:
static unsigned int
parse_unsigned_int(const char* str)
{
        unsigned int value = 0;
        const char *p = str;
        while(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit))
                value = value * 10 + (*p++ - '0');
        return value;
}

canonical_original_code:
static unsigned int parse_unsigned_int(char *str)
{
        unsigned int value = 0;
        char *p = str;
        while(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit))
                value = value * 10 + (*p++ - '0');
        return value;
}

variable_types:
str
char *

variable_types:
value
unsigned int

return_type: unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
int v7; // ebx
__int64 v9; // [rsp+0h] [rbp-58h] BYREF
unsigned int seconds; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]
__int64 v12; // [rsp+18h] [rbp-40h]
unsigned int v13; // [rsp+20h] [rbp-38h] BYREF
unsigned int v14; // [rsp+24h] [rbp-34h] BYREF
unsigned int v15; // [rsp+28h] [rbp-30h] BYREF
unsigned int v16[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v3 = buffer_new(argc, argv, envp);
if ( !v3 )
return -1;
v4 = v3;
v5 = gmbar_new_with_defaults(100LL, 10LL, "red", "none");
v6 = v5;
if ( v5 )
{
if ( (unsigned int)gmbar_add_sections(v5, 3LL, "red", "orange", "yellow") )
{
buffer_free(v4);
gmbar_free(v6);
v7 = -1;
}
else
{
v9 = v6;
seconds = 15;
v11 = 0LL;
v12 = 0LL;
v7 = argp_parse(&argp, argc, (char **)argv, 0, 0LL, &v9);
if ( !v7 )
{
while ( 1 )
{
v7 = get_meminfo(v4, v16, &v15, &v14, &v13);
if ( v7 )
break;
gmbar_set_section_width(**(_QWORD **)(v6 + 64), v16[0], v15);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 8LL), v16[0], v14);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 16LL), v16[0], v13);
v7 = print_bar(&v9);
if ( v7 )
break;
sleep(seconds);
if ( !seconds )
return v7;
}
}
buffer_free(v4);
gmbar_free(v6);
}
}
else
{
buffer_free(v4);
v7 = -1;
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
int v7; // ebx
__int64 v9; // [rsp+0h] [rbp-58h] BYREF
unsigned int seconds; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]
__int64 v12; // [rsp+18h] [rbp-40h]
unsigned int v13; // [rsp+20h] [rbp-38h] BYREF
unsigned int v14; // [rsp+24h] [rbp-34h] BYREF
unsigned int v15; // [rsp+28h] [rbp-30h] BYREF
unsigned int v16[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v3 = buffer_new(argc, argv, envp);
if ( !v3 )
return -1;
v4 = v3;
v5 = gmbar_new_with_defaults(100LL, 10LL, "red", "none");
v6 = v5;
if ( v5 )
{
if ( (unsigned int)gmbar_add_sections(v5, 3LL, "red", "orange", "yellow") )
{
buffer_free(v4);
gmbar_free(v6);
v7 = -1;
}
else
{
v9 = v6;
seconds = 15;
v11 = 0LL;
v12 = 0LL;
v7 = argp_parse(&argp, argc, (char **)argv, 0, 0LL, &v9);
if ( !v7 )
{
while ( 1 )
{
v7 = func4(v4, v16, &v15, &v14, &v13);
if ( v7 )
break;
gmbar_set_section_width(**(_QWORD **)(v6 + 64), v16[0], v15);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 8LL), v16[0], v14);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 16LL), v16[0], v13);
v7 = print_bar(&v9);
if ( v7 )
break;
sleep(seconds);
if ( !seconds )
return v7;
}
}
buffer_free(v4);
gmbar_free(v6);
}
}
else
{
buffer_free(v4);
v7 = -1;
}
return v7;
}

original_code:
int
main(int argc, char** argv)
{
        int err = 0;
        unsigned int total, used, buffers, cached;
        arguments config;
        buffer* meminfo = ((void *)0);
        gmbar* bar = ((void *)0);
        meminfo = buffer_new();
        if (!meminfo)
        {
                return -1;
        }
        bar = gmbar_new_with_defaults(100, 10, "red", "none");
        if (!bar)
        {
                buffer_free(meminfo);
                return -1;
        }
        err = gmbar_add_sections(bar, 3, "red", "orange", "yellow");
        if (err)
        {
                buffer_free(meminfo);
                gmbar_free(bar);
                return -1;
        }
        config.common_config.bar = bar;
        config.common_config.interval = 15;
        config.common_config.prefix = ((void *)0);
        config.common_config.suffix = ((void *)0);
        err = argp_parse(&argp, argc, argv, 0, ((void *)0), &config);
        if (err)
        {
                buffer_free(meminfo);
                gmbar_free(bar);
                return err;
        }
        do {
                err = get_meminfo(meminfo, &total, &used, &buffers, &cached);
                if (err)
                {
                        buffer_free(meminfo);
                        gmbar_free(bar);
                        return err;
                }
                gmbar_set_section_width(bar->sections[0], total, used);
                gmbar_set_section_width(bar->sections[1], total, buffers);
                gmbar_set_section_width(bar->sections[2], total, cached);
                err = print_bar(&config.common_config);
                if (err)
                {
                        buffer_free(meminfo);
                        gmbar_free(bar);
                        return err;
                }
                sleep(config.common_config.interval);
        } while (config.common_config.interval);
        return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
        int err = 0;
        unsigned int total; unsigned int used; unsigned int buffers; unsigned int cached;
        struct arguments config;
        struct buffer *meminfo = ((void *)0);
        struct gmbar *bar = ((void *)0);
        meminfo = buffer_new();
        if (!meminfo)
        {
                return -1;
        }
        bar = gmbar_new_with_defaults(100, 10, "red", "none");
        if (!bar)
        {
                buffer_free(meminfo);
                return -1;
        }
        err = gmbar_add_sections(bar, 3, "red", "orange", "yellow");
        if (err)
        {
                buffer_free(meminfo);
                gmbar_free(bar);
                return -1;
        }
        config.common_config.bar = bar;
        config.common_config.interval = 15;
        config.common_config.prefix = ((void *)0);
        config.common_config.suffix = ((void *)0);
        err = argp_parse(&argp, argc, argv, 0, ((void *)0), &config);
        if (err)
        {
                buffer_free(meminfo);
                gmbar_free(bar);
                return err;
        }
        do {
                err = get_meminfo(meminfo, &total, &used, &buffers, &cached);
                if (err)
                {
                        buffer_free(meminfo);
                        gmbar_free(bar);
                        return err;
                }
                gmbar_set_section_width(bar->sections[0], total, used);
                gmbar_set_section_width(bar->sections[1], total, buffers);
                gmbar_set_section_width(bar->sections[2], total, cached);
                err = print_bar(&config.common_config);
                if (err)
                {
                        buffer_free(meminfo);
                        gmbar_free(bar);
                        return err;
                }
                sleep(config.common_config.interval);
        } while (config.common_config.interval);
        return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
total
unsigned int

variable_types:
used
unsigned int

variable_types:
buffers
unsigned int

variable_types:
cached
unsigned int

variable_types: struct arguments { struct common_arguments { struct gmbar { struct gmsize { unsigned int width; unsigned int height; } size; struct gmcolor { char *fg; char *bg; } color; struct gmmargin { unsigned char top; unsigned char right; unsigned char bottom; unsigned char left; } margin; struct gmmargin padding; unsigned int segment_width; unsigned int segment_gap; unsigned int granularity; double rounding; unsigned char nsections; struct gmsection { void *bar; unsigned int width; char *color; } **sections; } *bar; unsigned int interval; char *prefix; char *suffix; } common_config; }

user_defined_types: struct arguments { struct common_arguments common_config; }

user_defined_types: struct common_arguments { struct gmbar *bar; unsigned int interval; char *prefix; char *suffix; }

user_defined_types: struct buffer { char *buf; unsigned int len; unsigned int max; }

user_defined_types: struct gmbar { struct gmsize size; struct gmcolor color; struct gmmargin margin; struct gmmargin padding; unsigned int segment_width; unsigned int segment_gap; unsigned int granularity; double rounding; unsigned char nsections; struct gmsection **sections; }


decompiled_code:
__int64 __fastcall parse_cpuinfo(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
__int64 v4; // r12
__int64 v5; // rax

v2 = a1;
v3 = a2;
v4 = 0LL;
while ( 1 )
{
v5 = memstr(a1, "processor", v3);
a1 = v5;
if ( !v5 )
break;
if ( v2 == v5 || *(_BYTE *)(v5 - 1) == 10 )
{
++v4;
v3 = a2 - (v5 - v2);
a1 = v5 + 1;
}
}
return v4;
}

original_code:
static long
parse_cpuinfo(const char* cpuinfo, const unsigned int size)
{
        const char* p = cpuinfo;
        unsigned int len = size;
        long cpus = 0;
        do
        {
                p = memstr(p, "processor", len);
                if (p && (p == cpuinfo || p[-1] == '\n'))
                {
                        cpus++;
                        len = size - (p - cpuinfo);
                        p++;
                }
        } while (p);
        return cpus;
}

canonical_original_code:
static long parse_cpuinfo(char *cpuinfo, unsigned int size)
{
        char *p = cpuinfo;
        unsigned int len = size;
        long cpus = 0;
        do
        {
                p = memstr(p, "processor", len);
                if (p && (p == cpuinfo || p[-1] == '\n'))
                {
                        cpus++;
                        len = size - (p - cpuinfo);
                        p++;
                }
        } while (p);
        return cpus;
}

variable_types:
cpuinfo
char *

variable_types:
size
unsigned int

variable_types:
p
char *

variable_types:
len
unsigned int

variable_types: cpus long

return_type: long


decompiled_code:
__int64 get_num_cpus()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
v2 = 0;
v1 = 0;
LODWORD(result) = readfile("/proc/cpuinfo", &v3, &v2, &v1);
if ( (_DWORD)result || !v3 )
result = (int)result;
else
result = parse_cpuinfo(v3, v2);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
v2 = 0;
v1 = 0;
LODWORD(result) = readfile("/proc/cpuinfo", &v3, &v2, &v1);
if ( (_DWORD)result || !v3 )
result = (int)result;
else
result = func2(v3, v2);
return result;
}

original_code:
static long
get_num_cpus()
{
        int err = 0;
        char* cpuinfo = ((void *)0);
        unsigned int size = 0;
        unsigned int max = 0;
        err = readfile("/proc/cpuinfo", &cpuinfo, &size, &max);
        if (err || !cpuinfo)
        {
                return err;
        }
        return parse_cpuinfo(cpuinfo, size);
}

canonical_original_code:
static long get_num_cpus()
{
        int err = 0;
        char *cpuinfo = ((void *)0);
        unsigned int size = 0;
        unsigned int max = 0;
        err = readfile("/proc/cpuinfo", &cpuinfo, &size, &max);
        if (err || !cpuinfo)
        {
                return err;
        }
        return parse_cpuinfo(cpuinfo, size);
}

variable_types: err int

variable_types:
max
unsigned int


decompiled_code:
__int64 __fastcall parse_stat(char *a1, unsigned int a2, const char *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6, _DWORD *a7)
{
__int64 v11; // rdx
char *v12; // rax
int v13; // eax
char *v15[8]; // [rsp+8h] [rbp-40h] BYREF

v15[0] = a1;
*a7 = 0;
*a6 = 0;
*a5 = 0;
*a4 = 0;
v11 = a2;
while ( 1 )
{
v12 = (char *)memstr(v15[0], a3, v11);
v15[0] = v12;
if ( !v12 )
break;
if ( v12 != a1 && *(v12 - 1) != 10 )
{
v15[0] = v12 + 1;
v13 = (_DWORD)v12 + 1 - (_DWORD)a1;
v11 = a2 - v13;
if ( a2 != v13 )
continue;
}
v15[0] += strlen(a3);
*a5 = parse_unsigned_int(v15[0], v15);
*a6 = parse_unsigned_int(v15[0], v15);
*a4 = parse_unsigned_int(v15[0], v15);
*a7 = parse_unsigned_int(v15[0], 0LL);
return 0LL;
}
log_error("Field not found: %d", 0xFFFFFFFFLL);
return 0xFFFFFFFFLL;
}

original_code:
static int
parse_stat(const char* stat,
           const unsigned int size,
           const char* field,
           unsigned int *kern,
           unsigned int *user,
           unsigned int *nice,
           unsigned int *idle)
{
        const char* p = stat;
        unsigned int len = size;
        *kern = *user = *nice = *idle = 0;
        do
        {
                p = memstr(p, field, len);
                if (!p)
                {
                        log_error("Field not found: %d", -1);
                        return -1;
                }
        } while (p != stat && p[-1] != '\n' && p++ && (len = size - (p - stat)));
        p += strlen(field);
        *user = parse_unsigned_int(p, &p);
        *nice = parse_unsigned_int(p, &p);
        *kern = parse_unsigned_int(p, &p);
        *idle = parse_unsigned_int(p, ((void *)0));
        return 0;
}

canonical_original_code:
static int parse_stat(char *stat, unsigned int size, char *field, unsigned int *kern, unsigned int *user, unsigned int *nice, unsigned int *idle)
{
        char *p = stat;
        unsigned int len = size;
        *kern = *user = *nice = *idle = 0;
        do
        {
                p = memstr(p, field, len);
                if (!p)
                {
                        log_error("Field not found: %d", -1);
                        return -1;
                }
        } while (p != stat && p[-1] != '\n' && p++ && (len = size - (p - stat)));
        p += strlen(field);
        *user = parse_unsigned_int(p, &p);
        *nice = parse_unsigned_int(p, &p);
        *kern = parse_unsigned_int(p, &p);
        *idle = parse_unsigned_int(p, ((void *)0));
        return 0;
}

variable_types:
stat
char *

variable_types:
field
char *

variable_types:
kern
unsigned int *

variable_types:
user
unsigned int *

variable_types:
nice
unsigned int *

variable_types:
idle
unsigned int *


decompiled_code:
__int64 __fastcall get_stat(__int64 a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
__int64 result; // rax

*a6 = 0;
*a5 = 0;
*a4 = 0;
*a3 = 0;
*(_DWORD *)(a1 + 8) = 0;
result = readfile("/proc/stat", a1, a1 + 8, a1 + 12);
if ( !(_DWORD)result )
result = parse_stat(*(char **)a1, *(_DWORD *)(a1 + 8), a2, a3, a4, a5, a6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
__int64 result; // rax

*a6 = 0;
*a5 = 0;
*a4 = 0;
*a3 = 0;
*(_DWORD *)(a1 + 8) = 0;
result = readfile("/proc/stat", a1, a1 + 8, a1 + 12);
if ( !(_DWORD)result )
result = func4(*(char **)a1, *(_DWORD *)(a1 + 8), a2, a3, a4, a5, a6);
return result;
}

original_code:
static int
get_stat(buffer* stat,
         const char* field,
         unsigned int *kern,
         unsigned int *user,
         unsigned int *nice,
         unsigned int *idle)
{
        int err = 0;
        *kern = *user = *nice = *idle = 0;
        stat->len = 0;
        err = readfile("/proc/stat", &stat->buf, &stat->len, &stat->max);
        if (err)
        {
                return err;
        }
        err = parse_stat(stat->buf, stat->len, field, kern, user, nice, idle);
        return err;
}

canonical_original_code:
static int get_stat(struct buffer *stat, char *field, unsigned int *kern, unsigned int *user, unsigned int *nice, unsigned int *idle)
{
        int err = 0;
        *kern = *user = *nice = *idle = 0;
        stat->len = 0;
        err = readfile("/proc/stat", &stat->buf, &stat->len, &stat->max);
        if (err)
        {
                return err;
        }
        err = parse_stat(stat->buf, stat->len, field, kern, user, nice, idle);
        return err;
}

variable_types: struct buffer { char *buf; unsigned int len; unsigned int max; } *


decompiled_code:
__int64 __fastcall parse_unsigned_int(char *a1, _QWORD *a2)
{
const unsigned __int16 *v3; // rcx
char v4; // al
unsigned int v5; // edx

v3 = *_ctype_b_loc();
while ( 1 )
{
v4 = *a1;
if ( (v3[*a1] & 0x800) != 0 )
break;
++a1;
}
v5 = 0;
do
{
++a1;
v5 = v4 + 10 * v5 - 48;
v4 = *a1;
}
while ( (v3[*a1] & 0x800) != 0 );
if ( a2 )
*a2 = a1;
return v5;
}

original_code:
static unsigned int
parse_unsigned_int(const char* str, const char** end)
{
        unsigned int value = 0;
        while (!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
                str++;
        while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
                value = value * 10 + (*str++ - '0');
        if (end)
                *end = (char*)str;
        return value;
}

canonical_original_code:
static unsigned int parse_unsigned_int(char *str, char **end)
{
        unsigned int value = 0;
        while (!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
                str++;
        while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
                value = value * 10 + (*str++ - '0');
        if (end)
                *end = (char *)str;
        return value;
}

variable_types:
str
char *

variable_types:
end
char **

variable_types:
value
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rbx
unsigned int v8; // edi
unsigned int v9; // ebx
__int64 v11; // [rsp+0h] [rbp-98h] BYREF
unsigned int seconds; // [rsp+8h] [rbp-90h]
__int64 v13; // [rsp+10h] [rbp-88h]
__int64 v14; // [rsp+18h] [rbp-80h]
unsigned int v15; // [rsp+20h] [rbp-78h]
__int64 v16; // [rsp+30h] [rbp-68h] BYREF
int v17; // [rsp+38h] [rbp-60h] BYREF
int v18; // [rsp+3Ch] [rbp-5Ch] BYREF
__int64 v19; // [rsp+40h] [rbp-58h] BYREF
int v20; // [rsp+48h] [rbp-50h] BYREF
int v21; // [rsp+4Ch] [rbp-4Ch] BYREF
char s[72]; // [rsp+50h] [rbp-48h] BYREF

v3 = buffer_new(argc, argv, envp);
if ( !v3 )
{
LODWORD(v7) = -1;
return v7;
}
v4 = v3;
v5 = gmbar_new_with_defaults(100LL, 10LL, "red", "none");
v6 = v5;
if ( v5 )
{
if ( (unsigned int)gmbar_add_sections(v5, 4LL, "red", "orange", "yellow", "none") )
{
buffer_free(v4);
gmbar_free(v6);
LODWORD(v7) = -1;
}
else
{
v15 = -1;
v11 = v6;
seconds = 15;
v13 = 0LL;
v14 = 0LL;
LODWORD(v7) = argp_parse(&argp, argc, (char **)argv, 0, 0LL, &v11);
if ( (_DWORD)v7
|| (sysconf(2), v7 = get_num_cpus(), v7 < 0)
|| (v15 <= 0x7F && (int)v15 < v7 ? snprintf(s, 0x14uLL, "cpu%i ", v15) : strcpy(s, "cpu "),
LODWORD(v7) = get_stat(v4, s, &v21, &v20, (_DWORD *)&v19 + 1, &v19),
(_DWORD)v7) )
{
LABEL_17:
buffer_free(v4);
gmbar_free(v6);
return v7;
}
v8 = seconds;
if ( seconds )
{
while ( 1 )
{
sleep(v8);
LODWORD(v7) = get_stat(v4, s, &v18, &v17, (_DWORD *)&v16 + 1, &v16);
if ( (_DWORD)v7 )
break;
v9 = v18 - v21 + v16 + v17 + HIDWORD(v16) - v20 - HIDWORD(v19) - v19;
gmbar_set_section_width(**(_QWORD **)(v6 + 64), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 8LL), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 16LL), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 24LL), v9);
LODWORD(v7) = print_bar(&v11);
if ( (_DWORD)v7 )
break;
v21 = v18;
v20 = v17;
v19 = v16;
v8 = seconds;
if ( !seconds )
return v7;
}
goto LABEL_17;
}
}
}
else
{
buffer_free(v4);
LODWORD(v7) = -1;
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rbx
unsigned int v8; // edi
unsigned int v9; // ebx
__int64 v11; // [rsp+0h] [rbp-98h] BYREF
unsigned int seconds; // [rsp+8h] [rbp-90h]
__int64 v13; // [rsp+10h] [rbp-88h]
__int64 v14; // [rsp+18h] [rbp-80h]
unsigned int v15; // [rsp+20h] [rbp-78h]
__int64 v16; // [rsp+30h] [rbp-68h] BYREF
int v17; // [rsp+38h] [rbp-60h] BYREF
int v18; // [rsp+3Ch] [rbp-5Ch] BYREF
__int64 v19; // [rsp+40h] [rbp-58h] BYREF
int v20; // [rsp+48h] [rbp-50h] BYREF
int v21; // [rsp+4Ch] [rbp-4Ch] BYREF
char s[72]; // [rsp+50h] [rbp-48h] BYREF

v3 = buffer_new(argc, argv, envp);
if ( !v3 )
{
LODWORD(v7) = -1;
return v7;
}
v4 = v3;
v5 = gmbar_new_with_defaults(100LL, 10LL, "red", "none");
v6 = v5;
if ( v5 )
{
if ( (unsigned int)gmbar_add_sections(v5, 4LL, "red", "orange", "yellow", "none") )
{
buffer_free(v4);
gmbar_free(v6);
LODWORD(v7) = -1;
}
else
{
v15 = -1;
v11 = v6;
seconds = 15;
v13 = 0LL;
v14 = 0LL;
LODWORD(v7) = argp_parse(&argp, argc, (char **)argv, 0, 0LL, &v11);
if ( (_DWORD)v7
|| (sysconf(2), v7 = func3(), v7 < 0)
|| (v15 <= 0x7F && (int)v15 < v7 ? snprintf(s, 0x14uLL, "cpu%i ", v15) : strcpy(s, "cpu "),
LODWORD(v7) = func5(v4, s, &v21, &v20, (_DWORD *)&v19 + 1, &v19),
(_DWORD)v7) )
{
LABEL_17:
buffer_free(v4);
gmbar_free(v6);
return v7;
}
v8 = seconds;
if ( seconds )
{
while ( 1 )
{
sleep(v8);
LODWORD(v7) = func5(v4, s, &v18, &v17, (_DWORD *)&v16 + 1, &v16);
if ( (_DWORD)v7 )
break;
v9 = v18 - v21 + v16 + v17 + HIDWORD(v16) - v20 - HIDWORD(v19) - v19;
gmbar_set_section_width(**(_QWORD **)(v6 + 64), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 8LL), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 16LL), v9);
gmbar_set_section_width(*(_QWORD *)(*(_QWORD *)(v6 + 64) + 24LL), v9);
LODWORD(v7) = print_bar(&v11);
if ( (_DWORD)v7 )
break;
v21 = v18;
v20 = v17;
v19 = v16;
v8 = seconds;
if ( !seconds )
return v7;
}
goto LABEL_17;
}
}
}
else
{
buffer_free(v4);
LODWORD(v7) = -1;
}
return v7;
}

original_code:
int
main(int argc, char** argv)
{
        int err = 0;
        long total;
        long num_cpus;
        char cpu_field[20 + 1];
        unsigned int _kern, _user, _nice, _idle;
        unsigned int kern, user, nice, idle;
        arguments config;
        buffer* stat = ((void *)0);
        gmbar* bar = ((void *)0);
        stat = buffer_new();
        if (!stat)
        {
                return -1;
        }
        bar = gmbar_new_with_defaults(100, 10, "red", "none");
        if (!bar)
        {
                buffer_free(stat);
                return -1;
        }
        err = gmbar_add_sections(bar, 4, "red", "orange", "yellow", "none");
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return -1;
        }
        config.cpu_index = -1;
        config.common_config.bar = bar;
        config.common_config.interval = 15;
        config.common_config.prefix = ((void *)0);
        config.common_config.suffix = ((void *)0);
        err = argp_parse(&argp, argc, argv, 0, ((void *)0), &config);
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return err;
        }
        total = sysconf(_SC_CLK_TCK);
        num_cpus = get_num_cpus();
        if (num_cpus < 0)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return num_cpus;
        }
        if (config.cpu_index >= 0
            && config.cpu_index <= 0x7f
            && config.cpu_index < num_cpus)
        {
                snprintf(cpu_field, 20, "cpu%i ", config.cpu_index);
        }
        else
        {
                snprintf(cpu_field, 20, "cpu ");
        }
        err = get_stat(stat, cpu_field, &_kern, &_user, &_nice, &_idle);
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return err;
        }
        while (config.common_config.interval)
        {
                sleep(config.common_config.interval);
                err = get_stat(stat, cpu_field, &kern, &user, &nice, &idle);
                if (err)
                {
                        buffer_free(stat);
                        gmbar_free(bar);
                        return err;
                }
                total = (kern - _kern) + (user - _user) + (nice - _nice) + (idle - _idle);
                gmbar_set_section_width(bar->sections[0], total, kern - _kern);
                gmbar_set_section_width(bar->sections[1], total, user - _user);
                gmbar_set_section_width(bar->sections[2], total, nice - _nice);
                gmbar_set_section_width(bar->sections[3], total, idle - _idle);
                err = print_bar(&config.common_config);
                if (err)
                {
                        buffer_free(stat);
                        gmbar_free(bar);
                        return err;
                }
                _kern = kern;
                _user = user;
                _nice = nice;
                _idle = idle;
        }
        return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
        int err = 0;
        long total;
        long num_cpus;
        char cpu_field[-1];
        unsigned int _kern; unsigned int _user; unsigned int _nice; unsigned int _idle;
        unsigned int kern; unsigned int user; unsigned int nice; unsigned int idle;
        struct arguments config;
        struct buffer *stat = ((void *)0);
        struct gmbar *bar = ((void *)0);
        stat = buffer_new();
        if (!stat)
        {
                return -1;
        }
        bar = gmbar_new_with_defaults(100, 10, "red", "none");
        if (!bar)
        {
                buffer_free(stat);
                return -1;
        }
        err = gmbar_add_sections(bar, 4, "red", "orange", "yellow", "none");
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return -1;
        }
        config.cpu_index = -1;
        config.common_config.bar = bar;
        config.common_config.interval = 15;
        config.common_config.prefix = ((void *)0);
        config.common_config.suffix = ((void *)0);
        err = argp_parse(&argp, argc, argv, 0, ((void *)0), &config);
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return err;
        }
        total = sysconf(_SC_CLK_TCK);
        num_cpus = get_num_cpus();
        if (num_cpus < 0)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return num_cpus;
        }
        if (config.cpu_index >= 0
            && config.cpu_index <= 0x7f
            && config.cpu_index < num_cpus)
        {
                snprintf(cpu_field, 20, "cpu%i ", config.cpu_index);
        }
        else
        {
                snprintf(cpu_field, 20, "cpu ");
        }
        err = get_stat(stat, cpu_field, &_kern, &_user, &_nice, &_idle);
        if (err)
        {
                buffer_free(stat);
                gmbar_free(bar);
                return err;
        }
        while (config.common_config.interval)
        {
                sleep(config.common_config.interval);
                err = get_stat(stat, cpu_field, &kern, &user, &nice, &idle);
                if (err)
                {
                        buffer_free(stat);
                        gmbar_free(bar);
                        return err;
                }
                total = (kern - _kern) + (user - _user) + (nice - _nice) + (idle - _idle);
                gmbar_set_section_width(bar->sections[0], total, kern - _kern);
                gmbar_set_section_width(bar->sections[1], total, user - _user);
                gmbar_set_section_width(bar->sections[2], total, nice - _nice);
                gmbar_set_section_width(bar->sections[3], total, idle - _idle);
                err = print_bar(&config.common_config);
                if (err)
                {
                        buffer_free(stat);
                        gmbar_free(bar);
                        return err;
                }
                _kern = kern;
                _user = user;
                _nice = nice;
                _idle = idle;
        }
        return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: total long

variable_types:
kern
unsigned int

variable_types:
user
unsigned int

variable_types:
nice
unsigned int

variable_types:
idle
unsigned int

variable_types: struct arguments { struct common_arguments { struct gmbar { struct gmsize { unsigned int width; unsigned int height; } size; struct gmcolor { char *fg; char *bg; } color; struct gmmargin { unsigned char top; unsigned char right; unsigned char bottom; unsigned char left; } margin; struct gmmargin padding; unsigned int segment_width; unsigned int segment_gap; unsigned int granularity; double rounding; unsigned char nsections; struct gmsection { void *bar; unsigned int width; char *color; } **sections; } *bar; unsigned int interval; char *prefix; char *suffix; } common_config; int cpu_index; }

user_defined_types: struct arguments { struct common_arguments common_config; int cpu_index; }


repo: vmj/othello

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

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

original_code:
void
oth_camera_free(Camera* camera)
{
        if (camera)
                free(camera);
}

canonical_original_code:
void oth_camera_free(struct Camera *camera)
{
        if (camera)
                free(camera);
}

variable_types: struct Camera { struct { double fov; } frustum; struct { float v; } angle; struct { float x; } radius; struct { float x; } eye; struct { float x; } at; struct { float x; } up; } *

return_type: void


original_code:
void
oth_camera_update(Camera* camera)
{
        double v_angle = ((camera->angle.v) * 0.01745329252);
        double h_angle = ((camera->angle.h) * 0.01745329252);
        camera->eye.x = camera->radius.x * cos(v_angle) * cos(h_angle) + camera->at.x;
        camera->eye.y = camera->radius.y * sin(v_angle) + camera->at.y;
        camera->eye.z = camera->radius.z * cos(v_angle) * sin(h_angle) + camera->at.z;
}

canonical_original_code:
void oth_camera_update(struct Camera *camera)
{
        double v_angle = ((camera->angle.v) * 0.01745329252);
        double h_angle = ((camera->angle.h) * 0.01745329252);
        camera->eye.x = camera->radius.x * cos(v_angle) * cos(h_angle) + camera->at.x;
        camera->eye.y = camera->radius.y * sin(v_angle) + camera->at.y;
        camera->eye.z = camera->radius.z * cos(v_angle) * sin(h_angle) + camera->at.z;
}

user_defined_types: struct Camera { struct { double fov; } frustum; struct { float v; } angle; struct { float x; } radius; struct { float x; } eye; struct { float x; } at; struct { float x; } up; }


original_code:
void
oth_camera_reset(Camera* camera, Board* board)
{
        camera->angle.v = 0 + (89 - 0) / 2;
        camera->angle.h = 0 + (360 - 0) / 2;
        camera->radius.x = ((unsigned)1) * board->ranks + (((unsigned)1) * 2);
        camera->radius.y = ((unsigned)1) * ( (board->ranks) > (board->files) ? (board->ranks) : (board->files) ) + (((unsigned)1) * 2);
        camera->radius.z = ((unsigned)1) * board->files + (((unsigned)1) * 2);
        camera->frustum.fov = 70.0;
        camera->frustum.close = 1.0;
        camera->frustum.distant =
                ( (( (camera->radius.x) > (camera->radius.z) ? (camera->radius.x) : (camera->radius.z) )) > (camera->radius.y) ? (( (camera->radius.x) > (camera->radius.z) ? (camera->radius.x) : (camera->radius.z) )) : (camera->radius.y) ) * 2;
        camera->at.x = board->ranks * ((unsigned)1) / (double)2;
        camera->at.y = 0.0;
        camera->at.z = board->files * ((unsigned)1) / (double)2;
        camera->up.x = 0;
        camera->up.y = 1;
        camera->up.z = 0;
        oth_camera_update(camera);
}

canonical_original_code:
void oth_camera_reset(struct Camera *camera, struct Board *board)
{
        camera->angle.v = 0 + (89 - 0) / 2;
        camera->angle.h = 0 + (360 - 0) / 2;
        camera->radius.x = ((unsigned int)1) * board->ranks + (((unsigned int)1) * 2);
        camera->radius.y = ((unsigned int)1) * ( (board->ranks) > (board->files) ? (board->ranks) : (board->files) ) + (((unsigned int)1) * 2);
        camera->radius.z = ((unsigned int)1) * board->files + (((unsigned int)1) * 2);
        camera->frustum.fov = 70.0;
        camera->frustum.close = 1.0;
        camera->frustum.distant =
                ( (( (camera->radius.x) > (camera->radius.z) ? (camera->radius.x) : (camera->radius.z) )) > (camera->radius.y) ? (( (camera->radius.x) > (camera->radius.z) ? (camera->radius.x) : (camera->radius.z) )) : (camera->radius.y) ) * 2;
        camera->at.x = board->ranks * ((unsigned int)1) / (double)2;
        camera->at.y = 0.0;
        camera->at.z = board->files * ((unsigned int)1) / (double)2;
        camera->up.x = 0;
        camera->up.y = 1;
        camera->up.z = 0;
        oth_camera_update(camera);
}

variable_types: struct Board { struct Square { unsigned int name; unsigned int rank; unsigned int file; struct Score { unsigned int blacks; unsigned int whites; } score; enum Disk { EMPTY=0, BLACK=1, WHITE=2 } disk; char flipping; struct Flipper { struct { float x; } translation; struct { float a; } rotation; float ambient[4]; float diffuse[4]; float specular[4]; } *flipper; } *squares; unsigned int nsquares; struct Square *best_dark; struct Square *best_light; int ranks; int files; struct Score score; } *

user_defined_types: struct Board { struct Square *squares; unsigned int nsquares; struct Square *best_dark; struct Square *best_light; int ranks; int files; struct Score score; }

user_defined_types: struct Square { unsigned int name; unsigned int rank; unsigned int file; struct Score score; enum Disk disk; char flipping; struct Flipper *flipper; }


decompiled_code:
void *__fastcall oth_camera_init(__int64 a1)
{
void *v1; // rax
void *v2; // rbx

v1 = calloc(1uLL, 0x50uLL);
v2 = v1;
if ( v1 )
oth_camera_reset((__int64)v1, a1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
void *v1; // rax
void *v2; // rbx

v1 = calloc(1uLL, 0x50uLL);
v2 = v1;
if ( v1 )
func2((__int64)v1, a1);
return v2;
}

original_code:
Camera*
oth_camera_init(Board* board, int *argc, char **argv)
{
        Camera* camera = (Camera*) calloc(1, sizeof(Camera));
        if (!camera)
                return ((void *)0);
        oth_camera_reset(camera, board);
        return camera;
}

canonical_original_code:
struct Camera *oth_camera_init(struct Board *board, int *argc, char **argv)
{
        struct Camera *camera = (Camera*) calloc(1, sizeof(Camera));
        if (!camera)
                return ((void *)0);
        oth_camera_reset(camera, board);
        return camera;
}

variable_types:
argc
int *

return_type: struct Camera { struct { double fov; } frustum; struct { float v; } angle; struct { float x; } radius; struct { float x; } eye; struct { float x; } at; struct { float x; } up; } *

user_defined_types: struct Score { unsigned int blacks; unsigned int whites; }

user_defined_types: struct Flipper { struct { float x; } translation; struct { float a; } rotation; float ambient[4]; float diffuse[4]; float specular[4]; }


decompiled_code:
void __fastcall oth_camera_move_up(float *a1)
{
float v1; // xmm0_4

v1 = a1[6] + 1.0;
if ( v1 <= 0.0 )
{
v1 = 0.0;
}
else if ( v1 >= 89.0 )
{
v1 = *(float *)&LC8;
}
a1[6] = v1;
oth_camera_update(a1);
}

original_code:
void
oth_camera_move_up(Camera* camera)
{
        camera->angle.v += 1;
        if (0 == 0 && 89 == 360)
        {
                if (camera->angle.v > 360)
                        camera->angle.v -= 360;
        }
        else
        {
                camera->angle.v =
                        ( (0) < (camera->angle.v) ? ( (camera->angle.v) < (89) ? (camera->angle.v) : (89) ) : (0) );
        }
        oth_camera_update(camera);
}

canonical_original_code:
void oth_camera_move_up(struct Camera *camera)
{
        camera->angle.v += 1;
        if (0 == 0 && 89 == 360)
        {
                if (camera->angle.v > 360)
                        camera->angle.v -= 360;
        }
        else
        {
                camera->angle.v =
                        ( (0) < (camera->angle.v) ? ( (camera->angle.v) < (89) ? (camera->angle.v) : (89) ) : (0) );
        }
        oth_camera_update(camera);
}


decompiled_code:
void __fastcall oth_camera_move_down(float *a1)
{
float v1; // xmm0_4

v1 = a1[6] - 1.0;
if ( v1 <= 0.0 )
{
v1 = 0.0;
}
else if ( v1 >= 89.0 )
{
v1 = *(float *)&LC8;
}
a1[6] = v1;
oth_camera_update(a1);
}

original_code:
void
oth_camera_move_down(Camera* camera)
{
        camera->angle.v -= 1;
        if (0 == 0 && 89 == 360)
        {
                if (camera->angle.v < 0)
                        camera->angle.v += 360;
        }
        else
        {
                camera->angle.v =
                        ( (0) < (camera->angle.v) ? ( (camera->angle.v) < (89) ? (camera->angle.v) : (89) ) : (0) );
        }
        oth_camera_update(camera);
}

canonical_original_code:
void oth_camera_move_down(struct Camera *camera)
{
        camera->angle.v -= 1;
        if (0 == 0 && 89 == 360)
        {
                if (camera->angle.v < 0)
                        camera->angle.v += 360;
        }
        else
        {
                camera->angle.v =
                        ( (0) < (camera->angle.v) ? ( (camera->angle.v) < (89) ? (camera->angle.v) : (89) ) : (0) );
        }
        oth_camera_update(camera);
}


decompiled_code:
void __fastcall oth_camera_move_left(float *a1)
{
float v1; // xmm0_4

v1 = (float)((float)(0.0 * a1[6]) + 1.0) + a1[7];
if ( v1 > 360.0 )
v1 = v1 - 360.0;
a1[7] = v1;
oth_camera_update(a1);
}

original_code:
void
oth_camera_move_left(Camera* camera)
{
        camera->angle.h +=
                ((10 -
                  1) / 89) *
                camera->angle.v + 1;
        if (0 == 0 && 360 == 360)
        {
                if (camera->angle.h > 360)
                        camera->angle.h -= 360;
        }
        else
        {
                camera->angle.h =
                        ( (0) < (camera->angle.h) ? ( (camera->angle.h) < (360) ? (camera->angle.h) : (360) ) : (0) );
        }
        oth_camera_update(camera);
}

canonical_original_code:
void oth_camera_move_left(struct Camera *camera)
{
        camera->angle.h +=
                ((10 -
                  1) / 89) *
                camera->angle.v + 1;
        if (0 == 0 && 360 == 360)
        {
                if (camera->angle.h > 360)
                        camera->angle.h -= 360;
        }
        else
        {
                camera->angle.h =
                        ( (0) < (camera->angle.h) ? ( (camera->angle.h) < (360) ? (camera->angle.h) : (360) ) : (0) );
        }
        oth_camera_update(camera);
}


decompiled_code:
void __fastcall oth_camera_move_right(float *a1)
{
float v1; // xmm0_4

v1 = a1[7] - (float)((float)(0.0 * a1[6]) + 1.0);
if ( v1 < 0.0 )
v1 = v1 + 360.0;
a1[7] = v1;
oth_camera_update(a1);
}

original_code:
void
oth_camera_move_right(Camera* camera)
{
        camera->angle.h -=
                ((10 -
                  1) / 89) *
                camera->angle.v + 1;
        if (0 == 0 && 360 == 360)
        {
                if (camera->angle.h < 0)
                        camera->angle.h += 360;
        }
        else
        {
                camera->angle.h =
                        ( (0) < (camera->angle.h) ? ( (camera->angle.h) < (360) ? (camera->angle.h) : (360) ) : (0) );
        }
        oth_camera_update(camera);
}

canonical_original_code:
void oth_camera_move_right(struct Camera *camera)
{
        camera->angle.h -=
                ((10 -
                  1) / 89) *
                camera->angle.v + 1;
        if (0 == 0 && 360 == 360)
        {
                if (camera->angle.h < 0)
                        camera->angle.h += 360;
        }
        else
        {
                camera->angle.h =
                        ( (0) < (camera->angle.h) ? ( (camera->angle.h) < (360) ? (camera->angle.h) : (360) ) : (0) );
        }
        oth_camera_update(camera);
}


decompiled_code:
double __fastcall oth_camera_frustum_fov(__int64 a1)
{
return *(double *)a1;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1)
{
return *(double *)a1;
}

original_code:
double
oth_camera_frustum_fov(Camera* camera)
{
        return camera->frustum.fov;
}

canonical_original_code:
double oth_camera_frustum_fov(struct Camera *camera)
{
        return camera->frustum.fov;
}

return_type: double


decompiled_code:
double __fastcall oth_camera_frustum_close(__int64 a1)
{
return *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func9(__int64 a1)
{
return *(double *)(a1 + 8);
}

original_code:
double
oth_camera_frustum_close(Camera* camera)
{
        return camera->frustum.close;
}

canonical_original_code:
double oth_camera_frustum_close(struct Camera *camera)
{
        return camera->frustum.close;
}


decompiled_code:
double __fastcall oth_camera_frustum_distant(__int64 a1)
{
return *(double *)(a1 + 16);
}

canonical_decompiled_code:
double __fastcall func10(__int64 a1)
{
return *(double *)(a1 + 16);
}

original_code:
double
oth_camera_frustum_distant(Camera* camera)
{
        return camera->frustum.distant;
}

canonical_original_code:
double oth_camera_frustum_distant(struct Camera *camera)
{
        return camera->frustum.distant;
}


decompiled_code:
float __fastcall oth_camera_angle_v(__int64 a1)
{
return *(float *)(a1 + 24);
}

canonical_decompiled_code:
float __fastcall func11(__int64 a1)
{
return *(float *)(a1 + 24);
}

original_code:
float
oth_camera_angle_v(Camera* camera)
{
        return camera->angle.v;
}

canonical_original_code:
float oth_camera_angle_v(struct Camera *camera)
{
        return camera->angle.v;
}

return_type: float


decompiled_code:
float __fastcall oth_camera_angle_h(__int64 a1)
{
return *(float *)(a1 + 28);
}

canonical_decompiled_code:
float __fastcall func12(__int64 a1)
{
return *(float *)(a1 + 28);
}

original_code:
float
oth_camera_angle_h(Camera* camera)
{
        return camera->angle.h;
}

canonical_original_code:
float oth_camera_angle_h(struct Camera *camera)
{
        return camera->angle.h;
}


decompiled_code:
float __fastcall oth_camera_radius_x(__int64 a1)
{
return *(float *)(a1 + 32);
}

canonical_decompiled_code:
float __fastcall func13(__int64 a1)
{
return *(float *)(a1 + 32);
}

original_code:
float
oth_camera_radius_x(Camera* camera)
{
        return camera->radius.x;
}

canonical_original_code:
float oth_camera_radius_x(struct Camera *camera)
{
        return camera->radius.x;
}


decompiled_code:
float __fastcall oth_camera_radius_y(__int64 a1)
{
return *(float *)(a1 + 36);
}

canonical_decompiled_code:
float __fastcall func14(__int64 a1)
{
return *(float *)(a1 + 36);
}

original_code:
float
oth_camera_radius_y(Camera* camera)
{
        return camera->radius.y;
}

canonical_original_code:
float oth_camera_radius_y(struct Camera *camera)
{
        return camera->radius.y;
}


decompiled_code:
float __fastcall oth_camera_radius_z(__int64 a1)
{
return *(float *)(a1 + 40);
}

canonical_decompiled_code:
float __fastcall func15(__int64 a1)
{
return *(float *)(a1 + 40);
}

original_code:
float
oth_camera_radius_z(Camera* camera)
{
        return camera->radius.z;
}

canonical_original_code:
float oth_camera_radius_z(struct Camera *camera)
{
        return camera->radius.z;
}


decompiled_code:
float __fastcall oth_camera_eye_x(__int64 a1)
{
return *(float *)(a1 + 44);
}

canonical_decompiled_code:
float __fastcall func16(__int64 a1)
{
return *(float *)(a1 + 44);
}

original_code:
float
oth_camera_eye_x(Camera* camera)
{
        return camera->eye.x;
}

canonical_original_code:
float oth_camera_eye_x(struct Camera *camera)
{
        return camera->eye.x;
}


decompiled_code:
float __fastcall oth_camera_eye_y(__int64 a1)
{
return *(float *)(a1 + 48);
}

canonical_decompiled_code:
float __fastcall func17(__int64 a1)
{
return *(float *)(a1 + 48);
}

original_code:
float
oth_camera_eye_y(Camera* camera)
{
        return camera->eye.y;
}

canonical_original_code:
float oth_camera_eye_y(struct Camera *camera)
{
        return camera->eye.y;
}


decompiled_code:
float __fastcall oth_camera_eye_z(__int64 a1)
{
return *(float *)(a1 + 52);
}

canonical_decompiled_code:
float __fastcall func18(__int64 a1)
{
return *(float *)(a1 + 52);
}

original_code:
float
oth_camera_eye_z(Camera* camera)
{
        return camera->eye.z;
}

canonical_original_code:
float oth_camera_eye_z(struct Camera *camera)
{
        return camera->eye.z;
}


decompiled_code:
float __fastcall oth_camera_at_x(__int64 a1)
{
return *(float *)(a1 + 56);
}

canonical_decompiled_code:
float __fastcall func19(__int64 a1)
{
return *(float *)(a1 + 56);
}

original_code:
float
oth_camera_at_x(Camera* camera)
{
        return camera->at.x;
}

canonical_original_code:
float oth_camera_at_x(struct Camera *camera)
{
        return camera->at.x;
}


decompiled_code:
float __fastcall oth_camera_at_y(__int64 a1)
{
return *(float *)(a1 + 60);
}

canonical_decompiled_code:
float __fastcall func20(__int64 a1)
{
return *(float *)(a1 + 60);
}

original_code:
float
oth_camera_at_y(Camera* camera)
{
        return camera->at.y;
}

canonical_original_code:
float oth_camera_at_y(struct Camera *camera)
{
        return camera->at.y;
}


decompiled_code:
float __fastcall oth_camera_at_z(__int64 a1)
{
return *(float *)(a1 + 64);
}

canonical_decompiled_code:
float __fastcall func21(__int64 a1)
{
return *(float *)(a1 + 64);
}

original_code:
float
oth_camera_at_z(Camera* camera)
{
        return camera->at.z;
}

canonical_original_code:
float oth_camera_at_z(struct Camera *camera)
{
        return camera->at.z;
}


decompiled_code:
float __fastcall oth_camera_up_x(__int64 a1)
{
return *(float *)(a1 + 68);
}

canonical_decompiled_code:
float __fastcall func22(__int64 a1)
{
return *(float *)(a1 + 68);
}

original_code:
float
oth_camera_up_x(Camera* camera)
{
        return camera->up.x;
}

canonical_original_code:
float oth_camera_up_x(struct Camera *camera)
{
        return camera->up.x;
}


decompiled_code:
float __fastcall oth_camera_up_y(__int64 a1)
{
return *(float *)(a1 + 72);
}

canonical_decompiled_code:
float __fastcall func23(__int64 a1)
{
return *(float *)(a1 + 72);
}

original_code:
float
oth_camera_up_y(Camera* camera)
{
        return camera->up.y;
}

canonical_original_code:
float oth_camera_up_y(struct Camera *camera)
{
        return camera->up.y;
}


decompiled_code:
float __fastcall oth_camera_up_z(__int64 a1)
{
return *(float *)(a1 + 76);
}

canonical_decompiled_code:
float __fastcall func24(__int64 a1)
{
return *(float *)(a1 + 76);
}

original_code:
float
oth_camera_up_z(Camera* camera)
{
        return camera->up.z;
}

canonical_original_code:
float oth_camera_up_z(struct Camera *camera)
{
        return camera->up.z;
}


decompiled_code:
void oth_flippers_free()
{
if ( flippers )
free(flippers);
}

canonical_decompiled_code:
void func2()
{
if ( flippers )
free(flippers);
}

original_code:
void
oth_flippers_free()
{
        if (flippers)
                free(flippers);
}


decompiled_code:
void oth_flippers_reset()
{
__int64 v0; // r12
int v1; // er13
__int64 i; // rbx
int v3; // eax
_DWORD *v4; // rax
__int64 v5; // rbp
_DWORD *v6; // rax

if ( nflippers > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
v6 = (char *)flippers + v0;
*v6 = 0;
v6[3] = 0;
v6[6] = LC1;
for ( i = 0LL; i != 3; ++i )
{
v3 = oth_shift_current();
switch ( v3 )
{
case 2:
*(_DWORD *)((char *)flippers + 4 * (int)i + v0 + 44) = dark_diffuse[i];
break;
case 3:
v4 = flippers;
v5 = (int)i + 8LL;
*((_DWORD *)flippers + v5 + 3) = light_diffuse[i];
v4[v5 + 22] = dark_diffuse[i];
break;
case 1:
*(_DWORD *)((char *)flippers + 4 * (int)i + v0 + 44) = light_diffuse[i];
break;
}
}
++v1;
v0 += 76LL;
}
while ( nflippers > v1 );
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // r12
int v1; // er13
__int64 i; // rbx
int v3; // eax
_DWORD *v4; // rax
__int64 v5; // rbp
_DWORD *v6; // rax

if ( nflippers > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
v6 = (char *)flippers + v0;
*v6 = 0;
v6[3] = 0;
v6[6] = LC1;
for ( i = 0LL; i != 3; ++i )
{
v3 = oth_shift_current();
switch ( v3 )
{
case 2:
*(_DWORD *)((char *)flippers + 4 * (int)i + v0 + 44) = dark_diffuse[i];
break;
case 3:
v4 = flippers;
v5 = (int)i + 8LL;
*((_DWORD *)flippers + v5 + 3) = light_diffuse[i];
v4[v5 + 22] = dark_diffuse[i];
break;
case 1:
*(_DWORD *)((char *)flippers + 4 * (int)i + v0 + 44) = light_diffuse[i];
break;
}
}
++v1;
v0 += 76LL;
}
while ( nflippers > v1 );
}
}

original_code:
void
oth_flippers_reset()
{
        register int i, j;
        for (i = 0; i < nflippers; ++i)
        {
                flippers[i].translation.x = 0.0f;
                flippers[i].rotation.a = 0.0f;
                flippers[i].rotation.z = 1.0f;
                for (j = 0; j < 3; ++j)
                {
                        switch (oth_shift_current()) {
                                case INITIAL:
                                        break;
                                case DARK:
                                        flippers[i].diffuse[j] = light_diffuse[j];
                                        break;
                                case LIGHT:
                                        flippers[i].diffuse[j] = dark_diffuse[j];
                                        break;
                                case NONE:
                                        flippers[0].diffuse[j] = light_diffuse[j];
                                        flippers[1].diffuse[j] = dark_diffuse[j];
                                        break;
                        }
                }
        }
}

canonical_original_code:
void oth_flippers_reset()
{
        register int i; register int j;
        for (i = 0; i < nflippers; ++i)
        {
                flippers[i].translation.x = 0.0f;
                flippers[i].rotation.a = 0.0f;
                flippers[i].rotation.z = 1.0f;
                for (j = 0; j < 3; ++j)
                {
                        switch (oth_shift_current()) {
                                case INITIAL:
                                        break;
                                case DARK:
                                        flippers[i].diffuse[j] = light_diffuse[j];
                                        break;
                                case LIGHT:
                                        flippers[i].diffuse[j] = dark_diffuse[j];
                                        break;
                                case NONE:
                                        flippers[0].diffuse[j] = light_diffuse[j];
                                        flippers[1].diffuse[j] = dark_diffuse[j];
                                        break;
                        }
                }
        }
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 oth_flippers_update()
{
__int64 v0; // rdi
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // r12
int v4; // ebp
float v5; // xmm0_4
float v6; // xmm0_4
__int64 k; // rax
float *v8; // rbx
int v9; // eax
float v10; // xmm0_4
float v11; // xmm0_4
__int64 l; // rax
float *v13; // rdx
float v14; // xmm0_4
float v15; // xmm0_4
__int64 i; // rax
float v17; // xmm0_4
float v18; // xmm0_4
__int64 j; // rax

if ( j_0 == -1 )
j_0 = nflippers - 1;
v0 = (unsigned int)nflippers;
v1 = (unsigned int)j_0;
if ( *((float *)flippers + 19 * (nflippers - j_0) - 16) >= (float)(180 / nflippers) )
{
if ( j_0 <= 0 )
LODWORD(v1) = 1;
v1 = (unsigned int)(v1 - 1);
j_0 = v1;
}
if ( (unsigned int)oth_shift_current((unsigned int)nflippers, v1, (unsigned int)(180 % nflippers)) == 3 )
{
last_used_flipper = 1;
v13 = (float *)flippers;
v14 = *(float *)flippers + *(float *)stepper;
if ( v14 >= 1.0 )
v14 = *(float *)&LC1;
*(float *)flippers = v14;
v15 = v13[3] + *(float *)&dword_7AC;
if ( v15 >= 180.0 )
v15 = *(float *)&LC7;
v13[3] = v15;
for ( i = 11LL; i != 14; ++i )
v13[i] = fmaxf(v13[i] - *(float *)&stepper[i], *(float *)&dark_diffuse[i - 11]);
v17 = v13[19] + *(float *)stepper;
if ( v17 >= 1.0 )
v17 = *(float *)&LC1;
v13[19] = v17;
v18 = v13[22] + *(float *)&dword_7AC;
if ( v18 >= 180.0 )
v18 = *(float *)&LC7;
v13[22] = v18;
for ( j = 0LL; j != 3; ++j )
v13[j + 30] = fminf(v13[j + 30] + *(float *)&dword_7CC[j], *(float *)&light_diffuse[j]);
}
else if ( nflippers - j_0 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
v8 = (float *)((char *)flippers + v3);
v9 = oth_shift_current(v0, v1, v2);
if ( v9 == 1 )
{
v5 = *v8 + *(float *)stepper;
if ( v5 >= 1.0 )
v5 = *(float *)&LC1;
*v8 = v5;
v6 = v8[3] + *(float *)&dword_7AC;
if ( v6 >= 180.0 )
v6 = *(float *)&LC7;
v8[3] = v6;
for ( k = 11LL; k != 14; ++k )
v8[k] = fmaxf(v8[k] - *(float *)&stepper[k], *(float *)&dark_diffuse[k - 11]);
}
else if ( v9 == 2 )
{
v10 = *v8 + *(float *)stepper;
if ( v10 >= 1.0 )
v10 = *(float *)&LC1;
*v8 = v10;
v11 = v8[3] + *(float *)&dword_7AC;
if ( v11 >= 180.0 )
v11 = *(float *)&LC7;
v8[3] = v11;
for ( l = 11LL; l != 14; ++l )
v8[l] = fminf(v8[l] + *(float *)&stepper[l], *(float *)&light_diffuse[l - 11]);
}
++v4;
v3 += 76LL;
}
while ( nflippers - j_0 > v4 );
}
if ( *((float *)flippers + 19 * last_used_flipper + 3) >= 180.0 )
{
j_0 = -1;
oth_shift_reset(current_board);
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // r12
int v4; // ebp
float v5; // xmm0_4
float v6; // xmm0_4
__int64 k; // rax
float *v8; // rbx
int v9; // eax
float v10; // xmm0_4
float v11; // xmm0_4
__int64 l; // rax
float *v13; // rdx
float v14; // xmm0_4
float v15; // xmm0_4
__int64 i; // rax
float v17; // xmm0_4
float v18; // xmm0_4
__int64 j; // rax

if ( j_0 == -1 )
j_0 = nflippers - 1;
v0 = (unsigned int)nflippers;
v1 = (unsigned int)j_0;
if ( *((float *)flippers + 19 * (nflippers - j_0) - 16) >= (float)(180 / nflippers) )
{
if ( j_0 <= 0 )
LODWORD(v1) = 1;
v1 = (unsigned int)(v1 - 1);
j_0 = v1;
}
if ( (unsigned int)oth_shift_current((unsigned int)nflippers, v1, (unsigned int)(180 % nflippers)) == 3 )
{
last_used_flipper = 1;
v13 = (float *)flippers;
v14 = *(float *)flippers + *(float *)stepper;
if ( v14 >= 1.0 )
v14 = *(float *)&LC1;
*(float *)flippers = v14;
v15 = v13[3] + *(float *)&dword_7AC;
if ( v15 >= 180.0 )
v15 = *(float *)&LC7;
v13[3] = v15;
for ( i = 11LL; i != 14; ++i )
v13[i] = fmaxf(v13[i] - *(float *)&stepper[i], *(float *)&dark_diffuse[i - 11]);
v17 = v13[19] + *(float *)stepper;
if ( v17 >= 1.0 )
v17 = *(float *)&LC1;
v13[19] = v17;
v18 = v13[22] + *(float *)&dword_7AC;
if ( v18 >= 180.0 )
v18 = *(float *)&LC7;
v13[22] = v18;
for ( j = 0LL; j != 3; ++j )
v13[j + 30] = fminf(v13[j + 30] + *(float *)&dword_7CC[j], *(float *)&light_diffuse[j]);
}
else if ( nflippers - j_0 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
v8 = (float *)((char *)flippers + v3);
v9 = oth_shift_current(v0, v1, v2);
if ( v9 == 1 )
{
v5 = *v8 + *(float *)stepper;
if ( v5 >= 1.0 )
v5 = *(float *)&LC1;
*v8 = v5;
v6 = v8[3] + *(float *)&dword_7AC;
if ( v6 >= 180.0 )
v6 = *(float *)&LC7;
v8[3] = v6;
for ( k = 11LL; k != 14; ++k )
v8[k] = fmaxf(v8[k] - *(float *)&stepper[k], *(float *)&dark_diffuse[k - 11]);
}
else if ( v9 == 2 )
{
v10 = *v8 + *(float *)stepper;
if ( v10 >= 1.0 )
v10 = *(float *)&LC1;
*v8 = v10;
v11 = v8[3] + *(float *)&dword_7AC;
if ( v11 >= 180.0 )
v11 = *(float *)&LC7;
v8[3] = v11;
for ( l = 11LL; l != 14; ++l )
v8[l] = fminf(v8[l] + *(float *)&stepper[l], *(float *)&light_diffuse[l - 11]);
}
++v4;
v3 += 76LL;
}
while ( nflippers - j_0 > v4 );
}
if ( *((float *)flippers + 19 * last_used_flipper + 3) >= 180.0 )
{
j_0 = -1;
oth_shift_reset(current_board);
}
return glutPostRedisplay();
}

original_code:
void
oth_flippers_update(void)
{
        Flipper *p;
        int flipper, i;
        static int j = -1;
        if (j == -1)
        {
                j = nflippers - 1;
        }
        if (flippers[nflippers - j - 1].rotation.a >= (180 / nflippers))
        {
                j = (j > 0) ? j - 1 : 0;
        }
        if (oth_shift_current() != NONE)
        {
                for (flipper = 0; flipper < nflippers - j; ++flipper)
                {
                        p = &flippers[flipper];
                        switch (oth_shift_current())
                        {
                        case DARK:
                                p->translation.x =
                                        ( (p->translation.x + stepper.translation.x) < (((unsigned)1)) ? (p->translation.x + stepper.translation.x) : (((unsigned)1)) );
                                p->rotation.a =
                                        ( (p->rotation.a + stepper.rotation.a) < (180) ? (p->rotation.a + stepper.rotation.a) : (180) );
                                for (i = 0; i < 3; ++i)
                                {
                                        p->diffuse[i] =
                                                ( (p->diffuse[i] - stepper.diffuse[i]) > (dark_diffuse[i]) ? (p->diffuse[i] - stepper.diffuse[i]) : (dark_diffuse[i]) );
                                }
                                break;
                        case LIGHT:
                                p->translation.x =
                                        ( (p->translation.x + stepper.translation.x) < (((unsigned)1)) ? (p->translation.x + stepper.translation.x) : (((unsigned)1)) );
                                p->rotation.a =
                                        ( (p->rotation.a + stepper.rotation.a) < (180) ? (p->rotation.a + stepper.rotation.a) : (180) );
                                for (i = 0; i < 3; ++i)
                                {
                                        p->diffuse[i] =
                                                ( (p->diffuse[i] + stepper.diffuse[i]) < (light_diffuse[i]) ? (p->diffuse[i] + stepper.diffuse[i]) : (light_diffuse[i]) );
                                }
                                break;
                        }
                }
        }
        else
        {
                last_used_flipper = 1;
                flippers[0].translation.x =
                        ( (flippers[0].translation.x + stepper.translation.x) < (((unsigned)1)) ? (flippers[0].translation.x + stepper.translation.x) : (((unsigned)1)) );
                flippers[0].rotation.a =
                        ( (flippers[0].rotation.a + stepper.rotation.a) < (180) ? (flippers[0].rotation.a + stepper.rotation.a) : (180) );
                for (i = 0; i < 3; ++i)
                {
                        flippers[0].diffuse[i] =
                                ( (flippers[0].diffuse[i] - stepper.diffuse[i]) > (dark_diffuse[i]) ? (flippers[0].diffuse[i] - stepper.diffuse[i]) : (dark_diffuse[i]) );
                }
                flippers[1].translation.x =
                        ( (flippers[1].translation.x + stepper.translation.x) < (((unsigned)1)) ? (flippers[1].translation.x + stepper.translation.x) : (((unsigned)1)) );
                flippers[1].rotation.a =
                        ( (flippers[1].rotation.a + stepper.rotation.a) < (180) ? (flippers[1].rotation.a + stepper.rotation.a) : (180) );
                for (i = 0; i < 3; ++i)
                {
                        flippers[1].diffuse[i] =
                                ( (flippers[1].diffuse[i] + stepper.diffuse[i]) < (light_diffuse[i]) ? (flippers[1].diffuse[i] + stepper.diffuse[i]) : (light_diffuse[i]) );
                }
        }
        if (flippers[last_used_flipper].rotation.a >= 180)
        {
                j = -1;
                oth_shift_reset(current_board);
        }
        glutPostRedisplay();
}

canonical_original_code:
void oth_flippers_update()
{
        struct Flipper *p;
        int flipper; int i;
        static int j = -1;
        if (j == -1)
        {
                j = nflippers - 1;
        }
        if (flippers[nflippers - j - 1].rotation.a >= (180 / nflippers))
        {
                j = (j > 0) ? j - 1 : 0;
        }
        if (oth_shift_current() != NONE)
        {
                for (flipper = 0; flipper < nflippers - j; ++flipper)
                {
                        p = &flippers[flipper];
                        switch (oth_shift_current())
                        {
                        case DARK:
                                p->translation.x =
                                        ( (p->translation.x + stepper.translation.x) < (((unsigned int)1)) ? (p->translation.x + stepper.translation.x) : (((unsigned int)1)) );
                                p->rotation.a =
                                        ( (p->rotation.a + stepper.rotation.a) < (180) ? (p->rotation.a + stepper.rotation.a) : (180) );
                                for (i = 0; i < 3; ++i)
                                {
                                        p->diffuse[i] =
                                                ( (p->diffuse[i] - stepper.diffuse[i]) > (dark_diffuse[i]) ? (p->diffuse[i] - stepper.diffuse[i]) : (dark_diffuse[i]) );
                                }
                                break;
                        case LIGHT:
                                p->translation.x =
                                        ( (p->translation.x + stepper.translation.x) < (((unsigned int)1)) ? (p->translation.x + stepper.translation.x) : (((unsigned int)1)) );
                                p->rotation.a =
                                        ( (p->rotation.a + stepper.rotation.a) < (180) ? (p->rotation.a + stepper.rotation.a) : (180) );
                                for (i = 0; i < 3; ++i)
                                {
                                        p->diffuse[i] =
                                                ( (p->diffuse[i] + stepper.diffuse[i]) < (light_diffuse[i]) ? (p->diffuse[i] + stepper.diffuse[i]) : (light_diffuse[i]) );
                                }
                                break;
                        }
                }
        }
        else
        {
                last_used_flipper = 1;
                flippers[0].translation.x =
                        ( (flippers[0].translation.x + stepper.translation.x) < (((unsigned int)1)) ? (flippers[0].translation.x + stepper.translation.x) : (((unsigned int)1)) );
                flippers[0].rotation.a =
                        ( (flippers[0].rotation.a + stepper.rotation.a) < (180) ? (flippers[0].rotation.a + stepper.rotation.a) : (180) );
                for (i = 0; i < 3; ++i)
                {
                        flippers[0].diffuse[i] =
                                ( (flippers[0].diffuse[i] - stepper.diffuse[i]) > (dark_diffuse[i]) ? (flippers[0].diffuse[i] - stepper.diffuse[i]) : (dark_diffuse[i]) );
                }
                flippers[1].translation.x =
                        ( (flippers[1].translation.x + stepper.translation.x) < (((unsigned int)1)) ? (flippers[1].translation.x + stepper.translation.x) : (((unsigned int)1)) );
                flippers[1].rotation.a =
                        ( (flippers[1].rotation.a + stepper.rotation.a) < (180) ? (flippers[1].rotation.a + stepper.rotation.a) : (180) );
                for (i = 0; i < 3; ++i)
                {
                        flippers[1].diffuse[i] =
                                ( (flippers[1].diffuse[i] + stepper.diffuse[i]) < (light_diffuse[i]) ? (flippers[1].diffuse[i] + stepper.diffuse[i]) : (light_diffuse[i]) );
                }
        }
        if (flippers[last_used_flipper].rotation.a >= 180)
        {
                j = -1;
                oth_shift_reset(current_board);
        }
        glutPostRedisplay();
}

variable_types: struct Flipper { struct { float x; } translation; struct { float a; } rotation; float ambient[4]; float diffuse[4]; float specular[4]; } *

variable_types: flipper int


decompiled_code:
__int64 __fastcall oth_flippers_flip_disks(__int64 a1, __int64 a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
last_used_flipper = 0;
return oth_board_flip_disks(a1, a2, _oth_flippers_flip_disks, v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
last_used_flipper = 0;
return oth_board_flip_disks(a1, a2, _oth_flippers_flip_disks, v3);
}

original_code:
void
oth_flippers_flip_disks(Board* board, Square* square)
{
    int flipper = 0;
    last_used_flipper = 0;
    oth_board_flip_disks(board, square, __oth_flippers_flip_disks, &flipper);
}

canonical_original_code:
void oth_flippers_flip_disks(struct Board *board, struct Square *square)
{
    int flipper = 0;
    last_used_flipper = 0;
    oth_board_flip_disks(board, square, __oth_flippers_flip_disks, &flipper);
}

variable_types:
square
struct Square *


decompiled_code:
__int64 __fastcall oth_flippers_game_over(__int64 a1)
{
int v2[4]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = *(_DWORD *)(a1 + 40);
v2[1] = *(_DWORD *)(a1 + 44);
oth_flippers_reset();
return oth_board_for_each_square(a1, _oth_flippers_game_over, v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v2[4]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = *(_DWORD *)(a1 + 40);
v2[1] = *(_DWORD *)(a1 + 44);
func3();
return oth_board_for_each_square(a1, _oth_flippers_game_over, v2);
}

original_code:
void
oth_flippers_game_over(Board* board) {
        Score score;
        score.blacks = board->score.blacks;
        score.whites = board->score.whites;
        oth_flippers_reset();
        oth_board_for_each_square(board, __oth_flippers_game_over, &score);
}

canonical_original_code:
void oth_flippers_game_over(struct Board *board) {
        struct Score score;
        score.blacks = board->score.blacks;
        score.whites = board->score.whites;
        oth_flippers_reset();
        oth_board_for_each_square(board, __oth_flippers_game_over, &score);
}

variable_types: struct Score { unsigned int blacks; unsigned int whites; }


decompiled_code:
__int64 __fastcall oth_shift_init(int *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
char v4; // si
time_t v5; // rdi

if ( *a1 <= 1 )
goto LABEL_11;
v2 = a2 + 8;
v3 = a2 + 8LL * (unsigned int)(*a1 - 2) + 16;
v4 = 0;
v5 = 1LL;
do
{
if ( **(_BYTE **)v2 == 45 && *(_BYTE *)(*(_QWORD *)v2 + 1LL) == 50 )
v4 = 1;
v2 += 8LL;
}
while ( v2 != v3 );
if ( v4 )
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_user;
_shift_unset_dark = (__int64)_shift_unset_user;
_shift_set_light = (__int64)_shift_set_user;
_shift_unset_light = (__int64)_shift_unset_user;
}
else
{
LABEL_11:
v5 = time(0LL);
srand(v5);
if ( (rand() & 1) != 0 )
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_user;
_shift_unset_dark = (__int64)_shift_unset_user;
_shift_set_light = (__int64)_shift_set_comp;
_shift_unset_light = (__int64)_shift_unset_comp;
}
else
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_comp;
_shift_unset_dark = (__int64)_shift_unset_comp;
_shift_set_light = (__int64)_shift_set_user;
_shift_unset_light = (__int64)_shift_unset_user;
}
}
shift = 1;
_shift_set_dark(v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
char v4; // si
time_t v5; // rdi

if ( *a1 <= 1 )
goto LABEL_11;
v2 = a2 + 8;
v3 = a2 + 8LL * (unsigned int)(*a1 - 2) + 16;
v4 = 0;
v5 = 1LL;
do
{
if ( **(_BYTE **)v2 == 45 && *(_BYTE *)(*(_QWORD *)v2 + 1LL) == 50 )
v4 = 1;
v2 += 8LL;
}
while ( v2 != v3 );
if ( v4 )
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_user;
_shift_unset_dark = (__int64)_shift_unset_user;
_shift_set_light = (__int64)_shift_set_user;
_shift_unset_light = (__int64)_shift_unset_user;
}
else
{
LABEL_11:
v5 = time(0LL);
srand(v5);
if ( (rand() & 1) != 0 )
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_user;
_shift_unset_dark = (__int64)_shift_unset_user;
_shift_set_light = (__int64)_shift_set_comp;
_shift_unset_light = (__int64)_shift_unset_comp;
}
else
{
_shift_set_dark = (__int64 (__fastcall *)(_QWORD))_shift_set_comp;
_shift_unset_dark = (__int64)_shift_unset_comp;
_shift_set_light = (__int64)_shift_set_user;
_shift_unset_light = (__int64)_shift_unset_user;
}
}
shift = 1;
_shift_set_dark(v5);
return 1LL;
}

original_code:
char
oth_shift_init(int *argc, char **argv)
{
        int i;
        char h2h = (char) 0;
        for (i = 1; i < *argc; ++i)
        {
                switch (argv[i][0])
                {
                case '-':
                        switch (argv[i][1])
                        {
                        case '2':
                                h2h = (char) 1;
                                break;
                        }
                        break;
                }
        }
        if (h2h)
        {
                __shift_set_dark = __shift_set_user;
                __shift_unset_dark = __shift_unset_user;
                __shift_set_light = __shift_set_user;
                __shift_unset_light = __shift_unset_user;
        }
        else
        {
                srand((unsigned)time(((void *)0)));
                if (rand() % 2)
                {
                        __shift_set_dark = __shift_set_user;
                        __shift_unset_dark = __shift_unset_user;
                        __shift_set_light = __shift_set_comp;
                        __shift_unset_light = __shift_unset_comp;
                }
                else
                {
                        __shift_set_dark = __shift_set_comp;
                        __shift_unset_dark = __shift_unset_comp;
                        __shift_set_light = __shift_set_user;
                        __shift_unset_light = __shift_unset_user;
                }
        }
        shift = DARK;
        __shift_set_dark();
        return (char) 1;
}

canonical_original_code:
char oth_shift_init(int *argc, char **argv)
{
        int i;
        char h2h = (char) 0;
        for (i = 1; i < *argc; ++i)
        {
                switch (argv[i][0])
                {
                case '-':
                        switch (argv[i][1])
                        {
                        case '2':
                                h2h = (char) 1;
                                break;
                        }
                        break;
                }
        }
        if (h2h)
        {
                __shift_set_dark = __shift_set_user;
                __shift_unset_dark = __shift_unset_user;
                __shift_set_light = __shift_set_user;
                __shift_unset_light = __shift_unset_user;
        }
        else
        {
                srand((unsigned int)time(((void *)0)));
                if (rand() % 2)
                {
                        __shift_set_dark = __shift_set_user;
                        __shift_unset_dark = __shift_unset_user;
                        __shift_set_light = __shift_set_comp;
                        __shift_unset_light = __shift_unset_comp;
                }
                else
                {
                        __shift_set_dark = __shift_set_comp;
                        __shift_unset_dark = __shift_unset_comp;
                        __shift_set_light = __shift_set_user;
                        __shift_unset_light = __shift_unset_user;
                }
        }
        shift = DARK;
        __shift_set_dark();
        return (char) 1;
}

return_type: char


decompiled_code:
void oth_shift_free()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void
oth_shift_free(void)
{
}

canonical_original_code:
void oth_shift_free()
{
}


decompiled_code:
bool __fastcall oth_shift_valid(__int64 a1, _DWORD *a2)
{
bool result; // al

result = 0;
if ( !a2[5] )
{
if ( shift == 1 )
{
if ( !a2[3] )
return result;
}
else if ( shift == 2 )
{
result = 0;
if ( !a2[4] )
return result;
}
result = shift != 3;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1, _DWORD *a2)
{
bool result; // al

result = 0;
if ( !a2[5] )
{
if ( shift == 1 )
{
if ( !a2[3] )
return result;
}
else if ( shift == 2 )
{
result = 0;
if ( !a2[4] )
return result;
}
result = shift != 3;
}
return result;
}

original_code:
char
oth_shift_valid(Board* board, Square* square)
{
        if (square->disk != EMPTY)
                return (char) 0;
        if (shift == DARK && square->score.blacks == 0)
                return (char) 0;
        else if (shift == LIGHT && square->score.whites == 0)
                return (char) 0;
        else if (shift == NONE)
                return (char) 0;
        return (char) 1;
}

canonical_original_code:
char oth_shift_valid(struct Board *board, struct Square *square)
{
        if (square->disk != EMPTY)
                return (char) 0;
        if (shift == DARK && square->score.blacks == 0)
                return (char) 0;
        else if (shift == LIGHT && square->score.whites == 0)
                return (char) 0;
        else if (shift == NONE)
                return (char) 0;
        return (char) 1;
}


decompiled_code:
char __fastcall oth_shift_update(__int64 a1, _DWORD *a2)
{
char result; // al
int v3; // eax

result = oth_shift_valid(a1, a2);
if ( result )
{
v3 = shift;
if ( shift != 1 )
v3 = 2;
a2[5] = v3;
oth_flippers_flip_disks(a1, a2);
if ( shift == 1 )
{
_shift_unset_dark();
}
else if ( shift == 2 )
{
_shift_unset_light();
}
result = glutIdleFunc(&oth_flippers_update);
}
return result;
}

canonical_decompiled_code:
char __fastcall func7(__int64 a1, _DWORD *a2)
{
char result; // al
int v3; // eax

result = func6(a1, a2);
if ( result )
{
v3 = shift;
if ( shift != 1 )
v3 = 2;
a2[5] = v3;
oth_flippers_flip_disks(a1, a2);
if ( shift == 1 )
{
_shift_unset_dark();
}
else if ( shift == 2 )
{
_shift_unset_light();
}
result = glutIdleFunc(&oth_flippers_update);
}
return result;
}

original_code:
void
oth_shift_update(Board* board, Square* square)
{
        if (!oth_shift_valid(board, square))
                return;
        square->disk = (shift == DARK ? BLACK : WHITE);
        oth_flippers_flip_disks(board, square);
        switch (shift)
        {
        case NONE:
                break;
        case DARK:
                __shift_unset_dark();
                break;
        case LIGHT:
                __shift_unset_light();
                break;
        }
        glutIdleFunc(oth_flippers_update);
}

canonical_original_code:
void oth_shift_update(struct Board *board, struct Square *square)
{
        if (!oth_shift_valid(board, square))
                return;
        square->disk = (shift == DARK ? BLACK : WHITE);
        oth_flippers_flip_disks(board, square);
        switch (shift)
        {
        case NONE:
                break;
        case DARK:
                __shift_unset_dark();
                break;
        case LIGHT:
                __shift_unset_light();
                break;
        }
        glutIdleFunc(oth_flippers_update);
}


decompiled_code:
__int64 oth_shift_current()
{
return (unsigned int)shift;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)shift;
}

canonical_original_code:
enum Shift oth_shift_current()
{
    return shift;
}

return_type: enum Shift { INITIAL=0, DARK=1, LIGHT=2, NONE=3 }


decompiled_code:
__int64 __fastcall oth_shift_reset(__int64 a1)
{
glutIdleFunc(0LL);
oth_board_reset(a1);
if ( shift == 1 )
{
if ( *(_QWORD *)(a1 + 24) )
{
shift = 2;
oth_flippers_reset();
return _shift_set_light();
}
if ( *(_QWORD *)(a1 + 16) )
{
oth_flippers_reset();
return _shift_set_dark(a1);
}
goto LABEL_9;
}
if ( shift == 2 )
{
if ( *(_QWORD *)(a1 + 16) )
{
shift = 1;
oth_flippers_reset();
return _shift_set_dark(a1);
}
if ( *(_QWORD *)(a1 + 24) )
{
oth_flippers_reset();
return _shift_set_light();
}
LABEL_9:
shift = 3;
return _oth_shift_game_over(a1);
}
return fwrite("Game Over!\n", 1uLL, 0xBuLL, stderr);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
glutIdleFunc(0LL);
oth_board_reset(a1);
if ( shift == 1 )
{
if ( *(_QWORD *)(a1 + 24) )
{
shift = 2;
oth_flippers_reset();
return _shift_set_light();
}
if ( *(_QWORD *)(a1 + 16) )
{
oth_flippers_reset();
return _shift_set_dark(a1);
}
goto LABEL_9;
}
if ( shift == 2 )
{
if ( *(_QWORD *)(a1 + 16) )
{
shift = 1;
oth_flippers_reset();
return _shift_set_dark(a1);
}
if ( *(_QWORD *)(a1 + 24) )
{
oth_flippers_reset();
return _shift_set_light();
}
LABEL_9:
shift = 3;
return func9(a1);
}
return fwrite("Game Over!\n", 1uLL, 0xBuLL, stderr);
}

original_code:
void
oth_shift_reset(Board* board)
{
        glutIdleFunc(((void *)0));
        oth_board_reset(board);
        if (shift == DARK)
        {
                if (board->best_light)
                {
                        shift = LIGHT;
                        oth_flippers_reset();
                        __shift_set_light();
                }
                else if (board->best_dark)
                {
                        oth_flippers_reset();
                        __shift_set_dark();
                }
                else
                {
                        shift = NONE;
                        __oth_shift_game_over(board);
                }
        }
        else if (shift == LIGHT)
        {
                if (board->best_dark)
                {
                        shift = DARK;
                        oth_flippers_reset();
                        __shift_set_dark();
                }
                else if (board->best_light)
                {
                        oth_flippers_reset();
                        __shift_set_light();
                }
                else
                {
                        shift = NONE;
                        __oth_shift_game_over(board);
                }
        }
        else
        {
                fprintf(stderr, "Game Over!\n");
        }
}

canonical_original_code:
void oth_shift_reset(struct Board *board)
{
        glutIdleFunc(((void *)0));
        oth_board_reset(board);
        if (shift == DARK)
        {
                if (board->best_light)
                {
                        shift = LIGHT;
                        oth_flippers_reset();
                        __shift_set_light();
                }
                else if (board->best_dark)
                {
                        oth_flippers_reset();
                        __shift_set_dark();
                }
                else
                {
                        shift = NONE;
                        __oth_shift_game_over(board);
                }
        }
        else if (shift == LIGHT)
        {
                if (board->best_dark)
                {
                        shift = DARK;
                        oth_flippers_reset();
                        __shift_set_dark();
                }
                else if (board->best_light)
                {
                        oth_flippers_reset();
                        __shift_set_light();
                }
                else
                {
                        shift = NONE;
                        __oth_shift_game_over(board);
                }
        }
        else
        {
                fprintf(stderr, "Game Over!\n");
        }
}


decompiled_code:
__int64 oth_comp()
{
__int64 v0; // rbx
__int64 v1; // rsi

v0 = current_board;
if ( (unsigned int)oth_shift_current() == 1 )
v1 = *(_QWORD *)(v0 + 16);
else
v1 = *(_QWORD *)(v0 + 24);
return oth_shift_update(v0, v1);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 v1; // rsi

v0 = current_board;
if ( (unsigned int)oth_shift_current() == 1 )
v1 = *(_QWORD *)(v0 + 16);
else
v1 = *(_QWORD *)(v0 + 24);
return oth_shift_update(v0, v1);
}

original_code:
void
oth_comp(void)
{
        Board* board = current_board;
        Square* square = oth_shift_current() == DARK ? board->best_dark : board->best_light;
        oth_shift_update(board, square);
}

canonical_original_code:
void oth_comp()
{
        struct Board *board = current_board;
        struct Square *square = oth_shift_current() == DARK ? board->best_dark : board->best_light;
        oth_shift_update(board, square);
}

variable_types: struct Square { unsigned int name; unsigned int rank; unsigned int file; struct Score { unsigned int blacks; unsigned int whites; } score; enum Disk { EMPTY=0, BLACK=1, WHITE=2 } disk; char flipping; struct Flipper { struct { float x; } translation; struct { float a; } rotation; float ambient[4]; float diffuse[4]; float specular[4]; } *flipper; } *


decompiled_code:
void __fastcall oth_keyboard(char a1)
{
if ( a1 == 27 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
if ( a1 == 27 )
exit(0);
}

original_code:
void
oth_keyboard(unsigned char key, int x, int y)
{
        if (key == 27 )
                exit(0);
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


ntop

decompiled_code:
char *__fastcall ntop(int a1, char *a2)
{
char *v2; // rbx
int cp[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a2;
cp[0] = a1;
if ( !inet_ntop(2, cp, a2, 0x10u) )
v2 = 0LL;
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, char *a2)
{
char *v2; // rbx
int cp[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a2;
cp[0] = a1;
if ( !inet_ntop(2, cp, a2, 0x10u) )
v2 = 0LL;
return v2;
}

original_code:
static inline char* ntop(u_long ip, char* buf)
{
 struct in_addr in;
 in.s_addr = ip;
 if (inet_ntop(2, (const void *) &in, buf, 16) == ((void *)0))
  return(((void *)0));
 return buf;
}

canonical_original_code:
static inline char *ntop(unsigned long ip, char *buf)
{
 struct in_addr in;
 in.s_addr = ip;
 if (inet_ntop(2, (void *) &in, buf, 16) == ((void *)0))
  return(((void *)0));
 return buf;
}

variable_types:
ip
unsigned long

variable_types:
buf
char *

variable_types:
in
struct in_addr { unsigned int s_addr; }

return_type: char *