getdirection

decompiled_code:
__int64 __fastcall getdirection(unsigned int a1, int a2, int a3)
{
__int64 result; // rax

switch ( a1 )
{
case 0xFFFFFFFF:
fwrite("moveball: still piece\n", 1uLL, 0x16uLL, stderr);
result = a1;
break;
case 0u:
result = 4LL;
break;
case 1u:
result = a3 == 0 ? 3 : 7;
break;
case 2u:
result = 6LL;
break;
case 3u:
result = a3 == 0 ? 1 : 5;
break;
case 4u:
result = 0LL;
break;
case 5u:
result = a2 == 0 ? 7 : 3;
break;
case 6u:
result = 2LL;
break;
case 7u:
result = a2 == 0 ? 5 : 1;
break;
default:
fwrite("moveball: bad direction\n", 1uLL, 0x18uLL, stderr);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0xFFFFFFFF:
fwrite("moveball: still piece\n", 1uLL, 0x16uLL, stderr);
result = a1;
break;
case 0u:
result = 4LL;
break;
case 1u:
result = a3 == 0 ? 3 : 7;
break;
case 2u:
result = 6LL;
break;
case 3u:
result = a3 == 0 ? 1 : 5;
break;
case 4u:
result = 0LL;
break;
case 5u:
result = a2 == 0 ? 7 : 3;
break;
case 6u:
result = 2LL;
break;
case 7u:
result = a2 == 0 ? 5 : 1;
break;
default:
fwrite("moveball: bad direction\n", 1uLL, 0x18uLL, stderr);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int getdirection(int d, int l, int r)
{
    switch (d) {
        case -1:
            fprintf(stderr, "moveball: still piece\n");
            break;
        case 0:
            return 4;
        case 1:
            if (r)
                return 7;
            return 3;
        case 2:
            return 6;
        case 3:
            if (r)
                return 5;
            return 1;
        case 4:
            return 0;
        case 5:
            if (l)
                return 3;
            return 7;
        case 6:
            return 2;
        case 7:
            if (l)
                return 1;
            return 5;
        default:
            fprintf(stderr, "moveball: bad direction\n");
    }
    return -1;
}

variable_types: d int

variable_types: l int

variable_types: r int


overlap

repo: khile/asciitennis

original_code:
int overlap(struct piece *ball, struct player *p)
{
    int b_min_y = ball->y;
    int b_max_y = b_min_y+ball->h;
    int p_min_y = p->p->y;
    int p_max_y = p_min_y+p->p->h;
    int b_min_x = ball->x;
    int b_max_x = b_min_x+ball->w;
    int p_min_x = p->p->x;
    if (p_min_x-b_max_x == -1) {
        if (p_max_y >= b_min_y && p_min_y <= b_max_y)
            return 1;
    }
    return 0;
}

variable_types: struct piece { int x; int y; int w; int h; short d; short c; } *

variable_types: struct player { int points; struct piece *p; } *

return_type: int


movepieces

original_code:
void movepieces(void)
{
    int i;
    int left, right, top, bottom;
    int ahit, bhit;
    struct piece *b = PIECE_PTR[0];
    int ball_y = (int)((float)b->y+((float)b->h/(float)2));
    int comp_y = (int)((float)PLAYER_B->p->y +
                 ((float)PLAYER_B->p->h/(float)2));
    int *comp_py = &PLAYER_B->p->y;
    for (i = 0; i < 1; i++) {
        b = PIECE_PTR[i];
        if (ball_y < comp_y)
            *comp_py -= 1;
        else if (ball_y > comp_y)
            *comp_py += 1;
        if ((*comp_py) < 0)
            *comp_py = 0;
        else if ((*comp_py)+PLAYER_B->p->h > HEIGHT)
            *comp_py = HEIGHT-PLAYER_B->p->h;
        switch (b->d) {
            case -1:
                break;
            case 0:
                b->y = (b->y)-1;
                break;
            case 1:
                b->x = (b->x)+1;
                b->y = (b->y)-1;
                break;
            case 2:
                b->x = (b->x)+1;
                break;
            case 3:
                b->x = (b->x)+1;
                b->y = (b->y)+1;
                break;
            case 4:
                b->y = (b->y)+1;
                break;
            case 5:
                b->x = (b->x)-1;
                b->y = (b->y)+1;
                break;
            case 6:
                b->x = (b->x)-1;
                break;
            case 7:
                b->x = (b->x)-1;
                b->y = (b->y)-1;
                break;
            default:
                fprintf(stderr, "movepieces: bad piece direction\n");
        }
        left = 0; right = 0; top = 0; bottom = 0;
        if (b->x < 0) {
            if (b->d < 5) {
                b->x -= 1;
                b->d += 4;
            } else {
                b->x += 1;
                b->d -= 4;
            }
        }
        if (b->x+b->w > WIDTH) {
            b->x = 10; b->y = 0;
            b->d = -1; b->c = 88;
            PLAYER_A->points += 1;
        }
        if (b->y < 0) {
            top = 1;
            b->y += 1;
        }
        if (b->y+b->h > HEIGHT) {
            bottom = 1;
            b->y -= 1;
        }
        if (left || right || top || bottom)
            b->d = getdirection(b->d, left, right);
        ahit = overlap(b, PLAYER_A);
        bhit = overlap(b, PLAYER_B);
        if (ahit) {
            b->x += 1;
            b->d -= 4;
        } else if (bhit) {
            b->x -= 1;
            b->d += 4;
        }
    }
}

canonical_original_code:
void movepieces()
{
    int i;
    int left; int right; int top; int bottom;
    int ahit; int bhit;
    struct piece *b = PIECE_PTR[0];
    int ball_y = (int)((float)b->y+((float)b->h/(float)2));
    int comp_y = (int)((float)PLAYER_B->p->y +
                 ((float)PLAYER_B->p->h/(float)2));
    int *comp_py = &PLAYER_B->p->y;
    for (i = 0; i < 1; i++) {
        b = PIECE_PTR[i];
        if (ball_y < comp_y)
            *comp_py -= 1;
        else if (ball_y > comp_y)
            *comp_py += 1;
        if ((*comp_py) < 0)
            *comp_py = 0;
        else if ((*comp_py)+PLAYER_B->p->h > HEIGHT)
            *comp_py = HEIGHT-PLAYER_B->p->h;
        switch (b->d) {
            case -1:
                break;
            case 0:
                b->y = (b->y)-1;
                break;
            case 1:
                b->x = (b->x)+1;
                b->y = (b->y)-1;
                break;
            case 2:
                b->x = (b->x)+1;
                break;
            case 3:
                b->x = (b->x)+1;
                b->y = (b->y)+1;
                break;
            case 4:
                b->y = (b->y)+1;
                break;
            case 5:
                b->x = (b->x)-1;
                b->y = (b->y)+1;
                break;
            case 6:
                b->x = (b->x)-1;
                break;
            case 7:
                b->x = (b->x)-1;
                b->y = (b->y)-1;
                break;
            default:
                fprintf(stderr, "movepieces: bad piece direction\n");
        }
        left = 0; right = 0; top = 0; bottom = 0;
        if (b->x < 0) {
            if (b->d < 5) {
                b->x -= 1;
                b->d += 4;
            } else {
                b->x += 1;
                b->d -= 4;
            }
        }
        if (b->x+b->w > WIDTH) {
            b->x = 10; b->y = 0;
            b->d = -1; b->c = 88;
            PLAYER_A->points += 1;
        }
        if (b->y < 0) {
            top = 1;
            b->y += 1;
        }
        if (b->y+b->h > HEIGHT) {
            bottom = 1;
            b->y -= 1;
        }
        if (left || right || top || bottom)
            b->d = getdirection(b->d, left, right);
        ahit = overlap(b, PLAYER_A);
        bhit = overlap(b, PLAYER_B);
        if (ahit) {
            b->x += 1;
            b->d -= 4;
        } else if (bhit) {
            b->x -= 1;
            b->d += 4;
        }
    }
}

variable_types: i int

variable_types: left int

variable_types: right int

variable_types: top int

variable_types: bottom int

variable_types: ahit int

variable_types: bhit int

return_type: void

user_defined_types: struct piece { int x; int y; int w; int h; short d; short c; }


getinput

decompiled_code:
__int64 getinput()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF
char buf[9]; // [rsp+3Fh] [rbp-9h] BYREF

buf[0] = 0;
*(_QWORD *)&v1.c_iflag = 0LL;
*(_QWORD *)&v1.c_cflag = 0LL;
*(_QWORD *)&v1.c_line = 0LL;
*(_QWORD *)&v1.c_cc[7] = 0LL;
*(_QWORD *)&v1.c_cc[15] = 0LL;
*(_QWORD *)&v1.c_cc[23] = 0LL;
*(_QWORD *)&v1.c_cc[31] = 0LL;
v1.c_ospeed = 0;
if ( tcgetattr(0, &v1) < 0 )
perror("tcsetattr()");
v1.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v1.c_cc[5] = 256;
if ( tcsetattr(0, 0, &v1) < 0 )
perror("tcsetattr ICANON");
if ( read(0, buf, 1uLL) < 0 )
perror("read()");
v1.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &v1) < 0 )
perror("tcsetattr ~ICANON");
return (unsigned __int8)buf[0];
}

canonical_decompiled_code:
__int64 func5()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF
char buf[9]; // [rsp+3Fh] [rbp-9h] BYREF

buf[0] = 0;
*(_QWORD *)&v1.c_iflag = 0LL;
*(_QWORD *)&v1.c_cflag = 0LL;
*(_QWORD *)&v1.c_line = 0LL;
*(_QWORD *)&v1.c_cc[7] = 0LL;
*(_QWORD *)&v1.c_cc[15] = 0LL;
*(_QWORD *)&v1.c_cc[23] = 0LL;
*(_QWORD *)&v1.c_cc[31] = 0LL;
v1.c_ospeed = 0;
if ( tcgetattr(0, &v1) < 0 )
perror("tcsetattr()");
v1.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v1.c_cc[5] = 256;
if ( tcsetattr(0, 0, &v1) < 0 )
perror("tcsetattr ICANON");
if ( read(0, buf, 1uLL) < 0 )
perror("read()");
v1.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &v1) < 0 )
perror("tcsetattr ~ICANON");
return (unsigned __int8)buf[0];
}

original_code:
char getinput(void)
{
    char buf = 0;
    struct termios old = {0};
    if (tcgetattr(0, &old) < 0)
            perror("tcsetattr()");
    old.c_lflag &= ~0000002;
    old.c_lflag &= ~0000010;
    old.c_cc[6] = 1;
    old.c_cc[5] = 0;
    if (tcsetattr(0, 0, &old) < 0)
        perror("tcsetattr ICANON");
    if (read(0, &buf, 1) < 0)
        perror ("read()");
    old.c_lflag |= 0000002;
    old.c_lflag |= 0000010;
    if (tcsetattr(0, 1, &old) < 0)
        perror ("tcsetattr ~ICANON");
    return (buf);
}

canonical_original_code:
char getinput()
{
    char buf = 0;
    struct termios old = {0};
    if (tcgetattr(0, &old) < 0)
            perror("tcsetattr()");
    old.c_lflag &= ~0000002;
    old.c_lflag &= ~0000010;
    old.c_cc[6] = 1;
    old.c_cc[5] = 0;
    if (tcsetattr(0, 0, &old) < 0)
        perror("tcsetattr ICANON");
    if (read(0, &buf, 1) < 0)
        perror ("read()");
    old.c_lflag |= 0000002;
    old.c_lflag |= 0000010;
    if (tcsetattr(0, 1, &old) < 0)
        perror ("tcsetattr ~ICANON");
    return (buf);
}

variable_types: buf char

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char


clear

decompiled_code:
void clear()
{
_WORD *v0; // rax
__int64 v1; // rdx

if ( HEIGHT * WIDTH > 0 )
{
v0 = (_WORD *)(BOARD + 8);
v1 = BOARD + 2LL * (unsigned int)(HEIGHT * WIDTH - 1) + 10;
do
{
if ( *v0 != 32 )
*v0 = 32;
++v0;
}
while ( v0 != (_WORD *)v1 );
}
}

canonical_decompiled_code:
void func6()
{
_WORD *v0; // rax
__int64 v1; // rdx

if ( HEIGHT * WIDTH > 0 )
{
v0 = (_WORD *)(BOARD + 8);
v1 = BOARD + 2LL * (unsigned int)(HEIGHT * WIDTH - 1) + 10;
do
{
if ( *v0 != 32 )
*v0 = 32;
++v0;
}
while ( v0 != (_WORD *)v1 );
}
}

