decompiled_code:
int __fastcall log_console_color_callback(int a1, const char *a2)
{
printf(
"\x1B[1m\x1B[30m[ \x1B[3%dm%c%c\x1B[0m \x1B[1m\x1B[30m]\x1B[0m ",
(unsigned int)log_console_color_params_1[2 * a1],
(unsigned int)byte_464[8 * a1],
(unsigned int)byte_464[8 * a1]);
return puts(a2);
}

canonical_decompiled_code:
int __fastcall func6(int a1, const char *a2)
{
printf(
"\x1B[1m\x1B[30m[ \x1B[3%dm%c%c\x1B[0m \x1B[1m\x1B[30m]\x1B[0m ",
(unsigned int)log_console_color_params_1[2 * a1],
(unsigned int)byte_464[8 * a1],
(unsigned int)byte_464[8 * a1]);
return puts(a2);
}

original_code:
void log_console_color_callback(int level, const char *msg)
{
 static const struct {
  int color;
  char ch;
 } log_console_color_params[] = {
  {1, '!'},
  {3, '!'},
  {2, '+'},
  {6, '-'},
  {5, '*'}
 };
 printf("\033[1m\033[30m[ \033[3%dm%c%c\033[0m \033[1m\033[30m]\033[0m ",
   log_console_color_params[level].color,
   log_console_color_params[level].ch,
   log_console_color_params[level].ch);
 printf("%s\n", msg);
}

canonical_original_code:
void log_console_color_callback(int level, char *msg)
{
 static struct { int color; char ch; } log_console_color_params[] = {
  {1, '!'},
  {3, '!'},
  {2, '+'},
  {6, '-'},
  {5, '*'}
 };
 printf("\033[1m\033[30m[ \033[3%dm%c%c\033[0m \033[1m\033[30m]\033[0m ",
   log_console_color_params[level].color,
   log_console_color_params[level].ch,
   log_console_color_params[level].ch);
 printf("%s\n", msg);
}


createDeque

decompiled_code:
_DWORD *createDeque()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
__assert_fail("dp != NULL", "deque.c", 0x19u, "createDeque");
v1 = v0;
*v0 = 0;
v2 = malloc(0x18uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
__assert_fail("dp->head != NULL", "deque.c", 0x1Du, "createDeque");
v2[1] = v2;
v2[2] = v2;
return v1;
}

canonical_decompiled_code:
_DWORD *func7()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
__assert_fail("dp != NULL", "deque.c", 0x19u, "createDeque");
v1 = v0;
*v0 = 0;
v2 = malloc(0x18uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
__assert_fail("dp->head != NULL", "deque.c", 0x1Du, "createDeque");
v2[1] = v2;
v2[2] = v2;
return v1;
}

original_code:
struct deque *createDeque(void)
{
    struct deque *dp;
    dp = malloc(sizeof(struct deque));
    ((void) sizeof ((dp != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp != ((void *)0)) ; else __assert_fail ("dp != NULL", "deque.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    dp->count = 0;
    dp->head = malloc(sizeof(struct node));
    ((void) sizeof ((dp->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp->head != ((void *)0)) ; else __assert_fail ("dp->head != NULL", "deque.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    dp->head->next = dp->head;
    dp->head->prev = dp->head;
    return dp;
}

canonical_original_code:
struct deque *createDeque()
{
    struct deque *dp;
    dp = malloc(sizeof(struct deque));
    ((void) sizeof ((dp != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp != ((void *)0)) ; else __assert_fail ("dp != NULL", "deque.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    dp->count = 0;
    dp->head = malloc(sizeof(struct node));
    ((void) sizeof ((dp->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp->head != ((void *)0)) ; else __assert_fail ("dp->head != NULL", "deque.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    dp->head->next = dp->head;
    dp->head->prev = dp->head;
    return dp;
}

variable_types: struct deque { int count; struct node { int data; struct node *next; struct node *prev; } *head; } *

user_defined_types: struct deque { int count; struct node *head; }


destroyDeque

decompiled_code:
void __fastcall destroyDeque(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( !ptr )
__assert_fail("dp != NULL", "deque.c", 0x2Bu, "destroyDeque");
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( *((_QWORD **)ptr + 1) != v2 );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( !ptr )
__assert_fail("dp != NULL", "deque.c", 0x2Bu, "destroyDeque");
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( *((_QWORD **)ptr + 1) != v2 );
free(ptr);
}

original_code:
void destroyDeque(struct deque *dp)
{
    struct node *np, *next;
    ((void) sizeof ((dp != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp != ((void *)0)) ; else __assert_fail ("dp != NULL", "deque.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    np = dp->head;
    do {
 next = np->next;
 free(np);
 np = next;
    } while (np != dp->head);
    free(dp);
}

canonical_original_code:
void destroyDeque(struct deque *dp)
{
    struct node *np; struct node *next;
    ((void) sizeof ((dp != ((void *)0)) ? 1 : 0), __extension__ ({ if (dp != ((void *)0)) ; else __assert_fail ("dp != NULL", "deque.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    np = dp->head;
    do {
 next = np->next;
 free(np);
 np = next;
    } while (np != dp->head);
    free(dp);
}

variable_types: struct node { int data; struct node *next; struct node *prev; } *

return_type: void


removeFirst

decompiled_code:
__int64 __fastcall removeFirst(__int64 a1)
{
__int64 v1; // rdx
_QWORD *v2; // rdi
__int64 v3; // rax
unsigned int v4; // ebx

if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x68u, "removeFirst");
v1 = *(_QWORD *)(a1 + 8);
--*(_DWORD *)a1;
v2 = *(_QWORD **)(v1 + 8);
v3 = v2[1];
*(_QWORD *)(v1 + 8) = v3;
*(_QWORD *)(v3 + 16) = v1;
v4 = *(_DWORD *)v2;
free(v2);
return v4;
}

original_code:
int removeFirst(struct deque *dp)
{
    int x;
    struct node *np, *sentinel;
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 104, __extension__ __PRETTY_FUNCTION__); }));
    sentinel = dp->head;
    dp->count --;
    np = sentinel->next;
    sentinel->next = np->next;
    np->next->prev = sentinel;
    x = np->data;
    free(np);
    return x;
}

canonical_original_code:
int removeFirst(struct deque *dp)
{
    int x;
    struct node *np; struct node *sentinel;
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 104, __extension__ __PRETTY_FUNCTION__); }));
    sentinel = dp->head;
    dp->count --;
    np = sentinel->next;
    sentinel->next = np->next;
    np->next->prev = sentinel;
    x = np->data;
    free(np);
    return x;
}

variable_types: x int

return_type: int

user_defined_types: struct node { int data; struct node *next; struct node *prev; }


removeLast

decompiled_code:
__int64 __fastcall removeLast(__int64 a1)
{
__int64 v1; // rdx
_QWORD *v2; // rdi
__int64 v3; // rax
unsigned int v4; // ebx

if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x7Cu, "removeLast");
v1 = *(_QWORD *)(a1 + 8);
--*(_DWORD *)a1;
v2 = *(_QWORD **)(v1 + 16);
v3 = v2[2];
*(_QWORD *)(v1 + 16) = v3;
*(_QWORD *)(v3 + 8) = v1;
v4 = *(_DWORD *)v2;
free(v2);
return v4;
}

original_code:
int removeLast(struct deque *dp)
{
    int x;
    struct node *np, *sentinel;
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 124, __extension__ __PRETTY_FUNCTION__); }));
    sentinel = dp->head;
    dp->count --;
    np = sentinel->prev;
    sentinel->prev = np->prev;
    np->prev->next = sentinel;
    x = np->data;
    free(np);
    return x;
}

canonical_original_code:
int removeLast(struct deque *dp)
{
    int x;
    struct node *np; struct node *sentinel;
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 124, __extension__ __PRETTY_FUNCTION__); }));
    sentinel = dp->head;
    dp->count --;
    np = sentinel->prev;
    sentinel->prev = np->prev;
    np->prev->next = sentinel;
    x = np->data;
    free(np);
    return x;
}


getFirst

decompiled_code:
__int64 __fastcall getFirst(__int64 a1)
{
if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x8Cu, "getFirst");
return **(unsigned int **)(*(_QWORD *)(a1 + 8) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x8Cu, "getFirst");
return **(unsigned int **)(*(_QWORD *)(a1 + 8) + 8LL);
}

original_code:
int getFirst(struct deque *dp)
{
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 140, __extension__ __PRETTY_FUNCTION__); }));
    return dp->head->next->data;
}


getLast

decompiled_code:
__int64 __fastcall getLast(__int64 a1)
{
if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x93u, "getLast");
return **(unsigned int **)(*(_QWORD *)(a1 + 8) + 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
if ( !a1 || *(int *)a1 <= 0 )
__assert_fail("dp != NULL && dp->count > 0", "deque.c", 0x93u, "getLast");
return **(unsigned int **)(*(_QWORD *)(a1 + 8) + 16LL);
}

original_code:
int getLast(struct deque *dp)
{
    ((void) sizeof ((dp != ((void *)0) && dp->count > 0) ? 1 : 0), __extension__ ({ if (dp != ((void *)0) && dp->count > 0) ; else __assert_fail ("dp != NULL && dp->count > 0", "deque.c", 147, __extension__ __PRETTY_FUNCTION__); }));
    return dp->head->prev->data;
}


numItems

decompiled_code:
__int64 __fastcall numItems(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1)
{
return *a1;
}

original_code:
int numItems(struct deque *dp)
{
    return dp->count;
}


initMaze

decompiled_code:
__int64 initMaze()
{
__int64 result; // rax
int v1; // er8
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v4; // rdx

result = (unsigned int)height;
if ( height > 0 )
{
v1 = width;
v2 = 8LL * (unsigned int)height;
v3 = 8LL * (unsigned int)(width - 1) + 8;
v4 = 0LL;
do
{
result = 0LL;
if ( v1 > 0 )
{
do
{
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 6) = 0;
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 4) = 1;
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 5) = 1;
result += 8LL;
}
while ( result != v3 );
}
v4 += 8LL;
}
while ( v4 != v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // er8
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v4; // rdx

result = (unsigned int)height;
if ( height > 0 )
{
v1 = width;
v2 = 8LL * (unsigned int)height;
v3 = 8LL * (unsigned int)(width - 1) + 8;
v4 = 0LL;
do
{
result = 0LL;
if ( v1 > 0 )
{
do
{
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 6) = 0;
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 4) = 1;
*(_BYTE *)(*(_QWORD *)(maze + v4) + result + 5) = 1;
result += 8LL;
}
while ( result != v3 );
}
v4 += 8LL;
}
while ( v4 != v2 );
}
return result;
}

original_code:
static void initMaze(void)
{
    int x, y;
    for (y = 0; y < height; y ++)
 for (x = 0; x < width; x ++) {
     maze[y][x].visited = 0;
     maze[y][x].bottom = 1;
     maze[y][x].right = 1;
 }
}

canonical_original_code:
static void initMaze()
{
    int x; int y;
    for (y = 0; y < height; y ++)
 for (x = 0; x < width; x ++) {
     maze[y][x].visited = 0;
     maze[y][x].bottom = 1;
     maze[y][x].right = 1;
 }
}

variable_types: y int


createMaze

decompiled_code:
void createMaze()
{
int v0; // ebp
__int64 v1; // rbx
void **v2; // rbp
unsigned int v3; // eax

v0 = height;
maze = (__int64)malloc(8LL * height);
if ( !maze )
_assert_fail("maze != NULL", "maze.c", 0x6Au, "createMaze");
v1 = 0LL;
if ( v0 > 0 )
{
do
{
v2 = (void **)(maze + 8 * v1);
*v2 = malloc(8LL * width);
if ( !*(_QWORD *)(maze + 8 * v1) )
_assert_fail("maze[y] != NULL", "maze.c", 0x6Eu, "createMaze");
++v1;
}
while ( height > (int)v1 );
}
v3 = time(0LL);
srand(v3);
}

canonical_decompiled_code:
void func1()
{
int v0; // ebp
__int64 v1; // rbx
void **v2; // rbp
unsigned int v3; // eax

v0 = height;
maze = (__int64)malloc(8LL * height);
if ( !maze )
_assert_fail("maze != NULL", "maze.c", 0x6Au, "createMaze");
v1 = 0LL;
if ( v0 > 0 )
{
do
{
v2 = (void **)(maze + 8 * v1);
*v2 = malloc(8LL * width);
if ( !*(_QWORD *)(maze + 8 * v1) )
_assert_fail("maze[y] != NULL", "maze.c", 0x6Eu, "createMaze");
++v1;
}
while ( height > (int)v1 );
}
v3 = time(0LL);
srand(v3);
}

