decompiled_code:
int con_clearScr()
{
wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func18()
{
wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
int con_clearScr()
{
    wclear(stdscr);
    return wrefresh(stdscr);
}


decompiled_code:
__int64 con_outTxt(char *format, ...)
{
unsigned int v1; // ebx
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf(v3, 0x3FFuLL, format, arg);
if ( printw(v3) == -1 )
v1 = -1;
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
return v1;
}

canonical_decompiled_code:
__int64 func19(char *format, ...)
{
unsigned int v1; // ebx
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf(v3, 0x3FFuLL, format, arg);
if ( printw(v3) == -1 )
v1 = -1;
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
return v1;
}

original_code:
int con_outTxt(const char *format, ...)
{
    va_list arglist;
    char buffer[1024];
    int len;
    __builtin_va_start(arglist,format);
    len = vsnprintf(buffer, sizeof(buffer)-1, format, arglist);
    len = (printw(buffer) != (-1)) ? len : -1;
    wrefresh(stdscr);
    return len;
}

canonical_original_code:
int con_outTxt(char *format, ...)
{
    __builtin_va_list arglist;
    char buffer[1024];
    int len;
    __builtin_va_start(arglist,format);
    len = vsnprintf(buffer, sizeof(buffer)-1, format, arglist);
    len = (printw(buffer) != (-1)) ? len : -1;
    wrefresh(stdscr);
    return len;
}

variable_types:
format
char *

variable_types:
buffer
char [1024]

variable_types: len int

return_type: int


decompiled_code:
__int64 con_keyPressed()
{
int v0; // edi
__int64 result; // rax

v0 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
result = 0LL;
if ( v0 != -1 )
{
ungetch(v0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // edi
__int64 result; // rax

v0 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
result = 0LL;
if ( v0 != -1 )
{
ungetch(v0);
result = 1LL;
}
return result;
}

original_code:
int con_keyPressed()
{
    int ch = wgetch(stdscr);
    if (ch != (-1))
    {
        ungetch(ch);
        return 1;
    }
    return 0;
}

variable_types: ch int


decompiled_code:
int con_getKey()
{
return wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func21()
{
return wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
int con_getKey()
{
    return wgetch(stdscr);
}


decompiled_code:
int __fastcall con_initPair(__int16 a1, __int16 a2, __int16 a3)
{
return init_pair(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func22(__int16 a1, __int16 a2, __int16 a3)
{
return init_pair(a1, a2, a3);
}

original_code:
int con_initPair(short n, short fg, short bg)
{
    return init_pair(n, fg, bg);
}

variable_types: n short

variable_types: fg short

variable_types: bg short


decompiled_code:
int __fastcall con_setColor(__int16 a1)
{
return wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned __int16)(a1 << 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func23(__int16 a1)
{
return wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned __int16)(a1 << 8), 0LL);
}


limitValue

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

result = a2;
if ( a1 >= (int)a2 )
{
result = a3;
if ( a1 <= (int)a3 )
result = (unsigned int)a1;
}
return result;
}

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

result = a2;
if ( a1 >= (int)a2 )
{
result = a3;
if ( a1 <= (int)a3 )
result = (unsigned int)a1;
}
return result;
}

original_code:
static int limitValue(int x, int min, int max) {
    return (x < min) ? min : ((x > max) ? max : x);
}

variable_types: x int

variable_types: min int

variable_types: max int


checkSDLResult

decompiled_code:
void __fastcall checkSDLResult(int a1)
{
const char *v1; // rax

if ( !a1 )
{
v1 = (const char *)SDL_GetError();
fprintf(stderr, "Error: %s\n", v1);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
const char *v1; // rax

if ( !a1 )
{
v1 = (const char *)SDL_GetError();
fprintf(stderr, "Error: %s\n", v1);
exit(1);
}
}

original_code:
static void checkSDLResult(int result) {
    if (!result) {
        fprintf(stderr, "Error: %s\n", SDL_GetError());
        exit(1);
    }
}

variable_types: result int

return_type: void


absentDeLigne

repo: cyprieng/Sudoku

decompiled_code:
__int64 __fastcall absentDeLigne(int a1, __int64 a2, int a3)
{
_DWORD *v3; // rax
_DWORD *v4; // rdx

v3 = (_DWORD *)(a2 + 36LL * a3);
v4 = v3 + 9;
while ( *v3 != a1 )
{
if ( ++v3 == v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
_DWORD *v3; // rax
_DWORD *v4; // rdx

v3 = (_DWORD *)(a2 + 36LL * a3);
v4 = v3 + 9;
while ( *v3 != a1 )
{
if ( ++v3 == v4 )
return 1LL;
}
return 0LL;
}

original_code:
int absentDeLigne(int k, int grille[9][9], int i){
    int j;
    for(j=0; j < 9; j++){
        if(grille[i][j] == k) return 0;
    }
    return 1;
}

variable_types: k int

variable_types:
grille
int [9][9]

variable_types: i int

variable_types: j int


absentDeColonne

decompiled_code:
__int64 __fastcall absentDeColonne(int a1, __int64 a2, int a3)
{
_DWORD *v3; // rax
_DWORD *v4; // rdx

v3 = (_DWORD *)(a2 + 4LL * a3);
v4 = v3 + 81;
while ( *v3 != a1 )
{
v3 += 9;
if ( v3 == v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, int a3)
{
_DWORD *v3; // rax
_DWORD *v4; // rdx

v3 = (_DWORD *)(a2 + 4LL * a3);
v4 = v3 + 81;
while ( *v3 != a1 )
{
v3 += 9;
if ( v3 == v4 )
return 1LL;
}
return 0LL;
}

original_code:
int absentDeColonne(int k, int grille[9][9], int j){
    int i;
    for (i=0; i < 9; i++){
        if(grille[i][j] == k) return 0;
    }
    return 1;
}


absentDeBloc

original_code:
int absentDeBloc (int k, int grille[9][9], int i, int j){
    int _i = i-(i%3), _j = j-(j%3);
    for (i=_i; i < _i+3; i++){
        for (j=_j; j < _j+3; j++){
            if (grille[i][j] == k) return 0;
        }
    }
    return 1;
}

canonical_original_code:
int absentDeBloc(int k, int grille[9][9], int i, int j){
    int _i = i-(i%3); int _j = j-(j%3);
    for (i=_i; i < _i+3; i++){
        for (j=_j; j < _j+3; j++){
            if (grille[i][j] == k) return 0;
        }
    }
    return 1;
}


resolve

decompiled_code:
__int64 __fastcall resolve(__int64 a1, int a2, int a3)
{
int v3; // er12
int v4; // er14
int v5; // ebx
unsigned int v6; // eax
int v7; // er13
int v8; // ebx
unsigned int v10; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]

v10 = 1;
if ( a2 != 81 )
{
v3 = a2 / 9;
v4 = a2 % 9;
v11 = a1 + 36LL * (a2 / 9);
v10 = *(_DWORD *)(v11 + 4LL * (a2 % 9));
if ( v10 )
{
v10 = resolve(a1, (unsigned int)(a2 + 1));
}
else if ( a3 )
{
v6 = time(0LL);
srand(v6);
v7 = 20;
do
{
v8 = rand() % 9 + 1;
if ( (unsigned int)absentDeLigne(v8, a1, v3) )
{
if ( (unsigned int)absentDeColonne(v8, a1, v4) )
{
if ( (unsigned int)absentDeBloc(v8, a1, v3, v4) )
{
*(_DWORD *)(v11 + 4LL * v4) = v8;
if ( (unsigned int)resolve(a1, (unsigned int)(a2 + 1)) )
return 1;
}
}
}
--v7;
}
while ( v7 );
LABEL_19:
*(_DWORD *)(v11 + 4LL * v4) = 0;
}
else
{
v5 = 1;
while ( 1 )
{
if ( (unsigned int)absentDeLigne(v5, a1, v3) )
{
if ( (unsigned int)absentDeColonne(v5, a1, v4) )
{
if ( (unsigned int)absentDeBloc(v5, a1, v3, v4) )
{
*(_DWORD *)(v11 + 4LL * v4) = v5;
if ( (unsigned int)resolve(a1, (unsigned int)(a2 + 1)) )
break;
}
}
}
if ( ++v5 == 10 )
goto LABEL_19;
}
v10 = 1;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
int v3; // er12
int v4; // er14
int v5; // ebx
unsigned int v6; // eax
int v7; // er13
int v8; // ebx
unsigned int v10; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]

v10 = 1;
if ( a2 != 81 )
{
v3 = a2 / 9;
v4 = a2 % 9;
v11 = a1 + 36LL * (a2 / 9);
v10 = *(_DWORD *)(v11 + 4LL * (a2 % 9));
if ( v10 )
{
v10 = func3(a1, (unsigned int)(a2 + 1));
}
else if ( a3 )
{
v6 = time(0LL);
srand(v6);
v7 = 20;
do
{
v8 = rand() % 9 + 1;
if ( (unsigned int)func0(v8, a1, v3) )
{
if ( (unsigned int)func1(v8, a1, v4) )
{
if ( (unsigned int)func2(v8, a1, v3, v4) )
{
*(_DWORD *)(v11 + 4LL * v4) = v8;
if ( (unsigned int)func3(a1, (unsigned int)(a2 + 1)) )
return 1;
}
}
}
--v7;
}
while ( v7 );
LABEL_19:
*(_DWORD *)(v11 + 4LL * v4) = 0;
}
else
{
v5 = 1;
while ( 1 )
{
if ( (unsigned int)func0(v5, a1, v3) )
{
if ( (unsigned int)func1(v5, a1, v4) )
{
if ( (unsigned int)func2(v5, a1, v3, v4) )
{
*(_DWORD *)(v11 + 4LL * v4) = v5;
if ( (unsigned int)func3(a1, (unsigned int)(a2 + 1)) )
break;
}
}
}
if ( ++v5 == 10 )
goto LABEL_19;
}
v10 = 1;
}
}
return v10;
}

original_code:
int resolve(int grille[9][9], int position, int generate){
    int k;
    if(position == 9*9) return 1;
    int i = position/9, j = position%9;
    if(grille[i][j] != 0)
        return resolve(grille, position+1, generate);
    if(!generate){
        for(k=1; k <= 9; k++){
            if(absentDeLigne(k,grille,i) && absentDeColonne(k,grille,j) && absentDeBloc(k,grille,i,j)){
                grille[i][j] = k;
                if(resolve(grille, position+1, generate)) return 1;
            }
        }
    }
    else{
        int nb;
        srand(time(((void *)0)));
        for(k=1; k <= 20; k++){
            nb = rand()%9 + 1;
            if (absentDeLigne(nb,grille,i) && absentDeColonne(nb,grille,j) && absentDeBloc(nb,grille,i,j)){
                grille[i][j] = nb;
                if(resolve(grille, position+1, generate)) return 1;
            }
        }
    }
    grille[i][j] = 0;
    return 0;
}

canonical_original_code:
int resolve(int grille[9][9], int position, int generate){
    int k;
    if(position == 9*9) return 1;
    int i = position/9; int j = position%9;
    if(grille[i][j] != 0)
        return resolve(grille, position+1, generate);
    if(!generate){
        for(k=1; k <= 9; k++){
            if(absentDeLigne(k,grille,i) && absentDeColonne(k,grille,j) && absentDeBloc(k,grille,i,j)){
                grille[i][j] = k;
                if(resolve(grille, position+1, generate)) return 1;
            }
        }
    }
    else{
        int nb;
        srand(time(((void *)0)));
        for(k=1; k <= 20; k++){
            nb = rand()%9 + 1;
            if (absentDeLigne(nb,grille,i) && absentDeColonne(nb,grille,j) && absentDeBloc(nb,grille,i,j)){
                grille[i][j] = nb;
                if(resolve(grille, position+1, generate)) return 1;
            }
        }
    }
    grille[i][j] = 0;
    return 0;
}

variable_types: position int

variable_types: generate int

variable_types: nb int


isUnique

original_code:
int isUnique(int grid[][9]){
    int grid_copy[9][9] = {{0}};
    int grid_to_resolve[9][9] = {{0}};
    int grid_resolve[9][9] = {{0}};
    int grid_fixes[9][9] = {{0}};
    int i = 0, k = 0;
    int row,col;
    int value;
    for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid[col][row] != 0){grid_fixes[col][row] = 1;}
    }
    memcpy(grid_to_resolve, grid, sizeof(grid_to_resolve));
    memcpy(grid_copy, grid, sizeof(grid_copy));
    resolve(grid_copy, 0, 0);
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid_fixes[col][row] == 1)continue;
        value = grid_to_resolve[col][row];
        for(k=1;k<=9;k++){
            grid_to_resolve[col][row] = k;
            if(!is_grid_valid(grid_to_resolve)) continue;
            memcpy(grid_resolve, grid_to_resolve, sizeof(grid_resolve));
            if(!resolve(grid_resolve, 0, 0)) continue;
            if(!equal_grid(grid_copy, grid_resolve))return 0;
        }
        grid_to_resolve[col][row] = value;
    }
 return 1;
}

canonical_original_code:
int isUnique(int grid[][9]){
    int grid_copy[9][9] = {{0}};
    int grid_to_resolve[9][9] = {{0}};
    int grid_resolve[9][9] = {{0}};
    int grid_fixes[9][9] = {{0}};
    int i = 0; int k = 0;
    int row; int col;
    int value;
    for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid[col][row] != 0){grid_fixes[col][row] = 1;}
    }
    memcpy(grid_to_resolve, grid, sizeof(grid_to_resolve));
    memcpy(grid_copy, grid, sizeof(grid_copy));
    resolve(grid_copy, 0, 0);
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid_fixes[col][row] == 1)continue;
        value = grid_to_resolve[col][row];
        for(k=1;k<=9;k++){
            grid_to_resolve[col][row] = k;
            if(!is_grid_valid(grid_to_resolve)) continue;
            memcpy(grid_resolve, grid_to_resolve, sizeof(grid_resolve));
            if(!resolve(grid_resolve, 0, 0)) continue;
            if(!equal_grid(grid_copy, grid_resolve))return 0;
        }
        grid_to_resolve[col][row] = value;
    }
 return 1;
}

variable_types:
grid
int [][9]

variable_types: row int

variable_types: col int

variable_types: value int


generate

decompiled_code:
void __fastcall generate(_DWORD *a1, int a2)
{
unsigned int v2; // eax
int v3; // er12
int v4; // eax
int v5; // ebx
_DWORD *v6; // r14
int v7; // er15

resolve((__int64)a1, 0, 1);
v2 = time(0LL);
srand(v2);
v3 = 0;
if ( a2 > 0 )
{
do
{
while ( 1 )
{
do
{
v4 = rand() % 81;
v5 = v4 / 9;
v6 = &a1[9 * (v4 % 9)];
v7 = v6[v4 / 9];
}
while ( !v7 );
v6[v5] = 0;
if ( (unsigned int)isUnique(a1) )
break;
v6[v5] = v7;
}
++v3;
}
while ( a2 != v3 );
}
}

original_code:
void generate(int grid[][9], int type){
    int i, valide, position, row, col, inter;
    resolve(grid, 0, 1);
    srand(time(((void *)0)));
    for(i=0;i<type;i++){
        valide = 0;
        do{
            position = rand() % 81;
            row = floor(position/9);
            col = position%9;
            if(grid[col][row] == 0) continue;
            inter = grid[col][row];
            grid[col][row] = 0;
            if(isUnique(grid)){valide = 1;}
            else{grid[col][row] = inter;}
        }while(!valide);
    }
}

canonical_original_code:
void generate(int grid[][9], int type){
    int i; int valide; int position; int row; int col; int inter;
    resolve(grid, 0, 1);
    srand(time(((void *)0)));
    for(i=0;i<type;i++){
        valide = 0;
        do{
            position = rand() % 81;
            row = floor(position/9);
            col = position%9;
            if(grid[col][row] == 0) continue;
            inter = grid[col][row];
            grid[col][row] = 0;
            if(isUnique(grid)){valide = 1;}
            else{grid[col][row] = inter;}
        }while(!valide);
    }
}

variable_types: type int

variable_types: valide int

variable_types: inter int


decompiled_code:
__int64 __fastcall is_grid_valid(__int64 a1)
{
int i; // ebp
int v2; // ebx
__int64 v3; // r15
unsigned int *v4; // r13
unsigned int v5; // er12

for ( i = 0; i != 81; ++i )
{
v2 = i / 9;
v3 = a1 + 36LL * (i % 9);
v4 = (unsigned int *)(v3 + 4LL * (i / 9));
v5 = *v4;
*v4 = 0;
if ( (!(unsigned int)absentDeBloc(v5, a1, (unsigned int)(i % 9), (unsigned int)(i / 9))
|| !(unsigned int)absentDeColonne(v5, a1, (unsigned int)v2)
|| !(unsigned int)absentDeLigne(v5, a1, (unsigned int)(i % 9)))
&& v5 )
{
*(_DWORD *)(v3 + 4LL * v2) = v5;
return 0LL;
}
*v4 = v5;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int i; // ebp
int v2; // ebx
__int64 v3; // r15
unsigned int *v4; // r13
unsigned int v5; // er12

for ( i = 0; i != 81; ++i )
{
v2 = i / 9;
v3 = a1 + 36LL * (i % 9);
v4 = (unsigned int *)(v3 + 4LL * (i / 9));
v5 = *v4;
*v4 = 0;
if ( (!(unsigned int)absentDeBloc(v5, a1, (unsigned int)(i % 9), (unsigned int)(i / 9))
|| !(unsigned int)absentDeColonne(v5, a1, (unsigned int)v2)
|| !(unsigned int)absentDeLigne(v5, a1, (unsigned int)(i % 9)))
&& v5 )
{
*(_DWORD *)(v3 + 4LL * v2) = v5;
return 0LL;
}
*v4 = v5;
}
return 1LL;
}

original_code:
int is_grid_valid(int grid[9][9]){
    int i = 0;
    int row,col;
    int value;
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        value = grid[col][row];
        grid[col][row] = 0;
        if((!absentDeBloc(value, grid, col, row) || !absentDeColonne(value, grid, row) || !absentDeLigne(value, grid, col)) && value != 0){
            grid[col][row] = value;
            return 0;
        }
        grid[col][row] = value;
    }
    return 1;
}

canonical_original_code:
int is_grid_valid(int grid[9][9]){
    int i = 0;
    int row; int col;
    int value;
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        value = grid[col][row];
        grid[col][row] = 0;
        if((!absentDeBloc(value, grid, col, row) || !absentDeColonne(value, grid, row) || !absentDeLigne(value, grid, col)) && value != 0){
            grid[col][row] = value;
            return 0;
        }
        grid[col][row] = value;
    }
    return 1;
}

variable_types:
grid
int [9][9]


original_code:
int equal_grid(int grid1[9][9], int grid2[9][9]){
    int i = 0;
    int row,col;
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid1[col][row] != grid2[col][row]){
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int equal_grid(int grid1[9][9], int grid2[9][9]){
    int i = 0;
    int row; int col;
     for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid1[col][row] != grid2[col][row]){
            return 0;
        }
    }
    return 1;
}


