decompiled_code:
_QWORD *create_form_receiver_start()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rax
__int64 v16; // rbp
__int64 v17; // rbp
__int64 v18; // rax
__int64 v19; // rbp
__int64 v20; // rax
__int64 v21; // rbp
__int64 v22; // rax
__int64 v23; // rbp

v0 = (_QWORD *)fl_malloc(112LL);
v0[2] = 0LL;
v1 = v0;
v0[1] = 0LL;
v0[3] = 0LL;
*v0 = fl_bgn_form(0LL, 518LL, 302LL);
v2 = fl_add_box(1LL, 0LL, 0LL, 518LL, 302LL, "Integrated RA Receiver Startup");
v1[4] = v2;
v3 = v2;
fl_set_object_color(v2, 9LL, 11LL);
fl_set_object_lcol(v3, 3LL);
fl_set_object_lsize(v3, 18LL);
fl_set_object_lalign(v3, 8194LL);
fl_set_object_lstyle(v3, 1LL);
v4 = fl_add_button(0LL, 380LL, 10LL, 120LL, 40LL, "Start RA Receiver");
v1[5] = v4;
v5 = v4;
fl_set_object_boxtype(v4, 7LL);
fl_set_object_lsize(v5, 12LL);
fl_set_object_lalign(v5, 0LL);
fl_set_object_lstyle(v5, 1LL);
fl_set_object_callback(v5, &start_receiver, 0LL);
v6 = fl_add_text(0LL, 25LL, 210LL, 450LL, 30LL, "Science Radio Laboratories http://www.science-radio-labs.com");
fl_set_object_boxtype(v6, 6LL);
fl_set_object_color(v6, 18LL, 16LL);
fl_set_object_lsize(v6, 12LL);
fl_set_object_lstyle(v6, 3LL);
v7 = fl_add_input(0LL, 10LL, 140LL, 290LL, 30LL, "License Key");
v1[6] = v7;
v8 = v7;
fl_set_object_boxtype(v7, 7LL);
fl_set_object_lsize(v8, 12LL);
fl_set_object_lalign(v8, 2LL);
fl_set_object_lstyle(v8, 1LL);
fl_set_object_callback(v8, &input_license_key, 0LL);
fl_set_object_return(v8, 4LL);
v9 = fl_add_input(0LL, 240LL, 80LL, 110LL, 30LL, "Longitude");
v1[7] = v9;
v10 = v9;
fl_set_object_boxtype(v9, 7LL);
fl_set_object_lsize(v10, 12LL);
fl_set_object_lalign(v10, 2LL);
fl_set_object_lstyle(v10, 1LL);
fl_set_object_callback(v10, &set_longitude, 0LL);
fl_set_object_return(v10, 4LL);
v11 = fl_add_button(0LL, 420LL, 255LL, 70LL, 30LL, "HELP");
v1[8] = v11;
v12 = v11;
fl_set_object_color(v11, 10LL, 11LL);
fl_set_object_lsize(v12, 12LL);
fl_set_object_lalign(v12, 0LL);
fl_set_object_lstyle(v12, 1LL);
fl_set_object_callback(v12, &show_help, 0LL);
v13 = fl_add_choice(1LL, 160LL, 10LL, 90LL, 30LL, "RA Mode");
v1[9] = v13;
v14 = v13;
fl_set_object_boxtype(v13, 7LL);
fl_set_object_lsize(v14, 12LL);
fl_set_object_lalign(v14, 2LL);
fl_set_object_lstyle(v14, 1LL);
fl_set_object_callback(v14, &set_ra_mode, 0LL);
fl_addto_choice(v14, "manual");
fl_set_choice_item_mode(v14, 1LL, 0LL);
fl_addto_choice(v14, "transit");
fl_set_choice_item_mode(v14, 2LL, 0LL);
fl_addto_choice(v14, "external");
fl_set_choice_item_mode(v14, 3LL, 0LL);
fl_set_choice(v14, 1LL);
v15 = fl_add_choice(1LL, 260LL, 10LL, 90LL, 30LL, "DEC Mode");
v1[10] = v15;
v16 = v15;
fl_set_object_boxtype(v15, 7LL);
fl_set_object_lsize(v16, 12LL);
fl_set_object_lalign(v16, 2LL);
fl_set_object_lstyle(v16, 1LL);
fl_set_object_callback(v16, &set_dec_mode, 0LL);
fl_addto_choice(v16, "manual");
fl_set_choice_item_mode(v16, 1LL, 0LL);
fl_addto_choice(v16, "external");
fl_set_choice_item_mode(v16, 2LL, 0LL);
fl_set_choice(v16, 1LL);
v17 = fl_add_button(0LL, 400LL, 120LL, 100LL, 40LL, "EXIT");
fl_set_object_boxtype(v17, 7LL);
fl_set_object_lsize(v17, 14LL);
fl_set_object_lalign(v17, 0LL);
fl_set_object_lstyle(v17, 1LL);
fl_set_object_callback(v17, &exit_receiver, 0LL);
v18 = fl_add_choice(1LL, 20LL, 10LL, 130LL, 30LL, "Bandwidth");
v1[11] = v18;
v19 = v18;
fl_set_object_boxtype(v18, 7LL);
fl_set_object_lsize(v19, 14LL);
fl_set_object_lalign(v19, 2LL);
fl_set_object_lstyle(v19, 1LL);
fl_set_object_callback(v19, &select_bandwidth, 0LL);
v20 = fl_add_choice(1LL, 20LL, 80LL, 80LL, 30LL, "Side");
v1[12] = v20;
v21 = v20;
fl_set_object_lsize(v20, 14LL);
fl_set_object_lalign(v21, 2LL);
fl_set_object_lstyle(v21, 1LL);
fl_set_object_callback(v21, &set_side_choice, 0LL);
fl_addto_choice(v21, "A");
fl_addto_choice(v21, "B");
fl_set_choice(v21, 1LL);
v22 = fl_add_choice(1LL, 110LL, 80LL, 120LL, 30LL, "Mode");
v1[13] = v22;
v23 = v22;
fl_set_object_lsize(v22, 14LL);
fl_set_object_lalign(v23, 2LL);
fl_set_object_lstyle(v23, 1LL);
fl_set_object_callback(v23, &select_single, 0LL);
fl_addto_choice(v23, "single");
fl_addto_choice(v23, "interferometer");
fl_set_choice(v23, 1LL);
fl_end_form();
*(_QWORD *)*v1 = v1;
return v1;
}

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

v0 = (_QWORD *)fl_malloc(112LL);
v0[2] = 0LL;
v1 = v0;
v0[1] = 0LL;
v0[3] = 0LL;
*v0 = fl_bgn_form(0LL, 518LL, 302LL);
v2 = fl_add_box(1LL, 0LL, 0LL, 518LL, 302LL, "Integrated RA Receiver Startup");
v1[4] = v2;
v3 = v2;
fl_set_object_color(v2, 9LL, 11LL);
fl_set_object_lcol(v3, 3LL);
fl_set_object_lsize(v3, 18LL);
fl_set_object_lalign(v3, 8194LL);
fl_set_object_lstyle(v3, 1LL);
v4 = fl_add_button(0LL, 380LL, 10LL, 120LL, 40LL, "Start RA Receiver");
v1[5] = v4;
v5 = v4;
fl_set_object_boxtype(v4, 7LL);
fl_set_object_lsize(v5, 12LL);
fl_set_object_lalign(v5, 0LL);
fl_set_object_lstyle(v5, 1LL);
fl_set_object_callback(v5, &start_receiver, 0LL);
v6 = fl_add_text(0LL, 25LL, 210LL, 450LL, 30LL, "Science Radio Laboratories http://www.science-radio-labs.com");
fl_set_object_boxtype(v6, 6LL);
fl_set_object_color(v6, 18LL, 16LL);
fl_set_object_lsize(v6, 12LL);
fl_set_object_lstyle(v6, 3LL);
v7 = fl_add_input(0LL, 10LL, 140LL, 290LL, 30LL, "License Key");
v1[6] = v7;
v8 = v7;
fl_set_object_boxtype(v7, 7LL);
fl_set_object_lsize(v8, 12LL);
fl_set_object_lalign(v8, 2LL);
fl_set_object_lstyle(v8, 1LL);
fl_set_object_callback(v8, &input_license_key, 0LL);
fl_set_object_return(v8, 4LL);
v9 = fl_add_input(0LL, 240LL, 80LL, 110LL, 30LL, "Longitude");
v1[7] = v9;
v10 = v9;
fl_set_object_boxtype(v9, 7LL);
fl_set_object_lsize(v10, 12LL);
fl_set_object_lalign(v10, 2LL);
fl_set_object_lstyle(v10, 1LL);
fl_set_object_callback(v10, &set_longitude, 0LL);
fl_set_object_return(v10, 4LL);
v11 = fl_add_button(0LL, 420LL, 255LL, 70LL, 30LL, "HELP");
v1[8] = v11;
v12 = v11;
fl_set_object_color(v11, 10LL, 11LL);
fl_set_object_lsize(v12, 12LL);
fl_set_object_lalign(v12, 0LL);
fl_set_object_lstyle(v12, 1LL);
fl_set_object_callback(v12, &show_help, 0LL);
v13 = fl_add_choice(1LL, 160LL, 10LL, 90LL, 30LL, "RA Mode");
v1[9] = v13;
v14 = v13;
fl_set_object_boxtype(v13, 7LL);
fl_set_object_lsize(v14, 12LL);
fl_set_object_lalign(v14, 2LL);
fl_set_object_lstyle(v14, 1LL);
fl_set_object_callback(v14, &set_ra_mode, 0LL);
fl_addto_choice(v14, "manual");
fl_set_choice_item_mode(v14, 1LL, 0LL);
fl_addto_choice(v14, "transit");
fl_set_choice_item_mode(v14, 2LL, 0LL);
fl_addto_choice(v14, "external");
fl_set_choice_item_mode(v14, 3LL, 0LL);
fl_set_choice(v14, 1LL);
v15 = fl_add_choice(1LL, 260LL, 10LL, 90LL, 30LL, "DEC Mode");
v1[10] = v15;
v16 = v15;
fl_set_object_boxtype(v15, 7LL);
fl_set_object_lsize(v16, 12LL);
fl_set_object_lalign(v16, 2LL);
fl_set_object_lstyle(v16, 1LL);
fl_set_object_callback(v16, &set_dec_mode, 0LL);
fl_addto_choice(v16, "manual");
fl_set_choice_item_mode(v16, 1LL, 0LL);
fl_addto_choice(v16, "external");
fl_set_choice_item_mode(v16, 2LL, 0LL);
fl_set_choice(v16, 1LL);
v17 = fl_add_button(0LL, 400LL, 120LL, 100LL, 40LL, "EXIT");
fl_set_object_boxtype(v17, 7LL);
fl_set_object_lsize(v17, 14LL);
fl_set_object_lalign(v17, 0LL);
fl_set_object_lstyle(v17, 1LL);
fl_set_object_callback(v17, &exit_receiver, 0LL);
v18 = fl_add_choice(1LL, 20LL, 10LL, 130LL, 30LL, "Bandwidth");
v1[11] = v18;
v19 = v18;
fl_set_object_boxtype(v18, 7LL);
fl_set_object_lsize(v19, 14LL);
fl_set_object_lalign(v19, 2LL);
fl_set_object_lstyle(v19, 1LL);
fl_set_object_callback(v19, &select_bandwidth, 0LL);
v20 = fl_add_choice(1LL, 20LL, 80LL, 80LL, 30LL, "Side");
v1[12] = v20;
v21 = v20;
fl_set_object_lsize(v20, 14LL);
fl_set_object_lalign(v21, 2LL);
fl_set_object_lstyle(v21, 1LL);
fl_set_object_callback(v21, &set_side_choice, 0LL);
fl_addto_choice(v21, "A");
fl_addto_choice(v21, "B");
fl_set_choice(v21, 1LL);
v22 = fl_add_choice(1LL, 110LL, 80LL, 120LL, 30LL, "Mode");
v1[13] = v22;
v23 = v22;
fl_set_object_lsize(v22, 14LL);
fl_set_object_lalign(v23, 2LL);
fl_set_object_lstyle(v23, 1LL);
fl_set_object_callback(v23, &select_single, 0LL);
fl_addto_choice(v23, "single");
fl_addto_choice(v23, "interferometer");
fl_set_choice(v23, 1LL);
fl_end_form();
*(_QWORD *)*v1 = v1;
return v1;
}