original_code:
static void createMaze(void)
{
    int y;
    maze = malloc(sizeof(CELL *) * height);
    ((void) sizeof ((maze != ((void *)0)) ? 1 : 0), __extension__ ({ if (maze != ((void *)0)) ; else __assert_fail ("maze != NULL", "maze.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    for (y = 0; y < height; y ++) {
 maze[y] = malloc(sizeof(CELL) * width);
 ((void) sizeof ((maze[y] != ((void *)0)) ? 1 : 0), __extension__ ({ if (maze[y] != ((void *)0)) ; else __assert_fail ("maze[y] != NULL", "maze.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    }
    srand(time(((void *)0)));
}

canonical_original_code:
static void createMaze()
{
    int y;
    maze = malloc(sizeof(struct cell *) * height);
    ((void) sizeof ((maze != ((void *)0)) ? 1 : 0), __extension__ ({ if (maze != ((void *)0)) ; else __assert_fail ("maze != NULL", "maze.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    for (y = 0; y < height; y ++) {
 maze[y] = malloc(sizeof(CELL) * width);
 ((void) sizeof ((maze[y] != ((void *)0)) ? 1 : 0), __extension__ ({ if (maze[y] != ((void *)0)) ; else __assert_fail ("maze[y] != NULL", "maze.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    }
    srand(time(((void *)0)));
}


buildMaze

decompiled_code:
__int64 __fastcall buildMaze(int a1, int a2)
{
int v4; // er14
int v5; // er14
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // eax
__int64 v9; // r15
__int64 v10; // rbx
int v11; // eax
__int64 result; // rax
int v13[18]; // [rsp+0h] [rbp-48h]

while ( 1 )
{
while ( 1 )
{
v9 = 8LL * a1;
v10 = 8LL * a2;
*(_BYTE *)(*(_QWORD *)(maze + v9) + v10 + 6) = 1;
v11 = 0;
if ( a1 > 0 )
{
v11 = 0;
if ( !*(_BYTE *)(*(_QWORD *)(maze + v9 - 8) + v10 + 6) )
{
v13[0] = -width;
v11 = 1;
}
}
if ( height - 1 > a1 && !*(_BYTE *)(*(_QWORD *)(maze + v9 + 8) + v10 + 6) )
v13[v11++] = width;
if ( a2 > 0 && !*(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 - 2) )
{
v4 = v11 + 1;
v13[v11] = -1;
if ( a2 >= width - 1 || *(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 + 14) )
goto LABEL_5;
++v11;
goto LABEL_4;
}
if ( width - 1 <= a2 || *(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 + 14) )
break;
LABEL_4:
v4 = v11 + 1;
v13[v11] = 1;
LABEL_5:
v5 = v13[rand() % v4];
addFirst(dp, (unsigned int)(a2 + width * a1));
v7 = (unsigned int)(width + v5);
if ( width + v5 )
{
if ( width == v5 )
{
*(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 + 4) = 0;
buildMaze((unsigned int)(a1 + 1), (unsigned int)a2, v6, v7);
}
else if ( v5 == -1 )
{
*(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 - 3) = 0;
buildMaze((unsigned int)a1, (unsigned int)(a2 - 1), v6, v7);
}
else
{
if ( v5 != 1 )
abort();
*(_BYTE *)(*(_QWORD *)(maze + 8LL * a1) + v10 + 5) = 0;
buildMaze((unsigned int)a1, (unsigned int)(a2 + 1), v6, v7);
}
}
else
{
*(_BYTE *)(*(_QWORD *)(maze + v9 - 8) + v10 + 4) = 0;
buildMaze((unsigned int)(a1 - 1), (unsigned int)a2, v6, v7);
}
}
if ( v11 > 0 )
{
v4 = v11;
goto LABEL_5;
}
if ( (int)numItems(dp) <= 0 )
break;
v8 = removeFirst(dp);
a2 = v8 % width;
a1 = v8 / width;
}
result = *(_QWORD *)(maze + 8LL * height - 8);
*(_BYTE *)(result + 8LL * width - 3) = 0;
return result;
}

original_code:
static void buildMaze(int y, int x)
{
    int numOffsets, offset, offsets[4];
    while (1) {
 numOffsets = 0;
 maze[y][x].visited = 1;
 if (y > 0 && !maze[y - 1][x].visited)
     offsets[numOffsets ++] = -width;
 if (y < height - 1 && !maze[y + 1][x].visited)
     offsets[numOffsets ++] = width;
 if (x > 0 && !maze[y][x - 1].visited)
     offsets[numOffsets ++] = -1;
 if (x < width - 1 && !maze[y][x + 1].visited)
     offsets[numOffsets ++] = 1;
 if (numOffsets > 0) {
     offset = offsets[rand() % numOffsets];
     addFirst(dp, ((y) * width + (x)));
     if (offset == -width) {
  maze[y - 1][x].bottom = 0;
  buildMaze(y - 1, x);
     } else if (offset == width) {
  maze[y][x].bottom = 0;
  buildMaze(y + 1, x);
     } else if (offset == -1) {
  maze[y][x - 1].right = 0;
  buildMaze(y, x - 1);
     } else if (offset == 1) {
  maze[y][x].right = 0;
  buildMaze(y, x + 1);
     } else
  abort();
 } else if (numItems(dp) > 0) {
     offset = removeFirst(dp);
     x = ((offset) % width);
     y = ((offset) / width);
 } else
     break;
    }
    maze[height - 1][width - 1].right = 0;
}

canonical_original_code:
static void buildMaze(int y, int x)
{
    int numOffsets; int offset; int offsets[4];
    while (1) {
 numOffsets = 0;
 maze[y][x].visited = 1;
 if (y > 0 && !maze[y - 1][x].visited)
     offsets[numOffsets ++] = -width;
 if (y < height - 1 && !maze[y + 1][x].visited)
     offsets[numOffsets ++] = width;
 if (x > 0 && !maze[y][x - 1].visited)
     offsets[numOffsets ++] = -1;
 if (x < width - 1 && !maze[y][x + 1].visited)
     offsets[numOffsets ++] = 1;
 if (numOffsets > 0) {
     offset = offsets[rand() % numOffsets];
     addFirst(dp, ((y) * width + (x)));
     if (offset == -width) {
  maze[y - 1][x].bottom = 0;
  buildMaze(y - 1, x);
     } else if (offset == width) {
  maze[y][x].bottom = 0;
  buildMaze(y + 1, x);
     } else if (offset == -1) {
  maze[y][x - 1].right = 0;
  buildMaze(y, x - 1);
     } else if (offset == 1) {
  maze[y][x].right = 0;
  buildMaze(y, x + 1);
     } else
  abort();
 } else if (numItems(dp) > 0) {
     offset = removeFirst(dp);
     x = ((offset) % width);
     y = ((offset) / width);
 } else
     break;
    }
    maze[height - 1][width - 1].right = 0;
}

variable_types: numOffsets int

variable_types: offset int

variable_types:
offsets
int [4]


printMaze

decompiled_code:
int printMaze()
{
__int64 v0; // rbx
__int64 v1; // r13
int v2; // er15
chtype v3; // rsi
__int64 v5; // rbx
chtype v6; // rsi
int v7; // eax
__int64 i; // rbx
unsigned __int8 v9; // bp
chtype v10; // rsi
__int64 v11; // r12
char v12; // al
unsigned __int8 v13; // [rsp+0h] [rbp-48h]
char v14; // [rsp+7h] [rbp-41h]

waddch(stdscr, 0x20uLL);
if ( width > 0 )
{
v0 = 0LL;
do
{
waddch(stdscr, HIDWORD(acs_map[56]));
if ( width - 1 == (_DWORD)v0 )
{
waddch(stdscr, HIDWORD(acs_map[53]));
}
else if ( *(_BYTE *)(*(_QWORD *)maze + 8 * v0 + 5) )
{
waddch(stdscr, HIDWORD(acs_map[59]));
}
else
{
waddch(stdscr, HIDWORD(acs_map[56]));
}
++v0;
}
while ( width > (int)v0 );
}
waddch(stdscr, 0xAuLL);
v1 = 0LL;
v2 = 0;
v3 = 32LL;
if ( height > 0 )
{
while ( 1 )
{
waddch(stdscr, v3);
if ( width > 0 )
{
v5 = 0LL;
do
{
waddch(stdscr, 0x20uLL);
v6 = 32LL;
if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * v5 + 5) )
v6 = LODWORD(acs_map[60]);
waddch(stdscr, v6);
++v5;
}
while ( width > (int)v5 );
}
waddch(stdscr, 0xAuLL);
if ( height - 1 == v2 )
{
waddch(stdscr, HIDWORD(acs_map[54]));
}
else if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 4LL) )
{
waddch(stdscr, LODWORD(acs_map[58]));
}
else
{
waddch(stdscr, LODWORD(acs_map[60]));
}
v7 = width;
for ( i = 0LL; width > (int)i; ++i )
{
v9 = 0;
if ( v7 - 1 != (_DWORD)i )
v9 = *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * i + 12);
v14 = v9 & 1;
v13 = 0;
if ( height - 1 != v2 )
v13 = *(_BYTE *)(*(_QWORD *)(maze + v1 + 8) + 8 * i + 5);
v10 = 32LL;
if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * i + 4) )
v10 = HIDWORD(acs_map[56]);
waddch(stdscr, v10);
v11 = *(_QWORD *)(maze + v1) + 8 * i;
if ( *(_BYTE *)(v11 + 4) )
{
v12 = v13 & 1;
if ( *(_BYTE *)(v11 + 5) )
{
if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[55]));
}
else if ( v14 )
{
waddch(stdscr, LODWORD(acs_map[59]));
}
else if ( v12 )
{
waddch(stdscr, HIDWORD(acs_map[58]));
}
else
{
waddch(stdscr, LODWORD(acs_map[53]));
}
}
else if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, HIDWORD(acs_map[59]));
}
else if ( v12 )
{
waddch(stdscr, HIDWORD(acs_map[53]));
}
else
{
waddch(stdscr, HIDWORD(acs_map[56]));
}
}
else if ( *(_BYTE *)(v11 + 5) )
{
if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[58]));
}
else if ( v14 )
{
waddch(stdscr, HIDWORD(acs_map[54]));
}
else
{
waddch(stdscr, LODWORD(acs_map[60]));
}
}
else if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[54]));
}
else
{
waddch(stdscr, 0x20uLL);
}
v7 = width;
}
waddch(stdscr, 0xAuLL);
if ( height <= ++v2 )
break;
v3 = 32LL;
if ( v2 )
v3 = LODWORD(acs_map[60]);
v1 += 8LL;
}
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbx
__int64 v1; // r13
int v2; // er15
chtype v3; // rsi
__int64 v5; // rbx
chtype v6; // rsi
int v7; // eax
__int64 i; // rbx
unsigned __int8 v9; // bp
chtype v10; // rsi
__int64 v11; // r12
char v12; // al
unsigned __int8 v13; // [rsp+0h] [rbp-48h]
char v14; // [rsp+7h] [rbp-41h]

waddch(stdscr, 0x20uLL);
if ( width > 0 )
{
v0 = 0LL;
do
{
waddch(stdscr, HIDWORD(acs_map[56]));
if ( width - 1 == (_DWORD)v0 )
{
waddch(stdscr, HIDWORD(acs_map[53]));
}
else if ( *(_BYTE *)(*(_QWORD *)maze + 8 * v0 + 5) )
{
waddch(stdscr, HIDWORD(acs_map[59]));
}
else
{
waddch(stdscr, HIDWORD(acs_map[56]));
}
++v0;
}
while ( width > (int)v0 );
}
waddch(stdscr, 0xAuLL);
v1 = 0LL;
v2 = 0;
v3 = 32LL;
if ( height > 0 )
{
while ( 1 )
{
waddch(stdscr, v3);
if ( width > 0 )
{
v5 = 0LL;
do
{
waddch(stdscr, 0x20uLL);
v6 = 32LL;
if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * v5 + 5) )
v6 = LODWORD(acs_map[60]);
waddch(stdscr, v6);
++v5;
}
while ( width > (int)v5 );
}
waddch(stdscr, 0xAuLL);
if ( height - 1 == v2 )
{
waddch(stdscr, HIDWORD(acs_map[54]));
}
else if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 4LL) )
{
waddch(stdscr, LODWORD(acs_map[58]));
}
else
{
waddch(stdscr, LODWORD(acs_map[60]));
}
v7 = width;
for ( i = 0LL; width > (int)i; ++i )
{
v9 = 0;
if ( v7 - 1 != (_DWORD)i )
v9 = *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * i + 12);
v14 = v9 & 1;
v13 = 0;
if ( height - 1 != v2 )
v13 = *(_BYTE *)(*(_QWORD *)(maze + v1 + 8) + 8 * i + 5);
v10 = 32LL;
if ( *(_BYTE *)(*(_QWORD *)(maze + v1) + 8 * i + 4) )
v10 = HIDWORD(acs_map[56]);
waddch(stdscr, v10);
v11 = *(_QWORD *)(maze + v1) + 8 * i;
if ( *(_BYTE *)(v11 + 4) )
{
v12 = v13 & 1;
if ( *(_BYTE *)(v11 + 5) )
{
if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[55]));
}
else if ( v14 )
{
waddch(stdscr, LODWORD(acs_map[59]));
}
else if ( v12 )
{
waddch(stdscr, HIDWORD(acs_map[58]));
}
else
{
waddch(stdscr, LODWORD(acs_map[53]));
}
}
else if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, HIDWORD(acs_map[59]));
}
else if ( v12 )
{
waddch(stdscr, HIDWORD(acs_map[53]));
}
else
{
waddch(stdscr, HIDWORD(acs_map[56]));
}
}
else if ( *(_BYTE *)(v11 + 5) )
{
if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[58]));
}
else if ( v14 )
{
waddch(stdscr, HIDWORD(acs_map[54]));
}
else
{
waddch(stdscr, LODWORD(acs_map[60]));
}
}
else if ( (v13 & v9 & 1) != 0 )
{
waddch(stdscr, LODWORD(acs_map[54]));
}
else
{
waddch(stdscr, 0x20uLL);
}
v7 = width;
}
waddch(stdscr, 0xAuLL);
if ( height <= ++v2 )
break;
v3 = 32LL;
if ( v2 )
v3 = LODWORD(acs_map[60]);
v1 += 8LL;
}
}
return wrefresh(stdscr);
}

