decompiled_code:
__int64 __fastcall analyze_state(__int64 *a1)
{
signed int v1; // esi
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r14
__int64 v5; // r13
__int64 v6; // r12
unsigned int v7; // ebx
__int64 v8; // rax
int *v9; // rdx
int v10; // xmm0_4
int v11; // edx
__int64 *v12; // rax
char *v13; // rdx
int v14; // xmm0_4
double v15; // xmm0_8
int v16; // ebx
__int64 v17[309]; // [rsp+0h] [rbp-9A8h] BYREF

v2 = 3LL * sensorlogpos++;
v1 = sensorlogpos;
sensorlog[v2] = *a1;
if ( v1 == 100 )
{
sensorlogpos = 0;
v1 = 0;
sensorlogready = 1;
}
else
{
result = (unsigned int)sensorlogready;
if ( !sensorlogready )
return result;
}
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
if ( (unsigned int)v1 <= 0x63 )
goto LABEL_6;
LABEL_15:
v11 = 0;
LABEL_9:
v12 = (__int64 *)((char *)sensorlog + 4 * v6);
v13 = (char *)&v17[v4 + 2] + 4 * v11;
do
{
v14 = *(_DWORD *)v12;
v12 += 3;
v13 += 4;
*((_DWORD *)v13 - 1) = v14;
}
while ( v12 != (__int64 *)((char *)&sensorlog[3 * (unsigned int)(v1 - 1) + 3] + 4 * v6) );
while ( 1 )
{
v15 = CalcBestLine(&v17[v5 + 2], 100LL, v17);
printf("line %d %f %f, %f\n", v7, *(float *)v17, *((float *)v17 + 1), *(float *)&v15);
v17[0] = 0x412000003F800000LL;
v17[1] = 0LL;
v16 = 5;
do
{
result = CalcBestSine(&v17[v5 + 2], 100LL, v17);
--v16;
}
while ( v16 );
++v6;
v4 += 50LL;
v5 += 50LL;
if ( v6 == 6 )
return result;
v1 = sensorlogpos;
v7 = v6;
if ( (unsigned int)sensorlogpos > 0x63 )
goto LABEL_15;
LABEL_6:
v8 = v1;
v9 = (int *)&sensorlog[3 * v1] + v6;
do
{
v10 = *v9;
v9 += 6;
*(_DWORD *)((char *)&v17[2] + 4 * v8++ + v5 * 8 - 4LL * v1) = v10;
}
while ( (unsigned int)v8 <= 0x63 );
v11 = 100 - v1;
if ( v1 )
goto LABEL_9;
}
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
signed int v1; // esi
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r14
__int64 v5; // r13
__int64 v6; // r12
unsigned int v7; // ebx
__int64 v8; // rax
int *v9; // rdx
int v10; // xmm0_4
int v11; // edx
__int64 *v12; // rax
char *v13; // rdx
int v14; // xmm0_4
double v15; // xmm0_8
int v16; // ebx
__int64 v17[309]; // [rsp+0h] [rbp-9A8h] BYREF

v2 = 3LL * sensorlogpos++;
v1 = sensorlogpos;
sensorlog[v2] = *a1;
if ( v1 == 100 )
{
sensorlogpos = 0;
v1 = 0;
sensorlogready = 1;
}
else
{
result = (unsigned int)sensorlogready;
if ( !sensorlogready )
return result;
}
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
if ( (unsigned int)v1 <= 0x63 )
goto LABEL_6;
LABEL_15:
v11 = 0;
LABEL_9:
v12 = (__int64 *)((char *)sensorlog + 4 * v6);
v13 = (char *)&v17[v4 + 2] + 4 * v11;
do
{
v14 = *(_DWORD *)v12;
v12 += 3;
v13 += 4;
*((_DWORD *)v13 - 1) = v14;
}
while ( v12 != (__int64 *)((char *)&sensorlog[3 * (unsigned int)(v1 - 1) + 3] + 4 * v6) );
while ( 1 )
{
v15 = CalcBestLine(&v17[v5 + 2], 100LL, v17);
printf("line %d %f %f, %f\n", v7, *(float *)v17, *((float *)v17 + 1), *(float *)&v15);
v17[0] = 0x412000003F800000LL;
v17[1] = 0LL;
v16 = 5;
do
{
result = CalcBestSine(&v17[v5 + 2], 100LL, v17);
--v16;
}
while ( v16 );
++v6;
v4 += 50LL;
v5 += 50LL;
if ( v6 == 6 )
return result;
v1 = sensorlogpos;
v7 = v6;
if ( (unsigned int)sensorlogpos > 0x63 )
goto LABEL_15;
LABEL_6:
v8 = v1;
v9 = (int *)&sensorlog[3 * v1] + v6;
do
{
v10 = *v9;
v9 += 6;
*(_DWORD *)((char *)&v17[2] + 4 * v8++ + v5 * 8 - 4LL * v1) = v10;
}
while ( (unsigned int)v8 <= 0x63 );
v11 = 100 - v1;
if ( v1 )
goto LABEL_9;
}
}

original_code:
void analyze_state(float state[6])
{
    memcpy(sensorlog[sensorlogpos++], state, sizeof state);
    if(sensorlogpos == (sizeof sensorlog) / (sizeof *sensorlog)) {
        sensorlogpos = 0;
        sensorlogready = 1;
    }
    if(sensorlogready) {
        float curlog[6][(sizeof sensorlog) / (sizeof *sensorlog)];
        int s, i, j;
        for(s=0; s<6; s++) {
            for(j = 0, i = sensorlogpos; i<(sizeof sensorlog) / (sizeof *sensorlog); i++, j++)
                curlog[s][j] = sensorlog[i][s];
            for(i = 0; i != sensorlogpos; i++, j++)
                curlog[s][j] = sensorlog[i][s];
            float X[4], r;
            r = CalcBestLine(curlog[s], (sizeof sensorlog) / (sizeof *sensorlog), X);
            printf("line %d %f %f, %f\n", s, X[0], X[1], r);
            X[0] = 1, X[1] = 10, X[2] = 0, X[3] = 0;
            int iters;
            for(iters = 0; iters < 5; iters++) {
                r = CalcBestSine(curlog[s], (sizeof sensorlog) / (sizeof *sensorlog), X);
            }
            if(r) {
            }
        }
    }
}

canonical_original_code:
void analyze_state(float state[6])
{
    memcpy(sensorlog[sensorlogpos++], state, sizeof state);
    if(sensorlogpos == (sizeof sensorlog) / (sizeof *sensorlog)) {
        sensorlogpos = 0;
        sensorlogready = 1;
    }
    if(sensorlogready) {
        float curlog[6][-1];
        int s; int i; int j;
        for(s=0; s<6; s++) {
            for(j = 0, i = sensorlogpos; i<(sizeof sensorlog) / (sizeof *sensorlog); i++, j++)
                curlog[s][j] = sensorlog[i][s];
            for(i = 0; i != sensorlogpos; i++, j++)
                curlog[s][j] = sensorlog[i][s];
            float X[4]; float r;
            r = CalcBestLine(curlog[s], (sizeof sensorlog) / (sizeof *sensorlog), X);
            printf("line %d %f %f, %f\n", s, X[0], X[1], r);
            X[0] = 1, X[1] = 10, X[2] = 0, X[3] = 0;
            int iters;
            for(iters = 0; iters < 5; iters++) {
                r = CalcBestSine(curlog[s], (sizeof sensorlog) / (sizeof *sensorlog), X);
            }
            if(r) {
            }
        }
    }
}

variable_types:
state
float [6]

variable_types:
curlog
float [6][-1]

variable_types: s int

variable_types: i int

variable_types: j int

variable_types:
X
float [4]

variable_types: r float

variable_types: iters int


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

while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
result = wgetch(stdscr);
if ( result == 61 )
goto LABEL_12;
if ( result <= 61 )
break;
if ( result == 97 )
{
engauged = engauged == 0;
}
else if ( result <= 97 )
{
if ( result == 95 )
LABEL_18:
*(float *)&desired_heading = *(float *)&desired_heading - 1.0;
}
else if ( result == 108 )
{
imu_level();
}
else if ( result == 113 )
{
exit(1);
}
}
if ( result == 45 )
goto LABEL_18;
if ( result <= 45 )
break;
if ( result == 48 )
*(float *)&desired_heading = *(float *)&desired_heading + *(float *)&dword_DA8;
}
if ( result == -1 )
return result;
if ( result == 43 )
LABEL_12:
*(float *)&desired_heading = *(float *)&desired_heading + 1.0;
}
}

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

while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
result = wgetch(stdscr);
if ( result == 61 )
goto LABEL_12;
if ( result <= 61 )
break;
if ( result == 97 )
{
engauged = engauged == 0;
}
else if ( result <= 97 )
{
if ( result == 95 )
LABEL_18:
*(float *)&desired_heading = *(float *)&desired_heading - 1.0;
}
else if ( result == 108 )
{
imu_level();
}
else if ( result == 113 )
{
exit(1);
}
}
if ( result == 45 )
goto LABEL_18;
if ( result <= 45 )
break;
if ( result == 48 )
*(float *)&desired_heading = *(float *)&desired_heading + *(float *)&dword_DA8;
}
if ( result == -1 )
return result;
if ( result == 43 )
LABEL_12:
*(float *)&desired_heading = *(float *)&desired_heading + 1.0;
}
}

original_code:
void read_input()
{
    for(;;)
        switch(wgetch(stdscr)) {
        case -1: return;
        case 'q': exit(1);
        case '+': case '=': desired_heading++; break;
        case '_': case '-': desired_heading--; break;
        case '0': desired_heading += states[YAW]; break;
        case 'a': engauged = !engauged; break;
        case 'l': imu_level(); break;
        }
}

return_type: void


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

initscr();
raw();
cbreak();
nodelay(stdscr, 0);
noecho();
result = fcntl(0, 4, 2048LL);
if ( result == -1 )
{
puts("failed to set stdin non blocking");
exit(1);
}
return result;
}

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

initscr();
raw();
cbreak();
nodelay(stdscr, 0);
noecho();
result = fcntl(0, 4, 2048LL);
if ( result == -1 )
{
puts("failed to set stdin non blocking");
exit(1);
}
return result;
}

original_code:
void setup_ncurses()
{
    initscr();
    raw();
    cbreak();
    nodelay(stdscr, 0);
    noecho();
    if(fcntl(0, 4, 04000) == -1) {
        printf("failed to set stdin non blocking\n");
        exit(1);
    }
}


decompiled_code:
int __fastcall print_valuew(float a1)
{
return printw("%c%05.2f ", 2 * (unsigned int)(a1 < 0.0) + 43, COERCE_FLOAT(LODWORD(a1) & LC6));
}

canonical_decompiled_code:
int __fastcall func6(float a1)
{
return printw("%c%05.2f ", 2 * (unsigned int)(a1 < 0.0) + 43, COERCE_FLOAT(LODWORD(a1) & LC6));
}

original_code:
void print_valuew(float v)
{
    printw("%c%05.2f ", v < 0 ? '-' : '+', fabs(v));
}