repo: cyrillos/compel

decompiled_code:
__int64 __fastcall task_in_compat_mode(unsigned int a1)
{
int *v1; // rbx
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v1 = _errno_location();
*v1 = 0;
v2 = ptrace(PTRACE_PEEKUSER, a1, 136LL, 0LL);
if ( *v1 )
{
print_on_level(1LL, "Error (%s:%d): Can't get CS register for %d: %m\n", "src/lib/arch/x86/ptrace.c", 29LL, a1);
result = 1LL;
}
else
{
v3 = v2;
v4 = ptrace(PTRACE_PEEKUSER, a1, 184LL, 0LL);
v5 = v4;
if ( *v1 )
{
print_on_level(1LL, "Error (%s:%d): Can't get DS register for %d: %m\n", "src/lib/arch/x86/ptrace.c", 36LL, a1);
result = 1LL;
}
else
{
LOBYTE(v4) = v3 != 51;
LOBYTE(v5) = v5 == 43;
result = (unsigned int)v5 | (unsigned int)v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int *v1; // rbx
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v1 = _errno_location();
*v1 = 0;
v2 = ptrace(PTRACE_PEEKUSER, a1, 136LL, 0LL);
if ( *v1 )
{
print_on_level(1LL, "Error (%s:%d): Can't get CS register for %d: %m\n", "src/lib/arch/x86/ptrace.c", 29LL, a1);
result = 1LL;
}
else
{
v3 = v2;
v4 = ptrace(PTRACE_PEEKUSER, a1, 184LL, 0LL);
v5 = v4;
if ( *v1 )
{
print_on_level(1LL, "Error (%s:%d): Can't get DS register for %d: %m\n", "src/lib/arch/x86/ptrace.c", 36LL, a1);
result = 1LL;
}
else
{
LOBYTE(v4) = v3 != 51;
LOBYTE(v5) = v5 == 43;
result = (unsigned int)v5 | (unsigned int)v4;
}
}
return result;
}

original_code:
_Bool task_in_compat_mode(pid_t pid)
{
 unsigned long cs, ds;
 (*__errno_location ()) = 0;
 cs = ptrace(PTRACE_PEEKUSER, pid, ((size_t) &((user_regs_struct_t *)0)->cs), 0);
 if ((*__errno_location ()) != 0) {
  print_on_level((1), "Error (%s:%d): " "Can't get CS register for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 29, pid);
  return -1;
 }
 (*__errno_location ()) = 0;
 ds = ptrace(PTRACE_PEEKUSER, pid, ((size_t) &((user_regs_struct_t *)0)->ds), 0);
 if ((*__errno_location ()) != 0) {
  print_on_level((1), "Error (%s:%d): " "Can't get DS register for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 36, pid);
  return -1;
 }
 return cs != 0x33 || ds == 0x2b;
}

canonical_original_code:
_Bool task_in_compat_mode(int pid)
{
 unsigned long cs; unsigned long ds;
 (*__errno_location ()) = 0;
 cs = ptrace(PTRACE_PEEKUSER, pid, ((unsigned long) &((struct user_regs_struct_t *)0)->cs), 0);
 if ((*__errno_location ()) != 0) {
  print_on_level((1), "Error (%s:%d): " "Can't get CS register for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 29, pid);
  return -1;
 }
 (*__errno_location ()) = 0;
 ds = ptrace(PTRACE_PEEKUSER, pid, ((unsigned long) &((struct user_regs_struct_t *)0)->ds), 0);
 if ((*__errno_location ()) != 0) {
  print_on_level((1), "Error (%s:%d): " "Can't get DS register for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 36, pid);
  return -1;
 }
 return cs != 0x33 || ds == 0x2b;
}

variable_types: pid int

variable_types:
cs
unsigned long

variable_types:
ds
unsigned long

user_defined_types: struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; }


decompiled_code:
__int64 __fastcall ptrace_get_fpu(unsigned int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a2;
v3[1] = 832LL;
if ( ptrace(PTRACE_GETREGSET, a1, 514LL, v3) < 0 )
{
if ( *_errno_location() == 19 && ptrace(PTRACE_GETFPREGS, a1, 0LL, a2) >= 0 )
{
*(_BYTE *)(a2 + 896) = 0;
result = 0LL;
}
else
{
print_on_level(
1LL,
"Error (%s:%d): Can't obtain FPU registers for %d: %m\n",
"src/lib/arch/x86/ptrace.c",
64LL,
a1);
result = 0xFFFFFFFFLL;
}
}
else
{
*(_BYTE *)(a2 + 896) = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a2;
v3[1] = 832LL;
if ( ptrace(PTRACE_GETREGSET, a1, 514LL, v3) < 0 )
{
if ( *_errno_location() == 19 && ptrace(PTRACE_GETFPREGS, a1, 0LL, a2) >= 0 )
{
*(_BYTE *)(a2 + 896) = 0;
result = 0LL;
}
else
{
print_on_level(
1LL,
"Error (%s:%d): Can't obtain FPU registers for %d: %m\n",
"src/lib/arch/x86/ptrace.c",
64LL,
a1);
result = 0xFFFFFFFFLL;
}
}
else
{
*(_BYTE *)(a2 + 896) = 1;
result = 0LL;
}
return result;
}

original_code:
int ptrace_get_fpu(pid_t pid, fpu_state_t *fpu)
{
 struct iovec iov = {
  .iov_base = &fpu->xsave,
  .iov_len = sizeof(fpu->xsave),
 };
 if (ptrace(PTRACE_GETREGSET, pid, (unsigned int)0x202, &iov) < 0) {
  if ((*__errno_location ()) != 19)
   goto fpuerr;
  else {
   if (ptrace(PTRACE_GETFPREGS, pid, ((void *)0), &fpu->xsave) < 0)
    goto fpuerr;
   fpu->has_xsave = 0;
  }
 } else
  fpu->has_xsave = 1;
 return 0;
fpuerr:
 print_on_level((1), "Error (%s:%d): " "Can't obtain FPU registers for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 64, pid);
 return -1;
}

canonical_original_code:
int ptrace_get_fpu(int pid, struct fpu_state_t *fpu)
{
 struct iovec iov = {
  .iov_base = &fpu->xsave,
  .iov_len = sizeof(fpu->xsave),
 };
 if (ptrace(PTRACE_GETREGSET, pid, (unsigned int)0x202, &iov) < 0) {
  if ((*__errno_location ()) != 19)
   goto fpuerr;
  else {
   if (ptrace(PTRACE_GETFPREGS, pid, ((void *)0), &fpu->xsave) < 0)
    goto fpuerr;
   fpu->has_xsave = 0;
  }
 } else
  fpu->has_xsave = 1;
 return 0;
fpuerr:
 print_on_level((1), "Error (%s:%d): " "Can't obtain FPU registers for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 64, pid);
 return -1;
}

variable_types: struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: struct fpu_state_t { union { struct xsave_struct xsave; unsigned char __pad[-1]; }; _Bool has_xsave; }

user_defined_types: struct xsave_struct { struct i387_fxsave_struct i387; struct xsave_hdr_struct xsave_hdr; struct ymmh_struct ymmh; }


decompiled_code:
__int64 __fastcall ptrace_set_fpu(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 832LL;
if ( *(_BYTE *)(a2 + 896) )
{
if ( ptrace(PTRACE_SETREGSET, a1, 514LL, v3) >= 0 )
return 0LL;
}
else if ( ptrace(PTRACE_SETFPREGS, a1, 0LL, a2) >= 0 )
{
return 0LL;
}
print_on_level(1LL, "Error (%s:%d): Can't set FPU registers for %d: %m\n", "src/lib/arch/x86/ptrace.c", 85LL, a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 832LL;
if ( *(_BYTE *)(a2 + 896) )
{
if ( ptrace(PTRACE_SETREGSET, a1, 514LL, v3) >= 0 )
return 0LL;
}
else if ( ptrace(PTRACE_SETFPREGS, a1, 0LL, a2) >= 0 )
{
return 0LL;
}
print_on_level(1LL, "Error (%s:%d): Can't set FPU registers for %d: %m\n", "src/lib/arch/x86/ptrace.c", 85LL, a1);
return 0xFFFFFFFFLL;
}

original_code:
int ptrace_set_fpu(pid_t pid, fpu_state_t *fpu)
{
 struct iovec iov = {
  .iov_base = &fpu->xsave,
  .iov_len = sizeof(fpu->xsave),
 };
 if (fpu->has_xsave) {
  if (ptrace(PTRACE_SETREGSET, pid, (unsigned int)0x202, &iov) < 0)
   goto fpuerr;
 } else {
  if (ptrace(PTRACE_SETFPREGS, pid, ((void *)0), &fpu->xsave) < 0)
   goto fpuerr;
 }
 return 0;
fpuerr:
 print_on_level((1), "Error (%s:%d): " "Can't set FPU registers for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 85, pid);
 return -1;
}

canonical_original_code:
int ptrace_set_fpu(int pid, struct fpu_state_t *fpu)
{
 struct iovec iov = {
  .iov_base = &fpu->xsave,
  .iov_len = sizeof(fpu->xsave),
 };
 if (fpu->has_xsave) {
  if (ptrace(PTRACE_SETREGSET, pid, (unsigned int)0x202, &iov) < 0)
   goto fpuerr;
 } else {
  if (ptrace(PTRACE_SETFPREGS, pid, ((void *)0), &fpu->xsave) < 0)
   goto fpuerr;
 }
 return 0;
fpuerr:
 print_on_level((1), "Error (%s:%d): " "Can't set FPU registers for %d" ": %m\n", "src/lib/arch/x86/ptrace.c", 85, pid);
 return -1;
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; }

user_defined_types: struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; }

user_defined_types: struct ymmh_struct { unsigned int ymmh_space[64]; }


original_code:
static int setup_load_headers(load_info_t *info)
{
 unsigned int i;
 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff;
 info->secstrings= (void *)info->hdr + info->sechdrs[info->hdr->e_shstrndx].sh_offset;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  if (info->sechdrs[i].sh_type == 2) {
   info->index.sym = i;
   info->index.str = info->sechdrs[i].sh_link;
   info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;
   break;
  } else if (info->sechdrs[i].sh_type == 1) {
   if (!strcmp(&info->secstrings[info->sechdrs[i].sh_name], ".compel.init")) {
    info->index.init = i;
   }
  }
 }
 if (info->index.sym == 0) {
  print_on_level((2), "Warn  (%s:%d): " "elf: " "Plugin has no symbols (stripped?)\n", "src/lib/arch/x86/elf.c", 287);
  return -8;
 }
 return 0;
}

canonical_original_code:
static int setup_load_headers(struct load_info_s *info)
{
 unsigned int i;
 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff;
 info->secstrings= (void *)info->hdr + info->sechdrs[info->hdr->e_shstrndx].sh_offset;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  if (info->sechdrs[i].sh_type == 2) {
   info->index.sym = i;
   info->index.str = info->sechdrs[i].sh_link;
   info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;
   break;
  } else if (info->sechdrs[i].sh_type == 1) {
   if (!strcmp(&info->secstrings[info->sechdrs[i].sh_name], ".compel.init")) {
    info->index.init = i;
   }
  }
 }
 if (info->index.sym == 0) {
  print_on_level((2), "Warn  (%s:%d): " "elf: " "Plugin has no symbols (stripped?)\n", "src/lib/arch/x86/elf.c", 287);
  return -8;
 }
 return 0;
}

variable_types: struct load_info_s { long addr_delta; struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *hdr; unsigned long len; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *sechdrs; char *secstrings; char *strtab; struct { unsigned int sym; unsigned int str; unsigned int symtab; unsigned int symtab_link; unsigned int init; } index; } *

variable_types:
i
unsigned int

user_defined_types: struct load_info_s { long addr_delta; struct Elf64_Ehdr *hdr; unsigned long len; struct Elf64_Shdr *sechdrs; char *secstrings; char *strtab; struct { unsigned int sym; unsigned int str; unsigned int symtab; unsigned int symtab_link; unsigned int init; } index; }


decompiled_code:
__int64 __fastcall rewrite_section_headers(_QWORD *a1)
{
__int64 v1; // rdx
unsigned int v2; // ecx
unsigned __int64 v3; // rax
unsigned __int64 v4; // r8

*(_QWORD *)(a1[3] + 16LL) = 0LL;
v1 = a1[1];
if ( *(_WORD *)(v1 + 60) <= 1u )
return 0LL;
v2 = 1;
do
{
v3 = a1[3] + ((unsigned __int64)v2 << 6);
if ( *(_DWORD *)(v3 + 4) != 8 )
{
v4 = a1[2];
if ( v4 < *(_QWORD *)(v3 + 24) + *(_QWORD *)(v3 + 32) )
{
print_on_level(1LL, "Error (%s:%d): elf: Plugin len %lu truncated\n", "src/lib/arch/x86/elf.c", 64LL, v4);
return 4294967288LL;
}
}
*(_QWORD *)(v3 + 16) = *(_QWORD *)(v3 + 24) + v1;
++v2;
v1 = a1[1];
}
while ( *(unsigned __int16 *)(v1 + 60) > v2 );
return 0LL;
}

original_code:
static int rewrite_section_headers(load_info_t *info)
{
 unsigned int i;
 info->sechdrs[0].sh_addr = 0;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  Elf64_Shdr *shdr = &info->sechdrs[i];
  if (shdr->sh_type != 8 &&
      info->len < shdr->sh_offset + shdr->sh_size) {
   print_on_level((1), "Error (%s:%d): " "elf: " "Plugin len %lu truncated\n", "src/lib/arch/x86/elf.c", 64, info->len);
   return -8;
  }
  shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
 }
 return 0;
}

canonical_original_code:
static int rewrite_section_headers(struct load_info_s *info)
{
 unsigned int i;
 info->sechdrs[0].sh_addr = 0;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  struct Elf64_Shdr *shdr = &info->sechdrs[i];
  if (shdr->sh_type != 8 &&
      info->len < shdr->sh_offset + shdr->sh_size) {
   print_on_level((1), "Error (%s:%d): " "elf: " "Plugin len %lu truncated\n", "src/lib/arch/x86/elf.c", 64, info->len);
   return -8;
  }
  shdr->sh_addr = (unsigned long)info->hdr + shdr->sh_offset;
 }
 return 0;
}

variable_types: struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *

user_defined_types: struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }


decompiled_code:
__int64 __fastcall simplify_symbols(__int64 a1)
{
unsigned __int64 v1; // r12
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // rcx
unsigned int *v6; // r9
const char *v7; // rdx
unsigned __int16 v8; // ax
__int64 v9; // rcx
__int64 v10; // r8

v1 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 48) << 6);
v2 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v1 + 32) <= 0x2FuLL )
return 0LL;
v3 = 1;
v4 = 1LL;
do
{
v6 = (unsigned int *)(v2 + 24 * v4);
v7 = (const char *)(*(_QWORD *)(a1 + 40) + *v6);
v8 = *((_WORD *)v6 + 3);
if ( v8 == 0xFFF1 )
{
print_on_level(4LL, "elf: Absolute symbol: %32s 0x%08lx\n", v7, *((_QWORD *)v6 + 1));
}
else
{
if ( v8 == 0xFFF2 )
{
print_on_level(4LL, "elf: Common symbol: %s\n", v7);
print_on_level(1LL, "Error (%s:%d): elf: Please compile with -fno-common\n", "src/lib/arch/x86/elf.c", 88LL);
return 4294967288LL;
}
if ( v8 )
{
v9 = *((_QWORD *)v6 + 1);
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + ((unsigned __int64)v8 << 6) + 16) + v9;
*((_QWORD *)v6 + 1) = v10;
print_on_level(4LL, "elf: sym %32s %8lx -> %8lx\n", v7, v9, v10);
}
else
{
if ( strcmp((const char *)(*(_QWORD *)(a1 + 40) + *v6), "_GLOBAL_OFFSET_TABLE_") )
{
print_on_level(
1LL,
"Error (%s:%d): elf: Unknown symbol: %32s 0x%08lx\n",
"src/lib/arch/x86/elf.c",
96LL,
v7,
*((_QWORD *)v6 + 1));
return 4294967294LL;
}
print_on_level(4LL, "elf: Undef symbol: %32s 0x%08lx\n", v7, *((_QWORD *)v6 + 1));
}
}
v4 = ++v3;
}
while ( v3 < *(_QWORD *)(v1 + 32) / 0x18uLL );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // r12
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // rcx
unsigned int *v6; // r9
const char *v7; // rdx
unsigned __int16 v8; // ax
__int64 v9; // rcx
__int64 v10; // r8