original_code:
FD_receiver_start *
create_form_receiver_start( void )
{
    FL_OBJECT *obj;
    FD_receiver_start *fdui = fl_malloc( sizeof *fdui );
    fdui->vdata = fdui->cdata = ((void *)0);
    fdui->ldata = 0;
    fdui->receiver_start = fl_bgn_form( FL_NO_BOX, 518, 302 );
    fdui->receiver_starter = obj = fl_add_box( FL_UP_BOX, 0, 0, 518, 302, "Integrated RA Receiver Startup" );
    fl_set_object_color( obj, FL_INDIANRED, FL_COL1 );
    fl_set_object_lcol( obj, FL_YELLOW );
    fl_set_object_lsize( obj, 18 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fdui->start_button = obj = fl_add_button( FL_NORMAL_BUTTON, 380, 10, 120, 40, "Start RA Receiver" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, start_receiver, 0 );
    obj = fl_add_text( FL_NORMAL_TEXT, 25, 210, 450, 30, "Science Radio Laboratories  http://www.science-radio-labs.com" );
    fl_set_object_boxtype( obj, FL_ROUNDED_BOX );
    fl_set_object_color( obj, FL_PALEGREEN, FL_MCOL );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lstyle( obj, FL_BOLDITALIC_STYLE );
    fdui->license_input = obj = fl_add_input( FL_NORMAL_INPUT, 10, 140, 290, 30, "License Key" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, input_license_key, 0 );
    fl_set_object_return( obj, 4U );
    fdui->longitude_input = obj = fl_add_input( FL_NORMAL_INPUT, 240, 80, 110, 30, "Longitude" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_longitude, 0 );
    fl_set_object_return( obj, 4U );
    fdui->help_button = obj = fl_add_button( FL_NORMAL_BUTTON, 420, 255, 70, 30, "HELP" );
    fl_set_object_color( obj, FL_SLATEBLUE, FL_COL1 );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, show_help, 0 );
    fdui->ra_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 160, 10, 90, 30, "RA Mode" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_ra_mode, 0 );
    fl_addto_choice( obj, "manual" );
    fl_set_choice_item_mode( obj, 1, FL_PUP_NONE );
    fl_addto_choice( obj, "transit" );
    fl_set_choice_item_mode( obj, 2, FL_PUP_NONE );
    fl_addto_choice( obj, "external" );
    fl_set_choice_item_mode( obj, 3, FL_PUP_NONE );
    fl_set_choice( obj, 1 );
    fdui->dec_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 260, 10, 90, 30, "DEC Mode" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_dec_mode, 0 );
    fl_addto_choice( obj, "manual" );
    fl_set_choice_item_mode( obj, 1, FL_PUP_NONE );
    fl_addto_choice( obj, "external" );
    fl_set_choice_item_mode( obj, 2, FL_PUP_NONE );
    fl_set_choice( obj, 1 );
    obj = fl_add_button( FL_NORMAL_BUTTON, 400, 120, 100, 40, "EXIT" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, exit_receiver, 0 );
    fdui->bw_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 20, 10, 130, 30, "Bandwidth" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, select_bandwidth, 0 );
    fdui->side_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 20, 80, 80, 30, "Side" );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_side_choice, 0 );
    fl_addto_choice( obj, "A" );
    fl_addto_choice( obj, "B" );
    fl_set_choice( obj, 1 );
    fdui->rcvr_mode = obj = fl_add_choice( FL_NORMAL_CHOICE2, 110, 80, 120, 30, "Mode" );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, select_single, 0 );
    fl_addto_choice( obj, "single" );
    fl_addto_choice( obj, "interferometer" );
    fl_set_choice( obj, 1 );
    fl_end_form( );
    fdui->receiver_start->fdui = fdui;
    return fdui;
}

canonical_original_code:
struct FD_receiver_start *create_form_receiver_start()
{
    struct FL_OBJECT_ *obj;
    struct FD_receiver_start *fdui = fl_malloc( sizeof *fdui );
    fdui->vdata = fdui->cdata = ((void *)0);
    fdui->ldata = 0;
    fdui->receiver_start = fl_bgn_form( FL_NO_BOX, 518, 302 );
    fdui->receiver_starter = obj = fl_add_box( FL_UP_BOX, 0, 0, 518, 302, "Integrated RA Receiver Startup" );
    fl_set_object_color( obj, FL_INDIANRED, FL_COL1 );
    fl_set_object_lcol( obj, FL_YELLOW );
    fl_set_object_lsize( obj, 18 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fdui->start_button = obj = fl_add_button( FL_NORMAL_BUTTON, 380, 10, 120, 40, "Start RA Receiver" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, start_receiver, 0 );
    obj = fl_add_text( FL_NORMAL_TEXT, 25, 210, 450, 30, "Science Radio Laboratories  http://www.science-radio-labs.com" );
    fl_set_object_boxtype( obj, FL_ROUNDED_BOX );
    fl_set_object_color( obj, FL_PALEGREEN, FL_MCOL );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lstyle( obj, FL_BOLDITALIC_STYLE );
    fdui->license_input = obj = fl_add_input( FL_NORMAL_INPUT, 10, 140, 290, 30, "License Key" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, input_license_key, 0 );
    fl_set_object_return( obj, 4U );
    fdui->longitude_input = obj = fl_add_input( FL_NORMAL_INPUT, 240, 80, 110, 30, "Longitude" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_longitude, 0 );
    fl_set_object_return( obj, 4U );
    fdui->help_button = obj = fl_add_button( FL_NORMAL_BUTTON, 420, 255, 70, 30, "HELP" );
    fl_set_object_color( obj, FL_SLATEBLUE, FL_COL1 );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, show_help, 0 );
    fdui->ra_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 160, 10, 90, 30, "RA Mode" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_ra_mode, 0 );
    fl_addto_choice( obj, "manual" );
    fl_set_choice_item_mode( obj, 1, FL_PUP_NONE );
    fl_addto_choice( obj, "transit" );
    fl_set_choice_item_mode( obj, 2, FL_PUP_NONE );
    fl_addto_choice( obj, "external" );
    fl_set_choice_item_mode( obj, 3, FL_PUP_NONE );
    fl_set_choice( obj, 1 );
    fdui->dec_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 260, 10, 90, 30, "DEC Mode" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 12 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_dec_mode, 0 );
    fl_addto_choice( obj, "manual" );
    fl_set_choice_item_mode( obj, 1, FL_PUP_NONE );
    fl_addto_choice( obj, "external" );
    fl_set_choice_item_mode( obj, 2, FL_PUP_NONE );
    fl_set_choice( obj, 1 );
    obj = fl_add_button( FL_NORMAL_BUTTON, 400, 120, 100, 40, "EXIT" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, exit_receiver, 0 );
    fdui->bw_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 20, 10, 130, 30, "Bandwidth" );
    fl_set_object_boxtype( obj, FL_EMBOSSED_BOX );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, select_bandwidth, 0 );
    fdui->side_choice = obj = fl_add_choice( FL_NORMAL_CHOICE2, 20, 80, 80, 30, "Side" );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, set_side_choice, 0 );
    fl_addto_choice( obj, "A" );
    fl_addto_choice( obj, "B" );
    fl_set_choice( obj, 1 );
    fdui->rcvr_mode = obj = fl_add_choice( FL_NORMAL_CHOICE2, 110, 80, 120, 30, "Mode" );
    fl_set_object_lsize( obj, 14 );
    fl_set_object_lalign( obj, FL_ALIGN_BOTTOM );
    fl_set_object_lstyle( obj, FL_BOLD_STYLE );
    fl_set_object_callback( obj, select_single, 0 );
    fl_addto_choice( obj, "single" );
    fl_addto_choice( obj, "interferometer" );
    fl_set_choice( obj, 1 );
    fl_end_form( );
    fdui->receiver_start->fdui = fdui;
    return fdui;
}

variable_types: struct FD_receiver_start { struct FL_FORM_ { void *fdui; void *u_vdata; char *u_cdata; long u_ldata; char *label; unsigned long window; int x; int handle_dec_x; int hotx; double w_hr; struct FL_OBJECT_ { struct FL_FORM_ *form; void *u_vdata; char *u_cdata; long u_ldata; int objclass; int type; int boxtype; int x; double fl1; int bw; unsigned long col1; char *label; unsigned long lcol; int align; int lsize; long *shortcut; int (*handle)(struct FL_OBJECT_ *, int, int, int, int, void *); void (*object_callback)(struct FL_OBJECT_ *, long); long argument; void *spec; int (*prehandle)(struct FL_OBJECT_ *, int, int, int, int, void *); int (*posthandle)(struct FL_OBJECT_ *, int, int, int, int, void *); void (*set_return)(struct FL_OBJECT_ *, unsigned int); unsigned int resize; unsigned int nwgravity; unsigned int segravity; struct FL_OBJECT_ *prev; struct FL_OBJECT_ *next; struct FL_OBJECT_ *parent; struct FL_OBJECT_ *child; struct FL_OBJECT_ *nc; struct FL_pixmap_ { unsigned long pixmap; unsigned long win; struct Visual { struct _XExtData { int number; struct _XExtData *next; int (*free_private)(struct _XExtData *extension); char *private_data; } *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; } *visual; int x; int depth; unsigned long dbl_background; unsigned long pixel; } *flpixmap; int use_pixmap; int returned; unsigned int how_return; int double_buffer; int pushed; int focus; int belowmouse; int active; int input; int wantkey; int radio; int automatic; int redraw; int visible; int is_under; int clip; unsigned long click_timeout; void *c_vdata; char *c_cdata; long c_ldata; unsigned long dbl_background; char *tooltip; int tipID; int group_id; int want_motion; int want_update; } *first; struct FL_OBJECT_ *last; struct FL_OBJECT_ *focusobj; void (*form_callback)(struct FL_OBJECT_ *, void *); void (*activate_callback)(struct FL_FORM_ *, void *); void (*deactivate_callback)(struct FL_FORM_ *, void *); void *form_cb_data; void *activate_data; void *deactivate_data; int (*key_callback)(struct FL_FORM_ *, void *); int (*push_callback)(struct FL_FORM_ *, void *); int (*crossing_callback)(struct FL_FORM_ *, void *); int (*motion_callback)(struct FL_FORM_ *, void *); int (*all_callback)(struct FL_FORM_ *, void *); unsigned long compress_mask; unsigned long evmask; int (*close_callback)(struct FL_FORM_ *, void *); void *close_data; struct FL_pixmap_ *flpixmap; unsigned long icon_pixmap; unsigned long icon_mask; int deactivated; int use_pixmap; int frozen; int visible; int wm_border; unsigned int prop; int num_auto_objects; int needs_full_redraw; int sort_of_modal; struct FL_FORM_ *parent; struct FL_FORM_ *child; struct FL_OBJECT_ *parent_obj; int attached; void (*pre_attach)(struct FL_FORM_ *); void *attach_data; int in_redraw; } *receiver_start; void *vdata; char *cdata; long ldata; struct FL_OBJECT_ *receiver_starter; struct FL_OBJECT_ *start_button; struct FL_OBJECT_ *license_input; struct FL_OBJECT_ *longitude_input; struct FL_OBJECT_ *help_button; struct FL_OBJECT_ *ra_choice; struct FL_OBJECT_ *dec_choice; struct FL_OBJECT_ *bw_choice; struct FL_OBJECT_ *side_choice; struct FL_OBJECT_ *rcvr_mode; } *

user_defined_types: struct FD_receiver_start { struct FL_FORM_ *receiver_start; void *vdata; char *cdata; long ldata; struct FL_OBJECT_ *receiver_starter; struct FL_OBJECT_ *start_button; struct FL_OBJECT_ *license_input; struct FL_OBJECT_ *longitude_input; struct FL_OBJECT_ *help_button; struct FL_OBJECT_ *ra_choice; struct FL_OBJECT_ *dec_choice; struct FL_OBJECT_ *bw_choice; struct FL_OBJECT_ *side_choice; struct FL_OBJECT_ *rcvr_mode; }


displayRoom

repo: pathawks/Castle