variable_types: v float


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
float v3; // er14
__int64 v4; // rbx
float v5; // xmm0_4
float v6; // xmm1_4
const char *v7; // rcx
struct timespec v8; // [rsp+0h] [rbp-48h] BYREF
int v9[2]; // [rsp+10h] [rbp-38h] BYREF
float v10; // [rsp+18h] [rbp-30h]
char v11[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

imu_init(argc, argv, envp);
servo = servo_open("/dev/ttyUSB0");
atexit(cleanup);
servo_set_mode(servo, 0LL, "POSITION");
setup_ncurses();
printw(
"Autopilot ncurses Control Interface\n"
"Keys include:\n"
"\t+/- - set desired heading\n"
"\t0 - desired heading to current heading\n"
"\ta - engauged/disengauge autopilot\n"
"\tl - level imu\n");
while ( 1 )
{
v4 = 0LL;
imu_orientation(v9);
imu_rate(v11);
do
{
if ( v4 == 2 )
{
v3 = COERCE_FLOAT(_mm_cvtsi128_si32((__m128i)LODWORD(v10)));
dword_DA8 = heading_resolve(v10 - *(float *)&desired_heading);
v5 = v10;
}
else
{
v5 = *(float *)&v9[v4];
*(float *)&states[v4] = v5;
}
v6 = (float)(v5 / 10.0) + dword_DB8[v4];
if ( v6 > 1.0 )
dword_DB8[v4] = 1.0;
else
dword_DB8[v4] = fmaxf(-1.0, v6);
dword_DD0[v4] = (float)(v5 - *(float *)&states[v4]) * 10.0;
++v4;
}
while ( v4 != 6 );
heel = lp_filter_constprop_0(*(float *)&heel, *(float *)&dword_DA4);
command = pid_command();
if ( (int)imu_runtime() > 5 && engauged )
servo_command(servo, 0LL, *(float *)&command);
read_input();
mvprintw(6, 0, "heading: ");
print_valuew(v3);
mvprintw(6, 40, "rate: ");
print_valuew(*(float *)&dword_DB4);
mvprintw(7, 0, "desired heading: ");
print_valuew(*(float *)&desired_heading);
mvprintw(7, 40, "heading error: ");
print_valuew(*(float *)&dword_DA8);
v7 = (const char *)servo_read_status(servo);
if ( v7 )
mvprintw(8, 0, "Status: %s ", v7);
v8.tv_sec = 0LL;
v8.tv_nsec = 100000000LL;
nanosleep(&v8, 0LL);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
float v3; // er14
__int64 v4; // rbx
float v5; // xmm0_4
float v6; // xmm1_4
const char *v7; // rcx
struct timespec v8; // [rsp+0h] [rbp-48h] BYREF
int v9[2]; // [rsp+10h] [rbp-38h] BYREF
float v10; // [rsp+18h] [rbp-30h]
char v11[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

imu_init(argc, argv, envp);
servo = servo_open("/dev/ttyUSB0");
atexit(cleanup);
servo_set_mode(servo, 0LL, "POSITION");
func5();
printw(
"Autopilot ncurses Control Interface\n"
"Keys include:\n"
"\t+/- - set desired heading\n"
"\t0 - desired heading to current heading\n"
"\ta - engauged/disengauge autopilot\n"
"\tl - level imu\n");
while ( 1 )
{
v4 = 0LL;
imu_orientation(v9);
imu_rate(v11);
do
{
if ( v4 == 2 )
{
v3 = COERCE_FLOAT(_mm_cvtsi128_si32((__m128i)LODWORD(v10)));
dword_DA8 = heading_resolve(v10 - *(float *)&desired_heading);
v5 = v10;
}
else
{
v5 = *(float *)&v9[v4];
*(float *)&states[v4] = v5;
}
v6 = (float)(v5 / 10.0) + dword_DB8[v4];
if ( v6 > 1.0 )
dword_DB8[v4] = 1.0;
else
dword_DB8[v4] = fmaxf(-1.0, v6);
dword_DD0[v4] = (float)(v5 - *(float *)&states[v4]) * 10.0;
++v4;
}
while ( v4 != 6 );
heel = func1(*(float *)&heel, *(float *)&dword_DA4);
command = pid_command();
if ( (int)imu_runtime() > 5 && engauged )
servo_command(servo, 0LL, *(float *)&command);
func4();
mvprintw(6, 0, "heading: ");
func6(v3);
mvprintw(6, 40, "rate: ");
func6(*(float *)&dword_DB4);
mvprintw(7, 0, "desired heading: ");
func6(*(float *)&desired_heading);
mvprintw(7, 40, "heading error: ");
func6(*(float *)&dword_DA8);
v7 = (const char *)servo_read_status(servo);
if ( v7 )
mvprintw(8, 0, "Status: %s ", v7);
v8.tv_sec = 0LL;
v8.tv_nsec = 100000000LL;
nanosleep(&v8, 0LL);
}
}

original_code:
int main()
{
    imu_init();
    servo = servo_open("/dev/ttyUSB0");
    atexit(cleanup);
    servo_set_mode(servo, 0, "POSITION");
    setup_ncurses();
    printw("Autopilot ncurses Control Interface\n"
           "Keys include:\n"
           "\t+/- - set desired heading\n"
           "\t0 - desired heading to current heading\n"
           "\ta - engauged/disengauge autopilot\n"
           "\tl - level imu\n");
    for(;;) {
        float X[6];
        imu_orientation(X);
        imu_rate(X+3);
        const float hz = 10;
        int i;
        float heading;
        for(i=0; i<6; i++) {
            if(i == YAW) {
                heading = X[YAW];
                states[i] = heading_resolve(heading - desired_heading);
            } else
                states[i] = X[i];
            states[i+INTEGRAL] += X[i] / hz;
            if(states[i+INTEGRAL] > 1) states[i+INTEGRAL] = 1;
            if(states[i+INTEGRAL] < -1) states[i+INTEGRAL] = -1;
            states[i+DERIVATIVE] = (X[i] - states[i])*hz;
        }
        enum {PORT, STARBOARD, };
        heel = lp_filter(heel, states[ROLL], .99);
        command = pid_command();
        int n = imu_runtime();
        if(n > 5 && engauged)
            servo_command(servo, 0, command);
        read_input();
        mvprintw(6, 0, "heading:        ");
        print_valuew(heading);
        mvprintw(6, 40, "rate:         ");
        print_valuew(states[YAW_RATE]);
        mvprintw(7, 0, "desired heading:          ");
        print_valuew(desired_heading);
        mvprintw(7, 40, "heading error:        ");
        print_valuew(states[YAW]);
        const char *status = servo_read_status(servo);
        if(status)
            mvprintw(8, 0, "Status: %s   ", status);
        struct timespec ts = {0, 1e8};
        nanosleep(&ts, ((void *)0));
    }
}

canonical_original_code:
int main()
{
    imu_init();
    servo = servo_open("/dev/ttyUSB0");
    atexit(cleanup);
    servo_set_mode(servo, 0, "POSITION");
    setup_ncurses();
    printw("Autopilot ncurses Control Interface\n"
           "Keys include:\n"
           "\t+/- - set desired heading\n"
           "\t0 - desired heading to current heading\n"
           "\ta - engauged/disengauge autopilot\n"
           "\tl - level imu\n");
    for(;;) {
        float X[6];
        imu_orientation(X);
        imu_rate(X+3);
        float hz = 10;
        int i;
        float heading;
        for(i=0; i<6; i++) {
            if(i == YAW) {
                heading = X[YAW];
                states[i] = heading_resolve(heading - desired_heading);
            } else
                states[i] = X[i];
            states[i+INTEGRAL] += X[i] / hz;
            if(states[i+INTEGRAL] > 1) states[i+INTEGRAL] = 1;
            if(states[i+INTEGRAL] < -1) states[i+INTEGRAL] = -1;
            states[i+DERIVATIVE] = (X[i] - states[i])*hz;
        }
        enum {PORT, STARBOARD, };
        heel = lp_filter(heel, states[ROLL], .99);
        command = pid_command();
        int n = imu_runtime();
        if(n > 5 && engauged)
            servo_command(servo, 0, command);
        read_input();
        mvprintw(6, 0, "heading:        ");
        print_valuew(heading);
        mvprintw(6, 40, "rate:         ");
        print_valuew(states[YAW_RATE]);
        mvprintw(7, 0, "desired heading:          ");
        print_valuew(desired_heading);
        mvprintw(7, 40, "heading error:        ");
        print_valuew(states[YAW]);
        char *status = servo_read_status(servo);
        if(status)
            mvprintw(8, 0, "Status: %s   ", status);
        struct timespec ts = {0, 1e8};
        nanosleep(&ts, ((void *)0));
    }
}

variable_types:
X
float [6]

variable_types: hz float

variable_types: heading float

variable_types: n int

variable_types:
status
char *

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

return_type: int


original_code:
void angvec2quat(float q[4], float angle, float v[3])
{
   float n = magnitude(v);
   float fac;
   if(n == 0)
      fac = 0;
   else
      fac = sin(angle/2) / n;
   q[0] = cos(angle/2);
   q[1] = v[0]*fac;
   q[2] = v[1]*fac;
   q[3] = v[2]*fac;
}

variable_types:
q
float [4]

variable_types: angle float

variable_types:
v
float [3]

variable_types: n float

variable_types: fac float


rotvecquat

variable_types:
w
float [4]

variable_types:
r
float [4]


decompiled_code:
void __fastcall vec2vec2quat(float *a1, __int64 a2, __int64 a3)
{
double v4; // rbx
double v5; // xmm0_8
double v6; // xmm0_8
float v7; // xmm0_4
double v8; // xmm1_8
float v9; // xmm0_4
float v10; // [rsp+Ch] [rbp-3Ch]
float v11[13]; // [rsp+14h] [rbp-34h] BYREF

cross(v11);
v4 = dot(a2, a3);
v10 = magnitude2(a2);
v5 = (float)(magnitude2(a3) * v10);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = v4 / v6;
v8 = LC3;
if ( v7 <= 1.0 && v7 >= -1.0 )
v8 = v7;
v9 = acos(v8);
angvec2quat(a1, v11, v9);
}

canonical_decompiled_code:
void __fastcall func4(float *a1, __int64 a2, __int64 a3)
{
double v4; // rbx
double v5; // xmm0_8
double v6; // xmm0_8
float v7; // xmm0_4
double v8; // xmm1_8
float v9; // xmm0_4
float v10; // [rsp+Ch] [rbp-3Ch]
float v11[13]; // [rsp+14h] [rbp-34h] BYREF

cross(v11);
v4 = dot(a2, a3);
v10 = magnitude2(a2);
v5 = (float)(magnitude2(a3) * v10);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = v4 / v6;
v8 = LC3;
if ( v7 <= 1.0 && v7 >= -1.0 )
v8 = v7;
v9 = acos(v8);
func2(a1, v11, v9);
}

original_code:
void vec2vec2quat(float x[4], float a[3], float b[3])
{
   float n[3];
   cross(n, a, b);
   float fac = dot(a, b) / sqrt(magnitude2(a) * magnitude2(b));
   if(fac > 1)
      fac = 1;
   if(fac < -1)
       fac = 1;
   float ang = acos(fac);
   angvec2quat(x, ang, n);
}

variable_types:
x
float [4]

variable_types:
a
float [3]

variable_types:
b
float [3]

variable_types:
n
float [3]

variable_types: ang float


quatmagnitude

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

v1 = (float)((float)((float)(a1[1] * a1[1]) + (float)(*a1 * *a1)) + (float)(a1[2] * a1[2])) + (float)(a1[3] * a1[3]);
if ( v1 < 0.0 )
sqrtf(v1);
}

original_code:
float quatmagnitude(float q[4])
{
    return sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
}

return_type: float


quatnormalize

decompiled_code:
void __fastcall quatnormalize(float *a1, float a2)
{
quatmagnitude(a1);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
a1[3] = a1[3] / a2;
}

original_code:
void quatnormalize(float q[4])
{
    float m = quatmagnitude(q);
    q[0] /= m;
    q[1] /= m;
    q[2] /= m;
    q[3] /= m;
}

variable_types: m float


quatangle

decompiled_code:
float __fastcall quatangle(float *a1)
{
double v1; // xmm0_8

v1 = acos(*a1);
return v1 + v1;
}

canonical_decompiled_code:
float __fastcall func7(float *a1)
{
double v1; // xmm0_8

v1 = acos(*a1);
return v1 + v1;
}

original_code:
float quatangle(float q[4])
{
  return 2*acos(q[0]);
}


subquatangle

decompiled_code:
float __fastcall subquatangle(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8

v1 = magnitude(a1);
v2 = asin(*(float *)&v1);
return v2 + v2;
}

canonical_decompiled_code:
float __fastcall func8(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8

v1 = magnitude(a1);
v2 = asin(*(float *)&v1);
return v2 + v2;
}

original_code:
float subquatangle(float v[3])
{
  return 2*asin(magnitude(v));
}


variable_types:
pitch
float *

variable_types:
roll
float *

variable_types:
yaw
float *


original_code: void vector_add(float x[], const float a[], const float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] + b[i]; }

canonical_original_code: void vector_add(float x[], float a[], float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] + b[i]; }

variable_types:
x
float []

variable_types:
a
float []

variable_types:
b
float []

variable_types: n int

variable_types: i int


original_code: void vector_sub(float x[], const float a[], const float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] - b[i]; }

canonical_original_code: void vector_sub(float x[], float a[], float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] - b[i]; }


original_code: void vector_mul(float x[], const float a[], const float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] * b[i]; }

canonical_original_code: void vector_mul(float x[], float a[], float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] * b[i]; }


original_code: void vector_div(float x[], const float a[], const float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] / b[i]; }

canonical_original_code: void vector_div(float x[], float a[], float b[], int n) { int i; for(i = 0; i<n; i++) x[i] = a[i] / b[i]; }


decompiled_code:
void __fastcall vector_length(float *a1, int a2)
{
double v2; // xmm0_8

v2 = vector_length2(a1, a2);
if ( *(float *)&v2 < 0.0 )
sqrtf(*(float *)&v2);
}

canonical_decompiled_code:
void __fastcall func5(float *a1, int a2)
{
double v2; // xmm0_8

v2 = func4(a1, a2);
if ( *(float *)&v2 < 0.0 )
sqrtf(*(float *)&v2);
}

original_code:
float vector_length(const float vec[], int n)
{
   return sqrt(vector_length2(vec, n));
}

canonical_original_code:
float vector_length(float vec[], int n)
{
   return sqrt(vector_length2(vec, n));
}

variable_types:
vec
float []


magnitude

decompiled_code:
void __fastcall magnitude(float *a1)
{
double v1; // xmm0_8

v1 = magnitude2(a1);
if ( *(float *)&v1 < 0.0 )
sqrtf(*(float *)&v1);
}

canonical_decompiled_code:
void __fastcall func7(float *a1)
{
double v1; // xmm0_8

v1 = func6(a1);
if ( *(float *)&v1 < 0.0 )
sqrtf(*(float *)&v1);
}

original_code:
float magnitude(const float vec[3])
{
   return sqrt(magnitude2(vec));
}

canonical_original_code:
float magnitude(float vec[3])
{
   return sqrt(magnitude2(vec));
}

variable_types:
vec
float [3]


normalize