v1 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 48) << 6);
v2 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v1 + 32) <= 0x2FuLL )
return 0LL;
v3 = 1;
v4 = 1LL;
do
{
v6 = (unsigned int *)(v2 + 24 * v4);
v7 = (const char *)(*(_QWORD *)(a1 + 40) + *v6);
v8 = *((_WORD *)v6 + 3);
if ( v8 == 0xFFF1 )
{
print_on_level(4LL, "elf: Absolute symbol: %32s 0x%08lx\n", v7, *((_QWORD *)v6 + 1));
}
else
{
if ( v8 == 0xFFF2 )
{
print_on_level(4LL, "elf: Common symbol: %s\n", v7);
print_on_level(1LL, "Error (%s:%d): elf: Please compile with -fno-common\n", "src/lib/arch/x86/elf.c", 88LL);
return 4294967288LL;
}
if ( v8 )
{
v9 = *((_QWORD *)v6 + 1);
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + ((unsigned __int64)v8 << 6) + 16) + v9;
*((_QWORD *)v6 + 1) = v10;
print_on_level(4LL, "elf: sym %32s %8lx -> %8lx\n", v7, v9, v10);
}
else
{
if ( strcmp((const char *)(*(_QWORD *)(a1 + 40) + *v6), "_GLOBAL_OFFSET_TABLE_") )
{
print_on_level(
1LL,
"Error (%s:%d): elf: Unknown symbol: %32s 0x%08lx\n",
"src/lib/arch/x86/elf.c",
96LL,
v7,
*((_QWORD *)v6 + 1));
return 4294967294LL;
}
print_on_level(4LL, "elf: Undef symbol: %32s 0x%08lx\n", v7, *((_QWORD *)v6 + 1));
}
}
v4 = ++v3;
}
while ( v3 < *(_QWORD *)(v1 + 32) / 0x18uLL );
return 0LL;
}