original_code:
static void printMaze(void)
{
    int x, y;
    _Bool eastBottom, southRight;
    waddch(stdscr,(' '));
    for (x = 0; x < width; x ++) {
 waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
 if (x == width - 1)
     waddch(stdscr,((acs_map[(unsigned char)(('k'))])));
 else if (maze[0][x].right)
     waddch(stdscr,((acs_map[(unsigned char)(('w'))])));
 else
     waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
    }
    waddch(stdscr,('\n'));
    for (y = 0; y < height; y ++) {
 waddch(stdscr,(y != 0 ? (acs_map[(unsigned char)(('x'))]) : ' '));
 for (x = 0; x < width; x ++) {
     waddch(stdscr,(' '));
     waddch(stdscr,(maze[y][x].right ? (acs_map[(unsigned char)(('x'))]) : ' '));
 }
 waddch(stdscr,('\n'));
 if (y == height - 1)
     waddch(stdscr,((acs_map[(unsigned char)(('m'))])));
 else if (maze[y][0].bottom)
     waddch(stdscr,((acs_map[(unsigned char)(('t'))])));
 else
     waddch(stdscr,((acs_map[(unsigned char)(('x'))])));
 for (x = 0; x < width; x ++) {
     eastBottom = (x != width - 1 && maze[y][x + 1].bottom);
     southRight = (y != height - 1 && maze[y + 1][x].right);
     waddch(stdscr,(maze[y][x].bottom ? (acs_map[(unsigned char)(('q'))]) : ' '));
     if (maze[y][x].bottom) {
  if (maze[y][x].right) {
      if (eastBottom && southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('n'))])));
      else if (eastBottom)
   waddch(stdscr,((acs_map[(unsigned char)(('v'))])));
      else if (southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('u'))])));
      else
   waddch(stdscr,((acs_map[(unsigned char)(('j'))])));
  } else {
      if (eastBottom && southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('w'))])));
      else if (southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('k'))])));
      else
   waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
  }
     } else if (maze[y][x].right) {
  if (eastBottom && southRight)
      waddch(stdscr,((acs_map[(unsigned char)(('t'))])));
  else if (eastBottom)
      waddch(stdscr,((acs_map[(unsigned char)(('m'))])));
  else
      waddch(stdscr,((acs_map[(unsigned char)(('x'))])));
     } else {
  if (eastBottom && southRight)
      waddch(stdscr,((acs_map[(unsigned char)(('l'))])));
  else
      waddch(stdscr,(' '));
     }
 }
 waddch(stdscr,('\n'));
    }
    wrefresh(stdscr);
}

canonical_original_code:
static void printMaze()
{
    int x; int y;
    _Bool eastBottom; _Bool southRight;
    waddch(stdscr,(' '));
    for (x = 0; x < width; x ++) {
 waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
 if (x == width - 1)
     waddch(stdscr,((acs_map[(unsigned char)(('k'))])));
 else if (maze[0][x].right)
     waddch(stdscr,((acs_map[(unsigned char)(('w'))])));
 else
     waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
    }
    waddch(stdscr,('\n'));
    for (y = 0; y < height; y ++) {
 waddch(stdscr,(y != 0 ? (acs_map[(unsigned char)(('x'))]) : ' '));
 for (x = 0; x < width; x ++) {
     waddch(stdscr,(' '));
     waddch(stdscr,(maze[y][x].right ? (acs_map[(unsigned char)(('x'))]) : ' '));
 }
 waddch(stdscr,('\n'));
 if (y == height - 1)
     waddch(stdscr,((acs_map[(unsigned char)(('m'))])));
 else if (maze[y][0].bottom)
     waddch(stdscr,((acs_map[(unsigned char)(('t'))])));
 else
     waddch(stdscr,((acs_map[(unsigned char)(('x'))])));
 for (x = 0; x < width; x ++) {
     eastBottom = (x != width - 1 && maze[y][x + 1].bottom);
     southRight = (y != height - 1 && maze[y + 1][x].right);
     waddch(stdscr,(maze[y][x].bottom ? (acs_map[(unsigned char)(('q'))]) : ' '));
     if (maze[y][x].bottom) {
  if (maze[y][x].right) {
      if (eastBottom && southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('n'))])));
      else if (eastBottom)
   waddch(stdscr,((acs_map[(unsigned char)(('v'))])));
      else if (southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('u'))])));
      else
   waddch(stdscr,((acs_map[(unsigned char)(('j'))])));
  } else {
      if (eastBottom && southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('w'))])));
      else if (southRight)
   waddch(stdscr,((acs_map[(unsigned char)(('k'))])));
      else
   waddch(stdscr,((acs_map[(unsigned char)(('q'))])));
  }
     } else if (maze[y][x].right) {
  if (eastBottom && southRight)
      waddch(stdscr,((acs_map[(unsigned char)(('t'))])));
  else if (eastBottom)
      waddch(stdscr,((acs_map[(unsigned char)(('m'))])));
  else
      waddch(stdscr,((acs_map[(unsigned char)(('x'))])));
     } else {
  if (eastBottom && southRight)
      waddch(stdscr,((acs_map[(unsigned char)(('l'))])));
  else
      waddch(stdscr,(' '));
     }
 }
 waddch(stdscr,('\n'));
    }
    wrefresh(stdscr);
}


draw

decompiled_code:
int __fastcall draw(int a1, int a2, char a3)
{
int v4; // eax
int result; // eax

if ( a3 )
{
wattr_on(stdscr, 0x40000uLL, 0LL);
}
else
{
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 1);
wechochar(stdscr, 0x20uLL);
}
v4 = *(_DWORD *)(*(_QWORD *)(maze + 8LL * a2) + 8LL * a1);
if ( v4 == 1 )
{
wmove(stdscr, 2 * a2 + 1, 2 * a1);
result = wechochar(stdscr, 0x20uLL);
}
else if ( v4 == -1 )
{
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 2);
result = wechochar(stdscr, 0x20uLL);
}
else if ( v4 == width )
{
wmove(stdscr, 2 * a2, 2 * a1 + 1);
result = wechochar(stdscr, 0x20uLL);
}
else
{
result = width + v4;
if ( !result )
{
wmove(stdscr, 2 * a2 + 2, 2 * a1 + 1);
result = wechochar(stdscr, 0x20uLL);
}
}
if ( a3 )
{
usleep(0x4E20u);
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 1);
wechochar(stdscr, 0x20uLL);
usleep(0x4E20u);
result = wattr_off(stdscr, 0x40000uLL, 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2, char a3)
{
int v4; // eax
int result; // eax

if ( a3 )
{
wattr_on(stdscr, 0x40000uLL, 0LL);
}
else
{
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 1);
wechochar(stdscr, 0x20uLL);
}
v4 = *(_DWORD *)(*(_QWORD *)(maze + 8LL * a2) + 8LL * a1);
if ( v4 == 1 )
{
wmove(stdscr, 2 * a2 + 1, 2 * a1);
result = wechochar(stdscr, 0x20uLL);
}
else if ( v4 == -1 )
{
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 2);
result = wechochar(stdscr, 0x20uLL);
}
else if ( v4 == width )
{
wmove(stdscr, 2 * a2, 2 * a1 + 1);
result = wechochar(stdscr, 0x20uLL);
}
else
{
result = width + v4;
if ( !result )
{
wmove(stdscr, 2 * a2 + 2, 2 * a1 + 1);
result = wechochar(stdscr, 0x20uLL);
}
}
if ( a3 )
{
usleep(0x4E20u);
wmove(stdscr, 2 * a2 + 1, 2 * a1 + 1);
wechochar(stdscr, 0x20uLL);
usleep(0x4E20u);
result = wattr_off(stdscr, 0x40000uLL, 0LL);
}
return result;
}

original_code:
static void draw(int x, int y, _Bool forward)
{
    if (!forward) {
 wmove(stdscr,(y * 2 + 1),(x * 2 + 1));
 wechochar(stdscr,(' '));
    } else
 wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
    if (maze[y][x].from == 1) {
 wmove(stdscr,(y * 2 + 1),(x * 2 + 1 - 1));
 wechochar(stdscr,(' '));
    } else if (maze[y][x].from == -1) {
 wmove(stdscr,(y * 2 + 1),(x * 2 + 1 + 1));
 wechochar(stdscr,(' '));
    } else if (maze[y][x].from == width) {
 wmove(stdscr,(y * 2 + 1 - 1),(x * 2 + 1));
 wechochar(stdscr,(' '));
    } else if (maze[y][x].from == -width) {
 wmove(stdscr,(y * 2 + 1 + 1),(x * 2 + 1));
 wechochar(stdscr,(' '));
    }
    if (forward) {
 usleep(20000);
 wmove(stdscr,(y * 2 + 1),(x * 2 + 1));
 wechochar(stdscr,(' '));
 usleep(20000);
 wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
    }
}


solveMaze

original_code:
static void solveMaze(void)
{
    int x, y, offset;
    for (y = 0; y < height; y ++)
 for (x = 0; x < width; x ++)
     maze[y][x].visited = 0;
    y = 0;
    x = 0;
    while (y != height - 1 || x != width - 1) {
 draw(x, y, 1);
 maze[y][x].visited = 1;
 if (!maze[y][x].right && !maze[y][x + 1].visited) {
     addLast(dp, ((y) * width + (x + 1)));
     maze[y][x + 1].from = 1;
 }
 if (!maze[y][x].bottom && !maze[y + 1][x].visited) {
     addLast(dp, ((y + 1) * width + (x)));
     maze[y + 1][x].from = width;
 }
 if (x > 0 && !maze[y][x - 1].right && !maze[y][x - 1].visited) {
     addLast(dp, ((y) * width + (x - 1)));
     maze[y][x - 1].from = -1;
 }
 if (y > 0 && !maze[y - 1][x].bottom && !maze[y - 1][x].visited) {
     addLast(dp, ((y - 1) * width + (x)));
     maze[y - 1][x].from = -width;
 }
 if (getLast(dp) == ((y) * width + (x))) {
     draw(x, y, 0);
     removeLast(dp);
 }
 offset = getLast(dp);
 x = ((offset) % width);
 y = ((offset) / width);
    }
    draw(width - 1, height - 1, 1);
}

canonical_original_code:
static void solveMaze()
{
    int x; int y; int offset;
    for (y = 0; y < height; y ++)
 for (x = 0; x < width; x ++)
     maze[y][x].visited = 0;
    y = 0;
    x = 0;
    while (y != height - 1 || x != width - 1) {
 draw(x, y, 1);
 maze[y][x].visited = 1;
 if (!maze[y][x].right && !maze[y][x + 1].visited) {
     addLast(dp, ((y) * width + (x + 1)));
     maze[y][x + 1].from = 1;
 }
 if (!maze[y][x].bottom && !maze[y + 1][x].visited) {
     addLast(dp, ((y + 1) * width + (x)));
     maze[y + 1][x].from = width;
 }
 if (x > 0 && !maze[y][x - 1].right && !maze[y][x - 1].visited) {
     addLast(dp, ((y) * width + (x - 1)));
     maze[y][x - 1].from = -1;
 }
 if (y > 0 && !maze[y - 1][x].bottom && !maze[y - 1][x].visited) {
     addLast(dp, ((y - 1) * width + (x)));
     maze[y - 1][x].from = -width;
 }
 if (getLast(dp) == ((y) * width + (x))) {
     draw(x, y, 0);
     removeLast(dp);
 }
 offset = getLast(dp);
 x = ((offset) % width);
 y = ((offset) / width);
    }
    draw(width - 1, height - 1, 1);
}


decompiled_code:
double random_uniform()
{
return (double)rand() / 2147483647.0;
}

canonical_decompiled_code:
double func0()
{
return (double)rand() / 2147483647.0;
}

original_code:
double random_uniform() {
  double ret;
  ret = ((double)rand()/(double)2147483647);
  return ret;
}

variable_types: ret double

return_type: double