decompiled_code:
void __fastcall normalize(float *a1, float a2)
{
magnitude(a1);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

original_code:
void normalize(float vec[3])
{
   float mag = magnitude(vec);
   vec[0] /= mag, vec[1] /= mag, vec[2] /= mag;
}

variable_types: mag float


dot

decompiled_code:
float __fastcall dot(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

canonical_decompiled_code:
float __fastcall func10(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

original_code:
float dot(const float a[3], const float b[3])
{
   return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
}


original_code:
float dist2(const float a[3], const float b[3])
{
   float x = a[0] - b[0];
   float y = a[1] - b[1];
   float z = a[2] - b[2];
   return x*x + y*y + z*z;
}

canonical_original_code:
float dist2(float a[3], float b[3])
{
   float x = a[0] - b[0];
   float y = a[1] - b[1];
   float z = a[2] - b[2];
   return x*x + y*y + z*z;
}

variable_types: x float

variable_types: y float

variable_types: z float


dist

decompiled_code:
void __fastcall dist(float *a1, float *a2)
{
float v2; // xmm0_4

v2 = dist2(a1, a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

canonical_decompiled_code:
void __fastcall func12(float *a1, float *a2)
{
float v2; // xmm0_4

v2 = func11(a1, a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

original_code:
float dist(const float a[3], const float b[3])
{
   return sqrt(dist2(a, b));
}

canonical_original_code:
float dist(float a[3], float b[3])
{
   return sqrt(dist2(a, b));
}

variable_types:
a
float [3]

variable_types:
b
float [3]


decompiled_code:
void __fastcall vector_scale(float *a1, int a2, float a3)
{
__int64 v4; // rax
float v5; // xmm0_4

if ( a2 > 0 )
{
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = *a1++;
*(a1 - 1) = v5 * a3;
}
while ( a1 != (float *)v4 );
}
}

original_code:
void vector_scale(float mag, float x[], int n)
{
   int i;
   for(i = 0; i<n; i++)
      x[i] *= mag;
}


decompiled_code:
void __fastcall vector_from_polar(__int64 a1, float a2, float a3, float a4)
{
float v4; // xmm0_4
float v5; // xmm0_4
double v6; // xmm1_8
float v7; // xmm0_4
float v8; // xmm0_4
double v9; // [rsp+0h] [rbp-38h]
double v10; // [rsp+8h] [rbp-30h]
double v11; // [rsp+10h] [rbp-28h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

v9 = a2;
v4 = (float)(a3 / 180.0) * 3.141592653589793;
sincos(v4, sinx, &cosx);
v10 = sinx[0];
v11 = v9 * cosx;
v5 = (float)(a4 / 180.0) * 3.141592653589793;
sincos(v5, sinx, &cosx);
v6 = v11 * sinx[0];
v7 = cosx * v11;
*(float *)a1 = v7;
*(float *)&v6 = v6;
*(_DWORD *)(a1 + 4) = LODWORD(v6);
v8 = v10 * v9;
*(float *)(a1 + 8) = v8;
}

original_code:
void vector_from_polar(float x[3], float radius, float incline, float azimuth)
{
   float ri = ((incline)/180*3.14159265358979323846), ra = ((azimuth)/180*3.14159265358979323846);
   x[0] = radius*cos(ri)*cos(ra);
   x[1] = radius*cos(ri)*sin(ra);
   x[2] = radius*sin(ri);
}

canonical_original_code:
void vector_from_polar(float x[3], float radius, float incline, float azimuth)
{
   float ri = ((incline)/180*3.14159265358979323846); float ra = ((azimuth)/180*3.14159265358979323846);
   x[0] = radius*cos(ri)*cos(ra);
   x[1] = radius*cos(ri)*sin(ra);
   x[2] = radius*sin(ri);
}

variable_types:
x
float [3]

variable_types: radius float

variable_types: incline float

variable_types: azimuth float

variable_types: ri float

variable_types: ra float


MahonyAHRSupdateIMU

decompiled_code:
void __fastcall MahonyAHRSupdateIMU(float a1, float a2, float a3, float a4, float a5, float a6)
{
char v7; // cl
float v8; // xmm7_4
float v9; // xmm1_4
float v10; // xmm2_4
float v11; // xmm4_4
float v12; // xmm3_4
float v13; // xmm4_4
float v14; // xmm1_4
float v15; // xmm9_4
float v16; // xmm2_4
float v17; // xmm0_4
float v18; // xmm0_4
float v19; // xmm5_4
float v20; // xmm9_4
float v21; // xmm8_4
float v22; // xmm4_4
float v23; // xmm0_4
float v24; // xmm3_4
float v25; // xmm10_4
float v26; // xmm5_4
float v27; // xmm3_4

v7 = 1;
if ( a6 != 0.0 || a5 != 0.0 )
goto LABEL_6;
if ( a4 == 0.0 )
v7 = 0;
if ( v7 )
{
LABEL_6:
v18 = invSqrt((float)((float)(a4 * a4) + (float)(a5 * a5)) + (float)(a6 * a6));
v19 = a6 * v18;
v20 = a4 * v18;
v21 = a5 * v18;
v22 = (float)(q1 * q3) - (float)(q0 * q2);
v23 = (float)(q0 * q1) + (float)(q2 * q3);
v24 = (float)((float)(q0 * q0) - 0.5) + (float)(q3 * q3);
v25 = (float)(v21 * v24) - (float)(v19 * v23);
v26 = (float)(v19 * v22) - (float)(v24 * v20);
v27 = (float)(v20 * v23) - (float)(v22 * v21);
if ( *(float *)&twoKi <= 0.0 )
{
integralFBx = 0;
integralFBy = 0;
integralFBz = 0;
}
else
{
*(float *)&integralFBx = (float)((float)(*(float *)&twoKi * v25) * 0.1) + *(float *)&integralFBx;
*(float *)&integralFBy = (float)((float)(*(float *)&twoKi * v26) * 0.1) + *(float *)&integralFBy;
*(float *)&integralFBz = (float)((float)(*(float *)&twoKi * v27) * 0.1) + *(float *)&integralFBz;
a1 = a1 + *(float *)&integralFBx;
a2 = a2 + *(float *)&integralFBy;
a3 = a3 + *(float *)&integralFBz;
}
a1 = a1 + (float)(v25 * *(float *)&twoKp);
a2 = a2 + (float)(v26 * *(float *)&twoKp);
a3 = a3 + (float)(v27 * *(float *)&twoKp);
}
v8 = q0;
v9 = a2 * 0.050000001;
v10 = a3 * 0.050000001;
v11 = (float)(a1 * 0.050000001) * q0;
q0 = (float)((float)((float)(COERCE_FLOAT(q1 ^ LC4) * (float)(a1 * 0.050000001)) - (float)(v9 * q2))
- (float)(q3 * v10))
+ q0;
v12 = (float)((float)(v10 * q2) + v11) - (float)(q3 * v9);
v13 = v9 * v8;
v14 = v9 * q1;
v15 = v10 * q1;
q1 = v12 + q1;
v16 = (float)((float)(v10 * v8) + v14) - (float)((float)(a1 * 0.050000001) * q2);
q2 = (float)((float)(q3 * (float)(a1 * 0.050000001)) + (float)(v13 - v15)) + q2;
q3 = v16 + q3;
v17 = invSqrt((float)((float)((float)(q0 * q0) + (float)(q1 * q1)) + (float)(q2 * q2)) + (float)(q3 * q3));
q0 = q0 * v17;
q1 = q1 * v17;
q2 = q2 * v17;
q3 = v17 * q3;
}

canonical_decompiled_code:
void __fastcall func0(float a1, float a2, float a3, float a4, float a5, float a6)
{
char v7; // cl
float v8; // xmm7_4
float v9; // xmm1_4
float v10; // xmm2_4
float v11; // xmm4_4
float v12; // xmm3_4
float v13; // xmm4_4
float v14; // xmm1_4
float v15; // xmm9_4
float v16; // xmm2_4
float v17; // xmm0_4
float v18; // xmm0_4
float v19; // xmm5_4
float v20; // xmm9_4
float v21; // xmm8_4
float v22; // xmm4_4
float v23; // xmm0_4
float v24; // xmm3_4
float v25; // xmm10_4
float v26; // xmm5_4
float v27; // xmm3_4

v7 = 1;
if ( a6 != 0.0 || a5 != 0.0 )
goto LABEL_6;
if ( a4 == 0.0 )
v7 = 0;
if ( v7 )
{
LABEL_6:
v18 = invSqrt((float)((float)(a4 * a4) + (float)(a5 * a5)) + (float)(a6 * a6));
v19 = a6 * v18;
v20 = a4 * v18;
v21 = a5 * v18;
v22 = (float)(q1 * q3) - (float)(q0 * q2);
v23 = (float)(q0 * q1) + (float)(q2 * q3);
v24 = (float)((float)(q0 * q0) - 0.5) + (float)(q3 * q3);
v25 = (float)(v21 * v24) - (float)(v19 * v23);
v26 = (float)(v19 * v22) - (float)(v24 * v20);
v27 = (float)(v20 * v23) - (float)(v22 * v21);
if ( *(float *)&twoKi <= 0.0 )
{
integralFBx = 0;
integralFBy = 0;
integralFBz = 0;
}
else
{
*(float *)&integralFBx = (float)((float)(*(float *)&twoKi * v25) * 0.1) + *(float *)&integralFBx;
*(float *)&integralFBy = (float)((float)(*(float *)&twoKi * v26) * 0.1) + *(float *)&integralFBy;
*(float *)&integralFBz = (float)((float)(*(float *)&twoKi * v27) * 0.1) + *(float *)&integralFBz;
a1 = a1 + *(float *)&integralFBx;
a2 = a2 + *(float *)&integralFBy;
a3 = a3 + *(float *)&integralFBz;
}
a1 = a1 + (float)(v25 * *(float *)&twoKp);
a2 = a2 + (float)(v26 * *(float *)&twoKp);
a3 = a3 + (float)(v27 * *(float *)&twoKp);
}
v8 = q0;
v9 = a2 * 0.050000001;
v10 = a3 * 0.050000001;
v11 = (float)(a1 * 0.050000001) * q0;
q0 = (float)((float)((float)(COERCE_FLOAT(q1 ^ LC4) * (float)(a1 * 0.050000001)) - (float)(v9 * q2))
- (float)(q3 * v10))
+ q0;
v12 = (float)((float)(v10 * q2) + v11) - (float)(q3 * v9);
v13 = v9 * v8;
v14 = v9 * q1;
v15 = v10 * q1;
q1 = v12 + q1;
v16 = (float)((float)(v10 * v8) + v14) - (float)((float)(a1 * 0.050000001) * q2);
q2 = (float)((float)(q3 * (float)(a1 * 0.050000001)) + (float)(v13 - v15)) + q2;
q3 = v16 + q3;
v17 = invSqrt((float)((float)((float)(q0 * q0) + (float)(q1 * q1)) + (float)(q2 * q2)) + (float)(q3 * q3));
q0 = q0 * v17;
q1 = q1 * v17;
q2 = q2 * v17;
q3 = v17 * q3;
}

original_code:
void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az) {
 float recipNorm;
 float halfvx, halfvy, halfvz;
 float halfex, halfey, halfez;
 float qa, qb, qc;
 if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
  recipNorm = invSqrt(ax * ax + ay * ay + az * az);
  ax *= recipNorm;
  ay *= recipNorm;
  az *= recipNorm;
  halfvx = q1 * q3 - q0 * q2;
  halfvy = q0 * q1 + q2 * q3;
  halfvz = q0 * q0 - 0.5f + q3 * q3;
  halfex = (ay * halfvz - az * halfvy);
  halfey = (az * halfvx - ax * halfvz);
  halfez = (ax * halfvy - ay * halfvx);
  if(twoKi > 0.0f) {
   integralFBx += twoKi * halfex * (1.0f / 10.0f);
   integralFBy += twoKi * halfey * (1.0f / 10.0f);
   integralFBz += twoKi * halfez * (1.0f / 10.0f);
   gx += integralFBx;
   gy += integralFBy;
   gz += integralFBz;
  }
  else {
   integralFBx = 0.0f;
   integralFBy = 0.0f;
   integralFBz = 0.0f;
  }
  gx += twoKp * halfex;
  gy += twoKp * halfey;
  gz += twoKp * halfez;
 }
 gx *= (0.5f * (1.0f / 10.0f));
 gy *= (0.5f * (1.0f / 10.0f));
 gz *= (0.5f * (1.0f / 10.0f));
 qa = q0;
 qb = q1;
 qc = q2;
 q0 += (-qb * gx - qc * gy - q3 * gz);
 q1 += (qa * gx + qc * gz - q3 * gy);
 q2 += (qa * gy - qb * gz + q3 * gx);
 q3 += (qa * gz + qb * gy - qc * gx);
 recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
 q0 *= recipNorm;
 q1 *= recipNorm;
 q2 *= recipNorm;
 q3 *= recipNorm;
}

canonical_original_code:
void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az) {
 float recipNorm;
 float halfvx; float halfvy; float halfvz;
 float halfex; float halfey; float halfez;
 float qa; float qb; float qc;
 if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
  recipNorm = invSqrt(ax * ax + ay * ay + az * az);
  ax *= recipNorm;
  ay *= recipNorm;
  az *= recipNorm;
  halfvx = q1 * q3 - q0 * q2;
  halfvy = q0 * q1 + q2 * q3;
  halfvz = q0 * q0 - 0.5f + q3 * q3;
  halfex = (ay * halfvz - az * halfvy);
  halfey = (az * halfvx - ax * halfvz);
  halfez = (ax * halfvy - ay * halfvx);
  if(twoKi > 0.0f) {
   integralFBx += twoKi * halfex * (1.0f / 10.0f);
   integralFBy += twoKi * halfey * (1.0f / 10.0f);
   integralFBz += twoKi * halfez * (1.0f / 10.0f);
   gx += integralFBx;
   gy += integralFBy;
   gz += integralFBz;
  }
  else {
   integralFBx = 0.0f;
   integralFBy = 0.0f;
   integralFBz = 0.0f;
  }
  gx += twoKp * halfex;
  gy += twoKp * halfey;
  gz += twoKp * halfez;
 }
 gx *= (0.5f * (1.0f / 10.0f));
 gy *= (0.5f * (1.0f / 10.0f));
 gz *= (0.5f * (1.0f / 10.0f));
 qa = q0;
 qb = q1;
 qc = q2;
 q0 += (-qb * gx - qc * gy - q3 * gz);
 q1 += (qa * gx + qc * gz - q3 * gy);
 q2 += (qa * gy - qb * gz + q3 * gx);
 q3 += (qa * gz + qb * gy - qc * gx);
 recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
 q0 *= recipNorm;
 q1 *= recipNorm;
 q2 *= recipNorm;
 q3 *= recipNorm;
}

variable_types: gx float

variable_types: gy float

variable_types: gz float

variable_types: ax float

variable_types: ay float

variable_types: az float

variable_types: recipNorm float

variable_types: halfvx float

variable_types: halfvy float

variable_types: halfvz float

variable_types: halfex float

variable_types: halfey float

variable_types: halfez float

variable_types: qa float

variable_types: qb float

variable_types: qc float


MahonyAHRSupdate

decompiled_code:
void __fastcall MahonyAHRSupdate(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9)
{
char v15; // cl
float v16; // xmm8_4
char v17; // cl
float v18; // xmm6_4
float v19; // xmm1_4
float v20; // xmm8_4
float v21; // xmm2_4
float v22; // xmm4_4
float v23; // xmm7_4
float v24; // xmm3_4
float v25; // xmm4_4
float v26; // xmm1_4
float v27; // xmm9_4
float v28; // xmm3_4
float v29; // xmm8_4
float v30; // xmm0_4
float v31; // xmm0_4
float v32; // xmm0_4
float v33; // xmm6_4
float v34; // xmm7_4
float v35; // xmm3_4
__m128i v36; // xmm10
float v37; // ebx
float v38; // xmm10_4
float v39; // xmm5_4
float v40; // xmm13_4
float v41; // xmm4_4
float v42; // xmm0_4
float v43; // xmm11_4
float v44; // xmm0_4
float v45; // xmm0_4
float v46; // xmm5_4
float v47; // xmm4_4
float v48; // xmm13_4
float v49; // xmm10_4
float v50; // xmm11_4
float v51; // xmm11_4
float v52; // xmm12_4
float v53; // xmm13_4
float v54; // xmm14_4
float v55; // xmm0_4
float v56; // xmm13_4
float v57; // xmm11_4
float v58; // xmm6_4
float v59; // xmm10_4
float v61; // [rsp+0h] [rbp-54h]
float v63; // [rsp+4h] [rbp-50h]
float v64; // [rsp+8h] [rbp-4Ch]
float v65; // [rsp+Ch] [rbp-48h]
float v66; // [rsp+10h] [rbp-44h]
float v67; // [rsp+14h] [rbp-40h]
float v68; // [rsp+18h] [rbp-3Ch]
float v69; // [rsp+1Ch] [rbp-38h]
float v70; // [rsp+20h] [rbp-34h]
float v71; // [rsp+24h] [rbp-30h]
float v72; // [rsp+38h] [rbp-1Ch]
float v73; // [rsp+3Ch] [rbp-18h]

v15 = 0;
v16 = a1;
if ( a9 != 0.0 || a8 != 0.0 )
goto LABEL_5;
if ( a7 == 0.0 )
v15 = 1;
if ( v15 )
{
MahonyAHRSupdateIMU(a1, a2, a3, a4, a5, a6);
}
else
{
LABEL_5:
v17 = 1;
if ( a6 != 0.0 || a5 != 0.0 )
goto LABEL_10;
if ( a4 == 0.0 )
v17 = 0;
if ( v17 )
{
LABEL_10:
v31 = invSqrt((float)((float)(a4 * a4) + (float)(a5 * a5)) + (float)(a6 * a6));
v67 = a4 * v31;
v61 = a5 * v31;
v63 = a6 * v31;
v32 = invSqrt((float)((float)(a7 * a7) + (float)(a8 * a8)) + (float)(a9 * a9));
v33 = a7 * v32;
v34 = a8 * v32;
v35 = v32 * a9;
v36 = (__m128i)q0;
*(float *)v36.m128i_i32 = q0 * q0;
v37 = COERCE_FLOAT(_mm_cvtsi128_si32(v36));
v68 = q0 * q1;
v38 = q0 * q2;
v39 = q1 * q3;
v40 = 0.5 - (float)(q1 * q1);
v41 = q2 * q3;
v69 = q2 * q2;
v66 = (float)(q0 * q2) + (float)(q1 * q3);
v65 = (float)(q1 * q2) - (float)(q0 * q3);
v70 = q3 * q3;
v64 = (float)(0.5 - (float)(q2 * q2)) - (float)(q3 * q3);
v42 = (float)((float)(v65 * v34) + (float)(v64 * v33)) + (float)(v66 * (float)(v32 * a9));
v43 = (float)((float)((float)(q1 * q2) + (float)(q0 * q3)) * v33) + (float)((float)(v40 - (float)(q3 * q3)) * v34);
v44 = (float)((float)(v42 + v42) * (float)(v42 + v42))
+ (float)((float)((float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))
+ (float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35)))
* (float)((float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))
+ (float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))));
if ( v44 < 0.0 )
{
v73 = q2 * q3;
v72 = q1 * q3;
v71 = 0.5 - (float)(q1 * q1);
v45 = sqrtf(v44);
v41 = v73;
v39 = v72;
v40 = v71;
}
else
{
v45 = fsqrt(v44);
}
v46 = v39 - v38;
v47 = v41 + v68;
v48 = v40 - v69;
v49 = (float)(v37 - 0.5) + v70;
v50 = (float)((float)(v47 * v34) + (float)(v46 * v33)) + (float)(v48 * v35);
v51 = v50 + v50;
v52 = (float)(v64 * v45) + (float)(v46 * v51);
v53 = (float)(v48 * v51) + (float)(v45 * v66);
v54 = (float)(v47 * v51) + (float)(v65 * v45);
v55 = v34 * v53;
v56 = v53 * v33;
v57 = (float)((float)(v61 * v49) - (float)(v63 * v47)) + (float)(v55 - (float)(v35 * v54));
v58 = (float)((float)(v33 * v54) - (float)(v34 * v52)) + (float)((float)(v47 * v67) - (float)(v46 * v61));
v59 = (float)((float)(v35 * v52) - v56) + (float)((float)(v63 * v46) - (float)(v49 * v67));
if ( *(float *)&twoKi <= 0.0 )
{
integralFBx = 0;
integralFBy = 0;
integralFBz = 0;
}
else
{
*(float *)&integralFBx = (float)((float)(*(float *)&twoKi * v57) * 0.1) + *(float *)&integralFBx;
*(float *)&integralFBy = (float)((float)(*(float *)&twoKi * v59) * 0.1) + *(float *)&integralFBy;
*(float *)&integralFBz = (float)((float)(*(float *)&twoKi * v58) * 0.1) + *(float *)&integralFBz;
v16 = v16 + *(float *)&integralFBx;
a2 = a2 + *(float *)&integralFBy;
a3 = a3 + *(float *)&integralFBz;
}
v16 = v16 + (float)(v57 * *(float *)&twoKp);
a2 = a2 + (float)(*(float *)&twoKp * v59);
a3 = a3 + (float)(v58 * *(float *)&twoKp);
}
v18 = q0;
v19 = a2 * 0.050000001;
v20 = v16 * 0.050000001;
v21 = a3 * 0.050000001;
v22 = v20 * q0;
q0 = (float)((float)((float)(COERCE_FLOAT(q1 ^ LC4) * v20) - (float)(v19 * q2)) - (float)(q3 * v21)) + q0;
v23 = q3 * v19;
v24 = (float)(v21 * q2) + v22;
v25 = v19 * v18;
v26 = v19 * q1;
v27 = v21 * q1;
q1 = (float)(v24 - v23) + q1;
v28 = q3 * v20;
v29 = v20 * q2;
q2 = (float)(v28 + (float)(v25 - v27)) + q2;
q3 = (float)((float)((float)(v21 * v18) + v26) - v29) + q3;
v30 = invSqrt((float)((float)((float)(q0 * q0) + (float)(q1 * q1)) + (float)(q2 * q2)) + (float)(q3 * q3));
q0 = q0 * v30;
q1 = q1 * v30;
q2 = q2 * v30;
q3 = v30 * q3;
}
}