original_code:
static int simplify_symbols(load_info_t *info)
{
 Elf64_Shdr *symsec = &info->sechdrs[info->index.sym];
 Elf64_Sym *sym = (void *)symsec->sh_addr;
 unsigned long secbase;
 unsigned int i;
 int ret = 0;
 for (i = 1; i < symsec->sh_size / sizeof(Elf64_Sym) && ret == 0; i++) {
  const char *name = info->strtab + sym[i].st_name;
  switch (sym[i].st_shndx) {
  case 0xfff2:
   print_on_level((4), "elf: " "Common symbol: %s\n", name);
   print_on_level((1), "Error (%s:%d): " "elf: " "Please compile with -fno-common\n", "src/lib/arch/x86/elf.c", 88);
   ret = -8;
   break;
  case 0xfff1:
   print_on_level((4), "elf: " "Absolute symbol: %32s 0x%08lx\n", name, (long)sym[i].st_value);
   break;
  case 0:
   if (strcmp(name, "_GLOBAL_OFFSET_TABLE_")) {
    print_on_level((1), "Error (%s:%d): " "elf: " "Unknown symbol: %32s 0x%08lx\n", "src/lib/arch/x86/elf.c", 96, name, (long)sym[i].st_value);
    ret = -2;
   } else
    print_on_level((4), "elf: " "Undef symbol: %32s 0x%08lx\n", name, (long)sym[i].st_value);
   break;
  default:
   secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
   sym[i].st_value += secbase;
   print_on_level((4), "elf: " "sym %32s %8lx -> %8lx\n", name, sym[i].st_value - secbase, sym[i].st_value);
   break;
  }
 }
 return ret;
}

canonical_original_code:
static int simplify_symbols(struct load_info_s *info)
{
 struct Elf64_Shdr *symsec = &info->sechdrs[info->index.sym];
 struct Elf64_Sym *sym = (void *)symsec->sh_addr;
 unsigned long secbase;
 unsigned int i;
 int ret = 0;
 for (i = 1; i < symsec->sh_size / sizeof(Elf64_Sym) && ret == 0; i++) {
  char *name = info->strtab + sym[i].st_name;
  switch (sym[i].st_shndx) {
  case 0xfff2:
   print_on_level((4), "elf: " "Common symbol: %s\n", name);
   print_on_level((1), "Error (%s:%d): " "elf: " "Please compile with -fno-common\n", "src/lib/arch/x86/elf.c", 88);
   ret = -8;
   break;
  case 0xfff1:
   print_on_level((4), "elf: " "Absolute symbol: %32s 0x%08lx\n", name, (long)sym[i].st_value);
   break;
  case 0:
   if (strcmp(name, "_GLOBAL_OFFSET_TABLE_")) {
    print_on_level((1), "Error (%s:%d): " "elf: " "Unknown symbol: %32s 0x%08lx\n", "src/lib/arch/x86/elf.c", 96, name, (long)sym[i].st_value);
    ret = -2;
   } else
    print_on_level((4), "elf: " "Undef symbol: %32s 0x%08lx\n", name, (long)sym[i].st_value);
   break;
  default:
   secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
   sym[i].st_value += secbase;
   print_on_level((4), "elf: " "sym %32s %8lx -> %8lx\n", name, sym[i].st_value - secbase, sym[i].st_value);
   break;
  }
 }
 return ret;
}

variable_types: struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; } *

variable_types:
secbase
unsigned long

variable_types: ret int

variable_types:
name
char *

user_defined_types: struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; }


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

result = elf_header_check((__int64)a1);
if ( !(_DWORD)result )
{
result = setup_load_headers((__int64)a1);
if ( !(_DWORD)result )
{
result = rewrite_section_headers(a1);
if ( !(_DWORD)result )
result = simplify_symbols((__int64)a1);
}
}
return result;
}

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

result = func0((__int64)a1);
if ( !(_DWORD)result )
{
result = func1((__int64)a1);
if ( !(_DWORD)result )
{
result = func2(a1);
if ( !(_DWORD)result )
result = func3((__int64)a1);
}
}
return result;
}

original_code:
static int load_elf_headers(load_info_t *info)
{
 int err = 0;
 if (!err)
  err = elf_header_check(info);
 if (!err)
  err = setup_load_headers(info);
 if (!err)
  err = rewrite_section_headers(info);
 if (!err)
  err = simplify_symbols(info);
 return err;
}

canonical_original_code:
static int load_elf_headers(struct load_info_s *info)
{
 int err = 0;
 if (!err)
  err = elf_header_check(info);
 if (!err)
  err = setup_load_headers(info);
 if (!err)
  err = rewrite_section_headers(info);
 if (!err)
  err = simplify_symbols(info);
 return err;
}

variable_types: err int


decompiled_code:
__int64 __fastcall apply_relocations(__int64 a1)
{
unsigned int v1; // ecx
int v3; // esi
unsigned int v4; // ebx
__int64 v6; // rdi
unsigned __int64 v7; // rax
unsigned int v8; // edx
int v9; // eax

v1 = *(unsigned __int16 *)(*(_QWORD *)(a1 + 8) + 60LL);
if ( v1 <= 1 )
return 0LL;
v3 = 0;
v4 = 1;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 24);
v7 = v6 + ((unsigned __int64)v4 << 6);
v8 = *(_DWORD *)(v7 + 44);
if ( v8 >= v1 || (*(_BYTE *)(v6 + ((unsigned __int64)v8 << 6) + 8) & 2) == 0 )
goto LABEL_6;
v9 = *(_DWORD *)(v7 + 4);
if ( v9 == 9 )
break;
if ( v9 == 4 )
v3 = apply_relocate_add(v6, *(_QWORD *)(a1 + 40), *(_DWORD *)(a1 + 48), v4, *(_QWORD *)a1);
if ( v3 < 0 )
return (unsigned int)v3;
LABEL_6:
++v4;
v1 = *(unsigned __int16 *)(*(_QWORD *)(a1 + 8) + 60LL);
if ( v1 <= v4 )
return (unsigned int)v3;
}
print_on_level(1LL, "Error (%s:%d): elf: SHT_REL unsupported\n", "src/lib/arch/x86/elf.c", 207LL);
return (unsigned int)-22;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // ecx
int v3; // esi
unsigned int v4; // ebx
__int64 v6; // rdi
unsigned __int64 v7; // rax
unsigned int v8; // edx
int v9; // eax

v1 = *(unsigned __int16 *)(*(_QWORD *)(a1 + 8) + 60LL);
if ( v1 <= 1 )
return 0LL;
v3 = 0;
v4 = 1;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 24);
v7 = v6 + ((unsigned __int64)v4 << 6);
v8 = *(_DWORD *)(v7 + 44);
if ( v8 >= v1 || (*(_BYTE *)(v6 + ((unsigned __int64)v8 << 6) + 8) & 2) == 0 )
goto LABEL_6;
v9 = *(_DWORD *)(v7 + 4);
if ( v9 == 9 )
break;
if ( v9 == 4 )
v3 = func5(v6, *(_QWORD *)(a1 + 40), *(_DWORD *)(a1 + 48), v4, *(_QWORD *)a1);
if ( v3 < 0 )
return (unsigned int)v3;
LABEL_6:
++v4;
v1 = *(unsigned __int16 *)(*(_QWORD *)(a1 + 8) + 60LL);
if ( v1 <= v4 )
return (unsigned int)v3;
}
print_on_level(1LL, "Error (%s:%d): elf: SHT_REL unsupported\n", "src/lib/arch/x86/elf.c", 207LL);
return (unsigned int)-22;
}

original_code:
static int apply_relocations(const load_info_t *info)
{
 unsigned int i;
 int err = 0;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  unsigned int infosec = info->sechdrs[i].sh_info;
  if (infosec >= info->hdr->e_shnum)
   continue;
  if (!(info->sechdrs[infosec].sh_flags & (1 << 1)))
   continue;
  if (info->sechdrs[i].sh_type == 9) {
   print_on_level((1), "Error (%s:%d): " "elf: " "SHT_REL unsupported\n", "src/lib/arch/x86/elf.c", 207);
   err = -22;
  } else if (info->sechdrs[i].sh_type == 4)
   err = apply_relocate_add(info->sechdrs, info->strtab,
       info->index.sym, i,
       info->addr_delta);
  if (err < 0)
   break;
 }
 return err;
}

canonical_original_code:
static int apply_relocations(struct load_info_s *info)
{
 unsigned int i;
 int err = 0;
 for (i = 1; i < info->hdr->e_shnum; i++) {
  unsigned int infosec = info->sechdrs[i].sh_info;
  if (infosec >= info->hdr->e_shnum)
   continue;
  if (!(info->sechdrs[infosec].sh_flags & (1 << 1)))
   continue;
  if (info->sechdrs[i].sh_type == 9) {
   print_on_level((1), "Error (%s:%d): " "elf: " "SHT_REL unsupported\n", "src/lib/arch/x86/elf.c", 207);
   err = -22;
  } else if (info->sechdrs[i].sh_type == 4)
   err = apply_relocate_add(info->sechdrs, info->strtab,
       info->index.sym, i,
       info->addr_delta);
  if (err < 0)
   break;
 }
 return err;
}

variable_types:
infosec
unsigned int


decompiled_code:
__int64 __fastcall lookup_elf_plugin_symbol(__int64 a1, const char *a2, char a3)
{
unsigned __int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // r12
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int *v8; // rbp
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-48h]

v3 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 48) << 6);
v4 = *(_QWORD *)(v3 + 16);
if ( *(_QWORD *)(v3 + 32) <= 0x2FuLL )
return 0LL;
v5 = *(_QWORD *)(v3 + 32) / 0x18uLL;
v10 = *(_QWORD *)(a1 + 40);
v6 = 1;
v7 = 1LL;
while ( 1 )
{
v8 = (unsigned int *)(v4 + 24 * v7);
if ( !strcmp((const char *)(v10 + *v8), a2) )
break;
v7 = ++v6;
if ( v6 >= v5 )
return 0LL;
}
if ( a3 )
result = *((_QWORD *)v8 + 1);
else
result = *((_QWORD *)v8 + 1) + *(_QWORD *)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, char a3)
{
unsigned __int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // r12
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int *v8; // rbp
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-48h]

v3 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 48) << 6);
v4 = *(_QWORD *)(v3 + 16);
if ( *(_QWORD *)(v3 + 32) <= 0x2FuLL )
return 0LL;
v5 = *(_QWORD *)(v3 + 32) / 0x18uLL;
v10 = *(_QWORD *)(a1 + 40);
v6 = 1;
v7 = 1LL;
while ( 1 )
{
v8 = (unsigned int *)(v4 + 24 * v7);
if ( !strcmp((const char *)(v10 + *v8), a2) )
break;
v7 = ++v6;
if ( v6 >= v5 )
return 0LL;
}
if ( a3 )
result = *((_QWORD *)v8 + 1);
else
result = *((_QWORD *)v8 + 1) + *(_QWORD *)a1;
return result;
}