decompiled_code:
int __fastcall displayRoom(void *ptr)
{
char *v1; // r12
char *v2; // rbp
char *v3; // rbx
const void *v4; // rdi
char *v5; // r12
const void *v6; // rdi
int result; // eax

v1 = (char *)ptr;
v2 = (char *)ptr + 432;
v3 = (char *)ptr;
do
{
v4 = v3;
v3 += 24;
fwrite(v4, 0x18uLL, 1uLL, stdout);
fputc(10, stdout);
}
while ( v3 != v2 );
v5 = v1 + 557;
do
{
v6 = v3;
v3 += 25;
fwrite(v6, 0x19uLL, 1uLL, stdout);
result = fputc(10, stdout);
}
while ( v5 != v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(void *ptr)
{
char *v1; // r12
char *v2; // rbp
char *v3; // rbx
const void *v4; // rdi
char *v5; // r12
const void *v6; // rdi
int result; // eax

v1 = (char *)ptr;
v2 = (char *)ptr + 432;
v3 = (char *)ptr;
do
{
v4 = v3;
v3 += 24;
fwrite(v4, 0x18uLL, 1uLL, stdout);
fputc(10, stdout);
}
while ( v3 != v2 );
v5 = v1 + 557;
do
{
v6 = v3;
v3 += 25;
fwrite(v6, 0x19uLL, 1uLL, stdout);
result = fputc(10, stdout);
}
while ( v5 != v3 );
return result;
}

original_code:
void displayRoom( Room *map ) {
 for (int i = 0; i < 18; ++i) {
  fwrite(map->map[i], 24, 1, stdout);
  fputc('\n', stdout);
 }
 for (int i = 0; i < 5; ++i) {
  fwrite(map->description[i], 25, 1, stdout);
  fputc('\n', stdout);
 }
}

canonical_original_code:
void displayRoom(struct Room *map) {
 for (int i = 0; i < 18; ++i) {
  fwrite(map->map[i], 24, 1, stdout);
  fputc('\n', stdout);
 }
 for (int i = 0; i < 5; ++i) {
  fwrite(map->description[i], 25, 1, stdout);
  fputc('\n', stdout);
 }
}

variable_types: struct Room { char map[18][24]; char description[5][25]; char nav[18]; } *

variable_types: i int

return_type: void


SystemPause

decompiled_code:
int SystemPause()
{
int result; // eax

puts("\nPress Enter to continue...");
do
result = getchar();
while ( result != 10 );
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax

puts("\nPress Enter to continue...");
do
result = getchar();
while ( result != 10 );
return result;
}

original_code:
void SystemPause() {
 puts("\nPress Enter to continue...");
 while (getchar() != '\n') {}
}


SystemClear

decompiled_code:
size_t SystemClear()
{
return fwrite("\x1B[2J\x1B[H", 1uLL, 7uLL, stdout);
}

canonical_decompiled_code:
size_t func10()
{
return fwrite("\x1B[2J\x1B[H", 1uLL, 7uLL, stdout);
}

original_code:
void SystemClear() {
 fputs("\033[2J\033[H", stdout);
}


addString

repo: patrickherrmann/BoggleOptimization

original_code:
void addString(Trie *node, char *string)
{
   int i = 0, childExists = 0;
   char letter;
   Trie *child;
   if (*string) {
      letter = tolower(*string);
      while (!childExists && i < node->childCount) {
         child = node->children + i++;
         if (child->letter == letter) {
            childExists = 1;
         }
      }
      if (!childExists) {
         node->children =
            realloc(node->children, sizeof(Trie) * (node->childCount + 1));
         child = node->children + node->childCount++;
         child->letter = letter;
         child->childCount = 0;
         child->children = ((void *)0);
         child->terminates = 0;
      }
      addString(child, string + 1);
   } else {
      node->terminates = 1;
   }
}

canonical_original_code:
void addString(struct Trie *node, char *string)
{
   int i = 0; int childExists = 0;
   char letter;
   struct Trie *child;
   if (*string) {
      letter = tolower(*string);
      while (!childExists && i < node->childCount) {
         child = node->children + i++;
         if (child->letter == letter) {
            childExists = 1;
         }
      }
      if (!childExists) {
         node->children =
            realloc(node->children, sizeof(Trie) * (node->childCount + 1));
         child = node->children + node->childCount++;
         child->letter = letter;
         child->childCount = 0;
         child->children = ((void *)0);
         child->terminates = 0;
      }
      addString(child, string + 1);
   } else {
      node->terminates = 1;
   }
}

variable_types: struct Trie { char letter; int terminates; int score; int childCount; unsigned int foundInBoard; struct Trie *children; } *

variable_types:
string
char *

variable_types: childExists int

variable_types: letter char


destroyNode

original_code:
void destroyNode(Trie *node)
{
   int i;
   for (i = 0; i < node->childCount; i++)
      destroyNode(node->children + i);
   free(node->children);
}

canonical_original_code:
void destroyNode(struct Trie *node)
{
   int i;
   for (i = 0; i < node->childCount; i++)
      destroyNode(node->children + i);
   free(node->children);
}

user_defined_types: struct Trie { char letter; int terminates; int score; int childCount; unsigned int foundInBoard; struct Trie *children; }


TrieDestroy

decompiled_code:
void __fastcall TrieDestroy(void *ptr)
{
destroyNode((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
func10((__int64)ptr);
free(ptr);
}

original_code:
void TrieDestroy(Trie *trie)
{
   destroyNode(trie);
   free(trie);
}

canonical_original_code:
void TrieDestroy(struct Trie *trie)
{
   destroyNode(trie);
   free(trie);
}


TrieGetChild

decompiled_code:
char *__fastcall TrieGetChild(__int64 a1, char a2)
{
int v4; // ecx
__int64 v5; // r8
int v6; // esi
int v7; // edx
char *result; // rax

v4 = *(_DWORD *)(a1 + 12) - 1;
if ( v4 < 0 )
return 0LL;
v5 = *(_QWORD *)(a1 + 24);
v6 = 0;
while ( 1 )
{
while ( 1 )
{
v7 = (v6 + v4) >> 1;
result = (char *)(v5 + 32LL * v7);
if ( *result >= a2 )
break;
v6 = v7 + 1;
if ( v4 < v7 + 1 )
return 0LL;
}
if ( *result <= a2 )
break;
v4 = v7 - 1;
if ( v7 - 1 < v6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, char a2)
{
int v4; // ecx
__int64 v5; // r8
int v6; // esi
int v7; // edx
char *result; // rax

v4 = *(_DWORD *)(a1 + 12) - 1;
if ( v4 < 0 )
return 0LL;
v5 = *(_QWORD *)(a1 + 24);
v6 = 0;
while ( 1 )
{
while ( 1 )
{
v7 = (v6 + v4) >> 1;
result = (char *)(v5 + 32LL * v7);
if ( *result >= a2 )
break;
v6 = v7 + 1;
if ( v4 < v7 + 1 )
return 0LL;
}
if ( *result <= a2 )
break;
v4 = v7 - 1;
if ( v7 - 1 < v6 )
return 0LL;
}
return result;
}

original_code:
Trie *TrieGetChild(Trie *trie, char letter)
{
   int min, max, mid;
   char childLetter;
   min = 0;
   max = trie->childCount - 1;
   while (max >= min) {
      mid = (min + max) / 2;
      childLetter = trie->children[mid].letter;
      if (childLetter < letter)
         min = mid + 1;
      else if (childLetter > letter)
         max = mid - 1;
      else
         return trie->children + mid;
   }
   return ((void *)0);
}

canonical_original_code:
struct Trie *TrieGetChild(struct Trie *trie, char letter)
{
   int min; int max; int mid;
   char childLetter;
   min = 0;
   max = trie->childCount - 1;
   while (max >= min) {
      mid = (min + max) / 2;
      childLetter = trie->children[mid].letter;
      if (childLetter < letter)
         min = mid + 1;
      else if (childLetter > letter)
         max = mid - 1;
      else
         return trie->children + mid;
   }
   return ((void *)0);
}

variable_types:
trie
struct Trie *

variable_types: min int

variable_types: max int

variable_types: mid int

variable_types: childLetter char

return_type: struct Trie { char letter; int terminates; int score; int childCount; unsigned int foundInBoard; struct Trie *children; } *


newBoard

decompiled_code:
_QWORD *newBoard()
{
_QWORD *result; // rax
void *v1; // rdx

result = freeList;
if ( freeList )
{
v1 = (void *)*((_QWORD *)freeList + 4);
*((_QWORD *)freeList + 2) = 0LL;
freeList = v1;
}
else
{
result = malloc(0x28uLL);
result[2] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax
void *v1; // rdx

result = freeList;
if ( freeList )
{
v1 = (void *)*((_QWORD *)freeList + 4);
*((_QWORD *)freeList + 2) = 0LL;
freeList = v1;
}
else
{
result = malloc(0x28uLL);
result[2] = 0LL;
}
return result;
}

original_code:
static Board *newBoard()
{
   Board *new;
   if (freeList) {
      new = freeList;
      freeList = new->next;
   } else {
      new = malloc(sizeof(Board));
   }
   new->score = 0;
   new->wordCount = 0;
   return new;
}

canonical_original_code:
static struct Board *newBoard()
{
   struct Board *new;
   if (freeList) {
      new = freeList;
      freeList = new->next;
   } else {
      new = malloc(sizeof(Board));
   }
   new->score = 0;
   new->wordCount = 0;
   return new;
}

variable_types: struct Board { char letters[4][4]; int wordCount; int score; unsigned long id; struct Board *next; } *


WordScore

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

result = 11LL;
if ( a1 <= 7 )
result = (unsigned int)CSWTCH_16[a1];
return result;
}

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

result = 11LL;
if ( a1 <= 7 )
result = (unsigned int)CSWTCH_16[a1];
return result;
}

original_code:
int WordScore(int wordLength)
{
   switch (wordLength) {
      case 0:
      case 1:
      case 2: return 0;
      case 3:
      case 4: return 1;
      case 5: return 2;
      case 6: return 3;
      case 7: return 5;
      default: return 11;
   }
}

variable_types: wordLength int

return_type: int


BoardWordCount

decompiled_code:
__int64 __fastcall BoardWordCount(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int BoardWordCount(Board *board)
{
   return board->wordCount;
}

canonical_original_code:
int BoardWordCount(struct Board *board)
{
   return board->wordCount;
}

user_defined_types: struct Board { char letters[4][4]; int wordCount; int score; unsigned long id; struct Board *next; }


BoardScore

decompiled_code:
__int64 __fastcall BoardScore(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int BoardScore(Board *board)
{
   return board->score;
}

canonical_original_code:
int BoardScore(struct Board *board)
{
   return board->score;
}


BoardGarbageCollect

decompiled_code:
void BoardGarbageCollect()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = freeList;
if ( freeList )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[4];
free(v1);
freeList = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func11()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = freeList;
if ( freeList )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[4];
free(v1);
freeList = v0;
}
while ( v0 );
}
}

original_code:
void BoardGarbageCollect()
{
   Board *temp;
   while (freeList) {
      temp = freeList->next;
      free(freeList);
      freeList = temp;
   }
}

canonical_original_code:
void BoardGarbageCollect()
{
   struct Board *temp;
   while (freeList) {
      temp = freeList->next;
      free(freeList);
      freeList = temp;
   }
}


newNode

decompiled_code:
void *newNode()
{
void *result; // rax

result = freeNodes;
if ( !freeNodes )
return malloc(0x20uLL);
freeNodes = (void *)*((_QWORD *)freeNodes + 2);
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

result = freeNodes;
if ( !freeNodes )
return malloc(0x20uLL);
freeNodes = (void *)*((_QWORD *)freeNodes + 2);
return result;
}

original_code:
static PointTree *newNode()
{
   PointTree *new;
   if (freeNodes) {
      new = freeNodes;
      freeNodes = new->sib;
   } else {
      new = malloc(sizeof(PointTree));
   }
   return new;
}

canonical_original_code:
static struct PointTree *newNode()
{
   struct PointTree *new;
   if (freeNodes) {
      new = freeNodes;
      freeNodes = new->sib;
   } else {
      new = malloc(sizeof(PointTree));
   }
   return new;
}

variable_types: struct PointTree { int row; int col; struct PointTree *parent; struct PointTree *sib; struct PointTree *child; } *


PointTreeInit

decompiled_code:
_QWORD *PointTreeInit()
{
_QWORD *result; // rax

result = newNode();
*result = -1LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = func1();
*result = -1LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
PointTree *PointTreeInit()
{
   PointTree *root = newNode();
   root->row = -1;
   root->col = -1;
   root->parent = ((void *)0);
   root->sib = ((void *)0);
   root->child = ((void *)0);
   return root;
}

canonical_original_code:
struct PointTree *PointTreeInit()
{
   struct PointTree *root = newNode();
   root->row = -1;
   root->col = -1;
   root->parent = ((void *)0);
   root->sib = ((void *)0);
   root->child = ((void *)0);
   return root;
}

return_type: struct PointTree { int row; int col; struct PointTree *parent; struct PointTree *sib; struct PointTree *child; } *


PointTreeGarbageCollect

decompiled_code:
void PointTreeGarbageCollect()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = freeNodes;
if ( freeNodes )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
free(v1);
freeNodes = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = freeNodes;
if ( freeNodes )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
free(v1);
freeNodes = v0;
}
while ( v0 );
}
}

original_code:
void PointTreeGarbageCollect()
{
   PointTree *temp;
   while (freeNodes) {
      temp = freeNodes->sib;
      free(freeNodes);
      freeNodes = temp;
   }
}

canonical_original_code:
void PointTreeGarbageCollect()
{
   struct PointTree *temp;
   while (freeNodes) {
      temp = freeNodes->sib;
      free(freeNodes);
      freeNodes = temp;
   }
}

user_defined_types: struct PointTree { int row; int col; struct PointTree *parent; struct PointTree *sib; struct PointTree *child; }


PointTreeAdd

decompiled_code:
__int64 __fastcall PointTreeAdd(__int64 *a1, int a2, int a3)
{
_QWORD *v4; // rdx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax
__int64 v8; // rcx

v4 = newNode();
v5 = *a1;
v4[3] = 0LL;
v4[1] = v5;
v4[2] = 0LL;
v6 = *a1;
*(_DWORD *)v4 = a2;
result = *(_QWORD *)(v6 + 24);
*((_DWORD *)v4 + 1) = a3;
if ( result )
{
do
{
v8 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v8 + 16) = v4;
*a1 = (__int64)v4;
}
else
{
*(_QWORD *)(v6 + 24) = v4;
*a1 = (__int64)v4;
}
return result;
}

original_code:
void PointTreeAdd(PointTree **tree, int row, int col)
{
   PointTree *new = newNode(), *child;
   new->parent = *tree;
   new->child = ((void *)0);
   new->sib = ((void *)0);
   new->row = row;
   new->col = col;
   if (!(*tree)->child) {
      (*tree)->child = new;
   } else {
      child = (*tree)->child;
      while (child->sib)
         child = child->sib;
      child->sib = new;
   }
   *tree = new;
}

canonical_original_code:
void PointTreeAdd(struct PointTree **tree, int row, int col)
{
   struct PointTree *new = newNode(); struct PointTree *child;
   new->parent = *tree;
   new->child = ((void *)0);
   new->sib = ((void *)0);
   new->row = row;
   new->col = col;
   if (!(*tree)->child) {
      (*tree)->child = new;
   } else {
      child = (*tree)->child;
      while (child->sib)
         child = child->sib;
      child->sib = new;
   }
   *tree = new;
}

variable_types: struct PointTree { int row; int col; struct PointTree *parent; struct PointTree *sib; struct PointTree *child; } **

variable_types: row int

variable_types: col int


PointTreePathContains

decompiled_code:
__int64 __fastcall PointTreePathContains(__int64 a1, int a2, int a3)
{
while ( a1 )
{
if ( *(_DWORD *)a1 == a2 && *(_DWORD *)(a1 + 4) == a3 )
return 1LL;
a1 = *(_QWORD *)(a1 + 8);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
while ( a1 )
{
if ( *(_DWORD *)a1 == a2 && *(_DWORD *)(a1 + 4) == a3 )
return 1LL;
a1 = *(_QWORD *)(a1 + 8);
}
return 0LL;
}

original_code:
int PointTreePathContains(PointTree *tree, int row, int col)
{
   int found = 0;
   while (!found && tree) {
      if (tree->row == row && tree->col == col)
         found = 1;
      else
         tree = tree->parent;
   }
   return found;
}

canonical_original_code:
int PointTreePathContains(struct PointTree *tree, int row, int col)
{
   int found = 0;
   while (!found && tree) {
      if (tree->row == row && tree->col == col)
         found = 1;
      else
         tree = tree->parent;
   }
   return found;
}

variable_types: found int


getPixel

repo: patrickherrmann/Mandelbrot

decompiled_code:
__int64 __fastcall getPixel(__int64 a1, int a2, int a3)
{
return *(_QWORD *)a1 + 3 * (a2 + (__int64)(*(_DWORD *)(a1 + 8) * a3));
}

original_code:
pixel_t *getPixel(bitmap_t *bitmap, int x, int y) {
    return bitmap->pixels + y * bitmap->width + x;
}

canonical_original_code:
struct pixel_t *getPixel(struct bitmap_t *bitmap, int x, int y) {
    return bitmap->pixels + y * bitmap->width + x;
}

variable_types: struct bitmap_t { struct pixel_t *pixels; int width; int height; } *

variable_types: x int

variable_types: y int

return_type: struct pixel_t { unsigned char r; unsigned char g; unsigned char b; } *


resample

original_code:
void resample(bitmap_t *image, bitmap_t *resampled, int boxSize) {
    int r, g, b;
    int x, y, ix, iy, bs2 = boxSize * boxSize;
    pixel_t *p;
    for (y = 0; y < resampled->height; y++) {
        for (x = 0; x < resampled->width; x++) {
            r = g = b = 0;
            for (iy = 0; iy < boxSize; iy++) {
                for (ix = 0; ix < boxSize; ix++) {
                    p = getPixel(image, x * boxSize + ix, y * boxSize + iy);
                    r += p->r;
                    g += p->g;
                    b += p->b;
                }
            }
            p = getPixel(resampled, x, y);
            p->r = r / bs2;
            p->g = g / bs2;
            p->b = b / bs2;
        }
    }
}

canonical_original_code:
void resample(struct bitmap_t *image, struct bitmap_t *resampled, int boxSize) {
    int r; int g; int b;
    int x; int y; int ix; int iy; int bs2 = boxSize * boxSize;
    struct pixel_t *p;
    for (y = 0; y < resampled->height; y++) {
        for (x = 0; x < resampled->width; x++) {
            r = g = b = 0;
            for (iy = 0; iy < boxSize; iy++) {
                for (ix = 0; ix < boxSize; ix++) {
                    p = getPixel(image, x * boxSize + ix, y * boxSize + iy);
                    r += p->r;
                    g += p->g;
                    b += p->b;
                }
            }
            p = getPixel(resampled, x, y);
            p->r = r / bs2;
            p->g = g / bs2;
            p->b = b / bs2;
        }
    }
}

variable_types: struct bitmap_t { struct pixel_t { unsigned char r; unsigned char g; unsigned char b; } *pixels; int width; int height; } *

variable_types:
resampled
struct bitmap_t *

variable_types: boxSize int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: ix int

variable_types: iy int

user_defined_types: struct bitmap_t { struct pixel_t *pixels; int width; int height; }


bitmapGC

decompiled_code:
void __fastcall bitmapGC(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void bitmapGC(bitmap_t *bitmap) {
    free(bitmap->pixels);
    free(bitmap);
}

canonical_original_code:
void bitmapGC(struct bitmap_t *bitmap) {
    free(bitmap->pixels);
    free(bitmap);
}

user_defined_types: struct pixel_t { unsigned char r; unsigned char g; unsigned char b; }


main

canonical_name: main

repo: patrickmalsom/SDE

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
double v4; // xmm0_8
int v5; // ebx
unsigned int v6; // er13
double v7; // xmm0_8
double v9; // [rsp+8h] [rbp-40h]
double v10; // [rsp+10h] [rbp-38h]
double v11; // [rsp+18h] [rbp-30h]

setbuf(stdout, 0LL);
gsl_rng_env_setup();
gsl_rng_alloc();
v11 = atof(argv[1]);
v3 = atoi(argv[2]);
v4 = (v11 + v11) * 0.001;
if ( v4 < 0.0 )
v9 = sqrt(v4);
else
v9 = sqrt(v4);
if ( v3 <= 0 )
{
v6 = 0;
}
else
{
v5 = 0;
v6 = 0;
v7 = 1.0;
v10 = 1.0;
do
{
while ( 1 )
{
gsl_ran_ugaussian();
v7 = v7 * v9 + (1.0 - v7 * v7) * (0.004 * v7) + v7;
if ( fabs(v7) > 1.0 && v10 * v7 < 0.0 )
{
++v6;
v10 = 1.0;
if ( v7 <= 0.0 )
break;
}
if ( v3 == ++v5 )
goto LABEL_10;
}
++v5;
v10 = -1.0;
}
while ( v3 != v5 );
}
LABEL_10:
printf("Temp=%f,Trans=%d\n", v11, v6);
gsl_rng_free();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  setbuf(stdout,((void *)0));
  const gsl_rng_type * RanNumType;
  gsl_rng *RanNumPointer;
  gsl_rng_env_setup();
  RanNumType = gsl_rng_default;
  RanNumPointer= gsl_rng_alloc (RanNumType);
  double Temp=atof(argv[1]);
  int Numt=atoi(argv[2]);
  double dt=0.001;
  double xstart=1.0;
  double pref=sqrt(2.0*Temp*dt);
  int trans=0;
  double basin=xstart;
  double xold=xstart;
  double xnew;
  int i;
  for(i=0;i<Numt;i++)
  {
    xnew=xold+dt*4.0*xold*(1.0-xold*xold)+pref*gsl_ran_ugaussian(RanNumPointer);
    if(fabs(xnew) > 1.0)
    {
      if(basin * xnew < 0.0 )
      {
        trans=trans+1;
        if(xnew>0.0)
          basin=1.0;
        else
          basin=-1.0;
      }
    }
  xold=xnew;
  }
  printf("Temp=%f,Trans=%d\n",Temp,trans);
  gsl_rng_free (RanNumPointer);
  return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  setbuf(stdout,((void *)0));
  struct gsl_rng_type *RanNumType;
  struct gsl_rng *RanNumPointer;
  gsl_rng_env_setup();
  RanNumType = gsl_rng_default;
  RanNumPointer= gsl_rng_alloc (RanNumType);
  double Temp = atof(argv[1]);
  int Numt = atoi(argv[2]);
  double dt = 0.001;
  double xstart = 1.0;
  double pref = sqrt(2.0*Temp*dt);
  int trans = 0;
  double basin = xstart;
  double xold = xstart;
  double xnew;
  int i;
  for(i=0;i<Numt;i++)
  {
    xnew=xold+dt*4.0*xold*(1.0-xold*xold)+pref*gsl_ran_ugaussian(RanNumPointer);
    if(fabs(xnew) > 1.0)
    {
      if(basin * xnew < 0.0 )
      {
        trans=trans+1;
        if(xnew>0.0)
          basin=1.0;
        else
          basin=-1.0;
      }
    }
  xold=xnew;
  }
  printf("Temp=%f,Trans=%d\n",Temp,trans);
  gsl_rng_free (RanNumPointer);
  return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: Temp double

variable_types: Numt int

variable_types: dt double

variable_types: xstart double

variable_types: pref double

variable_types: trans int

variable_types: basin double

variable_types: xold double

variable_types: xnew double

variable_types: i int

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }


repo: paulburton/fitbitd

decompiled_code:
_QWORD *postdata_create()
{
_QWORD *v0; // r12
__int64 v1; // rax
void *v3; // rdi

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = curl_easy_init();
v0[2] = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
__int64 v1; // rax
void *v3; // rdi

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = curl_easy_init();
v0[2] = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
postdata_t *postdata_create(void)
{
    postdata_t *pd;
    pd = calloc(1, sizeof(*pd));
    if (!pd)
        return ((void *)0);
    pd->curl = curl_easy_init();
    if (!pd->curl)
        goto err_curl;
    return pd;
err_curl:
    free(pd);
    return ((void *)0);
}

canonical_original_code:
struct postdata_s *postdata_create()
{
    struct postdata_s *pd;
    pd = calloc(1, sizeof(*pd));
    if (!pd)
        return ((void *)0);
    pd->curl = curl_easy_init();
    if (!pd->curl)
        goto err_curl;
    return pd;
err_curl:
    free(pd);
    return ((void *)0);
}

variable_types: struct postdata_s { char *str; unsigned long str_sz; void *curl; } *


decompiled_code:
void __fastcall postdata_destroy(void *ptr)
{
curl_easy_cleanup(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
curl_easy_cleanup(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

original_code:
void postdata_destroy(postdata_t *pd)
{
    curl_easy_cleanup(pd->curl);
    free(pd->str);
    free(pd);
}

canonical_original_code:
void postdata_destroy(struct postdata_s *pd)
{
    curl_easy_cleanup(pd->curl);
    free(pd->str);
    free(pd);
}

user_defined_types: struct postdata_s { char *str; unsigned long str_sz; void *curl; }


decompiled_code:
__int64 __fastcall postdata_append(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
const char *v6; // rbp
const char *v7; // r12
size_t v8; // r13
size_t v9; // rax
void *v10; // rdi
size_t v11; // rax
size_t v12; // r14
_BYTE *v13; // rax
__int64 v14; // rdx
__int64 v15; // r13
char *v16; // r13
size_t v17; // rax
char *v18; // r13
size_t v19; // rax
char *v21; // rax

v5 = curl_easy_escape(a1, a2, 0LL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = (const char *)v5;
v7 = (const char *)curl_easy_escape(a1, a3, 0LL);
if ( v7 )
{
v8 = strlen(v6);
v9 = strlen(v7);
v10 = *(void **)a1;
v11 = v8 + v9;
v12 = v11 + 1;
if ( *(_QWORD *)a1 )
{
v13 = realloc(v10, v12 + *(_QWORD *)(a1 + 8) + 2);
if ( v13 )
{
v14 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v14 + 1;
v13[v14] = 38;
v15 = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v13;
v16 = &v13[v15];
LABEL_6:
v17 = strlen(v6);
memcpy(v16, v6, v17);
v18 = &v16[strlen(v6)];
*v18 = 61;
v19 = strlen(v7);
memcpy(v18 + 1, v7, v19);
v18[strlen(v7) + 1] = 0;
*(_QWORD *)(a1 + 8) += v12;
curl_free(v7);
curl_free(v6);
return 0LL;
}
}
else
{
v21 = (char *)malloc(v11 + 2);
*(_QWORD *)a1 = v21;
v16 = v21;
if ( v21 )
goto LABEL_6;
}
curl_free(v7);
}
curl_free(v6);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
const char *v6; // rbp
const char *v7; // r12
size_t v8; // r13
size_t v9; // rax
void *v10; // rdi
size_t v11; // rax
size_t v12; // r14
_BYTE *v13; // rax
__int64 v14; // rdx
__int64 v15; // r13
char *v16; // r13
size_t v17; // rax
char *v18; // r13
size_t v19; // rax
char *v21; // rax

v5 = curl_easy_escape(a1, a2, 0LL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = (const char *)v5;
v7 = (const char *)curl_easy_escape(a1, a3, 0LL);
if ( v7 )
{
v8 = strlen(v6);
v9 = strlen(v7);
v10 = *(void **)a1;
v11 = v8 + v9;
v12 = v11 + 1;
if ( *(_QWORD *)a1 )
{
v13 = realloc(v10, v12 + *(_QWORD *)(a1 + 8) + 2);
if ( v13 )
{
v14 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v14 + 1;
v13[v14] = 38;
v15 = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v13;
v16 = &v13[v15];
LABEL_6:
v17 = strlen(v6);
memcpy(v16, v6, v17);
v18 = &v16[strlen(v6)];
*v18 = 61;
v19 = strlen(v7);
memcpy(v18 + 1, v7, v19);
v18[strlen(v7) + 1] = 0;
*(_QWORD *)(a1 + 8) += v12;
curl_free(v7);
curl_free(v6);
return 0LL;
}
}
else
{
v21 = (char *)malloc(v11 + 2);
*(_QWORD *)a1 = v21;
v16 = v21;
if ( v21 )
goto LABEL_6;
}
curl_free(v7);
}
curl_free(v6);
return 0xFFFFFFFFLL;
}

original_code:
int postdata_append(postdata_t *pd, const char *name, const char *val)
{
    size_t nsz;
    char *name_esc, *val_esc, *nstr, *write_pos;
    name_esc = curl_easy_escape(pd, name, 0);
    if (!name_esc)
        goto oom_name;
    val_esc = curl_easy_escape(pd, val, 0);
    if (!val_esc)
        goto oom_val;
    nsz = strlen(name_esc) + 1 + strlen(val_esc);
    if (pd->str) {
        nstr = realloc(pd->str, pd->str_sz + 1 + nsz + 1);
        if (!nstr)
            goto oom_str;
        nstr[pd->str_sz++] = '&';
        write_pos = &nstr[pd->str_sz];
        pd->str = nstr;
    } else {
        pd->str = malloc(nsz + 1);
        if (!pd->str)
            goto oom_str;
        write_pos = pd->str;
    }
    memcpy(write_pos, name_esc, strlen(name_esc));
    write_pos += strlen(name_esc);
    *write_pos++ = '=';
    memcpy(write_pos, val_esc, strlen(val_esc));
    write_pos += strlen(val_esc);
    *write_pos = 0;
    pd->str_sz += nsz;
    curl_free(val_esc);
    curl_free(name_esc);
    return 0;
oom_str:
    curl_free(val_esc);
oom_val:
    curl_free(name_esc);
oom_name:
    return -1;
}

canonical_original_code:
int postdata_append(struct postdata_s *pd, char *name, char *val)
{
    unsigned long nsz;
    char *name_esc; char *val_esc; char *nstr; char *write_pos;
    name_esc = curl_easy_escape(pd, name, 0);
    if (!name_esc)
        goto oom_name;
    val_esc = curl_easy_escape(pd, val, 0);
    if (!val_esc)
        goto oom_val;
    nsz = strlen(name_esc) + 1 + strlen(val_esc);
    if (pd->str) {
        nstr = realloc(pd->str, pd->str_sz + 1 + nsz + 1);
        if (!nstr)
            goto oom_str;
        nstr[pd->str_sz++] = '&';
        write_pos = &nstr[pd->str_sz];
        pd->str = nstr;
    } else {
        pd->str = malloc(nsz + 1);
        if (!pd->str)
            goto oom_str;
        write_pos = pd->str;
    }
    memcpy(write_pos, name_esc, strlen(name_esc));
    write_pos += strlen(name_esc);
    *write_pos++ = '=';
    memcpy(write_pos, val_esc, strlen(val_esc));
    write_pos += strlen(val_esc);
    *write_pos = 0;
    pd->str_sz += nsz;
    curl_free(val_esc);
    curl_free(name_esc);
    return 0;
oom_str:
    curl_free(val_esc);
oom_val:
    curl_free(name_esc);
oom_name:
    return -1;
}

variable_types:
name
char *

variable_types:
val
char *

variable_types:
nsz
unsigned long

variable_types:
nstr
char *


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

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

original_code:
char *postdata_string(postdata_t *pd)
{
    return pd->str;
}

canonical_original_code:
char *postdata_string(struct postdata_s *pd)
{
    return pd->str;
}

return_type: char *


decompiled_code:
int __fastcall devstate_enum_devices(void (__fastcall *a1)(_QWORD *, __int64), __int64 a2)
{
_QWORD *v2; // rbx

pthread_mutex_lock(&devs_mutex);
v2 = devs;
if ( devs )
{
do
{
a1(v2, a2);
v2 = *(_QWORD **)(v2[8] + 8LL);
}
while ( v2 );
}
return pthread_mutex_unlock(&devs_mutex);
}

canonical_decompiled_code:
int __fastcall func0(void (__fastcall *a1)(_QWORD *, __int64), __int64 a2)
{
_QWORD *v2; // rbx

pthread_mutex_lock(&devs_mutex);
v2 = devs;
if ( devs )
{
do
{
a1(v2, a2);
v2 = *(_QWORD **)(v2[8] + 8LL);
}
while ( v2 );
}
return pthread_mutex_unlock(&devs_mutex);
}

original_code:
void devstate_enum_devices(void (*callback)(devstate_t *dev, void *user), void *user)
{
    devstate_t *dev;
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next)
        callback(dev, user);
    pthread_mutex_unlock(&devs_mutex);
}

canonical_original_code:
void devstate_enum_devices(void (*callback)(struct devstate_s *dev, void *user), void *user)
{
    struct devstate_s *dev;
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next)
        callback(dev, user);
    pthread_mutex_unlock(&devs_mutex);
}

variable_types: void (*)(struct devstate_s { unsigned char serial[5]; long last_sync_time; unsigned int state; char tracker_id[20]; char user_id[20]; struct devstate_priv_s { struct devstate_s *prev; } *priv; } *dev, void *user)

variable_types:
user
void *

user_defined_types: struct devstate_s { unsigned char serial[5]; long last_sync_time; unsigned int state; char tracker_id[20]; char user_id[20]; struct devstate_priv_s *priv; }


decompiled_code:
int __fastcall devstate_record(int *a1, void (__fastcall *a2)(_BYTE *, __int64), __int64 a3)
{
_QWORD **v4; // r14
_BYTE *v5; // rbp
_QWORD *v7; // rax
int v8; // edx

pthread_mutex_lock(&devs_mutex);
v4 = (_QWORD **)devs;
if ( devs )
{
v5 = devs;
while ( *a1 != *(_DWORD *)v5 || *((_BYTE *)a1 + 4) != v5[4] )
{
v5 = *(_BYTE **)(*((_QWORD *)v5 + 8) + 8LL);
if ( !v5 )
goto LABEL_9;
}
}
else
{
LABEL_9:
v5 = calloc(1uLL, 0x48uLL);
if ( !v5 )
{
fwrite("E:devstate: failed to alloc devstate_t\n", 1uLL, 0x27uLL, stderr);
fflush(stderr);
return pthread_mutex_unlock(&devs_mutex);
}
v7 = calloc(1uLL, 0x10uLL);
*((_QWORD *)v5 + 8) = v7;
if ( !v7 )
{
fwrite("E:devstate: failed to alloc devstate_priv_t\n", 1uLL, 0x2CuLL, stderr);
fflush(stderr);
free(v5);
return pthread_mutex_unlock(&devs_mutex);
}
v8 = *a1;
v7[1] = v4;
*(_DWORD *)v5 = v8;
v5[4] = *((_BYTE *)a1 + 4);
if ( v4 )
*v4[8] = v5;
devs = v5;
}
if ( a2 )
a2(v5, a3);
return pthread_mutex_unlock(&devs_mutex);
}

canonical_decompiled_code:
int __fastcall func1(int *a1, void (__fastcall *a2)(_BYTE *, __int64), __int64 a3)
{
_QWORD **v4; // r14
_BYTE *v5; // rbp
_QWORD *v7; // rax
int v8; // edx

pthread_mutex_lock(&devs_mutex);
v4 = (_QWORD **)devs;
if ( devs )
{
v5 = devs;
while ( *a1 != *(_DWORD *)v5 || *((_BYTE *)a1 + 4) != v5[4] )
{
v5 = *(_BYTE **)(*((_QWORD *)v5 + 8) + 8LL);
if ( !v5 )
goto LABEL_9;
}
}
else
{
LABEL_9:
v5 = calloc(1uLL, 0x48uLL);
if ( !v5 )
{
fwrite("E:devstate: failed to alloc devstate_t\n", 1uLL, 0x27uLL, stderr);
fflush(stderr);
return pthread_mutex_unlock(&devs_mutex);
}
v7 = calloc(1uLL, 0x10uLL);
*((_QWORD *)v5 + 8) = v7;
if ( !v7 )
{
fwrite("E:devstate: failed to alloc devstate_priv_t\n", 1uLL, 0x2CuLL, stderr);
fflush(stderr);
free(v5);
return pthread_mutex_unlock(&devs_mutex);
}
v8 = *a1;
v7[1] = v4;
*(_DWORD *)v5 = v8;
v5[4] = *((_BYTE *)a1 + 4);
if ( v4 )
*v4[8] = v5;
devs = v5;
}
if ( a2 )
a2(v5, a3);
return pthread_mutex_unlock(&devs_mutex);
}

original_code:
void devstate_record(uint8_t serial[5], void (*callback)(devstate_t *dev, void *user), void *user)
{
    devstate_t *dev = ((void *)0);
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next) {
        if (!memcmp(serial, dev->serial, sizeof(dev->serial))) {
            goto out;
        }
    }
    dev = calloc(1, sizeof(*dev));
    if (!dev) {
        do { fprintf(stderr, "E:" "devstate" ": " "failed to alloc devstate_t\n"); fflush(stderr); } while (0);
        goto out;
    }
    dev->priv = calloc(1, sizeof(devstate_priv_t));
    if (!dev->priv) {
        do { fprintf(stderr, "E:" "devstate" ": " "failed to alloc devstate_priv_t\n"); fflush(stderr); } while (0);
        free(dev);
        dev = ((void *)0);
        goto out;
    }
    memcpy(dev->serial, serial, sizeof(dev->serial));
    dev->priv->next = devs;
    if (dev->priv->next)
        dev->priv->next->priv->prev = dev;
    devs = dev;
out:
    if (dev && callback)
        callback(dev, user);
    pthread_mutex_unlock(&devs_mutex);
}

canonical_original_code:
void devstate_record(unsigned char serial[5], void (*callback)(struct devstate_s *dev, void *user), void *user)
{
    struct devstate_s *dev = ((void *)0);
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next) {
        if (!memcmp(serial, dev->serial, sizeof(dev->serial))) {
            goto out;
        }
    }
    dev = calloc(1, sizeof(*dev));
    if (!dev) {
        do { fprintf(stderr, "E:" "devstate" ": " "failed to alloc devstate_t\n"); fflush(stderr); } while (0);
        goto out;
    }
    dev->priv = calloc(1, sizeof(devstate_priv_t));
    if (!dev->priv) {
        do { fprintf(stderr, "E:" "devstate" ": " "failed to alloc devstate_priv_t\n"); fflush(stderr); } while (0);
        free(dev);
        dev = ((void *)0);
        goto out;
    }
    memcpy(dev->serial, serial, sizeof(dev->serial));
    dev->priv->next = devs;
    if (dev->priv->next)
        dev->priv->next->priv->prev = dev;
    devs = dev;
out:
    if (dev && callback)
        callback(dev, user);
    pthread_mutex_unlock(&devs_mutex);
}

variable_types:
serial
unsigned char [5]

variable_types: struct devstate_s { unsigned char serial[5]; long last_sync_time; unsigned int state; char tracker_id[20]; char user_id[20]; struct devstate_priv_s { struct devstate_s *prev; } *priv; } *


decompiled_code:
int __fastcall devstate_clean(__int64 a1)
{
_QWORD *v1; // rbx
__int64 *v2; // rax
__int64 v3; // rdx
__int64 v4; // rax

pthread_mutex_lock(&devs_mutex);
v1 = devs;
if ( devs )
{
do
{
if ( v1[1] < a1 )
{
v2 = (__int64 *)v1[8];
v3 = *v2;
if ( *v2 )
*(_QWORD *)(*(_QWORD *)(v3 + 64) + 8LL) = v2[1];
v4 = v2[1];
if ( v4 )
**(_QWORD **)(v4 + 64) = v3;
free(v1);
}
v1 = *(_QWORD **)(v1[8] + 8LL);
}
while ( v1 );
}
return pthread_mutex_unlock(&devs_mutex);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
_QWORD *v1; // rbx
__int64 *v2; // rax
__int64 v3; // rdx
__int64 v4; // rax

pthread_mutex_lock(&devs_mutex);
v1 = devs;
if ( devs )
{
do
{
if ( v1[1] < a1 )
{
v2 = (__int64 *)v1[8];
v3 = *v2;
if ( *v2 )
*(_QWORD *)(*(_QWORD *)(v3 + 64) + 8LL) = v2[1];
v4 = v2[1];
if ( v4 )
**(_QWORD **)(v4 + 64) = v3;
free(v1);
}
v1 = *(_QWORD **)(v1[8] + 8LL);
}
while ( v1 );
}
return pthread_mutex_unlock(&devs_mutex);
}

original_code:
void devstate_clean(long discard_prior_to)
{
    devstate_t *dev;
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next) {
        if (dev->last_sync_time >= discard_prior_to)
            continue;
        if (dev->priv->prev)
            dev->priv->prev->priv->next = dev->priv->next;
        if (dev->priv->next)
            dev->priv->next->priv->prev = dev->priv->prev;
        free(dev);
    }
    pthread_mutex_unlock(&devs_mutex);
}

canonical_original_code:
void devstate_clean(long discard_prior_to)
{
    struct devstate_s *dev;
    pthread_mutex_lock(&devs_mutex);
    for (dev = devs; dev; dev = dev->priv->next) {
        if (dev->last_sync_time >= discard_prior_to)
            continue;
        if (dev->priv->prev)
            dev->priv->prev->priv->next = dev->priv->next;
        if (dev->priv->next)
            dev->priv->next->priv->prev = dev->priv->prev;
        free(dev);
    }
    pthread_mutex_unlock(&devs_mutex);
}

user_defined_types: struct devstate_priv_s { struct devstate_s *prev; }


decompiled_code:
char *get_config_home()
{
char *v1; // rax
char *v2; // rbp
size_t v3; // rbx
void *v4; // rax
char *v5; // r8
char *v6; // rax
char *v7; // rbp
size_t v8; // rbx
void *v9; // rax
char *v10; // rax
__m128i v11; // xmm0
__m128i *v12; // rbx

if ( cfg_home )
return (char *)cfg_home;
v1 = getenv("XDG_CONFIG_HOME");
v2 = v1;
if ( v1 )
{
v3 = strlen(v1);
v4 = malloc(v3 + 9);
cfg_home = (__int64)v4;
if ( v4 )
{
v5 = (char *)memcpy(v4, v2, v3);
strcpy(&v5[v3], "/fitbitd");
return v5;
}
}
v6 = getenv("HOME");
v7 = v6;
if ( v6 )
{
v8 = strlen(v6);
v9 = malloc(v8 + 17);
cfg_home = (__int64)v9;
if ( v9 )
{
v10 = (char *)memcpy(v9, v7, v8);
v11 = _mm_load_si128((const __m128i *)&LC2);
v12 = (__m128i *)&v10[v8];
v5 = v10;
v12[1].m128i_i8[0] = 0;
*v12 = v11;
return v5;
}
}
cfg_home = (__int64)cfg_home_fallback;
return cfg_home_fallback;
}

canonical_decompiled_code:
char *func0()
{
char *v1; // rax
char *v2; // rbp
size_t v3; // rbx
void *v4; // rax
char *v5; // r8
char *v6; // rax
char *v7; // rbp
size_t v8; // rbx
void *v9; // rax
char *v10; // rax
__m128i v11; // xmm0
__m128i *v12; // rbx

if ( cfg_home )
return (char *)cfg_home;
v1 = getenv("XDG_CONFIG_HOME");
v2 = v1;
if ( v1 )
{
v3 = strlen(v1);
v4 = malloc(v3 + 9);
cfg_home = (__int64)v4;
if ( v4 )
{
v5 = (char *)memcpy(v4, v2, v3);
strcpy(&v5[v3], "/fitbitd");
return v5;
}
}
v6 = getenv("HOME");
v7 = v6;
if ( v6 )
{
v8 = strlen(v6);
v9 = malloc(v8 + 17);
cfg_home = (__int64)v9;
if ( v9 )
{
v10 = (char *)memcpy(v9, v7, v8);
v11 = _mm_load_si128((const __m128i *)&LC2);
v12 = (__m128i *)&v10[v8];
v5 = v10;
v12[1].m128i_i8[0] = 0;
*v12 = v11;
return v5;
}
}
cfg_home = (__int64)cfg_home_fallback;
return cfg_home_fallback;
}

original_code:
static char *get_config_home(void)
{
    char *home;
    if (!cfg_home) {
        home = getenv("XDG_CONFIG_HOME");
        if (home) {
            cfg_home = malloc(strlen(home) + 9);
            if (cfg_home) {
                strcpy(cfg_home, home);
                strcpy(&cfg_home[strlen(home)], "/fitbitd");
            }
        }
    }
    if (!cfg_home) {
        home = getenv("HOME");
        if (home) {
            cfg_home = malloc(strlen(home) + 17);
            if (cfg_home) {
                strcpy(cfg_home, home);
                strcpy(&cfg_home[strlen(home)], "/.config/fitbitd");
            }
        }
    }
    if (!cfg_home)
        cfg_home = cfg_home_fallback;
    return cfg_home;
}

canonical_original_code:
static char *get_config_home()
{
    char *home;
    if (!cfg_home) {
        home = getenv("XDG_CONFIG_HOME");
        if (home) {
            cfg_home = malloc(strlen(home) + 9);
            if (cfg_home) {
                strcpy(cfg_home, home);
                strcpy(&cfg_home[strlen(home)], "/fitbitd");
            }
        }
    }
    if (!cfg_home) {
        home = getenv("HOME");
        if (home) {
            cfg_home = malloc(strlen(home) + 17);
            if (cfg_home) {
                strcpy(cfg_home, home);
                strcpy(&cfg_home[strlen(home)], "/.config/fitbitd");
            }
        }
    }
    if (!cfg_home)
        cfg_home = cfg_home_fallback;
    return cfg_home;
}

variable_types:
home
char *


decompiled_code:
void *prefs_create()
{
char *v0; // rbp
void *v1; // r12
char *v2; // rax
char *v3; // rax
char *v4; // rax
size_t v5; // rax
char *v6; // rax
char *v7; // r13
size_t v8; // rax
char *v9; // rax
char *v10; // rbx
size_t v11; // rax
void *v13; // rdi
struct utsname v14; // [rsp+0h] [rbp-1B8h] BYREF

v0 = get_config_home();
v1 = malloc(0x40uLL);
if ( v1 )
{
v2 = strdup("https://client.fitbit.com/device/tracker/uploadData");
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
{
LABEL_15:
v13 = v1;
v1 = 0LL;
free(v13);
return v1;
}
v3 = strdup("2ea32002-a079-48f4-8020-0badd22939e3");
*((_QWORD *)v1 + 2) = v3;
if ( !v3 )
{
LABEL_14:
free(*((void **)v1 + 1));
goto LABEL_15;
}
v4 = strdup("0.1~ba1f562");
*((_QWORD *)v1 + 3) = v4;
if ( !v4 )
{
LABEL_13:
free(*((void **)v1 + 2));
goto LABEL_14;
}
if ( uname(&v14) )
{
v7 = strdup("fitbitd");
*((_QWORD *)v1 + 4) = v7;
if ( v7 )
{
LABEL_8:
v8 = strlen(v0);
v9 = (char *)malloc(v8 + 6);
*((_QWORD *)v1 + 5) = v9;
v10 = v9;
if ( v9 )
{
strcpy(v9, v0);
v11 = strlen(v0);
*((_QWORD *)v1 + 6) = 0LL;
*((_QWORD *)v1 + 7) = 0LL;
strcpy(&v10[v11], "/lock");
*(_QWORD *)v1 = 0x3840000000ALL;
return v1;
}
free(v7);
goto LABEL_12;
}
}
else
{
v5 = strlen(v14.sysname);
v6 = (char *)malloc(v5 + 9);
*((_QWORD *)v1 + 4) = v6;
if ( v6 )
{
sprintf(v6, "fitbitd-%s", v14.sysname);
v7 = (char *)*((_QWORD *)v1 + 4);
if ( v7 )
goto LABEL_8;
}
}
LABEL_12:
free(*((void **)v1 + 3));
goto LABEL_13;
}
return v1;
}

canonical_decompiled_code:
void *func1()
{
char *v0; // rbp
void *v1; // r12
char *v2; // rax
char *v3; // rax
char *v4; // rax
size_t v5; // rax
char *v6; // rax
char *v7; // r13
size_t v8; // rax
char *v9; // rax
char *v10; // rbx
size_t v11; // rax
void *v13; // rdi
struct utsname v14; // [rsp+0h] [rbp-1B8h] BYREF

v0 = func0();
v1 = malloc(0x40uLL);
if ( v1 )
{
v2 = strdup("https://client.fitbit.com/device/tracker/uploadData");
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
{
LABEL_15:
v13 = v1;
v1 = 0LL;
free(v13);
return v1;
}
v3 = strdup("2ea32002-a079-48f4-8020-0badd22939e3");
*((_QWORD *)v1 + 2) = v3;
if ( !v3 )
{
LABEL_14:
free(*((void **)v1 + 1));
goto LABEL_15;
}
v4 = strdup("0.1~ba1f562");
*((_QWORD *)v1 + 3) = v4;
if ( !v4 )
{
LABEL_13:
free(*((void **)v1 + 2));
goto LABEL_14;
}
if ( uname(&v14) )
{
v7 = strdup("fitbitd");
*((_QWORD *)v1 + 4) = v7;
if ( v7 )
{
LABEL_8:
v8 = strlen(v0);
v9 = (char *)malloc(v8 + 6);
*((_QWORD *)v1 + 5) = v9;
v10 = v9;
if ( v9 )
{
strcpy(v9, v0);
v11 = strlen(v0);
*((_QWORD *)v1 + 6) = 0LL;
*((_QWORD *)v1 + 7) = 0LL;
strcpy(&v10[v11], "/lock");
*(_QWORD *)v1 = 0x3840000000ALL;
return v1;
}
free(v7);
goto LABEL_12;
}
}
else
{
v5 = strlen(v14.sysname);
v6 = (char *)malloc(v5 + 9);
*((_QWORD *)v1 + 4) = v6;
if ( v6 )
{
sprintf(v6, "fitbitd-%s", v14.sysname);
v7 = (char *)*((_QWORD *)v1 + 4);
if ( v7 )
goto LABEL_8;
}
}
LABEL_12:
free(*((void **)v1 + 3));
goto LABEL_13;
}
return v1;
}

original_code:
fitbitd_prefs_t *prefs_create(void)
{
    fitbitd_prefs_t *prefs;
    struct utsname un;
    char *cfg_home = get_config_home();
    prefs = malloc(sizeof(*prefs));
    if (!prefs)
        goto oom_prefs;
    prefs->upload_url = strdup("https://client.fitbit.com/device/tracker/uploadData");
    if (!prefs->upload_url)
        goto oom_upload_url;
    prefs->client_id = strdup("2ea32002-a079-48f4-8020-0badd22939e3");
    if (!prefs->client_id)
        goto oom_client_id;
    prefs->client_version = strdup("0.1~ba1f562");
    if (!prefs->client_version)
        goto oom_client_version;
    if (uname(&un)) {
        prefs->os_name = strdup("fitbitd");
    } else {
        prefs->os_name = malloc(8 + strlen(un.sysname) + 1);
        if (prefs->os_name)
            sprintf(prefs->os_name, "fitbitd-%s", un.sysname);
    }
    if (!prefs->os_name)
        goto oom_os_name;
    prefs->lock_filename = malloc(strlen(cfg_home) + 6);
    if (!prefs->lock_filename)
        goto oom_lock_filename;
    strcpy(prefs->lock_filename, cfg_home);
    strcpy(&prefs->lock_filename[strlen(cfg_home)], "/lock");
    prefs->dump_directory = ((void *)0);
    prefs->log_filename = ((void *)0);
    prefs->scan_delay = 10;
    prefs->sync_delay = 15 * 60;
    return prefs;
oom_lock_filename:
    free(prefs->os_name);
oom_os_name:
    free(prefs->client_version);
oom_client_version:
    free(prefs->client_id);
oom_client_id:
    free(prefs->upload_url);
oom_upload_url:
    free(prefs);
oom_prefs:
    return ((void *)0);
}

canonical_original_code:
struct fitbitd_prefs_t *prefs_create()
{
    struct fitbitd_prefs_t *prefs;
    struct utsname un;
    char *cfg_home = get_config_home();
    prefs = malloc(sizeof(*prefs));
    if (!prefs)
        goto oom_prefs;
    prefs->upload_url = strdup("https://client.fitbit.com/device/tracker/uploadData");
    if (!prefs->upload_url)
        goto oom_upload_url;
    prefs->client_id = strdup("2ea32002-a079-48f4-8020-0badd22939e3");
    if (!prefs->client_id)
        goto oom_client_id;
    prefs->client_version = strdup("0.1~ba1f562");
    if (!prefs->client_version)
        goto oom_client_version;
    if (uname(&un)) {
        prefs->os_name = strdup("fitbitd");
    } else {
        prefs->os_name = malloc(8 + strlen(un.sysname) + 1);
        if (prefs->os_name)
            sprintf(prefs->os_name, "fitbitd-%s", un.sysname);
    }
    if (!prefs->os_name)
        goto oom_os_name;
    prefs->lock_filename = malloc(strlen(cfg_home) + 6);
    if (!prefs->lock_filename)
        goto oom_lock_filename;
    strcpy(prefs->lock_filename, cfg_home);
    strcpy(&prefs->lock_filename[strlen(cfg_home)], "/lock");
    prefs->dump_directory = ((void *)0);
    prefs->log_filename = ((void *)0);
    prefs->scan_delay = 10;
    prefs->sync_delay = 15 * 60;
    return prefs;
oom_lock_filename:
    free(prefs->os_name);
oom_os_name:
    free(prefs->client_version);
oom_client_version:
    free(prefs->client_id);
oom_client_id:
    free(prefs->upload_url);
oom_upload_url:
    free(prefs);
oom_prefs:
    return ((void *)0);
}

variable_types: struct fitbitd_prefs_t { unsigned int scan_delay; unsigned int sync_delay; char *upload_url; char *client_id; char *client_version; char *os_name; char *lock_filename; char *dump_directory; char *log_filename; } *

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }


decompiled_code:
void __fastcall prefs_destroy(void *ptr)
{
free(*((void **)ptr + 7));
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 7));
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void prefs_destroy(fitbitd_prefs_t *prefs)
{
    free(prefs->log_filename);
    free(prefs->dump_directory);
    free(prefs->lock_filename);
    free(prefs->os_name);
    free(prefs->client_version);
    free(prefs->client_id);
    free(prefs->upload_url);
    free(prefs);
}

canonical_original_code:
void prefs_destroy(struct fitbitd_prefs_t *prefs)
{
    free(prefs->log_filename);
    free(prefs->dump_directory);
    free(prefs->lock_filename);
    free(prefs->os_name);
    free(prefs->client_version);
    free(prefs->client_id);
    free(prefs->upload_url);
    free(prefs);
}

user_defined_types: struct fitbitd_prefs_t { unsigned int scan_delay; unsigned int sync_delay; char *upload_url; char *client_id; char *client_version; char *os_name; char *lock_filename; char *dump_directory; char *log_filename; }


variable_types:
buf
unsigned char *

variable_types:
sz
unsigned long

variable_types:
str
unsigned char *

variable_types:
cur
unsigned char *

variable_types:
start
unsigned char *

variable_types: d int

variable_types: dlast int

variable_types: phase int

variable_types:
rem
unsigned long

variable_types:
c
unsigned char

variable_types:
table
int [256]


original_code:
int b64encode(uint8_t *buf, size_t buf_sz, const uint8_t* data, size_t data_sz)
{
   const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   size_t buf_idx = 0;
   size_t x;
   uint32_t n = 0;
   int padCount = data_sz % 3;
   uint8_t n0, n1, n2, n3;
   for (x = 0; x < data_sz; x += 3)
   {
      n = data[x] << 16;
      if((x+1) < data_sz)
         n += data[x+1] << 8;
      if((x+2) < data_sz)
         n += data[x+2];
      n0 = (uint8_t)(n >> 18) & 63;
      n1 = (uint8_t)(n >> 12) & 63;
      n2 = (uint8_t)(n >> 6) & 63;
      n3 = (uint8_t)n & 63;
      if(buf_idx >= buf_sz) return -1;
      buf[buf_idx++] = base64chars[n0];
      if(buf_idx >= buf_sz) return -1;
      buf[buf_idx++] = base64chars[n1];
      if((x+1) < data_sz)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = base64chars[n2];
      }
      if((x+2) < data_sz)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = base64chars[n3];
      }
   }
   if (padCount > 0)
   {
      for (; padCount < 3; padCount++)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = '=';
      }
   }
   if(buf_idx >= buf_sz) return -1;
   buf[buf_idx] = 0;
   return 0;
}