original_code:
void clear(void)
{
    int i = 0;
    int size = WIDTH*HEIGHT;
    short int c = 32;
    while (i < size) {
        if (BOARD->board[i] != c)
            BOARD->board[i] = c;
        i++;
    }
}

canonical_original_code:
void clear()
{
    int i = 0;
    int size = WIDTH*HEIGHT;
    short c = 32;
    while (i < size) {
        if (BOARD->board[i] != c)
            BOARD->board[i] = c;
        i++;
    }
}

variable_types: size int

variable_types: c short


playgame

decompiled_code:
__int64 __fastcall playgame(int a1)
{
if ( !(FRAME_C % a1) )
movepieces();
return drawpieces();
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
if ( !(FRAME_C % a1) )
func4();
return func1();
}

original_code:
void playgame(int delay)
{
    if (FRAME_C % delay == 0)
        movepieces();
    drawpieces();
}

variable_types: delay int


refresh

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

v0 = HEIGHT * WIDTH;
putc(13, stdout);
if ( v0 > 45 )
{
v1 = v0 - 45;
v2 = 0;
do
putc(*(__int16 *)(BOARD + 2LL * v2++ + 8), stdout);
while ( v1 != v2 );
}
printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli", *(unsigned int *)PLAYER_A, *(unsigned int *)PLAYER_B, FRAME_C);
result = fflush(stdout);
++FRAME_C;
return result;
}

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

v0 = HEIGHT * WIDTH;
putc(13, stdout);
if ( v0 > 45 )
{
v1 = v0 - 45;
v2 = 0;
do
putc(*(__int16 *)(BOARD + 2LL * v2++ + 8), stdout);
while ( v1 != v2 );
}
printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli", *(unsigned int *)PLAYER_A, *(unsigned int *)PLAYER_B, FRAME_C);
result = fflush(stdout);
++FRAME_C;
return result;
}

original_code:
void refresh(void)
{
    int i;
    int size = WIDTH*HEIGHT;
    putc(13, stdout);
    for (i = 0; i < size-45; i++) {
        putc(BOARD->board[i], stdout);
    }
    printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli",
           PLAYER_A->points,
           PLAYER_B->points,
           FRAME_C);
    fflush(stdout);
    FRAME_C++;
}

canonical_original_code:
void refresh()
{
    int i;
    int size = WIDTH*HEIGHT;
    putc(13, stdout);
    for (i = 0; i < size-45; i++) {
        putc(BOARD->board[i], stdout);
    }
    printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli",
           PLAYER_A->points,
           PLAYER_B->points,
           FRAME_C);
    fflush(stdout);
    FRAME_C++;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned __int16 v4; // r12
unsigned __int16 v5; // bx
_DWORD *v6; // rax
int v7; // er12
__pid_t v8; // eax
int v9; // er13
__useconds_t v10; // ebx
char buf[2]; // [rsp+Ch] [rbp-DCh] BYREF
char v13[2]; // [rsp+Eh] [rbp-DAh] BYREF
int v14; // [rsp+10h] [rbp-D8h] BYREF
int *v15; // [rsp+18h] [rbp-D0h]
int v16; // [rsp+20h] [rbp-C8h] BYREF
int *v17; // [rsp+28h] [rbp-C0h]
int v18[4]; // [rsp+30h] [rbp-B8h] BYREF
__int16 v19; // [rsp+40h] [rbp-A8h]
__int16 v20; // [rsp+42h] [rbp-A6h]
int v21[4]; // [rsp+50h] [rbp-98h] BYREF
__int16 v22; // [rsp+60h] [rbp-88h]
__int16 v23; // [rsp+62h] [rbp-86h]
int v24[4]; // [rsp+70h] [rbp-78h] BYREF
__int16 v25; // [rsp+80h] [rbp-68h]
__int16 v26; // [rsp+82h] [rbp-66h]
int v27[4]; // [rsp+90h] [rbp-58h] BYREF
__int16 v28; // [rsp+A0h] [rbp-48h]
__int16 v29; // [rsp+A2h] [rbp-46h]
unsigned __int16 v30; // [rsp+ACh] [rbp-3Ch] BYREF
unsigned __int16 v31; // [rsp+AEh] [rbp-3Ah]
int pipedes[2]; // [rsp+B4h] [rbp-34h] BYREF
int stat_loc[11]; // [rsp+BCh] [rbp-2Ch] BYREF

if ( argc == 2 )
{
v3 = atoi(argv[1]);
if ( v3 <= 0 )
{
fwrite("args: invalid FPS argument\n", 1uLL, 0x1BuLL, stderr);
return -1;
}
}
else
{
v3 = 30;
if ( argc > 2 )
{
fwrite("args: incorrect number of arguments\n", 1uLL, 0x24uLL, stderr);
fprintf(
stdout,
" $ pong [fps]\n fps - A positive integer.\n%s%s",
" The game pong. If fps is not set then it run at ~30FPS.\n",
"Lower this value if things run too slowly.");
}
}
ioctl(1, 0x5413uLL, &v30);
v4 = v30;
v5 = v31;
v6 = malloc(2 * v31 * (unsigned __int64)v30 + 8);
if ( v6 )
{
*v6 = v5;
v6[1] = v4;
v27[0] = 0;
v27[1] = 0;
v27[2] = 2;
v27[3] = 6;
v28 = -1;
v29 = 35;
v24[0] = v5 - 2;
v24[1] = 0;
v24[2] = 2;
v24[3] = 6;
v25 = -1;
v26 = 35;
v21[0] = 11;
v21[1] = 12;
v21[2] = 1;
v21[3] = 1;
v22 = 5;
v23 = 48;
v18[0] = v5 >> 1;
v18[1] = 0;
v18[2] = 1;
v18[3] = v4;
v19 = -1;
v20 = 124;
v16 = 0;
v17 = v27;
v14 = 0;
v15 = v24;
WIDTH = v5;
HEIGHT = v4;
BOARD = (__int64)v6;
PIECE_PTR = (__int64)v21;
*(&PIECE_PTR + 1) = (__int64)v27;
*(&PIECE_PTR + 2) = (__int64)v24;
*(&PIECE_PTR + 3) = (__int64)v18;
PLAYER_A = (__int64)&v16;
PLAYER_B = (__int64)&v14;
FRAME_C = 0LL;
v7 = pipe2(pipedes, 2048);
if ( v7 )
{
perror("pipe2");
v9 = -1;
}
else
{
v8 = fork();
v9 = v8;
if ( v8 < 0 )
{
perror("fork");
exit(127);
}
v10 = (int)(float)(1000000.0 / (float)v3);
if ( v8 )
{
close(pipedes[1]);
v13[1] = 0;
while ( 1 )
{
clear();
playgame(5LL);
refresh();
v13[0] = 0;
read(pipedes[0], v13, 2uLL);
switch ( v13[0] )
{
case 'a':
--**(_DWORD **)(PLAYER_A + 8);
goto LABEL_18;
case 'd':
++**(_DWORD **)(PLAYER_A + 8);
goto LABEL_18;
case 'q':
waitpid(-1, stat_loc, 0);
return v7;
case 's':
++*(_DWORD *)(*(_QWORD *)(PLAYER_A + 8) + 4LL);
goto LABEL_18;
case 'w':
--*(_DWORD *)(*(_QWORD *)(PLAYER_A + 8) + 4LL);
goto LABEL_18;
default:
LABEL_18:
usleep(v10);
break;
}
}
}
buf[1] = 0;
close(pipedes[0]);
while ( 1 )
{
buf[0] = getinput();
write(pipedes[1], buf, 2uLL);
if ( buf[0] == 113 )
break;
usleep(v10);
}
}
}
else
{
fwrite("malloc: Could not allocate memory for board.\n", 1uLL, 0x2DuLL, stderr);
v9 = -1;
}
return v9;
}

original_code:
int
main(int argc, char **argv)
{
    int delay = 5;
    int status;
    int cpid;
    int pfd[2];
    int speed = 30;
    if (argc == 2) {
        speed = atoi(argv[1]);
        if (speed < 1) {
            fprintf(stderr, "args: invalid FPS argument\n");
            return -1;
        }
    } else if (argc > 2) {
        fprintf(stderr, "args: incorrect number of arguments\n");
        fprintf(stdout,
                "    $ pong [fps]\n fps - A positive integer.\n%s%s",
                "    The game pong. If fps is not set then it run at ~30FPS.\n",
                "Lower this value if things run too slowly.");
    }
    struct winsize w;
    ioctl(1, 0x5413, &w);
    struct board *b = malloc(
        sizeof(struct board)+(sizeof(short int)*w.ws_row*w.ws_col));
    if (b == ((void *)0)) {
        fprintf(stderr, "malloc: Could not allocate memory for board.\n");
        return -1;
    }
    b->w = w.ws_col;
    b->h = w.ws_row;
    struct piece playerA = {0, 0, 2, 6, -1, 35};
    struct piece playerB = {((b->w)-2), 0, 2, 6, -1, 35};
    struct piece ball = {11, 12, 1, 1, 5, 48};
    struct piece median = {b->w/2, 0, 1, b->h, -1, 124};
    struct player pa = {0, &playerA};
    struct player pb = {0, &playerB};
    WIDTH = b->w;
    HEIGHT = b->h;
    BOARD = b;
    PIECE_PTR[0] = &ball;
    PIECE_PTR[1] = &playerA;
    PIECE_PTR[2] = &playerB;
    PIECE_PTR[3] = &median;
    PLAYER_A = &pa;
    PLAYER_B = &pb;
    FRAME_C = 0;
    if (pipe2(pfd, 04000)) {
        perror("pipe2");
        return -1;
    }
    cpid = fork();
    if (cpid < 0) {
        perror("fork");
        exit(127);
    }
    speed = (int)((float)1000000/(float)speed);
    if (cpid == 0) {
        char buf[2];
        buf[1] = 0;
        close(pfd[0]);
        for (;;) {
            buf[0] = getinput();
            write(pfd[1], &buf, 2);
            if (buf[0] == 'q') {
                return 0;
            }
            usleep(speed);
        }
        return -1;
    }
    close(pfd[1]);
    char input[2];
    input[1] = 0;
    for(;;) {
        clear();
        playgame(delay);
        refresh();
        input[0] = 0;
        read(pfd[0], &input, 2);
        switch (input[0]) {
            case 'w':
                PLAYER_A->p->y -= 1;
                break;
            case 's':
                PLAYER_A->p->y += 1;
                break;
            case 'a':
                PLAYER_A->p->x -= 1;
                break;
            case 'd':
                PLAYER_A->p->x += 1;
                break;
            case 'q':
                waitpid(-1, &status, 0);
                return 0;
        }
        usleep(speed);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: status int

variable_types: cpid int

variable_types:
pfd
int [2]

variable_types: speed int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: struct board { int w; int h; short board[]; } *

variable_types: struct player { int points; struct piece { int x; int y; int w; int h; short d; short c; } *p; }

variable_types:
buf
char [2]

variable_types:
input
char [2]

user_defined_types: struct player { int points; struct piece *p; }


strlen

repo: kholia/dedrop

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !magicSpellCasted )
{
magicSpellCasted = 1;
pthread_create(&magicThread, 0LL, (void *(*)(void *))thread, (void *)"");
}
if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
__int64 result; // rax

if ( !magicSpellCasted )
{
magicSpellCasted = 1;
pthread_create(&magicThread, 0LL, (void *(*)(void *))thread, (void *)"");
}
if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

original_code:
size_t strlen(const char *s)
{
    size_t l = 0;
    if (!magicSpellCasted) {
        magicSpellCasted = 1;
        pthread_create(&magicThread, ((void *)0), thread, (void *) "");
    }
    while (*s++)
        l++;
    return l;
}

canonical_original_code:
unsigned long strlen(char *s)
{
    unsigned long l = 0;
    if (!magicSpellCasted) {
        magicSpellCasted = 1;
        pthread_create(&magicThread, ((void *)0), thread, (void *) "");
    }
    while (*s++)
        l++;
    return l;
}

variable_types:
s
char *

variable_types:
l
unsigned long

return_type: unsigned long


repo: kholia/passe-partout

original_code:
int dbg_maps_lookup(
     proc_t *p,
     int flags,
     const char *name,
     mapping_t ***mappings)
{
 int c;
 mapping_t **maps, *map, **bak;
 *mappings = ((void *)0);
 for (map=p->maps, c=0, maps=((void *)0); map; map=map->next) {
  if (flags && (map->flags != flags))
   continue;
  if (name && !strstr(map->name, name))
   continue;
  if (0) {
  fprintf(stderr, "==> %s %s %s\n", map->name, name,
    strstr(map->name, name) ?
    strstr(map->name, name) : "NULL");
 }
  bak = maps;
  maps = realloc(maps, (c+1)*sizeof(mapping_t *));
  if (!maps) {
   if (bak)
    free(bak);
   return -2;;
  }
  maps[c] = map;
  ++c;
 }
 *mappings = maps;
 return c;
}

canonical_original_code:
int dbg_maps_lookup(struct _proc *p, int flags, char *name, struct _mapping ***mappings)
{
 int c;
 struct _mapping **maps; struct _mapping *map; struct _mapping **bak;
 *mappings = ((void *)0);
 for (map=p->maps, c=0, maps=((void *)0); map; map=map->next) {
  if (flags && (map->flags != flags))
   continue;
  if (name && !strstr(map->name, name))
   continue;
  if (0) {
  fprintf(stderr, "==> %s %s %s\n", map->name, name,
    strstr(map->name, name) ?
    strstr(map->name, name) : "NULL");
 }
  bak = maps;
  maps = realloc(maps, (c+1)*sizeof(struct _mapping *));
  if (!maps) {
   if (bak)
    free(bak);
   return -2;;
  }
  maps[c] = map;
  ++c;
 }
 *mappings = maps;
 return c;
}

variable_types: struct _proc { int pid; int flags; struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; } *maps; char pid_str[8]; } *