original_code:
unsigned long lookup_elf_plugin_symbol(load_info_t *info,
           const char *symbol_name,
           _Bool local)
{
 Elf64_Shdr *symsec = &info->sechdrs[info->index.sym];
 Elf64_Sym *sym = (void *)symsec->sh_addr;
 unsigned int i;
 for (i = 1; i < symsec->sh_size / sizeof(Elf64_Sym); i++) {
  const char *name = info->strtab + sym[i].st_name;
  if (!strcmp(name, symbol_name)) {
   if (local)
    return sym[i].st_value;
   else
    return sym[i].st_value + info->addr_delta;
  }
 }
 return 0;
}

canonical_original_code:
unsigned long lookup_elf_plugin_symbol(struct load_info_s *info, char *symbol_name, _Bool local)
{
 struct Elf64_Shdr *symsec = &info->sechdrs[info->index.sym];
 struct Elf64_Sym *sym = (void *)symsec->sh_addr;
 unsigned int i;
 for (i = 1; i < symsec->sh_size / sizeof(Elf64_Sym); i++) {
  char *name = info->strtab + sym[i].st_name;
  if (!strcmp(name, symbol_name)) {
   if (local)
    return sym[i].st_value;
   else
    return sym[i].st_value + info->addr_delta;
  }
 }
 return 0;
}

return_type: unsigned long

user_defined_types: struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; }


decompiled_code:
__int64 __fastcall fixup_init(__int64 a1)
{
unsigned __int64 v1; // rbp
_QWORD *v2; // rax
_QWORD *v3; // rax

v1 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 64) << 6);
if ( !*(_DWORD *)(a1 + 64) )
return 4294967294LL;
v2 = (_QWORD *)lookup_elf_plugin_symbol(a1, "__export_std_plugin_begin", 1);
if ( !v2 )
return 4294967294LL;
*v2 = *(_QWORD *)(v1 + 16) + *(_QWORD *)a1;
v3 = (_QWORD *)lookup_elf_plugin_symbol(a1, "__export_std_plugin_size", 1);
if ( !v3 )
return 4294967294LL;
*v3 = *(_QWORD *)(v1 + 32);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned __int64 v1; // rbp
_QWORD *v2; // rax
_QWORD *v3; // rax

v1 = *(_QWORD *)(a1 + 24) + ((unsigned __int64)*(unsigned int *)(a1 + 64) << 6);
if ( !*(_DWORD *)(a1 + 64) )
return 4294967294LL;
v2 = (_QWORD *)func7(a1, "__export_std_plugin_begin", 1);
if ( !v2 )
return 4294967294LL;
*v2 = *(_QWORD *)(v1 + 16) + *(_QWORD *)a1;
v3 = (_QWORD *)func7(a1, "__export_std_plugin_size", 1);
if ( !v3 )
return 4294967294LL;
*v3 = *(_QWORD *)(v1 + 32);
return 0LL;
}

original_code:
static int fixup_init(load_info_t *info)
{
 Elf64_Shdr *initsec = &info->sechdrs[info->index.init];
 unsigned long *where;
 if (!info->index.init)
  return -2;
 where = (void *)lookup_elf_plugin_symbol(info, "__export_std_plugin_begin", 1);
 if (!where)
  return -2;
 *where = (unsigned long)initsec->sh_addr + info->addr_delta;
 where = (void *)lookup_elf_plugin_symbol(info, "__export_std_plugin_size", 1);
 if (!where)
  return -2;
 *where = (unsigned long)initsec->sh_size;
 return 0;
}

canonical_original_code:
static int fixup_init(struct load_info_s *info)
{
 struct Elf64_Shdr *initsec = &info->sechdrs[info->index.init];
 unsigned long *where;
 if (!info->index.init)
  return -2;
 where = (void *)lookup_elf_plugin_symbol(info, "__export_std_plugin_begin", 1);
 if (!where)
  return -2;
 *where = (unsigned long)initsec->sh_addr + info->addr_delta;
 where = (void *)lookup_elf_plugin_symbol(info, "__export_std_plugin_size", 1);
 if (!where)
  return -2;
 *where = (unsigned long)initsec->sh_size;
 return 0;
}

variable_types:
where
unsigned long *


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

result = load_elf_headers(a1);
if ( !(_DWORD)result )
{
result = apply_relocations((__int64)a1);
if ( !(_DWORD)result )
result = fixup_init((__int64)a1);
}
return result;
}

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

result = func4(a1);
if ( !(_DWORD)result )
{
result = func6((__int64)a1);
if ( !(_DWORD)result )
result = func8((__int64)a1);
}
return result;
}

original_code:
int load_elf_plugin(load_info_t *info)
{
 int err = 0;
 if (!err)
  err = load_elf_headers(info);
 if (!err)
  err = apply_relocations(info);
 if (!err)
  err = fixup_init(info);
 return err;
}

canonical_original_code:
int load_elf_plugin(struct load_info_s *info)
{
 int err = 0;
 if (!err)
  err = load_elf_headers(info);
 if (!err)
  err = apply_relocations(info);
 if (!err)
  err = fixup_init(info);
 return err;
}


decompiled_code:
__int64 __fastcall verify_elf_packed(const char *a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct stat64 v5; // [rsp+0h] [rbp-F8h] BYREF
__int64 v6; // [rsp+90h] [rbp-68h] BYREF
void *addr; // [rsp+98h] [rbp-60h]
size_t v8; // [rsp+A0h] [rbp-58h]
__int64 v9; // [rsp+A8h] [rbp-50h]
__int64 v10; // [rsp+B0h] [rbp-48h]
__int64 v11; // [rsp+B8h] [rbp-40h]
__int64 v12; // [rsp+C0h] [rbp-38h]
__int64 v13; // [rsp+C8h] [rbp-30h]
__int64 v14; // [rsp+D0h] [rbp-28h]

v6 = 0LL;
addr = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v1 = open64(a1, 0);
if ( v1 < 0 )
{
print_on_level(1LL, "Error (%s:%d): elf: Can't open %s: %m\n", "src/lib/arch/x86/elf.c", 340LL, a1);
v3 = -1;
}
else
{
v2 = v1;
if ( fstat64(v1, &v5) )
{
print_on_level(
1LL,
"Error (%s:%d): elf: Failed to obtain statistics on %s: %m\n",
"src/lib/arch/x86/elf.c",
345LL,
a1);
v3 = -1;
}
else
{
v8 = v5.st_size;
addr = mmap64(0LL, v5.st_size, 3, 2, v2, 0LL);
if ( addr == (void *)-1LL )
{
print_on_level(1LL, "Error (%s:%d): elf: Can't map %s: %m\n", "src/lib/arch/x86/elf.c", 353LL, a1);
v3 = -1;
}
else
{
v3 = load_elf_headers(&v6);
}
}
munmap(addr, v8);
close(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct stat64 v5; // [rsp+0h] [rbp-F8h] BYREF
__int64 v6; // [rsp+90h] [rbp-68h] BYREF
void *addr; // [rsp+98h] [rbp-60h]
size_t v8; // [rsp+A0h] [rbp-58h]
__int64 v9; // [rsp+A8h] [rbp-50h]
__int64 v10; // [rsp+B0h] [rbp-48h]
__int64 v11; // [rsp+B8h] [rbp-40h]
__int64 v12; // [rsp+C0h] [rbp-38h]
__int64 v13; // [rsp+C8h] [rbp-30h]
__int64 v14; // [rsp+D0h] [rbp-28h]

v6 = 0LL;
addr = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v1 = open64(a1, 0);
if ( v1 < 0 )
{
print_on_level(1LL, "Error (%s:%d): elf: Can't open %s: %m\n", "src/lib/arch/x86/elf.c", 340LL, a1);
v3 = -1;
}
else
{
v2 = v1;
if ( fstat64(v1, &v5) )
{
print_on_level(
1LL,
"Error (%s:%d): elf: Failed to obtain statistics on %s: %m\n",
"src/lib/arch/x86/elf.c",
345LL,
a1);
v3 = -1;
}
else
{
v8 = v5.st_size;
addr = mmap64(0LL, v5.st_size, 3, 2, v2, 0LL);
if ( addr == (void *)-1LL )
{
print_on_level(1LL, "Error (%s:%d): elf: Can't map %s: %m\n", "src/lib/arch/x86/elf.c", 353LL, a1);
v3 = -1;
}
else
{
v3 = func4(&v6);
}
}
munmap(addr, v8);
close(v2);
}
return v3;
}

original_code:
int verify_elf_packed(char *path)
{
 int plugin_fd, ret = -1;
 load_info_t info = { };
 struct stat plugin_st;
 plugin_fd = open(path, 00);
 if (plugin_fd < 0) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Can't open %s" ": %m\n", "src/lib/arch/x86/elf.c", 340, path);
  return -1;
 }
 if (fstat(plugin_fd, &plugin_st)) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Failed to obtain statistics on %s" ": %m\n", "src/lib/arch/x86/elf.c", 345, path);
  goto err;
 }
 info.len = plugin_st.st_size;
 info.hdr = mmap(((void *)0), plugin_st.st_size, 0x1 | 0x2,
   0x02 | 0, plugin_fd, 0);
 if ((void *)info.hdr == ((void *) -1)) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Can't map %s" ": %m\n", "src/lib/arch/x86/elf.c", 353, path);
  goto err;
 }
 ret = load_elf_headers(&info);
 if (ret)
  goto err;
err:
 munmap((void *)info.hdr, info.len);
 close(plugin_fd);
 return ret;
}

canonical_original_code:
int verify_elf_packed(char *path)
{
 int plugin_fd; int ret = -1;
 struct load_info_s info = { };
 struct stat plugin_st;
 plugin_fd = open(path, 00);
 if (plugin_fd < 0) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Can't open %s" ": %m\n", "src/lib/arch/x86/elf.c", 340, path);
  return -1;
 }
 if (fstat(plugin_fd, &plugin_st)) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Failed to obtain statistics on %s" ": %m\n", "src/lib/arch/x86/elf.c", 345, path);
  goto err;
 }
 info.len = plugin_st.st_size;
 info.hdr = mmap(((void *)0), plugin_st.st_size, 0x1 | 0x2,
   0x02 | 0, plugin_fd, 0);
 if ((void *)info.hdr == ((void *) -1)) {
  print_on_level((1), "Error (%s:%d): " "elf: " "Can't map %s" ": %m\n", "src/lib/arch/x86/elf.c", 353, path);
  goto err;
 }
 ret = load_elf_headers(&info);
 if (ret)
  goto err;
err:
 munmap((void *)info.hdr, info.len);
 close(plugin_fd);
 return ret;
}

variable_types:
path
char *