decompiled_code:
__int64 __fastcall random_uniform_range(unsigned __int8 a1, unsigned __int8 a2)
{
return (unsigned int)(int)((double)rand() * 4.656612873077393e-10 * (double)(a2 - a1 + 1) + (double)a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, unsigned __int8 a2)
{
return (unsigned int)(int)((double)rand() * 4.656612873077393e-10 * (double)(a2 - a1 + 1) + (double)a1);
}

original_code:
uint8_t random_uniform_range(uint8_t min, uint8_t max) {
  double ret;
  ret = ((double) rand() / (((double)2147483647) + 1.0)) * (max-min+1) + min;
  return (uint8_t)ret;
}

canonical_original_code:
unsigned char random_uniform_range(unsigned char min, unsigned char max) {
  double ret;
  ret = ((double) rand() / (((double)2147483647) + 1.0)) * (max-min+1) + min;
  return (unsigned char)ret;
}

variable_types:
min
unsigned char

variable_types:
max
unsigned char

return_type: unsigned char


decompiled_code:
bool __fastcall random_bernoulli(double a1)
{
return a1 > random_uniform();
}

canonical_decompiled_code:
bool __fastcall func2(double a1)
{
return a1 > func0();
}

original_code:
uint8_t random_bernoulli(double tau) {
  return (uint8_t)(random_uniform() < tau);
}

canonical_original_code:
unsigned char random_bernoulli(double tau) {
  return (unsigned char)(random_uniform() < tau);
}

variable_types: tau double


decompiled_code:
__int64 random_uniform_uint32()
{
char v0; // bp
unsigned int v1; // ebx

v0 = 32;
v1 = 0;
do
{
v1 = (unsigned __int8)random_uniform_range(0, 1u) ^ (2 * v1);
--v0;
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // bp
unsigned int v1; // ebx

v0 = 32;
v1 = 0;
do
{
v1 = (unsigned __int8)func1(0, 1u) ^ (2 * v1);
--v0;
}
while ( v0 );
return v1;
}

original_code:
uint32_t random_uniform_uint32(void) {
  uint32_t n = 0;
  uint8_t i = 0;
  for(i = 0; i < 32; i++) {
    n <<= 1;
    n ^= (uint32_t)random_uniform_range(0, 1);
  }
  return n;
}

canonical_original_code:
unsigned int random_uniform_uint32() {
  unsigned int n = 0;
  unsigned char i = 0;
  for(i = 0; i < 32; i++) {
    n <<= 1;
    n ^= (unsigned int)random_uniform_range(0, 1);
  }
  return n;
}

variable_types:
n
unsigned int

variable_types:
i
unsigned char

return_type: unsigned int


decompiled_code:
__int64 __fastcall random_bernoulli_uint32(double a1)
{
char v1; // bp
unsigned int v2; // ebx

v1 = 32;
v2 = 0;
do
{
v2 = random_bernoulli(a1) ^ (2 * v2);
--v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(double a1)
{
char v1; // bp
unsigned int v2; // ebx

v1 = 32;
v2 = 0;
do
{
v2 = func2(a1) ^ (2 * v2);
--v1;
}
while ( v1 );
return v2;
}

original_code:
uint32_t random_bernoulli_uint32(double tau) {
  uint8_t i = 0;
  uint32_t n = 0;
  for(; i < 32; i++) {
    n <<= 1;
    n ^= (uint32_t)random_bernoulli(tau);
  }
  return n;
}

canonical_original_code:
unsigned int random_bernoulli_uint32(double tau) {
  unsigned char i = 0;
  unsigned int n = 0;
  for(; i < 32; i++) {
    n <<= 1;
    n ^= (unsigned int)random_bernoulli(tau);
  }
  return n;
}


usage

decompiled_code:
size_t usage()
{
return fwrite("Usage: \n", 1uLL, 8uLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite("Usage: \n", 1uLL, 8uLL, stderr);
}

original_code:
void usage() {
  fprintf(stderr, "Usage: \n");
}


decompiled_code:
__int64 test_lapin_reduc()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = lapin_init(1LL);
v1 = challenge_generate(*(unsigned __int8 *)(v0 + 16));
v2 = lapin_pimapping_reduc(v0, v1);
poly_crt_free(v2);
lapin_tag(v0, v1, v5, &v4);
poly_crt_free(v5[0]);
poly_crt_free(v4);
challenge_free(v1);
return lapin_end(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = lapin_init(1LL);
v1 = challenge_generate(*(unsigned __int8 *)(v0 + 16));
v2 = lapin_pimapping_reduc(v0, v1);
poly_crt_free(v2);
lapin_tag(v0, v1, v5, &v4);
poly_crt_free(v5[0]);
poly_crt_free(v4);
challenge_free(v1);
return lapin_end(v0);
}

original_code:
void test_lapin_reduc() {
  Lapin *lapin = lapin_init(1);
  Challenge c = challenge_generate(lapin->sec_param);
  PolyCRT *pi = lapin_pimapping_reduc(lapin, c);
  poly_crt_free(pi);
  PolyCRT *r, *z;
  lapin_tag(lapin, c, &r, &z);
  poly_crt_free(r);
  poly_crt_free(z);
  challenge_free(c);
  lapin_end(lapin);
}

canonical_original_code:
void test_lapin_reduc() {
  struct s_lapin *lapin = lapin_init(1);
  unsigned int *c = challenge_generate(lapin->sec_param);
  struct s_poly_crt *pi = lapin_pimapping_reduc(lapin, c);
  poly_crt_free(pi);
  struct s_poly_crt *r; struct s_poly_crt *z;
  lapin_tag(lapin, c, &r, &z);
  poly_crt_free(r);
  poly_crt_free(z);
  challenge_free(c);
  lapin_end(lapin);
}

variable_types: struct s_lapin { double tau; unsigned short sec_param; unsigned int n; struct s_key { struct s_poly { unsigned int *vec; unsigned short n_words; } *s1; } *key; struct s_key_crt { struct s_poly_crt { unsigned char m; struct s_poly **crt; } *s1; } *key_crt; struct s_poly *f_normal; struct s_poly_crt *f_crt; unsigned char reduc; } *

variable_types:
c
unsigned int *

variable_types: struct s_poly_crt { unsigned char m; struct s_poly { unsigned int *vec; unsigned short n_words; } **crt; } *

user_defined_types: struct s_lapin { double tau; unsigned short sec_param; unsigned int n; struct s_key *key; struct s_key_crt *key_crt; struct s_poly *f_normal; struct s_poly_crt *f_crt; unsigned char reduc; }

user_defined_types: struct s_key_crt { struct s_poly_crt *s1; }


decompiled_code:
__int64 test_lapin_irreduc()
{
__int64 v0; // rbx
__int64 v1; // rbp
char v2; // al
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = lapin_init(0LL);
v1 = challenge_generate(*(unsigned __int8 *)(v0 + 16));
lapin_tag(v0, v1, v5, &v4);
v2 = lapin_vrfy(v0, v1, v5[0], v4);
printf("irreduc vrfy = %u\n", (unsigned int)v2);
poly_free(v5[0]);
poly_free(v4);
challenge_free(v1);
return lapin_end(v0);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 v1; // rbp
char v2; // al
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = lapin_init(0LL);
v1 = challenge_generate(*(unsigned __int8 *)(v0 + 16));
lapin_tag(v0, v1, v5, &v4);
v2 = lapin_vrfy(v0, v1, v5[0], v4);
printf("irreduc vrfy = %u\n", (unsigned int)v2);
poly_free(v5[0]);
poly_free(v4);
challenge_free(v1);
return lapin_end(v0);
}

original_code:
void test_lapin_irreduc() {
  Lapin *lapin = lapin_init(0);
  Challenge c = challenge_generate(lapin->sec_param);
  Poly *r, *z;
  lapin_tag(lapin, c, &r, &z);
  printf("irreduc vrfy = %u\n", lapin_vrfy(lapin, c, r, z));
  poly_free(r);
  poly_free(z);
  challenge_free(c);
  lapin_end(lapin);
}

canonical_original_code:
void test_lapin_irreduc() {
  struct s_lapin *lapin = lapin_init(0);
  unsigned int *c = challenge_generate(lapin->sec_param);
  struct s_poly *r; struct s_poly *z;
  lapin_tag(lapin, c, &r, &z);
  printf("irreduc vrfy = %u\n", lapin_vrfy(lapin, c, r, z));
  poly_free(r);
  poly_free(z);
  challenge_free(c);
  lapin_end(lapin);
}

variable_types: struct s_poly { unsigned int *vec; unsigned short n_words; } *

user_defined_types: struct s_poly_crt { unsigned char m; struct s_poly **crt; }


main

canonical_name: main

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

v3 = time(0LL);
srand(v3);
test_lapin_irreduc(v3, argv);
return 0;
}

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

v3 = time(0LL);
srand(v3);
func2(v3, argv);
return 0;
}

original_code:
int main(int argc, char **argv) {
  srand((unsigned)time(((void *)0)));
  test_lapin_irreduc();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  srand((unsigned int)time(((void *)0)));
  test_lapin_irreduc();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


canonical_original_code:
unsigned char binary_hamming_weight(unsigned int n) {
  unsigned int wt = 0;
  wt = n - ((n >> 1) & B[0]);
  wt = ((wt >> S[1]) & B[1]) + (wt & B[1]);
  wt = ((wt >> S[2]) + wt) & B[2];
  wt = ((wt >> S[3]) + wt) & B[3];
  wt = ((wt >> S[4]) + wt) & B[4];
  return (unsigned char)wt;
}

variable_types:
wt
unsigned int


decompiled_code:
__int64 __fastcall binary_degree(unsigned int a1)
{
unsigned int v1; // edi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1 >> 1;
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 >>= 1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int v1; // edi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1 >> 1;
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 >>= 1;
}
while ( v1 );
return result;
}

original_code:
int16_t binary_degree(uint32_t p) {
  if(p == 0) {
    return -1;
  }
  int16_t deg = 0;
  while(p >>= 1)
    deg++;
  return deg;
}

canonical_original_code:
short binary_degree(unsigned int p) {
  if(p == 0) {
    return -1;
  }
  short deg = 0;
  while(p >>= 1)
    deg++;
  return deg;
}

variable_types:
p
unsigned int

variable_types: deg short

return_type: short


decompiled_code:
__int64 __fastcall binary_reverse_number(int a1)
{
__int64 result; // rax
int v2; // esi
unsigned int v3; // ecx
int v4; // edx

LODWORD(result) = a1;
v2 = 5;
v3 = 16;
v4 = -1;
do
{
v4 ^= v4 << v3;
result = ((_DWORD)result << v3) ^ v4 & (((_DWORD)result << v3) ^ ((unsigned int)result >> v3));
v3 >>= 1;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
int v2; // esi
unsigned int v3; // ecx
int v4; // edx

LODWORD(result) = a1;
v2 = 5;
v3 = 16;
v4 = -1;
do
{
v4 ^= v4 << v3;
result = ((_DWORD)result << v3) ^ v4 & (((_DWORD)result << v3) ^ ((unsigned int)result >> v3));
v3 >>= 1;
--v2;
}
while ( v2 );
return result;
}

original_code:
uint32_t binary_reverse_number(uint32_t n) {
  uint32_t s = sizeof(n) * sizeof(char) * 8;
  uint32_t mask = ~0;
  while ((s >>= 1) > 0) {
    mask ^= (mask << s);
    n = ((n >> s) & mask) | ((n << s) & ~mask);
  }
  return n;
}

canonical_original_code:
unsigned int binary_reverse_number(unsigned int n) {
  unsigned int s = sizeof(n) * sizeof(char) * 8;
  unsigned int mask = ~0;
  while ((s >>= 1) > 0) {
    mask ^= (mask << s);
    n = ((n >> s) & mask) | ((n << s) & ~mask);
  }
  return n;
}

variable_types:
s
unsigned int

variable_types:
mask
unsigned int


decompiled_code:
__int64 __fastcall binary_char_to_uint(_BYTE *a1)
{
char v1; // cl
_BYTE *v2; // rdx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
LODWORD(result) = 0;
do
{
result = (v1 != 48) | (unsigned int)(2 * result);
v1 = *++v2;
}
while ( *v2 && v2 - a1 <= 31 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
char v1; // cl
_BYTE *v2; // rdx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
LODWORD(result) = 0;
do
{
result = (v1 != 48) | (unsigned int)(2 * result);
v1 = *++v2;
}
while ( *v2 && v2 - a1 <= 31 );
return result;
}

original_code:
uint32_t binary_char_to_uint(const unsigned char *c) {
  uint32_t out = 0;
  const unsigned char *s = c;
  while(*s && s-c < (uint8_t)(sizeof(uint32_t) * 8)) {
    out = (out << 1) | (*s == '0' ? 0 : 1);
    s++;
  }
  return out;
}

canonical_original_code:
unsigned int binary_char_to_uint(unsigned char *c) {
  unsigned int out = 0;
  unsigned char *s = c;
  while(*s && s-c < (unsigned char)(sizeof(unsigned int) * 8)) {
    out = (out << 1) | (*s == '0' ? 0 : 1);
    s++;
  }
  return out;
}

variable_types:
c
unsigned char *

variable_types:
out
unsigned int

variable_types:
s
unsigned char *


decompiled_code:
bool __fastcall binary_get_bit(int a1, char a2)
{
return (a1 & (1 << a2)) != 0;
}

canonical_decompiled_code:
bool __fastcall func4(int a1, char a2)
{
return (a1 & (1 << a2)) != 0;
}

original_code:
uint8_t binary_get_bit(uint32_t w, uint8_t i) {
  uint8_t set = (w & (1 << i)) != 0;
  return set;
}

canonical_original_code:
unsigned char binary_get_bit(unsigned int w, unsigned char i) {
  unsigned char set = (w & (1 << i)) != 0;
  return set;
}

variable_types:
w
unsigned int

variable_types:
set
unsigned char


original_code:
int64_t time_in_ms(struct timespec *timeA_p, struct timespec *timeB_p) {
  return ((timeA_p->tv_sec * 1000000000) + timeA_p->tv_nsec) -
         ((timeB_p->tv_sec * 1000000000) + timeB_p->tv_nsec);
}

canonical_original_code:
long time_in_ms(struct timespec *timeA_p, struct timespec *timeB_p) {
  return ((timeA_p->tv_sec * 1000000000) + timeA_p->tv_nsec) -
         ((timeB_p->tv_sec * 1000000000) + timeB_p->tv_nsec);
}

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

return_type: long


randombytes

decompiled_code:
void __fastcall randombytes(void *buf, unsigned __int64 a2)
{
unsigned __int64 v3; // rbx
int v4; // edx
int v5; // eax

v3 = a2;
if ( fd == -1 )
{
while ( 1 )
{
fd = open("/dev/urandom", 0);
if ( fd != -1 )
break;
sleep(1u);
}
}
if ( a2 )
{
do
{
v4 = 0x100000;
if ( v3 <= 0xFFFFF )
v4 = v3;
v5 = read(fd, buf, v4);
if ( v5 <= 0 )
{
sleep(1u);
}
else
{
buf = (char *)buf + v5;
v3 -= v5;
}
}
while ( v3 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *buf, unsigned __int64 a2)
{
unsigned __int64 v3; // rbx
int v4; // edx
int v5; // eax

v3 = a2;
if ( fd == -1 )
{
while ( 1 )
{
fd = open("/dev/urandom", 0);
if ( fd != -1 )
break;
sleep(1u);
}
}
if ( a2 )
{
do
{
v4 = 0x100000;
if ( v3 <= 0xFFFFF )
v4 = v3;
v5 = read(fd, buf, v4);
if ( v5 <= 0 )
{
sleep(1u);
}
else
{
buf = (char *)buf + v5;
v3 -= v5;
}
}
while ( v3 );
}
}

original_code:
void randombytes(void *x, unsigned long xlen)
{
  int i;
  if (fd == -1) {
    for (;;) {
      fd = open("/dev/urandom",00);
      if (fd != -1) break;
      sleep(1);
    }
  }
  while (xlen > 0) {
    if (xlen < 1048576) i = xlen; else i = 1048576;
    i = read(fd,x,i);
    if (i < 1) {
      sleep(1);
      continue;
    }
    x += i;
    xlen -= i;
  }
}

variable_types:
x
void *

variable_types:
xlen
unsigned long

variable_types: i int


decompiled_code:
__int64 parse_opts()
{
flag_pretty = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
flag_pretty = 0;
return 0LL;
}

original_code:
int parse_opts(int argc, char *argv[]){
  flag_pretty = 0;
  flag_aur = 0;
  flag_echo = 0;
  flag_composite = 1;
  flag_prime = 1;
  return 0;
}

variable_types:
argv
char *[]


decompiled_code:
void handle_each_line()
{
int v0; // eax
int v1; // ebx
int v2; // ebx
void *v3; // rax
__int64 v4; // rbx
int v5; // er12
void *v6; // rax
__int64 i; // rbx
__int64 v8; // r12
__int64 v9; // rbp
__int64 v10; // r13
int v11; // ebx
const char *v12; // rax
size_t v13; // rax
__int64 v14; // [rsp+0h] [rbp-2038h] BYREF

v0 = cn_set_str(cn, buf);
if ( v0 )
{
v1 = v0;
if ( (unsigned int)(v0 - 1) > 1 )
{
if ( (v0 & 0xFC) != 0 )
{
fprintf(stderr, "%s\n", buf);
fprintf(
stderr,
"calc error retval = %d, reg1 = %d, reg2 = %d\n",
(unsigned __int8)v1,
BYTE1(v1),
(unsigned int)(v1 >> 16));
v3 = cn;
if ( *((int *)cn + 2) > 0 )
{
v4 = 0LL;
do
{
_gmpz_clear(*((_QWORD *)v3 + 2) + 16 * v4);
v3 = cn;
++v4;
}
while ( *((_DWORD *)cn + 2) > (int)v4 );
}
free(*((void **)v3 + 2));
}
else
{
v2 = v0 >> 8;
fprintf(stderr, "parse error:\n%s\n", buf);
for ( ; v2; --v2 )
fputc(32, stderr);
fwrite("^\n\n", 1uLL, 3uLL, stderr);
}
}
}
else
{
v5 = cn_check_algebraic_factor(cn);
if ( v5 > 0 )
{
puts(buf);
v8 = 16LL * (unsigned int)v5;
v9 = 0LL;
do
{
v10 = *((_QWORD *)cn + 4) + v9;
v11 = (unsigned int)_gmpz_probab_prime_p(v10, 30LL) == 0 ? 67 : 80;
v12 = (const char *)_gmpz_get_str(&v14, 10LL, v10);
v13 = strlen(v12);
printf("%c%d = ", (unsigned int)(char)v11, v13);
_gmpz_out_str(stdout, 10LL, *((_QWORD *)cn + 4) + v9);
puts(&s);
_gmpz_clear(*((_QWORD *)cn + 4) + v9);
v9 += 16LL;
}
while ( v9 != v8 );
puts(&s);
free(*((void **)cn + 4));
}
else
{
if ( flag_pretty )
printf("%c%d = ", (unsigned int)*((char *)cn + 24), *((unsigned int *)cn + 7));
_gmpz_out_str(stdout, 10LL, *((_QWORD *)cn + 2) + 16LL * *((int *)cn + 2) - 16);
puts(&s);
}
v6 = cn;
for ( i = 0LL; *((_DWORD *)cn + 2) > (int)i; ++i )
{
_gmpz_clear(*((_QWORD *)v6 + 2) + 16 * i);
v6 = cn;
}
free(*((void **)v6 + 2));
}
}

canonical_decompiled_code:
void func1()
{
int v0; // eax
int v1; // ebx
int v2; // ebx
void *v3; // rax
__int64 v4; // rbx
int v5; // er12
void *v6; // rax
__int64 i; // rbx
__int64 v8; // r12
__int64 v9; // rbp
__int64 v10; // r13
int v11; // ebx
const char *v12; // rax
size_t v13; // rax
__int64 v14; // [rsp+0h] [rbp-2038h] BYREF

v0 = cn_set_str(cn, buf);
if ( v0 )
{
v1 = v0;
if ( (unsigned int)(v0 - 1) > 1 )
{
if ( (v0 & 0xFC) != 0 )
{
fprintf(stderr, "%s\n", buf);
fprintf(
stderr,
"calc error retval = %d, reg1 = %d, reg2 = %d\n",
(unsigned __int8)v1,
BYTE1(v1),
(unsigned int)(v1 >> 16));
v3 = cn;
if ( *((int *)cn + 2) > 0 )
{
v4 = 0LL;
do
{
_gmpz_clear(*((_QWORD *)v3 + 2) + 16 * v4);
v3 = cn;
++v4;
}
while ( *((_DWORD *)cn + 2) > (int)v4 );
}
free(*((void **)v3 + 2));
}
else
{
v2 = v0 >> 8;
fprintf(stderr, "parse error:\n%s\n", buf);
for ( ; v2; --v2 )
fputc(32, stderr);
fwrite("^\n\n", 1uLL, 3uLL, stderr);
}
}
}
else
{
v5 = cn_check_algebraic_factor(cn);
if ( v5 > 0 )
{
puts(buf);
v8 = 16LL * (unsigned int)v5;
v9 = 0LL;
do
{
v10 = *((_QWORD *)cn + 4) + v9;
v11 = (unsigned int)_gmpz_probab_prime_p(v10, 30LL) == 0 ? 67 : 80;
v12 = (const char *)_gmpz_get_str(&v14, 10LL, v10);
v13 = strlen(v12);
printf("%c%d = ", (unsigned int)(char)v11, v13);
_gmpz_out_str(stdout, 10LL, *((_QWORD *)cn + 4) + v9);
puts(&s);
_gmpz_clear(*((_QWORD *)cn + 4) + v9);
v9 += 16LL;
}
while ( v9 != v8 );
puts(&s);
free(*((void **)cn + 4));
}
else
{
if ( flag_pretty )
printf("%c%d = ", (unsigned int)*((char *)cn + 24), *((unsigned int *)cn + 7));
_gmpz_out_str(stdout, 10LL, *((_QWORD *)cn + 2) + 16LL * *((int *)cn + 2) - 16);
puts(&s);
}
v6 = cn;
for ( i = 0LL; *((_DWORD *)cn + 2) > (int)i; ++i )
{
_gmpz_clear(*((_QWORD *)v6 + 2) + 16 * i);
v6 = cn;
}
free(*((void **)v6 + 2));
}
}

original_code:
void handle_each_line(){
  int ret;
  ret = cn_set_str(cn, buf);
  if(ret != 0){
    if(ret == 1 || ret == 2) return;
    if(((ret) != 0 && ((ret) & 0xff) <= 3)){
      int cnt = ((ret) >> 8);
      fprintf(stderr, "parse error:\n%s\n", buf);
      while(cnt--){
        fputc(' ', stderr);
      }
      fputs("^\n\n", stderr);
    }else{
      fprintf(stderr, "%s\n", buf);
      fprintf(stderr, "calc error retval = %d, reg1 = %d, reg2 = %d\n", ret&0xff, (ret>>8)&0xff, ret>>16);
      do{ int _i; for(_i = 0; _i < (cn)->nfactors; _i++){ __gmpz_clear((cn)->factor[_i]); } free((cn)->factor); }while(0);
    }
    return;
  }
  ret = cn_check_algebraic_factor(cn);
  if(ret > 0){
    int i;
    char tmpbuf[8192 +10];
      puts(buf);
    for(i = 0; i < ret; i++){
      char flag = __gmpz_probab_prime_p(cn->newfactor[i], 30) ? 'P' : 'C';
      int digit = strlen(__gmpz_get_str(tmpbuf, 10, cn->newfactor[i]));
      printf("%c%d = ", flag, digit);
      __gmpz_out_str(stdout, 10, cn->newfactor[i]);
      puts("");
      __gmpz_clear(cn->newfactor[i]);
    }
    puts("");
    free(cn->newfactor);
  }else{
    if(flag_pretty){
      printf("%c%d = ", cn->flag, cn->lf_digit);
    }
    __gmpz_out_str(stdout, 10, cn->factor[cn->nfactors-1]);
    puts("");
  }
  do{ int _i; for(_i = 0; _i < (cn)->nfactors; _i++){ __gmpz_clear((cn)->factor[_i]); } free((cn)->factor); }while(0);
}

canonical_original_code:
void handle_each_line(){
  int ret;
  ret = cn_set_str(cn, buf);
  if(ret != 0){
    if(ret == 1 || ret == 2) return;
    if(((ret) != 0 && ((ret) & 0xff) <= 3)){
      int cnt = ((ret) >> 8);
      fprintf(stderr, "parse error:\n%s\n", buf);
      while(cnt--){
        fputc(' ', stderr);
      }
      fputs("^\n\n", stderr);
    }else{
      fprintf(stderr, "%s\n", buf);
      fprintf(stderr, "calc error retval = %d, reg1 = %d, reg2 = %d\n", ret&0xff, (ret>>8)&0xff, ret>>16);
      do{ int _i; for(_i = 0; _i < (cn)->nfactors; _i++){ __gmpz_clear((cn)->factor[_i]); } free((cn)->factor); }while(0);
    }
    return;
  }
  ret = cn_check_algebraic_factor(cn);
  if(ret > 0){
    int i;
    char tmpbuf[-1];
      puts(buf);
    for(i = 0; i < ret; i++){
      char flag = __gmpz_probab_prime_p(cn->newfactor[i], 30) ? 'P' : 'C';
      int digit = strlen(__gmpz_get_str(tmpbuf, 10, cn->newfactor[i]));
      printf("%c%d = ", flag, digit);
      __gmpz_out_str(stdout, 10, cn->newfactor[i]);
      puts("");
      __gmpz_clear(cn->newfactor[i]);
    }
    puts("");
    free(cn->newfactor);
  }else{
    if(flag_pretty){
      printf("%c%d = ", cn->flag, cn->lf_digit);
    }
    __gmpz_out_str(stdout, 10, cn->factor[cn->nfactors-1]);
    puts("");
  }
  do{ int _i; for(_i = 0; _i < (cn)->nfactors; _i++){ __gmpz_clear((cn)->factor[_i]); } free((cn)->factor); }while(0);
}

variable_types: ret int

variable_types: cnt int

variable_types:
tmpbuf
char [-1]

variable_types: flag char

variable_types: digit int


main

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

if ( (int)parse_opts(argc, argv, envp) < 0 )
{
puts("komata");
}
else
{
cn = malloc(0x28uLL);
cnpoly_init();
aurpoly_init();
powlist_init();
while ( fgets(buf, 0x2000, stdin) )
{
v3 = strpbrk(buf, "\r\n");
if ( !v3 )
{
fwrite("Input too long\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*v3 = 0;
handle_each_line();
}
free(cn);
cnpoly_free();
aurpoly_free();
powlist_free();
}
return 0;
}

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

if ( (int)func0(argc, argv, envp) < 0 )
{
puts("komata");
}
else
{
cn = malloc(0x28uLL);
cnpoly_init();
aurpoly_init();
powlist_init();
while ( fgets(buf, 0x2000, stdin) )
{
v3 = strpbrk(buf, "\r\n");
if ( !v3 )
{
fwrite("Input too long\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*v3 = 0;
func1();
}
free(cn);
cnpoly_free();
aurpoly_free();
powlist_free();
}
return 0;
}

original_code:
int main(int argc, char *argv[]){
  if(parse_opts(argc, argv) < 0){
    printf("komata\n");
    return 0;
  }
  do{ (cn) = malloc(sizeof(_cn_t)); }while(0);
  cnpoly_init();
  aurpoly_init();
  powlist_init();
  while(fgets(buf, 8192, stdin) != ((void *)0)){
    char *pos = strpbrk(buf, "\r\n");
    if(pos == ((void *)0)){
      fputs("Input too long\n", stderr);
      exit(1);
    }
    *pos = '\0';
    handle_each_line();
  }
  free(cn);
  cnpoly_free();
  aurpoly_free();
  powlist_free();
  return 0;
}

variable_types: argc int

variable_types:
pos
char *


original_code:
static int algebraic_factor(cn_t cn, int k, int p){
  int factor[4];
  int faccnt[4];
  int pfactors = 0;
  int n = cn->n;
  int i, j;
  {
    int pp = p;
    p = 1;
    pfactors = 0;
    if((pp & 0x1) == 0){
      if((n & 0x1) == 0){
        do{
          pp >>= 1;
          p <<= 1;
        }while((pp & 0x1) == 0);
      }else{
        int cnt = 0;
        do{
          pp >>= 1;
          cnt++;
        }while((pp & 0x1) == 0);
        factor[pfactors] = 2;
        faccnt[pfactors++] = cnt;
      }
    }
    for(i = 3; i <= pp / i; i += 2){
      if(pp % i != 0) continue;
      if(n % i == 0){
        do{
          pp /= i;
          p *= i;
        }while(pp % i == 0);
      }else{
        int cnt = 0;
        do{
          pp /= i;
          cnt++;
        }while(pp % i == 0);
        factor[pfactors] = i;
        faccnt[pfactors++] = cnt;
      }
    }
    if(pp > 1){
      if(n % pp == 0){
        p *= pp;
      }else{
        factor[pfactors] = pp;
        faccnt[pfactors++] = 1;
      }
    }
  }
  if(pfactors == 0){
    mpz_t *afs = aur_factor(cn->factor[cn->nfactors-1], p*n, k);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
  {
    int kp;
    int nnewfactors = 0;
    mpz_t comp;
    memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
    cn->newfactor = ((void *)0);
    kp = 1;
    for(i = 0; i < p; i++){
      kp *= k;
    }
                         {
      int f = factor[0];
      int cnt = faccnt[0];
      int kpq = kp;
      int pnq = p*n;
      mpz_t prev, cur, alf;
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      __gmpz_set_ui(prev, 1);
      for(i = 0; i <= cnt; i++){
        cn_eval(cur, n, kpq);
        __gmpz_divexact(alf, cur, prev);
        __gmpz_gcd(alf, alf, comp);
        if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
          mpz_t *afs = aur_factor(alf, pnq, k);
          if(afs != ((void *)0)){
            nnewfactors += 2;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
            free(afs);
          }else if(__gmpz_cmp(alf, comp) != 0){
            nnewfactors += 1;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            __gmpz_init(cn->newfactor[nnewfactors-1]);
            __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
          }
        }
        __gmpz_swap(prev, cur);
        pnq *= f;
        {
          int tmp = kpq;
          int _;
          for(_ = 1; _ < f; _++){
            kpq *= tmp;
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    if(pfactors >= 2){
      int f0 = factor[0];
      int f1 = factor[1];
      int cnt0 = faccnt[0];
      int cnt1 = faccnt[1];
      int kpr = kp;
      int pnr = p*n;
      mpz_t prev, cur, alf;
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      for(i = 1; i <= cnt1; i++){
        int kpqrprev = kpr;
        int kpqrcur;
        int pnqr;
        kpqrcur = kpr;
        for(j = 1; j < f1; j++){
          kpqrcur *= kpr;
        }
        kpr = kpqrcur;
        pnr *= f1;
        pnqr = pnr;
        __gmpz_set_ui(prev, 1);
        for(j = 0; j <= cnt0; j++){
          cn_eval(alf, n, kpqrprev);
          cn_eval(cur, n, kpqrcur);
          __gmpz_divexact(cur, cur, alf);
          __gmpz_divexact(alf, cur, prev);
          __gmpz_gcd(alf, alf, comp);
          if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
            mpz_t *afs = aur_factor(alf, pnqr, k);
            if(afs != ((void *)0)){
              nnewfactors += 2;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
              free(afs);
            }else if(__gmpz_cmp(alf, comp) != 0){
              nnewfactors += 1;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              __gmpz_init(cn->newfactor[nnewfactors-1]);
              __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
            }
          }
          __gmpz_swap(prev, cur);
          pnqr *= f0;
          {
            int tmpprev = kpqrprev;
            int tmpcur = kpqrcur;
            int _;
            for(_ = 1; _ < f0; _++){
              kpqrprev *= tmpprev;
              kpqrcur *= tmpcur;
            }
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    return nnewfactors;
  }
}

canonical_original_code:
static int algebraic_factor(struct _cn_t *cn, int k, int p){
  int factor[4];
  int faccnt[4];
  int pfactors = 0;
  int n = cn->n;
  int i; int j;
  {
    int pp = p;
    p = 1;
    pfactors = 0;
    if((pp & 0x1) == 0){
      if((n & 0x1) == 0){
        do{
          pp >>= 1;
          p <<= 1;
        }while((pp & 0x1) == 0);
      }else{
        int cnt = 0;
        do{
          pp >>= 1;
          cnt++;
        }while((pp & 0x1) == 0);
        factor[pfactors] = 2;
        faccnt[pfactors++] = cnt;
      }
    }
    for(i = 3; i <= pp / i; i += 2){
      if(pp % i != 0) continue;
      if(n % i == 0){
        do{
          pp /= i;
          p *= i;
        }while(pp % i == 0);
      }else{
        int cnt = 0;
        do{
          pp /= i;
          cnt++;
        }while(pp % i == 0);
        factor[pfactors] = i;
        faccnt[pfactors++] = cnt;
      }
    }
    if(pp > 1){
      if(n % pp == 0){
        p *= pp;
      }else{
        factor[pfactors] = pp;
        faccnt[pfactors++] = 1;
      }
    }
  }
  if(pfactors == 0){
    struct __mpz_struct (*afs)[1] = aur_factor(cn->factor[cn->nfactors-1], p*n, k);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
  {
    int kp;
    int nnewfactors = 0;
    struct __mpz_struct comp[1];
    memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
    cn->newfactor = ((void *)0);
    kp = 1;
    for(i = 0; i < p; i++){
      kp *= k;
    }
                         {
      int f = factor[0];
      int cnt = faccnt[0];
      int kpq = kp;
      int pnq = p*n;
      struct __mpz_struct prev[1]; struct __mpz_struct cur[1]; struct __mpz_struct alf[1];
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      __gmpz_set_ui(prev, 1);
      for(i = 0; i <= cnt; i++){
        cn_eval(cur, n, kpq);
        __gmpz_divexact(alf, cur, prev);
        __gmpz_gcd(alf, alf, comp);
        if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
          struct __mpz_struct (*afs)[1] = aur_factor(alf, pnq, k);
          if(afs != ((void *)0)){
            nnewfactors += 2;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
            free(afs);
          }else if(__gmpz_cmp(alf, comp) != 0){
            nnewfactors += 1;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            __gmpz_init(cn->newfactor[nnewfactors-1]);
            __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
          }
        }
        __gmpz_swap(prev, cur);
        pnq *= f;
        {
          int tmp = kpq;
          int _;
          for(_ = 1; _ < f; _++){
            kpq *= tmp;
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    if(pfactors >= 2){
      int f0 = factor[0];
      int f1 = factor[1];
      int cnt0 = faccnt[0];
      int cnt1 = faccnt[1];
      int kpr = kp;
      int pnr = p*n;
      struct __mpz_struct prev[1]; struct __mpz_struct cur[1]; struct __mpz_struct alf[1];
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      for(i = 1; i <= cnt1; i++){
        int kpqrprev = kpr;
        int kpqrcur;
        int pnqr;
        kpqrcur = kpr;
        for(j = 1; j < f1; j++){
          kpqrcur *= kpr;
        }
        kpr = kpqrcur;
        pnr *= f1;
        pnqr = pnr;
        __gmpz_set_ui(prev, 1);
        for(j = 0; j <= cnt0; j++){
          cn_eval(alf, n, kpqrprev);
          cn_eval(cur, n, kpqrcur);
          __gmpz_divexact(cur, cur, alf);
          __gmpz_divexact(alf, cur, prev);
          __gmpz_gcd(alf, alf, comp);
          if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
            struct __mpz_struct (*afs)[1] = aur_factor(alf, pnqr, k);
            if(afs != ((void *)0)){
              nnewfactors += 2;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
              free(afs);
            }else if(__gmpz_cmp(alf, comp) != 0){
              nnewfactors += 1;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              __gmpz_init(cn->newfactor[nnewfactors-1]);
              __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
            }
          }
          __gmpz_swap(prev, cur);
          pnqr *= f0;
          {
            int tmpprev = kpqrprev;
            int tmpcur = kpqrcur;
            int _;
            for(_ = 1; _ < f0; _++){
              kpqrprev *= tmpprev;
              kpqrcur *= tmpcur;
            }
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    return nnewfactors;
  }
}

variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: k int

variable_types: p int

variable_types:
factor
int [4]

variable_types:
faccnt
int [4]

variable_types: pfactors int

variable_types: n int

variable_types: j int

variable_types: pp int

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: kp int

variable_types: nnewfactors int

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: f int

variable_types: kpq int

variable_types: pnq int

variable_types: tmp int

variable_types: kpr int

variable_types: pnr int

variable_types: kpqrprev int

variable_types: kpqrcur int

variable_types: pnqr int

variable_types: tmpprev int

variable_types: tmpcur int

user_defined_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; }


decompiled_code:
__int64 __fastcall cn_check_algebraic_factor(int *a1)
{
int v2; // er8
int v3; // ecx
int v4; // edi
unsigned int i; // esi
__int64 result; // rax
int v7; // eax
int v8; // edx
__int64 v9; // rdx

v2 = a1[1];
if ( v2 > 3 )
{
v3 = 2;
do
v4 = v3++;
while ( 1 << v3 <= v2 );
if ( v4 > 1 )
{
do
{
for ( i = 2; ; ++i )
{
if ( v4 > 0 )
{
v7 = 0;
v8 = 1;
do
{
v8 *= i;
++v7;
}
while ( v7 != v4 );
if ( v2 == v8 )
return algebraic_factor(a1, i, v4);
if ( v2 < v8 )
break;
}
}
--v4;
}
while ( v4 != 1 );
}
}
v9 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, (unsigned int)*a1, (unsigned int)v2);
result = 0LL;
if ( v9 )
{
*((_QWORD *)a1 + 4) = v9;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v2; // er8
int v3; // ecx
int v4; // edi
unsigned int i; // esi
__int64 result; // rax
int v7; // eax
int v8; // edx
__int64 v9; // rdx

v2 = a1[1];
if ( v2 > 3 )
{
v3 = 2;
do
v4 = v3++;
while ( 1 << v3 <= v2 );
if ( v4 > 1 )
{
do
{
for ( i = 2; ; ++i )
{
if ( v4 > 0 )
{
v7 = 0;
v8 = 1;
do
{
v8 *= i;
++v7;
}
while ( v7 != v4 );
if ( v2 == v8 )
return func0(a1, i, v4);
if ( v2 < v8 )
break;
}
}
--v4;
}
while ( v4 != 1 );
}
}
v9 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, (unsigned int)*a1, (unsigned int)v2);
result = 0LL;
if ( v9 )
{
*((_QWORD *)a1 + 4) = v9;
result = 2LL;
}
return result;
}

original_code:
int cn_check_algebraic_factor(cn_t cn){
  int x = cn->x;
  int p;
  for(p = 2; (1 << p) <= x; p++);
  while(--p > 1){
    int k = 2;
    while(1){
      int m = 1;
      int i;
      for(i = 0; i < p; i++){
        m *= k;
      }
      if(m == x){
        return algebraic_factor(cn, k, p);
      }
      if(m > x) break;
      k++;
    }
  }
  {
    mpz_t *afs = aur_factor(cn->factor[cn->nfactors-1], cn->n, x);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
}

canonical_original_code:
int cn_check_algebraic_factor(struct _cn_t *cn){
  int x = cn->x;
  int p;
  for(p = 2; (1 << p) <= x; p++);
  while(--p > 1){
    int k = 2;
    while(1){
      int m = 1;
      int i;
      for(i = 0; i < p; i++){
        m *= k;
      }
      if(m == x){
        return algebraic_factor(cn, k, p);
      }
      if(m > x) break;
      k++;
    }
  }
  {
    struct __mpz_struct (*afs)[1] = aur_factor(cn->factor[cn->nfactors-1], cn->n, x);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
}

variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: x int

variable_types: p int

variable_types: k int

variable_types: m int

variable_types: i int


decompiled_code:
__int64 __fastcall cn_eval(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // r15
unsigned int v5; // edx
int v6; // ebx
__int64 v7; // r13
__int64 result; // rax
__int64 v9; // r14
int v10; // ebx
int v11; // [rsp+Ch] [rbp-3Ch]

v4 = cn_poly(a2);
v6 = v5;
v11 = v5;
v7 = pow_list(a3, v5);
result = _gmpz_set_ui(a1, 0LL);
if ( v6 >= 0 )
{
v9 = 0LL;
do
{
v10 = *(_DWORD *)(v4 + 4 * v9);
if ( v10 <= 0 )
{
if ( v10 < 0 )
{
do
{
result = _gmpz_sub(a1, a1, v7);
++v10;
}
while ( v10 );
}
}
else
{
do
{
result = _gmpz_add(a1, a1, v7);
--v10;
}
while ( v10 );
}
++v9;
v7 += 16LL;
}
while ( v11 >= (int)v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // r15
unsigned int v5; // edx
int v6; // ebx
__int64 v7; // r13
__int64 result; // rax
__int64 v9; // r14
int v10; // ebx
int v11; // [rsp+Ch] [rbp-3Ch]

v4 = cn_poly(a2);
v6 = v5;
v11 = v5;
v7 = pow_list(a3, v5);
result = _gmpz_set_ui(a1, 0LL);
if ( v6 >= 0 )
{
v9 = 0LL;
do
{
v10 = *(_DWORD *)(v4 + 4 * v9);
if ( v10 <= 0 )
{
if ( v10 < 0 )
{
do
{
result = _gmpz_sub(a1, a1, v7);
++v10;
}
while ( v10 );
}
}
else
{
do
{
result = _gmpz_add(a1, a1, v7);
--v10;
}
while ( v10 );
}
++v9;
v7 += 16LL;
}
while ( v11 >= (int)v9 );
}
return result;
}

original_code:
void cn_eval(mpz_t cn, int n, int x){
  cnpoly_t cp;
  int *poly, degree;
  mpz_t *pw;
  int i;
  cp = cn_poly(n);
  poly = cp.poly;
  degree = cp.degree;
  pw = pow_list(x, degree);
  __gmpz_set_ui(cn, 0);
  for(i = 0; i <= degree; i++){
    int j = poly[i];
    while(j > 0){
      __gmpz_add(cn, cn, pw[i]);
      j--;
    }
    while(j < 0){
      __gmpz_sub(cn, cn, pw[i]);
      j++;
    }
  }
}

canonical_original_code:
void cn_eval(struct __mpz_struct cn[1], int n, int x){
  struct cnpoly_t cp;
  int *poly; int degree;
  struct __mpz_struct (*pw)[1];
  int i;
  cp = cn_poly(n);
  poly = cp.poly;
  degree = cp.degree;
  pw = pow_list(x, degree);
  __gmpz_set_ui(cn, 0);
  for(i = 0; i <= degree; i++){
    int j = poly[i];
    while(j > 0){
      __gmpz_add(cn, cn, pw[i]);
      j--;
    }
    while(j < 0){
      __gmpz_sub(cn, cn, pw[i]);
      j++;
    }
  }
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: n int

variable_types: struct cnpoly_t { int *poly; int degree; }

variable_types:
poly
int *

variable_types: degree int

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: j int


decompiled_code:
__int64 __fastcall get_inversed_poly(int a1, int a2)
{
int v2; // ebx
_DWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rsi

v2 = qword_548[2 * a2];
v3 = malloc(4LL * (v2 + 1));
result = 16LL * a1;
*(__int64 *)((char *)cnpoly + result) = (__int64)v3;
*v3 = 1;
if ( v2 > 0 )
{
v5 = cnpoly[2 * a2];
result = 1LL;
do
{
v3[result] = -*(_DWORD *)(v5 + 4 * result);
v3[result + 1] = *(_DWORD *)(v5 + 4 * result + 4);
result += 2LL;
}
while ( v2 >= (int)result );
}
LODWORD(qword_548[2 * a1]) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // ebx
_DWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rsi

v2 = qword_548[2 * a2];
v3 = malloc(4LL * (v2 + 1));
result = 16LL * a1;
*(__int64 *)((char *)cnpoly + result) = (__int64)v3;
*v3 = 1;
if ( v2 > 0 )
{
v5 = cnpoly[2 * a2];
result = 1LL;
do
{
v3[result] = -*(_DWORD *)(v5 + 4 * result);
v3[result + 1] = *(_DWORD *)(v5 + 4 * result + 4);
result += 2LL;
}
while ( v2 >= (int)result );
}
LODWORD(qword_548[2 * a1]) = v2;
return result;
}

original_code:
static inline void get_inversed_poly(int N, int n){
  int degree;
  int i;
  degree = cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = 1; i <= degree; i++){
    cnpoly[N].poly[i] = -cnpoly[n].poly[i];
    i++;
    cnpoly[N].poly[i] = cnpoly[n].poly[i];
  }
  cnpoly[N].degree = degree;
}

variable_types: N int


original_code:
static inline void get_multipled_poly(int N, int n){
  int degree;
  int p = N / n;
  int i, j;
  degree = p * cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = j = 1; i <= degree; ){
    int k = p - 1;
    do{
      cnpoly[N].poly[i++] = 0;
      k--;
    }while(k > 0);
    cnpoly[N].poly[i++] = cnpoly[n].poly[j++];
  }
  cnpoly[N].degree = degree;
}

canonical_original_code:
static inline void get_multipled_poly(int N, int n){
  int degree;
  int p = N / n;
  int i; int j;
  degree = p * cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = j = 1; i <= degree; ){
    int k = p - 1;
    do{
      cnpoly[N].poly[i++] = 0;
      k--;
    }while(k > 0);
    cnpoly[N].poly[i++] = cnpoly[n].poly[j++];
  }
  cnpoly[N].degree = degree;
}


original_code:
static void cn_poly_init(int N){
  int factor[4];
  int nfactors = 0;
  int n = N;
  int p;
  int i;
  if((n & 0x1) == 0){
    do{
      n >>= 1;
    }while((n & 0x1) == 0);
    factor[nfactors++] = 2;
    p = 2;
  }else{
    p = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    do{
      n /= i;
    }while(n % i == 0);
    factor[nfactors++] = i;
    p *= i;
  }
  if(n > 1){
    factor[nfactors++] = n;
    p *= n;
  }
  cn_poly_init_with_factors(p, factor, nfactors);
  if(N != p){
    get_multipled_poly(N, p);
  }
}

variable_types:
factor
int [4]

variable_types: nfactors int


decompiled_code:
__int64 __fastcall cn_poly(int a1)
{
if ( !cnpoly[2 * a1] )
cn_poly_init(a1);
return cnpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( !cnpoly[2 * a1] )
func2(a1);
return cnpoly[2 * a1];
}

canonical_original_code:
struct cnpoly_t cn_poly(int N){
  if(cnpoly[N].poly == ((void *)0)){
    cn_poly_init(N);
  }
  return cnpoly[N];
}

return_type: struct cnpoly_t { int *poly; int degree; }


decompiled_code:
const char *cnpoly_init()
{
const char *result; // rax

result = (const char *)cnpoly;
do
{
*(_QWORD *)result = 0LL;
result += 16;
}
while ( result != "cn_poly.c" );
return result;
}

canonical_decompiled_code:
const char *func4()
{
const char *result; // rax

result = (const char *)cnpoly;
do
{
*(_QWORD *)result = 0LL;
result += 16;
}
while ( result != "cn_poly.c" );
return result;
}

original_code:
void cnpoly_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    cnpoly[i].poly = ((void *)0);
  }
}


decompiled_code:
void cnpoly_free()
{
void **v0; // rbx

v0 = (void **)cnpoly;
do
{
free(*v0);
v0 += 2;
}
while ( v0 != (void **)"cn_poly.c" );
}

canonical_decompiled_code:
void func5()
{
void **v0; // rbx

v0 = (void **)cnpoly;
do
{
free(*v0);
v0 += 2;
}
while ( v0 != (void **)"cn_poly.c" );
}

original_code:
void cnpoly_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    free(cnpoly[i].poly);
  }
}


decompiled_code:
__int64 __fastcall pow_list_append(int a1, int a2)
{
unsigned __int64 v3; // rax
char *v4; // rdi
__int64 result; // rax
int v6; // ebp
char *v7; // rbx

v3 = 4LL * a1;
v4 = (char *)powlist[v3 / 2];
if ( dword_1EC[v3] < a2 )
{
v4 = (char *)realloc(v4, 16LL * (a2 + 1));
powlist[2 * a1] = (__int64)v4;
}
result = 16LL * a1;
v6 = *(int *)((char *)dword_1E8 + result) + 1;
if ( a2 >= v6 )
{
v7 = &v4[16 * v6];
do
{
_gmpz_init(v7);
result = _gmpz_mul_ui(v7, v7 - 16, a1);
++v6;
v7 += 16;
}
while ( a2 >= v6 );
}
dword_1E8[4 * a1] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
unsigned __int64 v3; // rax
char *v4; // rdi
__int64 result; // rax
int v6; // ebp
char *v7; // rbx

v3 = 4LL * a1;
v4 = (char *)powlist[v3 / 2];
if ( dword_1EC[v3] < a2 )
{
v4 = (char *)realloc(v4, 16LL * (a2 + 1));
powlist[2 * a1] = (__int64)v4;
}
result = 16LL * a1;
v6 = *(int *)((char *)dword_1E8 + result) + 1;
if ( a2 >= v6 )
{
v7 = &v4[16 * v6];
do
{
_gmpz_init(v7);
result = _gmpz_mul_ui(v7, v7 - 16, a1);
++v6;
v7 += 16;
}
while ( a2 >= v6 );
}
dword_1E8[4 * a1] = a2;
return result;
}

original_code:
static inline void pow_list_append(int x, int d){
  mpz_t *list = powlist[x].list;
  int i;
  if(powlist[x].maxdegree < d){
    powlist[x].list = list = realloc(list, (d+1) * sizeof(mpz_t));
  }
  for(i = powlist[x].degree+1; i <= d; i++){
    __gmpz_init(list[i]);
    __gmpz_mul_ui(list[i], list[i-1], x);
  }
  powlist[x].degree = d;
}

canonical_original_code:
static inline void pow_list_append(int x, int d){
  struct __mpz_struct (*list)[1] = powlist[x].list;
  int i;
  if(powlist[x].maxdegree < d){
    powlist[x].list = list = realloc(list, (d+1) * sizeof(mpz_t));
  }
  for(i = powlist[x].degree+1; i <= d; i++){
    __gmpz_init(list[i]);
    __gmpz_mul_ui(list[i], list[i-1], x);
  }
  powlist[x].degree = d;
}

variable_types: d int

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 __fastcall pow_list_init(int a1, int a2)
{
void *v2; // rax

v2 = malloc(0x1910uLL);
powlist[2 * a1] = (__int64)v2;
_gmpz_init_set_ui(v2, 1LL);
_gmpz_init_set_ui(powlist[2 * a1] + 16, a1);
dword_1E8[4 * a1] = 1;
dword_1EC[4 * a1] = 400;
return pow_list_append(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
void *v2; // rax

v2 = malloc(0x1910uLL);
powlist[2 * a1] = (__int64)v2;
_gmpz_init_set_ui(v2, 1LL);
_gmpz_init_set_ui(powlist[2 * a1] + 16, a1);
dword_1E8[4 * a1] = 1;
dword_1EC[4 * a1] = 400;
return func0(a1, a2);
}

original_code:
static inline void pow_list_init(int x, int d){
  powlist[x].list = malloc((400 +1) * sizeof(mpz_t));
  __gmpz_init_set_ui(powlist[x].list[0], 1);
  __gmpz_init_set_ui(powlist[x].list[1], x);
  powlist[x].degree = 1;
  powlist[x].maxdegree = 400;
  pow_list_append(x, d);
}


decompiled_code:
__int64 __fastcall pow_list(int a1, int a2)
{
if ( powlist[2 * a1] )
{
if ( dword_1E8[4 * a1] < a2 )
pow_list_append(a1, a2);
}
else
{
pow_list_init(a1, a2);
}
return powlist[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
if ( powlist[2 * a1] )
{
if ( dword_1E8[4 * a1] < a2 )
func0(a1, a2);
}
else
{
func1(a1, a2);
}
return powlist[2 * a1];
}

original_code:
mpz_t *pow_list(int x, int d){
  if(powlist[x].list == ((void *)0)){
    pow_list_init(x, d);
  }else if(powlist[x].degree < d){
    pow_list_append(x, d);
  }
  return powlist[x].list;
}

canonical_original_code:
struct __mpz_struct (*pow_list(int x, int d))[1]{
  if(powlist[x].list == ((void *)0)){
    pow_list_init(x, d);
  }else if(powlist[x].degree < d){
    pow_list_append(x, d);
  }
  return powlist[x].list;
}

return_type: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]


decompiled_code:
__int64 *powlist_init()
{
__int64 *result; // rax

result = powlist;
do
{
*result = 0LL;
result += 2;
}
while ( result != (__int64 *)&unk_4070 );
return result;
}

canonical_decompiled_code:
__int64 *func3()
{
__int64 *result; // rax

result = powlist;
do
{
*result = 0LL;
result += 2;
}
while ( result != (__int64 *)&unk_4070 );
return result;
}

original_code:
void powlist_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    powlist[i].list = ((void *)0);
  }
}


original_code:
void powlist_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    if(powlist[i].list != ((void *)0)){
      int j;
      for(j = 0; j <= powlist[i].degree; j++){
        __gmpz_clear(powlist[i].list[j]);
      }
      free(powlist[i].list);
    }
  }
}


original_code:
static inline int read_int(const char *str, int *n){
  int x = 0;
  int i = 0;
  do{
    x = x * 10 + str[i++] - '0';
  }while(str[i] >= '0' && str[i] <= '9');
  *n = x;
  return i;
}

canonical_original_code:
static inline int read_int(char *str, int *n){
  int x = 0;
  int i = 0;
  do{
    x = x * 10 + str[i++] - '0';
  }while(str[i] >= '0' && str[i] <= '9');
  *n = x;
  return i;
}

variable_types:
str
char *

variable_types:
n
int *


variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: ix int

variable_types: cnt int


original_code:
static int pass2(cn_t cn, const char *str){
  mpz_t comp;
  int ret = 0;
  str = strchr(str+5, '(');
  str++;
  __gmpz_init(comp);
  cn_eval(comp, cn->n, cn->x);
  if(str[0] == '1' && str[1] == ')'){
    memcpy(cn->factor[0], comp, sizeof(mpz_t));
    cn->nfactors = 1;
  }else{
    int fix = 0;
    mpz_t tmpq, tmpr;
    __gmpz_init(tmpq);
    __gmpz_init(tmpr);
    do{
      mpz_t factor;
      int i = 0;
      while(*str >= '0' && *str <= '9'){
        buf[i++] = *str++;
      }
      buf[i] = '\0';
      __gmpz_init_set_str(factor, buf, 10);
      __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
      if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)){
        if(ret == 0){
          ret = (4 | ((fix) << 8));
        }
      }else{
        __gmpz_set(comp, tmpq);
        if(!__gmpz_probab_prime_p(factor, 30)){
          if(ret == 0){
            ret = (5 | ((fix) << 8));
          }
        }
        if(fix > 0 && __gmpz_cmp(cn->factor[fix-1], factor) > 0){
          if(ret == 0){
            ret = (6 | ((fix) << 8));
          }
        }
        memcpy(cn->factor[fix++], factor, sizeof(mpz_t));
      }
    }while(*str++ == ' ');
    __gmpz_clear(tmpq);
    __gmpz_clear(tmpr);
    memcpy(cn->factor[fix++], comp, sizeof(mpz_t));
    cn->nfactors = fix;
  }
  {
    char realflag;
    int realdigit;
    realflag = __gmpz_probab_prime_p(comp, 30) ? 'P' : 'C';
    if(cn->flag != realflag){
      ret |= (1 << 3);
    }
    if(cn->nfactors > 1 && realflag == 'P'
    && __gmpz_cmp(cn->factor[cn->nfactors-2], comp) > 0){
      ret |= (1 << 4);
    }
    realdigit = strlen(__gmpz_get_str(buf, 10, comp));
    if(cn->lf_digit != realdigit){
      ret |= ((1 << 5) | ((realdigit) << 16));
    }
  }
  return ret;
}

canonical_original_code:
static int pass2(struct _cn_t *cn, char *str){
  struct __mpz_struct comp[1];
  int ret = 0;
  str = strchr(str+5, '(');
  str++;
  __gmpz_init(comp);
  cn_eval(comp, cn->n, cn->x);
  if(str[0] == '1' && str[1] == ')'){
    memcpy(cn->factor[0], comp, sizeof(mpz_t));
    cn->nfactors = 1;
  }else{
    int fix = 0;
    struct __mpz_struct tmpq[1]; struct __mpz_struct tmpr[1];
    __gmpz_init(tmpq);
    __gmpz_init(tmpr);
    do{
      struct __mpz_struct factor[1];
      int i = 0;
      while(*str >= '0' && *str <= '9'){
        buf[i++] = *str++;
      }
      buf[i] = '\0';
      __gmpz_init_set_str(factor, buf, 10);
      __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
      if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)){
        if(ret == 0){
          ret = (4 | ((fix) << 8));
        }
      }else{
        __gmpz_set(comp, tmpq);
        if(!__gmpz_probab_prime_p(factor, 30)){
          if(ret == 0){
            ret = (5 | ((fix) << 8));
          }
        }
        if(fix > 0 && __gmpz_cmp(cn->factor[fix-1], factor) > 0){
          if(ret == 0){
            ret = (6 | ((fix) << 8));
          }
        }
        memcpy(cn->factor[fix++], factor, sizeof(mpz_t));
      }
    }while(*str++ == ' ');
    __gmpz_clear(tmpq);
    __gmpz_clear(tmpr);
    memcpy(cn->factor[fix++], comp, sizeof(mpz_t));
    cn->nfactors = fix;
  }
  {
    char realflag;
    int realdigit;
    realflag = __gmpz_probab_prime_p(comp, 30) ? 'P' : 'C';
    if(cn->flag != realflag){
      ret |= (1 << 3);
    }
    if(cn->nfactors > 1 && realflag == 'P'
    && __gmpz_cmp(cn->factor[cn->nfactors-2], comp) > 0){
      ret |= (1 << 4);
    }
    realdigit = strlen(__gmpz_get_str(buf, 10, comp));
    if(cn->lf_digit != realdigit){
      ret |= ((1 << 5) | ((realdigit) << 16));
    }
  }
  return ret;
}

variable_types: ret int

variable_types: fix int

variable_types: i int

variable_types: realflag char

variable_types: realdigit int


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

result = pass1((__int64)a1, a2);
if ( !(_DWORD)result )
result = pass2(a1, a2);
return result;
}

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

result = func1((__int64)a1, a2);
if ( !(_DWORD)result )
result = func2(a1, a2);
return result;
}

original_code:
int cn_set_str(cn_t cn, const char *str){
  int ret;
  ret = pass1(cn, str);
  if(ret != 0){
    return ret;
  }
  return pass2(cn, str);
}

canonical_original_code:
int cn_set_str(struct _cn_t *cn, char *str){
  int ret;
  ret = pass1(cn, str);
  if(ret != 0){
    return ret;
  }
  return pass2(cn, str);
}


original_code:
int cn_add_factor(cn_t cn, const char *str){
  mpz_t comp, factor;
  mpz_t tmpq, tmpr;
  int i;
  __gmpz_init(factor);
  __gmpz_init(tmpq);
  __gmpz_init(tmpr);
  if(cn->flag != 'C') goto err;
  memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
  __gmpz_set_str(factor, str, 10);
  if(!__gmpz_probab_prime_p(factor, 30)) goto err;
  __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
  if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)) goto err;
  if((__builtin_constant_p (1) && (1) == 0 ? ((tmpq)->_mp_size < 0 ? -1 : (tmpq)->_mp_size > 0) : __gmpz_cmp_ui (tmpq,1)) <= 0) goto err;
  cn->flag = __gmpz_probab_prime_p(tmpq, 30) ? 'P' : 'C';
  cn->factor = realloc(cn->factor, (cn->nfactors+1) * sizeof(mpz_t));
  for(i = 0; i < cn->nfactors; i++){
    if(__gmpz_cmp(cn->factor[i], factor) > 0){
      memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i) * sizeof(mpz_t));
      memcpy(cn->factor[i], factor, sizeof(mpz_t));
      cn->nfactors++;
      break;
    }
  }
  if(cn->flag == 'P'){
    for(i = 0; i < cn->nfactors; i++){
      if(__gmpz_cmp(cn->factor[i], tmpq) > 0){
        memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i-1) * sizeof(mpz_t));
        __gmpz_set(comp, tmpq);
        memcpy(cn->factor[i], comp, sizeof(mpz_t));
        break;
      }
    }
  }else{
    __gmpz_set(cn->factor[cn->nfactors-1], tmpq);
  }
  {
    static char buf[1024];
    cn->lf_digit = strlen(__gmpz_get_str(buf, 10, cn->factor[cn->nfactors-1]));
  }
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return 0;
err:
  __gmpz_clear(factor);
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return (4 | ((0) << 8));
}

canonical_original_code:
int cn_add_factor(struct _cn_t *cn, char *str){
  struct __mpz_struct comp[1]; struct __mpz_struct factor[1];
  struct __mpz_struct tmpq[1]; struct __mpz_struct tmpr[1];
  int i;
  __gmpz_init(factor);
  __gmpz_init(tmpq);
  __gmpz_init(tmpr);
  if(cn->flag != 'C') goto err;
  memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
  __gmpz_set_str(factor, str, 10);
  if(!__gmpz_probab_prime_p(factor, 30)) goto err;
  __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
  if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)) goto err;
  if((__builtin_constant_p (1) && (1) == 0 ? ((tmpq)->_mp_size < 0 ? -1 : (tmpq)->_mp_size > 0) : __gmpz_cmp_ui (tmpq,1)) <= 0) goto err;
  cn->flag = __gmpz_probab_prime_p(tmpq, 30) ? 'P' : 'C';
  cn->factor = realloc(cn->factor, (cn->nfactors+1) * sizeof(mpz_t));
  for(i = 0; i < cn->nfactors; i++){
    if(__gmpz_cmp(cn->factor[i], factor) > 0){
      memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i) * sizeof(mpz_t));
      memcpy(cn->factor[i], factor, sizeof(mpz_t));
      cn->nfactors++;
      break;
    }
  }
  if(cn->flag == 'P'){
    for(i = 0; i < cn->nfactors; i++){
      if(__gmpz_cmp(cn->factor[i], tmpq) > 0){
        memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i-1) * sizeof(mpz_t));
        __gmpz_set(comp, tmpq);
        memcpy(cn->factor[i], comp, sizeof(mpz_t));
        break;
      }
    }
  }else{
    __gmpz_set(cn->factor[cn->nfactors-1], tmpq);
  }
  {
    static char buf[1024];
    cn->lf_digit = strlen(__gmpz_get_str(buf, 10, cn->factor[cn->nfactors-1]));
  }
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return 0;
err:
  __gmpz_clear(factor);
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return (4 | ((0) << 8));
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
buf
char [1024]


