decompiled_code:
float lsm303_magnet_angle_rad()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

lsm303_read_magnet_gauss_cal((float *)v1);
return atan2(COERCE_FLOAT(v1[1] ^ LC14), *(float *)v1);
}

canonical_decompiled_code:
float func6()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

func4((float *)v1);
return atan2(COERCE_FLOAT(v1[1] ^ LC14), *(float *)v1);
}

original_code:
float lsm303_magnet_angle_rad()
{
    float xyz[3];
    lsm303_read_magnet_gauss_cal(xyz);
    return atan2(-xyz[1], xyz[0]);
}

return_type: float


decompiled_code:
__int64 __fastcall lsm303_read_acc_measurements(float *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -88;
if ( write(facc, buf, 1uLL) == 1 )
{
if ( read(facc, v2, 6uLL) == 6 )
{
*a1 = (float)(v2[1] | (v2[0] << 8)) - xyz_acc_offset[0];
a1[1] = (float)(v2[3] | (v2[2] << 8)) - xyz_acc_offset[1];
a1[2] = (float)(v2[5] | (v2[4] << 8)) - xyz_acc_offset[2];
result = 1LL;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(float *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -88;
if ( write(facc, buf, 1uLL) == 1 )
{
if ( read(facc, v2, 6uLL) == 6 )
{
*a1 = (float)(v2[1] | (v2[0] << 8)) - xyz_acc_offset[0];
a1[1] = (float)(v2[3] | (v2[2] << 8)) - xyz_acc_offset[1];
a1[2] = (float)(v2[5] | (v2[4] << 8)) - xyz_acc_offset[2];
result = 1LL;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

original_code:
int lsm303_read_acc_measurements(float xyz[3])
{
    int8_t readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_acc_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_acc_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_acc_offset[2]);
    return 1;
}

canonical_original_code:
int lsm303_read_acc_measurements(float xyz[3])
{
    char readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    char buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_acc_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_acc_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_acc_offset[2]);
    return 1;
}

variable_types:
xyz
float [3]

variable_types: readReg char

variable_types:
buffer
char [6]

return_type: int


decompiled_code:
__int64 __fastcall lsm303_read_acc_raw(_WORD *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -88;
if ( write(facc, buf, 1uLL) == 1 )
{
if ( read(facc, v2, 6uLL) == 6 )
{
*a1 = (v2[0] << 8) | v2[1];
a1[1] = (v2[2] << 8) | v2[3];
a1[2] = (v2[4] << 8) | v2[5];
result = 1LL;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_WORD *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -88;
if ( write(facc, buf, 1uLL) == 1 )
{
if ( read(facc, v2, 6uLL) == 6 )
{
*a1 = (v2[0] << 8) | v2[1];
a1[1] = (v2[2] << 8) | v2[3];
a1[2] = (v2[4] << 8) | v2[5];
result = 1LL;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

original_code:
int lsm303_read_acc_raw(int16_t xyz[3])
{
    int8_t readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (int16_t) ((buffer[0]<<8 | buffer[1]));
    xyz[1] = (int16_t) ((buffer[2]<<8 | buffer[3]));
    xyz[2] = (int16_t) ((buffer[4]<<8 | buffer[5]));
    return 1;
}

canonical_original_code:
int lsm303_read_acc_raw(short xyz[3])
{
    char readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    char buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (short) ((buffer[0]<<8 | buffer[1]));
    xyz[1] = (short) ((buffer[2]<<8 | buffer[3]));
    xyz[2] = (short) ((buffer[4]<<8 | buffer[5]));
    return 1;
}

variable_types:
xyz
short [3]


decompiled_code:
__int64 __fastcall lsm303_read_acc_SI(float *a1)
{
__int64 result; // rax
__int16 v2[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = lsm303_read_acc_raw(v2);
*a1 = (float)v2[0] / 1000.0;
a1[1] = (float)v2[1] / 1000.0;
a1[2] = (float)v2[2] / 1000.0;
return result;
}

original_code:
int lsm303_read_acc_SI(float xyz[3])
{
    int status;
    int16_t xyz_raw[3];
    status = lsm303_read_acc_raw(xyz_raw);
    xyz[0] = (float)xyz_raw[0] / accelerometer_gain_SI;
    xyz[1] = (float)xyz_raw[1] / accelerometer_gain_SI;
    xyz[2] = (float)xyz_raw[2] / accelerometer_gain_SI;
    return status;
}

canonical_original_code:
int lsm303_read_acc_SI(float xyz[3])
{
    int status;
    short xyz_raw[3];
    status = lsm303_read_acc_raw(xyz_raw);
    xyz[0] = (float)xyz_raw[0] / accelerometer_gain_SI;
    xyz[1] = (float)xyz_raw[1] / accelerometer_gain_SI;
    xyz[2] = (float)xyz_raw[2] / accelerometer_gain_SI;
    return status;
}

variable_types: status int


original_code:
float lsm303_mag_convert_to_deg_2D(int16_t xy[])
{
    float angle_rad, angle_deg;
    angle_rad = atan2(xy[1], xy[0]);
    angle_deg = angle_rad*360/(2*3.14159265358979323846);
    angle_deg = fmod(angle_deg + 180.0, 360.0) - 180.0;
    return(angle_deg);
}

canonical_original_code:
float lsm303_mag_convert_to_deg_2D(short xy[])
{
    float angle_rad; float angle_deg;
    angle_rad = atan2(xy[1], xy[0]);
    angle_deg = angle_rad*360/(2*3.14159265358979323846);
    angle_deg = fmod(angle_deg + 180.0, 360.0) - 180.0;
    return(angle_deg);
}

variable_types:
xy
short []


original_code:
int lsm303_calibrate_acc()
{
    int status = 0;
    float xyz[3];
    float x_avg, y_avg, z_avg;
    int i,n;
    n = 100;
    int16_t x_pre_def = 0;
    int16_t y_pre_def = 0;
    int16_t z_pre_def = 16384;
    for(i=0; i<n; i++)
    {
        status += lsm303_read_acc_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_acc_offset[0] = x_avg-x_pre_def;
    xyz_acc_offset[1] = y_avg-y_pre_def;
    xyz_acc_offset[2] = z_avg-z_pre_def;
    return status;
}

canonical_original_code:
int lsm303_calibrate_acc()
{
    int status = 0;
    float xyz[3];
    float x_avg; float y_avg; float z_avg;
    int i; int n;
    n = 100;
    short x_pre_def = 0;
    short y_pre_def = 0;
    short z_pre_def = 16384;
    for(i=0; i<n; i++)
    {
        status += lsm303_read_acc_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_acc_offset[0] = x_avg-x_pre_def;
    xyz_acc_offset[1] = y_avg-y_pre_def;
    xyz_acc_offset[2] = z_avg-z_pre_def;
    return status;
}

variable_types: i int

variable_types: n int


original_code:
int lsm303_calibrate_mag()
{
    int status = 0;
    float xyz[3];
    float x_avg, y_avg, z_avg;
    int i, n;
    n = 100;
    int16_t x_pre_def = -190;
    int16_t y_pre_def = -5;
    int16_t z_pre_def = -420;
    for (i = 0; i < n; i++)
    {
        status += lsm303_read_mag_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_mag_offset[0] = x_pre_def-x_avg;
    xyz_mag_offset[1] = y_pre_def-y_avg;
    xyz_mag_offset[2] = z_pre_def-z_avg;
    return status;
}

canonical_original_code:
int lsm303_calibrate_mag()
{
    int status = 0;
    float xyz[3];
    float x_avg; float y_avg; float z_avg;
    int i; int n;
    n = 100;
    short x_pre_def = -190;
    short y_pre_def = -5;
    short z_pre_def = -420;
    for (i = 0; i < n; i++)
    {
        status += lsm303_read_mag_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_mag_offset[0] = x_pre_def-x_avg;
    xyz_mag_offset[1] = y_pre_def-y_avg;
    xyz_mag_offset[2] = z_pre_def-z_avg;
    return status;
}


decompiled_code:
__int64 itg3200_init()
{
int v0; // eax
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("/dev/i2c-0", 2306);
fgyro = v0;
if ( v0 == -1 )
{
printf("open_port: Unable to open i2c-bus");
result = 0LL;
}
else if ( ioctl(v0, 0x703uLL, 105LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
result = 0LL;
}
else
{
buf[0] = 0;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, buf, 1uLL) == 1 )
{
printf("Got whoami register: %x\n", (unsigned int)buf[0]);
result = 1LL;
}
else
{
puts("Failed to write to gyro");
result = 0LL;
}
}
else
{
puts("Failed to write to gyro (whoami-reg)");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("/dev/i2c-0", 2306);
fgyro = v0;
if ( v0 == -1 )
{
printf("open_port: Unable to open i2c-bus");
result = 0LL;
}
else if ( ioctl(v0, 0x703uLL, 105LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
result = 0LL;
}
else
{
buf[0] = 0;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, buf, 1uLL) == 1 )
{
printf("Got whoami register: %x\n", (unsigned int)buf[0]);
result = 1LL;
}
else
{
puts("Failed to write to gyro");
result = 0LL;
}
}
else
{
puts("Failed to write to gyro (whoami-reg)");
result = 0LL;
}
}
return result;
}

original_code:
int itg3200_init()
{
    fgyro = open("/dev/i2c-0", 02 | 0400 | 04000);
    if (fgyro == -1)
    {
        printf("open_port: Unable to open i2c-bus");
        return 0;
    }
    else
    {
        if (ioctl(fgyro, 0x0703, 0x69) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        int8_t whoami = 0x00;
        if (write(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro (whoami-reg)\n");
            return 0;
        }
        if (read(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro\n");
            return 0;
        }
        printf("Got whoami register: %x\n", whoami);
        return 1;
    }
}

canonical_original_code:
int itg3200_init()
{
    fgyro = open("/dev/i2c-0", 02 | 0400 | 04000);
    if (fgyro == -1)
    {
        printf("open_port: Unable to open i2c-bus");
        return 0;
    }
    else
    {
        if (ioctl(fgyro, 0x0703, 0x69) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        char whoami = 0x00;
        if (write(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro (whoami-reg)\n");
            return 0;
        }
        if (read(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro\n");
            return 0;
        }
        printf("Got whoami register: %x\n", whoami);
        return 1;
    }
}

variable_types: whoami char


decompiled_code:
__int64 __fastcall itg3200_read_raw(int *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 29;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, v2, 6uLL) == 6 )
{
*a1 = v2[1] | (v2[0] << 8);
a1[1] = v2[3] | (v2[2] << 8);
a1[2] = v2[5] | (v2[4] << 8);
result = 1LL;
}
else
{
puts("Read gyro xyz failed");
result = 0LL;
}
}
else
{
puts("Failed toaa write read Register to gyro");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 29;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, v2, 6uLL) == 6 )
{
*a1 = v2[1] | (v2[0] << 8);
a1[1] = v2[3] | (v2[2] << 8);
a1[2] = v2[5] | (v2[4] << 8);
result = 1LL;
}
else
{
puts("Read gyro xyz failed");
result = 0LL;
}
}
else
{
puts("Failed toaa write read Register to gyro");
result = 0LL;
}
return result;
}

original_code:
int itg3200_read_raw(int xyz_raw[3])
{
    int8_t readRegister = 0x1D;
    if (write(fgyro, &readRegister, 1) != 1)
    {
        printf("Failed toaa write read Register to gyro\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(fgyro, buffer, 6) != 6)
    {
        printf("Read gyro xyz failed\n");
        return 0;
    }
    xyz_raw[0] = buffer[0]<<8 | buffer[1];
    xyz_raw[1] = buffer[2]<<8 | buffer[3];
    xyz_raw[2] = buffer[4]<<8 | buffer[5];
    return 1;
}

canonical_original_code:
int itg3200_read_raw(int xyz_raw[3])
{
    char readRegister = 0x1D;
    if (write(fgyro, &readRegister, 1) != 1)
    {
        printf("Failed toaa write read Register to gyro\n");
        return 0;
    }
    char buffer[6];
    if(read(fgyro, buffer, 6) != 6)
    {
        printf("Read gyro xyz failed\n");
        return 0;
    }
    xyz_raw[0] = buffer[0]<<8 | buffer[1];
    xyz_raw[1] = buffer[2]<<8 | buffer[3];
    xyz_raw[2] = buffer[4]<<8 | buffer[5];
    return 1;
}

variable_types: readRegister char


original_code:
int itg3200_read_rad(float xyz_rad[3])
{
        int status = 0;
        static float factor = 1.0 / (8.0 * 14.375) * 0.017453293;
        int xyz_raw[3];
        status = itg3200_read_raw(xyz_raw);
        xyz_rad[0] = xyz_raw[0] * factor;
        xyz_rad[1] = xyz_raw[1] * factor;
        xyz_rad[2] = xyz_raw[2] * factor;
        return status;
}

variable_types: factor float


original_code:
int itg3200_read_deg(float xyz_deg[3])
{
        int status = 0;
        static float factor = 0.125 / 14.375;
        int xyz_raw[3];
        status = itg3200_read_raw(xyz_raw);
        xyz_deg[0] = xyz_raw[0] * factor;
        xyz_deg[1] = xyz_raw[1] * factor;
        xyz_deg[2] = xyz_raw[2] * factor;
        return status;
}


decompiled_code:
__int64 __fastcall itg3200_read_rad_calibrated(float *a1)
{
__int64 result; // rax
int v2[5]; // [rsp+4h] [rbp-14h] BYREF

result = itg3200_read_rad((float *)v2);
*a1 = *(float *)v2 - xyz_gyro_offset[0];
a1[1] = *(float *)&v2[1] - xyz_gyro_offset[1];
a1[2] = *(float *)&v2[2] - xyz_gyro_offset[2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(float *a1)
{
__int64 result; // rax
int v2[5]; // [rsp+4h] [rbp-14h] BYREF

result = func2((float *)v2);
*a1 = *(float *)v2 - xyz_gyro_offset[0];
a1[1] = *(float *)&v2[1] - xyz_gyro_offset[1];
a1[2] = *(float *)&v2[2] - xyz_gyro_offset[2];
return result;
}

original_code:
int itg3200_read_rad_calibrated(float xyz_rad_cal[3])
{
        int status;
        float xyz_rad[3];
        status = itg3200_read_rad(xyz_rad);
        xyz_rad_cal[0] = xyz_rad[0] - xyz_gyro_offset[0];
        xyz_rad_cal[1] = xyz_rad[1] - xyz_gyro_offset[1];
        xyz_rad_cal[2] = xyz_rad[2] - xyz_gyro_offset[2];
        return status;
}


decompiled_code:
__int64 __fastcall itg3200_read_deg_calibrated(float *a1)
{
__int64 result; // rax
float v2; // xmm0_4
float v3; // xmm0_4
float v4; // xmm0_4
int v5[5]; // [rsp+4h] [rbp-14h] BYREF

result = itg3200_read_deg((float *)v5);
v2 = *(float *)v5 - xyz_gyro_offset[0] * 57.29578;
*a1 = v2;
v3 = *(float *)&v5[1] - xyz_gyro_offset[1] * 57.29578;
a1[1] = v3;
v4 = *(float *)&v5[2] - xyz_gyro_offset[2] * 57.29578;
a1[2] = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(float *a1)
{
__int64 result; // rax
float v2; // xmm0_4
float v3; // xmm0_4
float v4; // xmm0_4
int v5[5]; // [rsp+4h] [rbp-14h] BYREF

result = func3((float *)v5);
v2 = *(float *)v5 - xyz_gyro_offset[0] * 57.29578;
*a1 = v2;
v3 = *(float *)&v5[1] - xyz_gyro_offset[1] * 57.29578;
a1[1] = v3;
v4 = *(float *)&v5[2] - xyz_gyro_offset[2] * 57.29578;
a1[2] = v4;
return result;
}

original_code:
int itg3200_read_deg_calibrated(float xyz_deg_cal[3])
{
        int status;
        float xyz_deg[3];
        status = itg3200_read_deg(xyz_deg);
        xyz_deg_cal[0] = xyz_deg[0] - xyz_gyro_offset[0] * 57.29578;
        xyz_deg_cal[1] = xyz_deg[1] - xyz_gyro_offset[1] * 57.29578;
        xyz_deg_cal[2] = xyz_deg[2] - xyz_gyro_offset[2] * 57.29578;
        return status;
}


original_code:
int itg3200_calibrate_gyro()
{
        int status = 0;
        int n = 100;
        int i;
        float xyz[3];
        float x_sum, y_sum, z_sum;
        x_sum = 0.0;
        y_sum = 0.0;
        z_sum = 0.0;
        for (i = 0; i < n; i++)
        {
                status += itg3200_read_rad(xyz);
                x_sum += xyz[0];
                y_sum += xyz[1];
                z_sum += xyz[2];
        }
        xyz_gyro_offset[0] = x_sum / n;
        xyz_gyro_offset[1] = y_sum / n;
        xyz_gyro_offset[2] = z_sum / n;
        return status;
}

canonical_original_code:
int itg3200_calibrate_gyro()
{
        int status = 0;
        int n = 100;
        int i;
        float xyz[3];
        float x_sum; float y_sum; float z_sum;
        x_sum = 0.0;
        y_sum = 0.0;
        z_sum = 0.0;
        for (i = 0; i < n; i++)
        {
                status += itg3200_read_rad(xyz);
                x_sum += xyz[0];
                y_sum += xyz[1];
                z_sum += xyz[2];
        }
        xyz_gyro_offset[0] = x_sum / n;
        xyz_gyro_offset[1] = y_sum / n;
        xyz_gyro_offset[2] = z_sum / n;
        return status;
}


decompiled_code:
void *nmea_property()
{
return &prop_0;
}

canonical_decompiled_code:
void *func0()
{
return &prop_0;
}

original_code:
nmeaPROPERTY * nmea_property()
{
    static nmeaPROPERTY prop = {
        0, 0, (1024)
        };
    return ∝
}

canonical_original_code:
struct _nmeaPROPERTY *nmea_property()
{
    static struct _nmeaPROPERTY prop = {
        0, 0, (1024)
        };
    return ∝
}

return_type: struct _nmeaPROPERTY { void (*trace_func)(char *str, int str_size); void (*error_func)(char *str, int str_size); int parse_buff_size; } *


decompiled_code:
int nmea_trace(char *format, ...)
{
__int64 (__fastcall **v1)(char *, _QWORD); // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = (__int64 (__fastcall **)(char *, _QWORD))nmea_property();
v2 = *v1;
if ( *v1 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
__int64 (__fastcall **v1)(char *, _QWORD); // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = (__int64 (__fastcall **)(char *, _QWORD))func0();
v2 = *v1;
if ( *v1 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

original_code:
void nmea_trace(const char *str, ...)
{
    int size;
    va_list arg_list;
    char buff[(1024)];
    nmeaTraceFunc func = nmea_property()->trace_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

canonical_original_code:
void nmea_trace(char *str, ...)
{
    int size;
    __builtin_va_list arg_list;
    char buff[-1];
    void (*func)(char *str, int str_size) = nmea_property()->trace_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

variable_types:
str
char *

variable_types: size int

variable_types:
buff
char [-1]

variable_types:
func
void (*)(char *str, int str_size)

return_type: void


decompiled_code:
int nmea_error(char *format, ...)
{
_QWORD *v1; // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = nmea_property();
v2 = (__int64 (__fastcall *)(char *, _QWORD))v1[1];
if ( v2 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

canonical_decompiled_code:
int func2(char *format, ...)
{
_QWORD *v1; // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = func0();
v2 = (__int64 (__fastcall *)(char *, _QWORD))v1[1];
if ( v2 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

original_code:
void nmea_error(const char *str, ...)
{
    int size;
    va_list arg_list;
    char buff[(1024)];
    nmeaErrorFunc func = nmea_property()->error_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

canonical_original_code:
void nmea_error(char *str, ...)
{
    int size;
    __builtin_va_list arg_list;
    char buff[-1];
    void (*func)(char *str, int str_size) = nmea_property()->error_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}


decompiled_code:
__int64 __fastcall nmea_time_now(__int64 a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = gmtime(&timer);
*(_DWORD *)a1 = v1->tm_year;
*(_DWORD *)(a1 + 4) = v1->tm_mon;
*(_DWORD *)(a1 + 8) = v1->tm_mday;
*(_DWORD *)(a1 + 12) = v1->tm_hour;
*(_DWORD *)(a1 + 16) = v1->tm_min;
result = (unsigned int)v1->tm_sec;
*(_QWORD *)(a1 + 20) = (unsigned int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = gmtime(&timer);
*(_DWORD *)a1 = v1->tm_year;
*(_DWORD *)(a1 + 4) = v1->tm_mon;
*(_DWORD *)(a1 + 8) = v1->tm_mday;
*(_DWORD *)(a1 + 12) = v1->tm_hour;
*(_DWORD *)(a1 + 16) = v1->tm_min;
result = (unsigned int)v1->tm_sec;
*(_QWORD *)(a1 + 20) = (unsigned int)result;
return result;
}

original_code:
void nmea_time_now(nmeaTIME *stm)
{
    time_t lt;
    struct tm *tt;
    time(&lt);
    tt = gmtime(&lt);
    stm->year = tt->tm_year;
    stm->mon = tt->tm_mon;
    stm->day = tt->tm_mday;
    stm->hour = tt->tm_hour;
    stm->min = tt->tm_min;
    stm->sec = tt->tm_sec;
    stm->hsec = 0;
}

canonical_original_code:
void nmea_time_now(struct _nmeaTIME *stm)
{
    long lt;
    struct tm *tt;
    time(&lt);
    tt = gmtime(&lt);
    stm->year = tt->tm_year;
    stm->mon = tt->tm_mon;
    stm->day = tt->tm_mday;
    stm->hour = tt->tm_hour;
    stm->min = tt->tm_min;
    stm->sec = tt->tm_sec;
    stm->hsec = 0;
}

variable_types: struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } *

variable_types: lt long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void __fastcall wait_period(__int64 a1)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)read(*(_DWORD *)a1, &buf, 8uLL) == -1 )
perror("read timer");
else
*(_QWORD *)(a1 + 8) += buf;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)read(*(_DWORD *)a1, &buf, 8uLL) == -1 )
perror("read timer");
else
*(_QWORD *)(a1 + 8) += buf;
}

original_code:
static void wait_period (struct periodic_info *info)
{
        unsigned long long missed;
        int ret;
        ret = read (info->timer_fd, &missed, sizeof (missed));
        if (ret == -1)
        {
                perror ("read timer");
                return;
        }
        info->wakeups_missed += missed;
}

canonical_original_code:
static void wait_period(struct periodic_info *info)
{
        unsigned long long missed;
        int ret;
        ret = read (info->timer_fd, &missed, sizeof (missed));
        if (ret == -1)
        {
                perror ("read timer");
                return;
        }
        info->wakeups_missed += missed;
}

variable_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; } *

variable_types:
missed
unsigned long long

variable_types: ret int


decompiled_code:
void __noreturn thread_DisplayValues()
{
unsigned int v0; // eax
time_t v1; // [rsp+0h] [rbp-38h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v3[2]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

make_periodic(0x186A0u, (__int64)v4);
v0 = time(0LL);
srand(v0);
time(&timer);
while ( 1 )
{
time(&v1);
v1 -= timer;
printw("Current Sensor output:\n");
printw("%ld s\n\n", v1);
if ( useMag )
printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
if ( useAcc )
printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
if ( useGyro )
printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
if ( useGPS )
{
nmea_info2pos(gpsInfo, v3);
printw(
"GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n",
180.0 * *(double *)v3 / 3.141592653589793,
180.0 * *(double *)&v3[1] / 3.141592653589793,
gpsInfo[10]);
}
wrefresh(stdscr);
werase(stdscr);
wait_period((__int64)v4);
}
}

canonical_decompiled_code:
void __noreturn func2()
{
unsigned int v0; // eax
time_t v1; // [rsp+0h] [rbp-38h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v3[2]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

func0(0x186A0u, (__int64)v4);
v0 = time(0LL);
srand(v0);
time(&timer);
while ( 1 )
{
time(&v1);
v1 -= timer;
printw("Current Sensor output:\n");
printw("%ld s\n\n", v1);
if ( useMag )
printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
if ( useAcc )
printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
if ( useGyro )
printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
if ( useGPS )
{
nmea_info2pos(gpsInfo, v3);
printw(
"GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n",
180.0 * *(double *)v3 / 3.141592653589793,
180.0 * *(double *)&v3[1] / 3.141592653589793,
gpsInfo[10]);
}
wrefresh(stdscr);
werase(stdscr);
func1((__int64)v4);
}
}

original_code:
void * thread_DisplayValues()
{
    struct periodic_info info;
    make_periodic (100000, &info);
    nmeaPOS dpos;
    srand ( time(((void *)0)) );
    time_t startTime;
    time(&startTime);
    while(1)
    {
        time_t currentTime;
        time ( &currentTime );
        currentTime -= startTime;
        printw("Current Sensor output:\n");
        printw("%ld s\n\n", currentTime );
        if(useMag) printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
        if(useAcc) printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
        if(useGyro) printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
        if(useGPS)
        {
            nmea_info2pos(&gpsInfo, &dpos);
            printw("GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n", 180*dpos.lat/3.14159265358979323846, 180*dpos.lon/3.14159265358979323846, gpsInfo.elv);
        }
        wrefresh(stdscr);
        werase(stdscr);
        wait_period(&info);
    }
}

canonical_original_code:
void *thread_DisplayValues()
{
    struct periodic_info info;
    make_periodic (100000, &info);
    struct _nmeaPOS dpos;
    srand ( time(((void *)0)) );
    long startTime;
    time(&startTime);
    while(1)
    {
        long currentTime;
        time ( &currentTime );
        currentTime -= startTime;
        printw("Current Sensor output:\n");
        printw("%ld s\n\n", currentTime );
        if(useMag) printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
        if(useAcc) printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
        if(useGyro) printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
        if(useGPS)
        {
            nmea_info2pos(&gpsInfo, &dpos);
            printw("GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n", 180*dpos.lat/3.14159265358979323846, 180*dpos.lon/3.14159265358979323846, gpsInfo.elv);
        }
        wrefresh(stdscr);
        werase(stdscr);
        wait_period(&info);
    }
}

variable_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; }

variable_types: struct _nmeaPOS { double lat; double lon; }

variable_types: startTime long

variable_types: currentTime long

return_type: void *


decompiled_code:
void __noreturn thread_SensorFusion()
{
_BYTE v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !useGyro )
{
LABEL_2:
if ( !(useMag | useAcc) )
{
LABEL_12:
if ( status_0 )
{
make_periodic(0x186A0u, (__int64)v0);
while ( 1 )
{
if ( useGyro )
itg3200_read_deg(gyro_xyz);
if ( useAcc )
lsm303_read_acc_SI(acc_xyz);
if ( useMag )
lsm303_read_mag_measurements(mag_xyz);
wait_period((__int64)v0);
}
}
LABEL_5:
perror("i2c-init failed\n");
exit(1);
}
LABEL_3:
if ( !(unsigned int)lsm303_init() )
{
status_0 = 0;
goto LABEL_5;
}
goto LABEL_12;
}
if ( (unsigned int)itg3200_init() )
{
if ( (unsigned int)itg3200_calibrate_gyro() )
goto LABEL_2;
status_0 = 0;
}
else
{
status_0 = 0;
}
if ( !(useMag | useAcc) )
goto LABEL_5;
goto LABEL_3;
}

canonical_decompiled_code:
void __noreturn func3()
{
_BYTE v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !useGyro )
{
LABEL_2:
if ( !(useMag | useAcc) )
{
LABEL_12:
if ( status_0 )
{
func0(0x186A0u, (__int64)v0);
while ( 1 )
{
if ( useGyro )
itg3200_read_deg(gyro_xyz);
if ( useAcc )
lsm303_read_acc_SI(acc_xyz);
if ( useMag )
lsm303_read_mag_measurements(mag_xyz);
func1((__int64)v0);
}
}
LABEL_5:
perror("i2c-init failed\n");
exit(1);
}
LABEL_3:
if ( !(unsigned int)lsm303_init() )
{
status_0 = 0;
goto LABEL_5;
}
goto LABEL_12;
}
if ( (unsigned int)itg3200_init() )
{
if ( (unsigned int)itg3200_calibrate_gyro() )
goto LABEL_2;
status_0 = 0;
}
else
{
status_0 = 0;
}
if ( !(useMag | useAcc) )
goto LABEL_5;
goto LABEL_3;
}

original_code:
void * thread_SensorFusion()
{
    struct periodic_info info;
    static int status = 1;
    if(useGyro)
        if (!itg3200_init())
            status = 0;
        else if (!itg3200_calibrate_gyro())
            status = 0;
    if(useAcc || useMag)
        if (!lsm303_init())
            status = 0;
    if (status)
    {
        make_periodic (100000, &info);
        while(1)
        {
           if(useGyro) itg3200_read_deg(gyro_xyz);
           if(useAcc) lsm303_read_acc_SI(acc_xyz);
           if(useMag) lsm303_read_mag_measurements(mag_xyz);
           wait_period(&info);
        }
    }
    perror("i2c-init failed\n");
    exit(1);
}

canonical_original_code:
void *thread_SensorFusion()
{
    struct periodic_info info;
    static int status = 1;
    if(useGyro)
        if (!itg3200_init())
            status = 0;
        else if (!itg3200_calibrate_gyro())
            status = 0;
    if(useAcc || useMag)
        if (!lsm303_init())
            status = 0;
    if (status)
    {
        make_periodic (100000, &info);
        while(1)
        {
           if(useGyro) itg3200_read_deg(gyro_xyz);
           if(useAcc) lsm303_read_acc_SI(acc_xyz);
           if(useMag) lsm303_read_mag_measurements(mag_xyz);
           wait_period(&info);
        }
    }
    perror("i2c-init failed\n");
    exit(1);
}

variable_types: status int

user_defined_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; }


decompiled_code:
void __noreturn thread_getGPS()
{
int v0; // eax
int v1; // ebp
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
char buf; // [rsp+Fh] [rbp-229h] BYREF
char v6[512]; // [rsp+10h] [rbp-228h] BYREF
char v7[40]; // [rsp+210h] [rbp-28h] BYREF

v0 = open("/dev/ttyUSB0", 2306);
if ( v0 == -1 )
{
perror("open_port: Unable to open /dev/ttyS0 -\n");
exit(1);
}
v1 = v0;
fcntl(v0, 4, 0LL);
make_periodic(0x7A120u, (__int64)v7);
while ( 1 )
{
LABEL_5:
v2 = 1LL;
do
{
if ( read(v1, &buf, 1uLL) != 1 )
{
wait_period((__int64)v7);
goto LABEL_5;
}
v3 = buf;
*(&buf + v2) = buf;
v4 = (unsigned int)v2++;
}
while ( v3 != 10 );
nmea_parse(&parser, v6, v4, gpsInfo);
}
}

canonical_decompiled_code:
void __noreturn func4()
{
int v0; // eax
int v1; // ebp
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
char buf; // [rsp+Fh] [rbp-229h] BYREF
char v6[512]; // [rsp+10h] [rbp-228h] BYREF
char v7[40]; // [rsp+210h] [rbp-28h] BYREF

v0 = open("/dev/ttyUSB0", 2306);
if ( v0 == -1 )
{
perror("open_port: Unable to open /dev/ttyS0 -\n");
exit(1);
}
v1 = v0;
fcntl(v0, 4, 0LL);
func0(0x7A120u, (__int64)v7);
while ( 1 )
{
LABEL_5:
v2 = 1LL;
do
{
if ( read(v1, &buf, 1uLL) != 1 )
{
func1((__int64)v7);
goto LABEL_5;
}
v3 = buf;
*(&buf + v2) = buf;
v4 = (unsigned int)v2++;
}
while ( v3 != 10 );
nmea_parse(&parser, v6, v4, gpsInfo);
}
}

original_code:
void * thread_getGPS()
{
    struct periodic_info info;
    int fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1)
    {
        perror("open_port: Unable to open /dev/ttyS0 -\n");
        exit(1);
    }
    else
    {
        fcntl(fd, 4, 0);
        make_periodic (500000, &info);
        char buffer[512];
        while(1)
        {
            char c;
            int index = 0;
            while(read(fd, &c, 1) == 1 )
            {
                buffer[index] = c;
                index++;
                if (c == '\n')
                {
                    nmea_parse(&parser, &buffer[0], index, &gpsInfo);
                    index = 0;
                }
            }
            wait_period(&info);
        }
    }
}

canonical_original_code:
void *thread_getGPS()
{
    struct periodic_info info;
    int fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1)
    {
        perror("open_port: Unable to open /dev/ttyS0 -\n");
        exit(1);
    }
    else
    {
        fcntl(fd, 4, 0);
        make_periodic (500000, &info);
        char buffer[512];
        while(1)
        {
            char c;
            int index = 0;
            while(read(fd, &c, 1) == 1 )
            {
                buffer[index] = c;
                index++;
                if (c == '\n')
                {
                    nmea_parse(&parser, &buffer[0], index, &gpsInfo);
                    index = 0;
                }
            }
            wait_period(&info);
        }
    }
}

variable_types: fd int

variable_types:
buffer
char [512]

variable_types: c char

variable_types: index int


decompiled_code:
__int64 __fastcall nmea_zero_GPGSV(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0LL;
*(_QWORD *)((char *)a1 + 84) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 92) >> 3));
return result;
}

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

*a1 = 0LL;
*(_QWORD *)((char *)a1 + 84) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 92) >> 3));
return result;
}

original_code:
void nmea_zero_GPGSV(nmeaGPGSV *pack)
{
    memset(pack, 0, sizeof(nmeaGPGSV));
}

canonical_original_code:
void nmea_zero_GPGSV(struct _nmeaGPGSV *pack)
{
    memset(pack, 0, sizeof(nmeaGPGSV));
}

variable_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat_data[-1]; } *

user_defined_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE sat_data[-1]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
size_t v5; // rbp
const char *v6; // r14
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
pthread_t th; // [rsp+10h] [rbp-38h] BYREF
pthread_t v9[6]; // [rsp+18h] [rbp-30h] BYREF

if ( argc > 1 )
{
v3 = argv;
do
{
if ( **v3 == 45 )
{
useGyro = 0;
useMag = 0;
useAcc = 0;
useGPS = 0;
v5 = 1LL;
while ( 2 )
{
v6 = *v3;
if ( strlen(*v3) > v5 )
{
switch ( v6[v5] )
{
case 'A':
case 'a':
useAcc = 1;
goto LABEL_10;
case 'G':
case 'g':
useGyro = 1;
goto LABEL_10;
case 'M':
case 'm':
useMag = 1;
goto LABEL_10;
case 'P':
case 'p':
useGPS = 1;
LABEL_10:
++v5;
continue;
default:
puts("Usage:");
puts("If no parameter is given all sensors are use.");
puts("Only use certain sensors with:");
puts("\t-m/-M:\t include magnetometer");
puts("\t-a/-A:\t include accelerometer");
puts("\t-g/-G:\t include gyroscope");
puts("\t-p/-P:\t include GPS position\n");
return 1;
}
}
break;
}
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
initscr();
if ( useGPS )
{
nmea_zero_INFO(&gpsInfo, argv);
nmea_parser_init(&parser);
pthread_create(v9, 0LL, (void *(*)(void *))&thread_getGPS, 0LL);
pthread_join(v9[0], 0LL);
}
pthread_create(&newthread, 0LL, (void *(*)(void *))&thread_SensorFusion, 0LL);
pthread_create(&th, 0LL, (void *(*)(void *))&thread_DisplayValues, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
endwin();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc != 1)
    {
        int i;
        for (i = 0; i< argc; i++)
            if (argv[i][0] == '-')
            {
                useGyro = 0;
                useMag = 0;
                useAcc = 0;
                useGPS = 0;
                int j;
                for (j = 1; j< strlen(argv[i]); j++)
                    switch (argv[i][j])
                    {
                    case 'm':
                    case 'M': useMag = 1; break;
                    case 'a':
                    case 'A': useAcc = 1; break;
                    case 'G':
                    case 'g': useGyro = 1; break;
                    case 'p':
                    case 'P': useGPS = 1; break;
                    default: printf("Usage:\n");
                        printf("If no parameter is given all sensors are use.\n");
                        printf("Only use certain sensors with:\n");
                        printf("\t-m/-M:\t include magnetometer\n");
                        printf("\t-a/-A:\t include accelerometer\n");
                        printf("\t-g/-G:\t include gyroscope\n");
                        printf("\t-p/-P:\t include GPS position\n\n");
                        return 1;
                    }
            }
    }
    initscr();
      pthread_t t_1;
      pthread_t t_2;
      pthread_t t_3;
      if(useGPS)
      {
        nmea_zero_INFO(&gpsInfo);
        nmea_parser_init(&parser);
        pthread_create (&t_1, ((void *)0), thread_getGPS, ((void *)0)) ;
        pthread_join (t_1, ((void *)0));
      }
      pthread_create (&t_3, ((void *)0), thread_SensorFusion, ((void *)0)) ;
      pthread_create (&t_2, ((void *)0), thread_DisplayValues, ((void *)0)) ;
       pthread_join (t_2, ((void *)0));
       pthread_join (t_3, ((void *)0));
      endwin();
      return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc != 1)
    {
        int i;
        for (i = 0; i< argc; i++)
            if (argv[i][0] == '-')
            {
                useGyro = 0;
                useMag = 0;
                useAcc = 0;
                useGPS = 0;
                int j;
                for (j = 1; j< strlen(argv[i]); j++)
                    switch (argv[i][j])
                    {
                    case 'm':
                    case 'M': useMag = 1; break;
                    case 'a':
                    case 'A': useAcc = 1; break;
                    case 'G':
                    case 'g': useGyro = 1; break;
                    case 'p':
                    case 'P': useGPS = 1; break;
                    default: printf("Usage:\n");
                        printf("If no parameter is given all sensors are use.\n");
                        printf("Only use certain sensors with:\n");
                        printf("\t-m/-M:\t include magnetometer\n");
                        printf("\t-a/-A:\t include accelerometer\n");
                        printf("\t-g/-G:\t include gyroscope\n");
                        printf("\t-p/-P:\t include GPS position\n\n");
                        return 1;
                    }
            }
    }
    initscr();
      unsigned long t_1;
      unsigned long t_2;
      unsigned long t_3;
      if(useGPS)
      {
        nmea_zero_INFO(&gpsInfo);
        nmea_parser_init(&parser);
        pthread_create (&t_1, ((void *)0), thread_getGPS, ((void *)0)) ;
        pthread_join (t_1, ((void *)0));
      }
      pthread_create (&t_3, ((void *)0), thread_SensorFusion, ((void *)0)) ;
      pthread_create (&t_2, ((void *)0), thread_DisplayValues, ((void *)0)) ;
       pthread_join (t_2, ((void *)0));
       pthread_join (t_3, ((void *)0));
      endwin();
      return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: j int


original_code:
static uint8_t read_bits(const uint8_t *data, size_t idx)
{
    size_t idx_base = idx / 8;
    size_t idx_off = idx % 8;
    return 0x3F &
        ((data[idx_base] >> idx_off) | (data[idx_base+1] << (8 - idx_off)));
}

canonical_original_code:
static unsigned char read_bits(unsigned char *data, unsigned long idx)
{
    unsigned long idx_base = idx / 8;
    unsigned long idx_off = idx % 8;
    return 0x3F &
        ((data[idx_base] >> idx_off) | (data[idx_base+1] << (8 - idx_off)));
}

variable_types:
data
unsigned char *

variable_types:
idx
unsigned long

return_type: unsigned char


decompiled_code:
__int64 __fastcall base64_todigit(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3F;
if ( (unsigned __int8)v1 <= 9u )
return (unsigned int)(v1 + 48);
if ( (unsigned __int8)(v1 - 10) <= 0x19u )
return (unsigned int)(v1 + 87);
if ( (unsigned __int8)(v1 - 36) <= 0x19u )
return (unsigned int)(v1 + 29);
result = 61LL;
if ( (_BYTE)v1 == 62 )
result = 45LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3F;
if ( (unsigned __int8)v1 <= 9u )
return (unsigned int)(v1 + 48);
if ( (unsigned __int8)(v1 - 10) <= 0x19u )
return (unsigned int)(v1 + 87);
if ( (unsigned __int8)(v1 - 36) <= 0x19u )
return (unsigned int)(v1 + 29);
result = 61LL;
if ( (_BYTE)v1 == 62 )
result = 45LL;
return result;
}

original_code:
static char base64_todigit(uint8_t val)
{
    val &= 0x3F;
    if (val < 10)
    {
        return val + '0';
    }
    val -= 10;
    if (val < 26)
    {
        return val + 'a';
    }
    val -= 26;
    if (val < 26)
    {
        return val + 'A';
    }
    val -= 26;
    if (val == 0)
    {
        return '-';
    }
    if (val == 1)
    {
        return '=';
    }
    return (-1);
}

canonical_original_code:
static char base64_todigit(unsigned char val)
{
    val &= 0x3F;
    if (val < 10)
    {
        return val + '0';
    }
    val -= 10;
    if (val < 26)
    {
        return val + 'a';
    }
    val -= 26;
    if (val < 26)
    {
        return val + 'A';
    }
    val -= 26;
    if (val == 0)
    {
        return '-';
    }
    if (val == 1)
    {
        return '=';
    }
    return (-1);
}

variable_types:
val
unsigned char

return_type: char


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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned __int8)(a1 - 65) <= 0x19u )
{
result = (unsigned int)(a1 - 29);
}
else if ( (_BYTE)a1 == 45 )
{
result = 62LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (_BYTE)a1 == 61 )
result = 63LL;
}
}
return result;
}

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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned __int8)(a1 - 65) <= 0x19u )
{
result = (unsigned int)(a1 - 29);
}
else if ( (_BYTE)a1 == 45 )
{
result = 62LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (_BYTE)a1 == 61 )
result = 63LL;
}
}
return result;
}

