decompiled_code:
__int64 __fastcall set_time_bnd(unsigned int a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int16 v4; // dx
float *v5; // rax
float v6; // xmm0_4
__int64 v7; // rbx
__int64 v8; // r13
float v9; // xmm0_4
int *v11; // rax
float v12; // [rsp+Ch] [rbp-6Ch]
unsigned int v13; // [rsp+18h] [rbp-60h] BYREF
char s[6]; // [rsp+1Eh] [rbp-5Ah] BYREF
char v15[4]; // [rsp+24h] [rbp-54h] BYREF
char v16[4]; // [rsp+28h] [rbp-50h] BYREF
float v17; // [rsp+2Ch] [rbp-4Ch] BYREF
float v18; // [rsp+30h] [rbp-48h] BYREF
char v19[9]; // [rsp+37h] [rbp-41h] BYREF
__int64 v20; // [rsp+40h] [rbp-38h] BYREF
__int64 v21; // [rsp+48h] [rbp-30h]

v2 = 144LL * a2;
sprintf(s, "time%i", *(unsigned __int16 *)(stored_um_vars + v2 + 80));
nc_inq_dimid(a1, s, v15);
if ( (unsigned int)nc_inq_dimid(a1, "nv", v16) )
nc_def_dim(a1, "nv", 2LL, v16);
sprintf(v19, "time_bnd%hu", *(unsigned __int16 *)(stored_um_vars + v2 + 80));
if ( (unsigned int)nc_inq_varid(a1, v19, &v13) )
{
nc_def_var(a1, v19, 5LL, 2LL, v15, &v13);
nc_put_att_text(a1, v13, "long_name", 37LL, "start & end times for the cell method");
nc_put_att_text(a1, v13, "units", 5LL, "hours");
}
nc_enddef(a1);
v3 = v2 + stored_um_vars;
v4 = *(_WORD *)(v2 + stored_um_vars + 60);
if ( v4 == 1 )
{
v11 = *(int **)(v3 + 96);
v17 = 0.0;
v18 = *(float *)v11;
nc_put_var_float(a1, v13, &v17);
}
else
{
v5 = *(float **)(v3 + 96);
v6 = *v5;
v12 = (float)(v5[1] - *v5) * 0.5;
if ( v4 )
{
v7 = 0LL;
while ( 1 )
{
v20 = v7;
v8 = 4 * v7;
v21 = 0LL;
v17 = v6 - v12;
nc_put_var1_float(a1, v13, &v20, &v17);
v21 = 1LL;
v9 = v12 + *(float *)(*(_QWORD *)(stored_um_vars + v2 + 96) + 4 * v7++);
v18 = v9;
nc_put_var1_float(a1, v13, &v20, &v18);
if ( *(unsigned __int16 *)(v2 + stored_um_vars + 60) <= (int)v7 )
break;
v6 = *(float *)(*(_QWORD *)(v2 + stored_um_vars + 96) + v8 + 4);
}
}
}
return nc_redef(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int16 v4; // dx
float *v5; // rax
float v6; // xmm0_4
__int64 v7; // rbx
__int64 v8; // r13
float v9; // xmm0_4
int *v11; // rax
float v12; // [rsp+Ch] [rbp-6Ch]
unsigned int v13; // [rsp+18h] [rbp-60h] BYREF
char s[6]; // [rsp+1Eh] [rbp-5Ah] BYREF
char v15[4]; // [rsp+24h] [rbp-54h] BYREF
char v16[4]; // [rsp+28h] [rbp-50h] BYREF
float v17; // [rsp+2Ch] [rbp-4Ch] BYREF
float v18; // [rsp+30h] [rbp-48h] BYREF
char v19[9]; // [rsp+37h] [rbp-41h] BYREF
__int64 v20; // [rsp+40h] [rbp-38h] BYREF
__int64 v21; // [rsp+48h] [rbp-30h]

v2 = 144LL * a2;
sprintf(s, "time%i", *(unsigned __int16 *)(stored_um_vars + v2 + 80));
nc_inq_dimid(a1, s, v15);
if ( (unsigned int)nc_inq_dimid(a1, "nv", v16) )
nc_def_dim(a1, "nv", 2LL, v16);
sprintf(v19, "time_bnd%hu", *(unsigned __int16 *)(stored_um_vars + v2 + 80));
if ( (unsigned int)nc_inq_varid(a1, v19, &v13) )
{
nc_def_var(a1, v19, 5LL, 2LL, v15, &v13);
nc_put_att_text(a1, v13, "long_name", 37LL, "start & end times for the cell method");
nc_put_att_text(a1, v13, "units", 5LL, "hours");
}
nc_enddef(a1);
v3 = v2 + stored_um_vars;
v4 = *(_WORD *)(v2 + stored_um_vars + 60);
if ( v4 == 1 )
{
v11 = *(int **)(v3 + 96);
v17 = 0.0;
v18 = *(float *)v11;
nc_put_var_float(a1, v13, &v17);
}
else
{
v5 = *(float **)(v3 + 96);
v6 = *v5;
v12 = (float)(v5[1] - *v5) * 0.5;
if ( v4 )
{
v7 = 0LL;
while ( 1 )
{
v20 = v7;
v8 = 4 * v7;
v21 = 0LL;
v17 = v6 - v12;
nc_put_var1_float(a1, v13, &v20, &v17);
v21 = 1LL;
v9 = v12 + *(float *)(*(_QWORD *)(stored_um_vars + v2 + 96) + 4 * v7++);
v18 = v9;
nc_put_var1_float(a1, v13, &v20, &v18);
if ( *(unsigned __int16 *)(v2 + stored_um_vars + 60) <= (int)v7 )
break;
v6 = *(float *)(*(_QWORD *)(v2 + stored_um_vars + 96) + v8 + 4);
}
}
}
return nc_redef(a1);
}

original_code:
void set_time_bnd( int ncid, int var_index ) {
    int i, ierr, dim_ids[2], varID;
    char time_bnd_str[9], dim_name[6];
    float dt, tval[2];
    size_t index[2];
     sprintf( dim_name, "time%i", stored_um_vars[var_index].t_dim );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_ids[0] );
     ierr = nc_inq_dimid( ncid, "nv", &dim_ids[1] );
     if ( ierr!=0 ) { ierr = nc_def_dim( ncid, "nv", 2, &dim_ids[1] ); }
     sprintf( time_bnd_str, "time_bnd%hu", stored_um_vars[var_index].t_dim );
     ierr = nc_inq_varid( ncid, time_bnd_str, &varID );
     if ( ierr!=0 ) {
        ierr = nc_def_var( ncid, time_bnd_str, 5, 2, dim_ids, &varID );
        ierr = nc_put_att_text( ncid, varID, "long_name", 37, "start & end times for the cell method" );
        ierr = nc_put_att_text( ncid, varID, "units", 5, "hours" );
     }
     ierr = nc_enddef( ncid );
     if ( stored_um_vars[var_index].nt==1 ) {
        tval[0] = 0.0;
        tval[1] = stored_um_vars[var_index].times[0];
        ierr = nc_put_var_float( ncid, varID, tval );
     } else {
        dt = 0.5*(stored_um_vars[var_index].times[1] - stored_um_vars[var_index].times[0]);
        for ( i=0; i<stored_um_vars[var_index].nt; i++ ) {
            index[0] = i;
            index[1] = 0;
            tval[0] = stored_um_vars[var_index].times[i] - dt;
            ierr = nc_put_var1_float( ncid, varID, index, &tval[0] );
            index[1] = 1;
            tval[1] = stored_um_vars[var_index].times[i] + dt;
            ierr = nc_put_var1_float( ncid, varID, index, &tval[1] );
        }
     }
     ierr = nc_redef( ncid );
     return;
}

canonical_original_code:
void set_time_bnd(int ncid, int var_index) {
    int i; int ierr; int dim_ids[2]; int varID;
    char time_bnd_str[9]; char dim_name[6];
    float dt; float tval[2];
    unsigned long index[2];
     sprintf( dim_name, "time%i", stored_um_vars[var_index].t_dim );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_ids[0] );
     ierr = nc_inq_dimid( ncid, "nv", &dim_ids[1] );
     if ( ierr!=0 ) { ierr = nc_def_dim( ncid, "nv", 2, &dim_ids[1] ); }
     sprintf( time_bnd_str, "time_bnd%hu", stored_um_vars[var_index].t_dim );
     ierr = nc_inq_varid( ncid, time_bnd_str, &varID );
     if ( ierr!=0 ) {
        ierr = nc_def_var( ncid, time_bnd_str, 5, 2, dim_ids, &varID );
        ierr = nc_put_att_text( ncid, varID, "long_name", 37, "start & end times for the cell method" );
        ierr = nc_put_att_text( ncid, varID, "units", 5, "hours" );
     }
     ierr = nc_enddef( ncid );
     if ( stored_um_vars[var_index].nt==1 ) {
        tval[0] = 0.0;
        tval[1] = stored_um_vars[var_index].times[0];
        ierr = nc_put_var_float( ncid, varID, tval );
     } else {
        dt = 0.5*(stored_um_vars[var_index].times[1] - stored_um_vars[var_index].times[0]);
        for ( i=0; i<stored_um_vars[var_index].nt; i++ ) {
            index[0] = i;
            index[1] = 0;
            tval[0] = stored_um_vars[var_index].times[i] - dt;
            ierr = nc_put_var1_float( ncid, varID, index, &tval[0] );
            index[1] = 1;
            tval[1] = stored_um_vars[var_index].times[i] + dt;
            ierr = nc_put_var1_float( ncid, varID, index, &tval[1] );
        }
     }
     ierr = nc_redef( ncid );
     return;
}

variable_types: ncid int

variable_types: ierr int

variable_types: varID int

variable_types: dt float

variable_types:
tval
float [2]

variable_types:
index
unsigned long [2]


decompiled_code:
__int64 __fastcall create_time_dim(unsigned int a1, int a2, __int64 a3)
{
__int64 v3; // rbx
char v5[4]; // [rsp+8h] [rbp-60h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-5Ch] BYREF
char s[6]; // [rsp+11h] [rbp-57h] BYREF
char v8[8]; // [rsp+17h] [rbp-51h] BYREF
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

sprintf(s, "time%i", a3);
v3 = 144LL * a2;
nc_def_dim(a1, s, *(unsigned __int16 *)(stored_um_vars + v3 + 60), v5);
nc_def_var(a1, s, 5LL, 1LL, v5, &v6);
if ( header[7] == 1LL )
sprintf(v8, "gregorian");
else
strcpy(v8, "360_day");
nc_put_att_text(a1, v6, "calendar", 9LL, v8);
strftime(v9, 0x21uLL, "hours since %Y-%m-%d %H:%M:%S", &forecast_reference);
nc_put_att_text(a1, v6, "units", 31LL, v9);
nc_put_att_text(a1, v6, "axis", 1LL, "T");
nc_put_att_text(a1, v6, "standard_name", 4LL, "time");
nc_put_att_text(a1, v6, "long_name", 42LL, "forecast period (end of reporting period)");
nc_enddef(a1);
nc_put_var_float(a1, v6, *(_QWORD *)(stored_um_vars + v3 + 96));
return nc_redef(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, __int64 a3)
{
__int64 v3; // rbx
char v5[4]; // [rsp+8h] [rbp-60h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-5Ch] BYREF
char s[6]; // [rsp+11h] [rbp-57h] BYREF
char v8[8]; // [rsp+17h] [rbp-51h] BYREF
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

sprintf(s, "time%i", a3);
v3 = 144LL * a2;
nc_def_dim(a1, s, *(unsigned __int16 *)(stored_um_vars + v3 + 60), v5);
nc_def_var(a1, s, 5LL, 1LL, v5, &v6);
if ( header[7] == 1LL )
sprintf(v8, "gregorian");
else
strcpy(v8, "360_day");
nc_put_att_text(a1, v6, "calendar", 9LL, v8);
strftime(v9, 0x21uLL, "hours since %Y-%m-%d %H:%M:%S", &forecast_reference);
nc_put_att_text(a1, v6, "units", 31LL, v9);
nc_put_att_text(a1, v6, "axis", 1LL, "T");
nc_put_att_text(a1, v6, "standard_name", 4LL, "time");
nc_put_att_text(a1, v6, "long_name", 42LL, "forecast period (end of reporting period)");
nc_enddef(a1);
nc_put_var_float(a1, v6, *(_QWORD *)(stored_um_vars + v3 + 96));
return nc_redef(a1);
}

original_code:
void create_time_dim( int ncid, int var_index, int time_dim_cnt ) {
     int dimID[1], ierr, varID;
     char time_des[40], dim_name[6], calendar[9];
     sprintf( dim_name, "time%i", time_dim_cnt );
     ierr = nc_def_dim( ncid, dim_name, (size_t ) stored_um_vars[var_index].nt, &dimID[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dimID, &varID );
     if ( header[7]==1 ) { sprintf( calendar, "gregorian" ); }
     else { sprintf( calendar, "360_day" ); }
     ierr = nc_put_att_text( ncid, varID, "calendar", 9, calendar );
     strftime( time_des, 33, "hours since %Y-%m-%d %H:%M:%S", &forecast_reference );
     ierr = nc_put_att_text( ncid, varID, "units", 31, time_des );
     ierr = nc_put_att_text( ncid, varID, "axis", 1, "T" );
     ierr = nc_put_att_text( ncid, varID, "standard_name", 4, "time" );
     ierr = nc_put_att_text( ncid, varID, "long_name", 42, "forecast period (end of reporting period)" );
     ierr = nc_enddef( ncid );
     ierr = nc_put_var_float( ncid, varID, stored_um_vars[var_index].times );
     ierr = nc_redef( ncid );
     return;
}

canonical_original_code:
void create_time_dim(int ncid, int var_index, int time_dim_cnt) {
     int dimID[1]; int ierr; int varID;
     char time_des[40]; char dim_name[6]; char calendar[9];
     sprintf( dim_name, "time%i", time_dim_cnt );
     ierr = nc_def_dim( ncid, dim_name, (unsigned long ) stored_um_vars[var_index].nt, &dimID[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dimID, &varID );
     if ( header[7]==1 ) { sprintf( calendar, "gregorian" ); }
     else { sprintf( calendar, "360_day" ); }
     ierr = nc_put_att_text( ncid, varID, "calendar", 9, calendar );
     strftime( time_des, 33, "hours since %Y-%m-%d %H:%M:%S", &forecast_reference );
     ierr = nc_put_att_text( ncid, varID, "units", 31, time_des );
     ierr = nc_put_att_text( ncid, varID, "axis", 1, "T" );
     ierr = nc_put_att_text( ncid, varID, "standard_name", 4, "time" );
     ierr = nc_put_att_text( ncid, varID, "long_name", 42, "forecast period (end of reporting period)" );
     ierr = nc_enddef( ncid );
     ierr = nc_put_var_float( ncid, varID, stored_um_vars[var_index].times );
     ierr = nc_redef( ncid );
     return;
}

variable_types:
dimID
int [1]

variable_types:
calendar
char [9]

return_type: void


original_code:
void set_temporal_dimensions( int ncid ) {
    float *sums, tol, flag;
    int i, j, num_unique_times;
    sums = (float *) calloc( num_stored_um_fields,sizeof(float) );
    for ( i=0; i<num_stored_um_fields; i++ ) {
    for ( j=0; j<stored_um_vars[i].nt; j++ ) {
        sums[i] += stored_um_vars[i].times[j];
    }
    }
    flag = -1.0;
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( sums[i]>-0.5 ) {
           for ( j=i+1; j<num_stored_um_fields; j++ ) {
               if ( sums[j]>-0.5 ) {
                  tol = (sums[i]-sums[j])*(sums[i]-sums[j]);
                  if ( tol<0.0001 ) { sums[j] = flag; }
               }
           }
           flag = flag-1.0;
        }
    }
    num_unique_times = (int )(-1.0*(flag+1.0));
    j = 0;
    for ( i=0; i<num_stored_um_fields; i++ )
        if ( sums[i]>-0.5 ) { create_time_dim( ncid, i, j ); j++; }
    j = 0;
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( sums[i]>-0.5 ) { stored_um_vars[i].t_dim = (unsigned short int) j; j++; }
        else { stored_um_vars[i].t_dim = (unsigned short int) ( -1.0*(sums[i]+1.0) ); }
    }
    free( sums );
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( (stored_um_vars[i].lbproc==128)||(stored_um_vars[i].lbproc==4096)||(stored_um_vars[i].lbproc==8192) ) {
           set_time_bnd( ncid, i );
           j++;
        }
    }
    return;
}