original_code:
static int q_update(int N){
  static int aurtable[4][4] = {
    { 0, 0, 0, 0},
    { 1, 1, 1, 1},
    { 2, 0, -2, 0},
    { 1, -1, 1, -1}
  };
  int factor[4];
  int nfactors = 0;
  int n = N;
  int phi;
  int k, i;
  if((n & 0x1) == 0){
    n >>= 1;
    factor[nfactors++] = 2;
    phi = 2;
  }else{
    phi = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    n /= i;
    factor[nfactors++] = i;
    phi *= i-1;
  }
  if(n > 1){
    factor[nfactors++] = n;
    phi *= n-1;
  }
  phi = (phi+1) >> 1;
  q[0] = 0;
  k = 1;
  do{
    {
      int kk;
      kk = k + k - 1;
      for(i = 0; i < nfactors; i++){
        if(kk % factor[i] == 0){
          q[kk] = 0;
          goto nojacobi;
        }
      }
      q[kk] = jacobi(N, kk);
nojacobi:;
    }
    {
      int r = aurtable[N & 0x3][k & 0x3];
      for(i = 0; i < nfactors; i++){
        if(k % factor[i] == 0){
          r *= factor[i]-1;
        }else{
          r = -r;
        }
      }
      q[k+k] = r;
    }
    k++;
  }while(k <= phi);
  return phi;
}