canonical_original_code:
int b64encode(unsigned char *buf, unsigned long buf_sz, unsigned char *data, unsigned long data_sz)
{
   char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   unsigned long buf_idx = 0;
   unsigned long x;
   unsigned int n = 0;
   int padCount = data_sz % 3;
   unsigned char n0; unsigned char n1; unsigned char n2; unsigned char n3;
   for (x = 0; x < data_sz; x += 3)
   {
      n = data[x] << 16;
      if((x+1) < data_sz)
         n += data[x+1] << 8;
      if((x+2) < data_sz)
         n += data[x+2];
      n0 = (unsigned char)(n >> 18) & 63;
      n1 = (unsigned char)(n >> 12) & 63;
      n2 = (unsigned char)(n >> 6) & 63;
      n3 = (unsigned char)n & 63;
      if(buf_idx >= buf_sz) return -1;
      buf[buf_idx++] = base64chars[n0];
      if(buf_idx >= buf_sz) return -1;
      buf[buf_idx++] = base64chars[n1];
      if((x+1) < data_sz)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = base64chars[n2];
      }
      if((x+2) < data_sz)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = base64chars[n3];
      }
   }
   if (padCount > 0)
   {
      for (; padCount < 3; padCount++)
      {
         if(buf_idx >= buf_sz) return -1;
         buf[buf_idx++] = '=';
      }
   }
   if(buf_idx >= buf_sz) return -1;
   buf[buf_idx] = 0;
   return 0;
}