variable_types: struct load_info_s { long addr_delta; struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *hdr; unsigned long len; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *sechdrs; char *secstrings; char *strtab; struct { unsigned int sym; unsigned int str; unsigned int symtab; unsigned int symtab_link; unsigned int init; } index; }

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall init_socket(struct sockaddr *a1)
{
__int64 result; // rax

result = sys_socket(1, 5, 0);
ctl_socket = result;
if ( (int)result >= 0 )
{
result = sys_connect(result, a1, *(_DWORD *)&a1[7].sa_family);
if ( (int)result > 0 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct sockaddr *a1)
{
__int64 result; // rax

result = sys_socket(1, 5, 0);
ctl_socket = result;
if ( (int)result >= 0 )
{
result = sys_connect(result, a1, *(_DWORD *)&a1[7].sa_family);
if ( (int)result > 0 )
result = 0LL;
}
return result;
}

original_code:
static int init_socket(struct prologue_init_args *args)
{
 int ret;
 ctl_socket = sys_socket(1, SOCK_SEQPACKET, 0);
 if (ctl_socket < 0)
  return ctl_socket;
 ret = sys_connect(ctl_socket, (struct sockaddr *)&args->ctl_sock_addr, args->ctl_sock_addr_len);
 if (ret < 0)
  return ret;
 return 0;
}

variable_types: struct prologue_init_args { struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } ctl_sock_addr; unsigned int ctl_sock_addr_len; unsigned int arg_s; void *arg_p; void *sigframe; } *

user_defined_types: struct prologue_init_args { struct sockaddr_un ctl_sock_addr; unsigned int ctl_sock_addr_len; unsigned int arg_s; void *arg_p; void *sigframe; }

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


decompiled_code:
__int64 std_ctl_sock()
{
return ctl_socket;
}

canonical_decompiled_code:
__int64 func2()
{
return ctl_socket;
}

original_code:
int std_ctl_sock(void)
{
 return ctl_socket;
}

canonical_original_code:
int std_ctl_sock()
{
 return ctl_socket;
}


original_code:
int parasite_syscall_seized(parasite_ctl_t *ctl,
       int nr, unsigned long *ret,
       unsigned long arg1,
       unsigned long arg2,
       unsigned long arg3,
       unsigned long arg4,
       unsigned long arg5,
       unsigned long arg6)
{
 user_regs_struct_t regs = ctl->thread_ctx_orig.regs;
 int err;
 regs.ax = (unsigned long)nr;
 regs.di = arg1;
 regs.si = arg2;
 regs.dx = arg3;
 regs.r10 = arg4;
 regs.r8 = arg5;
 regs.r9 = arg6;
 err = parasite_execute_syscall_trap(ctl, &regs);
 *ret = regs.ax;
 return err;
}

canonical_original_code:
int parasite_syscall_seized(struct parasite_ctl_s *ctl, int nr, unsigned long *ret, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6)
{
 struct user_regs_struct_t regs = ctl->thread_ctx_orig.regs;
 int err;
 regs.ax = (unsigned long)nr;
 regs.di = arg1;
 regs.si = arg2;
 regs.dx = arg3;
 regs.r10 = arg4;
 regs.r8 = arg5;
 regs.r9 = arg6;
 err = parasite_execute_syscall_trap(ctl, &regs);
 *ret = regs.ax;
 return err;
}

variable_types: struct parasite_ctl_s { int pid; int task_state; unsigned long syscall_ip; unsigned long entry_ip; int ctl_sock; int ctl_accepted; struct thread_ctx_t { struct k_rtsigset_t { unsigned long sig[-1]; } sigmask; struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } regs; struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } fpu; } thread_ctx_orig; unsigned char code_orig[8]; void *remote_map; void *local_map; unsigned long map_length; } *

variable_types: nr int

variable_types:
ret
unsigned long *

user_defined_types: struct parasite_ctl_s { int pid; int task_state; unsigned long syscall_ip; unsigned long entry_ip; int ctl_sock; int ctl_accepted; struct thread_ctx_t thread_ctx_orig; unsigned char code_orig[8]; void *remote_map; void *local_map; unsigned long map_length; }

user_defined_types: struct thread_ctx_t { struct k_rtsigset_t sigmask; struct user_regs_struct_t regs; struct fpu_state_t fpu; }


original_code:
void parasite_fixup_thread_ctx(thread_ctx_t *ctx)
{
 if ((int)ctx->regs.orig_ax >= 0) {
  switch ((int)ctx->regs.ax) {
  case -514:
  case -512:
  case -513:
   ctx->regs.ax = ctx->regs.orig_ax;
   ctx->regs.ip -= 2;
   break;
  case -516:
   ctx->regs.ax = 219;
   ctx->regs.ip -= 2;
   break;
  }
 }
}

canonical_original_code:
void parasite_fixup_thread_ctx(struct thread_ctx_t *ctx)
{
 if ((int)ctx->regs.orig_ax >= 0) {
  switch ((int)ctx->regs.ax) {
  case -514:
  case -512:
  case -513:
   ctx->regs.ax = ctx->regs.orig_ax;
   ctx->regs.ip -= 2;
   break;
  case -516:
   ctx->regs.ax = 219;
   ctx->regs.ip -= 2;
   break;
  }
 }
}

variable_types: struct thread_ctx_t { struct k_rtsigset_t { unsigned long sig[-1]; } sigmask; struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } regs; struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } fpu; } *


original_code:
void parasite_prepare_sigframe(parasite_ctl_t *c, unsigned long sigframe_at)
{
 rt_sigframe_t *sigframe;
 sigframe = (void *)sigframe_at;
 memset(sigframe, 0, sizeof(*sigframe));
 sigframe->uc.uc_mcontext.r8 = c->thread_ctx_orig.regs.r8;
 sigframe->uc.uc_mcontext.r9 = c->thread_ctx_orig.regs.r9;
 sigframe->uc.uc_mcontext.r10 = c->thread_ctx_orig.regs.r10;
 sigframe->uc.uc_mcontext.r11 = c->thread_ctx_orig.regs.r11;
 sigframe->uc.uc_mcontext.r12 = c->thread_ctx_orig.regs.r12;
 sigframe->uc.uc_mcontext.r13 = c->thread_ctx_orig.regs.r13;
 sigframe->uc.uc_mcontext.r14 = c->thread_ctx_orig.regs.r14;
 sigframe->uc.uc_mcontext.r15 = c->thread_ctx_orig.regs.r15;
 sigframe->uc.uc_mcontext.rdi = c->thread_ctx_orig.regs.di;
 sigframe->uc.uc_mcontext.rsi = c->thread_ctx_orig.regs.si;
 sigframe->uc.uc_mcontext.rbp = c->thread_ctx_orig.regs.bp;
 sigframe->uc.uc_mcontext.rbx = c->thread_ctx_orig.regs.bx;
 sigframe->uc.uc_mcontext.rdx = c->thread_ctx_orig.regs.dx;
 sigframe->uc.uc_mcontext.rax = c->thread_ctx_orig.regs.ax;
 sigframe->uc.uc_mcontext.rcx = c->thread_ctx_orig.regs.cx;
 sigframe->uc.uc_mcontext.rsp = c->thread_ctx_orig.regs.sp;
 sigframe->uc.uc_mcontext.rip = c->thread_ctx_orig.regs.ip;
 sigframe->uc.uc_mcontext.eflags = c->thread_ctx_orig.regs.flags;
 sigframe->uc.uc_mcontext.cs = c->thread_ctx_orig.regs.cs;
 sigframe->uc.uc_mcontext.gs = c->thread_ctx_orig.regs.gs;
 sigframe->uc.uc_mcontext.fs = c->thread_ctx_orig.regs.fs;
 sigframe->uc.uc_sigmask = c->thread_ctx_orig.sigmask;
 sigframe->fpu_state = c->thread_ctx_orig.fpu;
}

canonical_original_code:
void parasite_prepare_sigframe(struct parasite_ctl_s *c, unsigned long sigframe_at)
{
 struct rt_sigframe *sigframe;
 sigframe = (void *)sigframe_at;
 memset(sigframe, 0, sizeof(*sigframe));
 sigframe->uc.uc_mcontext.r8 = c->thread_ctx_orig.regs.r8;
 sigframe->uc.uc_mcontext.r9 = c->thread_ctx_orig.regs.r9;
 sigframe->uc.uc_mcontext.r10 = c->thread_ctx_orig.regs.r10;
 sigframe->uc.uc_mcontext.r11 = c->thread_ctx_orig.regs.r11;
 sigframe->uc.uc_mcontext.r12 = c->thread_ctx_orig.regs.r12;
 sigframe->uc.uc_mcontext.r13 = c->thread_ctx_orig.regs.r13;
 sigframe->uc.uc_mcontext.r14 = c->thread_ctx_orig.regs.r14;
 sigframe->uc.uc_mcontext.r15 = c->thread_ctx_orig.regs.r15;
 sigframe->uc.uc_mcontext.rdi = c->thread_ctx_orig.regs.di;
 sigframe->uc.uc_mcontext.rsi = c->thread_ctx_orig.regs.si;
 sigframe->uc.uc_mcontext.rbp = c->thread_ctx_orig.regs.bp;
 sigframe->uc.uc_mcontext.rbx = c->thread_ctx_orig.regs.bx;
 sigframe->uc.uc_mcontext.rdx = c->thread_ctx_orig.regs.dx;
 sigframe->uc.uc_mcontext.rax = c->thread_ctx_orig.regs.ax;
 sigframe->uc.uc_mcontext.rcx = c->thread_ctx_orig.regs.cx;
 sigframe->uc.uc_mcontext.rsp = c->thread_ctx_orig.regs.sp;
 sigframe->uc.uc_mcontext.rip = c->thread_ctx_orig.regs.ip;
 sigframe->uc.uc_mcontext.eflags = c->thread_ctx_orig.regs.flags;
 sigframe->uc.uc_mcontext.cs = c->thread_ctx_orig.regs.cs;
 sigframe->uc.uc_mcontext.gs = c->thread_ctx_orig.regs.gs;
 sigframe->uc.uc_mcontext.fs = c->thread_ctx_orig.regs.fs;
 sigframe->uc.uc_sigmask = c->thread_ctx_orig.sigmask;
 sigframe->fpu_state = c->thread_ctx_orig.fpu;
}

variable_types: struct rt_sigframe { char *pretcode; struct rt_ucontext { unsigned long uc_flags; struct rt_ucontext *uc_link; struct rt_sigaltstack { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct rt_sigcontext { unsigned long r8; unsigned long r9; unsigned long r10; unsigned long r11; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rdi; unsigned long rsi; unsigned long rbp; unsigned long rbx; unsigned long rdx; unsigned long rax; unsigned long rcx; unsigned long rsp; unsigned long rip; unsigned long eflags; unsigned short cs; unsigned short gs; unsigned short fs; unsigned short __pad0; unsigned long err; unsigned long trapno; unsigned long oldmask; unsigned long cr2; void *fpstate; unsigned long reserved1[8]; } uc_mcontext; struct k_rtsigset_t { unsigned long sig[-1]; } uc_sigmask; int __unused[-1]; unsigned long uc_regspace[128]; } uc; struct rt_siginfo { int si_signo; int si_errno; int si_code; int _pad[-1]; } info; struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } fpu_state; } *

user_defined_types: struct rt_sigframe { char *pretcode; struct rt_ucontext uc; struct rt_siginfo info; struct fpu_state_t fpu_state; }

user_defined_types: struct rt_ucontext { unsigned long uc_flags; struct rt_ucontext *uc_link; struct rt_sigaltstack uc_stack; struct rt_sigcontext uc_mcontext; struct k_rtsigset_t uc_sigmask; int __unused[-1]; unsigned long uc_regspace[128]; }


original_code:
unsigned long std_strtoul(const char *nptr, char **endptr, int base)
{
 const char *s = nptr;
 _Bool neg = 0;
 unsigned int v;
 long num = 0;
 if (base < 0 || base == 1 || base > 36)
  goto fin;
 while (__isspace(*s))
  s++;
 if (!*s)
  goto fin;
 if (*s == '-')
  neg = 1, s++;
 if (base == 0) {
  if (s[0] == '0') {
   unsigned char p = __tolower(s[1]);
   switch (p) {
   case 'b':
    base = 2, s += 2;
    break;
   case 'x':
    base = 16, s += 2;
    break;
   default:
    base = 8, s += 1;
    break;
   }
  } else
   base = 10;
 } else if (base == 16) {
  if (s[0] == '0' && __tolower(s[1]) == 'x')
   s += 2;
 }
 for (; *s; s++) {
  if (__isspace(*s))
   continue;
  if (!__isalnum(*s))
      goto fin;
  v = __conv_val(*s);
  if (v == -1u || v > base)
   goto fin;
  num *= base;
  num += v;
 }
fin:
 if (endptr)
  *endptr = (char *)s;
 return neg ? (unsigned long)-num : (unsigned long)num;
}