canonical_decompiled_code:
void __fastcall func1(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9)
{
char v15; // cl
float v16; // xmm8_4
char v17; // cl
float v18; // xmm6_4
float v19; // xmm1_4
float v20; // xmm8_4
float v21; // xmm2_4
float v22; // xmm4_4
float v23; // xmm7_4
float v24; // xmm3_4
float v25; // xmm4_4
float v26; // xmm1_4
float v27; // xmm9_4
float v28; // xmm3_4
float v29; // xmm8_4
float v30; // xmm0_4
float v31; // xmm0_4
float v32; // xmm0_4
float v33; // xmm6_4
float v34; // xmm7_4
float v35; // xmm3_4
__m128i v36; // xmm10
float v37; // ebx
float v38; // xmm10_4
float v39; // xmm5_4
float v40; // xmm13_4
float v41; // xmm4_4
float v42; // xmm0_4
float v43; // xmm11_4
float v44; // xmm0_4
float v45; // xmm0_4
float v46; // xmm5_4
float v47; // xmm4_4
float v48; // xmm13_4
float v49; // xmm10_4
float v50; // xmm11_4
float v51; // xmm11_4
float v52; // xmm12_4
float v53; // xmm13_4
float v54; // xmm14_4
float v55; // xmm0_4
float v56; // xmm13_4
float v57; // xmm11_4
float v58; // xmm6_4
float v59; // xmm10_4
float v61; // [rsp+0h] [rbp-54h]
float v63; // [rsp+4h] [rbp-50h]
float v64; // [rsp+8h] [rbp-4Ch]
float v65; // [rsp+Ch] [rbp-48h]
float v66; // [rsp+10h] [rbp-44h]
float v67; // [rsp+14h] [rbp-40h]
float v68; // [rsp+18h] [rbp-3Ch]
float v69; // [rsp+1Ch] [rbp-38h]
float v70; // [rsp+20h] [rbp-34h]
float v71; // [rsp+24h] [rbp-30h]
float v72; // [rsp+38h] [rbp-1Ch]
float v73; // [rsp+3Ch] [rbp-18h]

v15 = 0;
v16 = a1;
if ( a9 != 0.0 || a8 != 0.0 )
goto LABEL_5;
if ( a7 == 0.0 )
v15 = 1;
if ( v15 )
{
func0(a1, a2, a3, a4, a5, a6);
}
else
{
LABEL_5:
v17 = 1;
if ( a6 != 0.0 || a5 != 0.0 )
goto LABEL_10;
if ( a4 == 0.0 )
v17 = 0;
if ( v17 )
{
LABEL_10:
v31 = invSqrt((float)((float)(a4 * a4) + (float)(a5 * a5)) + (float)(a6 * a6));
v67 = a4 * v31;
v61 = a5 * v31;
v63 = a6 * v31;
v32 = invSqrt((float)((float)(a7 * a7) + (float)(a8 * a8)) + (float)(a9 * a9));
v33 = a7 * v32;
v34 = a8 * v32;
v35 = v32 * a9;
v36 = (__m128i)q0;
*(float *)v36.m128i_i32 = q0 * q0;
v37 = COERCE_FLOAT(_mm_cvtsi128_si32(v36));
v68 = q0 * q1;
v38 = q0 * q2;
v39 = q1 * q3;
v40 = 0.5 - (float)(q1 * q1);
v41 = q2 * q3;
v69 = q2 * q2;
v66 = (float)(q0 * q2) + (float)(q1 * q3);
v65 = (float)(q1 * q2) - (float)(q0 * q3);
v70 = q3 * q3;
v64 = (float)(0.5 - (float)(q2 * q2)) - (float)(q3 * q3);
v42 = (float)((float)(v65 * v34) + (float)(v64 * v33)) + (float)(v66 * (float)(v32 * a9));
v43 = (float)((float)((float)(q1 * q2) + (float)(q0 * q3)) * v33) + (float)((float)(v40 - (float)(q3 * q3)) * v34);
v44 = (float)((float)(v42 + v42) * (float)(v42 + v42))
+ (float)((float)((float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))
+ (float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35)))
* (float)((float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))
+ (float)(v43 + (float)((float)((float)(q2 * q3) - (float)(q0 * q1)) * v35))));
if ( v44 < 0.0 )
{
v73 = q2 * q3;
v72 = q1 * q3;
v71 = 0.5 - (float)(q1 * q1);
v45 = sqrtf(v44);
v41 = v73;
v39 = v72;
v40 = v71;
}
else
{
v45 = fsqrt(v44);
}
v46 = v39 - v38;
v47 = v41 + v68;
v48 = v40 - v69;
v49 = (float)(v37 - 0.5) + v70;
v50 = (float)((float)(v47 * v34) + (float)(v46 * v33)) + (float)(v48 * v35);
v51 = v50 + v50;
v52 = (float)(v64 * v45) + (float)(v46 * v51);
v53 = (float)(v48 * v51) + (float)(v45 * v66);
v54 = (float)(v47 * v51) + (float)(v65 * v45);
v55 = v34 * v53;
v56 = v53 * v33;
v57 = (float)((float)(v61 * v49) - (float)(v63 * v47)) + (float)(v55 - (float)(v35 * v54));
v58 = (float)((float)(v33 * v54) - (float)(v34 * v52)) + (float)((float)(v47 * v67) - (float)(v46 * v61));
v59 = (float)((float)(v35 * v52) - v56) + (float)((float)(v63 * v46) - (float)(v49 * v67));
if ( *(float *)&twoKi <= 0.0 )
{
integralFBx = 0;
integralFBy = 0;
integralFBz = 0;
}
else
{
*(float *)&integralFBx = (float)((float)(*(float *)&twoKi * v57) * 0.1) + *(float *)&integralFBx;
*(float *)&integralFBy = (float)((float)(*(float *)&twoKi * v59) * 0.1) + *(float *)&integralFBy;
*(float *)&integralFBz = (float)((float)(*(float *)&twoKi * v58) * 0.1) + *(float *)&integralFBz;
v16 = v16 + *(float *)&integralFBx;
a2 = a2 + *(float *)&integralFBy;
a3 = a3 + *(float *)&integralFBz;
}
v16 = v16 + (float)(v57 * *(float *)&twoKp);
a2 = a2 + (float)(*(float *)&twoKp * v59);
a3 = a3 + (float)(v58 * *(float *)&twoKp);
}
v18 = q0;
v19 = a2 * 0.050000001;
v20 = v16 * 0.050000001;
v21 = a3 * 0.050000001;
v22 = v20 * q0;
q0 = (float)((float)((float)(COERCE_FLOAT(q1 ^ LC4) * v20) - (float)(v19 * q2)) - (float)(q3 * v21)) + q0;
v23 = q3 * v19;
v24 = (float)(v21 * q2) + v22;
v25 = v19 * v18;
v26 = v19 * q1;
v27 = v21 * q1;
q1 = (float)(v24 - v23) + q1;
v28 = q3 * v20;
v29 = v20 * q2;
q2 = (float)(v28 + (float)(v25 - v27)) + q2;
q3 = (float)((float)((float)(v21 * v18) + v26) - v29) + q3;
v30 = invSqrt((float)((float)((float)(q0 * q0) + (float)(q1 * q1)) + (float)(q2 * q2)) + (float)(q3 * q3));
q0 = q0 * v30;
q1 = q1 * v30;
q2 = q2 * v30;
q3 = v30 * q3;
}
}