variable_types: flags int

variable_types:
name
char *

variable_types:
mappings
struct _mapping ***

variable_types: c int

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } **


decompiled_code:
__int64 __fastcall dbg_map_lookup(__int64 a1, int a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // rbx
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v3 = (unsigned int)dbg_maps_lookup(a1, a2, a3, &ptr);
fprintf(stderr, "retcount: %i\n", v3);
if ( (_DWORD)v3 == 1 )
{
v4 = *(_QWORD *)ptr;
}
else
{
if ( (int)v3 <= 0 )
return 0LL;
v4 = 0LL;
}
free(ptr);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // rbx
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v3 = (unsigned int)func1(a1, a2, a3, &ptr);
fprintf(stderr, "retcount: %i\n", v3);
if ( (_DWORD)v3 == 1 )
{
v4 = *(_QWORD *)ptr;
}
else
{
if ( (int)v3 <= 0 )
return 0LL;
v4 = 0LL;
}
free(ptr);
return v4;
}

original_code:
mapping_t *dbg_map_lookup(proc_t *p, int flags, const char *name)
{
 int ret;
 mapping_t **maps, *map;
 ret = dbg_maps_lookup(p, flags, name, &maps);
 fprintf(stderr, "retcount: %i\n", ret);
 map = (ret == 1 ? *maps : ((void *)0));
 if (ret > 0)
  free(maps);
 return map;
}

canonical_original_code:
struct _mapping *dbg_map_lookup(struct _proc *p, int flags, char *name)
{
 int ret;
 struct _mapping **maps; struct _mapping *map;
 ret = dbg_maps_lookup(p, flags, name, &maps);
 fprintf(stderr, "retcount: %i\n", ret);
 map = (ret == 1 ? *maps : ((void *)0));
 if (ret > 0)
  free(maps);
 return map;
}

variable_types:
p
struct _proc *

variable_types: ret int

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *

user_defined_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; }


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

result = dbg_map_lookup(a1, 3, "[stack]");
if ( !result )
result = dbg_map_lookup(a1, 7, "[stack]");
return result;
}

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

result = func2(a1, 3, "[stack]");
if ( !result )
result = func2(a1, 7, "[stack]");
return result;
}

original_code:
mapping_t *dbg_map_get_stack(proc_t *p)
{
 mapping_t *map;
 map = dbg_map_lookup(p, 1|2, "[stack]");
 if (!map)
  map = dbg_map_lookup(p, 1|2|4, "[stack]");
 return map;
}

canonical_original_code:
struct _mapping *dbg_map_get_stack(struct _proc *p)
{
 struct _mapping *map;
 map = dbg_map_lookup(p, 1|2, "[stack]");
 if (!map)
  map = dbg_map_lookup(p, 1|2|4, "[stack]");
 return map;
}

return_type: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *


decompiled_code:
__int64 __fastcall dbg_init(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
int i; // ebx
struct sigaction v5; // [rsp+0h] [rbp-B8h] BYREF

if ( ptraced_proc )
return (unsigned int)-7;
if ( !a2 )
return (unsigned int)-3;
if ( getpid() == a2 )
return (unsigned int)-3;
if ( getppid() == a2 )
return (unsigned int)-3;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)a1 = a2;
snprintf((char *)(a1 + 16), 8uLL, "%u", a2);
ptraced_proc = a1;
v2 = parse_maps(a1);
if ( v2 )
{
ptraced_proc = 0LL;
}
else
{
memset(&v5.sa_mask, 0, 0x90uLL);
for ( i = 1; i != 64; ++i )
{
while ( 1 )
{
v5.sa_flags = 4;
v5.sa_handler = (__sighandler_t)killme;
if ( i != 9 && i != 19 )
break;
++i;
}
sigaction(i, &v5, 0LL);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
int i; // ebx
struct sigaction v5; // [rsp+0h] [rbp-B8h] BYREF

if ( ptraced_proc )
return (unsigned int)-7;
if ( !a2 )
return (unsigned int)-3;
if ( getpid() == a2 )
return (unsigned int)-3;
if ( getppid() == a2 )
return (unsigned int)-3;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)a1 = a2;
snprintf((char *)(a1 + 16), 8uLL, "%u", a2);
ptraced_proc = a1;
v2 = func0(a1);
if ( v2 )
{
ptraced_proc = 0LL;
}
else
{
memset(&v5.sa_mask, 0, 0x90uLL);
for ( i = 1; i != 64; ++i )
{
while ( 1 )
{
v5.sa_flags = 4;
v5.sa_handler = (__sighandler_t)killme;
if ( i != 9 && i != 19 )
break;
++i;
}
sigaction(i, &v5, 0LL);
}
}
return v2;
}

original_code:
int dbg_init(proc_t *p, pid_t pid)
{
 int ret;
 unsigned int i;
 struct sigaction sa;
 if (ptraced_proc)
  return -7;
 if (!pid || (pid == getpid()) || (pid == getppid()))
  return -3;
 memset(p, 0, sizeof(*p));
 p->pid = pid;
 snprintf(p->pid_str, 8, "%u", pid);
 ptraced_proc = p;
 ret = parse_maps(p);
 if (ret) {
  ptraced_proc = ((void *)0);
  return ret;
 }
 memset(&sa, 0, sizeof(sa));
 for (i=1; i<(64 + 1)-1; ++i) {
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = killme;
  switch (i) {
   case 9:
   case 19:
    break;
   default:
    sigaction(i, &sa, ((void *)0));
  }
 }
 return 0;
}

canonical_original_code:
int dbg_init(struct _proc *p, int pid)
{
 int ret;
 unsigned int i;
 struct sigaction sa;
 if (ptraced_proc)
  return -7;
 if (!pid || (pid == getpid()) || (pid == getppid()))
  return -3;
 memset(p, 0, sizeof(*p));
 p->pid = pid;
 snprintf(p->pid_str, 8, "%u", pid);
 ptraced_proc = p;
 ret = parse_maps(p);
 if (ret) {
  ptraced_proc = ((void *)0);
  return ret;
 }
 memset(&sa, 0, sizeof(sa));
 for (i=1; i<(64 + 1)-1; ++i) {
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = killme;
  switch (i) {
   case 9:
   case 19:
    break;
   default:
    sigaction(i, &sa, ((void *)0));
  }
 }
 return 0;
}

variable_types: pid int