original_code:
static uint8_t base64_fromdigit(char dig)
{
    if (dig >= '0' && dig <= '9')
    {
        return dig - '0';
    }
    if (dig >= 'a' && dig <= 'z')
    {
        return dig - 'a' + 10;
    }
    if (dig >= 'A' && dig <= 'Z')
    {
        return dig - 'A' + 10 + 26;
    }
    if (dig == '-')
    {
        return 0x3E;
    }
    if (dig == '=')
    {
        return 0x3F;
    }
    return (uint8_t)(-1);
}

canonical_original_code:
static unsigned char base64_fromdigit(char dig)
{
    if (dig >= '0' && dig <= '9')
    {
        return dig - '0';
    }
    if (dig >= 'a' && dig <= 'z')
    {
        return dig - 'a' + 10;
    }
    if (dig >= 'A' && dig <= 'Z')
    {
        return dig - 'A' + 10 + 26;
    }
    if (dig == '-')
    {
        return 0x3E;
    }
    if (dig == '=')
    {
        return 0x3F;
    }
    return (unsigned char)(-1);
}

variable_types: dig char


decompiled_code:
unsigned __int64 __fastcall base64_encode(__int64 a1, __int64 a2, _BYTE *a3)
{
unsigned __int64 v4; // rdx
unsigned __int64 v5; // r14
_BYTE *v6; // rbx
__int64 v7; // r13
unsigned __int64 v8; // rbp
char v9; // al

v4 = (8 * a2 - 1) / 6uLL;
v5 = v4 + 1;
v6 = a3;
v7 = (__int64)&a3[v4 + 1];
v8 = 0LL;
do
{
v9 = read_bits(a1, v8);
*v6 = base64_todigit(v9);
v8 += 6LL;
++v6;
}
while ( v6 != (_BYTE *)v7 );
return v5;
}