original_code:
void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) {
 float recipNorm;
    float q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3;
 float hx, hy, bx, bz;
 float halfvx, halfvy, halfvz, halfwx, halfwy, halfwz;
 float halfex, halfey, halfez;
 float qa, qb, qc;
 if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) {
  MahonyAHRSupdateIMU(gx, gy, gz, ax, ay, az);
  return;
 }
 if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
  recipNorm = invSqrt(ax * ax + ay * ay + az * az);
  ax *= recipNorm;
  ay *= recipNorm;
  az *= recipNorm;
  recipNorm = invSqrt(mx * mx + my * my + mz * mz);
  mx *= recipNorm;
  my *= recipNorm;
  mz *= recipNorm;
        q0q0 = q0 * q0;
        q0q1 = q0 * q1;
        q0q2 = q0 * q2;
        q0q3 = q0 * q3;
        q1q1 = q1 * q1;
        q1q2 = q1 * q2;
        q1q3 = q1 * q3;
        q2q2 = q2 * q2;
        q2q3 = q2 * q3;
        q3q3 = q3 * q3;
        hx = 2.0f * (mx * (0.5f - q2q2 - q3q3) + my * (q1q2 - q0q3) + mz * (q1q3 + q0q2));
        hy = 2.0f * (mx * (q1q2 + q0q3) + my * (0.5f - q1q1 - q3q3) + mz * (q2q3 - q0q1));
        bx = sqrt(hx * hx + hy * hy);
        bz = 2.0f * (mx * (q1q3 - q0q2) + my * (q2q3 + q0q1) + mz * (0.5f - q1q1 - q2q2));
  halfvx = q1q3 - q0q2;
  halfvy = q0q1 + q2q3;
  halfvz = q0q0 - 0.5f + q3q3;
        halfwx = bx * (0.5f - q2q2 - q3q3) + bz * (q1q3 - q0q2);
        halfwy = bx * (q1q2 - q0q3) + bz * (q0q1 + q2q3);
        halfwz = bx * (q0q2 + q1q3) + bz * (0.5f - q1q1 - q2q2);
  halfex = (ay * halfvz - az * halfvy) + (my * halfwz - mz * halfwy);
  halfey = (az * halfvx - ax * halfvz) + (mz * halfwx - mx * halfwz);
  halfez = (ax * halfvy - ay * halfvx) + (mx * halfwy - my * halfwx);
  if(twoKi > 0.0f) {
   integralFBx += twoKi * halfex * (1.0f / 10.0f);
   integralFBy += twoKi * halfey * (1.0f / 10.0f);
   integralFBz += twoKi * halfez * (1.0f / 10.0f);
   gx += integralFBx;
   gy += integralFBy;
   gz += integralFBz;
  }
  else {
   integralFBx = 0.0f;
   integralFBy = 0.0f;
   integralFBz = 0.0f;
  }
  gx += twoKp * halfex;
  gy += twoKp * halfey;
  gz += twoKp * halfez;
 }
 gx *= (0.5f * (1.0f / 10.0f));
 gy *= (0.5f * (1.0f / 10.0f));
 gz *= (0.5f * (1.0f / 10.0f));
 qa = q0;
 qb = q1;
 qc = q2;
 q0 += (-qb * gx - qc * gy - q3 * gz);
 q1 += (qa * gx + qc * gz - q3 * gy);
 q2 += (qa * gy - qb * gz + q3 * gx);
 q3 += (qa * gz + qb * gy - qc * gx);
 recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
 q0 *= recipNorm;
 q1 *= recipNorm;
 q2 *= recipNorm;
 q3 *= recipNorm;
}

canonical_original_code:
void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) {
 float recipNorm;
    float q0q0; float q0q1; float q0q2; float q0q3; float q1q1; float q1q2; float q1q3; float q2q2; float q2q3; float q3q3;
 float hx; float hy; float bx; float bz;
 float halfvx; float halfvy; float halfvz; float halfwx; float halfwy; float halfwz;
 float halfex; float halfey; float halfez;
 float qa; float qb; float qc;
 if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) {
  MahonyAHRSupdateIMU(gx, gy, gz, ax, ay, az);
  return;
 }
 if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
  recipNorm = invSqrt(ax * ax + ay * ay + az * az);
  ax *= recipNorm;
  ay *= recipNorm;
  az *= recipNorm;
  recipNorm = invSqrt(mx * mx + my * my + mz * mz);
  mx *= recipNorm;
  my *= recipNorm;
  mz *= recipNorm;
        q0q0 = q0 * q0;
        q0q1 = q0 * q1;
        q0q2 = q0 * q2;
        q0q3 = q0 * q3;
        q1q1 = q1 * q1;
        q1q2 = q1 * q2;
        q1q3 = q1 * q3;
        q2q2 = q2 * q2;
        q2q3 = q2 * q3;
        q3q3 = q3 * q3;
        hx = 2.0f * (mx * (0.5f - q2q2 - q3q3) + my * (q1q2 - q0q3) + mz * (q1q3 + q0q2));
        hy = 2.0f * (mx * (q1q2 + q0q3) + my * (0.5f - q1q1 - q3q3) + mz * (q2q3 - q0q1));
        bx = sqrt(hx * hx + hy * hy);
        bz = 2.0f * (mx * (q1q3 - q0q2) + my * (q2q3 + q0q1) + mz * (0.5f - q1q1 - q2q2));
  halfvx = q1q3 - q0q2;
  halfvy = q0q1 + q2q3;
  halfvz = q0q0 - 0.5f + q3q3;
        halfwx = bx * (0.5f - q2q2 - q3q3) + bz * (q1q3 - q0q2);
        halfwy = bx * (q1q2 - q0q3) + bz * (q0q1 + q2q3);
        halfwz = bx * (q0q2 + q1q3) + bz * (0.5f - q1q1 - q2q2);
  halfex = (ay * halfvz - az * halfvy) + (my * halfwz - mz * halfwy);
  halfey = (az * halfvx - ax * halfvz) + (mz * halfwx - mx * halfwz);
  halfez = (ax * halfvy - ay * halfvx) + (mx * halfwy - my * halfwx);
  if(twoKi > 0.0f) {
   integralFBx += twoKi * halfex * (1.0f / 10.0f);
   integralFBy += twoKi * halfey * (1.0f / 10.0f);
   integralFBz += twoKi * halfez * (1.0f / 10.0f);
   gx += integralFBx;
   gy += integralFBy;
   gz += integralFBz;
  }
  else {
   integralFBx = 0.0f;
   integralFBy = 0.0f;
   integralFBz = 0.0f;
  }
  gx += twoKp * halfex;
  gy += twoKp * halfey;
  gz += twoKp * halfez;
 }
 gx *= (0.5f * (1.0f / 10.0f));
 gy *= (0.5f * (1.0f / 10.0f));
 gz *= (0.5f * (1.0f / 10.0f));
 qa = q0;
 qb = q1;
 qc = q2;
 q0 += (-qb * gx - qc * gy - q3 * gz);
 q1 += (qa * gx + qc * gz - q3 * gy);
 q2 += (qa * gy - qb * gz + q3 * gx);
 q3 += (qa * gz + qb * gy - qc * gx);
 recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
 q0 *= recipNorm;
 q1 *= recipNorm;
 q2 *= recipNorm;
 q3 *= recipNorm;
}

variable_types: mx float

variable_types: my float

variable_types: mz float

variable_types: hx float

variable_types: hy float

variable_types: bx float

variable_types: bz float

variable_types: halfwx float

variable_types: halfwy float

variable_types: halfwz float


cmdcmp

original_code:
static int cmdcmp(const char *cmd, const char *s, char **endptr)
{
    int len = strlen(cmd);
    if(endptr && len <= strlen(s)) {
        *endptr = (char*)s+len;
        while(**endptr == ' ') (*endptr)++;
    }
    return !strncmp(cmd, s, len);
}

canonical_original_code:
static int cmdcmp(char *cmd, char *s, char **endptr)
{
    int len = strlen(cmd);
    if(endptr && len <= strlen(s)) {
        *endptr = (char *)s+len;
        while(**endptr == ' ') (*endptr)++;
    }
    return !strncmp(cmd, s, len);
}

variable_types:
cmd
char *

variable_types:
s
char *

variable_types:
endptr
char **

variable_types: len int


main