canonical_original_code:
void set_temporal_dimensions(int ncid) {
    float *sums; float tol; float flag;
    int i; int j; int num_unique_times;
    sums = (float *) calloc( num_stored_um_fields,sizeof(float) );
    for ( i=0; i<num_stored_um_fields; i++ ) {
    for ( j=0; j<stored_um_vars[i].nt; j++ ) {
        sums[i] += stored_um_vars[i].times[j];
    }
    }
    flag = -1.0;
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( sums[i]>-0.5 ) {
           for ( j=i+1; j<num_stored_um_fields; j++ ) {
               if ( sums[j]>-0.5 ) {
                  tol = (sums[i]-sums[j])*(sums[i]-sums[j]);
                  if ( tol<0.0001 ) { sums[j] = flag; }
               }
           }
           flag = flag-1.0;
        }
    }
    num_unique_times = (int )(-1.0*(flag+1.0));
    j = 0;
    for ( i=0; i<num_stored_um_fields; i++ )
        if ( sums[i]>-0.5 ) { create_time_dim( ncid, i, j ); j++; }
    j = 0;
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( sums[i]>-0.5 ) { stored_um_vars[i].t_dim = (unsigned short) j; j++; }
        else { stored_um_vars[i].t_dim = (unsigned short) ( -1.0*(sums[i]+1.0) ); }
    }
    free( sums );
    for ( i=0; i<num_stored_um_fields; i++ ) {
        if ( (stored_um_vars[i].lbproc==128)||(stored_um_vars[i].lbproc==4096)||(stored_um_vars[i].lbproc==8192) ) {
           set_time_bnd( ncid, i );
           j++;
        }
    }
    return;
}

variable_types:
sums
float *

variable_types: tol float

variable_types: flag float

variable_types: i int

variable_types: j int


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

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

original_code:
void status_check( int status, char *message ) {
     if ( status==0 ) {
        printf( "\n %s \n\n", message );
        exit(1);
     }
}

canonical_original_code:
void status_check(int status, char *message) {
     if ( status==0 ) {
        printf( "\n %s \n\n", message );
        exit(1);
     }
}

variable_types: status int

variable_types:
message
char *


usage

decompiled_code:
int usage()
{
puts("\nUsage: um2netcdf.x [ OPTIONS ] <input-file> <stash-file> \n");
puts(" where\n");
puts(" input-file --> file whose contents are to be parsed and transferred to a netCDF");
puts(" file. It can be an UM fields or dump file.\n");
puts(" stash-file --> XML file that contains the metadata definitions of various UM");
puts(" variables. These definitions include units, title, valid values");
puts(" etc...\n");
puts(" The following options can be specified. They MUST appear before the input filename!\n");
puts(" -h used to display this help message");
puts(" -i interpolates all fields onto the thermodynamic grid (eg. P-points on an Arakawa-C grid)");
puts(" -r fields written in reduced precision (eg. INT/FLOAT instead of LONG/DOUBLE)");
puts(" -n output NetCDF file will not contain any NetCDF-4 features (chunking and/or compression)");
puts(" -o <filename> ");
puts(" used to specify a filename to the output NetCDF file");
puts(" -s used to specify a set of stash codes of UM variables that can be selectively extracted");
puts(" from the input UM fields file into the NetCDF output file. Selected stash codes should");
puts(" be in a space-delimited list. Example:\n");
puts(" um2netcdf.x -i -r -o test.nc -s 3209 3210 input.um stash.xml\n");
puts(" -c used to specify the name of the run configuration XML file");
puts(" -b used to specify a set of stash codes of UM variables to be ignored if located in the");
puts(" input UM fields file into the NetCDF output file. Specified stash codes should");
puts(" be in a space-delimited list. Example:\n");
puts(" um2netcdf.x -i -r -o test.nc -b 3209 3210 input.um stash.xml -c config.xml\n");
return puts(" It does not matter which order you put the option flags.\n");
}

canonical_decompiled_code:
int func3()
{
puts("\nUsage: um2netcdf.x [ OPTIONS ] <input-file> <stash-file> \n");
puts(" where\n");
puts(" input-file --> file whose contents are to be parsed and transferred to a netCDF");
puts(" file. It can be an UM fields or dump file.\n");
puts(" stash-file --> XML file that contains the metadata definitions of various UM");
puts(" variables. These definitions include units, title, valid values");
puts(" etc...\n");
puts(" The following options can be specified. They MUST appear before the input filename!\n");
puts(" -h used to display this help message");
puts(" -i interpolates all fields onto the thermodynamic grid (eg. P-points on an Arakawa-C grid)");
puts(" -r fields written in reduced precision (eg. INT/FLOAT instead of LONG/DOUBLE)");
puts(" -n output NetCDF file will not contain any NetCDF-4 features (chunking and/or compression)");
puts(" -o <filename> ");
puts(" used to specify a filename to the output NetCDF file");
puts(" -s used to specify a set of stash codes of UM variables that can be selectively extracted");
puts(" from the input UM fields file into the NetCDF output file. Selected stash codes should");
puts(" be in a space-delimited list. Example:\n");
puts(" um2netcdf.x -i -r -o test.nc -s 3209 3210 input.um stash.xml\n");
puts(" -c used to specify the name of the run configuration XML file");
puts(" -b used to specify a set of stash codes of UM variables to be ignored if located in the");
puts(" input UM fields file into the NetCDF output file. Specified stash codes should");
puts(" be in a space-delimited list. Example:\n");
puts(" um2netcdf.x -i -r -o test.nc -b 3209 3210 input.um stash.xml -c config.xml\n");
return puts(" It does not matter which order you put the option flags.\n");
}

original_code:
void usage() {
     printf( "\nUsage:  um2netcdf.x [ OPTIONS ] <input-file> <stash-file> \n\n" );
     printf( "  where\n\n" );
     printf( "    input-file  --> file whose contents are to be parsed and transferred to a netCDF\n" );
     printf( "                    file. It can be an UM fields or dump file.\n\n" );
     printf( "    stash-file  --> XML file that contains the metadata definitions of various UM\n" );
     printf( "                    variables. These definitions include units, title, valid values\n" );
     printf( "                    etc...\n\n" );
     printf( "  The following options can be specified.  They MUST appear before the input filename!\n\n" );
     printf( "    -h used to display this help message\n" );
     printf( "    -i interpolates all fields onto the thermodynamic grid (eg. P-points on an Arakawa-C grid)\n" );
     printf( "    -r fields written in reduced precision (eg. INT/FLOAT instead of LONG/DOUBLE)\n" );
     printf( "    -n output NetCDF file will not contain any NetCDF-4 features (chunking and/or compression)\n" );
     printf( "    -o <filename> \n");
     printf( "       used to specify a filename to the output NetCDF file\n" );
     printf( "    -s used to specify a set of stash codes of UM variables that can be selectively extracted\n" );
     printf( "       from the input UM fields file into the NetCDF output file. Selected stash codes should\n" );
     printf( "       be in a space-delimited list.  Example:\n\n" );
     printf( "          um2netcdf.x -i -r -o test.nc -s 3209 3210 input.um stash.xml\n\n" );
     printf( "    -c used to specify the name of the run configuration XML file\n" );
     printf( "    -b used to specify a set of stash codes of UM variables to be ignored if located in the\n" );
     printf( "       input UM fields file into the NetCDF output file. Specified stash codes should\n" );
     printf( "       be in a space-delimited list.  Example:\n\n" );
     printf( "            um2netcdf.x -i -r -o test.nc -b 3209 3210 input.um stash.xml -c config.xml\n\n" );
     printf( "   It does not matter which order you put the option flags.\n\n" );
}


decompiled_code:
int ieee_usage_message()
{
puts("\nWARNING: you are attempting to convert an UM Fields or Dump field with");
puts(" fields that are WGDOS-packed. You will need to unpack the input");
puts(" file using the following procedure:\n");
puts("STEP 1: log into FitzRoy or Barometer\n");
puts("STEP 2: set the UMDIR environment variable as so:");
puts(" export UMDIR=/oper/admin/um_fcm/um\n");
puts("STEP 3: Run the IEEE utility that comes with the UM release as so:");
return puts(" /oper/admin/um_fcm/um/vn8.4/ibm/utils/ieee -64e <input_filename> <output_filename>\n");
}

canonical_decompiled_code:
int func4()
{
puts("\nWARNING: you are attempting to convert an UM Fields or Dump field with");
puts(" fields that are WGDOS-packed. You will need to unpack the input");
puts(" file using the following procedure:\n");
puts("STEP 1: log into FitzRoy or Barometer\n");
puts("STEP 2: set the UMDIR environment variable as so:");
puts(" export UMDIR=/oper/admin/um_fcm/um\n");
puts("STEP 3: Run the IEEE utility that comes with the UM release as so:");
return puts(" /oper/admin/um_fcm/um/vn8.4/ibm/utils/ieee -64e <input_filename> <output_filename>\n");
}

original_code:
void ieee_usage_message() {
     printf( "\nWARNING: you are attempting to convert an UM Fields or Dump field with\n" );
     printf( "           fields that are WGDOS-packed.  You will need to unpack the input\n" );
     printf( "           file using the following procedure:\n\n" );
     printf( "STEP 1: log into FitzRoy or Barometer\n\n" );
     printf( "STEP 2: set the UMDIR environment variable as so:\n" );
     printf( "        export UMDIR=/oper/admin/um_fcm/um\n\n" );
     printf( "STEP 3: Run the IEEE utility that comes with the UM release as so:\n" );
     printf( "        /oper/admin/um_fcm/um/vn8.4/ibm/utils/ieee -64e <input_filename> <output_filename>\n\n" );
}


repo: adilinden/repeater-controller

decompiled_code:
void stdout_open()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void stdout_open(char *dev)
{
    return;
}

canonical_original_code:
void stdout_open(char *dev)
{
    return;
}

variable_types:
dev
char *


decompiled_code:
void stdout_setup()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void stdout_setup(int rate)
{
    return;
}

canonical_original_code:
void stdout_setup(int rate)
{
    return;
}

variable_types: rate int


decompiled_code:
size_t __fastcall stdout_write(const void **a1, int *a2)
{
return fwrite(*a1, 1uLL, *a2, stdout);
}

canonical_decompiled_code:
size_t __fastcall func2(const void **a1, int *a2)
{
return fwrite(*a1, 1uLL, *a2, stdout);
}

original_code:
int stdout_write(int16_t **bf, int *nbf)
{
    return fwrite(*bf, 1, *nbf, stdout);
}

canonical_original_code:
int stdout_write(short **bf, int *nbf)
{
    return fwrite(*bf, 1, *nbf, stdout);
}

variable_types:
bf
short **

variable_types:
nbf
int *

return_type: int


decompiled_code:
void stdout_close()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void stdout_close()
{
    return;
}

canonical_original_code:
void stdout_close()
{
    return;
}