original_code:
size_t base64_encode(const uint8_t *in, size_t insize, char *out)
{
    size_t outsize = (insize*8 - 1) / 6 + 1;
    for (size_t i = 0; i < outsize; i++)
    {
        uint8_t val = read_bits(in, 6 * i);
        out[i] = base64_todigit(val);
    }
    return outsize;
}

canonical_original_code:
unsigned long base64_encode(unsigned char *in, unsigned long insize, char *out)
{
    unsigned long outsize = (insize*8 - 1) / 6 + 1;
    for (unsigned long i = 0; i < outsize; i++)
    {
        unsigned char val = read_bits(in, 6 * i);
        out[i] = base64_todigit(val);
    }
    return outsize;
}

variable_types:
in
unsigned char *

variable_types:
insize
unsigned long

variable_types:
out
char *

variable_types:
outsize
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall base64_decode(char *a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
unsigned __int64 i; // rbp
unsigned __int8 v6; // al

if ( !a2 )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
v4 = a1;
for ( i = 0LL; ; i += 6LL )
{
v6 = base64_fromdigit(*v4);
if ( v6 == 0xFF )
break;
write_bits(a3, i, v6);
if ( ++v4 == &a1[a2] )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
unsigned __int64 i; // rbp
unsigned __int8 v6; // al

if ( !a2 )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
v4 = a1;
for ( i = 0LL; ; i += 6LL )
{
v6 = func3(*v4);
if ( v6 == 0xFF )
break;
func1(a3, i, v6);
if ( ++v4 == &a1[a2] )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
}
return -1LL;
}

original_code:
size_t base64_decode(const char *in, size_t insize, uint8_t *out)
{
    for (size_t i = 0; i < insize; i++)
    {
        uint8_t val = base64_fromdigit(in[i]);
        if (val == (uint8_t)(-1))
        {
            return (size_t)-1;
        }
        write_bits(out, i*6, val);
    }
    return (6*insize - 1) / 8 + 1;
}

canonical_original_code:
unsigned long base64_decode(char *in, unsigned long insize, unsigned char *out)
{
    for (unsigned long i = 0; i < insize; i++)
    {
        unsigned char val = base64_fromdigit(in[i]);
        if (val == (unsigned char)(-1))
        {
            return (unsigned long)-1;
        }
        write_bits(out, i*6, val);
    }
    return (6*insize - 1) / 8 + 1;
}

variable_types:
in
char *

variable_types:
out
unsigned char *


decompiled_code:
int __fastcall string_compare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int string_compare(const void *a, const void *b)
{
    const char *a1 = *((const char **)a);
    const char *b1 = *((const char **)b);
    return strcmp(a1, b1);
}

canonical_original_code:
static int string_compare(void *a, void *b)
{
    char *a1 = *((const char **)a);
    char *b1 = *((const char **)b);
    return strcmp(a1, b1);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall match_suffix(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
unsigned int v4; // edx

v2 = strlen(s2);
v3 = strlen(s);
v4 = 0;
if ( v2 < v3 )
LOBYTE(v4) = strcmp(&s[v3 - v2], s2) == 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
unsigned int v4; // edx

v2 = strlen(s2);
v3 = strlen(s);
v4 = 0;
if ( v2 < v3 )
LOBYTE(v4) = strcmp(&s[v3 - v2], s2) == 0;
return v4;
}

original_code:
static _Bool match_suffix(const char *name, const char *suffix)
{
    size_t suffix_len = strlen(suffix);
    size_t name_len = strlen(name);
    if (name_len <= suffix_len)
    {
        return 0;
    }
    return (strcmp(name + name_len - suffix_len, suffix) == 0);
}

canonical_original_code:
static _Bool match_suffix(char *name, char *suffix)
{
    unsigned long suffix_len = strlen(suffix);
    unsigned long name_len = strlen(name);
    if (name_len <= suffix_len)
    {
        return 0;
    }
    return (strcmp(name + name_len - suffix_len, suffix) == 0);
}

variable_types:
name
char *

variable_types:
suffix
char *


decompiled_code:
__int64 __fastcall should_optimise(char *s)
{
char v1; // dl
char v2; // al
char v3; // dl

v1 = match_suffix(s, ".html");
v2 = 1;
if ( !v1 )
{
v3 = match_suffix(s, ".css");
v2 = 1;
if ( !v3 )
v2 = match_suffix(s, ".js");
}
return v2 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s)
{
char v1; // dl
char v2; // al
char v3; // dl

v1 = func8(s, ".html");
v2 = 1;
if ( !v1 )
{
v3 = func8(s, ".css");
v2 = 1;
if ( !v3 )
v2 = func8(s, ".js");
}
return v2 & 1;
}

original_code:
static _Bool should_optimise(const char *name)
{
    return (match_suffix(name, ".html") ||
            match_suffix(name, ".css") ||
            match_suffix(name, ".js"));
}

canonical_original_code:
static _Bool should_optimise(char *name)
{
    return (match_suffix(name, ".html") ||
            match_suffix(name, ".css") ||
            match_suffix(name, ".js"));
}


decompiled_code:
int __fastcall print_symbol(char *a1)
{
int result; // eax
char v2; // bl
const unsigned __int16 **v3; // r12
char *v4; // rbp

result = fwrite("data_", 1uLL, 5uLL, _bss_start);
v2 = *a1;
if ( *a1 )
{
v3 = __ctype_b_loc();
v4 = a1 + 1;
do
{
if ( ((*v3)[v2] & 8) != 0 )
result = fputc(v2, _bss_start);
else
result = fputc(95, _bss_start);
v2 = *v4++;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *a1)
{
int result; // eax
char v2; // bl
const unsigned __int16 **v3; // r12
char *v4; // rbp

result = fwrite("data_", 1uLL, 5uLL, _bss_start);
v2 = *a1;
if ( *a1 )
{
v3 = __ctype_b_loc();
v4 = a1 + 1;
do
{
if ( ((*v3)[v2] & 8) != 0 )
result = fputc(v2, _bss_start);
else
result = fputc(95, _bss_start);
v2 = *v4++;
}
while ( v2 );
}
return result;
}

original_code:
static void print_symbol(const char *name)
{
    fputs("data_", stdout);
    for (int i = 0; name[i]; i++)
    {
        if (((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short int) _ISalnum))
        {
            fputc(name[i], stdout);
        }
        else
        {
            fputc('_', stdout);
        }
    }
}

canonical_original_code:
static void print_symbol(char *name)
{
    fputs("data_", stdout);
    for (int i = 0; name[i]; i++)
    {
        if (((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short) _ISalnum))
        {
            fputc(name[i], stdout);
        }
        else
        {
            fputc('_', stdout);
        }
    }
}

variable_types: i int


original_code:
static int128_t aes_expandkey_assist(int128_t a, int128_t b)
{
    b = __builtin_ia32_pshufd(b, 0xFF);
    int128_t c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    return c ^ a ^ b;
}

canonical_original_code:
static long long aes_expandkey_assist(long long a, long long b)
{
    b = __builtin_ia32_pshufd(b, 0xFF);
    long long c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    return c ^ a ^ b;
}

variable_types:
a
long long

variable_types:
b
long long

variable_types:
c
long long

return_type: long long


decompiled_code:
_BOOL8 aes_hardware_test()
{
_RAX = 1LL;
__asm { cpuid }
return (_RCX & 0x2000000) != 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
_RAX = 1LL;
__asm { cpuid }
return (_RCX & 0x2000000) != 0;
}

original_code:
extern _Bool aes_hardware_test(void)
{
    unsigned a, b, c, d;
    __asm__ __volatile__ ("cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (1));
    return ((c & 0x02000000) != 0);
}

canonical_original_code:
extern _Bool aes_hardware_test()
{
    unsigned int a; unsigned int b; unsigned int c; unsigned int d;
    __asm__ __volatile__ ("cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (1));
    return ((c & 0x02000000) != 0);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int


decompiled_code:
__int16 __fastcall cktp_calculate_checksum(_BYTE *a1, __int16 a2)
{
_BYTE *v2; // rcx
__int64 v3; // rsi
__int16 result; // ax

if ( !a2 )
return 0;
v2 = a1;
v3 = (__int64)&a1[(unsigned __int16)(a2 - 1) + 1];
result = 0;
do
result = crc16_table[(unsigned __int8)(*v2++ ^ HIBYTE(result))] ^ (result << 8);
while ( v2 != (_BYTE *)v3 );
return result;
}

canonical_decompiled_code:
__int16 __fastcall func0(_BYTE *a1, __int16 a2)
{
_BYTE *v2; // rcx
__int64 v3; // rsi
__int16 result; // ax

if ( !a2 )
return 0;
v2 = a1;
v3 = (__int64)&a1[(unsigned __int16)(a2 - 1) + 1];
result = 0;
do
result = crc16_table[(unsigned __int8)(*v2++ ^ HIBYTE(result))] ^ (result << 8);
while ( v2 != (_BYTE *)v3 );
return result;
}

original_code:
uint16_t cktp_calculate_checksum(uint8_t *data, uint16_t length)
{
    uint16_t remainder = 0;
    for (uint16_t i = 0; i < length; i++)
    {
        uint8_t byte = data[i] ^ (remainder >> 8*(sizeof(uint16_t)-1));
        remainder = crc16_table[byte] ^ (remainder << 8);
    }
    return remainder;
}

canonical_original_code:
unsigned short cktp_calculate_checksum(unsigned char *data, unsigned short length)
{
    unsigned short remainder = 0;
    for (unsigned short i = 0; i < length; i++)
    {
        unsigned char byte = data[i] ^ (remainder >> 8*(sizeof(uint16_t)-1));
        remainder = crc16_table[byte] ^ (remainder << 8);
    }
    return remainder;
}

variable_types:
data
unsigned char *

variable_types:
length
unsigned short

variable_types:
remainder
unsigned short

variable_types:
i
unsigned short

variable_types:
byte
unsigned char

return_type: unsigned short


decompiled_code:
const char *__fastcall cktp_error_to_string(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 == 2 )
return "Operation not supported";
if ( a1 > 2u )
{
result = "Unknown error";
if ( a1 == 3 )
result = "Invalid argument";
}
else
{
result = "Not authenticated";
if ( !a1 )
result = "Success";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 == 2 )
return "Operation not supported";
if ( a1 > 2u )
{
result = "Unknown error";
if ( a1 == 3 )
result = "Invalid argument";
}
else
{
result = "Not authenticated";
if ( !a1 )
result = "Success";
}
return result;
}

original_code:
const char *cktp_error_to_string(uint8_t err)
{
    switch (err)
    {
        case 0x00:
            return "Success";
        case 0x01:
            return "Not authenticated";
        case 0x02:
            return "Operation not supported";
        case 0x03:
            return "Invalid argument";
        default:
            return "Unknown error";
    }
}

canonical_original_code:
char *cktp_error_to_string(unsigned char err)
{
    switch (err)
    {
        case 0x00:
            return "Success";
        case 0x01:
            return "Not authenticated";
        case 0x02:
            return "Operation not supported";
        case 0x03:
            return "Invalid argument";
        default:
            return "Unknown error";
    }
}

variable_types:
err
unsigned char

return_type: char *


repo: bastibl/bame

decompiled_code:
void __noreturn sig_handler()
{
endwin();
puts("blame exiting...cya");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
endwin();
puts("blame exiting...cya");
exit(0);
}

original_code:
static void
sig_handler(int s) {
 endwin();
 printf("blame exiting...cya\n");
 exit(0);
}

variable_types: s int


decompiled_code:
int init_curses()
{
initscr();
curs_set(0);
noecho();
cbreak();
start_color();
use_default_colors();
init_pair(1, 7, -1);
init_pair(2, 7, 1);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
return mvprintw(0, 0, "..:: B-A-M-E ::..");
}

canonical_decompiled_code:
int func8()
{
initscr();
curs_set(0);
noecho();
cbreak();
start_color();
use_default_colors();
init_pair(1, 7, -1);
init_pair(2, 7, 1);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
return mvprintw(0, 0, "..:: B-A-M-E ::..");
}


decompiled_code:
int update_score()
{
return mvprintw(1, 0, "score: % 10u level: % 2u", (unsigned int)score, (unsigned int)level);
}

canonical_decompiled_code:
int func9()
{
return mvprintw(1, 0, "score: % 10u level: % 2u", (unsigned int)score, (unsigned int)level);
}

original_code:
void
update_score() {
 mvprintw(1, 0, "score: % 10u   level:  % 2u", score, level);
}


decompiled_code:
int print_current()
{
unsigned int i; // ebx
int v1; // eax

wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 19, 1);
printw(" | ");
for ( i = 7; i != -1; --i )
{
v1 = (unsigned __int16)cur_line;
if ( _bittest(&v1, i) )
{
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200uLL, 0LL);
printw("__");
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
printw(" | ");
}
else
{
printw("__ | ");
}
}
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func10()
{
unsigned int i; // ebx
int v1; // eax

wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 19, 1);
printw(" | ");
for ( i = 7; i != -1; --i )
{
v1 = (unsigned __int16)cur_line;
if ( _bittest(&v1, i) )
{
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200uLL, 0LL);
printw("__");
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
printw(" | ");
}
else
{
printw("__ | ");
}
}
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

variable_types: line int


decompiled_code:
int print_rows()
{
int v0; // ebx
int i; // ebp
__int64 v2; // rsi

v0 = row_index;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 18, 5);
for ( i = 18; i != 3; wmove(stdscr__NCURSES6_TINFO_5_0_19991023, i, 5) )
{
v2 = (unsigned int)rows[v0];
if ( (_DWORD)v2 )
printw("% 6u", v2);
else
printw(" ");
v0 = (v0 + 1) % 15;
--i;
}
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func11()
{
int v0; // ebx
int i; // ebp
__int64 v2; // rsi

v0 = row_index;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 18, 5);
for ( i = 18; i != 3; wmove(stdscr__NCURSES6_TINFO_5_0_19991023, i, 5) )
{
v2 = (unsigned int)rows[v0];
if ( (_DWORD)v2 )
printw("% 6u", v2);
else
printw(" ");
v0 = (v0 + 1) % 15;
--i;
}
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
void
print_rows() {
 int i;
 int index = row_index;
 int line = 15 + 3;
 int col = 5;
 wmove(stdscr,(line),(col));
 for(i = 0; i < 15; i++) {
  if(!rows[index]) {
   printw("      ");
  } else {
   printw("% 6u", rows[index]);
  }
  index = (index + 1) % 15;
  wmove(stdscr,(--line),(col));
 }
 wrefresh(stdscr);
}

variable_types: index int

variable_types: col int


decompiled_code:
int reset_game()
{
int *v0; // rax
int result; // eax

score = 0;
update_score();
v0 = rows;
do
*v0++ = 0;
while ( v0 != &score );
row_index = 0;
cur_line = 0;
print_current();
print_rows();
go_on = 1;
result = mvprintw(2, 0, " ");
delay = 2500000;
lines_in_level = 0;
level = 0;
return result;
}

canonical_decompiled_code:
int func12()
{
int *v0; // rax
int result; // eax

score = 0;
func9();
v0 = rows;
do
*v0++ = 0;
while ( v0 != &score );
row_index = 0;
cur_line = 0;
func10();
func11();
go_on = 1;
result = mvprintw(2, 0, " ");
delay = 2500000;
lines_in_level = 0;
level = 0;
return result;
}

original_code:
void
reset_game() {
 int i;
 score = 0;
 update_score();
 for(i = 0; i < 15; i++) {
  rows[i] = 0;
 }
 row_index = 0;
 cur_line = 0;
 print_current();
 print_rows();
 go_on = 1;
 mvprintw(2,0,"                                           ");
 delay = 2500 * 1000;
 lines_in_level = 0;
 level = 0;
}

variable_types: i int


decompiled_code:
int add_row()
{
int v0; // ebx
int v1; // ebp
int result; // eax

v0 = row_index;
v1 = 15;
while ( rows[v0] )
{
result = (v0 + 1) % 15;
v0 = result;
if ( !--v1 )
{
go_on = 0;
return result;
}
}
rows[v0] = rand() % 255 + 1;
if ( ++lines_in_level == 18 )
{
delay -= 100000;
lines_in_level = 0;
++level;
}
return print_rows();
}

canonical_decompiled_code:
int func13()
{
int v0; // ebx
int v1; // ebp
int result; // eax

v0 = row_index;
v1 = 15;
while ( rows[v0] )
{
result = (v0 + 1) % 15;
v0 = result;
if ( !--v1 )
{
go_on = 0;
return result;
}
}
rows[v0] = rand() % 255 + 1;
if ( ++lines_in_level == 18 )
{
delay -= 100000;
lines_in_level = 0;
++level;
}
return func11();
}

original_code:
void
add_row() {
 int i = 15;
 int index = row_index;
 while(i) {
  if(!rows[index]) {
   rows[index] = (rand() % 255) + 1;
   break;
  }
  i--;
  index = (index + 1) % 15;
 }
 if(!i) {
  go_on = i;
  return;
 }
 lines_in_level++;
 if(lines_in_level == 18) {
  delay -= 100 * 1000;
  lines_in_level = 0;
  level++;
 }
 print_rows();
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
int v5; // ebx
int v6; // ebx
char v7; // al

init_curses();
signal(2, (__sighandler_t)sig_handler);
signal(15, (__sighandler_t)sig_handler);
v3 = time(0LL);
srand(v3);
v4 = 3;
v5 = 7;
if ( pthread_mutex_init(&mutex, 0LL) )
{
puts("can't create mutex");
pthread_cancel(thread);
endwin();
v6 = 1;
}
else
{
do
{
mvprintw(20, v4, "% 3u", (unsigned int)(1 << v5--));
v4 += 7;
}
while ( v5 != -1 );
mvprintw(3, 1, "-----------------------------------------");
while ( 1 )
{
reset_game();
v6 = pthread_create(&thread, 0LL, input_thread, 0LL);
if ( v6 )
break;
while ( go_on )
{
usleep(delay);
add_row();
}
pthread_cancel(thread);
mvprintw(2, 1, "press space for new game, or 'q' to exit");
while ( 1 )
{
v7 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( (v7 & 0xDF) == 0 )
break;
if ( v7 == 113 )
{
endwin();
return v6;
}
}
}
printf("can't create thread");
endwin();
v6 = 1;
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
int v5; // ebx
int v6; // ebx
char v7; // al

func8();
signal(2, (__sighandler_t)sig_handler);
signal(15, (__sighandler_t)sig_handler);
v3 = time(0LL);
srand(v3);
v4 = 3;
v5 = 7;
if ( pthread_mutex_init(&mutex, 0LL) )
{
puts("can't create mutex");
pthread_cancel(thread);
endwin();
v6 = 1;
}
else
{
do
{
mvprintw(20, v4, "% 3u", (unsigned int)(1 << v5--));
v4 += 7;
}
while ( v5 != -1 );
mvprintw(3, 1, "-----------------------------------------");
while ( 1 )
{
func12();
v6 = pthread_create(&thread, 0LL, input_thread, 0LL);
if ( v6 )
break;
while ( go_on )
{
usleep(delay);
func13();
}
pthread_cancel(thread);
mvprintw(2, 1, "press space for new game, or 'q' to exit");
while ( 1 )
{
v7 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( (v7 & 0xDF) == 0 )
break;
if ( v7 == 113 )
{
endwin();
return v6;
}
}
}
printf("can't create thread");
endwin();
v6 = 1;
}
return v6;
}

original_code:
int
main(int argc, char **arvc) {
 init_curses();
 signal(2, sig_handler);
 signal(15, sig_handler);
 srand((unsigned) time(((void *)0)));
 if(pthread_mutex_init(&mutex, ((void *)0))) {
  printf("can't create mutex\n");
  pthread_cancel(thread);
  endwin();
  return 1;
 }
 int i;
 for(i = 7; i >= 0; i--) {
  mvprintw(15 + 5, (7 - i) * 7 + 3 , "% 3u", 1<<i);
 }
 mvprintw(3, 1, "-----------------------------------------");
 char c;
 while(1) {
  reset_game();
  if(pthread_create(&thread, ((void *)0), input_thread, ((void *)0))) {
   printf("can't create thread");
   endwin();
   return 1;
  }
  while(go_on) {
   usleep(delay);
   add_row();
  }
  pthread_cancel(thread);
  mvprintw(2, 1, "press space for new game, or 'q' to exit");
  while(c = wgetch(stdscr)) {
   if(c == ' ') {
    break;
   }
   if(c == 'q') {
    goto out;
   }
  }
 }
out:
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **arvc) {
 init_curses();
 signal(2, sig_handler);
 signal(15, sig_handler);
 srand((unsigned int) time(((void *)0)));
 if(pthread_mutex_init(&mutex, ((void *)0))) {
  printf("can't create mutex\n");
  pthread_cancel(thread);
  endwin();
  return 1;
 }
 int i;
 for(i = 7; i >= 0; i--) {
  mvprintw(15 + 5, (7 - i) * 7 + 3 , "% 3u", 1<<i);
 }
 mvprintw(3, 1, "-----------------------------------------");
 char c;
 while(1) {
  reset_game();
  if(pthread_create(&thread, ((void *)0), input_thread, ((void *)0))) {
   printf("can't create thread");
   endwin();
   return 1;
  }
  while(go_on) {
   usleep(delay);
   add_row();
  }
  pthread_cancel(thread);
  mvprintw(2, 1, "press space for new game, or 'q' to exit");
  while(c = wgetch(stdscr)) {
   if(c == ' ') {
    break;
   }
   if(c == 'q') {
    goto out;
   }
  }
 }
out:
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
arvc
char **

variable_types: c char


decompiled_code:
int delete_row()
{
int v0; // edx

v0 = row_index;
rows[row_index] = 0;
row_index = (v0 + 1) % 0xFu;
return print_rows();
}

canonical_decompiled_code:
int func14()
{
int v0; // edx

v0 = row_index;
rows[row_index] = 0;
row_index = (v0 + 1) % 0xFu;
return func11();
}

original_code:
void
delete_row() {
 rows[row_index] = 0;
 row_index = (row_index + 1) % 15;
 print_rows();
}


decompiled_code:
int check_row()
{
int v0; // eax

v0 = rows[row_index];
if ( v0 && v0 == (unsigned __int16)cur_line )
{
score += 10;
update_score();
cur_line = 0;
delete_row();
}
return print_current();
}

canonical_decompiled_code:
int func15()
{
int v0; // eax

v0 = rows[row_index];
if ( v0 && v0 == (unsigned __int16)cur_line )
{
score += 10;
func9();
cur_line = 0;
func14();
}
return func10();
}

original_code:
void
check_row() {
 if(rows[row_index] && (rows[row_index] == cur_line)) {
  score += 10;
  update_score();
  cur_line = 0;
  delete_row();
 }
 print_current();
}


decompiled_code:
void __fastcall input_thread(void *a1)
{
while ( 1 )
{
switch ( (unsigned __int8)wgetch(stdscr__NCURSES6_TINFO_5_0_19991023) )
{
case ';':
cur_line ^= 1u;
break;
case 'a':
cur_line ^= 0x80u;
break;
case 'd':
cur_line ^= 0x20u;
break;
case 'f':
cur_line ^= 0x10u;
break;
case 'j':
cur_line ^= 8u;
break;
case 'k':
cur_line ^= 4u;
break;
case 'l':
cur_line ^= 2u;
break;
case 'q':
go_on = 0;
break;
case 's':
cur_line ^= 0x40u;
break;
default:
break;
}
check_row();
}
}

canonical_decompiled_code:
void __fastcall func16(void *a1)
{
while ( 1 )
{
switch ( (unsigned __int8)wgetch(stdscr__NCURSES6_TINFO_5_0_19991023) )
{
case ';':
cur_line ^= 1u;
break;
case 'a':
cur_line ^= 0x80u;
break;
case 'd':
cur_line ^= 0x20u;
break;
case 'f':
cur_line ^= 0x10u;
break;
case 'j':
cur_line ^= 8u;
break;
case 'k':
cur_line ^= 4u;
break;
case 'l':
cur_line ^= 2u;
break;
case 'q':
go_on = 0;
break;
case 's':
cur_line ^= 0x40u;
break;
default:
break;
}
func15();
}
}

original_code:
void*
input_thread(void *args) {
 char c;
 while(1) {
  c = wgetch(stdscr);
  switch(c) {
   case 'a':
    cur_line ^= 1 << 7;
    break;
   case 's':
    cur_line ^= 1 << 6;
    break;
   case 'd':
    cur_line ^= 1 << 5;
    break;
   case 'f':
    cur_line ^= 1 << 4;
    break;
   case 'j':
    cur_line ^= 1 << 3;
    break;
   case 'k':
    cur_line ^= 1 << 2;
    break;
   case 'l':
    cur_line ^= 1 << 1;
    break;
   case ';':
    cur_line ^= 1 << 0;
    break;
   case 'q':
    go_on = 0;
    break;
  }
  check_row();
 }
}

canonical_original_code:
void *input_thread(void *args) {
 char c;
 while(1) {
  c = wgetch(stdscr);
  switch(c) {
   case 'a':
    cur_line ^= 1 << 7;
    break;
   case 's':
    cur_line ^= 1 << 6;
    break;
   case 'd':
    cur_line ^= 1 << 5;
    break;
   case 'f':
    cur_line ^= 1 << 4;
    break;
   case 'j':
    cur_line ^= 1 << 3;
    break;
   case 'k':
    cur_line ^= 1 << 2;
    break;
   case 'l':
    cur_line ^= 1 << 1;
    break;
   case ';':
    cur_line ^= 1 << 0;
    break;
   case 'q':
    go_on = 0;
    break;
  }
  check_row();
 }
}

variable_types:
args
void *


repo: bauerca/gridfloat

original_code:
void gf_init_data(int types, size_t sz, gf_data *data) {
    memset((void *)data, 0, sizeof(gf_data));
    if (types & ELEVATION)
        data->elev = (float *)malloc(sz * sizeof(float));
    if (types & GRADX)
        data->gradx = (double *)malloc(sz * sizeof(double));
    if (types & GRADY)
        data->grady = (double *)malloc(sz * sizeof(double));
    if (types & SHADE)
        data->shade = (unsigned char *)malloc(sz * sizeof(unsigned char));
}

canonical_original_code:
void gf_init_data(int types, unsigned long sz, struct gf_data *data) {
    memset((void *)data, 0, sizeof(gf_data));
    if (types & ELEVATION)
        data->elev = (float *)malloc(sz * sizeof(float));
    if (types & GRADX)
        data->gradx = (double *)malloc(sz * sizeof(double));
    if (types & GRADY)
        data->grady = (double *)malloc(sz * sizeof(double));
    if (types & SHADE)
        data->shade = (unsigned char *)malloc(sz * sizeof(unsigned char));
}

variable_types: types int

variable_types:
sz
unsigned long

variable_types: struct gf_data { float *elev; double *gradx; double *grady; unsigned char *shade; } *


original_code:
void gf_init_grid_point(gf_grid *grid, double lat, double lng, double width, double height, int nlat, int nlng) {
    grid->ny = nlat;
    grid->nx = nlng;
    grid->left = lng - 0.5 * width;
    grid->right = lng + 0.5 * width;
    grid->bottom = lat - 0.5 * height;
    grid->top = lat + 0.5 * height;
    grid->dx = (grid->right - grid->left) / ((double)(grid->nx - 1));
    grid->dy = (grid->top - grid->bottom) / ((double)(grid->ny - 1));
}

canonical_original_code:
void gf_init_grid_point(struct gf_grid *grid, double lat, double lng, double width, double height, int nlat, int nlng) {
    grid->ny = nlat;
    grid->nx = nlng;
    grid->left = lng - 0.5 * width;
    grid->right = lng + 0.5 * width;
    grid->bottom = lat - 0.5 * height;
    grid->top = lat + 0.5 * height;
    grid->dx = (grid->right - grid->left) / ((double)(grid->nx - 1));
    grid->dy = (grid->top - grid->bottom) / ((double)(grid->ny - 1));
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types: lat double

variable_types: lng double

variable_types: width double

variable_types: height double

variable_types: nlat int

variable_types: nlng int


decompiled_code:
void __fastcall gf_init_bounds_point(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v6; // xmm3_8

v5 = a4 * 0.5;
*a1 = a3 - v5;
a1[1] = v5 + a3;
v6 = a5 * 0.5;
a1[2] = a2 - v6;
a1[3] = v6 + a2;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v6; // xmm3_8

v5 = a4 * 0.5;
*a1 = a3 - v5;
a1[1] = v5 + a3;
v6 = a5 * 0.5;
a1[2] = a2 - v6;
a1[3] = v6 + a2;
}

original_code:
void gf_init_bounds_point(gf_bounds *b, double lat, double lng, double w, double h) {
    b->left = lng - 0.5 * w;
    b->right = lng + 0.5 * w;
    b->bottom = lat - 0.5 * h;
    b->top = lat + 0.5 * h;
}

canonical_original_code:
void gf_init_bounds_point(struct gf_bounds *b, double lat, double lng, double w, double h) {
    b->left = lng - 0.5 * w;
    b->right = lng + 0.5 * w;
    b->bottom = lat - 0.5 * h;
    b->top = lat + 0.5 * h;
}

variable_types: struct gf_bounds { double left; double right; double bottom; double top; } *

variable_types: w double

variable_types: h double


decompiled_code:
void __fastcall gf_init_grid_bounds(__int64 a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
gf_init_grid_point(a1, a2, a3, (a7 + a6) * 0.5, (a5 + a4) * 0.5, a5 - a4, a7 - a6);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
func1(a1, a2, a3, (a7 + a6) * 0.5, (a5 + a4) * 0.5, a5 - a4, a7 - a6);
}

original_code:
void gf_init_grid_bounds(gf_grid *grid, double left, double right, double bottom, double top, int nlat, int nlng) {
    gf_init_grid_point(grid, 0.5 * (top + bottom), 0.5 * (left + right), right - left, top - bottom, nlat, nlng);
}

canonical_original_code:
void gf_init_grid_bounds(struct gf_grid *grid, double left, double right, double bottom, double top, int nlat, int nlng) {
    gf_init_grid_point(grid, 0.5 * (top + bottom), 0.5 * (left + right), right - left, top - bottom, nlat, nlng);
}

variable_types: left double

variable_types: right double

variable_types: bottom double

variable_types: top double

user_defined_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; }


original_code:
void gf_lengths(double lat, double lng, double dlat, double dlng, double ecc, double *dx, double *dy) {
    double theta, dtheta, dphi;
    theta = 3.14159265 * lat / 180.0;
    dtheta = 3.14159265 * dlat / 180.0;
    dphi = 3.14159265 * dlng / 180.0;
    if (ecc == 0.0) {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta);
    } else {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta) / sqrt(1.0 - (ecc * sin(theta)) * (ecc * sin(theta)));
    }
}

canonical_original_code:
void gf_lengths(double lat, double lng, double dlat, double dlng, double ecc, double *dx, double *dy) {
    double theta; double dtheta; double dphi;
    theta = 3.14159265 * lat / 180.0;
    dtheta = 3.14159265 * dlat / 180.0;
    dphi = 3.14159265 * dlng / 180.0;
    if (ecc == 0.0) {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta);
    } else {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta) / sqrt(1.0 - (ecc * sin(theta)) * (ecc * sin(theta)));
    }
}

variable_types: dlat double

variable_types: dlng double

variable_types: ecc double

variable_types:
dx
double *

variable_types:
dy
double *

variable_types: theta double

variable_types: dtheta double

variable_types: dphi double


original_code:
void gf_cellsize_meters(gf_grid *grid, double *dxm, double *dym) {
    double lat, lng;
    lat = 0.5 * (grid->top + grid->bottom);
    lng = 0.5 * (grid->left + grid->right);
    gf_lengths(lat, lng, grid->dy, grid->dx, 0.0, dxm, dym);
}

canonical_original_code:
void gf_cellsize_meters(struct gf_grid *grid, double *dxm, double *dym) {
    double lat; double lng;
    lat = 0.5 * (grid->top + grid->bottom);
    lng = 0.5 * (grid->left + grid->right);
    gf_lengths(lat, lng, grid->dy, grid->dx, 0.0, dxm, dym);
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types:
dxm
double *

variable_types:
dym
double *

variable_types: lat double

variable_types: lng double


original_code:
void gf_print(const gf_grid *grid, gf_float *data, int xy) {
    long ni, nj, i, j, k;
    int c, nc = 1;
    ni = grid->ny;
    nj = grid->nx;
    if (xy) {
        ni = grid->nx;
        nj = grid->ny;
    }
    for (i = 0, k = 0; i < ni; ++i) {
        fprintf(stdout, "[");
        for (j = 0; j < nj; ++j) {
            if (nc > 1) {
                fprintf(stdout, "[");
            }
            for (c = 0; c < nc; ++c) {
                if (xy) {
                    k = c + nc * (i + ni * (nj - 1 - j));
                } else {
                    k = c + nc * (j + nj * i);
                }
                fprintf(stdout, "%.12e", data[k]);
                if (c < nc - 1) {
                    fprintf(stdout, ", ");
                }
            }
            if (nc > 1) {
                fprintf(stdout, "]");
            }
            if (j < nj - 1) {
                fprintf(stdout, ", ");
            }
        }
        fprintf(stdout, "]\n");
    }
}

canonical_original_code:
void gf_print(struct gf_grid *grid, float *data, int xy) {
    long ni; long nj; long i; long j; long k;
    int c; int nc = 1;
    ni = grid->ny;
    nj = grid->nx;
    if (xy) {
        ni = grid->nx;
        nj = grid->ny;
    }
    for (i = 0, k = 0; i < ni; ++i) {
        fprintf(stdout, "[");
        for (j = 0; j < nj; ++j) {
            if (nc > 1) {
                fprintf(stdout, "[");
            }
            for (c = 0; c < nc; ++c) {
                if (xy) {
                    k = c + nc * (i + ni * (nj - 1 - j));
                } else {
                    k = c + nc * (j + nj * i);
                }
                fprintf(stdout, "%.12e", data[k]);
                if (c < nc - 1) {
                    fprintf(stdout, ", ");
                }
            }
            if (nc > 1) {
                fprintf(stdout, "]");
            }
            if (j < nj - 1) {
                fprintf(stdout, ", ");
            }
        }
        fprintf(stdout, "]\n");
    }
}

variable_types:
data
float *

variable_types: xy int

variable_types: ni long

variable_types: nj long

variable_types: i long

variable_types: j long

variable_types: k long

variable_types: c int

variable_types: nc int


decompiled_code:
int __fastcall gf_print_grid_info(double *a1)
{
return fprintf(
stdout,
"grid info:\n"
" bounds:\n"
" left: %f\n"
" right: %f\n"
" bottom: %f\n"
" top: %f\n"
" cellsize: %fx%f degrees\n"
" resolution: %dx%d\n",
a1[3],
a1[4],
a1[5],
a1[6],
a1[1],
a1[2],
*(unsigned int *)a1,
*((unsigned int *)a1 + 1));
}

canonical_decompiled_code:
int __fastcall func13(double *a1)
{
return fprintf(
stdout,
"grid info:\n"
" bounds:\n"
" left: %f\n"
" right: %f\n"
" bottom: %f\n"
" top: %f\n"
" cellsize: %fx%f degrees\n"
" resolution: %dx%d\n",
a1[3],
a1[4],
a1[5],
a1[6],
a1[1],
a1[2],
*(unsigned int *)a1,
*((unsigned int *)a1 + 1));
}

original_code:
void gf_print_grid_info(gf_grid *grid) {
    fprintf(stdout,
        "grid info:\n"
        "  bounds:\n"
        "    left: %f\n"
        "    right: %f\n"
        "    bottom: %f\n"
        "    top: %f\n"
        "  cellsize: %fx%f degrees\n"
        "  resolution: %dx%d\n",
        grid->left,
        grid->right,
        grid->bottom,
        grid->top,
        grid->dx,
        grid->dy,
        grid->nx,
        grid->ny);
}

canonical_original_code:
void gf_print_grid_info(struct gf_grid *grid) {
    fprintf(stdout,
        "grid info:\n"
        "  bounds:\n"
        "    left: %f\n"
        "    right: %f\n"
        "    bottom: %f\n"
        "    top: %f\n"
        "  cellsize: %fx%f degrees\n"
        "  resolution: %dx%d\n",
        grid->left,
        grid->right,
        grid->bottom,
        grid->top,
        grid->dx,
        grid->dy,
        grid->nx,
        grid->ny);
}


decompiled_code:
__int64 __fastcall gf_set_null_gradient(__int64 a1)
{
**(_QWORD **)a1 = LC0;
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = LC0;
*(_QWORD *)a1 += 16LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
**(_QWORD **)a1 = LC0;
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = LC0;
*(_QWORD *)a1 += 16LL;
return 0LL;
}

original_code:
static
int gf_set_null_gradient(void **data_ptr) {
    double **grad_ptr = (double **)data_ptr;
    (*grad_ptr)[0] = -9999.0;
    (*grad_ptr)[1] = -9999.0;
    grad_ptr[0] += 2;
    return 0;
}


canonical_original_code:
int gf_biquadratic_gradient_kernel(float nine[][3], struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    double **dptr = (double **)data_ptr;
    double dx_m = -1.0; double dy_m = -1.0;
    int i; int k;
    double avg_w;
    double v[3];
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    if (w[0] < 0.0) {
        k = 0;
        avg_w = 1.0 + w[0];
    } else {
        k = 1;
        avg_w = w[0];
    }
    for (i = 0; i < 3; ++i) {
        v[i] = (1.0 - avg_w) * nine[k][i] + avg_w * nine[k + 1][i];
    }
    (*dptr)[0] = ((v[0] + v[2] - 2.0 * v[1]) * w[1] + 0.5 * (v[2] - v[0])) / dx_m;
    if (w[1] < 0.0) {
        k = 0;
        avg_w = 1.0 + w[1];
    } else {
        k = 1;
        avg_w = w[1];
    }
    for (i = 0; i < 3; ++i) {
        v[i] = (1.0 - avg_w) * nine[i][k] + avg_w * nine[i][k + 1];
    }
    (*dptr)[1] = -((v[0] + v[2] - 2.0 * v[1]) * w[0] + 0.5 * (v[2] - v[0])) / dy_m;
    dptr[0] += 2;
    return 0;
}

variable_types:
nine
float [][3]

variable_types:
w
double *

variable_types:
latlng
double *

variable_types:
xtras
void *

variable_types:
dptr
double **

variable_types: i int

variable_types: k int

variable_types:
v
double [3]


decompiled_code:
__int64 __fastcall gf_set_null_png_byte(_QWORD *a1)
{
*(_BYTE *)(*a1)++ = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
*(_BYTE *)(*a1)++ = 0;
return 0LL;
}

original_code:
static
int gf_set_null_png_byte(void **data_ptr) {
    png_byte **dptr = (png_byte **)data_ptr;
    (*dptr)[0] = 0;
    dptr[0]++;
    return 0;
}

canonical_original_code:
static int gf_set_null_png_byte(void **data_ptr) {
    unsigned char **dptr = (png_byte **)data_ptr;
    (*dptr)[0] = 0;
    dptr[0]++;
    return 0;
}

variable_types:
dptr
unsigned char **


decompiled_code:
__int64 __fastcall gf_relief_shade_kernel(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double *a5, _QWORD *a6)
{
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
__int64 result; // rax
double *v12; // [rsp+8h] [rbp-30h] BYREF
double v13; // [rsp+10h] [rbp-28h] BYREF
double v14; // [rsp+18h] [rbp-20h]

v13 = *(double *)&LC1;
v14 = *(double *)&LC1;
v12 = &v13;
gf_biquadratic_gradient_kernel(a1, a2, a3, a4, 0LL, &v12);
if ( v13 == -9999.0 || v14 == -9999.0 )
{
fwrite("gf_relief_shade_kernel: Something wrong. Please report.\n", 1uLL, 0x38uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v8 = v14 * v14 + v13 * v13 + 1.0;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
v10 = 1.0 / v9 * a5[2]
+ COERCE_DOUBLE(*(_QWORD *)&v14 ^ LC4) / v9 * a5[1]
+ COERCE_DOUBLE(*(_QWORD *)&v13 ^ LC4) / v9 * *a5
+ 0.0;
if ( v10 <= 0.0 )
v10 = 0.0;
*(_BYTE *)(*a6)++ = (int)(v10 * 255.0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double *a5, _QWORD *a6)
{
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
__int64 result; // rax
double *v12; // [rsp+8h] [rbp-30h] BYREF
double v13; // [rsp+10h] [rbp-28h] BYREF
double v14; // [rsp+18h] [rbp-20h]

v13 = *(double *)&LC1;
v14 = *(double *)&LC1;
v12 = &v13;
gf_biquadratic_gradient_kernel(a1, a2, a3, a4, 0LL, &v12);
if ( v13 == -9999.0 || v14 == -9999.0 )
{
fwrite("gf_relief_shade_kernel: Something wrong. Please report.\n", 1uLL, 0x38uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v8 = v14 * v14 + v13 * v13 + 1.0;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
v10 = 1.0 / v9 * a5[2]
+ COERCE_DOUBLE(*(_QWORD *)&v14 ^ LC4) / v9 * a5[1]
+ COERCE_DOUBLE(*(_QWORD *)&v13 ^ LC4) / v9 * *a5
+ 0.0;
if ( v10 <= 0.0 )
v10 = 0.0;
*(_BYTE *)(*a6)++ = (int)(v10 * 255.0);
result = 0LL;
}
return result;
}

original_code:
int gf_relief_shade_kernel(gf_float nine[][3], const gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    int i;
    png_byte **shade_ptr = (png_byte **)data_ptr;
    double grad[2] = {-9999.0, -9999.0}, *grad_view, n_surf[3], *n_sun, norm, shade;
    grad_view = grad;
    n_sun = (double *)xtras;
    gf_biquadratic_gradient_kernel(nine, from_grid, w, latlng, (void *)((void *)0), (void **)&grad_view);
    if (grad[0] == -9999.0 || grad[1] == -9999.0) {
        fprintf(stderr, "gf_relief_shade_kernel: Something wrong. Please report.\n");
        return -1;
    }
    norm = sqrt(1.0 + grad[0] * grad[0] + grad[1] * grad[1]);
    n_surf[0] = -grad[0] / norm;
    n_surf[1] = -grad[1] / norm;
    n_surf[2] = 1.0 / norm;
    shade = 0.0;
    for (i = 0; i < 3; ++i) {
        shade += n_sun[i] * n_surf[i];
    }
    (*shade_ptr)[0] = (int)(255.0 * (shade > 0.0 ? shade : 0.0));
    shade_ptr[0]++;
    return 0;
}

canonical_original_code:
int gf_relief_shade_kernel(float nine[][3], struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    int i;
    unsigned char **shade_ptr = (png_byte **)data_ptr;
    double grad[2] = {-9999.0, -9999.0}; double *grad_view; double n_surf[3]; double *n_sun; double norm; double shade;
    grad_view = grad;
    n_sun = (double *)xtras;
    gf_biquadratic_gradient_kernel(nine, from_grid, w, latlng, (void *)((void *)0), (void **)&grad_view);
    if (grad[0] == -9999.0 || grad[1] == -9999.0) {
        fprintf(stderr, "gf_relief_shade_kernel: Something wrong. Please report.\n");
        return -1;
    }
    norm = sqrt(1.0 + grad[0] * grad[0] + grad[1] * grad[1]);
    n_surf[0] = -grad[0] / norm;
    n_surf[1] = -grad[1] / norm;
    n_surf[2] = 1.0 / norm;
    shade = 0.0;
    for (i = 0; i < 3; ++i) {
        shade += n_sun[i] * n_surf[i];
    }
    (*shade_ptr)[0] = (int)(255.0 * (shade > 0.0 ? shade : 0.0));
    shade_ptr[0]++;
    return 0;
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types:
grad
double [2]

variable_types: norm double

variable_types: shade double