variable_types:
data
unsigned char *

variable_types:
x
unsigned long

variable_types:
n
unsigned int

variable_types: padCount int


decompiled_code:
void __fastcall ant_message_destroy(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void ant_message_destroy(ant_message_t *msg)
{
    free(msg->data);
    free(msg);
}

canonical_original_code:
void ant_message_destroy(struct ant_message_t *msg)
{
    free(msg->data);
    free(msg);
}

variable_types: struct ant_message_t { unsigned char id; unsigned char len; unsigned char *data; } *


original_code:
int ant_message_encode(ant_message_t *msg, uint8_t *buf, size_t sz, size_t *len)
{
    uint8_t cksum = 0;
    int i;
    if (sz < (msg->len + 4)) {
        do { fprintf(stderr, "D:" "ant-message" ": " "buffer too small\n"); fflush(stderr); } while (0);
        return -1;
    }
    buf[0] = 0xa4;
    buf[1] = msg->len;
    buf[2] = msg->id;
    memcpy(&buf[3], msg->data, msg->len);
    for (i = 0; i < (3 + msg->len); i++)
        cksum ^= buf[i];
    buf[3+msg->len] = cksum;
    if (len)
        *len = 4 + msg->len;
    return 0;
}

canonical_original_code:
int ant_message_encode(struct ant_message_t *msg, unsigned char *buf, unsigned long sz, unsigned long *len)
{
    unsigned char cksum = 0;
    int i;
    if (sz < (msg->len + 4)) {
        do { fprintf(stderr, "D:" "ant-message" ": " "buffer too small\n"); fflush(stderr); } while (0);
        return -1;
    }
    buf[0] = 0xa4;
    buf[1] = msg->len;
    buf[2] = msg->id;
    memcpy(&buf[3], msg->data, msg->len);
    for (i = 0; i < (3 + msg->len); i++)
        cksum ^= buf[i];
    buf[3+msg->len] = cksum;
    if (len)
        *len = 4 + msg->len;
    return 0;
}

variable_types:
len
unsigned long *

variable_types:
cksum
unsigned char

variable_types: i int

user_defined_types: struct ant_message_t { unsigned char id; unsigned char len; unsigned char *data; }


decompiled_code:
__kernel_long_t get_uptime()
{
int v0; // er8
__kernel_long_t result; // rax
int *v2; // rax
struct sysinfo v3; // [rsp+0h] [rbp-78h] BYREF

v0 = sysinfo(&v3);
result = v3.uptime;
if ( v0 )
{
v2 = _errno_location();
fprintf(stderr, "E:fitbitd-utils: sysinfo failure %d\n", (unsigned int)*v2);
fflush(stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__kernel_long_t func0()
{
int v0; // er8
__kernel_long_t result; // rax
int *v2; // rax
struct sysinfo v3; // [rsp+0h] [rbp-78h] BYREF

v0 = sysinfo(&v3);
result = v3.uptime;
if ( v0 )
{
v2 = _errno_location();
fprintf(stderr, "E:fitbitd-utils: sysinfo failure %d\n", (unsigned int)*v2);
fflush(stderr);
result = 0LL;
}
return result;
}

original_code:
long get_uptime(void)
{
    struct sysinfo info;
    if (sysinfo(&info)) {
        do { fprintf(stderr, "E:" "fitbitd-utils" ": " "sysinfo failure %d\n", (*__errno_location ())); fflush(stderr); } while (0);
        return 0;
    }
    return info.uptime;
}

canonical_original_code:
long get_uptime()
{
    struct sysinfo info;
    if (sysinfo(&info)) {
        do { fprintf(stderr, "E:" "fitbitd-utils" ": " "sysinfo failure %d\n", (*__errno_location ())); fflush(stderr); } while (0);
        return 0;
    }
    return info.uptime;
}

variable_types: struct sysinfo { long uptime; unsigned long loads[3]; unsigned long totalram; unsigned long freeram; unsigned long sharedram; unsigned long bufferram; unsigned long totalswap; unsigned long freeswap; unsigned short procs; unsigned short pad; unsigned long totalhigh; unsigned long freehigh; unsigned int mem_unit; char _f[-1]; }

return_type: long


repo: pauldmccarthy/ccnet

decompiled_code:
__int64 __fastcall stats_edge_betweenness(__int64 a1, __int64 a2, void *a3)
{
unsigned int v4; // ebx
unsigned int v5; // er14
const void *v7; // rsi
int v8; // [rsp+Ch] [rbp-ACh] BYREF
char v9[16]; // [rsp+10h] [rbp-A8h] BYREF
__int64 v10; // [rsp+20h] [rbp-98h]
char v11[16]; // [rsp+50h] [rbp-68h] BYREF
__int64 v12; // [rsp+60h] [rbp-58h]

v10 = 0LL;
v12 = 0LL;
v4 = graph_num_neighbours(a1, a2);
stats_cache_node_component(a1, (unsigned int)a2, &v8);
if ( (unsigned __int8)edge_array_create(a1, 8LL, v9)
|| (unsigned __int8)edge_array_create(a1, 8LL, v11)
|| (v5 = all_edge_betweenness(a1, (__int64)v9, (__int64)v11, v8), (_BYTE)v5) )
{
if ( v10 )
edge_array_free(v9);
v5 = 1;
if ( v12 )
edge_array_free(v11);
}
else
{
if ( a3 )
{
v7 = (const void *)edge_array_get_all(v11, (unsigned int)a2);
memcpy(a3, v7, 8LL * v4);
}
edge_array_free(v9);
edge_array_free(v11);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, void *a3)
{
unsigned int v4; // ebx
unsigned int v5; // er14
const void *v7; // rsi
int v8; // [rsp+Ch] [rbp-ACh] BYREF
char v9[16]; // [rsp+10h] [rbp-A8h] BYREF
__int64 v10; // [rsp+20h] [rbp-98h]
char v11[16]; // [rsp+50h] [rbp-68h] BYREF
__int64 v12; // [rsp+60h] [rbp-58h]

v10 = 0LL;
v12 = 0LL;
v4 = graph_num_neighbours(a1, a2);
stats_cache_node_component(a1, (unsigned int)a2, &v8);
if ( (unsigned __int8)edge_array_create(a1, 8LL, v9)
|| (unsigned __int8)edge_array_create(a1, 8LL, v11)
|| (v5 = func1(a1, (__int64)v9, (__int64)v11, v8), (_BYTE)v5) )
{
if ( v10 )
edge_array_free(v9);
v5 = 1;
if ( v12 )
edge_array_free(v11);
}
else
{
if ( a3 )
{
v7 = (const void *)edge_array_get_all(v11, (unsigned int)a2);
memcpy(a3, v7, 8LL * v4);
}
edge_array_free(v9);
edge_array_free(v11);
}
return v5;
}

original_code:
uint8_t stats_edge_betweenness(graph_t *g, uint32_t v, double *betweenness) {
  uint32_t nnbrs;
  edge_array_t betw;
  edge_array_t ttlbetw;
  uint32_t cmp;
  betw.vals = ((void *)0);
  ttlbetw.vals = ((void *)0);
  nnbrs = graph_num_neighbours( g, v);
  stats_cache_node_component(g, v, &cmp);
  if (edge_array_create(g, sizeof(double), &betw)) goto fail;
  if (edge_array_create(g, sizeof(double), &ttlbetw)) goto fail;
  if (_all_edge_betweenness(g, &betw, &ttlbetw, cmp)) goto fail;
  if (betweenness != ((void *)0))
    memcpy(betweenness,
           edge_array_get_all(&ttlbetw, v),
           nnbrs*sizeof(double));
  edge_array_free(&betw);
  edge_array_free(&ttlbetw);
  return 0;
fail:
  if (betw.vals != ((void *)0)) edge_array_free(&betw);
  if (ttlbetw.vals != ((void *)0)) edge_array_free(&ttlbetw);
  return 1;
}

canonical_original_code:
unsigned char stats_edge_betweenness(struct _graph *g, unsigned int v, double *betweenness) {
  unsigned int nnbrs;
  struct _edge_array betw;
  struct _edge_array ttlbetw;
  unsigned int cmp;
  betw.vals = ((void *)0);
  ttlbetw.vals = ((void *)0);
  nnbrs = graph_num_neighbours( g, v);
  stats_cache_node_component(g, v, &cmp);
  if (edge_array_create(g, sizeof(double), &betw)) goto fail;
  if (edge_array_create(g, sizeof(double), &ttlbetw)) goto fail;
  if (_all_edge_betweenness(g, &betw, &ttlbetw, cmp)) goto fail;
  if (betweenness != ((void *)0))
    memcpy(betweenness,
           edge_array_get_all(&ttlbetw, v),
           nnbrs*sizeof(double));
  edge_array_free(&betw);
  edge_array_free(&ttlbetw);
  return 0;
fail:
  if (betw.vals != ((void *)0)) edge_array_free(&betw);
  if (ttlbetw.vals != ((void *)0)) edge_array_free(&ttlbetw);
  return 1;
}

variable_types:
v
unsigned int

variable_types:
betweenness
double *

variable_types:
nnbrs
unsigned int

variable_types: struct _edge_array { struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *g; unsigned short valsz; struct _array *vals; struct _graph_event_listener { unsigned long id; void *ctx; void (*edge_added)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx, float wt); void (*edge_removed)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx); } gel; }

variable_types:
cmp
unsigned int

return_type: unsigned char

user_defined_types: struct _edge_array { struct _graph *g; unsigned short valsz; struct _array *vals; struct _graph_event_listener gel; }

user_defined_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); }


decompiled_code:
__int64 __fastcall graph_log_init(__int64 a1)
{
void *v1; // rax
void *v2; // rbp
__int64 result; // rax

v1 = calloc(0x28uLL, 1uLL);
if ( v1 )
{
v2 = v1;
result = array_create(v1, 8LL, 10LL);
if ( !(_BYTE)result )
{
*(_QWORD *)(a1 + 208) = v2;
*(_QWORD *)(a1 + 248) = log_free;
return result;
}
free(v2);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v1; // rax
void *v2; // rbp
__int64 result; // rax

v1 = calloc(0x28uLL, 1uLL);
if ( v1 )
{
v2 = v1;
result = array_create(v1, 8LL, 10LL);
if ( !(_BYTE)result )
{
*(_QWORD *)(a1 + 208) = v2;
*(_QWORD *)(a1 + 248) = log_free;
return result;
}
free(v2);
}
return 1LL;
}

original_code:
uint8_t graph_log_init(graph_t *g) {
  array_t *log;
  log = calloc(sizeof(array_t), 1);
  if (log == ((void *)0)) goto fail;
  if (array_create(log, sizeof(char *), 10)) goto fail;
  g->ctx[ 2] = log;
  g->ctx_free[2] = _log_free;
  return 0;
fail:
  if (log != ((void *)0)) free(log);
  return 1;
}

canonical_original_code:
unsigned char graph_log_init(struct _graph *g) {
  struct _array *log;
  log = calloc(sizeof(array_t), 1);
  if (log == ((void *)0)) goto fail;
  if (array_create(log, sizeof(char *), 10)) goto fail;
  g->ctx[ 2] = log;
  g->ctx_free[2] = _log_free;
  return 0;
fail:
  if (log != ((void *)0)) free(log);
  return 1;
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } *


decompiled_code:
bool __fastcall graph_log_exists(__int64 a1)
{
return *(_QWORD *)(a1 + 208) != 0LL;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 208) != 0LL;
}

original_code:
uint8_t graph_log_exists(graph_t *g) {
  return g->ctx[2] != ((void *)0) ? 1 : 0;
}

canonical_original_code:
unsigned char graph_log_exists(struct _graph *g) {
  return g->ctx[2] != ((void *)0) ? 1 : 0;
}

user_defined_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); }


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