canonical_original_code:
unsigned long std_strtoul(char *nptr, char **endptr, int base)
{
 char *s = nptr;
 _Bool neg = 0;
 unsigned int v;
 long num = 0;
 if (base < 0 || base == 1 || base > 36)
  goto fin;
 while (__isspace(*s))
  s++;
 if (!*s)
  goto fin;
 if (*s == '-')
  neg = 1, s++;
 if (base == 0) {
  if (s[0] == '0') {
   unsigned char p = __tolower(s[1]);
   switch (p) {
   case 'b':
    base = 2, s += 2;
    break;
   case 'x':
    base = 16, s += 2;
    break;
   default:
    base = 8, s += 1;
    break;
   }
  } else
   base = 10;
 } else if (base == 16) {
  if (s[0] == '0' && __tolower(s[1]) == 'x')
   s += 2;
 }
 for (; *s; s++) {
  if (__isspace(*s))
   continue;
  if (!__isalnum(*s))
      goto fin;
  v = __conv_val(*s);
  if (v == -1u || v > base)
   goto fin;
  num *= base;
  num += v;
 }
fin:
 if (endptr)
  *endptr = (char *)s;
 return neg ? (unsigned long)-num : (unsigned long)num;
}

variable_types:
nptr
char *

variable_types:
endptr
char **

variable_types: base int

variable_types:
s
char *

variable_types:
v
unsigned int

variable_types: num long

variable_types:
p
unsigned char


decompiled_code:
__int64 __fastcall std_memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v6; // edx

if ( !a3 )
return 0;
for ( i = 0LL; i != a3; ++i )
{
v6 = *(unsigned __int8 *)(a1 + i) - *(unsigned __int8 *)(a2 + i);
if ( v6 )
break;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v6; // edx

if ( !a3 )
return 0;
for ( i = 0LL; i != a3; ++i )
{
v6 = *(unsigned __int8 *)(a1 + i) - *(unsigned __int8 *)(a2 + i);
if ( v6 )
break;
}
return v6;
}

original_code:
int std_memcmp(const void *cs, const void *ct, size_t count)
{
 const unsigned char *su1, *su2;
 int res = 0;
 for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
  if ((res = *su1 - *su2) != 0)
   break;
 return res;
}

canonical_original_code:
int std_memcmp(void *cs, void *ct, unsigned long count)
{
 unsigned char *su1; unsigned char *su2;
 int res = 0;
 for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
  if ((res = *su1 - *su2) != 0)
   break;
 return res;
}

variable_types:
cs
void *

variable_types:
ct
void *

variable_types:
count
unsigned long

variable_types: res int


decompiled_code:
__int64 __fastcall std_strcmp(__int64 a1, __int64 a2)
{
__int64 i; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl

for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
v4 = *(_BYTE *)(a2 + i);
if ( v3 != v4 )
break;
if ( !v3 )
return 0LL;
}
return v3 < v4 ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 i; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl

for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
v4 = *(_BYTE *)(a2 + i);
if ( v3 != v4 )
break;
if ( !v3 )
return 0LL;
}
return v3 < v4 ? -1 : 1;
}

original_code:
int std_strcmp(const char *cs, const char *ct)
{
 unsigned char c1, c2;
 while (1) {
  c1 = *cs++;
  c2 = *ct++;
  if (c1 != c2)
   return c1 < c2 ? -1 : 1;
  if (!c1)
   break;
 }
 return 0;
}

canonical_original_code:
int std_strcmp(char *cs, char *ct)
{
 unsigned char c1; unsigned char c2;
 while (1) {
  c1 = *cs++;
  c2 = *ct++;
  if (c1 != c2)
   return c1 < c2 ? -1 : 1;
  if (!c1)
   break;
 }
 return 0;
}

variable_types:
cs
char *

variable_types:
ct
char *


decompiled_code:
__int64 __fastcall unseize_task(__pid_t pid, unsigned int a2)
{
print_on_level(4LL, "\tUnseizing %d into %d\n", (unsigned int)pid, a2);
if ( a2 == 2 )
{
kill(pid, 9);
}
else if ( a2 == 3 )
{
kill(pid, 19);
}
else if ( a2 != 1 )
{
print_on_level(1LL, "Error (%s:%d): Unknown final state %d\n", "src/lib/ptrace.c", 31LL, a2);
}
return ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__pid_t pid, unsigned int a2)
{
print_on_level(4LL, "\tUnseizing %d into %d\n", (unsigned int)pid, a2);
if ( a2 == 2 )
{
kill(pid, 9);
}
else if ( a2 == 3 )
{
kill(pid, 19);
}
else if ( a2 != 1 )
{
print_on_level(1LL, "Error (%s:%d): Unknown final state %d\n", "src/lib/ptrace.c", 31LL, a2);
}
return ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
}

original_code:
int unseize_task(pid_t pid, int state)
{
 print_on_level((4), "\tUnseizing %d into %d\n", pid, state);
 if (state == 0x2)
  kill(pid, 9);
 else if (state == 0x3)
  kill(pid, 19);
 else if (state == 0x1)
                   ;
 else
  print_on_level((1), "Error (%s:%d): " "Unknown final state %d\n", "src/lib/ptrace.c", 31, state);
 return ptrace(PTRACE_DETACH, pid, ((void *)0), ((void *)0));
}

canonical_original_code:
int unseize_task(int pid, int state)
{
 print_on_level((4), "\tUnseizing %d into %d\n", pid, state);
 if (state == 0x2)
  kill(pid, 9);
 else if (state == 0x3)
  kill(pid, 19);
 else if (state == 0x1)
                   ;
 else
  print_on_level((1), "Error (%s:%d): " "Unknown final state %d\n", "src/lib/ptrace.c", 31, state);
 return ptrace(PTRACE_DETACH, pid, ((void *)0), ((void *)0));
}

variable_types: pid int

variable_types: state int


decompiled_code:
__int64 __fastcall seize_task(__pid_t pid)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__pid_t v4; // eax
unsigned int v5; // [rsp+0h] [rbp-A8h] BYREF
char v6; // [rsp+9h] [rbp-9Fh]
__WAIT_STATUS stat_loc; // [rsp+8Ch] [rbp-1Ch] BYREF

if ( (int)ptrace(PTRACE_SEIZE, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't seize task: %m\n", "src/lib/ptrace.c", 50LL, (unsigned int)pid);
return 0xFFFFFFFFLL;
}
if ( (int)ptrace(PTRACE_INTERRUPT, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't interrupt task: %m\n",
"src/lib/ptrace.c",
56LL,
(unsigned int)pid);
LABEL_13:
unseize_task(pid, 3u);
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v1 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
v2 = v1;
if ( (v1 & 0x80000000) != 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", 63LL, (unsigned int)pid);
goto LABEL_13;
}
if ( pid != v1 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: wrong task attached (%d)\n",
"src/lib/ptrace.c",
68LL,
(unsigned int)pid,
v1);
goto LABEL_13;
}
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73LL, v1);
goto LABEL_13;
}
if ( (int)ptrace(PTRACE_GETSIGINFO, v1, 0LL, &v5) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't read signfo: %m\n", "src/lib/ptrace.c", 79LL, v2);
goto LABEL_13;
}
if ( v6 == (char)0x80 )
break;
if ( ptrace(PTRACE_CONT, v2, 0LL, (int)v5) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't continue signal handling. Aborting: %m\n",
"src/lib/ptrace.c",
91LL,
v2);
goto LABEL_13;
}
}
result = 1LL;
if ( v5 != 5 )
{
if ( v5 != 19 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132LL, v2, v5);
goto LABEL_13;
}
if ( (unsigned int)ptrace(PTRACE_CONT, v2, 0LL, 0LL) )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: unable to start process: %m\n", "src/lib/ptrace.c", 109LL, v2);
goto LABEL_13;
}
v4 = wait4(v2, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
if ( v4 < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", 115LL, v2);
goto LABEL_13;
}
if ( v2 != v4 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: wrong task attached (%d)\n",
"src/lib/ptrace.c",
120LL,
v2,
(unsigned int)v4);
goto LABEL_13;
}
result = 3LL;
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125LL, v2);
goto LABEL_13;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__pid_t pid)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__pid_t v4; // eax
unsigned int v5; // [rsp+0h] [rbp-A8h] BYREF
char v6; // [rsp+9h] [rbp-9Fh]
__WAIT_STATUS stat_loc; // [rsp+8Ch] [rbp-1Ch] BYREF

if ( (int)ptrace(PTRACE_SEIZE, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't seize task: %m\n", "src/lib/ptrace.c", 50LL, (unsigned int)pid);
return 0xFFFFFFFFLL;
}
if ( (int)ptrace(PTRACE_INTERRUPT, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't interrupt task: %m\n",
"src/lib/ptrace.c",
56LL,
(unsigned int)pid);
LABEL_13:
func0(pid, 3u);
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v1 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
v2 = v1;
if ( (v1 & 0x80000000) != 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", 63LL, (unsigned int)pid);
goto LABEL_13;
}
if ( pid != v1 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: wrong task attached (%d)\n",
"src/lib/ptrace.c",
68LL,
(unsigned int)pid,
v1);
goto LABEL_13;
}
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73LL, v1);
goto LABEL_13;
}
if ( (int)ptrace(PTRACE_GETSIGINFO, v1, 0LL, &v5) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't read signfo: %m\n", "src/lib/ptrace.c", 79LL, v2);
goto LABEL_13;
}
if ( v6 == (char)0x80 )
break;
if ( ptrace(PTRACE_CONT, v2, 0LL, (int)v5) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't continue signal handling. Aborting: %m\n",
"src/lib/ptrace.c",
91LL,
v2);
goto LABEL_13;
}
}
result = 1LL;
if ( v5 != 5 )
{
if ( v5 != 19 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132LL, v2, v5);
goto LABEL_13;
}
if ( (unsigned int)ptrace(PTRACE_CONT, v2, 0LL, 0LL) )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: unable to start process: %m\n", "src/lib/ptrace.c", 109LL, v2);
goto LABEL_13;
}
v4 = wait4(v2, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
if ( v4 < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", 115LL, v2);
goto LABEL_13;
}
if ( v2 != v4 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: wrong task attached (%d)\n",
"src/lib/ptrace.c",
120LL,
v2,
(unsigned int)v4);
goto LABEL_13;
}
result = 3LL;
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125LL, v2);
goto LABEL_13;
}
}
return result;
}

original_code:
int seize_task(pid_t pid)
{
 int status, ret;
 siginfo_t si;
 ret = ptrace(PTRACE_SEIZE, pid, ((void *)0), 0);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't seize task" ": %m\n", "src/lib/ptrace.c", 50, pid);
  return -1;
 }
 ret = ptrace(PTRACE_INTERRUPT, pid, ((void *)0), ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't interrupt task" ": %m\n", "src/lib/ptrace.c", 56, pid);
  goto err;
 }
try_again:
 ret = wait4(pid, &status, 0x40000000, ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 63, pid);
  goto err;
 }
 if (ret != pid) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 68, pid, ret);
  goto err;
 }
 if (!(((status) & 0xff) == 0x7f)) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73, pid);
  goto err;
 }
 ret = ptrace(PTRACE_GETSIGINFO, pid, ((void *)0), &si);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't read signfo" ": %m\n", "src/lib/ptrace.c", 79, pid);
  goto err;
 }
 if ((((si.si_code) & 0xFFFF) >> 8) != 128) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), (void *)(unsigned long)si.si_signo)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't continue signal handling. Aborting" ": %m\n", "src/lib/ptrace.c", 91, pid);
   goto err;
  }
  goto try_again;
 }
 if (si.si_signo == 5)
  return 0x1;
 else if (si.si_signo == 19) {
  ret = ptrace(PTRACE_CONT, pid, 0, 0);
  if (ret) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: unable to start process" ": %m\n", "src/lib/ptrace.c", 109, pid);
   goto err;
  }
  ret = wait4(pid, &status, 0x40000000, ((void *)0));
  if (ret < 0) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 115, pid);
   goto err;
  }
  if (ret != pid) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 120, pid, ret);
   goto err;
  }
  if (!(((status) & 0xff) == 0x7f)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125, pid);
   goto err;
  }
  return 0x3;
 }
 print_on_level((1), "Error (%s:%d): " "SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132, pid, si.si_signo);
err:
 unseize_task(pid, 0x3);
 return -1;
}