decompiled_code:
int __fastcall dsp_open(const char *a1)
{
int result; // eax

result = open(a1, 2);
fd = result;
if ( result < 0 )
{
fprintf(stderr, "open of %s failed\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = open(a1, 2);
fd = result;
if ( result < 0 )
{
fprintf(stderr, "open of %s failed\n", a1);
exit(1);
}
return result;
}

original_code:
void dsp_open(char *dev)
{
    fd = open(dev, 02);
    if (fd < 0) {
        fprintf(stderr, "open of %s failed\n", dev);
        exit(1);
    }
}


decompiled_code:
int __fastcall dsp_setup(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 16;
if ( ioctl(fd, 0xC0045005uLL, v2) < -1 )
fwrite("SNDCTL_DSP_SETFMT ioctl failed\n", 1uLL, 0x1FuLL, stderr);
v2[0] = 1;
if ( ioctl(fd, 0xC0045006uLL, v2) < -1 )
fwrite("SNDCTL_DSP_CHANNELS ioctl failed\n", 1uLL, 0x21uLL, stderr);
if ( v2[0] != 1 )
fwrite("unable to set channels\n", 1uLL, 0x17uLL, stderr);
v2[0] = a1;
result = ioctl(fd, 0xC0045002uLL, v2);
if ( result < -1 )
result = fwrite("SNDCTL_DSP_SPEED ioctl failed\n", 1uLL, 0x1EuLL, stderr);
if ( v2[0] != a1 )
result = fprintf(stderr, "unable to set sample rate, using %d\n", (unsigned int)v2[0]);
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 16;
if ( ioctl(fd, 0xC0045005uLL, v2) < -1 )
fwrite("SNDCTL_DSP_SETFMT ioctl failed\n", 1uLL, 0x1FuLL, stderr);
v2[0] = 1;
if ( ioctl(fd, 0xC0045006uLL, v2) < -1 )
fwrite("SNDCTL_DSP_CHANNELS ioctl failed\n", 1uLL, 0x21uLL, stderr);
if ( v2[0] != 1 )
fwrite("unable to set channels\n", 1uLL, 0x17uLL, stderr);
v2[0] = a1;
result = ioctl(fd, 0xC0045002uLL, v2);
if ( result < -1 )
result = fwrite("SNDCTL_DSP_SPEED ioctl failed\n", 1uLL, 0x1EuLL, stderr);
if ( v2[0] != a1 )
result = fprintf(stderr, "unable to set sample rate, using %d\n", (unsigned int)v2[0]);
return result;
}

variable_types: a int

variable_types: r int


decompiled_code:
ssize_t __fastcall dsp_write(const void **a1, int *a2)
{
return write(fd, *a1, *a2);
}

canonical_decompiled_code:
ssize_t __fastcall func2(const void **a1, int *a2)
{
return write(fd, *a1, *a2);
}

original_code:
int dsp_write(int16_t **bf, int *nbf)
{
    return write(fd, *bf, *nbf);
}

canonical_original_code:
int dsp_write(short **bf, int *nbf)
{
    return write(fd, *bf, *nbf);
}


decompiled_code:
int dsp_close()
{
return close(fd);
}

canonical_decompiled_code:
int func3()
{
return close(fd);
}

original_code:
void dsp_close()
{
    close(fd);
}

canonical_original_code:
void dsp_close()
{
    close(fd);
}


portctl

decompiled_code:
__int64 __fastcall portctl(char a1, unsigned int a2, const char *a3)
{
__int64 result; // rax
char v4; // [rsp+Dh] [rbp-11Bh] BYREF
char v5; // [rsp+Eh] [rbp-11Ah] BYREF
char v6; // [rsp+Fh] [rbp-119h]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

sprintf(s, "Doing: %s", a3);
do_log(s);
if ( (int)irlpdev_open(s) < 0 )
{
fwrite("Can't open parallel port", 1uLL, 0x18uLL, stderr);
result = a2;
}
else
{
if ( (unsigned int)read_irlpdev(&v5, 2LL) == 2 )
{
if ( a2 == 1 )
{
v4 = a1 | v6;
write_irlpdev(&v4, 1LL);
}
else
{
if ( !a2 )
v4 = v6 & ~a1;
write_irlpdev(&v4, 1LL);
}
}
result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, unsigned int a2, const char *a3)
{
__int64 result; // rax
char v4; // [rsp+Dh] [rbp-11Bh] BYREF
char v5; // [rsp+Eh] [rbp-11Ah] BYREF
char v6; // [rsp+Fh] [rbp-119h]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

sprintf(s, "Doing: %s", a3);
func29(s);
if ( (int)func23(s) < 0 )
{
fwrite("Can't open parallel port", 1uLL, 0x18uLL, stderr);
result = a2;
}
else
{
if ( (unsigned int)func24(&v5, 2LL) == 2 )
{
if ( a2 == 1 )
{
v4 = a1 | v6;
func25(&v4, 1LL);
}
else
{
if ( !a2 )
v4 = v6 & ~a1;
func25(&v4, 1LL);
}
}
result = a2;
}
return result;
}

original_code:
int portctl(char mask, int pin, char *name)
{
    unsigned char out;
    unsigned char c[2];
    char str[255];
    sprintf(str, "Doing: %s", name);
    do_log(str);
    if ( irlpdev_open() < 0 ) {
        fprintf(stderr, "Can't open parallel port");
        return pin;
    }
    if (read_irlpdev(c, 2) != 2) return pin;
    if (pin == 1) out = (c[1] | mask);
    if (pin == 0) out = (c[1] & ~mask);
    if (write_irlpdev(&out, 1) != 1) return pin;
    return pin;
}

variable_types: mask char

variable_types: pin int

variable_types:
name
char *

variable_types:
out
unsigned char

variable_types:
c
unsigned char [2]

variable_types:
str
char [255]


unkey

decompiled_code:
__int64 unkey()
{
portctl(4, 0, "unkey");
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
func7(4, 0, "unkey");
return 0LL;
}

original_code:
int unkey()
{
    int pin = 0;
    char mask = 0x04;
    portctl(mask, pin, "unkey");
    return 0;
}


key

decompiled_code:
__int64 key()
{
portctl(4, 1u, "key");
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
func7(4, 1u, "key");
return 1LL;
}

original_code:
int key()
{
    int pin = 1;
    char mask = 0x04;
    portctl(mask, pin, "key");
    return 1;
}


keyup

decompiled_code:
__int64 keyup()
{
portctl(4, 1u, "keyup");
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
func7(4, 1u, "keyup");
return 1LL;
}

original_code:
int keyup()
{
    int pin = 1;
    char mask = 0x04;
    portctl(mask, pin, "keyup");
    return 1;
}


unmute

decompiled_code:
__int64 unmute()
{
portctl(8, 1u, "unmute");
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
func7(8, 1u, "unmute");
return 0LL;
}

original_code:
int unmute()
{
    int pin = 1;
    char mask = 0x08;
    portctl(mask, pin, "unmute");
    return 0;
}


mute

decompiled_code:
__int64 mute()
{
portctl(8, 0, "mute");
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
func7(8, 0, "mute");
return 1LL;
}

original_code:
int mute()
{
    int pin = 0;
    char mask = 0x08;
    portctl(mask, pin, "mute");
    return 1;
}


ctcssoff

decompiled_code:
__int64 ctcssoff()
{
portctl(16, 1u, "ctcssoff");
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
func7(16, 1u, "ctcssoff");
return 0LL;
}

original_code:
int ctcssoff()
{
    int pin = 1;
    char mask = 0x10;
    portctl(mask, pin, "ctcssoff");
    return 0;
}


ctcsson

decompiled_code:
__int64 ctcsson()
{
portctl(16, 0, "ctcsson");
return 1LL;
}

canonical_decompiled_code:
__int64 func14()
{
func7(16, 0, "ctcsson");
return 1LL;
}

original_code:
int ctcsson()
{
    int pin = 0;
    char mask = 0x10;
    portctl(mask, pin, "ctcsson");
    return 1;
}


fanoff

decompiled_code:
__int64 fanoff()
{
portctl(32, 0, "fanoff");
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
func7(32, 0, "fanoff");
return 0LL;
}

original_code:
int fanoff()
{
    int pin = 0;
    char mask = 0x20;
    portctl(mask, pin, "fanoff");
    return 0;
}


decompiled_code:
__int64 aux4off()
{
portctl(32, 0, "aux4off");
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
func7(32, 0, "aux4off");
return 0LL;
}

original_code:
int aux4off()
{
    int pin = 0;
    char mask = 0x20;
    portctl(mask, pin, "aux4off");
    return 0;
}


fanon

decompiled_code:
__int64 fanon()
{
portctl(32, 1u, "fanon");
return 1LL;
}

canonical_decompiled_code:
__int64 func17()
{
func7(32, 1u, "fanon");
return 1LL;
}

original_code:
int fanon()
{
    int pin = 1;
    char mask = 0x20;
    portctl(mask, pin, "fanon");
    return 1;
}


decompiled_code:
__int64 aux4on()
{
portctl(32, 1u, "aux4on");
return 1LL;
}

canonical_decompiled_code:
__int64 func18()
{
func7(32, 1u, "aux4on");
return 1LL;
}

original_code:
int aux4on()
{
    int pin = 1;
    char mask = 0x20;
    portctl(mask, pin, "aux4on");
    return 1;
}


decompiled_code:
__int64 aux5off()
{
portctl(64, 0, "aux5off");
return 0LL;
}

canonical_decompiled_code:
__int64 func19()
{
func7(64, 0, "aux5off");
return 0LL;
}

original_code:
int aux5off()
{
    int pin = 0;
    char mask = 0x40;
    portctl(mask, pin, "aux5off");
    return 0;
}


decompiled_code:
__int64 aux5on()
{
portctl(64, 1u, "aux5on");
return 1LL;
}

canonical_decompiled_code:
__int64 func20()
{
func7(64, 1u, "aux5on");
return 1LL;
}

original_code:
int aux5on()
{
    int pin = 1;
    char mask = 0x40;
    portctl(mask, pin, "aux5on");
    return 1;
}


ppclaim

decompiled_code:
int ppclaim()
{
int v0; // edi
int result; // eax
int *v2; // rax
int *v3; // rax

if ( fd < 0 )
return -1;
v0 = lockfilefd;
if ( lockfilefd < 0 )
{
lockfilefd = open("/tmp/irlp-lockfile-parport0", 65, 436LL);
v0 = lockfilefd;
if ( lockfilefd < 0 )
{
perror("Can't open lock file /tmp/irlp-lockfile-parport0");
v2 = __errno_location();
exit(*v2);
}
}
if ( flock(v0, 2) < 0 )
{
perror("Can't optain exclusive lock on /tmp/irlp-lockfile-parport0");
v3 = __errno_location();
exit(*v3);
}
result = ioctl(fd, 0x708BuLL);
if ( result )
{
perror("PPCLAIM");
flock(lockfilefd, 8);
result = -1;
}
return result;
}

canonical_decompiled_code:
int func21()
{
int v0; // edi
int result; // eax
int *v2; // rax
int *v3; // rax

if ( fd < 0 )
return -1;
v0 = lockfilefd;
if ( lockfilefd < 0 )
{
lockfilefd = open("/tmp/irlp-lockfile-parport0", 65, 436LL);
v0 = lockfilefd;
if ( lockfilefd < 0 )
{
perror("Can't open lock file /tmp/irlp-lockfile-parport0");
v2 = __errno_location();
exit(*v2);
}
}
if ( flock(v0, 2) < 0 )
{
perror("Can't optain exclusive lock on /tmp/irlp-lockfile-parport0");
v3 = __errno_location();
exit(*v3);
}
result = ioctl(fd, 0x708BuLL);
if ( result )
{
perror("PPCLAIM");
flock(lockfilefd, 8);
result = -1;
}
return result;
}

original_code:
int ppclaim() {
    if( fd < 0 )
        return -1;
    if( lockfilefd < 0 ) {
        lockfilefd = open("/tmp/irlp-lockfile-parport0", 01|0100, 0664);
        if( lockfilefd < 0 ) {
            perror("Can't open lock file ""/tmp/irlp-lockfile-parport0");
            exit((*__errno_location ()));
        }
    }
    if( flock(lockfilefd, 2) < 0 ) {
        perror("Can't optain exclusive lock on ""/tmp/irlp-lockfile-parport0");
        exit((*__errno_location ()));
    }
    if( ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x8b)) << 0) | ((0) << ((0 +8)+8)))) ) {
        perror("PPCLAIM");
           flock(lockfilefd, 8);
        return -1;
    }
    return 0;
}


pprelease

decompiled_code:
__int64 pprelease()
{
unsigned int v0; // er12

if ( fd < 0 )
{
v0 = -1;
}
else
{
v0 = ioctl(fd, 0x708CuLL);
if ( v0 )
{
v0 = -1;
perror("PPRELEASE");
}
}
flock(lockfilefd, 8);
return v0;
}

canonical_decompiled_code:
__int64 func22()
{
unsigned int v0; // er12

if ( fd < 0 )
{
v0 = -1;
}
else
{
v0 = ioctl(fd, 0x708CuLL);
if ( v0 )
{
v0 = -1;
perror("PPRELEASE");
}
}
flock(lockfilefd, 8);
return v0;
}

variable_types: ret int


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

result = (unsigned int)fd;
if ( fd < 0 )
{
fd = open("/dev/parport0", 2);
if ( fd < 0 )
{
perror("open(\"/dev/parport0\") failed.");
result = 0xFFFFFFFFLL;
}
else if ( ppclaim() < 0 )
{
perror("Trial PPCLAIM failed on /dev/parport0");
close(fd);
result = 0xFFFFFFFFLL;
fd = -1;
}
else
{
pprelease();
result = (unsigned int)fd;
}
}
return result;
}

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

result = (unsigned int)fd;
if ( fd < 0 )
{
fd = open("/dev/parport0", 2);
if ( fd < 0 )
{
perror("open(\"/dev/parport0\") failed.");
result = 0xFFFFFFFFLL;
}
else if ( func21() < 0 )
{
perror("Trial PPCLAIM failed on /dev/parport0");
close(fd);
result = 0xFFFFFFFFLL;
fd = -1;
}
else
{
func22();
result = (unsigned int)fd;
}
}
return result;
}

original_code:
int irlpdev_open() {
    if( fd >= 0 )
        return fd;
    if( (fd = open("/dev/parport0", 02)) < 0 ) {
        perror("open(\"/dev/parport0\") failed.");
        return -1;
    }
    if( ppclaim() < 0 ) {
        perror("Trial PPCLAIM failed on /dev/parport0");
        close(fd);
        fd = -1;
        return -1;
    }
    pprelease();
    return fd;
}


decompiled_code:
__int64 __fastcall read_irlpdev(__int64 a1, int a2)
{
unsigned int v2; // er12
int v4; // er12

if ( ppclaim() < 0 )
return (unsigned int)-1;
v2 = 0;
if ( a2 > 0 )
{
v4 = fd;
if ( ioctl(fd, 0x80017081uLL, a1) )
{
v2 = -1;
perror("PPRSTATUS");
pprelease();
return v2;
}
if ( a2 == 1 )
{
v2 = 1;
}
else
{
if ( ioctl(v4, 0x80017085uLL, a1 + 1) )
{
v2 = -1;
perror("PPRDATA");
pprelease();
return v2;
}
v2 = 2;
}
}
pprelease();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, int a2)
{
unsigned int v2; // er12
int v4; // er12

if ( func21() < 0 )
return (unsigned int)-1;
v2 = 0;
if ( a2 > 0 )
{
v4 = fd;
if ( ioctl(fd, 0x80017081uLL, a1) )
{
v2 = -1;
perror("PPRSTATUS");
func22();
return v2;
}
if ( a2 == 1 )
{
v2 = 1;
}
else
{
if ( ioctl(v4, 0x80017085uLL, a1 + 1) )
{
v2 = -1;
perror("PPRDATA");
func22();
return v2;
}
v2 = 2;
}
}
func22();
return v2;
}