repo: sebasalazar/C

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
int v4; // ebx
socklen_t v5; // edx
size_t v6; // rax
int v7; // eax
int v8; // ebp
char *endptr; // [rsp+8h] [rbp-420h] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-418h] BYREF
char s[1032]; // [rsp+20h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = strtol(argv[1], &endptr, 0);
if ( *endptr )
{
fwrite("ECHOSERV: Invalid port number.\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
}
else
{
v3 = 2002;
if ( argc > 1 )
{
fwrite("ECHOSERV: Invalid arguments.\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
}
v4 = socket(2, 1, 0);
if ( v4 >= 0 )
{
*(_QWORD *)&v10.sa_data[6] = 0LL;
v10.sa_family = 2;
*(_QWORD *)&v10.sa_data[2] = (unsigned int)_bswap_32_constprop_0(v3, &v10, 16LL);
*(_WORD *)v10.sa_data = _bswap_16();
if ( bind(v4, &v10, v5) >= 0 )
{
if ( listen(v4, 1024) < 0 )
{
fwrite("ECHOSERV: Error calling listen()\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
while ( 1 )
{
v7 = accept(v4, 0LL, 0LL);
v8 = v7;
if ( v7 < 0 )
break;
Readline(v7);
v6 = strlen(s);
Writeline(v8, s, v6);
if ( close(v8) < 0 )
{
fwrite("ECHOSERV: Error calling close()\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
}
fwrite("ECHOSERV: Error calling accept()\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
fwrite("ECHOSERV: Error calling bind()\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
fwrite("ECHOSERV: Error creating listening socket.\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
int v4; // ebx
socklen_t v5; // edx
size_t v6; // rax
int v7; // eax
int v8; // ebp
char *endptr; // [rsp+8h] [rbp-420h] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-418h] BYREF
char s[1032]; // [rsp+20h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = strtol(argv[1], &endptr, 0);
if ( *endptr )
{
fwrite("ECHOSERV: Invalid port number.\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
}
else
{
v3 = 2002;
if ( argc > 1 )
{
fwrite("ECHOSERV: Invalid arguments.\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
}
v4 = socket(2, 1, 0);
if ( v4 >= 0 )
{
*(_QWORD *)&v10.sa_data[6] = 0LL;
v10.sa_family = 2;
*(_QWORD *)&v10.sa_data[2] = (unsigned int)func8(v3, &v10, 16LL);
*(_WORD *)v10.sa_data = func7();
if ( bind(v4, &v10, v5) >= 0 )
{
if ( listen(v4, 1024) < 0 )
{
fwrite("ECHOSERV: Error calling listen()\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
while ( 1 )
{
v7 = accept(v4, 0LL, 0LL);
v8 = v7;
if ( v7 < 0 )
break;
func9(v7);
v6 = strlen(s);
func10(v8, s, v6);
if ( close(v8) < 0 )
{
fwrite("ECHOSERV: Error calling close()\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
}
fwrite("ECHOSERV: Error calling accept()\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
fwrite("ECHOSERV: Error calling bind()\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
fwrite("ECHOSERV: Error creating listening socket.\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    int list_s;
    int conn_s;
    short int port;
    struct sockaddr_in servaddr;
    char buffer[(1000)];
    char *endptr;
    if ( argc == 2 ) {
 port = strtol(argv[1], &endptr, 0);
 if ( *endptr ) {
     fprintf(stderr, "ECHOSERV: Invalid port number.\n");
     exit(1);
 }
    }
    else if ( argc < 2 ) {
 port = (2002);
    }
    else {
 fprintf(stderr, "ECHOSERV: Invalid arguments.\n");
 exit(1);
    }
    if ( (list_s = socket(2, SOCK_STREAM, 0)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
 exit(1);
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    servaddr.sin_port = htons(port);
    if ( bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error calling bind()\n");
 exit(1);
    }
    if ( listen(list_s, (1024)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error calling listen()\n");
 exit(1);
    }
    while ( 1 ) {
 if ( (conn_s = accept(list_s, ((void *)0), ((void *)0)) ) < 0 ) {
     fprintf(stderr, "ECHOSERV: Error calling accept()\n");
     exit(1);
 }
 Readline(conn_s, buffer, (1000)-1);
 Writeline(conn_s, buffer, strlen(buffer));
 if ( close(conn_s) < 0 ) {
     fprintf(stderr, "ECHOSERV: Error calling close()\n");
     exit(1);
 }
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int list_s;
    int conn_s;
    short port;
    struct sockaddr_in servaddr;
    char buffer[-1];
    char *endptr;
    if ( argc == 2 ) {
 port = strtol(argv[1], &endptr, 0);
 if ( *endptr ) {
     fprintf(stderr, "ECHOSERV: Invalid port number.\n");
     exit(1);
 }
    }
    else if ( argc < 2 ) {
 port = (2002);
    }
    else {
 fprintf(stderr, "ECHOSERV: Invalid arguments.\n");
 exit(1);
    }
    if ( (list_s = socket(2, SOCK_STREAM, 0)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
 exit(1);
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    servaddr.sin_port = htons(port);
    if ( bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error calling bind()\n");
 exit(1);
    }
    if ( listen(list_s, (1024)) < 0 ) {
 fprintf(stderr, "ECHOSERV: Error calling listen()\n");
 exit(1);
    }
    while ( 1 ) {
 if ( (conn_s = accept(list_s, ((void *)0), ((void *)0)) ) < 0 ) {
     fprintf(stderr, "ECHOSERV: Error calling accept()\n");
     exit(1);
 }
 Readline(conn_s, buffer, (1000)-1);
 Writeline(conn_s, buffer, strlen(buffer));
 if ( close(conn_s) < 0 ) {
     fprintf(stderr, "ECHOSERV: Error calling close()\n");
     exit(1);
 }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: port short

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
buffer
char [-1]

variable_types:
endptr
char *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


Readline

decompiled_code:
__int64 __fastcall Readline(int fd, _BYTE *a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // rbx
ssize_t v7; // rax
char v8; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v5 = 1LL;
}
else
{
v4 = a3;
v5 = a3;
v6 = 1LL;
while ( 1 )
{
while ( 1 )
{
v7 = read(fd, buf, 1uLL);
if ( v7 != 1 )
break;
v8 = buf[0];
*a2 = buf[0];
if ( v8 == 10 )
{
v5 = v6;
++a2;
goto LABEL_9;
}
++v6;
++a2;
if ( v6 == v4 )
goto LABEL_9;
}
if ( !v7 )
break;
if ( *__errno_location() != 4 )
return -1LL;
if ( ++v6 == v4 )
goto LABEL_9;
}
v5 = 0LL;
if ( v6 == 1 )
return v5;
v5 = v6;
}
LABEL_9:
*a2 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, _BYTE *a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // rbx
ssize_t v7; // rax
char v8; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v5 = 1LL;
}
else
{
v4 = a3;
v5 = a3;
v6 = 1LL;
while ( 1 )
{
while ( 1 )
{
v7 = read(fd, buf, 1uLL);
if ( v7 != 1 )
break;
v8 = buf[0];
*a2 = buf[0];
if ( v8 == 10 )
{
v5 = v6;
++a2;
goto LABEL_9;
}
++v6;
++a2;
if ( v6 == v4 )
goto LABEL_9;
}
if ( !v7 )
break;
if ( *__errno_location() != 4 )
return -1LL;
if ( ++v6 == v4 )
goto LABEL_9;
}
v5 = 0LL;
if ( v6 == 1 )
return v5;
v5 = v6;
}
LABEL_9:
*a2 = 0;
return v5;
}

original_code:
ssize_t Readline(int sockd, void *vptr, size_t maxlen) {
    ssize_t n, rc;
    char c, *buffer;
    buffer = vptr;
    for ( n = 1; n < maxlen; n++ ) {
 if ( (rc = read(sockd, &c, 1)) == 1 ) {
     *buffer++ = c;
     if ( c == '\n' )
  break;
 }
 else if ( rc == 0 ) {
     if ( n == 1 )
  return 0;
     else
  break;
 }
 else {
     if ( (*__errno_location ()) == 4 )
  continue;
     return -1;
 }
    }
    *buffer = 0;
    return n;
}

canonical_original_code:
long Readline(int sockd, void *vptr, unsigned long maxlen) {
    long n; long rc;
    char c; char *buffer;
    buffer = vptr;
    for ( n = 1; n < maxlen; n++ ) {
 if ( (rc = read(sockd, &c, 1)) == 1 ) {
     *buffer++ = c;
     if ( c == '\n' )
  break;
 }
 else if ( rc == 0 ) {
     if ( n == 1 )
  return 0;
     else
  break;
 }
 else {
     if ( (*__errno_location ()) == 4 )
  continue;
     return -1;
 }
    }
    *buffer = 0;
    return n;
}

variable_types: sockd int

variable_types:
vptr
void *

variable_types:
maxlen
unsigned long

variable_types: n long

variable_types: rc long

variable_types: c char

variable_types:
buffer
char *

return_type: long


Writeline

decompiled_code:
size_t __fastcall Writeline(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *__errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func10(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *__errno_location() == 4 );
return -1LL;
}

original_code:
ssize_t Writeline(int sockd, const void *vptr, size_t n) {
    size_t nleft;
    ssize_t nwritten;
    const char *buffer;
    buffer = vptr;
    nleft = n;
    while ( nleft > 0 ) {
 if ( (nwritten = write(sockd, buffer, nleft)) <= 0 ) {
     if ( (*__errno_location ()) == 4 )
  nwritten = 0;
     else
  return -1;
 }
 nleft -= nwritten;
 buffer += nwritten;
    }
    return n;
}

canonical_original_code:
long Writeline(int sockd, void *vptr, unsigned long n) {
    unsigned long nleft;
    long nwritten;
    char *buffer;
    buffer = vptr;
    nleft = n;
    while ( nleft > 0 ) {
 if ( (nwritten = write(sockd, buffer, nleft)) <= 0 ) {
     if ( (*__errno_location ()) == 4 )
  nwritten = 0;
     else
  return -1;
 }
 nleft -= nwritten;
 buffer += nwritten;
    }
    return n;
}

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax

fwrite("\nEjemplo de uso Curl en C\n\t\tDesarrollado por Sebastian Salazar Molina\n", 1uLL, 0x46uLL, _bss_start);
fprintf(_bss_start, "\nMensaje Enviado: %s\n", "txtRUN=159978869");
v3 = (const char *)comunicar("http://consulta.servel.cl", 80LL, "/", "txtRUN=159978869", 0LL);
if ( v3 )
fprintf(stderr, "\nRespuesta : %s\n", v3);
else
fwrite("\nError de Comunicacion.", 1uLL, 0x17uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax

fwrite("\nEjemplo de uso Curl en C\n\t\tDesarrollado por Sebastian Salazar Molina\n", 1uLL, 0x46uLL, _bss_start);
fprintf(_bss_start, "\nMensaje Enviado: %s\n", "txtRUN=159978869");
v3 = (const char *)func12("http://consulta.servel.cl", 80LL, "/", "txtRUN=159978869", 0LL);
if ( v3 )
fprintf(stderr, "\nRespuesta : %s\n", v3);
else
fwrite("\nError de Comunicacion.", 1uLL, 0x17uLL, stderr);
return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
unsigned __int64 v4; // rbx
__int64 v5; // rbp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // rdi
const char *v8; // rax

v3 = (char *)calloc(0x10uLL, 1uLL);
strcpy(v3, "146.83.0.0");
v4 = ip2numero(v3);
v5 = cantidad_direcciones(16LL);
printf("\n%ld %ld\n", v4, v5);
v6 = v4 + v5;
if ( v4 < v6 )
{
do
{
v7 = v4++;
v8 = (const char *)numero2ip(v7);
puts(v8);
}
while ( v4 != v6 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
unsigned __int64 v4; // rbx
__int64 v5; // rbp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // rdi
const char *v8; // rax

v3 = (char *)calloc(0x10uLL, 1uLL);
strcpy(v3, "146.83.0.0");
v4 = func15(v3);
v5 = func16(16LL);
printf("\n%ld %ld\n", v4, v5);
v6 = v4 + v5;
if ( v4 < v6 )
{
do
{
v7 = v4++;
v8 = (const char *)func13(v7);
puts(v8);
}
while ( v4 != v6 );
}
return 0;
}


decompiled_code:
ssize_t __fastcall send_message(int a1, const void *a2)
{
return write(a1, a2, 8uLL);
}

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

original_code:
void send_message(int sd, struct controlMessage *m)
{
    write(sd,m,sizeof(m));
}

variable_types: sd int

variable_types: struct controlMessage { int type; int argLength; char *arg; } *


decompiled_code:
void __fastcall __noreturn get_response(__int64 a1, int a2, const void *a3)
{
send_message(a2, a3);
read(a2, 0LL, 4uLL);
BUG();
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1, int a2, const void *a3)
{
func2(a2, a3);
read(a2, 0LL, 4uLL);
BUG();
}

original_code:
void get_response(int type, int sd, struct controlMessage *m)
{
    send_message(sd,m);
    int* typeMessage=((void *)0);
    read(sd,typeMessage,sizeof(int));
    if(*typeMessage != type || *typeMessage != 13)
    {
        fprintf( stderr, "Error of transmission" );
        return;
    }
    int* length=((void *)0);
    read(sd,length,sizeof(int));
    char* buff=((void *)0);
    read(sd,buff,*length*sizeof(char));
    fprintf( stdout, "%s", buff);
}

canonical_original_code:
void get_response(int type, int sd, struct controlMessage *m)
{
    send_message(sd,m);
    int *typeMessage = ((void *)0);
    read(sd,typeMessage,sizeof(int));
    if(*typeMessage != type || *typeMessage != 13)
    {
        fprintf( stderr, "Error of transmission" );
        return;
    }
    int *length = ((void *)0);
    read(sd,length,sizeof(int));
    char *buff = ((void *)0);
    read(sd,buff,*length*sizeof(char));
    fprintf( stdout, "%s", buff);
}

variable_types: type int

variable_types:
typeMessage
int *

variable_types:
length
int *

variable_types:
buff
char *

user_defined_types: struct controlMessage { int type; int argLength; char *arg; }


decompiled_code:
void __fastcall clear_message(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void clear_message(struct controlMessage *m)
{
    m->type=0;
    m->argLength=0;
    m->arg=((void *)0);
}


decompiled_code:
int __fastcall transfer_and_recieve_files(int fd)
{
int v2; // eax
int v3; // ebp
const char *v5; // rdi
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( listen(fd, 5) == -1 )
{
v5 = "The file sender/reciever can't listen on port %i";
goto LABEL_5;
}
fprintf(stderr, "The file sender/reciever is listening on port %i ...", 7000LL);
v2 = accept(fd, &addr, &addr_len);
v3 = v2;
if ( v2 < 0 )
{
v5 = "The file sender/reciever can't accept a connection\n";
LABEL_5:
perror(v5);
close(fd);
exit(1);
}
read(v2, 0LL, 4uLL);
fwrite("unauthorized connection to the FTP server", 1uLL, 0x29uLL, stderr);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
int v2; // eax
int v3; // ebp
const char *v5; // rdi
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( listen(fd, 5) == -1 )
{
v5 = "The file sender/reciever can't listen on port %i";
goto LABEL_5;
}
fprintf(stderr, "The file sender/reciever is listening on port %i ...", 7000LL);
v2 = accept(fd, &addr, &addr_len);
v3 = v2;
if ( v2 < 0 )
{
v5 = "The file sender/reciever can't accept a connection\n";
LABEL_5:
perror(v5);
close(fd);
exit(1);
}
read(v2, 0LL, 4uLL);
fwrite("unauthorized connection to the FTP server", 1uLL, 0x29uLL, stderr);
return close(v3);
}

original_code:
void transfer_and_recieve_files(int sd)
{
    if(listen(sd,5) == -1)
    {
        perror("The file sender/reciever can't listen on port %i");
        close(sd);
        exit(1);
    }
    fprintf(stderr,"The file sender/reciever is listening on port %i ...",7000);
    int sdf;
    socklen_t sin_size;
    struct sockaddr_in sockaddrC;
    if ((sdf = accept(sd, (struct sockaddr *)&sockaddrC, &sin_size)) < 0)
    {
        perror("The file sender/reciever can't accept a connection\n");
        close(sd);
        exit(1);
    }
    int* typeMessage=((void *)0);
    read(sdf,typeMessage,sizeof(int));
    if(*typeMessage != 8|| *typeMessage != 7)
    {
        fprintf( stderr, "unauthorized connection to the FTP server" );
        close(sdf);
        return;
    }
    int* length=((void *)0);
    read(sdf,length,sizeof(int));
    char* name=((void *)0);
    read(sdf,name,*length*sizeof(char));
    if(*typeMessage == 8)
        recieve_file(sdf,name);
    else
        transfer_file(sdf,name);
    close(sdf);
}

canonical_original_code:
void transfer_and_recieve_files(int sd)
{
    if(listen(sd,5) == -1)
    {
        perror("The file sender/reciever can't listen on port %i");
        close(sd);
        exit(1);
    }
    fprintf(stderr,"The file sender/reciever is listening on port %i ...",7000);
    int sdf;
    unsigned int sin_size;
    struct sockaddr_in sockaddrC;
    if ((sdf = accept(sd, (struct sockaddr *)&sockaddrC, &sin_size)) < 0)
    {
        perror("The file sender/reciever can't accept a connection\n");
        close(sd);
        exit(1);
    }
    int *typeMessage = ((void *)0);
    read(sdf,typeMessage,sizeof(int));
    if(*typeMessage != 8|| *typeMessage != 7)
    {
        fprintf( stderr, "unauthorized connection to the FTP server" );
        close(sdf);
        return;
    }
    int *length = ((void *)0);
    read(sdf,length,sizeof(int));
    char *name = ((void *)0);
    read(sdf,name,*length*sizeof(char));
    if(*typeMessage == 8)
        recieve_file(sdf,name);
    else
        transfer_file(sdf,name);
    close(sdf);
}

variable_types: sdf int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
name
char *


decompiled_code:
void func_send()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void func_send(char* cmd)
{
}

canonical_original_code:
void func_send(char *cmd)
{
}

variable_types:
cmd
char *


decompiled_code:
__int64 __fastcall recieve_message(int fd)
{
size_t v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

clear_message(&v5);
read(fd, &v5, v1);
read(fd, (char *)&v5 + 4, 4uLL);
read(fd, &v6, SHIDWORD(v5));
v3 = 1LL;
if ( (v5 & 0xFFFFFFFD) != 1 )
{
LOBYTE(v3) = (_DWORD)v5 != 9;
if ( (_DWORD)v5 == 5 )
{
get_response(3LL, (unsigned int)fd, &v5, v2, v3);
func_cd(v6);
LODWORD(v3) = 1;
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd)
{
size_t v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

func1(&v5);
read(fd, &v5, v1);
read(fd, (char *)&v5 + 4, 4uLL);
read(fd, &v6, SHIDWORD(v5));
v3 = 1LL;
if ( (v5 & 0xFFFFFFFD) != 1 )
{
LOBYTE(v3) = (_DWORD)v5 != 9;
if ( (_DWORD)v5 == 5 )
{
get_response(3LL, (unsigned int)fd, &v5, v2, v3);
func_cd(v6);
LODWORD(v3) = 1;
}
}
return (unsigned int)v3;
}

original_code:
_Bool recieve_message(int sd)
{
    struct controlMessage mess;
    clear_message(&mess);
    read(sd,&mess.type,sizeof(int));
    read(sd,&mess.argLength,sizeof(int));
    read(sd,&mess.arg,(mess.argLength)*sizeof(char));
    if(mess.type == 1)
        func_send("pwd");
    else if(mess.type == 3)
        func_send("ls");
    else if(mess.type == 5)
    {
        get_response(3,sd,&mess);
        func_cd(mess.arg);
    }
    else if(mess.type == 9)
    {
        return 0;
    }
    return 1;
}

variable_types: struct controlMessage { int type; int argLength; char *arg; }


repo: sebcat/yarlib

decompiled_code:
__int64 __fastcall port_range_next(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // edx
unsigned int v4; // er8

if ( !a1 )
_assert_fail("range != NULL", "port.c", 0x74u, "port_range_next");
if ( !a2 )
_assert_fail("dst != NULL", "port.c", 0x75u, "port_range_next");
v2 = *a1;
v3 = a1[1];
if ( *a1 <= v3 )
{
if ( v2 < v3 )
{
v2 += a1[2];
v4 = 0;
if ( v3 < v2 )
return v4;
goto LABEL_5;
}
if ( v2 != v3 )
_assert_fail("0", "port.c", 0x87u, "port_range_next");
v4 = 0;
if ( !a1[2] )
{
LABEL_5:
*a2 = v2;
v4 = 1;
++a1[2];
return v4;
}
}
else
{
v2 -= a1[2];
v4 = 0;
if ( v3 <= v2 )
goto LABEL_5;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // edx
unsigned int v4; // er8

if ( !a1 )
_assert_fail("range != NULL", "port.c", 0x74u, "port_range_next");
if ( !a2 )
_assert_fail("dst != NULL", "port.c", 0x75u, "port_range_next");
v2 = *a1;
v3 = a1[1];
if ( *a1 <= v3 )
{
if ( v2 < v3 )
{
v2 += a1[2];
v4 = 0;
if ( v3 < v2 )
return v4;
goto LABEL_5;
}
if ( v2 != v3 )
_assert_fail("0", "port.c", 0x87u, "port_range_next");
v4 = 0;
if ( !a1[2] )
{
LABEL_5:
*a2 = v2;
v4 = 1;
++a1[2];
return v4;
}
}
else
{
v2 -= a1[2];
v4 = 0;
if ( v3 <= v2 )
goto LABEL_5;
}
return v4;
}

original_code:
static _Bool port_range_next(port_range_t *range, yar_port_t *dst)
{
    yar_port_t curr;
    ((void) sizeof ((range != ((void *)0)) ? 1 : 0), __extension__ ({ if (range != ((void *)0)) ; else __assert_fail ("range != NULL", "port.c", 116, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "port.c", 117, __extension__ __PRETTY_FUNCTION__); }));
    if (range->start > range->end) {
        curr = range->start - range->offset;
        if (curr < range->end) {
            return 0;
        }
    } else if (range->start < range->end) {
        curr = range->start + range->offset;
        if (curr > range->end) {
            return 0;
        }
    } else if (range->start == range->end) {
        curr = range->start;
        if (range->offset != 0) {
            return 0;
        }
    } else {
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "port.c", 135, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
    *dst = curr;
    range->offset++;
    return 1;
}

canonical_original_code:
static _Bool port_range_next(struct port_range_t *range, unsigned int *dst)
{
    unsigned int curr;
    ((void) sizeof ((range != ((void *)0)) ? 1 : 0), __extension__ ({ if (range != ((void *)0)) ; else __assert_fail ("range != NULL", "port.c", 116, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "port.c", 117, __extension__ __PRETTY_FUNCTION__); }));
    if (range->start > range->end) {
        curr = range->start - range->offset;
        if (curr < range->end) {
            return 0;
        }
    } else if (range->start < range->end) {
        curr = range->start + range->offset;
        if (curr > range->end) {
            return 0;
        }
    } else if (range->start == range->end) {
        curr = range->start;
        if (range->offset != 0) {
            return 0;
        }
    } else {
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "port.c", 135, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
    *dst = curr;
    range->offset++;
    return 1;
}

variable_types: struct port_range_t { unsigned int start; unsigned int offset; } *

variable_types:
dst
unsigned int *

variable_types:
curr
unsigned int


decompiled_code:
__int64 __fastcall yar_port_from_str(_DWORD *a1, const char *a2)
{
unsigned __int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
_assert_fail("port != NULL", "port.c", 0x3Au, "yar_port_from_str");
if ( !a2 )
_assert_fail("str != NULL", "port.c", 0x3Bu, "yar_port_from_str");
if ( *a2 )
{
v2 = strtoul(a2, &endptr, 10);
if ( !*endptr )
{
if ( v2 )
{
if ( v2 <= 0xFFFF )
{
LABEL_7:
*a1 = v2;
return 0LL;
}
}
else if ( *_errno_location() != 22 )
{
goto LABEL_7;
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, const char *a2)
{
unsigned __int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
_assert_fail("port != NULL", "port.c", 0x3Au, "yar_port_from_str");
if ( !a2 )
_assert_fail("str != NULL", "port.c", 0x3Bu, "yar_port_from_str");
if ( *a2 )
{
v2 = strtoul(a2, &endptr, 10);
if ( !*endptr )
{
if ( v2 )
{
if ( v2 <= 0xFFFF )
{
LABEL_7:
*a1 = v2;
return 0LL;
}
}
else if ( *_errno_location() != 22 )
{
goto LABEL_7;
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int yar_port_from_str(yar_port_t *port, const char *str)
{
    unsigned long tmp;
    char *cptr;
    ((void) sizeof ((port != ((void *)0)) ? 1 : 0), __extension__ ({ if (port != ((void *)0)) ; else __assert_fail ("port != NULL", "port.c", 58, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "port.c", 59, __extension__ __PRETTY_FUNCTION__); }));
    if (str == ((void *)0) || *str == '\0') {
        return -1;
    }
    tmp = strtoul(str, &cptr, 10);
    if (*cptr != '\0') {
        return -1;
    }
    if ((tmp == 0 && (*__errno_location ()) == 22) || tmp > 65535) {
        return -1;
    }
    *port = (yar_port_t)tmp;
    return 0;
}

canonical_original_code:
int yar_port_from_str(unsigned int *port, char *str)
{
    unsigned long tmp;
    char *cptr;
    ((void) sizeof ((port != ((void *)0)) ? 1 : 0), __extension__ ({ if (port != ((void *)0)) ; else __assert_fail ("port != NULL", "port.c", 58, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "port.c", 59, __extension__ __PRETTY_FUNCTION__); }));
    if (str == ((void *)0) || *str == '\0') {
        return -1;
    }
    tmp = strtoul(str, &cptr, 10);
    if (*cptr != '\0') {
        return -1;
    }
    if ((tmp == 0 && (*__errno_location ()) == 22) || tmp > 65535) {
        return -1;
    }
    *port = (unsigned int)tmp;
    return 0;
}

variable_types:
port
unsigned int *

variable_types:
str
char *

variable_types:
tmp
unsigned long

variable_types:
cptr
char *


decompiled_code:
__int64 __fastcall port_range_init_from_str(int *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rbp
int v4; // eax
int v6; // [rsp+8h] [rbp-120h] BYREF
int v7; // [rsp+Ch] [rbp-11Ch] BYREF
char dest[280]; // [rsp+10h] [rbp-118h] BYREF

strncpy(dest, a2, 0xFFuLL);
dest[255] = 0;
v2 = strchr(dest, 45);
if ( v2 )
{
*v2 = 0;
v3 = v2 + 1;
if ( !(unsigned int)yar_port_from_str(&v6, dest) && !(unsigned int)yar_port_from_str(&v7, v3) )
{
LABEL_4:
v4 = v6;
a1[2] = 0;
*a1 = v4;
a1[1] = v7;
return 0LL;
}
}
else if ( !(unsigned int)yar_port_from_str(&v6, dest) && !(unsigned int)yar_port_from_str(&v7, dest) )
{
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rbp
int v4; // eax
int v6; // [rsp+8h] [rbp-120h] BYREF
int v7; // [rsp+Ch] [rbp-11Ch] BYREF
char dest[280]; // [rsp+10h] [rbp-118h] BYREF

strncpy(dest, a2, 0xFFuLL);
dest[255] = 0;
v2 = strchr(dest, 45);
if ( v2 )
{
*v2 = 0;
v3 = v2 + 1;
if ( !(unsigned int)func1(&v6, dest) && !(unsigned int)func1(&v7, v3) )
{
LABEL_4:
v4 = v6;
a1[2] = 0;
*a1 = v4;
a1[1] = v7;
return 0LL;
}
}
else if ( !(unsigned int)func1(&v6, dest) && !(unsigned int)func1(&v7, dest) )
{
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

original_code:
static int port_range_init_from_str(port_range_t *range, const char *rangestr)
{
    char buf[256], *cptr;
    yar_port_t startport, endport;
    strncpy(buf, rangestr, sizeof(buf));
    buf[sizeof(buf)-1] = '\0';
    cptr = strchr(buf, '-');
    if (cptr != ((void *)0)) {
        *cptr++ = '\0';
        if (yar_port_from_str(&startport, buf) != 0 ||
                yar_port_from_str(&endport, cptr) != 0) {
            return -1;
        }
    } else {
        if (yar_port_from_str(&startport, buf) != 0 ||
                yar_port_from_str(&endport, buf) != 0) {
            return -1;
        }
    }
    do { (range)->start = (startport); (range)->offset = 0; (range)->end = (endport); } while(0);;
    return 0;
}

canonical_original_code:
static int port_range_init_from_str(struct port_range_t *range, char *rangestr)
{
    char buf[256]; char *cptr;
    unsigned int startport; unsigned int endport;
    strncpy(buf, rangestr, sizeof(buf));
    buf[sizeof(buf)-1] = '\0';
    cptr = strchr(buf, '-');
    if (cptr != ((void *)0)) {
        *cptr++ = '\0';
        if (yar_port_from_str(&startport, buf) != 0 ||
                yar_port_from_str(&endport, cptr) != 0) {
            return -1;
        }
    } else {
        if (yar_port_from_str(&startport, buf) != 0 ||
                yar_port_from_str(&endport, buf) != 0) {
            return -1;
        }
    }
    do { (range)->start = (startport); (range)->offset = 0; (range)->end = (endport); } while(0);;
    return 0;
}

variable_types:
rangestr
char *

variable_types:
buf
char [256]

variable_types:
startport
unsigned int

variable_types:
endport
unsigned int

user_defined_types: struct port_range_t { unsigned int start; unsigned int offset; }


decompiled_code:
int __fastcall yar_port_to_str(unsigned int a1, char *a2, size_t a3)
{
int result; // eax

if ( !a2 )
_assert_fail("dst != NULL", "port.c", 0x50u, "yar_port_to_str");
if ( !a3 )
_assert_fail("dstlen > 0", "port.c", 0x51u, "yar_port_to_str");
result = snprintf(a2, a3, "%u", a1);
a2[a3 - 1] = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, char *a2, size_t a3)
{
int result; // eax

if ( !a2 )
_assert_fail("dst != NULL", "port.c", 0x50u, "yar_port_to_str");
if ( !a3 )
_assert_fail("dstlen > 0", "port.c", 0x51u, "yar_port_to_str");
result = snprintf(a2, a3, "%u", a1);
a2[a3 - 1] = 0;
return result;
}

original_code:
void yar_port_to_str(const yar_port_t port, char *dst, size_t dstlen)
{
    ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "port.c", 80, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dstlen > 0) ? 1 : 0), __extension__ ({ if (dstlen > 0) ; else __assert_fail ("dstlen > 0", "port.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    snprintf(dst, dstlen, "%u", port);
    dst[dstlen-1] = '\0';
}

canonical_original_code:
void yar_port_to_str(unsigned int port, char *dst, unsigned long dstlen)
{
    ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "port.c", 80, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dstlen > 0) ? 1 : 0), __extension__ ({ if (dstlen > 0) ; else __assert_fail ("dstlen > 0", "port.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    snprintf(dst, dstlen, "%u", port);
    dst[dstlen-1] = '\0';
}

variable_types:
port
unsigned int

variable_types:
dst
char *

variable_types:
dstlen
unsigned long


decompiled_code:
__int64 __fastcall yar_portspec_next(unsigned __int64 *a1, unsigned int *a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // er12
unsigned __int64 v4; // rdx
unsigned __int64 v5; // rax

if ( !a1 )
_assert_fail("spec != NULL", "port.c", 0xD2u, "yar_portspec_next");
v2 = a1[2];
if ( !v2 )
_assert_fail("spec->ranges != NULL", "port.c", 0xD3u, "yar_portspec_next");
v3 = port_range_next((unsigned int *)(v2 + 12 * a1[1]), a2);
if ( (_BYTE)v3 )
return 1LL;
v4 = *a1;
v5 = a1[1] + 1;
a1[1] = v5;
if ( v5 < v4 )
{
if ( (unsigned __int8)port_range_next((unsigned int *)(a1[2] + 12 * v5), a2) )
return 1LL;
v4 = *a1;
}
a1[1] = v4;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, unsigned int *a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // er12
unsigned __int64 v4; // rdx
unsigned __int64 v5; // rax

if ( !a1 )
_assert_fail("spec != NULL", "port.c", 0xD2u, "yar_portspec_next");
v2 = a1[2];
if ( !v2 )
_assert_fail("spec->ranges != NULL", "port.c", 0xD3u, "yar_portspec_next");
v3 = func0((unsigned int *)(v2 + 12 * a1[1]), a2);
if ( (_BYTE)v3 )
return 1LL;
v4 = *a1;
v5 = a1[1] + 1;
a1[1] = v5;
if ( v5 < v4 )
{
if ( (unsigned __int8)func0((unsigned int *)(a1[2] + 12 * v5), a2) )
return 1LL;
v4 = *a1;
}
a1[1] = v4;
return v3;
}

original_code:
_Bool yar_portspec_next(struct portspec_t *spec, yar_port_t *port)
{
    ((void) sizeof ((spec != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec != ((void *)0)) ; else __assert_fail ("spec != NULL", "port.c", 210, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((spec->ranges != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec->ranges != ((void *)0)) ; else __assert_fail ("spec->ranges != NULL", "port.c", 211, __extension__ __PRETTY_FUNCTION__); }));
    if (!port_range_next(&spec->ranges[spec->rangeix], port)) {
        spec->rangeix++;
        if (spec->rangeix >= spec->nranges
                || !port_range_next(&spec->ranges[spec->rangeix], port)) {
            spec->rangeix = spec->nranges;
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
_Bool yar_portspec_next(struct portspec_t *spec, unsigned int *port)
{
    ((void) sizeof ((spec != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec != ((void *)0)) ; else __assert_fail ("spec != NULL", "port.c", 210, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((spec->ranges != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec->ranges != ((void *)0)) ; else __assert_fail ("spec->ranges != NULL", "port.c", 211, __extension__ __PRETTY_FUNCTION__); }));
    if (!port_range_next(&spec->ranges[spec->rangeix], port)) {
        spec->rangeix++;
        if (spec->rangeix >= spec->nranges
                || !port_range_next(&spec->ranges[spec->rangeix], port)) {
            spec->rangeix = spec->nranges;
            return 0;
        }
    }
    return 1;
}

variable_types: struct portspec_t { unsigned long nranges; struct port_range_t { unsigned int start; unsigned int offset; } *ranges; } *

user_defined_types: struct portspec_t { unsigned long nranges; struct port_range_t *ranges; }


decompiled_code:
void __fastcall yar_portspec_reset(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rcx
_DWORD *v3; // rax
__int64 v4; // rdx

if ( !a1 )
_assert_fail("spec != NULL", "port.c", 0xE3u, "yar_portspec_reset");
v1 = a1[2];
if ( !v1 )
_assert_fail("spec->ranges != NULL", "port.c", 0xE4u, "yar_portspec_reset");
v2 = *a1;
a1[1] = 0LL;
if ( v2 )
{
v3 = (_DWORD *)(v1 + 8);
v4 = v1 + 12 * v2 + 8;
do
{
*v3 = 0;
v3 += 3;
}
while ( v3 != (_DWORD *)v4 );
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rcx
_DWORD *v3; // rax
__int64 v4; // rdx

if ( !a1 )
_assert_fail("spec != NULL", "port.c", 0xE3u, "yar_portspec_reset");
v1 = a1[2];
if ( !v1 )
_assert_fail("spec->ranges != NULL", "port.c", 0xE4u, "yar_portspec_reset");
v2 = *a1;
a1[1] = 0LL;
if ( v2 )
{
v3 = (_DWORD *)(v1 + 8);
v4 = v1 + 12 * v2 + 8;
do
{
*v3 = 0;
v3 += 3;
}
while ( v3 != (_DWORD *)v4 );
}
}

original_code:
void yar_portspec_reset(struct portspec_t *spec)
{
    size_t i;
    ((void) sizeof ((spec != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec != ((void *)0)) ; else __assert_fail ("spec != NULL", "port.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((spec->ranges != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec->ranges != ((void *)0)) ; else __assert_fail ("spec->ranges != NULL", "port.c", 228, __extension__ __PRETTY_FUNCTION__); }));
    spec->rangeix = 0;
    for(i=0; i<spec->nranges; i++) {
        spec->ranges[i].offset = 0;
    }
}

canonical_original_code:
void yar_portspec_reset(struct portspec_t *spec)
{
    unsigned long i;
    ((void) sizeof ((spec != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec != ((void *)0)) ; else __assert_fail ("spec != NULL", "port.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((spec->ranges != ((void *)0)) ? 1 : 0), __extension__ ({ if (spec->ranges != ((void *)0)) ; else __assert_fail ("spec->ranges != NULL", "port.c", 228, __extension__ __PRETTY_FUNCTION__); }));
    spec->rangeix = 0;
    for(i=0; i<spec->nranges; i++) {
        spec->ranges[i].offset = 0;
    }
}

variable_types:
i
unsigned long


decompiled_code:
void __fastcall yar_portspec_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void yar_portspec_free(struct portspec_t *spec)
{
    if (spec != ((void *)0)) {
        if (spec->ranges != ((void *)0)) {
            free(spec->ranges);
        }
        free(spec);
    }
}


decompiled_code:
bool __fastcall yar_portspec_is_expired(_QWORD *a1)
{
return a1[1] >= *a1;
}

canonical_decompiled_code:
bool __fastcall func7(_QWORD *a1)
{
return a1[1] >= *a1;
}

original_code:
_Bool yar_portspec_is_expired(struct portspec_t *spec)
{
    return (spec->rangeix < spec->nranges) ? 0 : 1;
}


GetType

repo: secmobi/android-utils

decompiled_code:
unsigned __int64 __fastcall GetType(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 64LL) <= a2 )
result = 0LL;
else
result = GetString(a1, *(_DWORD *)(a1[4] + 4LL * a2));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 64LL) <= a2 )
result = 0LL;
else
result = func0(a1, *(_DWORD *)(a1[4] + 4LL * a2));
return result;
}

original_code:
static char *
GetType(DexFile_t *dex, uint32_t idx)
{
 DexTypeId_t *id;
 if(idx >= dex->header->typeIdsSize)
  return ((void *)0);
 id = dex->typeIds + idx;
 return GetString(dex, id->descriptorIdx);
}

canonical_original_code:
static char *GetType(struct DexFile_t *dex, unsigned int idx)
{
 struct DexTypeId_t *id;
 if(idx >= dex->header->typeIdsSize)
  return ((void *)0);
 id = dex->typeIds + idx;
 return GetString(dex, id->descriptorIdx);
}

variable_types: struct DexFile_t { unsigned char *data; unsigned long len; struct DexHeader_t { unsigned char magic[8]; unsigned int checksum; unsigned char signature[20]; unsigned int fileSize; unsigned int headerSize; unsigned int endianTag; unsigned int linkSize; unsigned int linkOff; unsigned int mapOff; unsigned int stringIdsSize; unsigned int stringIdsOff; unsigned int typeIdsSize; unsigned int typeIdsOff; unsigned int protoIdsSize; unsigned int protoIdsOff; unsigned int fieldIdsSize; unsigned int fieldIdsOff; unsigned int methodIdsSize; unsigned int methodIdsOff; unsigned int classDefsSize; unsigned int classDefsOff; unsigned int dataSize; unsigned int dataOff; } *header; struct DexStringId_t { unsigned int stringDataOff; } *stringIds; struct DexTypeId_t { unsigned int descriptorIdx; } *typeIds; struct DexProtoId_t { unsigned int shortyIdx; unsigned int returnTypeIdx; unsigned int parametersOff; } *protoIds; struct DexFieldId_t { unsigned short classIdx; unsigned short typeIdx; unsigned int nameIdx; } *fieldIds; struct DexMethodId_t { unsigned short classIdx; unsigned short protoIdx; unsigned int nameIdx; } *methodIds; struct DexClassDef_t { unsigned int classIdx; unsigned int accessFlags; unsigned int superclassIdx; unsigned int interfacesOff; unsigned int sourceFileIdx; unsigned int annotationsOff; unsigned int classDataOff; unsigned int staticValuesOff; } *classDefs; struct DexLink_t { unsigned char bleargh; } *linkData; } *

variable_types:
idx
unsigned int

return_type: char *

user_defined_types: struct DexFile_t { unsigned char *data; unsigned long len; struct DexHeader_t *header; struct DexStringId_t *stringIds; struct DexTypeId_t *typeIds; struct DexProtoId_t *protoIds; struct DexFieldId_t *fieldIds; struct DexMethodId_t *methodIds; struct DexClassDef_t *classDefs; struct DexLink_t *linkData; }


GetProtoShorty

decompiled_code:
unsigned __int64 __fastcall GetProtoShorty(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) <= a2 )
result = 0LL;
else
result = GetString(a1, *(_DWORD *)(a1[5] + 12LL * a2));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) <= a2 )
result = 0LL;
else
result = func0(a1, *(_DWORD *)(a1[5] + 12LL * a2));
return result;
}

original_code:
static char *
GetProtoShorty(DexFile_t *dex, uint32_t idx)
{
 DexProtoId_t *id;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 return GetString(dex, id->shortyIdx);
}

canonical_original_code:
static char *GetProtoShorty(struct DexFile_t *dex, unsigned int idx)
{
 struct DexProtoId_t *id;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 return GetString(dex, id->shortyIdx);
}

variable_types: struct DexProtoId_t { unsigned int shortyIdx; unsigned int returnTypeIdx; unsigned int parametersOff; } *

user_defined_types: struct DexHeader_t { unsigned char magic[8]; unsigned int checksum; unsigned char signature[20]; unsigned int fileSize; unsigned int headerSize; unsigned int endianTag; unsigned int linkSize; unsigned int linkOff; unsigned int mapOff; unsigned int stringIdsSize; unsigned int stringIdsOff; unsigned int typeIdsSize; unsigned int typeIdsOff; unsigned int protoIdsSize; unsigned int protoIdsOff; unsigned int fieldIdsSize; unsigned int fieldIdsOff; unsigned int methodIdsSize; unsigned int methodIdsOff; unsigned int classDefsSize; unsigned int classDefsOff; unsigned int dataSize; unsigned int dataOff; }

user_defined_types: struct DexStringId_t { unsigned int stringDataOff; }

user_defined_types: struct DexTypeId_t { unsigned int descriptorIdx; }

user_defined_types: struct DexFieldId_t { unsigned short classIdx; unsigned short typeIdx; unsigned int nameIdx; }

user_defined_types: struct DexMethodId_t { unsigned short classIdx; unsigned short protoIdx; unsigned int nameIdx; }

user_defined_types: struct DexClassDef_t { unsigned int classIdx; unsigned int accessFlags; unsigned int superclassIdx; unsigned int interfacesOff; unsigned int sourceFileIdx; unsigned int annotationsOff; unsigned int classDataOff; unsigned int staticValuesOff; }

user_defined_types: struct DexLink_t { unsigned char bleargh; }


GetProtoReturnType

decompiled_code:
unsigned __int64 __fastcall GetProtoReturnType(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) <= a2 )
result = 0LL;
else
result = GetType(a1, *(_DWORD *)(a1[5] + 12LL * a2 + 4));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) <= a2 )
result = 0LL;
else
result = func1(a1, *(_DWORD *)(a1[5] + 12LL * a2 + 4));
return result;
}

original_code:
static char *
GetProtoReturnType(DexFile_t *dex, uint32_t idx)
{
 DexProtoId_t *id;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 return GetType(dex, id->returnTypeIdx);
}

canonical_original_code:
static char *GetProtoReturnType(struct DexFile_t *dex, unsigned int idx)
{
 struct DexProtoId_t *id;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 return GetType(dex, id->returnTypeIdx);
}

user_defined_types: struct DexProtoId_t { unsigned int shortyIdx; unsigned int returnTypeIdx; unsigned int parametersOff; }


GetProtoParameterCount

decompiled_code:
__int64 __fastcall GetProtoParameterCount(_QWORD *a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1[2] + 72LL) > a2 )
{
v3 = *(unsigned int *)(a1[5] + 12LL * a2 + 8);
result = v3;
if ( v3 >= a1[1] )
{
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)v3 )
{
result = *(unsigned int *)(*a1 + v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1[2] + 72LL) > a2 )
{
v3 = *(unsigned int *)(a1[5] + 12LL * a2 + 8);
result = v3;
if ( v3 >= a1[1] )
{
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)v3 )
{
result = *(unsigned int *)(*a1 + v3);
}
}
return result;
}

original_code:
static uint32_t
GetProtoParameterCount(DexFile_t *dex, uint32_t idx)
{
 DexProtoId_t *id;
 DexTypeList_t *para;
 if(idx >= dex->header->protoIdsSize)
  return -1;
 id = dex->protoIds + idx;
 if(id->parametersOff >= dex->len)
  return -1;
 if(id->parametersOff == 0)
  return 0;
 para = (DexTypeList_t *)(dex->data + id->parametersOff);
 return para->size;
}

canonical_original_code:
static unsigned int GetProtoParameterCount(struct DexFile_t *dex, unsigned int idx)
{
 struct DexProtoId_t *id;
 struct DexTypeList_t *para;
 if(idx >= dex->header->protoIdsSize)
  return -1;
 id = dex->protoIds + idx;
 if(id->parametersOff >= dex->len)
  return -1;
 if(id->parametersOff == 0)
  return 0;
 para = (struct DexTypeList_t *)(dex->data + id->parametersOff);
 return para->size;
}

variable_types: struct DexTypeList_t { unsigned int size; struct DexTypeItem_t { unsigned short typeIdx; } list[1]; } *

return_type: unsigned int

user_defined_types: struct DexTypeList_t { unsigned int size; struct DexTypeItem_t list[1]; }


GetProtoParameter

decompiled_code:
unsigned __int64 __fastcall GetProtoParameter(_QWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned __int64 v3; // rax
unsigned int *v4; // rax
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) > a2
&& (v3 = *(unsigned int *)(a1[5] + 12LL * a2 + 8), v3 < a1[1])
&& (_DWORD)v3
&& (v4 = (unsigned int *)(*a1 + v3), *v4 > a3) )
{
result = GetType(a1, *((unsigned __int16 *)v4 + a3 + 2));
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned __int64 v3; // rax
unsigned int *v4; // rax
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 72LL) > a2
&& (v3 = *(unsigned int *)(a1[5] + 12LL * a2 + 8), v3 < a1[1])
&& (_DWORD)v3
&& (v4 = (unsigned int *)(*a1 + v3), *v4 > a3) )
{
result = func1(a1, *((unsigned __int16 *)v4 + a3 + 2));
}
else
{
result = 0LL;
}
return result;
}

original_code:
static char *
GetProtoParameter(DexFile_t *dex, uint32_t idx, uint32_t n)
{
 DexProtoId_t *id;
 DexTypeList_t *para;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 if(id->parametersOff >= dex->len)
  return ((void *)0);
 if(id->parametersOff == 0)
  return ((void *)0);
 para = (DexTypeList_t *)(dex->data + id->parametersOff);
 if(n >= para->size)
  return ((void *)0);
 return GetType(dex, para->list[n].typeIdx);
}

canonical_original_code:
static char *GetProtoParameter(struct DexFile_t *dex, unsigned int idx, unsigned int n)
{
 struct DexProtoId_t *id;
 struct DexTypeList_t *para;
 if(idx >= dex->header->protoIdsSize)
  return ((void *)0);
 id = dex->protoIds + idx;
 if(id->parametersOff >= dex->len)
  return ((void *)0);
 if(id->parametersOff == 0)
  return ((void *)0);
 para = (struct DexTypeList_t *)(dex->data + id->parametersOff);
 if(n >= para->size)
  return ((void *)0);
 return GetType(dex, para->list[n].typeIdx);
}

variable_types:
n
unsigned int

user_defined_types: struct DexTypeItem_t { unsigned short typeIdx; }


GetFieldClass

decompiled_code:
unsigned __int64 __fastcall GetFieldClass(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 80LL) <= a2 )
result = 0LL;
else
result = GetType(a1, *(unsigned __int16 *)(a1[6] + 8LL * a2));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( *(_DWORD *)(a1[2] + 80LL) <= a2 )
result = 0LL;
else
result = func1(a1, *(unsigned __int16 *)(a1[6] + 8LL * a2));
return result;
}

original_code:
static char *
GetFieldClass(DexFile_t *dex, uint32_t idx)
{
 DexFieldId_t *id;
 if(idx >= dex->header->fieldIdsSize)
  return ((void *)0);
 id = dex->fieldIds + idx;
 return GetType(dex, id->classIdx);
}

canonical_original_code:
static char *GetFieldClass(struct DexFile_t *dex, unsigned int idx)
{
 struct DexFieldId_t *id;
 if(idx >= dex->header->fieldIdsSize)
  return ((void *)0);
 id = dex->fieldIds + idx;
 return GetType(dex, id->classIdx);
}

variable_types: struct DexFieldId_t { unsigned short classIdx; unsigned short typeIdx; unsigned int nameIdx; } *