v1 = *(_QWORD *)(a1 + 208);
if ( v1 )
result = *(unsigned __int16 *)(v1 + 4);
else
result = 0LL;
return result;
}

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

v1 = *(_QWORD *)(a1 + 208);
if ( v1 )
result = *(unsigned __int16 *)(v1 + 4);
else
result = 0LL;
return result;
}

original_code:
uint16_t graph_log_num_msgs(graph_t *g) {
  array_t *log;
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  return log->size;
  return 0;
}

canonical_original_code:
unsigned short graph_log_num_msgs(struct _graph *g) {
  struct _array *log;
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  return log->size;
  return 0;
}

return_type: unsigned short


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

result = *(_QWORD *)(a1 + 208);
if ( result )
{
if ( (unsigned int)a2 >= *(_DWORD *)(result + 4) )
result = 0LL;
else
result = *(_QWORD *)array_getd(*(_QWORD *)(a1 + 208), a2);
}
return result;
}

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

result = *(_QWORD *)(a1 + 208);
if ( result )
{
if ( (unsigned int)a2 >= *(_DWORD *)(result + 4) )
result = 0LL;
else
result = *(_QWORD *)array_getd(*(_QWORD *)(a1 + 208), a2);
}
return result;
}

original_code:
char * graph_log_get_msg(graph_t *g, uint16_t i) {
  array_t *log;
  log = g->ctx[2];
  if (log == ((void *)0)) return ((void *)0);
  if (i >= log->size) return ((void *)0);
  return *(char **)array_getd(log, i);
}