variable_types:
i
unsigned int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
void __fastcall dbg_exit(_QWORD *a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp
void *v4; // rdi

v2 = (_QWORD *)a1[1];
if ( v2 )
{
while ( 1 )
{
v4 = (void *)v2[5];
if ( v4 )
free(v4);
v3 = (_QWORD *)*v2;
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp
void *v4; // rdi

v2 = (_QWORD *)a1[1];
if ( v2 )
{
while ( 1 )
{
v4 = (void *)v2[5];
if ( v4 )
free(v4);
v3 = (_QWORD *)*v2;
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

original_code:
void dbg_exit(proc_t *p)
{
 mapping_t *tmp, *next;
 for (tmp=p->maps; tmp; tmp=next) {
  if (tmp->data)
   free(tmp->data);
  next = tmp->next;
  free(tmp);
 }
 memset(p, 0, sizeof(*p));
}

canonical_original_code:
void dbg_exit(struct _proc *p)
{
 struct _mapping *tmp; struct _mapping *next;
 for (tmp=p->maps; tmp; tmp=next) {
  if (tmp->data)
   free(tmp->data);
  next = tmp->next;
  free(tmp);
 }
 memset(p, 0, sizeof(*p));
}


decompiled_code:
int __fastcall dbg_detach(unsigned int *a1)
{
int result; // eax

if ( (a1[1] & 1) != 0 )
{
result = ptrace(PTRACE_DETACH, *a1, 0LL, 0LL);
a1[1] &= 0xFFFFFFFE;
if ( dbg_verbose )
result = fprintf(stdout, "dbg: detached from process %u\n", *a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
int result; // eax

if ( (a1[1] & 1) != 0 )
{
result = ptrace(PTRACE_DETACH, *a1, 0LL, 0LL);
a1[1] &= 0xFFFFFFFE;
if ( dbg_verbose )
result = fprintf(stdout, "dbg: detached from process %u\n", *a1);
}
return result;
}

original_code:
void dbg_detach(proc_t *p)
{
 if (p->flags & 1) {
  ptrace(PTRACE_DETACH, p->pid, 0, 0);
  p->flags &= ~1;
  if (dbg_verbose)
   fprintf(stdout, "dbg: detached from process %u\n", p->pid);
 }
}

canonical_original_code:
void dbg_detach(struct _proc *p)
{
 if (p->flags & 1) {
  ptrace(PTRACE_DETACH, p->pid, 0, 0);
  p->flags &= ~1;
  if (dbg_verbose)
   fprintf(stdout, "dbg: detached from process %u\n", p->pid);
 }
}


killme

decompiled_code:
int __fastcall killme(int a1, __int64 a2)
{
int result; // eax

if ( a1 != 17 )
{
dbg_detach((unsigned int *)ptraced_proc);
ptraced_proc = 0LL;
fwrite("killed\n", 1uLL, 7uLL, stderr);
exit(0);
}
if ( dbg_verbose )
result = fprintf(stderr, "dbg: attached to process %u\n", *(unsigned int *)(a2 + 16));
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
int result; // eax

if ( a1 != 17 )
{
func6((unsigned int *)ptraced_proc);
ptraced_proc = 0LL;
fwrite("killed\n", 1uLL, 7uLL, stderr);
exit(0);
}
if ( dbg_verbose )
result = fprintf(stderr, "dbg: attached to process %u\n", *(unsigned int *)(a2 + 16));
return result;
}

original_code:
static void killme(int sig, siginfo_t *si, void *bla)
{
 if (sig == 17) {
  if (dbg_verbose)
   fprintf(stderr, "dbg: attached to process %u\n", si->_sifields._kill.si_pid);
  return;
 }
 dbg_detach(ptraced_proc);
 ptraced_proc = ((void *)0);
 fprintf(stderr, "killed\n");
 exit(0);
}

canonical_original_code:
static void killme(int sig, struct siginfo_t *si, void *bla)
{
 if (sig == 17) {
  if (dbg_verbose)
   fprintf(stderr, "dbg: attached to process %u\n", si->_sifields._kill.si_pid);
  return;
 }
 dbg_detach(ptraced_proc);
 ptraced_proc = ((void *)0);
 fprintf(stderr, "killed\n");
 exit(0);
}

variable_types: sig int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
bla
void *


decompiled_code:
__int64 __fastcall dbg_attach(unsigned int *a1)
{
unsigned int v1; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1[1] & 1;
if ( v1 )
return (unsigned int)-5;
a1[1] |= 1u;
if ( ptrace(PTRACE_ATTACH, *a1, 0LL, 0LL) )
{
a1[1] &= 0xFFFFFFFE;
v1 = -4;
if ( *_errno_location() != 1 )
{
perror("ptrace");
v1 = -1;
}
}
else
{
alarm(5u);
wait((__WAIT_STATUS)&stat_loc);
alarm(0);
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
dbg_detach(a1);
v1 = -6;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
unsigned int v1; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1[1] & 1;
if ( v1 )
return (unsigned int)-5;
a1[1] |= 1u;
if ( ptrace(PTRACE_ATTACH, *a1, 0LL, 0LL) )
{
a1[1] &= 0xFFFFFFFE;
v1 = -4;
if ( *_errno_location() != 1 )
{
perror("ptrace");
v1 = -1;
}
}
else
{
alarm(5u);
wait((__WAIT_STATUS)&stat_loc);
alarm(0);
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
func6(a1);
v1 = -6;
}
}
return v1;
}

original_code:
int dbg_attach(proc_t *p, int mode)
{
 int status;
 if (p->flags & 1)
  return -5;
 p->flags |= 1;
 if (ptrace(PTRACE_ATTACH, p->pid, 0, 0)) {
  p->flags &= ~1;
  if ((*__errno_location ()) == 1)
   return -4;
  perror("ptrace");
  return -1;
 }
 alarm(5);
 wait(&status);
 alarm(0);
 if (!(((status) & 0xff) == 0x7f)) {
  dbg_detach(p);
  return -6;
 }
 return 0;
}

canonical_original_code:
int dbg_attach(struct _proc *p, int mode)
{
 int status;
 if (p->flags & 1)
  return -5;
 p->flags |= 1;
 if (ptrace(PTRACE_ATTACH, p->pid, 0, 0)) {
  p->flags &= ~1;
  if ((*__errno_location ()) == 1)
   return -4;
  perror("ptrace");
  return -1;
 }
 alarm(5);
 wait(&status);
 alarm(0);
 if (!(((status) & 0xff) == 0x7f)) {
  dbg_detach(p);
  return -6;
 }
 return 0;
}

variable_types: mode int

variable_types: status int


decompiled_code:
__int64 __fastcall dbg_get_regs(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_GETREGS, *a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_GETREGS, *a1, 0LL, a2);
}

original_code:
int dbg_get_regs(proc_t *p, void *regs)
{
 return ptrace(PTRACE_GETREGS, p->pid, ((void *)0), regs);
}

canonical_original_code:
int dbg_get_regs(struct _proc *p, void *regs)
{
 return ptrace(PTRACE_GETREGS, p->pid, ((void *)0), regs);
}

variable_types: struct _proc { int pid; int flags; struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; } *maps; char pid_str[8]; } *

variable_types:
regs
void *


decompiled_code:
__int64 __fastcall dbg_set_regs(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_SETREGS, *a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_SETREGS, *a1, 0LL, a2);
}

original_code:
int dbg_set_regs(proc_t *p, const void *regs)
{
 return ptrace(PTRACE_SETREGS, p->pid, ((void *)0), regs);
}

canonical_original_code:
int dbg_set_regs(struct _proc *p, void *regs)
{
 return ptrace(PTRACE_SETREGS, p->pid, ((void *)0), regs);
}


decompiled_code:
__int64 __fastcall dbg_continue(unsigned int *a1)
{
return ptrace(PTRACE_CONT, *a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1)
{
return ptrace(PTRACE_CONT, *a1, 0LL, 0LL);
}

original_code:
int dbg_continue(proc_t *p)
{
 return ptrace(PTRACE_CONT, p->pid, ((void *)0), ((void *)0));
}

canonical_original_code:
int dbg_continue(struct _proc *p)
{
 return ptrace(PTRACE_CONT, p->pid, ((void *)0), ((void *)0));
}


decompiled_code:
char *__fastcall dbg_get_binpath(__int64 a1)
{
char *v1; // rbx
size_t v2; // rbp
size_t v3; // r12
char *v4; // r13
char *v5; // rax
ssize_t v6; // rax
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

snprintf(v8, 0x3FuLL, "/proc/%s/exe", (const char *)(a1 + 16));
v8[63] = 0;
v1 = 0LL;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
v2 += 256LL;
v4 = v1;
v5 = (char *)realloc(v1, v2);
v1 = v5;
if ( !v5 )
break;
v6 = readlink(v8, v5, v3 + 255);
if ( v6 > 0 )
{
v1[v6] = 0;
return v1;
}
if ( *_errno_location() != 36 )
return 0LL;
}
if ( !v4 )
return 0LL;
free(v4);
return v1;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1)
{
char *v1; // rbx
size_t v2; // rbp
size_t v3; // r12
char *v4; // r13
char *v5; // rax
ssize_t v6; // rax
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

snprintf(v8, 0x3FuLL, "/proc/%s/exe", (const char *)(a1 + 16));
v8[63] = 0;
v1 = 0LL;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
v2 += 256LL;
v4 = v1;
v5 = (char *)realloc(v1, v2);
v1 = v5;
if ( !v5 )
break;
v6 = readlink(v8, v5, v3 + 255);
if ( v6 > 0 )
{
v1[v6] = 0;
return v1;
}
if ( *_errno_location() != 36 )
return 0LL;
}
if ( !v4 )
return 0LL;
free(v4);
return v1;
}

original_code:
char *dbg_get_binpath(proc_t *p)
{
 ssize_t ret;
 size_t len;
 char *bak, *real_path, path[64];
 snprintf(path, 63, "/proc/%s/exe", p->pid_str);
 path[63] = 0;
 len = 0;
 real_path = ((void *)0);
 do {
  bak = real_path;
  real_path = realloc(real_path, len+256);
  if (!real_path) {
   if (bak)
    free(bak);
   return ((void *)0);
  }
  len += 256;
  ret = readlink(path, real_path, len-1);
  if (ret > 0) {
   real_path[ret] = 0;
   return real_path;
  }
 } while ((*__errno_location ()) == 36);
 return ((void *)0);
}

canonical_original_code:
char *dbg_get_binpath(struct _proc *p)
{
 long ret;
 unsigned long len;
 char *bak; char *real_path; char path[64];
 snprintf(path, 63, "/proc/%s/exe", p->pid_str);
 path[63] = 0;
 len = 0;
 real_path = ((void *)0);
 do {
  bak = real_path;
  real_path = realloc(real_path, len+256);
  if (!real_path) {
   if (bak)
    free(bak);
   return ((void *)0);
  }
  len += 256;
  ret = readlink(path, real_path, len-1);
  if (ret > 0) {
   real_path[ret] = 0;
   return real_path;
  }
 } while ((*__errno_location ()) == 36);
 return ((void *)0);
}

variable_types: ret long

variable_types:
len
unsigned long

variable_types:
bak
char *

variable_types:
path
char [64]

return_type: char *


decompiled_code:
__int64 __fastcall dbg_read(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
int *v6; // r12
__int64 v7; // rbx
__int64 v8; // rax

if ( !a4 )
return 0LL;
v6 = _errno_location();
v7 = 0LL;
while ( 1 )
{
*v6 = 0;
v8 = ptrace(PTRACE_PEEKDATA, *a1, a2 + (unsigned int)v7, 1LL);
if ( v8 == -1 )
{
if ( *v6 )
break;
}
*(_QWORD *)(a3 + v7) = v8;
v7 += 8LL;
if ( a4 <= (unsigned int)v7 )
return 0LL;
}
fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", a2 + (unsigned int)v7);
if ( *v6 == 3 )
fwrite("ptrace: access denied or process has terminated\n", 1uLL, 0x30uLL, stderr);
else
perror("ptrace");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
int *v6; // r12
__int64 v7; // rbx
__int64 v8; // rax

if ( !a4 )
return 0LL;
v6 = _errno_location();
v7 = 0LL;
while ( 1 )
{
*v6 = 0;
v8 = ptrace(PTRACE_PEEKDATA, *a1, a2 + (unsigned int)v7, 1LL);
if ( v8 == -1 )
{
if ( *v6 )
break;
}
*(_QWORD *)(a3 + v7) = v8;
v7 += 8LL;
if ( a4 <= (unsigned int)v7 )
return 0LL;
}
fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", a2 + (unsigned int)v7);
if ( *v6 == 3 )
fwrite("ptrace: access denied or process has terminated\n", 1uLL, 0x30uLL, stderr);
else
perror("ptrace");
return 0xFFFFFFFFLL;
}

original_code:
int dbg_read(proc_t *p, xaddr_t addr, void *buf, unsigned int size)
{
  unsigned int i;
  long ret, *out;
  for (i=0, out=(long*)buf; i<size; i+=sizeof(long), ++out) {
    (*__errno_location ()) = 0;
    ret = ptrace(PTRACE_PEEKDATA, p->pid, addr+i, 1);
    if ((ret == -1) && (*__errno_location ())) {
      fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", addr+i);
      if ((*__errno_location ()) == 3) {
        fprintf(stderr,
            "ptrace: access denied or process has terminated\n");
      } else {
        perror("ptrace");
      }
      return -1;
    }
    *out = ret;
  }
  return 0;
}

canonical_original_code:
int dbg_read(struct _proc *p, unsigned long addr, void *buf, unsigned int size)
{
  unsigned int i;
  long ret; long *out;
  for (i=0, out=(long *)buf; i<size; i+=sizeof(long), ++out) {
    (*__errno_location ()) = 0;
    ret = ptrace(PTRACE_PEEKDATA, p->pid, addr+i, 1);
    if ((ret == -1) && (*__errno_location ())) {
      fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", addr+i);
      if ((*__errno_location ()) == 3) {
        fprintf(stderr,
            "ptrace: access denied or process has terminated\n");
      } else {
        perror("ptrace");
      }
      return -1;
    }
    *out = ret;
  }
  return 0;
}

variable_types:
addr
unsigned long

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types:
out
long *


decompiled_code:
__int64 __fastcall dbg_map_cache(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v3; // ebp
void *v4; // rax
void *v5; // r12

v1 = 1;
if ( !*(_QWORD *)(a1 + 40) )
{
v3 = *(_DWORD *)(a1 + 16);
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
v1 = dbg_read(*(unsigned int **)(a1 + 32), *(_QWORD *)(a1 + 8), (__int64)v4, v3);
if ( v1 )
{
fprintf(stderr, "error: failed to read %u bytes\n", *(unsigned int *)(a1 + 16));
free(v5);
}
else
{
*(_QWORD *)(a1 + 40) = v5;
}
}
else
{
fprintf(stderr, "error: failed to alloc %u bytes\n", v3);
v1 = -2;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v3; // ebp
void *v4; // rax
void *v5; // r12

v1 = 1;
if ( !*(_QWORD *)(a1 + 40) )
{
v3 = *(_DWORD *)(a1 + 16);
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
v1 = func13(*(unsigned int **)(a1 + 32), *(_QWORD *)(a1 + 8), (__int64)v4, v3);
if ( v1 )
{
fprintf(stderr, "error: failed to read %u bytes\n", *(unsigned int *)(a1 + 16));
free(v5);
}
else
{
*(_QWORD *)(a1 + 40) = v5;
}
}
else
{
fprintf(stderr, "error: failed to alloc %u bytes\n", v3);
v1 = -2;
}
}
return v1;
}

original_code:
int dbg_map_cache(mapping_t *map)
{
 void *buf;
 int ret;
 if (map->data)
  return 1;
 buf = malloc(map->size);
 if (!buf) {
  fprintf(stderr, "error: failed to alloc %u bytes\n", map->size);
  return -2;;
 }
 ret = dbg_read(map->proc, map->address, buf, map->size);
 if (!ret) {
  map->data = buf;
 } else {
  fprintf(stderr, "error: failed to read %u bytes\n", map->size);
  free(buf);
 }
 return ret;
}

canonical_original_code:
int dbg_map_cache(struct _mapping *map)
{
 void *buf;
 int ret;
 if (map->data)
  return 1;
 buf = malloc(map->size);
 if (!buf) {
  fprintf(stderr, "error: failed to alloc %u bytes\n", map->size);
  return -2;;
 }
 ret = dbg_read(map->proc, map->address, buf, map->size);
 if (!ret) {
  map->data = buf;
 } else {
  fprintf(stderr, "error: failed to read %u bytes\n", map->size);
  free(buf);
 }
 return ret;
}

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall dbg_read_ptr(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( (*(_BYTE *)(a1 + 4) & 1) != 0 )
result = dbg_read((unsigned int *)a1, a2, a3, 8u);
else
result = 4294967274LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( (*(_BYTE *)(a1 + 4) & 1) != 0 )
result = func13((unsigned int *)a1, a2, a3, 8u);
else
result = 4294967274LL;
return result;
}

original_code:
int dbg_read_ptr(proc_t *p, xaddr_t addr, xaddr_t *v)
{
 if (!(p->flags & 1))
  return -22;
 return dbg_read(p, addr, v, sizeof(*v));
}

canonical_original_code:
int dbg_read_ptr(struct _proc *p, unsigned long addr, unsigned long *v)
{
 if (!(p->flags & 1))
  return -22;
 return dbg_read(p, addr, v, sizeof(*v));
}

variable_types:
v
unsigned long *


decompiled_code:
__int64 __fastcall dbg_get_memory(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
if ( (*(_DWORD *)(v1 + 20) & 0xB) == 3 && (unsigned int)dbg_map_cache(v1) )
{
fprintf(stderr, "error reading %d bytes at %p\n", *(unsigned int *)(v1 + 16), *(const void **)(v1 + 8));
v2 = 1;
}
v1 = *(_QWORD *)v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
if ( (*(_DWORD *)(v1 + 20) & 0xB) == 3 && (unsigned int)func14(v1) )
{
fprintf(stderr, "error reading %d bytes at %p\n", *(unsigned int *)(v1 + 16), *(const void **)(v1 + 8));
v2 = 1;
}
v1 = *(_QWORD *)v1;
}
while ( v1 );
return v2;
}

original_code:
int dbg_get_memory(proc_t *p) {
    mapping_t * map;
    int error = 0;
    for (map=(p)->maps; map; map=map->next) {
        if (((map->flags & (1|2)) != (1|2))
  || (map->flags & 8))
            continue;
 if (dbg_map_cache(map)) {
            fprintf(stderr, "error reading %d bytes at %p\n", map->size, (void *)map->address);
     error = 1;
 }
    }
   return error;
}

canonical_original_code:
int dbg_get_memory(struct _proc *p) {
    struct _mapping *map;
    int error = 0;
    for (map=(p)->maps; map; map=map->next) {
        if (((map->flags & (1|2)) != (1|2))
  || (map->flags & 8))
            continue;
 if (dbg_map_cache(map)) {
            fprintf(stderr, "error reading %d bytes at %p\n", map->size, (void *)map->address);
     error = 1;
 }
    }
   return error;
}

variable_types: error int


repo: kichiki/WaoN

decompiled_code:
size_t print_pv_version()
{
fprintf(stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n", "0.11");
fwrite("Copyright (C) 1998-2013 Kengo Ichiki <kengoichiki@gmail.com>\n", 1uLL, 0x3DuLL, stdout);
return fwrite("Web: http://kichiki.github.com/WaoN//\n\n", 1uLL, 0x27uLL, stdout);
}

canonical_decompiled_code:
size_t func0()
{
fprintf(stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n", "0.11");
fwrite("Copyright (C) 1998-2013 Kengo Ichiki <kengoichiki@gmail.com>\n", 1uLL, 0x3DuLL, stdout);
return fwrite("Web: http://kichiki.github.com/WaoN//\n\n", 1uLL, 0x27uLL, stdout);
}

original_code:
void print_pv_version (void)
{
  fprintf (stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n",
    "0.11");
  fprintf (stdout, "Copyright (C) 1998-2013 Kengo Ichiki "
    "<kengoichiki@gmail.com>\n");
  fprintf (stdout, "Web: http://kichiki.github.com/WaoN//\n\n");
}

canonical_original_code:
void print_pv_version()
{
  fprintf (stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n",
    "0.11");
  fprintf (stdout, "Copyright (C) 1998-2013 Kengo Ichiki "
    "<kengoichiki@gmail.com>\n");
  fprintf (stdout, "Web: http://kichiki.github.com/WaoN//\n\n");
}


decompiled_code:
size_t __fastcall print_pv_usage(const char *a1)
{
print_pv_version();
fwrite(
"WaoN-pv is yet-another phase vocoder, with which you can do time-strech \nand pitch-shift a sound file.\n\n",
1uLL,
0x68uLL,
stdout);
fprintf(stdout, "Usage: %s [option ...]\n\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h, --help\tprint this help.\n", 1uLL, 0x1EuLL, stdout);
fwrite(" -v, --version\tprint version information.\n", 1uLL, 0x2BuLL, stdout);
fwrite("OPTIONS FOR FILES\n", 1uLL, 0x12uLL, stdout);
fwrite(" -i, --input\tinput file (default: stdin)\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -o, --output\toutput file in flac (default: play audio by ao)\n", 1uLL, 0x3FuLL, stdout);
fwrite("FFT OPTIONS\n", 1uLL, 0xCuLL, stdout);
fwrite(" -n \tFFT data number (default: 2048)\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -w --window\t0 no window\n", 1uLL, 0x1AuLL, stdout);
fwrite("\t\t1 parzen window\n", 1uLL, 0x12uLL, stdout);
fwrite("\t\t2 welch window\n", 1uLL, 0x11uLL, stdout);
fwrite("\t\t3 hanning window (default)\n", 1uLL, 0x1DuLL, stdout);
fwrite("\t\t4 hamming window\n", 1uLL, 0x13uLL, stdout);
fwrite("\t\t5 blackman window\n", 1uLL, 0x14uLL, stdout);
fwrite("\t\t6 steeper 30-dB/octave rolloff window\n", 1uLL, 0x28uLL, stdout);
fwrite("PHASE-VOCODER OPTIONS\n", 1uLL, 0x16uLL, stdout);
fwrite(" -hop \thop number (default: 512)\n", 1uLL, 0x28uLL, stdout);
fwrite(" -rate \tsynthesize rate; larger is faster (default: 1.0)\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -pitch\tpitch shift. +1/-1 is half-note up/down (default: 0)\n", 1uLL, 0x3EuLL, stdout);
fwrite(" -scheme \tgive the number for PV scheme\n", 1uLL, 0x2CuLL, stdout);
fwrite("\t\t1 : conventional PV\n", 1uLL, 0x16uLL, stdout);
fwrite("\t\t2 : PV by complex arithmetics with fixed hops\n", 1uLL, 0x30uLL, stdout);
fwrite("\t\t3 : Puckette's loose-locking PV\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t4 : Puckette's loose-locking PV by complex with fixed hops\n", 1uLL, 0x3DuLL, stdout);
fwrite("\t\t5 : PV with fixed hops by Ellis\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t6 : PV in freq. domain\n", 1uLL, 0x19uLL, stdout);
fwrite("\t\t7 : plain superimpose (no-FFT)\n", 1uLL, 0x21uLL, stdout);
fwrite("\t\t0 : interactive PV with curses (default)\n", 1uLL, 0x2BuLL, stdout);
return fwrite(
"KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
"\tSPACE : play / stop\n"
"\t< > : set loop range\n"
"\t[{ }] : expand the loop range\n"
"\tL l : phase-lock on / off\n"
"\tW w : change window\n"
"\tH h : hop-size up / down\n"
"\tUP / DOWN : pitch up / down\n"
"\tLEFT / RIGHT : pitch up / down\n"
"\tR r HOME : reset parameters\n"
"\tN n : toggle for no-FFT mode\n"
"\tQ q : quit\n",
1uLL,
0x19DuLL,
stdout);
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
func0();
fwrite(
"WaoN-pv is yet-another phase vocoder, with which you can do time-strech \nand pitch-shift a sound file.\n\n",
1uLL,
0x68uLL,
stdout);
fprintf(stdout, "Usage: %s [option ...]\n\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h, --help\tprint this help.\n", 1uLL, 0x1EuLL, stdout);
fwrite(" -v, --version\tprint version information.\n", 1uLL, 0x2BuLL, stdout);
fwrite("OPTIONS FOR FILES\n", 1uLL, 0x12uLL, stdout);
fwrite(" -i, --input\tinput file (default: stdin)\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -o, --output\toutput file in flac (default: play audio by ao)\n", 1uLL, 0x3FuLL, stdout);
fwrite("FFT OPTIONS\n", 1uLL, 0xCuLL, stdout);
fwrite(" -n \tFFT data number (default: 2048)\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -w --window\t0 no window\n", 1uLL, 0x1AuLL, stdout);
fwrite("\t\t1 parzen window\n", 1uLL, 0x12uLL, stdout);
fwrite("\t\t2 welch window\n", 1uLL, 0x11uLL, stdout);
fwrite("\t\t3 hanning window (default)\n", 1uLL, 0x1DuLL, stdout);
fwrite("\t\t4 hamming window\n", 1uLL, 0x13uLL, stdout);
fwrite("\t\t5 blackman window\n", 1uLL, 0x14uLL, stdout);
fwrite("\t\t6 steeper 30-dB/octave rolloff window\n", 1uLL, 0x28uLL, stdout);
fwrite("PHASE-VOCODER OPTIONS\n", 1uLL, 0x16uLL, stdout);
fwrite(" -hop \thop number (default: 512)\n", 1uLL, 0x28uLL, stdout);
fwrite(" -rate \tsynthesize rate; larger is faster (default: 1.0)\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -pitch\tpitch shift. +1/-1 is half-note up/down (default: 0)\n", 1uLL, 0x3EuLL, stdout);
fwrite(" -scheme \tgive the number for PV scheme\n", 1uLL, 0x2CuLL, stdout);
fwrite("\t\t1 : conventional PV\n", 1uLL, 0x16uLL, stdout);
fwrite("\t\t2 : PV by complex arithmetics with fixed hops\n", 1uLL, 0x30uLL, stdout);
fwrite("\t\t3 : Puckette's loose-locking PV\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t4 : Puckette's loose-locking PV by complex with fixed hops\n", 1uLL, 0x3DuLL, stdout);
fwrite("\t\t5 : PV with fixed hops by Ellis\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t6 : PV in freq. domain\n", 1uLL, 0x19uLL, stdout);
fwrite("\t\t7 : plain superimpose (no-FFT)\n", 1uLL, 0x21uLL, stdout);
fwrite("\t\t0 : interactive PV with curses (default)\n", 1uLL, 0x2BuLL, stdout);
return fwrite(
"KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
"\tSPACE : play / stop\n"
"\t< > : set loop range\n"
"\t[{ }] : expand the loop range\n"
"\tL l : phase-lock on / off\n"
"\tW w : change window\n"
"\tH h : hop-size up / down\n"
"\tUP / DOWN : pitch up / down\n"
"\tLEFT / RIGHT : pitch up / down\n"
"\tR r HOME : reset parameters\n"
"\tN n : toggle for no-FFT mode\n"
"\tQ q : quit\n",
1uLL,
0x19DuLL,
stdout);
}

original_code:
void print_pv_usage (char * argv0)
{
  print_pv_version ();
  fprintf (stdout, "WaoN-pv is yet-another phase vocoder, "
    "with which you can do time-strech \n"
    "and pitch-shift a sound file.\n\n");
  fprintf (stdout, "Usage: %s [option ...]\n\n", argv0);
  fprintf (stdout, "Options:\n");
  fprintf (stdout, "  -h, --help\tprint this help.\n");
  fprintf (stdout, "  -v, --version\tprint version information.\n");
  fprintf (stdout, "OPTIONS FOR FILES\n");
  fprintf (stdout, "  -i, --input\tinput file (default: stdin)\n");
  fprintf (stdout, "  -o, --output\toutput file in flac"
    " (default: play audio by ao)\n");
  fprintf (stdout, "FFT OPTIONS\n");
  fprintf (stdout, "  -n         \tFFT data number (default: 2048)\n");
  fprintf (stdout, "  -w --window\t0 no window\n");
  fprintf (stdout, "\t\t1 parzen window\n");
  fprintf (stdout, "\t\t2 welch window\n");
  fprintf (stdout, "\t\t3 hanning window (default)\n");
  fprintf (stdout, "\t\t4 hamming window\n");
  fprintf (stdout, "\t\t5 blackman window\n");
  fprintf (stdout, "\t\t6 steeper 30-dB/octave rolloff window\n");
  fprintf (stdout, "PHASE-VOCODER OPTIONS\n");
  fprintf (stdout, "  -hop       \thop number (default: 512)\n");
  fprintf (stdout, "  -rate      \tsynthesize rate; larger is faster"
    " (default: 1.0)\n");
  fprintf (stdout, "  -pitch\tpitch shift. +1/-1 is half-note up/down"
    " (default: 0)\n");
  fprintf (stdout, "  -scheme    \tgive the number for PV scheme\n");
  fprintf (stdout, "\t\t1 : conventional PV\n");
  fprintf (stdout, "\t\t2 : PV by complex arithmetics with fixed hops\n");
  fprintf (stdout, "\t\t3 : Puckette's loose-locking PV\n");
  fprintf (stdout, "\t\t4 : Puckette's loose-locking PV by complex"
    " with fixed hops\n");
  fprintf (stdout, "\t\t5 : PV with fixed hops by Ellis\n");
  fprintf (stdout, "\t\t6 : PV in freq. domain\n");
  fprintf (stdout, "\t\t7 : plain superimpose (no-FFT)\n");
  fprintf (stdout, "\t\t0 : interactive PV with curses (default)\n");
  fprintf (stdout, "KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
    "\tSPACE        : play / stop\n"
    "\t< >          : set loop range\n"
    "\t[{ }]        : expand the loop range\n"
    "\tL l          : phase-lock on / off\n"
    "\tW w          : change window\n"
    "\tH h          : hop-size up / down\n"
    "\tUP / DOWN    : pitch up / down\n"
    "\tLEFT / RIGHT : pitch up / down\n"
    "\tR r HOME     : reset parameters\n"
    "\tN n          : toggle for no-FFT mode\n"
    "\tQ q          : quit\n");
}

canonical_original_code:
void print_pv_usage(char *argv0)
{
  print_pv_version ();
  fprintf (stdout, "WaoN-pv is yet-another phase vocoder, "
    "with which you can do time-strech \n"
    "and pitch-shift a sound file.\n\n");
  fprintf (stdout, "Usage: %s [option ...]\n\n", argv0);
  fprintf (stdout, "Options:\n");
  fprintf (stdout, "  -h, --help\tprint this help.\n");
  fprintf (stdout, "  -v, --version\tprint version information.\n");
  fprintf (stdout, "OPTIONS FOR FILES\n");
  fprintf (stdout, "  -i, --input\tinput file (default: stdin)\n");
  fprintf (stdout, "  -o, --output\toutput file in flac"
    " (default: play audio by ao)\n");
  fprintf (stdout, "FFT OPTIONS\n");
  fprintf (stdout, "  -n         \tFFT data number (default: 2048)\n");
  fprintf (stdout, "  -w --window\t0 no window\n");
  fprintf (stdout, "\t\t1 parzen window\n");
  fprintf (stdout, "\t\t2 welch window\n");
  fprintf (stdout, "\t\t3 hanning window (default)\n");
  fprintf (stdout, "\t\t4 hamming window\n");
  fprintf (stdout, "\t\t5 blackman window\n");
  fprintf (stdout, "\t\t6 steeper 30-dB/octave rolloff window\n");
  fprintf (stdout, "PHASE-VOCODER OPTIONS\n");
  fprintf (stdout, "  -hop       \thop number (default: 512)\n");
  fprintf (stdout, "  -rate      \tsynthesize rate; larger is faster"
    " (default: 1.0)\n");
  fprintf (stdout, "  -pitch\tpitch shift. +1/-1 is half-note up/down"
    " (default: 0)\n");
  fprintf (stdout, "  -scheme    \tgive the number for PV scheme\n");
  fprintf (stdout, "\t\t1 : conventional PV\n");
  fprintf (stdout, "\t\t2 : PV by complex arithmetics with fixed hops\n");
  fprintf (stdout, "\t\t3 : Puckette's loose-locking PV\n");
  fprintf (stdout, "\t\t4 : Puckette's loose-locking PV by complex"
    " with fixed hops\n");
  fprintf (stdout, "\t\t5 : PV with fixed hops by Ellis\n");
  fprintf (stdout, "\t\t6 : PV in freq. domain\n");
  fprintf (stdout, "\t\t7 : plain superimpose (no-FFT)\n");
  fprintf (stdout, "\t\t0 : interactive PV with curses (default)\n");
  fprintf (stdout, "KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
    "\tSPACE        : play / stop\n"
    "\t< >          : set loop range\n"
    "\t[{ }]        : expand the loop range\n"
    "\tL l          : phase-lock on / off\n"
    "\tW w          : change window\n"
    "\tH h          : hop-size up / down\n"
    "\tUP / DOWN    : pitch up / down\n"
    "\tLEFT / RIGHT : pitch up / down\n"
    "\tR r HOME     : reset parameters\n"
    "\tN n          : toggle for no-FFT mode\n"
    "\tQ q          : quit\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
int v4; // ebx
char *v5; // r13
const char *v6; // rbp
size_t v7; // rax
char *v8; // rax
const char *v9; // rbp
const char *v10; // rbp
size_t v11; // rax
char *dest; // [rsp+10h] [rbp-68h]
__int64 v14; // [rsp+18h] [rbp-60h]
__int64 v15; // [rsp+20h] [rbp-58h]
double v16; // [rsp+28h] [rbp-50h]
double v17; // [rsp+30h] [rbp-48h]
int v18; // [rsp+38h] [rbp-40h]
unsigned int v19; // [rsp+3Ch] [rbp-3Ch]

if ( argc <= 1 )
goto LABEL_41;
v3 = argv + 1;
v4 = 2;
v19 = 3;
v18 = 0;
v17 = 0.0;
v16 = *(double *)&LC36;
v15 = 512LL;
v14 = 2048LL;
dest = 0LL;
v5 = 0LL;
while ( 1 )
{
v9 = *v3;
if ( !strcmp(*v3, "--input") || !strcmp(*v3, "-i") )
{
if ( v4 >= argc )
goto LABEL_9;
v6 = argv[v4];
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
v5 = v8;
if ( !v8 )
{
fwrite("main : malloc error for file_in\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
strcpy(v8, v6);
goto LABEL_5;
}
if ( !strcmp(*v3, "--output") || !strcmp(*v3, "-o") )
{
if ( v4 >= argc )
goto LABEL_9;
v10 = argv[v4];
v11 = strlen(v10);
dest = (char *)malloc(v11 + 1);
if ( !dest )
{
fwrite("main : malloc error for file_out\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strcpy(dest, v10);
goto LABEL_5;
}
if ( !strcmp(*v3, "-n") )
{
if ( v4 >= argc )
goto LABEL_9;
v14 = atoi(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(*v3, "-hop") )
{
if ( v4 >= argc )
goto LABEL_9;
v15 = atoi(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(*v3, "-rate") )
{
if ( v4 >= argc )
goto LABEL_9;
v16 = atof(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(v9, "-pitch") )
{
if ( v4 >= argc )
goto LABEL_9;
v17 = atof(argv[v4]);
goto LABEL_5;
}
if ( strcmp(v9, "-scheme") )
break;
if ( v4 >= argc )
goto LABEL_9;
v18 = atoi(argv[v4]);
LABEL_5:
v3 += 2;
v4 += 2;
if ( v4 == ((argc - 2) & 0xFFFFFFFE) + 4 )
goto LABEL_9;
}
if ( strcmp(v9, "--window") && strcmp(v9, "-w") )
{
if ( !strcmp(v9, "--version") || !strcmp(v9, "-v") )
{
print_pv_version();
exit(1);
}
print_pv_usage(*argv);
exit(1);
}
if ( v4 < argc )
{
v19 = atoi(argv[v4]);
goto LABEL_5;
}
LABEL_9:
if ( !v5 )
{
LABEL_41:
print_pv_usage(*argv);
exit(1);
}
switch ( v18 )
{
case 0:
pv_complex_curses(v5, v14, v15);
break;
case 1:
pv_conventional(v5, dest, v14, v15, v19, v16, v17);
break;
case 2:
pv_complex(v5, dest, v14, v15, v19, 0LL, v16, v17);
break;
case 3:
pv_loose_lock(v5, dest, v14, v15, v19, v16, v17);
break;
case 4:
pv_complex(v5, dest, v14, v15, v19, 1LL, v16, v17);
break;
case 5:
pv_ellis(v5, dest, v14, v15, v19, v16, v17);
break;
case 6:
if ( v17 == 0.0 )
pv_freq(v5, dest, v14, v15, v19, v16);
else
fwrite("pitch-shifting is not implemented yet\n", 1uLL, 0x26uLL, stderr);
break;
case 7:
pv_nofft(v5, dest, v14, v15, v19, v16, v17);
break;
default:
fwrite("invalid scheme number\n", 1uLL, 0x16uLL, stderr);
break;
}
free(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
int v4; // ebx
char *v5; // r13
const char *v6; // rbp
size_t v7; // rax
char *v8; // rax
const char *v9; // rbp
const char *v10; // rbp
size_t v11; // rax
char *dest; // [rsp+10h] [rbp-68h]
__int64 v14; // [rsp+18h] [rbp-60h]
__int64 v15; // [rsp+20h] [rbp-58h]
double v16; // [rsp+28h] [rbp-50h]
double v17; // [rsp+30h] [rbp-48h]
int v18; // [rsp+38h] [rbp-40h]
unsigned int v19; // [rsp+3Ch] [rbp-3Ch]

if ( argc <= 1 )
goto LABEL_41;
v3 = argv + 1;
v4 = 2;
v19 = 3;
v18 = 0;
v17 = 0.0;
v16 = *(double *)&LC36;
v15 = 512LL;
v14 = 2048LL;
dest = 0LL;
v5 = 0LL;
while ( 1 )
{
v9 = *v3;
if ( !strcmp(*v3, "--input") || !strcmp(*v3, "-i") )
{
if ( v4 >= argc )
goto LABEL_9;
v6 = argv[v4];
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
v5 = v8;
if ( !v8 )
{
fwrite("main : malloc error for file_in\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
strcpy(v8, v6);
goto LABEL_5;
}
if ( !strcmp(*v3, "--output") || !strcmp(*v3, "-o") )
{
if ( v4 >= argc )
goto LABEL_9;
v10 = argv[v4];
v11 = strlen(v10);
dest = (char *)malloc(v11 + 1);
if ( !dest )
{
fwrite("main : malloc error for file_out\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strcpy(dest, v10);
goto LABEL_5;
}
if ( !strcmp(*v3, "-n") )
{
if ( v4 >= argc )
goto LABEL_9;
v14 = atoi(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(*v3, "-hop") )
{
if ( v4 >= argc )
goto LABEL_9;
v15 = atoi(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(*v3, "-rate") )
{
if ( v4 >= argc )
goto LABEL_9;
v16 = atof(argv[v4]);
goto LABEL_5;
}
if ( !strcmp(v9, "-pitch") )
{
if ( v4 >= argc )
goto LABEL_9;
v17 = atof(argv[v4]);
goto LABEL_5;
}
if ( strcmp(v9, "-scheme") )
break;
if ( v4 >= argc )
goto LABEL_9;
v18 = atoi(argv[v4]);
LABEL_5:
v3 += 2;
v4 += 2;
if ( v4 == ((argc - 2) & 0xFFFFFFFE) + 4 )
goto LABEL_9;
}
if ( strcmp(v9, "--window") && strcmp(v9, "-w") )
{
if ( !strcmp(v9, "--version") || !strcmp(v9, "-v") )
{
func0();
exit(1);
}
func1(*argv);
exit(1);
}
if ( v4 < argc )
{
v19 = atoi(argv[v4]);
goto LABEL_5;
}
LABEL_9:
if ( !v5 )
{
LABEL_41:
func1(*argv);
exit(1);
}
switch ( v18 )
{
case 0:
pv_complex_curses(v5, v14, v15);
break;
case 1:
pv_conventional(v5, dest, v14, v15, v19, v16, v17);
break;
case 2:
pv_complex(v5, dest, v14, v15, v19, 0LL, v16, v17);
break;
case 3:
pv_loose_lock(v5, dest, v14, v15, v19, v16, v17);
break;
case 4:
pv_complex(v5, dest, v14, v15, v19, 1LL, v16, v17);
break;
case 5:
pv_ellis(v5, dest, v14, v15, v19, v16, v17);
break;
case 6:
if ( v17 == 0.0 )
pv_freq(v5, dest, v14, v15, v19, v16);
else
fwrite("pitch-shifting is not implemented yet\n", 1uLL, 0x26uLL, stderr);
break;
case 7:
pv_nofft(v5, dest, v14, v15, v19, v16, v17);
break;
default:
fwrite("invalid scheme number\n", 1uLL, 0x16uLL, stderr);
break;
}
free(v5);
return 0;
}

original_code:
int main (int argc, char** argv)
{
  char *file_in = ((void *)0);
  char *file_out = ((void *)0);
  long len = 2048;
  long hop = 512;
  double rate = 1.0;
  double pitch_shift = 0.0;
  int scheme = 0;
  int flag_window = 3;
  int i;
  for (i = 1; i < argc; i++)
    {
      if ((strcmp (argv[i], "--input" ) == 0)
  || (strcmp (argv[i], "-i" ) == 0))
 {
   if (i+1 < argc)
     {
       file_in = (char *)malloc (sizeof (char)
     * (strlen (argv [++i]) + 1));
       if (file_in == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_in" "\n"); exit (1); };
       strcpy (file_in, argv[i]);
     }
 }
      else if ((strcmp (argv[i], "--output" ) == 0)
  || (strcmp (argv[i], "-o" ) == 0))
 {
   if (i+1 < argc)
     {
       file_out = (char *)malloc (sizeof (char)
      * (strlen (argv [++i]) + 1));
       if (file_out == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_out" "\n"); exit (1); };
       strcpy (file_out, argv[i]);
     }
 }
      else if (strcmp (argv[i], "-n" ) == 0)
 {
   if (i+1 < argc)
     {
       len = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-hop" ) == 0)
 {
   if (i+1 < argc)
     {
       hop = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-rate" ) == 0)
 {
   if (i+1 < argc)
     {
       rate = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-pitch" ) == 0)
 {
   if (i+1 < argc)
     {
       pitch_shift = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-scheme" ) == 0)
 {
   if (i+1 < argc)
     {
       scheme = atoi (argv [++i]);
     }
 }
      else if ((strcmp (argv[i], "--window") == 0)
        || (strcmp (argv[i], "-w") == 0))
 {
   if ( i+1 < argc )
     {
       flag_window = atoi (argv[++i]);
     }
 }
      else if ((strcmp (argv[i], "--version") == 0)
        || (strcmp (argv[i], "-v") == 0))
 {
   print_pv_version ();
   exit (1);
 }
      else
 {
   print_pv_usage (argv [0]);
   exit (1);
 }
    }
  if (file_in == ((void *)0))
    {
      print_pv_usage (argv [0]);
      exit (1);
    }
  switch (scheme)
    {
    case 0:
      pv_complex_curses (file_in, len, hop);
      break;
    case 1:
      pv_conventional (file_in, file_out, rate, pitch_shift,
         len, hop, flag_window);
      break;
    case 2:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    0
    );
      break;
    case 3:
      pv_loose_lock (file_in, file_out, rate, pitch_shift,
       len, hop, flag_window);
      break;
    case 4:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    1
    );
      break;
    case 5:
      pv_ellis (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    case 6:
      if (pitch_shift != 0.0)
 {
   fprintf (stderr, "pitch-shifting is not implemented yet\n");
   break;
 }
      pv_freq (file_in, file_out, rate, len, hop, flag_window);
      break;
    case 7:
      pv_nofft (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    default:
      fprintf (stderr, "invalid scheme number\n");
      break;
    }
  free (file_in);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  char *file_in = ((void *)0);
  char *file_out = ((void *)0);
  long len = 2048;
  long hop = 512;
  double rate = 1.0;
  double pitch_shift = 0.0;
  int scheme = 0;
  int flag_window = 3;
  int i;
  for (i = 1; i < argc; i++)
    {
      if ((strcmp (argv[i], "--input" ) == 0)
  || (strcmp (argv[i], "-i" ) == 0))
 {
   if (i+1 < argc)
     {
       file_in = (char *)malloc (sizeof (char)
     * (strlen (argv [++i]) + 1));
       if (file_in == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_in" "\n"); exit (1); };
       strcpy (file_in, argv[i]);
     }
 }
      else if ((strcmp (argv[i], "--output" ) == 0)
  || (strcmp (argv[i], "-o" ) == 0))
 {
   if (i+1 < argc)
     {
       file_out = (char *)malloc (sizeof (char)
      * (strlen (argv [++i]) + 1));
       if (file_out == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_out" "\n"); exit (1); };
       strcpy (file_out, argv[i]);
     }
 }
      else if (strcmp (argv[i], "-n" ) == 0)
 {
   if (i+1 < argc)
     {
       len = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-hop" ) == 0)
 {
   if (i+1 < argc)
     {
       hop = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-rate" ) == 0)
 {
   if (i+1 < argc)
     {
       rate = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-pitch" ) == 0)
 {
   if (i+1 < argc)
     {
       pitch_shift = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-scheme" ) == 0)
 {
   if (i+1 < argc)
     {
       scheme = atoi (argv [++i]);
     }
 }
      else if ((strcmp (argv[i], "--window") == 0)
        || (strcmp (argv[i], "-w") == 0))
 {
   if ( i+1 < argc )
     {
       flag_window = atoi (argv[++i]);
     }
 }
      else if ((strcmp (argv[i], "--version") == 0)
        || (strcmp (argv[i], "-v") == 0))
 {
   print_pv_version ();
   exit (1);
 }
      else
 {
   print_pv_usage (argv [0]);
   exit (1);
 }
    }
  if (file_in == ((void *)0))
    {
      print_pv_usage (argv [0]);
      exit (1);
    }
  switch (scheme)
    {
    case 0:
      pv_complex_curses (file_in, len, hop);
      break;
    case 1:
      pv_conventional (file_in, file_out, rate, pitch_shift,
         len, hop, flag_window);
      break;
    case 2:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    0
    );
      break;
    case 3:
      pv_loose_lock (file_in, file_out, rate, pitch_shift,
       len, hop, flag_window);
      break;
    case 4:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    1
    );
      break;
    case 5:
      pv_ellis (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    case 6:
      if (pitch_shift != 0.0)
 {
   fprintf (stderr, "pitch-shifting is not implemented yet\n");
   break;
 }
      pv_freq (file_in, file_out, rate, len, hop, flag_window);
      break;
    case 7:
      pv_nofft (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    default:
      fprintf (stderr, "invalid scheme number\n");
      break;
    }
  free (file_in);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: len long

variable_types: hop long

variable_types: rate double

variable_types: scheme int

variable_types: i int


decompiled_code:
void on_preference()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void
on_preference (void)
{
}

canonical_original_code:
static void on_preference()
{
}


decompiled_code:
int __fastcall print_ao_info(const char **a1, const char *a2)
{
fprintf(stdout, "%s type : %d\n", a2, *(unsigned int *)a1);
fprintf(stdout, "%s name : %s\n", a2, a1[1]);
fprintf(stdout, "%s short name : %s\n", a2, a1[2]);
return fprintf(stdout, "%s driver comment : %s\n", a2, a1[4]);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1, const char *a2)
{
fprintf(stdout, "%s type : %d\n", a2, *(unsigned int *)a1);
fprintf(stdout, "%s name : %s\n", a2, a1[1]);
fprintf(stdout, "%s short name : %s\n", a2, a1[2]);
return fprintf(stdout, "%s driver comment : %s\n", a2, a1[4]);
}

original_code:
static void
print_ao_info (const ao_info *info,
        const char *label)
{
  fprintf (stdout, "%s type : %d\n", label, info->type);
  fprintf (stdout, "%s name : %s\n", label, info->name);
  fprintf (stdout, "%s short name : %s\n", label, info->short_name);
  fprintf (stdout, "%s driver comment : %s\n", label, info->comment);
}

canonical_original_code:
static void print_ao_info(struct ao_info *info, char *label)
{
  fprintf (stdout, "%s type : %d\n", label, info->type);
  fprintf (stdout, "%s name : %s\n", label, info->name);
  fprintf (stdout, "%s short name : %s\n", label, info->short_name);
  fprintf (stdout, "%s driver comment : %s\n", label, info->comment);
}

variable_types: struct ao_info { int type; char *name; char *short_name; char *author; char *comment; int preferred_byte_format; int priority; char **options; int option_count; } *

variable_types:
label
char *


decompiled_code:
int print_ao_driver_info_list()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rbx
char v4[92]; // [rsp+0h] [rbp-78h] BYREF
int v5[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

v0 = ao_driver_info_list(v5);
if ( v5[0] > 0 )
{
v1 = v0;
v2 = 0LL;
do
{
sprintf(v4, "%d : ", (unsigned int)v2);
LODWORD(v0) = print_ao_info(*(const char ***)(v1 + 8 * v2++), v4);
}
while ( v5[0] > (int)v2 );
}
return v0;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rbx
char v4[92]; // [rsp+0h] [rbp-78h] BYREF
int v5[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

v0 = ao_driver_info_list(v5);
if ( v5[0] > 0 )
{
v1 = v0;
v2 = 0LL;
do
{
sprintf(v4, "%d : ", (unsigned int)v2);
LODWORD(v0) = func0(*(const char ***)(v1 + 8 * v2++), v4);
}
while ( v5[0] > (int)v2 );
}
return v0;
}

original_code:
void
print_ao_driver_info_list (void)
{
  int driver_count;
  ao_info** info_list;
  info_list = ao_driver_info_list (&driver_count);
  int i;
  char label [80];
  for (i = 0; i < driver_count; i ++)
    {
      sprintf (label, "%d : ", i);
      print_ao_info (info_list [i], label);
    }
}

canonical_original_code:
void print_ao_driver_info_list()
{
  int driver_count;
  struct ao_info **info_list;
  info_list = ao_driver_info_list (&driver_count);
  int i;
  char label[80];
  for (i = 0; i < driver_count; i ++)
    {
      sprintf (label, "%d : ", i);
      print_ao_info (info_list [i], label);
    }
}

variable_types: struct ao_info { int type; char *name; char *short_name; char *author; char *comment; int preferred_byte_format; int priority; char **options; int option_count; } **

variable_types:
label
char [80]


original_code:
double
midi_to_freq (int midi)
{
  double f;
  f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
  return (f);
}

canonical_original_code:
double midi_to_freq(int midi)
{
  double f;
  f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
  return (f);
}

variable_types: midi int

variable_types: f double

return_type: double


decompiled_code:
__int64 __fastcall freq_to_midi(double a1)
{
return (unsigned int)(int)(log(a1 / 440.0) * 17.31234049066756 + 69.5);
}

original_code:
int
freq_to_midi (double f)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * log (f / 440.0));
  return (midi);
}

canonical_original_code:
int freq_to_midi(double f)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * log (f / 440.0));
  return (midi);
}


original_code:
double
midi_to_logf (int midi)
{
  double logf;
  logf = log (440.0) + (double)(midi - 69) * log (2.0) / 12.0;
  return (logf);
}

canonical_original_code:
double midi_to_logf(int midi)
{
  double logf;
  logf = log (440.0) + (double)(midi - 69) * log (2.0) / 12.0;
  return (logf);
}

variable_types: logf double


original_code:
int
logf_to_midi (double logf)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * (logf - log (440.0)));
  return (midi);
}

canonical_original_code:
int logf_to_midi(double logf)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * (logf - log (440.0)));
  return (midi);
}


decompiled_code:
__int64 __fastcall get_note(double a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = log(a1 / 440.0) * 17.31234049066756 + 69.5 + *(double *)&adj_pitch;
result = (unsigned int)(int)v1;
*(double *)&pitch_shift = v1 - (double)(int)result + *(double *)&pitch_shift;
++n_pitch;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(double a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = log(a1 / 440.0) * 17.31234049066756 + 69.5 + *(double *)&adj_pitch;
result = (unsigned int)(int)v1;
*(double *)&pitch_shift = v1 - (double)(int)result + *(double *)&pitch_shift;
++n_pitch;
return result;
}

original_code:
int
get_note (double freq)
{
  extern double adj_pitch;
  extern double pitch_shift;
  extern int n_pitch;
  const double factor = 1.731234049066756242e+01;
  double dnote;
  int inote;
  dnote = 69.5 + factor * log(freq/440.0) + adj_pitch;
  inote = (int)dnote;
  pitch_shift += (dnote - (double)inote);
  n_pitch ++;
  return inote;
}

canonical_original_code:
int get_note(double freq)
{
  extern double adj_pitch;
  extern double pitch_shift;
  extern int n_pitch;
  double factor = 1.731234049066756242e+01;
  double dnote;
  int inote;
  dnote = 69.5 + factor * log(freq/440.0) + adj_pitch;
  inote = (int)dnote;
  pitch_shift += (dnote - (double)inote);
  n_pitch ++;
  return inote;
}

variable_types: freq double

variable_types: factor double

variable_types: dnote double

variable_types: inote int


decompiled_code:
ssize_t __fastcall smf_prog_change(int a1, char a2, char a3)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 0;
buf[1] = a2 - 64;
buf[2] = a3;
return write(a1, buf, 3uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, char a2, char a3)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 0;
buf[1] = a2 - 64;
buf[2] = a3;
return write(a1, buf, 3uLL);
}

original_code:
int
smf_prog_change (int fd, char channel, char prog)
{
  unsigned char data[3];
  data[0] = 0x00;
  data[1] = 0xC0 + channel;
  data[2] = prog;
  return write (fd, data, 3);
}

canonical_original_code:
int smf_prog_change(int fd, char channel, char prog)
{
  unsigned char data[3];
  data[0] = 0x00;
  data[1] = 0xC0 + channel;
  data[2] = prog;
  return write (fd, data, 3);
}

variable_types: fd int

variable_types: channel char

variable_types: prog char

variable_types:
data
unsigned char [3]


decompiled_code:
ssize_t __fastcall smf_tempo(int a1, int a2)
{
char buf[15]; // [rsp+9h] [rbp-Fh] BYREF

buf[0] = 0;
buf[1] = -1;
buf[2] = 81;
buf[3] = 3;
buf[4] = BYTE2(a2);
buf[5] = BYTE1(a2);
buf[6] = a2;
return write(a1, buf, 7uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, int a2)
{
char buf[15]; // [rsp+9h] [rbp-Fh] BYREF

buf[0] = 0;
buf[1] = -1;
buf[2] = 81;
buf[3] = 3;
buf[4] = BYTE2(a2);
buf[5] = BYTE1(a2);
buf[6] = a2;
return write(a1, buf, 7uLL);
}

original_code:
int
smf_tempo (int fd, unsigned long tempo)
{
  unsigned char data[7];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x51;
  data[3] = 0x03;
  data[4] = (char) (tempo >> 16) & 0xff;
  data[5] = (char) (tempo >> 8) & 0xff;
  data[6] = (char) (tempo ) & 0xff;
  return write (fd, data, 7);
}

canonical_original_code:
int smf_tempo(int fd, unsigned long tempo)
{
  unsigned char data[7];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x51;
  data[3] = 0x03;
  data[4] = (char) (tempo >> 16) & 0xff;
  data[5] = (char) (tempo >> 8) & 0xff;
  data[6] = (char) (tempo ) & 0xff;
  return write (fd, data, 7);
}

variable_types:
tempo
unsigned long

variable_types:
data
unsigned char [7]


decompiled_code:
ssize_t __fastcall smf_track_end(int a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 0;
buf[1] = -1;
buf[2] = 47;
buf[3] = 0;
return write(a1, buf, 4uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func7(int a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 0;
buf[1] = -1;
buf[2] = 47;
buf[3] = 0;
return write(a1, buf, 4uLL);
}

original_code:
int
smf_track_end (int fd)
{
  unsigned char data[4];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x2f;
  data[3] = 0x00;
  return write (fd, data, 4);
}

canonical_original_code:
int smf_track_end(int fd)
{
  unsigned char data[4];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x2f;
  data[3] = 0x00;
  return write (fd, data, 4);
}

variable_types:
data
unsigned char [4]


decompiled_code:
ssize_t __fastcall write_var_len(int a1, __int64 a2)
{
__int64 v2; // rsi
int v3; // edx
char *v4; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[3] = a2 & 0x7F;
v2 = a2 >> 7;
v3 = 1;
if ( v2 > 0 )
{
v4 = buf;
do
{
v4[2] = v2 | 0x80;
v3 = (unsigned int)buf + 2 - (_DWORD)v4;
v2 >>= 7;
--v4;
}
while ( v2 > 0 );
}
return write(a1, &buf[4 - v3], v3);
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, __int64 a2)
{
__int64 v2; // rsi
int v3; // edx
char *v4; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[3] = a2 & 0x7F;
v2 = a2 >> 7;
v3 = 1;
if ( v2 > 0 )
{
v4 = buf;
do
{
v4[2] = v2 | 0x80;
v3 = (unsigned int)buf + 2 - (_DWORD)v4;
v2 >>= 7;
--v4;
}
while ( v2 > 0 );
}
return write(a1, &buf[4 - v3], v3);
}

original_code:
int
write_var_len (int fd, long value)
{
  unsigned char rep[4];
  int bytes;
  bytes = 1;
  rep[3] = value & 0x7f;
  value >>= 7;
  while (value >0)
    {
      rep[3 - bytes] = (value & 0x7f) | 0x80;
      bytes ++;
      value >>= 7;
    }
  return (write (fd, &rep[4-bytes], bytes));
}

canonical_original_code:
int write_var_len(int fd, long value)
{
  unsigned char rep[4];
  int bytes;
  bytes = 1;
  rep[3] = value & 0x7f;
  value >>= 7;
  while (value >0)
    {
      rep[3 - bytes] = (value & 0x7f) | 0x80;
      bytes ++;
      value >>= 7;
    }
  return (write (fd, &rep[4-bytes], bytes));
}

variable_types: value long

variable_types:
rep
unsigned char [4]

variable_types: bytes int


decompiled_code:
__int64 __fastcall smf_note_on(int fd, __int64 a2, char a3, char a4, char a5)
{
int v8; // ebx
char buf[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v8 = write_var_len(fd, a2);
buf[0] = a5 - 112;
buf[1] = a3;
buf[2] = a4;
return v8 + (unsigned int)write(fd, buf, 3uLL);
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, char a3, char a4, char a5)
{
int v8; // ebx
char buf[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v8 = func8(fd, a2);
buf[0] = a5 - 112;
buf[1] = a3;
buf[2] = a4;
return v8 + (unsigned int)write(fd, buf, 3uLL);
}

original_code:
int
smf_note_on (int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x90 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

canonical_original_code:
int smf_note_on(int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x90 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

variable_types: dtime long

variable_types: note char

variable_types: vel char

variable_types: num int


decompiled_code:
__int64 __fastcall smf_note_off(int fd, __int64 a2, char a3, char a4, char a5)
{
int v8; // ebx
char buf[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v8 = write_var_len(fd, a2);
buf[0] = a5 + 0x80;
buf[1] = a3;
buf[2] = a4;
return v8 + (unsigned int)write(fd, buf, 3uLL);
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __int64 a2, char a3, char a4, char a5)
{
int v8; // ebx
char buf[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v8 = func8(fd, a2);
buf[0] = a5 + 0x80;
buf[1] = a3;
buf[2] = a4;
return v8 + (unsigned int)write(fd, buf, 3uLL);
}

original_code:
int
smf_note_off (int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x80 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

canonical_original_code:
int smf_note_off(int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x80 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}


decompiled_code:
__int64 __fastcall read_var_len(int fd, _QWORD *a2)
{
unsigned int v2; // ebp
char v3; // al
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

*a2 = 0LL;
v2 = 0;
do
{
*a2 <<= 7;
v2 += read(fd, buf, 1uLL);
v3 = buf[0];
*a2 += buf[0] & 0x7F;
}
while ( v3 < 0 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, _QWORD *a2)
{
unsigned int v2; // ebp
char v3; // al
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

*a2 = 0LL;
v2 = 0;
do
{
*a2 <<= 7;
v2 += read(fd, buf, 1uLL);
v3 = buf[0];
*a2 += buf[0] & 0x7F;
}
while ( v3 < 0 );
return v2;
}

original_code:
int
read_var_len (int fd, long *value)
{
  unsigned char c;
  int bytes;
  *value = 0;
  bytes = 0;
  do
    {
      (*value) <<= 7;
      bytes += read (fd, &c, 1);
      (*value) += (c & 0x7f);
    }
  while ( (c & 0x80) == 0x80 );
  return bytes;
}

canonical_original_code:
int read_var_len(int fd, long *value)
{
  unsigned char c;
  int bytes;
  *value = 0;
  bytes = 0;
  do
    {
      (*value) <<= 7;
      bytes += read (fd, &c, 1);
      (*value) += (c & 0x7f);
    }
  while ( (c & 0x80) == 0x80 );
  return bytes;
}

variable_types:
value
long *

variable_types:
c
unsigned char


wblong

decompiled_code:
ssize_t __fastcall wblong(int a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = HIBYTE(a2);
buf[1] = BYTE2(a2);
buf[2] = BYTE1(a2);
buf[3] = a2;
return write(a1, buf, 4uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func12(int a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = HIBYTE(a2);
buf[1] = BYTE2(a2);
buf[2] = BYTE1(a2);
buf[3] = a2;
return write(a1, buf, 4uLL);
}

original_code:
int
wblong (int fd, unsigned long ul)
{
  unsigned char data[4];
  data[0] = (char) (ul >> 24) & 0xff;
  data[1] = (char) (ul >> 16) & 0xff;
  data[2] = (char) (ul >> 8) & 0xff;
  data[3] = (char) (ul) & 0xff;
  return write (fd, data, 4);
}

canonical_original_code:
int wblong(int fd, unsigned long ul)
{
  unsigned char data[4];
  data[0] = (char) (ul >> 24) & 0xff;
  data[1] = (char) (ul >> 16) & 0xff;
  data[2] = (char) (ul >> 8) & 0xff;
  data[3] = (char) (ul) & 0xff;
  return write (fd, data, 4);
}

variable_types:
ul
unsigned long


decompiled_code:
__int64 __fastcall smf_track_head(int a1, int a2)
{
int v2; // ebp

v2 = write(a1, "MTrk", 4uLL);
return v2 + (unsigned int)wblong(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2)
{
int v2; // ebp

v2 = write(a1, "MTrk", 4uLL);
return v2 + (unsigned int)func12(a1, a2);
}

original_code:
int
smf_track_head (int fd, unsigned long size)
{
  int num;
  num = write (fd, "MTrk", 4);
  num += wblong (fd, size);
  return num;
}

canonical_original_code:
int smf_track_head(int fd, unsigned long size)
{
  int num;
  num = write (fd, "MTrk", 4);
  num += wblong (fd, size);
  return num;
}

variable_types: fd int

variable_types:
size
unsigned long


wbshort

decompiled_code:
ssize_t __fastcall wbshort(int a1, __int16 a2)
{
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = HIBYTE(a2);
buf[1] = a2;
return write(a1, buf, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func14(int a1, __int16 a2)
{
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = HIBYTE(a2);
buf[1] = a2;
return write(a1, buf, 2uLL);
}

original_code:
int
wbshort (int fd, unsigned short us)
{
  unsigned char data[2];
  data[0] = (char) (us >> 8) & 0xff;
  data[1] = (char) (us) & 0xff;
  return write (fd, data, 2);
}

canonical_original_code:
int wbshort(int fd, unsigned short us)
{
  unsigned char data[2];
  data[0] = (char) (us >> 8) & 0xff;
  data[1] = (char) (us) & 0xff;
  return write (fd, data, 2);
}

variable_types:
us
unsigned short

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall smf_header_fmt(int a1, __int16 a2, __int16 a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
int v8; // ebx
int v9; // ebx

v6 = write(a1, "MThd", 4uLL);
v7 = wblong(a1, 6) + v6;
v8 = wbshort(a1, a2) + v7;
v9 = wbshort(a1, a3) + v8;
return v9 + (unsigned int)wbshort(a1, a4);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, __int16 a2, __int16 a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
int v8; // ebx
int v9; // ebx

v6 = write(a1, "MThd", 4uLL);
v7 = func12(a1, 6) + v6;
v8 = func14(a1, a2) + v7;
v9 = func14(a1, a3) + v8;
return v9 + (unsigned int)func14(a1, a4);
}

original_code:
int
smf_header_fmt (int fd,
  unsigned short format,
  unsigned short tracks,
  unsigned short divisions)
{
  int num;
  num = write (fd, "MThd", 4);
  num += wblong (fd, 6);
  num += wbshort (fd, format);
  num += wbshort (fd, tracks);
  num += wbshort (fd, divisions);
  return num;
}

canonical_original_code:
int smf_header_fmt(int fd, unsigned short format, unsigned short tracks, unsigned short divisions)
{
  int num;
  num = write (fd, "MThd", 4);
  num += wblong (fd, 6);
  num += wbshort (fd, format);
  num += wbshort (fd, tracks);
  num += wbshort (fd, divisions);
  return num;
}

variable_types:
format
unsigned short

variable_types:
tracks
unsigned short

variable_types:
divisions
unsigned short