variable_types:
buff
unsigned char *

variable_types: n int

variable_types: k int


decompiled_code:
__int64 __fastcall write_irlpdev(__int64 a1, int a2)
{
unsigned int v2; // er13

v2 = -1;
if ( ppclaim() >= 0 )
{
if ( a2 <= 0 )
{
v2 = 0;
}
else
{
v2 = 1;
if ( ioctl(fd, 0x40017086uLL, a1) )
{
v2 = -1;
perror("PPWDATA");
pprelease();
return v2;
}
}
pprelease();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, int a2)
{
unsigned int v2; // er13

v2 = -1;
if ( func21() >= 0 )
{
if ( a2 <= 0 )
{
v2 = 0;
}
else
{
v2 = 1;
if ( ioctl(fd, 0x40017086uLL, a1) )
{
v2 = -1;
perror("PPWDATA");
func22();
return v2;
}
}
func22();
}
return v2;
}

original_code:
int write_irlpdev(unsigned char *buff, int n) {
    int k;
    if( ppclaim() < 0 )
        return -1;
    k = 0;
    if( n > 0 ) {
        if( ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x86)) << 0) | ((((sizeof(unsigned char)))) << ((0 +8)+8))), buff) ) {
            perror("PPWDATA");
            pprelease();
            return -1;
        }
        k++;
    }
    pprelease();
    return k;
}


timestamp

decompiled_code:
size_t __fastcall timestamp(char *s, int a2)
{
struct tm *v2; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
*s = 0;
v2 = localtime(&v4.tv_sec);
return strftime(s, a2, "%b %d %H:%M:%S", v2);
}

canonical_decompiled_code:
size_t __fastcall func26(char *s, int a2)
{
struct tm *v2; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
*s = 0;
v2 = localtime(&v4.tv_sec);
return strftime(s, a2, "%b %d %H:%M:%S", v2);
}

original_code:
void timestamp(char *buf, int sz)
{
    struct timeval tv;
    if( gettimeofday(&tv, ((void *)0)) < 0 ) buf[0] = 0;
    strftime(buf, sz, "%b %d %H:%M:%S", localtime(&tv.tv_sec));
}

variable_types:
buf
char *

variable_types: sz int

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void __fastcall open_syslog(const char *a1)
{
openlog(a1, 9, 24);
}

canonical_decompiled_code:
void __fastcall func27(const char *a1)
{
openlog(a1, 9, 24);
}

original_code:
void open_syslog(char *nam)
{
    openlog(nam, 0x08 | 0x01, (3<<3));
}

variable_types:
nam
char *


decompiled_code:
void __fastcall write_syslog(char *fmt)
{
syslog(6, fmt);
}

canonical_decompiled_code:
void __fastcall func28(char *fmt)
{
syslog(6, fmt);
}

original_code:
void write_syslog(char *str)
{
    syslog(6, str);
}

variable_types:
str
char *


decompiled_code:
void __fastcall do_log(char *fmt)
{
char v1[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !verbose )
{
if ( !logging )
return;
LABEL_5:
write_syslog(fmt);
return;
}
timestamp(v1, 40);
fprintf(stdout, "[%s] %s\n", v1, fmt);
if ( logging )
goto LABEL_5;
}

canonical_decompiled_code:
void __fastcall func29(char *fmt)
{
char v1[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !verbose )
{
if ( !logging )
return;
LABEL_5:
func28(fmt);
return;
}
func26(v1, 40);
fprintf(stdout, "[%s] %s\n", v1, fmt);
if ( logging )
goto LABEL_5;
}

original_code:
void do_log(char *str)
{
    int sztime = 40;
    char time[sztime];
    if (verbose) {
        timestamp(time, sztime);
        fprintf(stdout, "[%s] %s\n", time, str);
    }
    if (logging) {
        write_syslog(str);
    }
}

canonical_original_code:
void do_log(char *str)
{
    int sztime = 40;
    char time[-1];
    if (verbose) {
        timestamp(time, sztime);
        fprintf(stdout, "[%s] %s\n", time, str);
    }
    if (logging) {
        write_syslog(str);
    }
}

variable_types: sztime int

variable_types:
time
char [-1]


mktones