canonical_original_code:
static int q_update(int N){
  static int aurtable[4][4] = {
    { 0, 0, 0, 0},
    { 1, 1, 1, 1},
    { 2, 0, -2, 0},
    { 1, -1, 1, -1}
  };
  int factor[4];
  int nfactors = 0;
  int n = N;
  int phi;
  int k; int i;
  if((n & 0x1) == 0){
    n >>= 1;
    factor[nfactors++] = 2;
    phi = 2;
  }else{
    phi = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    n /= i;
    factor[nfactors++] = i;
    phi *= i-1;
  }
  if(n > 1){
    factor[nfactors++] = n;
    phi *= n-1;
  }
  phi = (phi+1) >> 1;
  q[0] = 0;
  k = 1;
  do{
    {
      int kk;
      kk = k + k - 1;
      for(i = 0; i < nfactors; i++){
        if(kk % factor[i] == 0){
          q[kk] = 0;
          goto nojacobi;
        }
      }
      q[kk] = jacobi(N, kk);
nojacobi:;
    }
    {
      int r = aurtable[N & 0x3][k & 0x3];
      for(i = 0; i < nfactors; i++){
        if(k % factor[i] == 0){
          r *= factor[i]-1;
        }else{
          r = -r;
        }
      }
      q[k+k] = r;
    }
    k++;
  }while(k <= phi);
  return phi;
}