canonical_original_code:
char *graph_log_get_msg(struct _graph *g, unsigned short i) {
  struct _array *log;
  log = g->ctx[2];
  if (log == ((void *)0)) return ((void *)0);
  if (i >= log->size) return ((void *)0);
  return *(char **)array_getd(log, i);
}

variable_types:
i
unsigned short


decompiled_code:
__int64 __fastcall graph_log_add(__int64 a1, const char *a2)
{
__int64 v2; // r12
size_t v3; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = *(_QWORD *)(a1 + 208);
ptr = 0LL;
if ( !v2 )
return 0LL;
v3 = strlen(a2);
ptr = malloc((unsigned int)(v3 + 1));
if ( ptr )
{
memcpy(ptr, a2, v3 + 1);
if ( !(unsigned __int8)array_append(v2, &ptr) )
return 0LL;
if ( ptr )
free(ptr);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
__int64 v2; // r12
size_t v3; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = *(_QWORD *)(a1 + 208);
ptr = 0LL;
if ( !v2 )
return 0LL;
v3 = strlen(a2);
ptr = malloc((unsigned int)(v3 + 1));
if ( ptr )
{
memcpy(ptr, a2, v3 + 1);
if ( !(unsigned __int8)array_append(v2, &ptr) )
return 0LL;
if ( ptr )
free(ptr);
}
return 1LL;
}

original_code:
uint8_t graph_log_add(graph_t *g, char *msg) {
  array_t *log;
  char *msgcpy;
  uint32_t len;
  msgcpy = ((void *)0);
  len = strlen(msg);
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  msgcpy = malloc(len+1);
  if (msgcpy == ((void *)0)) goto fail;
  strcpy(msgcpy, msg);
  if (array_append(log, &msgcpy)) goto fail;
  return 0;
fail:
  if (msgcpy!= ((void *)0)) free(msgcpy);
  return 1;
}

canonical_original_code:
unsigned char graph_log_add(struct _graph *g, char *msg) {
  struct _array *log;
  char *msgcpy;
  unsigned int len;
  msgcpy = ((void *)0);
  len = strlen(msg);
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  msgcpy = malloc(len+1);
  if (msgcpy == ((void *)0)) goto fail;
  strcpy(msgcpy, msg);
  if (array_append(log, &msgcpy)) goto fail;
  return 0;
fail:
  if (msgcpy!= ((void *)0)) free(msgcpy);
  return 1;
}

variable_types:
msg
char *

variable_types:
msgcpy
char *

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall graph_log_copy(__int64 a1, __int64 a2)
{
unsigned __int16 v3; // ax
int v4; // er13
int v5; // ebx
const char *v6; // rsi

if ( !a1 )
return 1LL;
if ( a2 && (graph_log_exists(a2) || !(unsigned __int8)graph_log_init(a2)) )
{
if ( !graph_log_exists(a1) )
return 0LL;
v3 = graph_log_num_msgs(a1);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = (const char *)graph_log_get_msg(a1, v5);
if ( v6 )
{
if ( (unsigned __int8)graph_log_add(a2, v6) )
break;
}
if ( ++v5 == v4 )
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned __int16 v3; // ax
int v4; // er13
int v5; // ebx
const char *v6; // rsi

if ( !a1 )
return 1LL;
if ( a2 && (func2(a2) || !(unsigned __int8)func1(a2)) )
{
if ( !func2(a1) )
return 0LL;
v3 = func3(a1);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = (const char *)func4(a1, v5);
if ( v6 )
{
if ( (unsigned __int8)func5(a2, v6) )
break;
}
if ( ++v5 == v4 )
return 0LL;
}
}
return 1LL;
}

original_code:
uint8_t graph_log_copy(graph_t *gin, graph_t *gout) {
  uint32_t i;
  uint16_t nmsgs;
  char *msg;
  if (gin == ((void *)0)) goto fail;
  if (gout == ((void *)0)) goto fail;
  if (!graph_log_exists(gout)) {
    if (graph_log_init(gout))
      goto fail;
  }
  if (!graph_log_exists(gin)) return 0;
  nmsgs = graph_log_num_msgs(gin);
  for (i = 0; i < nmsgs; i++) {
    msg = graph_log_get_msg(gin, i);
    if (msg == ((void *)0)) continue;
    if (graph_log_add(gout, msg)) goto fail;
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_log_copy(struct _graph *gin, struct _graph *gout) {
  unsigned int i;
  unsigned short nmsgs;
  char *msg;
  if (gin == ((void *)0)) goto fail;
  if (gout == ((void *)0)) goto fail;
  if (!graph_log_exists(gout)) {
    if (graph_log_init(gout))
      goto fail;
  }
  if (!graph_log_exists(gin)) return 0;
  nmsgs = graph_log_num_msgs(gin);
  for (i = 0; i < nmsgs; i++) {
    msg = graph_log_get_msg(gin, i);
    if (msg == ((void *)0)) continue;
    if (graph_log_add(gout, msg)) goto fail;
  }
  return 0;
fail:
  return 1;
}

variable_types:
gout
struct _graph *

variable_types:
i
unsigned int

variable_types:
nmsgs
unsigned short


decompiled_code:
__int64 __fastcall graph_log_total_len(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
unsigned __int64 v3; // rbx
__int64 v4; // rsi
const char **v5; // rax

v1 = 0;
v2 = *(_QWORD *)(a1 + 208);
if ( v2 && *(_DWORD *)(v2 + 4) )
{
v3 = 0LL;
do
{
v4 = (unsigned int)v3++;
v5 = (const char **)array_getd(v2, v4);
v1 += strlen(*v5);
}
while ( *(unsigned int *)(v2 + 4) > v3 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
unsigned __int64 v3; // rbx
__int64 v4; // rsi
const char **v5; // rax

v1 = 0;
v2 = *(_QWORD *)(a1 + 208);
if ( v2 && *(_DWORD *)(v2 + 4) )
{
v3 = 0LL;
do
{
v4 = (unsigned int)v3++;
v5 = (const char **)array_getd(v2, v4);
v1 += strlen(*v5);
}
while ( *(unsigned int *)(v2 + 4) > v3 );
}
return v1;
}

original_code:
uint16_t graph_log_total_len(graph_t *g) {
  uint64_t i;
  uint16_t len;
  array_t *log;
  char *msg;
  len = 0;
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  for (i = 0; i < log->size; i++) {
    msg = *(char **)array_getd(log, i);
    len += strlen(msg);
  }
  return len;
}

canonical_original_code:
unsigned short graph_log_total_len(struct _graph *g) {
  unsigned long i;
  unsigned short len;
  struct _array *log;
  char *msg;
  len = 0;
  log = g->ctx[2];
  if (log == ((void *)0)) return 0;
  for (i = 0; i < log->size; i++) {
    msg = *(char **)array_getd(log, i);
    len += strlen(msg);
  }
  return len;
}

variable_types:
i
unsigned long

variable_types:
len
unsigned short


decompiled_code:
__int64 __fastcall graph_log_import(__int64 a1, const char *a2, const char *a3)
{
const char *v3; // r14
__int64 v5; // r13
int v6; // ebx
int v7; // er15
unsigned __int16 v8; // ax
unsigned __int16 v9; // r12
int v10; // eax
char *v11; // rax
unsigned __int16 v12; // bx
void *v14; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
v5 = *(_QWORD *)(a1 + 208);
v14 = 0LL;
v6 = strlen(a2);
v7 = v6;
v8 = strlen(a3);
if ( !v5 )
return 0LL;
v9 = v8;
if ( v6 <= 0 )
return 0LL;
while ( 1 )
{
v11 = strstr(v3, a3);
v12 = (_WORD)v11 - (_WORD)v3;
if ( !v11 )
v12 = v7;
if ( v12 )
{
v14 = calloc(v12 + 1, 1uLL);
if ( !v14 )
break;
*((_BYTE *)memcpy(v14, v3, v12) + v12) = 0;
if ( (unsigned __int8)array_append(v5, &v14) )
break;
}
v10 = v12 + v9;
v7 -= v10;
v3 += v10;
if ( v7 <= 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, const char *a3)
{
const char *v3; // r14
__int64 v5; // r13
int v6; // ebx
int v7; // er15
unsigned __int16 v8; // ax
unsigned __int16 v9; // r12
int v10; // eax
char *v11; // rax
unsigned __int16 v12; // bx
void *v14; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
v5 = *(_QWORD *)(a1 + 208);
v14 = 0LL;
v6 = strlen(a2);
v7 = v6;
v8 = strlen(a3);
if ( !v5 )
return 0LL;
v9 = v8;
if ( v6 <= 0 )
return 0LL;
while ( 1 )
{
v11 = strstr(v3, a3);
v12 = (_WORD)v11 - (_WORD)v3;
if ( !v11 )
v12 = v7;
if ( v12 )
{
v14 = calloc(v12 + 1, 1uLL);
if ( !v14 )
break;
*((_BYTE *)memcpy(v14, v3, v12) + v12) = 0;
if ( (unsigned __int8)array_append(v5, &v14) )
break;
}
v10 = v12 + v9;
v7 -= v10;
v3 += v10;
if ( v7 <= 0 )
return 0LL;
}
return 1LL;
}

original_code:
uint8_t graph_log_import(graph_t *g, char *data, char *delim) {
  int32_t len;
  uint16_t dlen;
  array_t *log;
  char *msg;
  char *substr;
  uint16_t substrlen;
  msg = ((void *)0);
  log = g->ctx[2];
  len = strlen(data);
  dlen = strlen(delim);
  if (log == ((void *)0)) return 0;
  while (len > 0) {
    substr = strstr(data, delim);
    if (substr == ((void *)0)) substrlen = len;
    else substrlen = substr - data;
    if (substrlen > 0) {
      msg = calloc(substrlen+1, 1);
      if (msg == ((void *)0)) goto fail;
      memcpy(msg, data, substrlen);
      msg[substrlen] = '\0';
      if (array_append(log, &msg)) goto fail;
    }
    data += (substrlen + dlen);
    len -= (substrlen + dlen);
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_log_import(struct _graph *g, char *data, char *delim) {
  int len;
  unsigned short dlen;
  struct _array *log;
  char *msg;
  char *substr;
  unsigned short substrlen;
  msg = ((void *)0);
  log = g->ctx[2];
  len = strlen(data);
  dlen = strlen(delim);
  if (log == ((void *)0)) return 0;
  while (len > 0) {
    substr = strstr(data, delim);
    if (substr == ((void *)0)) substrlen = len;
    else substrlen = substr - data;
    if (substrlen > 0) {
      msg = calloc(substrlen+1, 1);
      if (msg == ((void *)0)) goto fail;
      memcpy(msg, data, substrlen);
      msg[substrlen] = '\0';
      if (array_append(log, &msg)) goto fail;
    }
    data += (substrlen + dlen);
    len -= (substrlen + dlen);
  }
  return 0;
fail:
  return 1;
}

variable_types:
data
char *

variable_types:
delim
char *

variable_types: len int

variable_types:
dlen
unsigned short

variable_types:
substr
char *

variable_types:
substrlen
unsigned short