decompiled_code:
__int64 __fastcall mktones(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v6; // er15
__int64 result; // rax

v6 = (int)(1200.0 / (double)a1);
sditbf = mkwave(a2, a3, a4, v6);
if ( sditbf < 0 )
{
fwrite("Dit waveform generation failed\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
sdahbf = mkwave(a2, a3, a4, 3 * v6);
if ( sditbf < 0 )
{
fwrite("dah waveform generation failed\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
ssgapbf = mksilence(a3, v6, &sgapbf, &nsgapbf);
if ( sditbf < 0 )
{
fwrite("short gap waveform generation failed\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
slgapbf = mksilence(a3, 3 * v6, &lgapbf, &nlgapbf);
if ( sditbf < 0 )
{
fwrite("Long gap waveform generation failed\n", 1uLL, 0x24uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v6; // er15
__int64 result; // rax

v6 = (int)(1200.0 / (double)a1);
sditbf = mkwave(a2, a3, a4, v6);
if ( sditbf < 0 )
{
fwrite("Dit waveform generation failed\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
sdahbf = mkwave(a2, a3, a4, 3 * v6);
if ( sditbf < 0 )
{
fwrite("dah waveform generation failed\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
ssgapbf = mksilence(a3, v6, &sgapbf, &nsgapbf);
if ( sditbf < 0 )
{
fwrite("short gap waveform generation failed\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
slgapbf = mksilence(a3, 3 * v6, &lgapbf, &nlgapbf);
if ( sditbf < 0 )
{
fwrite("Long gap waveform generation failed\n", 1uLL, 0x24uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
}
return result;
}

original_code:
int mktones(int wpm, int freq, int rate, int ampl, int atta, int deca)
{
    int ditlen;
    ditlen = (double) 1200 / wpm;
    sditbf = mkwave(freq, rate, ampl, ditlen, atta, deca, &ditbf, &nditbf);
    if (sditbf < 0) {
        fprintf(stderr, "Dit waveform generation failed\n");
        return -1;
    }
    sdahbf = mkwave(freq, rate, ampl, ditlen * 3, atta, deca, &dahbf, &ndahbf);
    if (sditbf < 0) {
        fprintf(stderr, "dah waveform generation failed\n");
        return -1;
    }
    ssgapbf = mksilence(rate, ditlen, &sgapbf, &nsgapbf);
    if (sditbf < 0) {
        fprintf(stderr, "short gap waveform generation failed\n");
        return -1;
    }
    slgapbf = mksilence(rate, ditlen * 3, &lgapbf, &nlgapbf);
    if (sditbf < 0) {
        fprintf(stderr, "Long gap waveform generation failed\n");
        return -1;
    }
    return 0;
}

variable_types: wpm int

variable_types: freq int

variable_types: rate int

variable_types: ampl int

variable_types: atta int

variable_types: deca int

variable_types: ditlen int


decompiled_code:
int __fastcall code2snd(char *a1)
{
_BYTE *v1; // rbx
char i; // al
int result; // eax

v1 = a1 + 1;
setbuf(stdout, 0LL);
for ( i = *a1; i; i = *(v1 - 1) )
{
switch ( i )
{
case '.':
sound_write(&ditbf, &nditbf, (unsigned int)outp);
if ( verbose )
fputc(46, stderr);
break;
case '-':
sound_write(&dahbf, &ndahbf, (unsigned int)outp);
if ( verbose )
fputc(45, stderr);
break;
case 'S':
sound_write(&lgapbf, &nlgapbf, (unsigned int)outp);
if ( verbose )
fwrite(" ", 1uLL, 2uLL, stderr);
break;
}
++v1;
sound_write(&sgapbf, &nsgapbf, (unsigned int)outp);
}
result = sound_write(&lgapbf, &nlgapbf, (unsigned int)outp);
if ( verbose )
result = fputc(32, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *a1)
{
_BYTE *v1; // rbx
char i; // al
int result; // eax

v1 = a1 + 1;
setbuf(stdout, 0LL);
for ( i = *a1; i; i = *(v1 - 1) )
{
switch ( i )
{
case '.':
sound_write(&ditbf, &nditbf, (unsigned int)outp);
if ( verbose )
fputc(46, stderr);
break;
case '-':
sound_write(&dahbf, &ndahbf, (unsigned int)outp);
if ( verbose )
fputc(45, stderr);
break;
case 'S':
sound_write(&lgapbf, &nlgapbf, (unsigned int)outp);
if ( verbose )
fwrite(" ", 1uLL, 2uLL, stderr);
break;
}
++v1;
sound_write(&sgapbf, &nsgapbf, (unsigned int)outp);
}
result = sound_write(&lgapbf, &nlgapbf, (unsigned int)outp);
if ( verbose )
result = fputc(32, stderr);
return result;
}

original_code:
void code2snd(char *cd)
{
    char ch, w;
    setbuf(stdout, ((void *)0));
    while ((ch = *cd++) != '\0') {
        if (ch == '.') {
            w = sound_write(&ditbf, &nditbf, outp);
            if (verbose) fprintf(stderr, ".");
        }
        if (ch == '-') {
            w = sound_write(&dahbf, &ndahbf, outp);
            if (verbose) fprintf(stderr, "-");
        }
        if (ch == 'S') {
            w = sound_write(&lgapbf, &nlgapbf, outp);
            if (verbose) fprintf(stderr, "  ");
        }
        w = sound_write(&sgapbf, &nsgapbf, outp);
    }
    w = sound_write(&lgapbf, &nlgapbf, outp);
    if (verbose) fprintf(stderr, " ");
}

canonical_original_code:
void code2snd(char *cd)
{
    char ch; char w;
    setbuf(stdout, ((void *)0));
    while ((ch = *cd++) != '\0') {
        if (ch == '.') {
            w = sound_write(&ditbf, &nditbf, outp);
            if (verbose) fprintf(stderr, ".");
        }
        if (ch == '-') {
            w = sound_write(&dahbf, &ndahbf, outp);
            if (verbose) fprintf(stderr, "-");
        }
        if (ch == 'S') {
            w = sound_write(&lgapbf, &nlgapbf, outp);
            if (verbose) fprintf(stderr, "  ");
        }
        w = sound_write(&sgapbf, &nsgapbf, outp);
    }
    w = sound_write(&lgapbf, &nlgapbf, outp);
    if (verbose) fprintf(stderr, " ");
}

variable_types:
cd
char *

variable_types: ch char

variable_types: w char


decompiled_code:
int __fastcall text2code(_BYTE *a1)
{
int v1; // ebp
char *v2; // r13
__int64 v3; // rbx
const unsigned __int16 **v4; // r12
char *v5; // rdi

v1 = (char)*a1;
if ( *a1 )
{
v2 = a1 + 1;
v3 = (char)*a1;
v4 = _ctype_b_loc();
while ( 1 )
{
if ( ((*v4)[v3] & 0x400) != 0 )
v1 = toupper(v1);
if ( (unsigned int)(v1 - 65) <= 0x19 )
break;
if ( (unsigned int)(v1 - 48) <= 9 )
{
v5 = morse[v1 - 22];
goto LABEL_4;
}
if ( v1 == 63 )
{
v5 = "..--..";
goto LABEL_4;
}
if ( v1 == 47 )
{
v5 = "-..-.";
goto LABEL_4;
}
v5 = "S";
if ( v1 == 32 )
{
LABEL_4:
code2snd(v5);
v3 = *v2++;
v1 = (char)v3;
if ( !(_BYTE)v3 )
return code2snd("S");
}
else
{
v3 = *v2++;
v1 = (char)v3;
if ( !(_BYTE)v3 )
return code2snd("S");
}
}
v5 = morse[v1 - 65];
goto LABEL_4;
}
return code2snd("S");
}

original_code:
void text2code(char *tx)
{
    int ch;
    char *cd;
    while ((ch = *tx++) != '\0') {
        if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha))
            ch = toupper(ch);
        if ((ch >= 'A') && (ch <= 'Z'))
            ch = ch - 65;
        else if ((ch >= '0') && (ch <= '9'))
            ch = ch - 22;
        else if (ch == '?')
            ch = 36;
        else if (ch == '/')
            ch = 37;
        else if (ch == ' ')
            ch = 38;
        else
            continue;
        cd = morse[ch];
        code2snd(cd);
    }
    cd = morse[38];
    code2snd(cd);
}

canonical_original_code:
void text2code(char *tx)
{
    int ch;
    char *cd;
    while ((ch = *tx++) != '\0') {
        if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha))
            ch = toupper(ch);
        if ((ch >= 'A') && (ch <= 'Z'))
            ch = ch - 65;
        else if ((ch >= '0') && (ch <= '9'))
            ch = ch - 22;
        else if (ch == '?')
            ch = 36;
        else if (ch == '/')
            ch = 37;
        else if (ch == ' ')
            ch = 38;
        else
            continue;
        cd = morse[ch];
        code2snd(cd);
    }
    cd = morse[38];
    code2snd(cd);
}

variable_types:
tx
char *

variable_types: ch int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v5; // er12
int v6; // ebx
const char *v7; // r14
int v8; // er13
int v9; // er13
const char **v10; // rbx
char *v11; // rdi
int v13; // [rsp+Ch] [rbp-4Ch]
int v14; // [rsp+10h] [rbp-48h]
unsigned int v15; // [rsp+14h] [rbp-44h]

if ( argc <= 1 )
{
LABEL_52:
fwrite("No text given\n", 1uLL, 0xEuLL, stderr);
LABEL_53:
v9 = -1;
}
else
{
v3 = argc;
v5 = 22500;
v15 = 100;
v13 = 660;
v14 = 10;
while ( 1 )
{
v7 = argv[1];
if ( *v7 != 45 )
break;
v8 = *((unsigned __int8 *)v7 + 1);
if ( v8 == 119 && !v7[2] )
v14 = atoi(argv[2]);
v6 = *(unsigned __int8 *)v7;
if ( v6 == 45 )
{
if ( v8 == 111 && !v7[2] )
{
if ( !strcmp(argv[2], "alsa") )
{
outp = 1;
v6 = *(unsigned __int8 *)v7;
}
else
{
if ( !strcmp(argv[2], "dsp") )
outp = 2;
else
outp = 0;
v6 = *(unsigned __int8 *)v7;
}
}
if ( v6 == 45 )
{
if ( v7[1] == 102 && !v7[2] )
v13 = atoi(argv[2]);
if ( v7[1] == 114 && !v7[2] )
v5 = atoi(argv[2]);
if ( v7[1] == 97 && !v7[2] )
v15 = atoi(argv[2]);
}
}
if ( !strcmp(v7, "-da") )
atoi(argv[2]);
if ( !strcmp(v7, "-dd") )
atoi(argv[2]);
if ( v6 == 45 )
{
if ( v7[1] == 104 && !v7[2] )
{
v9 = -1;
fprintf(
stderr,
"Usage: cw [OPTION] [TEXT ...]\n"
"Play morse code from command line.\n"
" -o output method [alsa|dsp|stdout]\n"
" -w word per minute\n"
" -f frequency in hertz\n"
" -r sample rate in samples per second\n"
" -a amplitude in %\n"
" -da attack in milliseconds\n"
" -dd decay in milliseconds\n"
" -v clutter the screen\n"
" -h display this help and exit\n"
"Copyright (c) 2011, Adi Linden <adi@adis.ca>\n",
10LL);
return v9;
}
if ( v7[1] == 118 && !v7[2] )
{
verbose = 1;
++v3;
--argv;
}
}
v3 -= 2;
argv += 2;
if ( v3 <= 1 )
goto LABEL_52;
}
if ( (unsigned int)(v14 - 2) > 0x62 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d word per minute range\n", 2LL, 100LL);
}
else if ( outp <= 0 )
{
v9 = -1;
fwrite("Output format needs to be alsa, dsp, or stdout\n", 1uLL, 0x2FuLL, stderr);
}
else if ( 2 * v13 > v5 )
{
v9 = -1;
fwrite("Sample rate must be more then twice the frequency\n", 1uLL, 0x32uLL, stderr);
}
else if ( (unsigned int)(v13 - 10) > 0x57DA )
{
v9 = -1;
fprintf(stderr, "Support %d to %d Hz frequency range\n", 10LL, 22500LL);
}
else if ( (unsigned int)(v5 - 8000) > 0x8D04 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d samples per second\n", 8000LL, 44100LL);
}
else if ( v15 > 0x64 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d amplitude\n", 0LL, 100LL);
}
else
{
v9 = mktones(v14, v13, v5, v15);
if ( v9 )
goto LABEL_53;
sound_open((unsigned int)outp);
sound_setup((unsigned int)v5, (unsigned int)outp);
if ( verbose )
fwrite("Morse code: ", 1uLL, 0xCuLL, stderr);
v10 = &argv[v3 - 1];
do
{
v11 = (char *)argv[1];
++argv;
text2code(v11);
}
while ( argv != v10 );
if ( verbose )
fputc(10, stderr);
free(ditbf);
free(dahbf);
free(sgapbf);
free(lgapbf);
sound_close((unsigned int)outp);
}
}
return v9;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v5; // er12
int v6; // ebx
const char *v7; // r14
int v8; // er13
int v9; // er13
const char **v10; // rbx
char *v11; // rdi
int v13; // [rsp+Ch] [rbp-4Ch]
int v14; // [rsp+10h] [rbp-48h]
unsigned int v15; // [rsp+14h] [rbp-44h]

if ( argc <= 1 )
{
LABEL_52:
fwrite("No text given\n", 1uLL, 0xEuLL, stderr);
LABEL_53:
v9 = -1;
}
else
{
v3 = argc;
v5 = 22500;
v15 = 100;
v13 = 660;
v14 = 10;
while ( 1 )
{
v7 = argv[1];
if ( *v7 != 45 )
break;
v8 = *((unsigned __int8 *)v7 + 1);
if ( v8 == 119 && !v7[2] )
v14 = atoi(argv[2]);
v6 = *(unsigned __int8 *)v7;
if ( v6 == 45 )
{
if ( v8 == 111 && !v7[2] )
{
if ( !strcmp(argv[2], "alsa") )
{
outp = 1;
v6 = *(unsigned __int8 *)v7;
}
else
{
if ( !strcmp(argv[2], "dsp") )
outp = 2;
else
outp = 0;
v6 = *(unsigned __int8 *)v7;
}
}
if ( v6 == 45 )
{
if ( v7[1] == 102 && !v7[2] )
v13 = atoi(argv[2]);
if ( v7[1] == 114 && !v7[2] )
v5 = atoi(argv[2]);
if ( v7[1] == 97 && !v7[2] )
v15 = atoi(argv[2]);
}
}
if ( !strcmp(v7, "-da") )
atoi(argv[2]);
if ( !strcmp(v7, "-dd") )
atoi(argv[2]);
if ( v6 == 45 )
{
if ( v7[1] == 104 && !v7[2] )
{
v9 = -1;
fprintf(
stderr,
"Usage: cw [OPTION] [TEXT ...]\n"
"Play morse code from command line.\n"
" -o output method [alsa|dsp|stdout]\n"
" -w word per minute\n"
" -f frequency in hertz\n"
" -r sample rate in samples per second\n"
" -a amplitude in %\n"
" -da attack in milliseconds\n"
" -dd decay in milliseconds\n"
" -v clutter the screen\n"
" -h display this help and exit\n"
"Copyright (c) 2011, Adi Linden <adi@adis.ca>\n",
10LL);
return v9;
}
if ( v7[1] == 118 && !v7[2] )
{
verbose = 1;
++v3;
--argv;
}
}
v3 -= 2;
argv += 2;
if ( v3 <= 1 )
goto LABEL_52;
}
if ( (unsigned int)(v14 - 2) > 0x62 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d word per minute range\n", 2LL, 100LL);
}
else if ( outp <= 0 )
{
v9 = -1;
fwrite("Output format needs to be alsa, dsp, or stdout\n", 1uLL, 0x2FuLL, stderr);
}
else if ( 2 * v13 > v5 )
{
v9 = -1;
fwrite("Sample rate must be more then twice the frequency\n", 1uLL, 0x32uLL, stderr);
}
else if ( (unsigned int)(v13 - 10) > 0x57DA )
{
v9 = -1;
fprintf(stderr, "Support %d to %d Hz frequency range\n", 10LL, 22500LL);
}
else if ( (unsigned int)(v5 - 8000) > 0x8D04 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d samples per second\n", 8000LL, 44100LL);
}
else if ( v15 > 0x64 )
{
v9 = -1;
fprintf(stderr, "Support %d to %d amplitude\n", 0LL, 100LL);
}
else
{
v9 = func0(v14, v13, v5, v15);
if ( v9 )
goto LABEL_53;
sound_open((unsigned int)outp);
sound_setup((unsigned int)v5, (unsigned int)outp);
if ( verbose )
fwrite("Morse code: ", 1uLL, 0xCuLL, stderr);
v10 = &argv[v3 - 1];
do
{
v11 = (char *)argv[1];
++argv;
func2(v11);
}
while ( argv != v10 );
if ( verbose )
fputc(10, stderr);
free(ditbf);
free(dahbf);
free(sgapbf);
free(lgapbf);
sound_close((unsigned int)outp);
}
}
return v9;
}

original_code:
int main(int argc, char *argv[])
{
    int wpm = 10;
    int freq = 660;
    int rate = 22500;
    int ampl = 100;
    int atta = 6;
    int deca = 12;
    while (argc > 1 && *argv[1] == '-') {
        if (!strcmp(argv[1], "-w")) {
            wpm = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-o")) {
            if (!strcmp(argv[2], "alsa"))
                outp = 1;
            else if (!strcmp(argv[2], "dsp"))
                outp = 2;
            else if (!strcmp(argv[2], "alsa"))
                outp = 3;
            else
                outp = 0;
        }
        if (!strcmp(argv[1], "-f")) {
            freq = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-r")) {
            rate = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-a")) {
            ampl = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-da")) {
            atta = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-dd")) {
            deca = atoi(argv[2]);
        }
        if (!strcmp(argv[1], "-h")) {
            fprintf(stderr, usage, 10);
            return -1;
        }
        if (!strcmp(argv[1], "-v")) {
            verbose = 1;
            ++argc;
            --argv;
        }
        argc -= 2;
        argv += 2;
    }
    if (!(argc > 1)) {
        fprintf(stderr, "No text given\n");
        return -1;
    }
    if (wpm < 2 || wpm > 100) {
        fprintf(stderr, "Support %d to %d word per minute range\n",
                2, 100);
        return -1;
    }
    if (outp < 1) {
        fprintf(stderr, "Output format needs to be alsa, dsp, or stdout\n");
        return -1;
    }
    if (rate < 2 * freq) {
        fprintf(stderr, "Sample rate must be more then twice the frequency\n");
        return -1;
    }
    if (freq < 10 || freq > 22500) {
        fprintf(stderr, "Support %d to %d Hz frequency range\n",
                10, 22500);
        return -1;
    }
    if (rate < 8000 || rate > 44100) {
        fprintf(stderr, "Support %d to %d samples per second\n",
                8000, 44100);
        return -1;
    }
    if (ampl < 0 || ampl > 100) {
        fprintf(stderr, "Support %d to %d amplitude\n", 0, 100);
        return -1;
    }
    if (mktones(wpm, freq, rate, ampl, atta, deca)) {
        return -1;
    }
    sound_open(outp);
    sound_setup(rate, outp);
    if (verbose) fprintf(stderr, "Morse code: ");
    while (argc > 1) {
        text2code(argv[1]);
        argc--;
        argv++;
    }
    if (verbose) fprintf(stderr, "\n");
    free(ditbf);
    free(dahbf);
    free(sgapbf);
    free(lgapbf);
    sound_close(outp);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
size_t __fastcall sound_open(int a1)
{
switch ( a1 )
{
case 2:
return dsp_open("/dev/dsp");
case 3:
return stdout_open("/dev/dsp");
case 1:
return alsa_open("default");
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(int a1)
{
switch ( a1 )
{
case 2:
return dsp_open("/dev/dsp");
case 3:
return stdout_open("/dev/dsp");
case 1:
return alsa_open("default");
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

original_code:
void sound_open(int outp)
{
    switch (outp) {
        case 1:
            alsa_open("default");
            break;
        case 2:
            dsp_open("/dev/dsp");
            break;
        case 3:
            stdout_open("/dev/dsp");
            break;
        default:
            fprintf(stderr, "Unknown output method\n");
    }
}

variable_types: outp int


decompiled_code:
size_t __fastcall sound_setup(__int64 a1, int a2)
{
switch ( a2 )
{
case 2:
return dsp_setup();
case 3:
return stdout_setup();
case 1:
return alsa_setup();
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1, int a2)
{
switch ( a2 )
{
case 2:
return dsp_setup();
case 3:
return stdout_setup();
case 1:
return alsa_setup();
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

original_code:
void sound_setup(int rate, int outp)
{
    switch (outp) {
        case 1:
            alsa_setup(rate);
            break;
        case 2:
            dsp_setup(rate);
            break;
        case 3:
            stdout_setup(rate);
            break;
        default:
            fprintf(stderr, "Unknown output method\n");
    }
}


decompiled_code:
__int64 __fastcall sound_write(__int64 a1, __int64 a2, int a3)
{
switch ( a3 )
{
case 2:
return dsp_write();
case 3:
return stdout_write();
case 1:
return alsa_write();
}
fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
switch ( a3 )
{
case 2:
return dsp_write();
case 3:
return stdout_write();
case 1:
return alsa_write();
}
fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int sound_write(int16_t **bf, int *nbf, int outp)
{
    switch (outp) {
        case 1:
            return alsa_write(bf, nbf);
            break;
        case 2:
            return dsp_write(bf, nbf);
            break;
        case 3:
            return stdout_write(bf, nbf);
            break;
        default:
            fprintf(stderr, "Unknown output method\n");
    }
    return -1;
}

canonical_original_code:
int sound_write(short **bf, int *nbf, int outp)
{
    switch (outp) {
        case 1:
            return alsa_write(bf, nbf);
            break;
        case 2:
            return dsp_write(bf, nbf);
            break;
        case 3:
            return stdout_write(bf, nbf);
            break;
        default:
            fprintf(stderr, "Unknown output method\n");
    }
    return -1;
}

variable_types:
bf
short **

variable_types:
nbf
int *


decompiled_code:
size_t __fastcall sound_close(int a1)
{
switch ( a1 )
{
case 2:
return dsp_close();
case 3:
return stdout_close();
case 1:
return alsa_close();
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func3(int a1)
{
switch ( a1 )
{
case 2:
return dsp_close();
case 3:
return stdout_close();
case 1:
return alsa_close();
}
return fwrite("Unknown output method\n", 1uLL, 0x16uLL, stderr);
}

original_code:
void sound_close(int outp)
{
    switch (outp) {
        case 1:
            alsa_close();
            break;
        case 2:
            dsp_close();
            break;
        case 3:
            stdout_close();
            break;
        default:
            fprintf(stderr, "Unknown output method\n");
    }
}


decompiled_code:
__pid_t __fastcall fork_script(__pid_t *a1, const char *a2)
{
__pid_t result; // eax

result = fork();
*a1 = result;
if ( !result )
{
usleep(0x186A0u);
system(a2);
usleep(0x186A0u);
exit(0);
}
if ( result < 0 )
exit(-1);
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func0(__pid_t *a1, const char *a2)
{
__pid_t result; // eax

result = fork();
*a1 = result;
if ( !result )
{
usleep(0x186A0u);
system(a2);
usleep(0x186A0u);
exit(0);
}
if ( result < 0 )
exit(-1);
return result;
}

original_code:
void fork_script(pid_t *pid, const char *script)
{
    *pid = fork();
    if (*pid == 0) {
        usleep(100 * 1000);
        system(script);
        usleep(100 * 1000);
        exit(0);
    }
    if (*pid < 0) {
        exit(-1);
    }
}

canonical_original_code:
void fork_script(int *pid, char *script)
{
    *pid = fork();
    if (*pid == 0) {
        usleep(100 * 1000);
        system(script);
        usleep(100 * 1000);
        exit(0);
    }
    if (*pid < 0) {
        exit(-1);
    }
}

variable_types:
pid
int *

variable_types:
script
char *


decompiled_code:
__int64 __fastcall do_ct(__pid_t *a1)
{
char v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( *a1 )
return do_log("Failed: courtesy");
fork_script(a1, "courtesy");
sprintf(v2, "Script: [%d] courtesy", (unsigned int)*a1);
return do_log(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__pid_t *a1)
{
char v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( *a1 )
return do_log("Failed: courtesy");
func0(a1, "courtesy");
sprintf(v2, "Script: [%d] courtesy", (unsigned int)*a1);
return do_log(v2);
}

original_code:
void do_ct(pid_t *pid)
{
    char m[30];
    if (!*pid) {
        fork_script(pid, "courtesy");
        sprintf(m, "Script: [%d] " "courtesy", *pid);
        do_log(m);
    }
    else {
        do_log("Failed: " "courtesy");
    }
}

canonical_original_code:
void do_ct(int *pid)
{
    char m[30];
    if (!*pid) {
        fork_script(pid, "courtesy");
        sprintf(m, "Script: [%d] " "courtesy", *pid);
        do_log(m);
    }
    else {
        do_log("Failed: " "courtesy");
    }
}

variable_types:
m
char [30]


decompiled_code:
__int64 __fastcall do_id(__pid_t *a1)
{
char v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( *a1 )
return do_log("Failed: ider");
fork_script(a1, "ider");
sprintf(v2, "Script: [%d] ider", (unsigned int)*a1);
return do_log(v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__pid_t *a1)
{
char v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( *a1 )
return do_log("Failed: ider");
func0(a1, "ider");
sprintf(v2, "Script: [%d] ider", (unsigned int)*a1);
return do_log(v2);
}

original_code:
void do_id(pid_t *pid)
{
    char m[30];
    if (!*pid) {
        fork_script(pid, "ider");
        sprintf(m, "Script: [%d] " "ider", *pid);
        do_log(m);
    }
    else {
        do_log("Failed: " "ider");
    }
}

canonical_original_code:
void do_id(int *pid)
{
    char m[30];
    if (!*pid) {
        fork_script(pid, "ider");
        sprintf(m, "Script: [%d] " "ider", *pid);
        do_log(m);
    }
    else {
        do_log("Failed: " "ider");
    }
}


dnow

decompiled_code:
double dnow()
{
double result; // xmm0_8
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

result = 0.0;
if ( gettimeofday(&v1, 0LL) >= 0 )
result = ((double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec)) * 1000.0;
return result;
}

canonical_decompiled_code:
double func4()
{
double result; // xmm0_8
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

result = 0.0;
if ( gettimeofday(&v1, 0LL) >= 0 )
result = ((double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec)) * 1000.0;
return result;
}

original_code:
double dnow()
{
    struct timeval tv;
    if( gettimeofday(&tv, ((void *)0)) < 0 ) return (0);
    else return(1000*((double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec));
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rcx
const char *v4; // rax
__pid_t v6; // ebp
int v7; // er15
int v8; // er14
int v9; // ebx
char v10; // r12
__pid_t v11; // eax
bool v12; // zf
int v13; // edx
__pid_t v14; // eax
bool v15; // r13
__pid_t v16; // eax
bool v17; // zf
int v18; // edx
__int64 v19; // rsi
unsigned __int8 v20; // dl
char v21; // r13
int v22; // eax
double v23; // xmm0_8
double v24; // xmm0_8
int v25; // eax
double v26; // [rsp+0h] [rbp-A8h]
int v27; // [rsp+8h] [rbp-A0h]
int v28; // [rsp+Ch] [rbp-9Ch]
double v29; // [rsp+10h] [rbp-98h]
int v30; // [rsp+18h] [rbp-90h]
int v31; // [rsp+1Ch] [rbp-8Ch]
double v32; // [rsp+20h] [rbp-88h]
int v33; // [rsp+28h] [rbp-80h]
int v34; // [rsp+2Ch] [rbp-7Ch]
double v35; // [rsp+30h] [rbp-78h]
double v36; // [rsp+38h] [rbp-70h]
char v37; // [rsp+38h] [rbp-70h]
int v38; // [rsp+40h] [rbp-68h]
unsigned __int8 v39; // [rsp+47h] [rbp-61h]
unsigned __int8 v40; // [rsp+47h] [rbp-61h]
double v41; // [rsp+48h] [rbp-60h]
char v42[2]; // [rsp+56h] [rbp-52h] BYREF
__pid_t v43; // [rsp+58h] [rbp-50h] BYREF
__pid_t v44; // [rsp+5Ch] [rbp-4Ch] BYREF
struct timespec requested_time; // [rsp+60h] [rbp-48h] BYREF

v43 = 0;
v44 = 0;
if ( argc <= 1 )
{
LABEL_15:
if ( logging )
open_syslog("repeater", argv, envp);
do_log("Starting: repeater, version 20130112");
if ( (int)irlpdev_open("Starting: repeater, version 20130112", argv) < 0 )
{
fwrite("Can't access parallel port", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
v6 = 0;
v7 = 1;
requested_time.tv_sec = 0LL;
v8 = 0;
requested_time.tv_nsec = 5000000LL;
v9 = unkey(0LL);
v34 = 0;
v31 = mute(0LL);
v30 = 0;
v33 = 0;
v27 = 1;
v28 = 0;
v38 = 0;
v36 = 0.0;
v35 = 0.0;
v29 = 0.0;
v32 = 0.0;
v26 = 0.0;
v41 = 0.0;
while ( 1 )
{
v19 = 2LL;
if ( (unsigned int)read_irlpdev(v42, 2LL) != 2 )
{
v19 = 1LL;
fwrite("Can't read parallel port", 1uLL, 0x18uLL, stderr);
}
v20 = v42[0];
v21 = v42[1] & 2;
v10 = (unsigned __int8)v42[0] >> 7;
if ( v9 )
{
if ( !v30 )
{
v37 = v42[0];
v22 = fanon(0LL);
v20 = v37;
v30 = v22;
}
v39 = v20;
v23 = dnow();
v20 = v39;
v36 = v23;
}
else if ( v30 )
{
v40 = v42[0];
v24 = dnow();
v20 = v40;
if ( v24 - v36 > 300000.0 )
{
v25 = fanoff(0LL, v19, v40);
v20 = v40;
v30 = v25;
}
}
if ( v10 )
break;
if ( !v31 )
v31 = mute(0LL);
LABEL_73:
if ( v21 )
{
if ( v9 )
{
v10 |= v21;
v26 = dnow();
v32 = dnow();
if ( v6 )
{
v34 = v6;
v7 = 0;
goto LABEL_22;
}
LABEL_104:
v34 = 1;
v7 = 0;
LABEL_105:
if ( v33 )
{
v6 = 0;
check_script(&v43);
goto LABEL_32;
}
if ( dnow() - v35 <= 10.0 )
goto LABEL_24;
goto LABEL_112;
}
v10 |= v21;
v9 = keyup(0LL);
v35 = dnow();
v26 = dnow();
v32 = dnow();
if ( !v6 )
goto LABEL_104;
v34 = v6;
v7 = 0;
LABEL_98:
if ( !v9 )
{
v9 = keyup(0LL);
v35 = dnow();
}
LABEL_22:
v26 = dnow();
if ( !v33 && dnow() - v35 > 10.0 )
{
LABEL_112:
do_log("Shortkey exceeded");
v33 = 1;
}
if ( v10 )
goto LABEL_24;
goto LABEL_76;
}
if ( v6 )
goto LABEL_98;
if ( v10 )
goto LABEL_105;
LABEL_76:
if ( !v28 && !(v43 | v27) )
{
if ( v34 )
{
if ( dnow() - v32 > 300.0 )
{
do_ct(&v43);
v38 = v34;
v6 = v34;
}
}
else if ( dnow() - v32 > 1000.0 )
{
do_ct(&v43);
check_script(&v43);
v6 = v43;
if ( v43 )
{
v27 = 0;
v10 = 0;
v6 = 1;
v38 = 1;
}
else
{
v38 = 0;
v10 = 0;
v27 = 1;
}
goto LABEL_32;
}
}
v10 = 0;
LABEL_24:
check_script(&v43);
v11 = v43;
if ( !v43 )
{
v12 = (v6 & v38) == 0;
v13 = v6 & v38;
if ( (v6 & v38) == 0 )
v13 = v27;
if ( (v6 & v38) != 0 )
v6 = 0;
if ( v12 )
v11 = v38;
v27 = v13;
v38 = v11;
}
LABEL_32:
if ( !(v7 | v8) )
{
v29 = dnow();
do_log("ID: immediate");
if ( !v44 )
{
LABEL_89:
if ( !v10 && v9 && (v27 & 1) != 0 )
{
v6 = 1;
do_id(&v44);
v28 = 1;
v29 = dnow();
}
if ( dnow() - v29 > 480000.0 )
{
v6 = 1;
do_id(&v44);
v28 = 1;
v29 = dnow();
}
}
v8 = 1;
v15 = v9 != 0;
goto LABEL_44;
}
if ( v8 == 3 && (v7 & 1) == 0 )
{
do_log("ID: delayed");
v14 = v44;
LABEL_36:
v8 = 2;
v15 = v9 != 0;
if ( !v14 )
{
if ( !v10 && (v27 & 1) != 0 && v9 && dnow() - v29 > 1200000.0 )
{
v6 = 1;
do_id(&v44);
v28 = 1;
v29 = dnow();
}
v8 = 2;
if ( dnow() - v29 > 1680000.0 )
{
v6 = 1;
v8 = 2;
do_id(&v44);
v28 = 1;
v29 = dnow();
}
}
goto LABEL_44;
}
v14 = v44;
if ( v8 == 1 && !v44 )
goto LABEL_89;
if ( v8 == 2 )
goto LABEL_36;
v15 = v9 != 0;
if ( v8 == 3 && dnow() - v29 > 1680000.0 )
{
v8 = 0;
do_log("ID: reset");
}
LABEL_44:
check_script(&v44);
v16 = v44;
if ( !v44 )
{
v17 = (v6 & v28) == 0;
v18 = v6 & v28;
if ( (v6 & v28) != 0 )
v6 = 0;
if ( v17 )
v16 = v28;
if ( !v17 )
v7 = v18;
v28 = v16;
if ( !v17 )
v8 = 3;
}
if ( !v10 && (v6 & 1) == 0 && v15 )
{
if ( v33 || (v7 = 1, v34 = 0, v27 = 1, (v9 = unkey(0LL)) != 0) )
{
if ( dnow() - v26 > 3000.0 )
{
v34 = 0;
v33 = 0;
v9 = unkey(0LL);
}
}
}
fflush(stdout);
fflush(stderr);
nanosleep(&requested_time, 0LL);
}
if ( (unsigned __int8)(((v20 >> 3) & 0xF) - 1) > 0x10u )
{
if ( v31 && dnow() - v41 > 1000.0 )
{
v31 = unmute(0LL);
if ( v9 )
goto LABEL_72;
goto LABEL_110;
}
}
else
{
if ( !v31 )
v31 = mute(0LL);
v41 = dnow();
}
if ( v9 )
{
LABEL_72:
v7 = 0;
v26 = dnow();
v27 = 0;
v32 = dnow();
goto LABEL_73;
}
LABEL_110:
v9 = keyup(0LL);
v35 = dnow();
goto LABEL_72;
}
v3 = &argv[argc - 1];
while ( 1 )
{
v4 = argv[1];
envp = (const char **)*(unsigned __int8 *)v4;
if ( (_DWORD)envp == 45 )
break;
LABEL_14:
if ( ++argv == v3 )
goto LABEL_15;
}
if ( v4[1] != 104 || v4[2] )
{
if ( v4[1] == 118 && !v4[2] )
{
verbose = 1;
envp = (const char **)*(unsigned __int8 *)v4;
}
if ( (_DWORD)envp == 45 && v4[1] == 108 && !v4[2] )
logging = 1;
goto LABEL_14;
}
fwrite(
"Usage: repeater [OPTION]\n"
"The repeater controller.\n"
" -l log to syslog\n"
" -v clutter the screen\n"
" -h display this help and exit\n"
"Copyright (c) 2013, Adi Linden <adi@adis.ca>\n",
1uLL,
0xBCuLL,
stderr);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rcx
const char *v4; // rax
__pid_t v6; // ebp
int v7; // er15
int v8; // er14
int v9; // ebx
char v10; // r12
__pid_t v11; // eax
bool v12; // zf
int v13; // edx
__pid_t v14; // eax
bool v15; // r13
__pid_t v16; // eax
bool v17; // zf
int v18; // edx
__int64 v19; // rsi
unsigned __int8 v20; // dl
char v21; // r13
int v22; // eax
double v23; // xmm0_8
double v24; // xmm0_8
int v25; // eax
double v26; // [rsp+0h] [rbp-A8h]
int v27; // [rsp+8h] [rbp-A0h]
int v28; // [rsp+Ch] [rbp-9Ch]
double v29; // [rsp+10h] [rbp-98h]
int v30; // [rsp+18h] [rbp-90h]
int v31; // [rsp+1Ch] [rbp-8Ch]
double v32; // [rsp+20h] [rbp-88h]
int v33; // [rsp+28h] [rbp-80h]
int v34; // [rsp+2Ch] [rbp-7Ch]
double v35; // [rsp+30h] [rbp-78h]
double v36; // [rsp+38h] [rbp-70h]
char v37; // [rsp+38h] [rbp-70h]
int v38; // [rsp+40h] [rbp-68h]
unsigned __int8 v39; // [rsp+47h] [rbp-61h]
unsigned __int8 v40; // [rsp+47h] [rbp-61h]
double v41; // [rsp+48h] [rbp-60h]
char v42[2]; // [rsp+56h] [rbp-52h] BYREF
__pid_t v43; // [rsp+58h] [rbp-50h] BYREF
__pid_t v44; // [rsp+5Ch] [rbp-4Ch] BYREF
struct timespec requested_time; // [rsp+60h] [rbp-48h] BYREF

v43 = 0;
v44 = 0;
if ( argc <= 1 )
{
LABEL_15:
if ( logging )
open_syslog("repeater", argv, envp);
do_log("Starting: repeater, version 20130112");
if ( (int)irlpdev_open("Starting: repeater, version 20130112", argv) < 0 )
{
fwrite("Can't access parallel port", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
v6 = 0;
v7 = 1;
requested_time.tv_sec = 0LL;
v8 = 0;
requested_time.tv_nsec = 5000000LL;
v9 = unkey(0LL);
v34 = 0;
v31 = mute(0LL);
v30 = 0;
v33 = 0;
v27 = 1;
v28 = 0;
v38 = 0;
v36 = 0.0;
v35 = 0.0;
v29 = 0.0;
v32 = 0.0;
v26 = 0.0;
v41 = 0.0;
while ( 1 )
{
v19 = 2LL;
if ( (unsigned int)read_irlpdev(v42, 2LL) != 2 )
{
v19 = 1LL;
fwrite("Can't read parallel port", 1uLL, 0x18uLL, stderr);
}
v20 = v42[0];
v21 = v42[1] & 2;
v10 = (unsigned __int8)v42[0] >> 7;
if ( v9 )
{
if ( !v30 )
{
v37 = v42[0];
v22 = fanon(0LL);
v20 = v37;
v30 = v22;
}
v39 = v20;
v23 = func4();
v20 = v39;
v36 = v23;
}
else if ( v30 )
{
v40 = v42[0];
v24 = func4();
v20 = v40;
if ( v24 - v36 > 300000.0 )
{
v25 = fanoff(0LL, v19, v40);
v20 = v40;
v30 = v25;
}
}
if ( v10 )
break;
if ( !v31 )
v31 = mute(0LL);
LABEL_73:
if ( v21 )
{
if ( v9 )
{
v10 |= v21;
v26 = func4();
v32 = func4();
if ( v6 )
{
v34 = v6;
v7 = 0;
goto LABEL_22;
}
LABEL_104:
v34 = 1;
v7 = 0;
LABEL_105:
if ( v33 )
{
v6 = 0;
func3(&v43);
goto LABEL_32;
}
if ( func4() - v35 <= 10.0 )
goto LABEL_24;
goto LABEL_112;
}
v10 |= v21;
v9 = keyup(0LL);
v35 = func4();
v26 = func4();
v32 = func4();
if ( !v6 )
goto LABEL_104;
v34 = v6;
v7 = 0;
LABEL_98:
if ( !v9 )
{
v9 = keyup(0LL);
v35 = func4();
}
LABEL_22:
v26 = func4();
if ( !v33 && func4() - v35 > 10.0 )
{
LABEL_112:
do_log("Shortkey exceeded");
v33 = 1;
}
if ( v10 )
goto LABEL_24;
goto LABEL_76;
}
if ( v6 )
goto LABEL_98;
if ( v10 )
goto LABEL_105;
LABEL_76:
if ( !v28 && !(v43 | v27) )
{
if ( v34 )
{
if ( func4() - v32 > 300.0 )
{
func1(&v43);
v38 = v34;
v6 = v34;
}
}
else if ( func4() - v32 > 1000.0 )
{
func1(&v43);
func3(&v43);
v6 = v43;
if ( v43 )
{
v27 = 0;
v10 = 0;
v6 = 1;
v38 = 1;
}
else
{
v38 = 0;
v10 = 0;
v27 = 1;
}
goto LABEL_32;
}
}
v10 = 0;
LABEL_24:
func3(&v43);
v11 = v43;
if ( !v43 )
{
v12 = (v6 & v38) == 0;
v13 = v6 & v38;
if ( (v6 & v38) == 0 )
v13 = v27;
if ( (v6 & v38) != 0 )
v6 = 0;
if ( v12 )
v11 = v38;
v27 = v13;
v38 = v11;
}
LABEL_32:
if ( !(v7 | v8) )
{
v29 = func4();
do_log("ID: immediate");
if ( !v44 )
{
LABEL_89:
if ( !v10 && v9 && (v27 & 1) != 0 )
{
v6 = 1;
func2(&v44);
v28 = 1;
v29 = func4();
}
if ( func4() - v29 > 480000.0 )
{
v6 = 1;
func2(&v44);
v28 = 1;
v29 = func4();
}
}
v8 = 1;
v15 = v9 != 0;
goto LABEL_44;
}
if ( v8 == 3 && (v7 & 1) == 0 )
{
do_log("ID: delayed");
v14 = v44;
LABEL_36:
v8 = 2;
v15 = v9 != 0;
if ( !v14 )
{
if ( !v10 && (v27 & 1) != 0 && v9 && func4() - v29 > 1200000.0 )
{
v6 = 1;
func2(&v44);
v28 = 1;
v29 = func4();
}
v8 = 2;
if ( func4() - v29 > 1680000.0 )
{
v6 = 1;
v8 = 2;
func2(&v44);
v28 = 1;
v29 = func4();
}
}
goto LABEL_44;
}
v14 = v44;
if ( v8 == 1 && !v44 )
goto LABEL_89;
if ( v8 == 2 )
goto LABEL_36;
v15 = v9 != 0;
if ( v8 == 3 && func4() - v29 > 1680000.0 )
{
v8 = 0;
do_log("ID: reset");
}
LABEL_44:
func3(&v44);
v16 = v44;
if ( !v44 )
{
v17 = (v6 & v28) == 0;
v18 = v6 & v28;
if ( (v6 & v28) != 0 )
v6 = 0;
if ( v17 )
v16 = v28;
if ( !v17 )
v7 = v18;
v28 = v16;
if ( !v17 )
v8 = 3;
}
if ( !v10 && (v6 & 1) == 0 && v15 )
{
if ( v33 || (v7 = 1, v34 = 0, v27 = 1, (v9 = unkey(0LL)) != 0) )
{
if ( func4() - v26 > 3000.0 )
{
v34 = 0;
v33 = 0;
v9 = unkey(0LL);
}
}
}
fflush(stdout);
fflush(stderr);
nanosleep(&requested_time, 0LL);
}
if ( (unsigned __int8)(((v20 >> 3) & 0xF) - 1) > 0x10u )
{
if ( v31 && func4() - v41 > 1000.0 )
{
v31 = unmute(0LL);
if ( v9 )
goto LABEL_72;
goto LABEL_110;
}
}
else
{
if ( !v31 )
v31 = mute(0LL);
v41 = func4();
}
if ( v9 )
{
LABEL_72:
v7 = 0;
v26 = func4();
v27 = 0;
v32 = func4();
goto LABEL_73;
}
LABEL_110:
v9 = keyup(0LL);
v35 = func4();
goto LABEL_72;
}
v3 = &argv[argc - 1];
while ( 1 )
{
v4 = argv[1];
envp = (const char **)*(unsigned __int8 *)v4;
if ( (_DWORD)envp == 45 )
break;
LABEL_14:
if ( ++argv == v3 )
goto LABEL_15;
}
if ( v4[1] != 104 || v4[2] )
{
if ( v4[1] == 118 && !v4[2] )
{
verbose = 1;
envp = (const char **)*(unsigned __int8 *)v4;
}
if ( (_DWORD)envp == 45 && v4[1] == 108 && !v4[2] )
logging = 1;
goto LABEL_14;
}
fwrite(
"Usage: repeater [OPTION]\n"
"The repeater controller.\n"
" -l log to syslog\n"
" -v clutter the screen\n"
" -h display this help and exit\n"
"Copyright (c) 2013, Adi Linden <adi@adis.ca>\n",
1uLL,
0xBCuLL,
stderr);
return -1;
}

original_code:
int main(int argc, char *argv[])
  {
    int irlpdev = 0;
    unsigned char c[2];
    pid_t ctpid = 0;
    pid_t idpid = 0;
    int idstate = 0;
    int ctbusy = 0;
    int idbusy = 0;
    int ctflag = 1;
    int idflag = 1;
    int muteflag = 0;
    int keyflag = 0;
    int shortkeyflag = 0;
    int forcekeyflag = 0;
    int fanflag = 0;
    int irlpflag = 0;
    unsigned char COS = '1';
    unsigned char dtmf = '0';
    unsigned char irlpkey;
    struct timespec tim;
    double mutetimer = 0;
    double hangtimer = 0;
    double cttimer = 0;
    double idtimer = 0;
    double shortkeytimer = 0;
    double fantimer = 0;
    while (argc > 1) {
        if (!strcmp(argv[1], "-h")) {
            fprintf(stderr, usage);
            return -1;
        }
        if (!strcmp(argv[1], "-v")) {
            verbose = 1;
        }
        if (!strcmp(argv[1], "-l")) {
            logging = 1;
        }
        --argc;
        ++argv;
    }
    if (logging)
        open_syslog("repeater");
    do_log("Starting: " "repeater" ", version " "20130112");
    if(irlpdev_open() < 0 ) {
        fprintf(stderr, "Can't access parallel port");
        exit(-1);
    }
    tim.tv_sec = 0;
    tim.tv_nsec = 5000000;
    keyflag = unkey(irlpdev);
    muteflag = mute(irlpdev);
    while (1) {
        if (read_irlpdev(c, 2) != 2)
            fprintf(stderr, "Can't read parallel port");
        COS = (c[0] >> 7) & 0x01;
        dtmf = (c[0] >> 3) & 0x0f;
        irlpkey = c[1] & 0x02;
        if (keyflag && !fanflag) {
            fanflag = fanon(irlpdev);
        }
        if (!keyflag && fanflag && dnow() - fantimer > 300000) {
            fanflag = fanoff(irlpdev);
        }
        if (keyflag) {
            fantimer = dnow();
        }
        if (COS) {
            if (dtmf >= 1 && dtmf <= 17) {
                if (!muteflag)
                    muteflag = mute(irlpdev);
                mutetimer = dnow();
            } else {
                if (muteflag) {
                    if (((dnow() - mutetimer) > 1000) && muteflag)
                        muteflag = unmute(irlpdev);
                }
            }
        }
        if (!COS && !muteflag) {
            muteflag = mute(irlpdev);
        }
        if (COS) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
            cttimer = dnow();
            ctflag = 0;
            idflag = 0;
        }
        if (irlpkey) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
            cttimer = dnow();
            irlpflag = 1;
            idflag = 0;
        }
        if(forcekeyflag) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
        }
        if (COS || irlpkey || forcekeyflag) {
            if (!shortkeyflag && dnow() - shortkeytimer > 10) {
                do_log("Shortkey exceeded");
                shortkeyflag = 1;
            }
        }
        if (!COS && !irlpkey && !idbusy) {
            if (!ctflag && !ctpid && irlpflag && dnow() - cttimer > 300) {
                do_ct(&ctpid);
                ctbusy = 1;
                forcekeyflag = 1;
            }
            if (!ctflag && !ctpid && !irlpflag && dnow() - cttimer > 1000) {
                do_ct(&ctpid);
                ctbusy = 1;
                forcekeyflag = 1;
            }
        }
        check_script(&ctpid);
        if (!ctpid && ctbusy && forcekeyflag) {
            ctbusy = 0;
            ctflag = 1;
            forcekeyflag = 0;
        }
        if (idstate == 0 && !idflag) {
            idstate = 1;
            idtimer = dnow();
            do_log("ID: immediate");
        }
        if (idstate == 3 && !idflag) {
            idstate = 2;
            do_log("ID: delayed");
        }
        if (idstate == 1 && !idpid) {
            if (!COS && !irlpkey && keyflag && ctflag) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
            if (dnow() - idtimer > 480000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
        }
        if (idstate == 2 && !idpid) {
            if (!COS && !irlpkey && keyflag && ctflag &&
                    dnow() - idtimer > 1200000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
            if (dnow() - idtimer > 1200000 + 480000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
        }
        if (idstate == 3 && dnow() - idtimer > 1200000 + 480000) {
            idstate = 0;
            do_log("ID: reset");
        }
        check_script(&idpid);
        if (!idpid && idbusy && forcekeyflag) {
            idbusy = 0;
            idflag = 1;
            idstate = 3;
            forcekeyflag = 0;
        }
        if (!COS && !irlpkey && !forcekeyflag && keyflag && !shortkeyflag) {
            keyflag = unkey(irlpdev);
            ctflag = 1;
            idflag = 1;
            irlpflag = 0;
            shortkeyflag = 0;
        }
        if (!COS && !irlpkey && !forcekeyflag &&
                keyflag && (dnow() - hangtimer > 3000)) {
            keyflag = unkey(irlpdev);
            irlpflag = 0;
            shortkeyflag = 0;
        }
        fflush(stdout);
        fflush(stderr);
        nanosleep(&tim, ((void *)0));
    }
}

canonical_original_code:
int main(int argc, char *argv[])
  {
    int irlpdev = 0;
    unsigned char c[2];
    int ctpid = 0;
    int idpid = 0;
    int idstate = 0;
    int ctbusy = 0;
    int idbusy = 0;
    int ctflag = 1;
    int idflag = 1;
    int muteflag = 0;
    int keyflag = 0;
    int shortkeyflag = 0;
    int forcekeyflag = 0;
    int fanflag = 0;
    int irlpflag = 0;
    unsigned char COS = '1';
    unsigned char dtmf = '0';
    unsigned char irlpkey;
    struct timespec tim;
    double mutetimer = 0;
    double hangtimer = 0;
    double cttimer = 0;
    double idtimer = 0;
    double shortkeytimer = 0;
    double fantimer = 0;
    while (argc > 1) {
        if (!strcmp(argv[1], "-h")) {
            fprintf(stderr, usage);
            return -1;
        }
        if (!strcmp(argv[1], "-v")) {
            verbose = 1;
        }
        if (!strcmp(argv[1], "-l")) {
            logging = 1;
        }
        --argc;
        ++argv;
    }
    if (logging)
        open_syslog("repeater");
    do_log("Starting: " "repeater" ", version " "20130112");
    if(irlpdev_open() < 0 ) {
        fprintf(stderr, "Can't access parallel port");
        exit(-1);
    }
    tim.tv_sec = 0;
    tim.tv_nsec = 5000000;
    keyflag = unkey(irlpdev);
    muteflag = mute(irlpdev);
    while (1) {
        if (read_irlpdev(c, 2) != 2)
            fprintf(stderr, "Can't read parallel port");
        COS = (c[0] >> 7) & 0x01;
        dtmf = (c[0] >> 3) & 0x0f;
        irlpkey = c[1] & 0x02;
        if (keyflag && !fanflag) {
            fanflag = fanon(irlpdev);
        }
        if (!keyflag && fanflag && dnow() - fantimer > 300000) {
            fanflag = fanoff(irlpdev);
        }
        if (keyflag) {
            fantimer = dnow();
        }
        if (COS) {
            if (dtmf >= 1 && dtmf <= 17) {
                if (!muteflag)
                    muteflag = mute(irlpdev);
                mutetimer = dnow();
            } else {
                if (muteflag) {
                    if (((dnow() - mutetimer) > 1000) && muteflag)
                        muteflag = unmute(irlpdev);
                }
            }
        }
        if (!COS && !muteflag) {
            muteflag = mute(irlpdev);
        }
        if (COS) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
            cttimer = dnow();
            ctflag = 0;
            idflag = 0;
        }
        if (irlpkey) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
            cttimer = dnow();
            irlpflag = 1;
            idflag = 0;
        }
        if(forcekeyflag) {
            if (!keyflag) {
                keyflag = keyup(irlpdev);
                shortkeytimer = dnow();
            }
            hangtimer = dnow();
        }
        if (COS || irlpkey || forcekeyflag) {
            if (!shortkeyflag && dnow() - shortkeytimer > 10) {
                do_log("Shortkey exceeded");
                shortkeyflag = 1;
            }
        }
        if (!COS && !irlpkey && !idbusy) {
            if (!ctflag && !ctpid && irlpflag && dnow() - cttimer > 300) {
                do_ct(&ctpid);
                ctbusy = 1;
                forcekeyflag = 1;
            }
            if (!ctflag && !ctpid && !irlpflag && dnow() - cttimer > 1000) {
                do_ct(&ctpid);
                ctbusy = 1;
                forcekeyflag = 1;
            }
        }
        check_script(&ctpid);
        if (!ctpid && ctbusy && forcekeyflag) {
            ctbusy = 0;
            ctflag = 1;
            forcekeyflag = 0;
        }
        if (idstate == 0 && !idflag) {
            idstate = 1;
            idtimer = dnow();
            do_log("ID: immediate");
        }
        if (idstate == 3 && !idflag) {
            idstate = 2;
            do_log("ID: delayed");
        }
        if (idstate == 1 && !idpid) {
            if (!COS && !irlpkey && keyflag && ctflag) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
            if (dnow() - idtimer > 480000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
        }
        if (idstate == 2 && !idpid) {
            if (!COS && !irlpkey && keyflag && ctflag &&
                    dnow() - idtimer > 1200000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
            if (dnow() - idtimer > 1200000 + 480000) {
                do_id(&idpid);
                idbusy = 1;
                forcekeyflag = 1;
                idtimer = dnow();
            }
        }
        if (idstate == 3 && dnow() - idtimer > 1200000 + 480000) {
            idstate = 0;
            do_log("ID: reset");
        }
        check_script(&idpid);
        if (!idpid && idbusy && forcekeyflag) {
            idbusy = 0;
            idflag = 1;
            idstate = 3;
            forcekeyflag = 0;
        }
        if (!COS && !irlpkey && !forcekeyflag && keyflag && !shortkeyflag) {
            keyflag = unkey(irlpdev);
            ctflag = 1;
            idflag = 1;
            irlpflag = 0;
            shortkeyflag = 0;
        }
        if (!COS && !irlpkey && !forcekeyflag &&
                keyflag && (dnow() - hangtimer > 3000)) {
            keyflag = unkey(irlpdev);
            irlpflag = 0;
            shortkeyflag = 0;
        }
        fflush(stdout);
        fflush(stderr);
        nanosleep(&tim, ((void *)0));
    }
}

variable_types: irlpdev int

variable_types:
c
unsigned char [2]

variable_types: ctpid int

variable_types: idpid int

variable_types: idstate int

variable_types: ctbusy int

variable_types: idbusy int

variable_types: ctflag int

variable_types: idflag int

variable_types: muteflag int

variable_types: keyflag int

variable_types: shortkeyflag int

variable_types: forcekeyflag int

variable_types: fanflag int

variable_types: irlpflag int

variable_types:
COS
unsigned char

variable_types:
dtmf
unsigned char

variable_types:
irlpkey
unsigned char

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

variable_types: mutetimer double

variable_types: hangtimer double

variable_types: cttimer double

variable_types: idtimer double

variable_types: shortkeytimer double

variable_types: fantimer double


decompiled_code:
__int64 __fastcall alsa_open(__int64 a1)
{
__int64 result; // rax
const char *v2; // rax

result = snd_pcm_open(&ph, a1, 0LL, 0LL);
if ( (int)result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
fprintf(stderr, "open of pcm device %s failed\n", v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
const char *v2; // rax

result = snd_pcm_open(&ph, a1, 0LL, 0LL);
if ( (int)result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
fprintf(stderr, "open of pcm device %s failed\n", v2);
exit(1);
}
return result;
}

original_code:
void alsa_open(char *ident)
{
    int rc;
    rc = snd_pcm_open(&ph, ident, SND_PCM_STREAM_PLAYBACK, 0);
    if (rc < 0) {
        fprintf(stderr, "open of pcm device %s failed\n", snd_strerror(rc));
        exit(1);
    }
}

variable_types:
ident
char *

variable_types: rc int


decompiled_code:
__int64 __fastcall alsa_write(_QWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er12
const char *v5; // rax

v2 = snd_pcm_writei(ph, *a1, *a2 / 2);
v3 = v2;
if ( v2 < 0 )
{
v5 = (const char *)snd_strerror((unsigned int)v2);
fprintf(stderr, "write error: %s\n", v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er12
const char *v5; // rax

v2 = snd_pcm_writei(ph, *a1, *a2 / 2);
v3 = v2;
if ( v2 < 0 )
{
v5 = (const char *)snd_strerror((unsigned int)v2);
fprintf(stderr, "write error: %s\n", v5);
}
return v3;
}

original_code:
int alsa_write(int16_t **bf, int *nbf)
{
    snd_pcm_sframes_t rc;
    int n;
    n = *nbf / 2;
    rc = snd_pcm_writei(ph, *bf, n);
    if (rc < 0) {
        fprintf(stderr, "write error: %s\n", snd_strerror(rc));
    }
    return rc;
}

canonical_original_code:
int alsa_write(short **bf, int *nbf)
{
    long rc;
    int n;
    n = *nbf / 2;
    rc = snd_pcm_writei(ph, *bf, n);
    if (rc < 0) {
        fprintf(stderr, "write error: %s\n", snd_strerror(rc));
    }
    return rc;
}

variable_types:
bf
short **

variable_types:
nbf
int *

variable_types: rc long

variable_types: n int


decompiled_code:
__int64 alsa_close()
{
snd_pcm_drain(ph);
return snd_pcm_close(ph);
}

canonical_decompiled_code:
__int64 func3()
{
snd_pcm_drain(ph);
return snd_pcm_close(ph);
}

original_code:
void alsa_close()
{
    snd_pcm_drain(ph);
    snd_pcm_close(ph);
}


sinval

decompiled_code:
int __fastcall sinval(int a1, int a2, int a3, int a4)
{
return (__int16)(int)((double)a3 * 32767.0 / 100.0 * sin((double)a4 / (double)a2 * (double)a1 * 6.283185307179586));
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, int a4)
{
return (__int16)(int)((double)a3 * 32767.0 / 100.0 * sin((double)a4 / (double)a2 * (double)a1 * 6.283185307179586));
}

original_code:
int sinval(int freq, int rate, int ampl, int p)
{
    int16_t v;
    v = ((double)ampl * 0x7fff / 100) * sin((double)p / rate * freq * (2 * 3.141592653589793));
    return v;
}

canonical_original_code:
int sinval(int freq, int rate, int ampl, int p)
{
    short v;
    v = ((double)ampl * 0x7fff / 100) * sin((double)p / rate * freq * (2 * 3.141592653589793));
    return v;
}

variable_types: freq int

variable_types: rate int

variable_types: ampl int

variable_types: p int

variable_types: v short


mkwave

original_code:
int mkwave(int freq, int rate, int ampl, int dura, int atta, int deca,
           int16_t **bf, int *nbf)
{
    int st, sa, sd, ss;
    int16_t *tbf;
    int ntbf;
    int i;
    int a;
    st = (double)rate * dura / 1000;
    sa = (double)rate * atta / 1000;
    sd = (double)rate * deca / 1000;
    ss = st - sa - sd;
    ntbf = st * 2;
    tbf = malloc(ntbf);
    if (tbf == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < sa; ++i) {
        a = ((double)ampl / sa) * i;
        tbf[i] = sinval(freq, rate, a, i);
    }
    for (i = sa; i < sa + ss; ++i) {
        tbf[i] = sinval(freq, rate, ampl, i);
    }
    for (i = sa + ss; i < st; ++i) {
        a = ((double)ampl / sd) * (st - i);
        tbf[i] = sinval(freq, rate, a, i);
    }
    *bf = tbf;
    *nbf = ntbf;
    return st;
}

canonical_original_code:
int mkwave(int freq, int rate, int ampl, int dura, int atta, int deca, short **bf, int *nbf)
{
    int st; int sa; int sd; int ss;
    short *tbf;
    int ntbf;
    int i;
    int a;
    st = (double)rate * dura / 1000;
    sa = (double)rate * atta / 1000;
    sd = (double)rate * deca / 1000;
    ss = st - sa - sd;
    ntbf = st * 2;
    tbf = malloc(ntbf);
    if (tbf == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < sa; ++i) {
        a = ((double)ampl / sa) * i;
        tbf[i] = sinval(freq, rate, a, i);
    }
    for (i = sa; i < sa + ss; ++i) {
        tbf[i] = sinval(freq, rate, ampl, i);
    }
    for (i = sa + ss; i < st; ++i) {
        a = ((double)ampl / sd) * (st - i);
        tbf[i] = sinval(freq, rate, a, i);
    }
    *bf = tbf;
    *nbf = ntbf;
    return st;
}

variable_types: dura int

variable_types: atta int

variable_types: deca int

variable_types: st int

variable_types: sa int

variable_types: sd int

variable_types: ss int

variable_types:
tbf
short *

variable_types: ntbf int

variable_types: i int

variable_types: a int


mksilence

decompiled_code:
__int64 __fastcall mksilence(int a1, int a2, _QWORD *a3, _DWORD *a4)
{
int v6; // er12
void *v7; // rax
void *v8; // rcx

v6 = (int)((double)a1 * (double)a2 / 1000.0);
v7 = malloc(2 * v6);
if ( v7 )
{
v8 = v7;
if ( v6 > 0 )
v8 = memset(v7, 0, 2LL * v6);
*a3 = v8;
*a4 = 2 * v6;
}
else
{
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, _QWORD *a3, _DWORD *a4)
{
int v6; // er12
void *v7; // rax
void *v8; // rcx

v6 = (int)((double)a1 * (double)a2 / 1000.0);
v7 = malloc(2 * v6);
if ( v7 )
{
v8 = v7;
if ( v6 > 0 )
v8 = memset(v7, 0, 2LL * v6);
*a3 = v8;
*a4 = 2 * v6;
}
else
{
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
int mksilence(int rate, int dura, int16_t **bf, int *nbf)
{
    int16_t *tbf;
    int ntbf;
    int i, st;
    st = (double)rate * dura / 1000;
    ntbf = st * 2;
    tbf = malloc(ntbf);
    if (tbf == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < st; ++i) {
        tbf[i] = 0;
    }
    *bf = tbf;
    *nbf = ntbf;
    return st;
}

canonical_original_code:
int mksilence(int rate, int dura, short **bf, int *nbf)
{
    short *tbf;
    int ntbf;
    int i; int st;
    st = (double)rate * dura / 1000;
    ntbf = st * 2;
    tbf = malloc(ntbf);
    if (tbf == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < st; ++i) {
        tbf[i] = 0;
    }
    *bf = tbf;
    *nbf = ntbf;
    return st;
}

variable_types:
bf
short **

variable_types:
nbf
int *


repo: aditibarbhai/buxfer

decompiled_code:
int __fastcall list_groups(const char **a1)
{
const char **i; // rbx

if ( !a1 )
return puts(" ");
for ( i = a1; i[3]; i = (const char **)i[3] )
printf("%s \n", *i);
return printf("%s \n", *i);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
const char **i; // rbx

if ( !a1 )
return puts(" ");
for ( i = a1; i[3]; i = (const char **)i[3] )
printf("%s \n", *i);
return printf("%s \n", *i);
}

original_code:
void list_groups(Group *group_list) {
    Group *currentGrp = group_list;
    if ( currentGrp ) {
        while ( currentGrp->next ) {
            printf("%s \n", currentGrp->name);
            currentGrp = currentGrp->next;
        }
        printf("%s \n", currentGrp->name);
    } else printf(" \n");
}

canonical_original_code:
void list_groups(struct group *group_list) {
    struct group *currentGrp = group_list;
    if ( currentGrp ) {
        while ( currentGrp->next ) {
            printf("%s \n", currentGrp->name);
            currentGrp = currentGrp->next;
        }
        printf("%s \n", currentGrp->name);
    } else printf(" \n");
}

variable_types: struct group { char *name; struct user { char *name; double balance; struct user *next; } *users; struct xct { char *name; double amount; struct xct *next; } *xcts; struct group *next; } *

user_defined_types: struct group { char *name; struct user *users; struct xct *xcts; struct group *next; }


decompiled_code:
const char **__fastcall find_group(__int64 a1, const char *a2)
{
__int64 v2; // rbx
int v3; // eax
const char **v5; // r12

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v5 = (const char **)v2;
v2 = *(_QWORD *)(v2 + 24);
v3 = strcmp(*v5, a2);
if ( !v2 )
break;
if ( !v3 )
return v5;
}
if ( v3 )
v5 = 0LL;
return v5;
}

canonical_decompiled_code:
const char **__fastcall func1(__int64 a1, const char *a2)
{
__int64 v2; // rbx
int v3; // eax
const char **v5; // r12

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v5 = (const char **)v2;
v2 = *(_QWORD *)(v2 + 24);
v3 = strcmp(*v5, a2);
if ( !v2 )
break;
if ( !v3 )
return v5;
}
if ( v3 )
v5 = 0LL;
return v5;
}

original_code:
Group *find_group(Group *group_list, const char *group_name) {
    Group *currentGrp = group_list;
    if ( currentGrp == ((void *)0) ) return ((void *)0);
    while( currentGrp->next ) {
        if ( strcmp(currentGrp->name, group_name) == 0 ) {
            return currentGrp;
        }
        currentGrp = currentGrp->next;
    }
    if( strcmp( currentGrp->name, group_name ) == 0 ) {
        return currentGrp;
    } else return ((void *)0);
}

canonical_original_code:
struct group *find_group(struct group *group_list, char *group_name) {
    struct group *currentGrp = group_list;
    if ( currentGrp == ((void *)0) ) return ((void *)0);
    while( currentGrp->next ) {
        if ( strcmp(currentGrp->name, group_name) == 0 ) {
            return currentGrp;
        }
        currentGrp = currentGrp->next;
    }
    if( strcmp( currentGrp->name, group_name ) == 0 ) {
        return currentGrp;
    } else return ((void *)0);
}

return_type: struct group { char *name; struct user { char *name; double balance; struct user *next; } *users; struct xct { char *name; double amount; struct xct *next; } *xcts; struct group *next; } *