variable_types:
aurtable
int [4][4]

variable_types: n int

variable_types: phi int

variable_types: k int

variable_types: kk int

variable_types: r int


decompiled_code:
__int64 __fastcall aur_Cpoly(int a1)
{
if ( !aurCpoly[2 * a1] )
aur_poly_init(a1);
return aurCpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( !aurCpoly[2 * a1] )
func2(a1);
return aurCpoly[2 * a1];
}

canonical_original_code:
struct aurpoly_t aur_Cpoly(int n){
  if(aurCpoly[n].poly == ((void *)0)){
    aur_poly_init(n);
  }
  return aurCpoly[n];
}

return_type: struct aurpoly_t { long *poly; int degree; }


decompiled_code:
__int64 __fastcall aur_Dpoly(int a1)
{
if ( !aurDpoly[2 * a1] )
aur_poly_init(a1);
return aurDpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( !aurDpoly[2 * a1] )
func2(a1);
return aurDpoly[2 * a1];
}

canonical_original_code:
struct aurpoly_t aur_Dpoly(int n){
  if(aurDpoly[n].poly == ((void *)0)){
    aur_poly_init(n);
  }
  return aurDpoly[n];
}

user_defined_types: struct aurpoly_t { long *poly; int degree; }


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

for ( result = 0LL; result != 2002; result += 2LL )
{
aurCpoly[result] = 0LL;
aurDpoly[result] = 0LL;
}
return result * 8;
}

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