canonical_original_code:
int seize_task(int pid)
{
 int status; int ret;
 struct siginfo_t si;
 ret = ptrace(PTRACE_SEIZE, pid, ((void *)0), 0);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't seize task" ": %m\n", "src/lib/ptrace.c", 50, pid);
  return -1;
 }
 ret = ptrace(PTRACE_INTERRUPT, pid, ((void *)0), ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't interrupt task" ": %m\n", "src/lib/ptrace.c", 56, pid);
  goto err;
 }
try_again:
 ret = wait4(pid, &status, 0x40000000, ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 63, pid);
  goto err;
 }
 if (ret != pid) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 68, pid, ret);
  goto err;
 }
 if (!(((status) & 0xff) == 0x7f)) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73, pid);
  goto err;
 }
 ret = ptrace(PTRACE_GETSIGINFO, pid, ((void *)0), &si);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't read signfo" ": %m\n", "src/lib/ptrace.c", 79, pid);
  goto err;
 }
 if ((((si.si_code) & 0xFFFF) >> 8) != 128) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), (void *)(unsigned long)si.si_signo)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't continue signal handling. Aborting" ": %m\n", "src/lib/ptrace.c", 91, pid);
   goto err;
  }
  goto try_again;
 }
 if (si.si_signo == 5)
  return 0x1;
 else if (si.si_signo == 19) {
  ret = ptrace(PTRACE_CONT, pid, 0, 0);
  if (ret) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: unable to start process" ": %m\n", "src/lib/ptrace.c", 109, pid);
   goto err;
  }
  ret = wait4(pid, &status, 0x40000000, ((void *)0));
  if (ret < 0) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 115, pid);
   goto err;
  }
  if (ret != pid) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 120, pid, ret);
   goto err;
  }
  if (!(((status) & 0xff) == 0x7f)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125, pid);
   goto err;
  }
  return 0x3;
 }
 print_on_level((1), "Error (%s:%d): " "SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132, pid, si.si_signo);
err:
 unseize_task(pid, 0x3);
 return -1;
}

variable_types: status int

variable_types: ret 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; }

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:
__int64 __fastcall ptrace_peek_area(unsigned int a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rbx
unsigned __int64 v5; // r15
__int64 v7; // rax

v4 = a4 & 7;
if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v5 = a4 >> 3;
if ( a4 <= 7 )
return 0LL;
do
{
v7 = ptrace(PTRACE_PEEKDATA, a1, a3, 0LL);
*(_QWORD *)(a2 + 8 * v4) = v7;
if ( v7 == 0xFFFFFFFFLL && *_errno_location() )
return 4294967294LL;
++v4;
a3 += 8LL;
}
while ( v4 < v5 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rbx
unsigned __int64 v5; // r15
__int64 v7; // rax

v4 = a4 & 7;
if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v5 = a4 >> 3;
if ( a4 <= 7 )
return 0LL;
do
{
v7 = ptrace(PTRACE_PEEKDATA, a1, a3, 0LL);
*(_QWORD *)(a2 + 8 * v4) = v7;
if ( v7 == 0xFFFFFFFFLL && *_errno_location() )
return 4294967294LL;
++v4;
a3 += 8LL;
}
while ( v4 < v5 );
return 0LL;
}

original_code:
int ptrace_peek_area(pid_t pid, void *dst, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *d = dst, *a = addr;
  d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, ((void *)0));
  if (d[w] == -1U && (*__errno_location ()))
   goto err;
 }
 return 0;
err:
 return -2;
}

canonical_original_code:
int ptrace_peek_area(int pid, void *dst, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *d = dst; unsigned long *a = addr;
  d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, ((void *)0));
  if (d[w] == -1U && (*__errno_location ()))
   goto err;
 }
 return 0;
err:
 return -2;
}

variable_types:
dst
void *

variable_types:
addr
void *

variable_types:
bytes
unsigned long

variable_types:
w
unsigned long

variable_types:
d
unsigned long *

variable_types:
a
unsigned long *


decompiled_code:
__int64 __fastcall ptrace_poke_area(unsigned int a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rbx
unsigned __int64 v5; // r14
__int64 result; // rax

v4 = a4 & 7;
if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v5 = a4 >> 3;
if ( a4 <= 7 )
return 0LL;
while ( 1 )
{
result = ptrace(PTRACE_POKEDATA, a1, a3, *(_QWORD *)(a2 + 8 * v4));
if ( result )
break;
++v4;
a3 += 8LL;
if ( v4 >= v5 )
return result;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rbx
unsigned __int64 v5; // r14
__int64 result; // rax

v4 = a4 & 7;
if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v5 = a4 >> 3;
if ( a4 <= 7 )
return 0LL;
while ( 1 )
{
result = ptrace(PTRACE_POKEDATA, a1, a3, *(_QWORD *)(a2 + 8 * v4));
if ( result )
break;
++v4;
a3 += 8LL;
if ( v4 >= v5 )
return result;
}
return 4294967294LL;
}

original_code:
int ptrace_poke_area(pid_t pid, void *src, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *s = src, *a = addr;
  if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
   goto err;
 }
 return 0;
err:
 return -2;
}

canonical_original_code:
int ptrace_poke_area(int pid, void *src, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *s = src; unsigned long *a = addr;
  if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
   goto err;
 }
 return 0;
err:
 return -2;
}

variable_types:
src
void *

variable_types:
s
unsigned long *


decompiled_code:
__int64 __fastcall ptrace_swap_area(unsigned int a1, __int64 a2, void *a3, unsigned __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
void *dest; // [rsp+8h] [rbp-38h]

dest = a3;
v6 = alloca(a4 + 8);
if ( (unsigned int)ptrace_peek_area(a1, (__int64)&v9, a2, a4) )
return (unsigned int)-1;
v7 = ptrace_poke_area(a1, (__int64)a3, a2, a4);
if ( v7 )
return (unsigned int)(((unsigned int)ptrace_poke_area(a1, (__int64)&v9, a2, a4) == 0) - 2);
memcpy(dest, &v9, a4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, void *a3, unsigned __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
void *dest; // [rsp+8h] [rbp-38h]

dest = a3;
v6 = alloca(a4 + 8);
if ( (unsigned int)func2(a1, (__int64)&v9, a2, a4) )
return (unsigned int)-1;
v7 = func3(a1, (__int64)a3, a2, a4);
if ( v7 )
return (unsigned int)(((unsigned int)func3(a1, (__int64)&v9, a2, a4) == 0) - 2);
memcpy(dest, &v9, a4);
return v7;
}

original_code:
int ptrace_swap_area(pid_t pid, void *dst, void *src, unsigned long bytes)
{
 void *t = __builtin_alloca (bytes);
 if (ptrace_peek_area(pid, t, dst, bytes))
  return -1;
 if (ptrace_poke_area(pid, src, dst, bytes)) {
  if (ptrace_poke_area(pid, t, dst, bytes))
   return -2;
  return -1;
 }
 memcpy(src, t, bytes);
 return 0;
}

canonical_original_code:
int ptrace_swap_area(int pid, void *dst, void *src, unsigned long bytes)
{
 void *t = __builtin_alloca (bytes);
 if (ptrace_peek_area(pid, t, dst, bytes))
  return -1;
 if (ptrace_poke_area(pid, src, dst, bytes)) {
  if (ptrace_poke_area(pid, t, dst, bytes))
   return -2;
  return -1;
 }
 memcpy(src, t, bytes);
 return 0;
}

variable_types:
t
void *


decompiled_code:
__int64 __fastcall ptrace_get_regs(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_GETREGSET, a1, 1LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_GETREGSET, a1, 1LL, v3);
}

original_code:
int ptrace_get_regs(int pid, user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_GETREGSET, pid, 1, &iov);
}

canonical_original_code:
int ptrace_get_regs(int pid, struct user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_GETREGSET, pid, 1, &iov);
}

variable_types: struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 __fastcall ptrace_set_regs(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_SETREGSET, a1, 1LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_SETREGSET, a1, 1LL, v3);
}

original_code:
int ptrace_set_regs(int pid, user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_SETREGSET, pid, 1, &iov);
}

canonical_original_code:
int ptrace_set_regs(int pid, struct user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_SETREGSET, pid, 1, &iov);
}

user_defined_types: struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; }


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

if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKDATA, a1, 8LL, a2) )
{
print_on_level(1LL, "Error (%s:%d): can't get signal blocking mask for %d: %m\n", "src/lib/ptrace.c", 208LL, a1);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)ptrace_get_regs(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't obtain registers (pid: %d): %m\n", "src/lib/ptrace.c", 213LL, a1);
result = 0xFFFFFFFFLL;
}
else
{
result = ptrace_get_fpu(a1, a2 + 256);
}
return result;
}

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

if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKDATA, a1, 8LL, a2) )
{
print_on_level(1LL, "Error (%s:%d): can't get signal blocking mask for %d: %m\n", "src/lib/ptrace.c", 208LL, a1);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)func5(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't obtain registers (pid: %d): %m\n", "src/lib/ptrace.c", 213LL, a1);
result = 0xFFFFFFFFLL;
}
else
{
result = ptrace_get_fpu(a1, a2 + 256);
}
return result;
}

original_code:
int ptrace_get_thread_ctx(pid_t pid, thread_ctx_t *ctx)
{
 if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "can't get signal blocking mask for %d" ": %m\n", "src/lib/ptrace.c", 208, pid);
  return -1;
 }
 if (ptrace_get_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't obtain registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 213, pid);
  return -1;
 }
 return ptrace_get_fpu(pid, &ctx->fpu);
}

canonical_original_code:
int ptrace_get_thread_ctx(int pid, struct thread_ctx_t *ctx)
{
 if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "can't get signal blocking mask for %d" ": %m\n", "src/lib/ptrace.c", 208, pid);
  return -1;
 }
 if (ptrace_get_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't obtain registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 213, pid);
  return -1;
 }
 return ptrace_get_fpu(pid, &ctx->fpu);
}

variable_types: struct thread_ctx_t { struct k_rtsigset_t { unsigned long sig[-1]; } sigmask; struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } regs; struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } fpu; } *

user_defined_types: struct fpu_state_t { union { struct xsave_struct xsave; unsigned char __pad[-1]; }; _Bool has_xsave; }

user_defined_types: struct xsave_struct { struct i387_fxsave_struct i387; struct xsave_hdr_struct xsave_hdr; struct ymmh_struct ymmh; }


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

if ( (unsigned int)ptrace_set_regs(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't restore registers (pid: %d): %m\n", "src/lib/ptrace.c", 225LL, a1);
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
else
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
{
LABEL_3:
print_on_level(1LL, "Error (%s:%d): Can't block signals: %m\n", "src/lib/ptrace.c", 230LL);
return 0xFFFFFFFFLL;
}
result = ptrace_set_fpu(a1, a2 + 256);
}
return result;
}

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

if ( (unsigned int)func6(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't restore registers (pid: %d): %m\n", "src/lib/ptrace.c", 225LL, a1);
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
else
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
{
LABEL_3:
print_on_level(1LL, "Error (%s:%d): Can't block signals: %m\n", "src/lib/ptrace.c", 230LL);
return 0xFFFFFFFFLL;
}
result = ptrace_set_fpu(a1, a2 + 256);
}
return result;
}

original_code:
int ptrace_set_thread_ctx(pid_t pid, thread_ctx_t *ctx)
{
 int ret = 0;
 if (ptrace_set_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't restore registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 225, pid);
  ret = -1;
 }
 if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "Can't block signals" ": %m\n", "src/lib/ptrace.c", 230);
  ret = -1;
 }
 if (!ret)
  ret = ptrace_set_fpu(pid, &ctx->fpu);
 return ret;
}

canonical_original_code:
int ptrace_set_thread_ctx(int pid, struct thread_ctx_t *ctx)
{
 int ret = 0;
 if (ptrace_set_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't restore registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 225, pid);
  ret = -1;
 }
 if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "Can't block signals" ": %m\n", "src/lib/ptrace.c", 230);
  ret = -1;
 }
 if (!ret)
  ret = ptrace_set_fpu(pid, &ctx->fpu);
 return ret;
}

variable_types: pid int

user_defined_types: struct k_rtsigset_t { unsigned long sig[-1]; }

user_defined_types: struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; }

user_defined_types: struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; }