for ( result = 0LL; result != 2002; result += 2LL )
{
aurCpoly[result] = 0LL;
aurDpoly[result] = 0LL;
}
return result * 8;
}

original_code:
void aurpoly_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    aurCpoly[i].poly = ((void *)0);
    aurDpoly[i].poly = ((void *)0);
  }
}


decompiled_code:
void aurpoly_free()
{
__int64 i; // rbx

for ( i = 0LL; i != 2002; i += 2LL )
{
free((void *)aurCpoly[i]);
free((void *)aurDpoly[i]);
}
}

canonical_decompiled_code:
void func6()
{
__int64 i; // rbx

for ( i = 0LL; i != 2002; i += 2LL )
{
free((void *)aurCpoly[i]);
free((void *)aurDpoly[i]);
}
}

original_code:
void aurpoly_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    free(aurCpoly[i].poly);
    free(aurDpoly[i].poly);
  }
}


printUsage

repo: nubbel/simple-gpio

decompiled_code:
void __fastcall __noreturn printUsage(const char **a1)
{
fprintf(stderr, "Usage: %s export <pin>\n\n", *a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char **a1)
{
fprintf(stderr, "Usage: %s export <pin>\n\n", *a1);
exit(1);
}

original_code:
void printUsage(char *argv[]) {
 fprintf(stderr, "Usage: %s export <pin>\n\n", argv[0]);
 exit(1);
}

variable_types:
argv
char *[]


changeOwner

decompiled_code:
int __fastcall changeOwner(unsigned int a1, const char *a2, __uid_t a3, __gid_t a4)
{
int result; // eax
int *v7; // r12
char *v8; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( snprintf(v9, 0x1000uLL, "/sys/class/gpio/gpio%d/%s", a1, a2) > 4095 )
return fwrite("Path of GPIO pin is too long!", 1uLL, 0x1DuLL, stderr);
result = chown(v9, a3, a4);
if ( result < 0 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", v9, a3, a4, (unsigned int)*v7, v8);
exit(-*v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2, __uid_t a3, __gid_t a4)
{
int result; // eax
int *v7; // r12
char *v8; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( snprintf(v9, 0x1000uLL, "/sys/class/gpio/gpio%d/%s", a1, a2) > 4095 )
return fwrite("Path of GPIO pin is too long!", 1uLL, 0x1DuLL, stderr);
result = chown(v9, a3, a4);
if ( result < 0 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", v9, a3, a4, (unsigned int)*v7, v8);
exit(-*v7);
}
return result;
}

original_code:
void changeOwner(int pin, const char *filename, int uid, int gid) {
   char path[4096];
   int size = snprintf(path, 4096, "/sys/class/gpio/gpio%d/%s", pin, filename);
   if (size >= 4096) {
    fprintf(stderr, "Path of GPIO pin is too long!");
     return;
   }
 if (chown(path, uid, gid) < 0) {
     fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", path, uid, gid, (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
 }
}

canonical_original_code:
void changeOwner(int pin, char *filename, int uid, int gid) {
   char path[4096];
   int size = snprintf(path, 4096, "/sys/class/gpio/gpio%d/%s", pin, filename);
   if (size >= 4096) {
    fprintf(stderr, "Path of GPIO pin is too long!");
     return;
   }
 if (chown(path, uid, gid) < 0) {
     fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", path, uid, gid, (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
 }
}

variable_types: pin int

variable_types:
filename
char *

variable_types: uid int

variable_types: gid int

variable_types:
path
char [4096]

variable_types: size int


export

decompiled_code:
int __fastcall export(unsigned int a1)
{
return writePinToFile(a1, "/sys/class/gpio/export");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
return func9(a1, "/sys/class/gpio/export");
}

original_code:
void export(int pin) {
 writePinToFile(pin, "/sys/class/gpio/export");
}


unexport

decompiled_code:
int __fastcall unexport(unsigned int a1)
{
return writePinToFile(a1, "/sys/class/gpio/unexport");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1)
{
return func9(a1, "/sys/class/gpio/unexport");
}

original_code:
void unexport(int pin) {
 writePinToFile(pin, "/sys/class/gpio/unexport");
}