alocarBloque

decompiled_code:
__int64 __fastcall alocarBloque(int a1, _DWORD *a2)
{
unsigned int v2; // ebp
unsigned int v3; // er14
int v4; // er15
void *v5; // r13
int v6; // er12
unsigned __int8 *v7; // rax
int i; // ebp
unsigned int v9; // ebx
unsigned __int8 v11; // dl
int v12; // ecx

v2 = a2[2];
v3 = a2[4];
printf("primer blq = %d\n", v3);
v4 = a2[3];
v5 = calloc(v2, 1uLL);
if ( v3 >= v3 + v4 )
return 0LL;
v6 = v3;
while ( 2 )
{
leer_bloque(a1, v6, v5);
v7 = (unsigned __int8 *)v5;
for ( i = 0; i != 4096; ++i )
{
v11 = *v7;
if ( *v7 )
{
v12 = v11;
if ( (v11 & 1) != 0 )
{
v9 = 0;
}
else
{
v9 = 1;
while ( !_bittest(&v12, v9) )
{
if ( ++v9 == 7 )
goto LABEL_6;
}
}
*v7 = __ROL4__(-2, v9) & v11;
printf("bit #%d\n", v9);
escribir_bloque(a1, v6, v5);
return (v4 + 8) * (v6 - v3) + v9 + 8 * i;
}
LABEL_6:
++v7;
}
if ( ++v6 < v3 + v4 )
continue;
return 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, _DWORD *a2)
{
unsigned int v2; // ebp
unsigned int v3; // er14
int v4; // er15
void *v5; // r13
int v6; // er12
unsigned __int8 *v7; // rax
int i; // ebp
unsigned int v9; // ebx
unsigned __int8 v11; // dl
int v12; // ecx

v2 = a2[2];
v3 = a2[4];
printf("primer blq = %d\n", v3);
v4 = a2[3];
v5 = calloc(v2, 1uLL);
if ( v3 >= v3 + v4 )
return 0LL;
v6 = v3;
while ( 2 )
{
func8(a1, v6, v5);
v7 = (unsigned __int8 *)v5;
for ( i = 0; i != 4096; ++i )
{
v11 = *v7;
if ( *v7 )
{
v12 = v11;
if ( (v11 & 1) != 0 )
{
v9 = 0;
}
else
{
v9 = 1;
while ( !_bittest(&v12, v9) )
{
if ( ++v9 == 7 )
goto LABEL_6;
}
}
*v7 = __ROL4__(-2, v9) & v11;
printf("bit #%d\n", v9);
func7(a1, v6, v5);
return (v4 + 8) * (v6 - v3) + v9 + 8 * i;
}
LABEL_6:
++v7;
}
if ( ++v6 < v3 + v4 )
continue;
return 0LL;
}
}

original_code:
unsigned int alocarBloque(int fd, struct Super_Block *superBlock)
 {
     unsigned int size_bloques = superBlock->size_bloques;
     unsigned int inicio_bitmap = superBlock->primerbloque_mapabits;
     printf("primer blq = %d\n", inicio_bitmap);
     unsigned int size_bitmap = superBlock->sizebloques_mapabits;
     unsigned int i;
     unsigned char *buffer = (unsigned char*)calloc(size_bloques, 1);
     for(i = inicio_bitmap; i < (inicio_bitmap + size_bitmap); i++){
         leer_bloque(fd, i, buffer);
         unsigned int j;
         for(j = 0; j < 4096; j++){
             if (buffer[j] != 0){
                 int x;
                 for(x = 0; x < 7; x++){
                     if (buffer[j] & (1 << x)){
                         buffer[j] &= ~(1 << x);
                         printf("bit #%d\n", x);
                         escribir_bloque(fd, i, buffer);
                         return (i-inicio_bitmap) * (8 + size_bitmap) + (j * 8) + x;
                     }
                 }
             }
         }
     }
     return 0;
 }

variable_types: struct Super_Block { int magic_number; int total_bloques; int size_bloques; int sizebloques_mapabits; int primerbloque_mapabits; int bloques_libres; int bloque_root; int padding[-1]; } *

variable_types:
i
unsigned int

variable_types:
buffer
unsigned char *

variable_types:
j
unsigned int

variable_types: x int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r12
int v4; // eax
const char *v5; // rbp
_DWORD *v6; // rbx
__off_t v7; // r13
int v8; // ebp
int v9; // er12
int v10; // er14
int v11; // er8
struct stat64 *v12; // rax
int v13; // esi
int v14; // er9
int v15; // er14
__uid_t v16; // er12
__gid_t v17; // er13
struct passwd *v18; // rax
const char *v19; // r15
size_t v20; // rax
char *v21; // rax
int v22; // eax
_WORD *v23; // rax
unsigned int v25; // ecx
int v26; // edx
char *v27; // rax
const char **v28; // [rsp+8h] [rbp-10E0h]
time_t timer; // [rsp+18h] [rbp-10D0h] BYREF
char v30[4096]; // [rsp+20h] [rbp-10C8h] BYREF
struct stat64 stat_buf; // [rsp+1020h] [rbp-C8h] BYREF

v3 = 0LL;
while ( 1 )
{
v4 = getopt_long_only(argc, (char *const *)argv, "", &opciones_0, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 99 )
v3 = getSize((char *)optarg);
else
printf("Opcion erronea!!");
}
printf("Size del disco es de: %lu\n", v3);
if ( v3 == -1LL )
{
perror("Tamano invalido para formatear, numero debe ser multiplo de 128\n");
exit(1);
}
if ( _bss_start >= argc )
mensaje();
v5 = argv[_bss_start];
v6 = calloc(0x1000uLL, 1uLL);
if ( v3 )
{
LODWORD(v7) = v3 >> 12;
v8 = open64(v5, 577);
if ( v8 < 0 )
{
perror("Error al crear el archivo");
exit(1);
}
v15 = 0;
if ( (int)(v3 >> 12) > 0 )
{
do
{
if ( write(v8, v6, 0x1000uLL) < 0 )
{
perror("Error al escribir al archivo!!\n");
exit(1);
}
++v15;
}
while ( (_DWORD)v7 != v15 );
}
lseek64(v8, 0LL, 0);
}
else
{
if ( open64(v5, 1, 511LL) < 0 || (int)fstat64(0, &stat_buf) < 0 )
{
perror("Error al abrir el archivo!!\n");
exit(1);
}
v7 = stat_buf.st_size / 4096;
v8 = 0;
}
*v6 = 257;
v6[2] = 4096;
v6[1] = v7;
v6[4] = 1;
v9 = cantidad_bloques_bits(v3, descripcion);
v6[3] = v9;
v10 = v9 + 1;
v6[6] = v9 + 1;
v6[5] = v7 - v9 - 2;
escribir_bloque(v8, 0, v6);
v11 = v9 + 2;
v12 = (struct stat64 *)v30;
do
{
LOBYTE(v12->st_dev) = -1;
v12 = (struct stat64 *)((char *)v12 + 1);
}
while ( v12 != &stat_buf );
v13 = 0;
v14 = 1;
if ( v9 > 0 )
{
LABEL_43:
v27 = v30;
while ( 1 )
{
if ( *v27 )
{
if ( v11 <= v13 )
{
LABEL_26:
escribir_bloque(v8, v14, v30);
break;
}
v25 = 0;
while ( 1 )
{
v26 = (unsigned __int8)*v27;
if ( _bittest(&v26, v25) )
{
*v27 &= ~(1 << v25);
++v13;
}
if ( ++v25 == 7 )
break;
if ( v13 >= v11 )
goto LABEL_26;
}
}
if ( ++v27 == (char *)&stat_buf )
{
++v14;
goto LABEL_43;
}
}
}
v16 = getuid();
if ( v16 == -1 )
perror("getuid() error.");
v17 = getgid();
if ( v17 == -1 )
perror("getgid() error.");
timer = time(0LL);
v18 = getpwuid(v16);
*(_WORD *)v6 = 2;
v28 = (const char **)&v18->pw_name;
v19 = v18->pw_name;
v20 = strlen(v18->pw_name);
memcpy(v6 + 6, v19, v20 + 1);
printf("creador = %s\n", *v28);
*((_WORD *)v6 + 1) = v16;
printf("uid = %d\n", v16);
*((_WORD *)v6 + 2) = v17;
printf("gid = %d\n", v17);
*((_WORD *)v6 + 3) = 16895;
printf("Permisos para / = %d\n", 16895LL);
v6[3] = timer;
v21 = ctime(&timer);
printf("fcreacion = %s\n", v21);
v22 = timer;
v6[4] = timer;
v6[2] = v22;
v6[5] = 0;
v23 = (_WORD *)v6 + 61;
do
{
*v23 = 0;
v23 += 32;
}
while ( (_WORD *)((char *)v6 + 4154) != v23 );
escribir_bloque(v8, v10, v6);
close(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r12
int v4; // eax
const char *v5; // rbp
_DWORD *v6; // rbx
__off_t v7; // r13
int v8; // ebp
int v9; // er12
int v10; // er14
int v11; // er8
struct stat64 *v12; // rax
int v13; // esi
int v14; // er9
int v15; // er14
__uid_t v16; // er12
__gid_t v17; // er13
struct passwd *v18; // rax
const char *v19; // r15
size_t v20; // rax
char *v21; // rax
int v22; // eax
_WORD *v23; // rax
unsigned int v25; // ecx
int v26; // edx
char *v27; // rax
const char **v28; // [rsp+8h] [rbp-10E0h]
time_t timer; // [rsp+18h] [rbp-10D0h] BYREF
char v30[4096]; // [rsp+20h] [rbp-10C8h] BYREF
struct stat64 stat_buf; // [rsp+1020h] [rbp-C8h] BYREF

v3 = 0LL;
while ( 1 )
{
v4 = getopt_long_only(argc, (char *const *)argv, "", &opciones_0, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 99 )
v3 = func9((char *)optarg);
else
printf("Opcion erronea!!");
}
printf("Size del disco es de: %lu\n", v3);
if ( v3 == -1LL )
{
perror("Tamano invalido para formatear, numero debe ser multiplo de 128\n");
exit(1);
}
if ( _bss_start >= argc )
func10();
v5 = argv[_bss_start];
v6 = calloc(0x1000uLL, 1uLL);
if ( v3 )
{
LODWORD(v7) = v3 >> 12;
v8 = open64(v5, 577);
if ( v8 < 0 )
{
perror("Error al crear el archivo");
exit(1);
}
v15 = 0;
if ( (int)(v3 >> 12) > 0 )
{
do
{
if ( write(v8, v6, 0x1000uLL) < 0 )
{
perror("Error al escribir al archivo!!\n");
exit(1);
}
++v15;
}
while ( (_DWORD)v7 != v15 );
}
lseek64(v8, 0LL, 0);
}
else
{
if ( open64(v5, 1, 511LL) < 0 || (int)func15(0, &stat_buf) < 0 )
{
perror("Error al abrir el archivo!!\n");
exit(1);
}
v7 = stat_buf.st_size / 4096;
v8 = 0;
}
*v6 = 257;
v6[2] = 4096;
v6[1] = v7;
v6[4] = 1;
v9 = func11(v3, descripcion);
v6[3] = v9;
v10 = v9 + 1;
v6[6] = v9 + 1;
v6[5] = v7 - v9 - 2;
func7(v8, 0, v6);
v11 = v9 + 2;
v12 = (struct stat64 *)v30;
do
{
LOBYTE(v12->st_dev) = -1;
v12 = (struct stat64 *)((char *)v12 + 1);
}
while ( v12 != &stat_buf );
v13 = 0;
v14 = 1;
if ( v9 > 0 )
{
LABEL_43:
v27 = v30;
while ( 1 )
{
if ( *v27 )
{
if ( v11 <= v13 )
{
LABEL_26:
func7(v8, v14, v30);
break;
}
v25 = 0;
while ( 1 )
{
v26 = (unsigned __int8)*v27;
if ( _bittest(&v26, v25) )
{
*v27 &= ~(1 << v25);
++v13;
}
if ( ++v25 == 7 )
break;
if ( v13 >= v11 )
goto LABEL_26;
}
}
if ( ++v27 == (char *)&stat_buf )
{
++v14;
goto LABEL_43;
}
}
}
v16 = getuid();
if ( v16 == -1 )
perror("getuid() error.");
v17 = getgid();
if ( v17 == -1 )
perror("getgid() error.");
timer = time(0LL);
v18 = getpwuid(v16);
*(_WORD *)v6 = 2;
v28 = (const char **)&v18->pw_name;
v19 = v18->pw_name;
v20 = strlen(v18->pw_name);
memcpy(v6 + 6, v19, v20 + 1);
printf("creador = %s\n", *v28);
*((_WORD *)v6 + 1) = v16;
printf("uid = %d\n", v16);
*((_WORD *)v6 + 2) = v17;
printf("gid = %d\n", v17);
*((_WORD *)v6 + 3) = 16895;
printf("Permisos para / = %d\n", 16895LL);
v6[3] = timer;
v21 = ctime(&timer);
printf("fcreacion = %s\n", v21);
v22 = timer;
v6[4] = timer;
v6[2] = v22;
v6[5] = 0;
v23 = (_WORD *)v6 + 61;
do
{
*v23 = 0;
v23 += 32;
}
while ( (_WORD *)((char *)v6 + 4154) != v23 );
func7(v8, v10, v6);
close(v8);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    static struct option opciones[] =
    {
        {"crear", 1, ((void *)0), 'c'},
        {0, 0, 0, 0}
    };
    int c;
    unsigned long size_disco = 0;
    while ((c = getopt_long_only(argc, argv, "", opciones, ((void *)0))) != -1) {
        switch(c) {
            case 'c': size_disco = getSize(optarg);
                        break;
            default: printf("Opcion erronea!!");
        }
    }
    printf("Size del disco es de: %lu\n", size_disco);
    if (size_disco == -1) {
        perror("Tamano invalido para formatear, numero debe ser multiplo de 128\n");
        exit(1);
    }
    if (optind >= argc) {
        mensaje();
    }
    char *path = argv[optind];
    int i, fd, numero_bloques;
    struct stat sb;
    void *buffer = calloc(4096, 1);
    if (size_disco == 0) {
        if ((fd = open(path, 01, 0777) < 0) || (fstat(fd, &sb) < 0)) {
            perror("Error al abrir el archivo!!\n"),
            exit(1);
        }
        numero_bloques = sb.st_size / 4096;
    } else {
        numero_bloques = size_disco / 4096;
        if ((fd = open(path, 01 | 0100 | 01000)) < 0) {
              perror("Error al crear el archivo");
              exit(1);
        }
        for (i = 0; i < numero_bloques; i++) {
            if (write(fd, buffer, 4096) < 0) {
                perror("Error al escribir al archivo!!\n");
                exit(1);
            }
        }
        lseek(fd, 0, 0);
     }
    struct Super_Block *sp = buffer;
    sp->magic_number = 0x101;
    sp->size_bloques = 4096;
    sp->total_bloques = numero_bloques;
    sp->primerbloque_mapabits = 1;
    int size_bloquesmapa = cantidad_bloques_bits(size_disco, descripcion);
    sp->sizebloques_mapabits = size_bloquesmapa;
    sp->bloque_root = size_bloquesmapa + 1;
    sp->bloques_libres = numero_bloques - size_bloquesmapa - 2;
    escribir_bloque(fd, 0, buffer);
    unsigned char arr[4096];
    void *bitsmapa = malloc(4096);
    int j, k, cont = 0;
    int escribirmapabits = 1 + 1 + size_bloquesmapa;
    for (j = 0; j < 4096; j++)
        arr[j] = 255;
    for (i = 1; i < i + size_bloquesmapa; i++) {
        _Bool flag = 0;
        for (j = 0;j < 4096; j++) {
            if (arr[j] != 0) {
                for (k = 0;k < 7; k++) {
                    if (cont < escribirmapabits) {
                        if(arr[j] & (1 << k)) {
                            arr[j]=arr[j]&~(1<<k);
                            cont++;
                        }
                    } else {
                        bitsmapa = &arr;
                        escribir_bloque(fd,i,bitsmapa);
                        flag = 1;
                    }
                    if (flag)
                        break;
                }
            }
            if (flag)
                break;
        }
        if (flag)
            break;
    }
    struct Directory *rootDir = buffer;
    uid_t uid;
    if ((uid = getuid()) == -1) perror("getuid() error.");
    gid_t gid;
    if ((gid = getgid()) == -1) perror("getgid() error.");
    time_t tiempo = time(((void *)0));
    struct passwd *pws = getpwuid(uid);
    rootDir->info.tipo_bloque = 2;
    memcpy(rootDir->creador, pws->pw_name, strlen(pws->pw_name) + 1); printf("creador = %s\n", pws->pw_name);
    rootDir->info.uid = uid; printf("uid = %d\n", uid);
    rootDir->info.gid = gid; printf("gid = %d\n", gid);
    rootDir->info.mode = 0040000 | (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3); printf("Permisos para / = %d\n", 0040000 | (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
    rootDir->info.fcreacion = tiempo; printf("fcreacion = %s\n", ctime(&tiempo));
    rootDir->info.fmodificacion = tiempo;
    rootDir->info.facceso = tiempo;
    rootDir->cantidad_elementos = 0;
    for (k = 0; k < ((4096 - 64) / 64); k++)
        rootDir->directory_Entries[k].tipo_bloque = 0;
    escribir_bloque(fd, 1 + size_bloquesmapa, rootDir);
    close(fd);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    static struct option opciones[] = {
        {"crear", 1, ((void *)0), 'c'},
        {0, 0, 0, 0}
    };
    int c;
    unsigned long size_disco = 0;
    while ((c = getopt_long_only(argc, argv, "", opciones, ((void *)0))) != -1) {
        switch(c) {
            case 'c': size_disco = getSize(optarg);
                        break;
            default: printf("Opcion erronea!!");
        }
    }
    printf("Size del disco es de: %lu\n", size_disco);
    if (size_disco == -1) {
        perror("Tamano invalido para formatear, numero debe ser multiplo de 128\n");
        exit(1);
    }
    if (optind >= argc) {
        mensaje();
    }
    char *path = argv[optind];
    int i; int fd; int numero_bloques;
    struct stat sb;
    void *buffer = calloc(4096, 1);
    if (size_disco == 0) {
        if ((fd = open(path, 01, 0777) < 0) || (fstat(fd, &sb) < 0)) {
            perror("Error al abrir el archivo!!\n"),
            exit(1);
        }
        numero_bloques = sb.st_size / 4096;
    } else {
        numero_bloques = size_disco / 4096;
        if ((fd = open(path, 01 | 0100 | 01000)) < 0) {
              perror("Error al crear el archivo");
              exit(1);
        }
        for (i = 0; i < numero_bloques; i++) {
            if (write(fd, buffer, 4096) < 0) {
                perror("Error al escribir al archivo!!\n");
                exit(1);
            }
        }
        lseek(fd, 0, 0);
     }
    struct Super_Block *sp = buffer;
    sp->magic_number = 0x101;
    sp->size_bloques = 4096;
    sp->total_bloques = numero_bloques;
    sp->primerbloque_mapabits = 1;
    int size_bloquesmapa = cantidad_bloques_bits(size_disco, descripcion);
    sp->sizebloques_mapabits = size_bloquesmapa;
    sp->bloque_root = size_bloquesmapa + 1;
    sp->bloques_libres = numero_bloques - size_bloquesmapa - 2;
    escribir_bloque(fd, 0, buffer);
    unsigned char arr[4096];
    void *bitsmapa = malloc(4096);
    int j; int k; int cont = 0;
    int escribirmapabits = 1 + 1 + size_bloquesmapa;
    for (j = 0; j < 4096; j++)
        arr[j] = 255;
    for (i = 1; i < i + size_bloquesmapa; i++) {
        _Bool flag = 0;
        for (j = 0;j < 4096; j++) {
            if (arr[j] != 0) {
                for (k = 0;k < 7; k++) {
                    if (cont < escribirmapabits) {
                        if(arr[j] & (1 << k)) {
                            arr[j]=arr[j]&~(1<<k);
                            cont++;
                        }
                    } else {
                        bitsmapa = &arr;
                        escribir_bloque(fd,i,bitsmapa);
                        flag = 1;
                    }
                    if (flag)
                        break;
                }
            }
            if (flag)
                break;
        }
        if (flag)
            break;
    }
    struct Directory *rootDir = buffer;
    unsigned int uid;
    if ((uid = getuid()) == -1) perror("getuid() error.");
    unsigned int gid;
    if ((gid = getgid()) == -1) perror("getgid() error.");
    long tiempo = time(((void *)0));
    struct passwd *pws = getpwuid(uid);
    rootDir->info.tipo_bloque = 2;
    memcpy(rootDir->creador, pws->pw_name, strlen(pws->pw_name) + 1); printf("creador = %s\n", pws->pw_name);
    rootDir->info.uid = uid; printf("uid = %d\n", uid);
    rootDir->info.gid = gid; printf("gid = %d\n", gid);
    rootDir->info.mode = 0040000 | (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3); printf("Permisos para / = %d\n", 0040000 | (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
    rootDir->info.fcreacion = tiempo; printf("fcreacion = %s\n", ctime(&tiempo));
    rootDir->info.fmodificacion = tiempo;
    rootDir->info.facceso = tiempo;
    rootDir->cantidad_elementos = 0;
    for (k = 0; k < ((4096 - 64) / 64); k++)
        rootDir->directory_Entries[k].tipo_bloque = 0;
    escribir_bloque(fd, 1 + size_bloquesmapa, rootDir);
    close(fd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int

variable_types:
path
char *

variable_types: i int

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types:
buffer
void *

variable_types:
arr
unsigned char [4096]

variable_types:
bitsmapa
void *

variable_types: j int

variable_types: k int

variable_types: cont int

variable_types: escribirmapabits int

variable_types: struct Directory { struct inodo { unsigned short tipo_bloque; unsigned short uid; unsigned short gid; unsigned short mode; unsigned int facceso; unsigned int fcreacion; unsigned int fmodificacion; } info; unsigned int cantidad_elementos; char creador[40]; struct Directory_Entry { char nombre[58]; unsigned short tipo_bloque; unsigned int apuntador; } directory_Entries[-1]; } *

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types: tiempo long

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

return_type: int

user_defined_types: struct Super_Block { int magic_number; int total_bloques; int size_bloques; int sizebloques_mapabits; int primerbloque_mapabits; int bloques_libres; int bloque_root; int padding[-1]; }

user_defined_types: struct Directory { struct inodo info; unsigned int cantidad_elementos; char creador[40]; struct Directory_Entry directory_Entries[-1]; }


repo: dannoy/tools

decompiled_code:
__int64 next_element()
{
return __isoc99_scanf();
}

canonical_decompiled_code:
__int64 func7()
{
return __isoc99_scanf();
}

original_code:
int next_element(int *value)
{
    return scanf("%d", value);
}

variable_types:
value
int *


decompiled_code:
__int64 __fastcall print_value(unsigned int a1)
{
fprintf(_bss_start, "%d\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
fprintf(_bss_start, "%d\n", a1);
return 0LL;
}

original_code:
int print_value(int value)
{
    fprintf(stdout, "%d\n", value);
    return 0;
}

variable_types: value int


decompiled_code:
_BOOL8 __fastcall int_smaller(int a1, int a2)
{
return a1 < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1, int a2)
{
return a1 < a2;
}

original_code:
static int int_smaller(int a, int b)
{
    return a < b ? 1 : 0;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall heap_init(__int64 a1, int a2)
{
if ( !a1 )
__assert_fail("h != (void *)0", "heap.c", 0x20u, "heap_init");
*(_QWORD *)a1 = malloc(4LL * (a2 + 1));
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = a2;
return 0LL;
}

original_code:
static int heap_init(struct heap *h, int cap)
{
    ((void) sizeof ((h != (void *)0) ? 1 : 0), __extension__ ({ if (h != (void *)0) ; else __assert_fail ("h != (void *)0", "heap.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    h->data = malloc((cap + 1) * sizeof(int));
    h->size = 0;
    h->cap = cap;
    return 0;
}

variable_types: struct heap { int *data; int size; int cap; } *

variable_types: cap int


decompiled_code:
__int64 __fastcall heap_fini(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !v1 )
return 0LL;
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !v1 )
return 0LL;
free(v1);
return 0LL;
}

original_code:
static int heap_fini(struct heap *h)
{
    if(h && h->data) free(h->data);
    return 0;
}

user_defined_types: struct heap { int *data; int size; int cap; }


decompiled_code:
__int64 __fastcall min_heap_init(__int64 a1, int a2)
{
return heap_init(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
return func11(a1, a2);
}

original_code:
int min_heap_init(struct heap *h, int cap)
{
    return heap_init(h, cap);
}


decompiled_code:
__int64 __fastcall min_heap_fini(void **a1)
{
return heap_fini(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(void **a1)
{
return func12(a1);
}

original_code:
int min_heap_fini(struct heap *h)
{
    return heap_fini(h);
}


decompiled_code:
__int64 __fastcall min_heap_replace_root(__int64 a1, int a2)
{
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = a2;
return heapify(a1, 1, (unsigned int (__fastcall *)(_QWORD, _QWORD))int_smaller);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = a2;
return func10(a1, 1, (unsigned int (__fastcall *)(_QWORD, _QWORD))int_smaller);
}

original_code:
int min_heap_replace_root(struct heap *h, int value)
{
    h->data[1] = value;
    return heapify(h, 1, int_smaller);
}


decompiled_code:
__int64 __fastcall min_heap_root(int *a1, _DWORD *a2)
{
if ( a1[2] <= 0 )
return 0xFFFFFFFFLL;
*a2 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(int *a1, _DWORD *a2)
{
if ( a1[2] <= 0 )
return 0xFFFFFFFFLL;
*a2 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
return 0LL;
}

original_code:
int min_heap_root(struct heap *h, int *value)
{
    if(h->size > 0) {
        *value = h->data[1];
        return 0;
    }
    return -1;
}


decompiled_code:
__int64 __fastcall min_heap_iterate(__int64 a1, int (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
int v3; // ebp

if ( *(int *)(a1 + 8) <= 0 )
return 0LL;
v2 = 4LL;
v3 = 1;
while ( a2(*(unsigned int *)(*(_QWORD *)a1 + v2)) >= 0 )
{
++v3;
v2 += 4LL;
if ( *(_DWORD *)(a1 + 8) < v3 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
int v3; // ebp

if ( *(int *)(a1 + 8) <= 0 )
return 0LL;
v2 = 4LL;
v3 = 1;
while ( a2(*(unsigned int *)(*(_QWORD *)a1 + v2)) >= 0 )
{
++v3;
v2 += 4LL;
if ( *(_DWORD *)(a1 + 8) < v3 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int min_heap_iterate(struct heap *h, int (*iter)(int value))
{
    int i = 1;
    for(i = 1; i <= h->size; ++i) {
        if(iter(h->data[i]) < 0) return -1;
    }
    return 0;
}

variable_types:
iter
int (*)(int value)

variable_types: i int


decompiled_code:
__int64 __fastcall max_heap_init(__int64 a1, int a2)
{
return heap_init(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2)
{
return func11(a1, a2);
}

original_code:
int max_heap_init(struct heap *h, int cap)
{
    return heap_init(h, cap);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int result; // eax
_BYTE v5[24]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

min_heap_init(v5, 1000LL, envp);
v3 = 1000;
while ( 1 )
{
result = next_element(v7);
if ( result == -1 )
break;
min_heap_insert(v5, (unsigned int)v7[0]);
if ( !--v3 )
{
while ( 1 )
{
if ( (unsigned int)next_element(v7) == -1 )
{
min_heap_fini(v5);
return 0;
}
if ( (int)min_heap_root(v5, &v6) < 0 )
break;
if ( v7[0] > v6 )
min_heap_replace_root(v5);
}
return -1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int result; // eax
_BYTE v5[24]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

func13(v5, 1000LL, envp);
v3 = 1000;
while ( 1 )
{
result = func7(v7);
if ( result == -1 )
break;
func15(v5, (unsigned int)v7[0]);
if ( !--v3 )
{
while ( 1 )
{
if ( (unsigned int)func7(v7) == -1 )
{
func14(v5);
return 0;
}
if ( (int)func17(v5, &v6) < 0 )
break;
if ( v7[0] > v6 )
func16(v5);
}
return -1;
}
}
return result;
}

original_code:
int main()
{
    int i = 0, value, root;
    struct heap h;
    min_heap_init(&h, 1000);
    for(i = 0; i < 1000; ++i) {
        if((-1) == next_element(&value)) {
            return -1;
        }
        min_heap_insert(&h, value);
    }
    while((-1) != next_element(&value)) {
        if(min_heap_root(&h, &root) < 0) {
            return -1;
        }
        else if(value > root) {
            min_heap_replace_root(&h, value);
        }
    }
    min_heap_fini(&h);
    return 0;
}

canonical_original_code:
int main()
{
    int i = 0; int value; int root;
    struct heap h;
    min_heap_init(&h, 1000);
    for(i = 0; i < 1000; ++i) {
        if((-1) == next_element(&value)) {
            return -1;
        }
        min_heap_insert(&h, value);
    }
    while((-1) != next_element(&value)) {
        if(min_heap_root(&h, &root) < 0) {
            return -1;
        }
        else if(value > root) {
            min_heap_replace_root(&h, value);
        }
    }
    min_heap_fini(&h);
    return 0;
}

variable_types: root int

variable_types: struct heap { int *data; int size; int cap; }


fatal

decompiled_code:
void __noreturn fatal(__int64 a1, int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fwrite("[FWU] ", 1uLL, 6uLL, stderr);
vfprintf(stderr, a3, arg);
exit(a2);
}

canonical_decompiled_code:
void __noreturn func7(__int64 a1, int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fwrite("[FWU] ", 1uLL, 6uLL, stderr);
vfprintf(stderr, a3, arg);
exit(a2);
}

original_code:
void fatal(struct ctx *u, int errnum, char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "[FWU] ");
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    exit(errnum);
}

canonical_original_code:
void fatal(struct ctx *u, int errnum, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "[FWU] ");
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    exit(errnum);
}

variable_types:
u
struct ctx {  } *

variable_types: errnum int

variable_types:
fmt
char *

return_type: void


decompiled_code:
__int64 __fastcall elf_get_file_size(__int64 a1, unsigned __int64 a2)
{
unsigned int v3; // ebp
unsigned int *v4; // rax
unsigned __int16 v5; // bx
unsigned int *v6; // r9
__int64 v7; // r10
int v8; // edx
__int64 result; // rax
int v10; // ebp

if ( a2 <= 0x34 )
__assert_fail("size > sizeof(Elf32_Ehdr)", "elf_size.c", 0x38u, "elf_get_file_size");
v3 = *(_DWORD *)(a1 + 32);
v4 = (unsigned int *)(a1 + v3);
v5 = *(_WORD *)(a1 + 48);
v6 = &v4[10 * v5];
v7 = v4[10 * *(unsigned __int16 *)(a1 + 50) + 4];
if ( v4 >= v6 )
{
result = *(v6 - 6) + *(v6 - 5);
LABEL_8:
v10 = *(unsigned __int16 *)(a1 + 46) * v5 + v3;
if ( (int)result < v10 )
result = (unsigned int)v10;
return result;
}
v8 = 0;
do
{
if ( !memcmp((const void *)(a1 + v7 + *v4), ".debug", 6uLL) )
v8 = 1;
v4 += 10;
}
while ( v6 > v4 );
result = *(v6 - 6) + *(v6 - 5);
if ( !v8 )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
unsigned int v3; // ebp
unsigned int *v4; // rax
unsigned __int16 v5; // bx
unsigned int *v6; // r9
__int64 v7; // r10
int v8; // edx
__int64 result; // rax
int v10; // ebp

if ( a2 <= 0x34 )
__assert_fail("size > sizeof(Elf32_Ehdr)", "elf_size.c", 0x38u, "elf_get_file_size");
v3 = *(_DWORD *)(a1 + 32);
v4 = (unsigned int *)(a1 + v3);
v5 = *(_WORD *)(a1 + 48);
v6 = &v4[10 * v5];
v7 = v4[10 * *(unsigned __int16 *)(a1 + 50) + 4];
if ( v4 >= v6 )
{
result = *(v6 - 6) + *(v6 - 5);
LABEL_8:
v10 = *(unsigned __int16 *)(a1 + 46) * v5 + v3;
if ( (int)result < v10 )
result = (unsigned int)v10;
return result;
}
v8 = 0;
do
{
if ( !memcmp((const void *)(a1 + v7 + *v4), ".debug", 6uLL) )
v8 = 1;
v4 += 10;
}
while ( v6 > v4 );
result = *(v6 - 6) + *(v6 - 5);
if ( !v8 )
goto LABEL_8;
return result;
}

original_code:
int elf_get_file_size(char *start_addr, size_t size)
{
    int fsize = 0, fsize2 = 0;
    Elf32_Ehdr *eh = (Elf32_Ehdr *)start_addr;
    Elf32_Shdr *sh= ((void *)0);
    Elf32_Shdr *sh_start = ((void *)0) ,*sh_end = ((void *)0);
    Elf32_Shdr *sh_shstrtab = ((void *)0);
    char *shstrtab = ((void *)0);
    int is_debug_elf = 0;
    ((void) sizeof ((size > sizeof(Elf32_Ehdr)) ? 1 : 0), __extension__ ({ if (size > sizeof(Elf32_Ehdr)) ; else __assert_fail ("size > sizeof(Elf32_Ehdr)", "elf_size.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    sh_start = (Elf32_Shdr *)(start_addr + eh->e_shoff);
    sh_end = sh_start + eh->e_shnum;
    sh_shstrtab = sh_start + eh->e_shstrndx;
    shstrtab = start_addr + sh_shstrtab->sh_offset;
    for(sh = sh_start; sh < sh_end; ++sh) {
        if(0 == strncmp(&shstrtab[sh->sh_name], ".debug", strlen(".debug"))) {
            is_debug_elf = 1;
        }
    }
 sh = sh_end - 1;
 fsize = sh->sh_offset + sh->sh_size;
    if(is_debug_elf) {
  return fsize;
    }
    else {
        fsize2 = eh->e_shoff + eh->e_shnum * eh->e_shentsize;
  fsize = fsize > fsize2 ? fsize : fsize2;
    }
    return fsize;
}

canonical_original_code:
int elf_get_file_size(char *start_addr, unsigned long size)
{
    int fsize = 0; int fsize2 = 0;
    struct Elf32_Ehdr *eh = (Elf32_Ehdr *)start_addr;
    struct Elf32_Shdr *sh = ((void *)0);
    struct Elf32_Shdr *sh_start = ((void *)0); struct Elf32_Shdr *sh_end = ((void *)0);
    struct Elf32_Shdr *sh_shstrtab = ((void *)0);
    char *shstrtab = ((void *)0);
    int is_debug_elf = 0;
    ((void) sizeof ((size > sizeof(Elf32_Ehdr)) ? 1 : 0), __extension__ ({ if (size > sizeof(Elf32_Ehdr)) ; else __assert_fail ("size > sizeof(Elf32_Ehdr)", "elf_size.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    sh_start = (struct Elf32_Shdr *)(start_addr + eh->e_shoff);
    sh_end = sh_start + eh->e_shnum;
    sh_shstrtab = sh_start + eh->e_shstrndx;
    shstrtab = start_addr + sh_shstrtab->sh_offset;
    for(sh = sh_start; sh < sh_end; ++sh) {
        if(0 == strncmp(&shstrtab[sh->sh_name], ".debug", strlen(".debug"))) {
            is_debug_elf = 1;
        }
    }
 sh = sh_end - 1;
 fsize = sh->sh_offset + sh->sh_size;
    if(is_debug_elf) {
  return fsize;
    }
    else {
        fsize2 = eh->e_shoff + eh->e_shnum * eh->e_shentsize;
  fsize = fsize > fsize2 ? fsize : fsize2;
    }
    return fsize;
}

variable_types:
size
unsigned long

variable_types: fsize int

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

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

variable_types:
shstrtab
char *


decompiled_code:
__int64 __fastcall elf_read_elf_info(const char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
void *v4; // rax
void *v5; // rbx
__off_t v6; // r13
unsigned int v7; // er12
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
fatal(0LL, 1, "Cannot open %s\n", a1);
v2 = v1;
v3 = fstat(v1, &v9);
if ( v3 < 0 )
fatal(0LL, 1, "Cannot stat %s\n", a1);
v4 = mmap(0LL, v9.st_size, 1, 2, v2, 0LL);
v5 = v4;
if ( v4 == (void *)-1LL )
fatal(0LL, 1, "Cannot mmap %s\n", a1);
v6 = v9.st_size;
v7 = elf_get_file_size((__int64)v4, v9.st_size);
munmap(v5, v6);
fprintf(stderr, "[DBG] elf file size %d\n", v7);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
void *v4; // rax
void *v5; // rbx
__off_t v6; // r13
unsigned int v7; // er12
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
func7(0LL, 1, "Cannot open %s\n", a1);
v2 = v1;
v3 = func12(v1, &v9);
if ( v3 < 0 )
func7(0LL, 1, "Cannot stat %s\n", a1);
v4 = mmap(0LL, v9.st_size, 1, 2, v2, 0LL);
v5 = v4;
if ( v4 == (void *)-1LL )
func7(0LL, 1, "Cannot mmap %s\n", a1);
v6 = v9.st_size;
v7 = func8((__int64)v4, v9.st_size);
munmap(v5, v6);
fprintf(stderr, "[DBG] elf file size %d\n", v7);
return (unsigned int)v3;
}

original_code:
int elf_read_elf_info(char *file)
{
    int ret = 0;
    int fsize = 0;
    int fd = -1;
    void *faddr = ((void *)0);
    struct stat st;
    char *elf_info = ((void *)0);
    if((fd = open(file, 00)) < 0) {
        fatal(((void *)0), ELF_ERR, "Cannot open %s\n", file);
    }
    else if((ret = fstat(fd, &st)) < 0) {
        fatal(((void *)0), ELF_ERR, "Cannot stat %s\n", file);
    }
    else if((faddr = mmap(((void *)0), st.st_size,
                0x1, 0x02,
                fd, 0)) == ((void *) -1)) {
        fatal(((void *)0), ELF_ERR, "Cannot mmap %s\n", file);
    }
    fsize = elf_get_file_size((char *)faddr, st.st_size);
    munmap(faddr, st.st_size);
 fprintf(stderr, "[DBG] ""elf file size %d\n", fsize);
    return ret;
}

variable_types:
file
char *

variable_types: ret int

variable_types: fd int

variable_types:
faddr
void *

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

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
elf_read_elf_info(*argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(*argv);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int ret = 0;
 elf_read_elf_info(argv[0]);
 return ret;
}

variable_types: argc int

variable_types:
argv
char *[]


original_code:
int kmp_table(char *W, int T[], int SIZE)
{
    int proper_suffix_length = 0;
    int T_idx = 2;
    ((void) sizeof ((SIZE >= 2) ? 1 : 0), __extension__ ({ if (SIZE >= 2) ; else __assert_fail ("SIZE >= 2", "kmp.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    T[0] = -1;
    T[1] = 0;
    while(T_idx < SIZE) {
        if(W[T_idx - 1] == W[proper_suffix_length]) {
            ++proper_suffix_length;
            T[T_idx] = proper_suffix_length;
            ++T_idx;
        }
        else if(proper_suffix_length > 0) {
            proper_suffix_length = T[proper_suffix_length];
        }
        else{
            T[T_idx] = 0;
            ++T_idx;
        }
    }
    void dump(){
        int i = 0;
        printf("T:\n");
        for(i = 0; i < SIZE; ++i) {
            printf("%d ", T[i]);
        }
        printf("\n");
    }
    return 0;
}

variable_types:
W
char *

variable_types:
T
int []

variable_types: SIZE int

variable_types: i int


decompiled_code:
__int64 __fastcall kmp_search(const char *a1, const char *a2)
{
int v3; // er13
void *v4; // rsp
unsigned int v5; // ecx
unsigned int v6; // edi
int v7; // eax
_DWORD v9[3]; // [rsp+0h] [rbp-40h] BYREF
int v10; // [rsp+Ch] [rbp-34h]

v3 = strlen(a1);
v10 = strlen(a2);
v4 = alloca(4LL * v10);
kmp_table((__int64)a2, v9, v10);
if ( v3 > 0 )
{
v5 = 0;
v6 = 0;
v7 = 0;
while ( 1 )
{
if ( a1[v5] == a2[v7] )
{
if ( v10 == ++v7 )
return v6;
}
else
{
v7 = v9[v7];
v6 = v5 - v7;
if ( v7 < 0 )
v7 = 0;
}
v5 = v6 + v7;
if ( (int)(v6 + v7) >= v3 )
return v6;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
int v3; // er13
void *v4; // rsp
unsigned int v5; // ecx
unsigned int v6; // edi
int v7; // eax
_DWORD v9[3]; // [rsp+0h] [rbp-40h] BYREF
int v10; // [rsp+Ch] [rbp-34h]

v3 = strlen(a1);
v10 = strlen(a2);
v4 = alloca(4LL * v10);
func7((__int64)a2, v9, v10);
if ( v3 > 0 )
{
v5 = 0;
v6 = 0;
v7 = 0;
while ( 1 )
{
if ( a1[v5] == a2[v7] )
{
if ( v10 == ++v7 )
return v6;
}
else
{
v7 = v9[v7];
v6 = v5 - v7;
if ( v7 < 0 )
v7 = 0;
}
v5 = v6 + v7;
if ( (int)(v6 + v7) >= v3 )
return v6;
}
}
return 0;
}

original_code:
int kmp_search(char *S, char *W)
{
    int S_length = strlen(S);
    int W_length = strlen(W);
    int T[W_length];
    int m = 0, i = 0;
    kmp_table(W, T, W_length);
    while(m + i < S_length) {
        if(S[m + i] == W[i]) {
            if(++i == W_length) {
                return m;
            }
            continue;
        }
        m = m + i - T[i];
        if(T[i] > -1) {
            i = T[i];
        }
        else {
            i = 0;
        }
    }
    return m;
}

canonical_original_code:
int kmp_search(char *S, char *W)
{
    int S_length = strlen(S);
    int W_length = strlen(W);
    int T[-1];
    int m = 0; int i = 0;
    kmp_table(W, T, W_length);
    while(m + i < S_length) {
        if(S[m + i] == W[i]) {
            if(++i == W_length) {
                return m;
            }
            continue;
        }
        m = m + i - T[i];
        if(T[i] > -1) {
            i = T[i];
        }
        else {
            i = 0;
        }
    }
    return m;
}

variable_types:
S
char *

variable_types:
T
int [-1]

variable_types: m int


original_code:
int kmp_table_myself(char *W, int T[], int SIZE)
{
    int proper_suffix_length = 0;
    int T_idx = 2;
    ((void) sizeof ((SIZE >= 2) ? 1 : 0), __extension__ ({ if (SIZE >= 2) ; else __assert_fail ("SIZE >= 2", "kmp.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    T[0] = -1;
    T[1] = 0;
    while(T_idx < SIZE) {
        if(W[T_idx - 1] == W[proper_suffix_length]) {
            ++proper_suffix_length;
            T[T_idx] = proper_suffix_length;
            ++T_idx;
        }
        else {
            proper_suffix_length = 0;
            T[T_idx] = 0;
            ++T_idx;
        }
    }
    {
        int i = 0;
        for(i = 0; i < SIZE; ++i) {
            printf("%d ", T[i]);
        }
        printf("\n");
    }
    return 0;
}


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

v3 = kmp_search("abc abcdab abcdabcdabde", "abcdabd");
printf("pos %d\n", v3);
return 0;
}

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

v3 = func8("abc abcdab abcdabcdabde", "abcdabd");
printf("pos %d\n", v3);
return 0;
}

original_code:
int main()
{
    int pos = -1;
    pos = kmp_search("abc abcdab abcdabcdabde", "abcdabd");
    printf("pos %d\n",pos);
    return 0;
}

variable_types: pos int


decompiled_code:
__int64 __fastcall gcd1(int a1, signed int a2)
{
int v2; // ecx
unsigned int v3; // edi

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v2 = a2 % v2;
a2 = v3;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, signed int a2)
{
int v2; // ecx
unsigned int v3; // edi

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v2 = a2 % v2;
a2 = v3;
}
while ( v2 );
return v3;
}

original_code:
int gcd1(int m, int n)
{
    int r = 0;
    r = m % n;
    while(r) {
        m = n;
        n = r;
        r = m % n;
    }
    return n;
}

variable_types: n int

variable_types: r int


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

LODWORD(result) = a1;
do
{
v3 = a2;
a2 = (int)result % a2;
result = v3;
}
while ( a2 );
return result;
}

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

LODWORD(result) = a1;
do
{
v3 = a2;
a2 = (int)result % a2;
result = v3;
}
while ( a2 );
return result;
}

original_code:
int gcd2(int m, int n)
{
    int r = 1;
    while(r) {
        r = m % n;
        m = n;
        n = r;
    }
    return m;
}


decompiled_code:
__int64 __fastcall gcd3(signed int a1, signed int a2)
{
while ( 1 )
{
a1 %= a2;
if ( !a1 )
break;
a2 %= a1;
if ( !a2 )
return (unsigned int)a1;
}
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func9(signed int a1, signed int a2)
{
while ( 1 )
{
a1 %= a2;
if ( !a1 )
break;
a2 %= a1;
if ( !a2 )
return (unsigned int)a1;
}
return (unsigned int)a2;
}

original_code:
int gcd3(int m, int n)
{
    while(1) {
        if(0 == (m = m % n)) {
            return n;
        }
        else if(0 == (n = n % m)) {
            return m;
        }
    }
    return 1;
}


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

if ( a1 % (int)a2 )
result = gcd4(a2, (unsigned int)(a1 % (int)a2));
else
result = a2;
return result;
}

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

if ( a1 % (int)a2 )
result = func10(a2, (unsigned int)(a1 % (int)a2));
else
result = a2;
return result;
}

original_code:
int gcd4(int m, int n)
{
    if(0 == m % n) {
        return n;
    }
    return gcd4(n, m % n);
}


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

v3 = gcd1(119, 544);
printf("gcd1 is %d\n", v3);
v4 = gcd2(119, 544);
printf("gcd2 is %d\n", v4);
v5 = gcd3(119, 544);
printf("gcd3 is %d\n", v5);
v6 = gcd4(119, 0x220u);
printf("gcd4 is %d\n", v6);
return 0;
}

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

v3 = func7(119, 544);
printf("gcd1 is %d\n", v3);
v4 = func8(119, 544);
printf("gcd2 is %d\n", v4);
v5 = func9(119, 544);
printf("gcd3 is %d\n", v5);
v6 = func10(119, 0x220u);
printf("gcd4 is %d\n", v6);
return 0;
}

original_code:
int main()
{
    int gcd = 0;
    gcd = gcd1(119, 544);
    printf("gcd1 is %d\n", gcd);
    gcd = gcd2(119, 544);
    printf("gcd2 is %d\n", gcd);
    gcd = gcd3(119, 544);
    printf("gcd3 is %d\n", gcd);
    gcd = gcd4(119, 544);
    printf("gcd4 is %d\n", gcd);
    return 0;
}

variable_types: gcd int


decompiled_code:
__int64 __fastcall get_number_partition_count(__int64 a1, __int64 a2)
{
int v2; // er12

if ( (_DWORD)a1 == 1 )
return 1LL;
if ( (_DWORD)a2 == 1 )
return 1LL;
if ( (int)a1 < (int)a2 )
return get_number_partition_count(a1, (unsigned int)a1);
if ( (_DWORD)a1 == (_DWORD)a2 )
return (unsigned int)get_number_partition_count(a1, (unsigned int)(a1 - 1)) + 1;
if ( (int)a1 <= (int)a2 )
__assert_fail("0", "partition_number.c", 0x15u, "get_number_partition_count");
v2 = get_number_partition_count((unsigned int)(a1 - a2), a2);
return v2 + (unsigned int)get_number_partition_count((unsigned int)a1, (unsigned int)(a2 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // er12

if ( (_DWORD)a1 == 1 )
return 1LL;
if ( (_DWORD)a2 == 1 )
return 1LL;
if ( (int)a1 < (int)a2 )
return func7(a1, (unsigned int)a1);
if ( (_DWORD)a1 == (_DWORD)a2 )
return (unsigned int)func7(a1, (unsigned int)(a1 - 1)) + 1;
if ( (int)a1 <= (int)a2 )
__assert_fail("0", "partition_number.c", 0x15u, "get_number_partition_count");
v2 = func7((unsigned int)(a1 - a2), a2);
return v2 + (unsigned int)func7((unsigned int)a1, (unsigned int)(a2 - 1));
}

original_code:
int get_number_partition_count(int n, int max)
{
    if(n == 1 || max == 1) {
        return 1;
    }
    else if(n < max) {
        return get_number_partition_count(n, n);
    }
    else if(n == max) {
        return 1 + get_number_partition_count(n, n - 1);
    }
    else if(n > max) {
        return get_number_partition_count(n - max, max) +
                    get_number_partition_count(n, max - 1);
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "partition_number.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

variable_types: max int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // eax

for ( i = 1; i != 10; ++i )
{
v4 = get_number_partition_count(i, i);
printf("%d : %d\n", i, v4);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // eax

for ( i = 1; i != 10; ++i )
{
v4 = func7(i, i);
printf("%d : %d\n", i, v4);
}
return 0;
}

original_code:
int main()
{
    int ret = 0;
    int n = 0;
    for(n = 1; n < 10; ++n) {
        int partition = get_number_partition_count(n, n);
        printf("%d : %d\n", n, partition);
    }
    return ret;
}

variable_types: ret int

variable_types: partition int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-A8h] BYREF
char s; // [rsp+8h] [rbp-A0h] BYREF
char v8; // [rsp+88h] [rbp-20h] BYREF
unsigned int v9; // [rsp+8Ch] [rbp-1Ch]

v3 = &s;
do
{
__isoc99_scanf();
v4 = v9;
*((double *)v3 - 1) = (double)(int)v9;
sprintf(v3, "%d", v4);
v3 += 32;
}
while ( v3 != &v8 );
if ( (unsigned __int8)game24(&v6, 4LL) )
puts("Done");
else
puts("No Answer");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-A8h] BYREF
char s; // [rsp+8h] [rbp-A0h] BYREF
char v8; // [rsp+88h] [rbp-20h] BYREF
unsigned int v9; // [rsp+8Ch] [rbp-1Ch]

v3 = &s;
do
{
__isoc99_scanf();
v4 = v9;
*((double *)v3 - 1) = (double)(int)v9;
sprintf(v3, "%d", v4);
v3 += 32;
}
while ( v3 != &v8 );
if ( (unsigned __int8)func7(&v6, 4LL) )
puts("Done");
else
puts("No Answer");
return 0;
}

original_code:
int main( void )
{
  int i, poke;
  Card card[4];
  for( i = 0; i < 4; i++ ) {
    scanf( "%d", &poke );
    card[i].value = ( double )poke;
    sprintf( card[i].expression, "%d", poke );
  }
  if( game24( card, 4 ) ) {
    printf( "Done\n");
  } else {
    printf( "No Answer\n" );
  }
  return 0;
}

canonical_original_code:
int main()
{
  int i; int poke;
  struct Card card[4];
  for( i = 0; i < 4; i++ ) {
    scanf( "%d", &poke );
    card[i].value = ( double )poke;
    sprintf( card[i].expression, "%d", poke );
  }
  if( game24( card, 4 ) ) {
    printf( "Done\n");
  } else {
    printf( "No Answer\n" );
  }
  return 0;
}

variable_types: poke int

variable_types: struct Card { double value; char expression[-1]; } [4]


original_code:
_Bool game24( Card *card, int size )
{
  Card stack[ size - 1 ];
  if( size == 1 ) {
    if( fabs( card[0].value - 24 ) < 1E-6 ) {
      printf( "%d = %s\n", 24, card[0].expression );
      return 1;
    } else {
      return 0;
    }
  }
  int m, n, i, t;
  for( m = 0; m < size - 1; m++ ) {
    for( n = m + 1; n < size; n++ ) {
      t = 0;
      for( i = 0; i < size; i++ ) {
 if( i != m && i != n ) {
   stack[t].value = card[i].value;
   sprintf( stack[t].expression, "%s", card[i].expression );
   t++;
 }
      }
      stack[size - 2].value = card[m].value + card[n].value;
      sprintf( stack[size - 2].expression, "(%s + %s)", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value > card[n].value ) {
 stack[size - 2].value = card[m].value - card[n].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[m].expression, card[n].expression );
      } else {
 stack[size - 2].value = card[n].value - card[m].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[n].expression, card[m].expression );
      }
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      stack[size - 2].value = card[m].value * card[n].value;
      sprintf( stack[size - 2].expression, "%s * %s", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value != 0 ) {
 stack[size - 2].value = card[n].value / card[m].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[n].expression, card[m].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
      if( card[n].value != 0 ) {
 stack[size - 2].value = card[m].value / card[n].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[m].expression, card[n].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
    }
  }
  return 0;
}

canonical_original_code:
_Bool game24(struct Card *card, int size)
{
  struct Card stack[-1];
  if( size == 1 ) {
    if( fabs( card[0].value - 24 ) < 1E-6 ) {
      printf( "%d = %s\n", 24, card[0].expression );
      return 1;
    } else {
      return 0;
    }
  }
  int m; int n; int i; int t;
  for( m = 0; m < size - 1; m++ ) {
    for( n = m + 1; n < size; n++ ) {
      t = 0;
      for( i = 0; i < size; i++ ) {
 if( i != m && i != n ) {
   stack[t].value = card[i].value;
   sprintf( stack[t].expression, "%s", card[i].expression );
   t++;
 }
      }
      stack[size - 2].value = card[m].value + card[n].value;
      sprintf( stack[size - 2].expression, "(%s + %s)", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value > card[n].value ) {
 stack[size - 2].value = card[m].value - card[n].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[m].expression, card[n].expression );
      } else {
 stack[size - 2].value = card[n].value - card[m].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[n].expression, card[m].expression );
      }
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      stack[size - 2].value = card[m].value * card[n].value;
      sprintf( stack[size - 2].expression, "%s * %s", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value != 0 ) {
 stack[size - 2].value = card[n].value / card[m].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[n].expression, card[m].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
      if( card[n].value != 0 ) {
 stack[size - 2].value = card[m].value / card[n].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[m].expression, card[n].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
    }
  }
  return 0;
}

variable_types: struct Card { double value; char expression[-1]; } *

variable_types: size int

variable_types: struct Card { double value; char expression[-1]; } [-1]

variable_types: t int


repo: dantin/sudoku

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
read(argc, argv, envp);
puts("Result(s):");
sudoku();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func12(argc, argv, envp);
puts("Result(s):");
func11();
return 0;
}

original_code:
int main( void )
{
  read();
  printf( "Result(s):\n" );
  sudoku();
  return 0;
}

canonical_original_code:
int main()
{
  read();
  printf( "Result(s):\n" );
  sudoku();
  return 0;
}


find

decompiled_code:
__int64 find()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 0LL;
while ( 1 )
{
v1 = v0;
if ( !matrix[v0] )
break;
if ( ++v0 == 81 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 0LL;
while ( 1 )
{
v1 = v0;
if ( !matrix[v0] )
break;
if ( ++v0 == 81 )
return (unsigned int)-1;
}
return v1;
}

original_code:
static int find( void )
{
  int i;
  for( i = 0; i < 9 * 9; i++ ) {
    if( matrix[i] == 0 ) {
      return i;
    }
  }
  return -1;
}

canonical_original_code:
static int find()
{
  int i;
  for( i = 0; i < 9 * 9; i++ ) {
    if( matrix[i] == 0 ) {
      return i;
    }
  }
  return -1;
}

variable_types: i int


set

original_code:
static _Bool set( const int loc, const int num )
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  _Bool valid = matrix[loc] == 0
    && ( cols[c] & ( 1 << num ) ) == 0
    && ( rows[r] & ( 1 << num ) ) == 0
    && ( grids[g] & ( 1 << num ) ) == 0;
  if( !valid ) {
    return 0;
  }
  matrix[loc] = num;
  cols[c] |= ( 1 << num );
  rows[r] |= ( 1 << num );
  grids[g] |= ( 1 << num );
  return 1;
}

canonical_original_code:
static _Bool set(int loc, int num)
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  _Bool valid = matrix[loc] == 0
    && ( cols[c] & ( 1 << num ) ) == 0
    && ( rows[r] & ( 1 << num ) ) == 0
    && ( grids[g] & ( 1 << num ) ) == 0;
  if( !valid ) {
    return 0;
  }
  matrix[loc] = num;
  cols[c] |= ( 1 << num );
  rows[r] |= ( 1 << num );
  grids[g] |= ( 1 << num );
  return 1;
}

variable_types: loc int

variable_types: num int

variable_types: c int

variable_types: g int


unset

original_code:
static void unset( const int loc )
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  int num = matrix[loc];
  matrix[loc] = 0;
  cols[c] ^= ( 1 << num );
  rows[r] ^= ( 1 << num );
  grids[g] ^= ( 1 << num );
}

canonical_original_code:
static void unset(int loc)
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  int num = matrix[loc];
  matrix[loc] = 0;
  cols[c] ^= ( 1 << num );
  rows[r] ^= ( 1 << num );
  grids[g] ^= ( 1 << num );
}


sudoku

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

v0 = find();
v1 = 1;
if ( v0 < 0 )
return print();
do
{
result = set(v0, v1);
if ( (_BYTE)result )
{
sudoku();
result = unset(v0);
}
++v1;
}
while ( v1 != 10 );
return result;
}

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

v0 = func7();
v1 = 1;
if ( v0 < 0 )
return func10();
do
{
result = func8(v0, v1);
if ( (_BYTE)result )
{
func11();
result = func9(v0);
}
++v1;
}
while ( v1 != 10 );
return result;
}

original_code:
void sudoku( void )
{
  int loc = find();
  if( loc < 0 ) {
    print();
    return;
  }
  int n;
  for( n = 1; n < 10; n++ ) {
    if( set( loc, n ) ) {
      sudoku();
      unset( loc );
    }
  }
}

canonical_original_code:
void sudoku()
{
  int loc = find();
  if( loc < 0 ) {
    print();
    return;
  }
  int n;
  for( n = 1; n < 10; n++ ) {
    if( set( loc, n ) ) {
      sudoku();
      unset( loc );
    }
  }
}

variable_types: n int


read

decompiled_code:
int read()
{
int v0; // ebx
int v1; // eax
int v2; // eax

v0 = 0;
do
{
v2 = getchar();
if ( v2 == -1 )
break;
if ( v2 == 35 )
{
do
v1 = getchar();
while ( v1 > 0 && v1 != 10 && v1 != 13 );
}
else if ( (unsigned int)(v2 - 49) <= 8 )
{
set(v0++, v2 - 48);
}
else
{
v0 += ((v2 - 46) & 0xFFFFFFFD) == 0;
}
}
while ( v0 <= 80 );
puts("Sudoku Game:");
return print();
}

canonical_decompiled_code:
int func12()
{
int v0; // ebx
int v1; // eax
int v2; // eax

v0 = 0;
do
{
v2 = getchar();
if ( v2 == -1 )
break;
if ( v2 == 35 )
{
do
v1 = getchar();
while ( v1 > 0 && v1 != 10 && v1 != 13 );
}
else if ( (unsigned int)(v2 - 49) <= 8 )
{
func8(v0++, v2 - 48);
}
else
{
v0 += ((v2 - 46) & 0xFFFFFFFD) == 0;
}
}
while ( v0 <= 80 );
puts("Sudoku Game:");
return func10();
}


decompiled_code:
__int64 __fastcall iterate_section_4(__int64 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

if ( n_5 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v3, v4, v5, v6);
FDTD_2D_iterate_Ey(a1);
}
else
{
copy_simulation_up_to(a1, (_QWORD *)(2 * a1[7]));
}
return ++n_5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

if ( n_5 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v3, v4, v5, v6);
FDTD_2D_iterate_Ey(a1);
}
else
{
func4(a1, (_QWORD *)(2 * a1[7]));
}
return ++n_5;
}

original_code:
long iterate_section_4(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_4(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
    }
    ++n;
    return n;
}

variable_types: struct fdtd_2d_t { long I; long J; double *Hz; double *Ex; double *Ey; double gamma_x; double gamma_y; long N_P; } *

variable_types: I long

variable_types: J long

variable_types:
Ex
double *

variable_types:
Ey
double *

variable_types:
Hz
double *

variable_types: n long

variable_types: i long

variable_types: j long

return_type: long


decompiled_code:
__int64 __fastcall iterate_section_7(__int64 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

if ( n_2 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v3, v4, v5, v6);
FDTD_2D_iterate_Ey_mur(a1);
}
else
{
copy_simulation_up_to(a1, (_QWORD *)(2 * a1[7]));
}
return ++n_2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

if ( n_2 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v3, v4, v5, v6);
FDTD_2D_iterate_Ey_mur(a1);
}
else
{
func4(a1, (_QWORD *)(2 * a1[7]));
}
return ++n_2;
}

original_code:
long iterate_section_7(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_7(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
    }
    ++n;
    return n;
}

user_defined_types: struct fdtd_2d_t { long I; long J; double *Hz; double *Ex; double *Ey; double gamma_x; double gamma_y; long N_P; }


decompiled_code:
__int64 __fastcall iterate_section_5(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // r14
double v5; // r13
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
double v10; // xmm0_8

v2 = *(_QWORD *)(a1 + 56);
if ( n_4 )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = *(double *)(a1 + 40);
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v6, v7, v8, v9);
FDTD_2D_iterate_Ey(a1);
v10 = round((double)(6 * (int)v2) * v5);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v10, v4 / 2, v4 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v2));
}
return ++n_4;
}

original_code:
long iterate_section_5(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_5(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

variable_types: S long


decompiled_code:
__int64 __fastcall iterate_section_8(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // r14
double v5; // r13
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
double v10; // xmm0_8

v2 = *(_QWORD *)(a1 + 56);
if ( n_1 )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = *(double *)(a1 + 40);
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v6, v7, v8, v9);
FDTD_2D_iterate_Ey_mur(a1);
v10 = round((double)(6 * (int)v2) * v5);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v10, v4 / 2, v4 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v2));
}
return ++n_1;
}

original_code:
long iterate_section_8(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_8(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}


decompiled_code:
__int64 __fastcall iterate_section_9(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // r14
double v4; // r13
double v5; // xmm0_8

v1 = *(_QWORD *)(a1 + 56);
if ( n_0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = *(double *)(a1 + 40);
FDTD_2D_iterate_Hz_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ex_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ey_PML(a1, 20LL, 1.0);
v5 = round((double)(6 * (int)v1) * v4);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v5, v3 / 2, v3 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v1));
}
return ++n_0;
}

original_code:
long iterate_section_9(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ex_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ey_PML(fdtd, 20, 1);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_9(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ex_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ey_PML(fdtd, 20, 1);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}


clamp

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

result = 0LL;
if ( a1 > 0 )
{
result = 0xFFFFFFFFLL;
if ( a1 <= 254 )
result = (unsigned int)a1;
}
return result;
}

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

result = 0LL;
if ( a1 > 0 )
{
result = 0xFFFFFFFFLL;
if ( a1 <= 254 )
result = (unsigned int)a1;
}
return result;
}

original_code:
unsigned char clamp(long c)
{
    if (c <= 0) return 0;
    if (c >= 255) return 255;
    return c;
}

variable_types: c long

return_type: unsigned char


decompiled_code:
double __fastcall fdtd_excitation(__int64 a1, __int64 a2)
{
double result; // xmm0_8
double v3; // xmm0_8

result = 0.0;
if ( a1 >= 0 && 2 * a2 >= a1 )
{
v3 = sin((double)((int)a1 - (int)a2) * 3.141592653589793 / (double)(int)a2);
result = pow(v3, 3.0);
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, __int64 a2)
{
double result; // xmm0_8
double v3; // xmm0_8

result = 0.0;
if ( a1 >= 0 && 2 * a2 >= a1 )
{
v3 = sin((double)((int)a1 - (int)a2) * 3.141592653589793 / (double)(int)a2);
result = pow(v3, 3.0);
}
return result;
}

return_type: double


decompiled_code:
double __fastcall fdtd_excitation2(unsigned __int64 a1)
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( a1 > 6 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(unsigned __int64 a1)
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( a1 > 6 )
result = 0.0;
return result;
}

original_code:
double fdtd_excitation2(long n, long N_P)
{
    if ((n >=0) && (n <= 6)) {
        return 1.0f;
    } else {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall get_next_time(char *a1)
{
char *v1; // rbx
char v2; // bp
__int64 v3; // rcx
char *v4; // rax
char v5; // dl

if ( first_time_1 == 1 )
{
c_0 = a1;
first_time_1 = 0;
}
v1 = c_0;
v2 = *c_0;
if ( !*c_0 )
return -1LL;
v3 = atol(c_0);
if ( v2 == 44 )
goto LABEL_10;
v4 = v1 + 1;
do
{
v1 = v4;
v5 = *v4++;
}
while ( v5 != 44 && v5 );
c_0 = v1;
if ( v5 )
LABEL_10:
c_0 = v1 + 1;
return v3;
}

original_code:
long get_next_time(char *snapshot_times)
{
    static short first_time = 1;
    static char *c = ((void *)0);
    long n = 0;
    if (1 == first_time) {
        c = snapshot_times;
        first_time = 0;
    }
    if ('\0' == *c) {
        return -1;
    } else {
        n = atol(c);
        while ((',' != *c) && ('\0' != *c)) ++c;
        if ('\0' != *c) ++c;
        return n;
    }
}

variable_types:
c
char *


usage

decompiled_code:
size_t usage()
{
return fwrite("USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n", 1uLL, 0x43uLL, stderr);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n", 1uLL, 0x43uLL, stderr);
}

original_code:
void usage(void)
{
    fprintf(stderr, "USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n");
}

canonical_original_code:
void usage()
{
    fprintf(stderr, "USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n");
}


repo: daogangtang/lgstring

decompiled_code:
__int64 __fastcall has_key(char *s1, _DWORD *a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(s1, &tagset[6 * v2]) )
{
if ( ++v2 == 8 )
return 0LL;
}
*a2 = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *s1, _DWORD *a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(s1, &tagset[6 * v2]) )
{
if ( ++v2 == 8 )
return 0LL;
}
*a2 = v2;
return 1LL;
}

original_code:
static int has_key (const char *str, int *which) {
 int i;
 for (i=0; i<8; i++) {
  if (!strcmp(str, tagset[i][0])) {
   *which = i;
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static int has_key(char *str, int *which) {
 int i;
 for (i=0; i<8; i++) {
  if (!strcmp(str, tagset[i][0])) {
   *which = i;
   return 1;
  }
 }
 return 0;
}

variable_types:
str
char *

variable_types:
which
int *

variable_types: i int


decompiled_code:
__int64 __fastcall get_next_char(__int64 a1, int *a2, _BYTE *a3)
{
unsigned int v3; // ecx
int v4; // eax

if ( !a1 )
{
puts("Error, the string is missing.");
exit(1);
}
v3 = 0;
if ( *(_BYTE *)(a1 + *a2) )
{
v4 = *a2 + 1;
*a2 = v4;
*a3 = *(_BYTE *)(a1 + v4);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int *a2, _BYTE *a3)
{
unsigned int v3; // ecx
int v4; // eax

if ( !a1 )
{
puts("Error, the string is missing.");
exit(1);
}
v3 = 0;
if ( *(_BYTE *)(a1 + *a2) )
{
v4 = *a2 + 1;
*a2 = v4;
*a3 = *(_BYTE *)(a1 + v4);
v3 = 1;
}
return v3;
}

original_code:
static int get_next_char (const char* str, int* ip, char* ncp) {
 if (!str) {
  printf("Error, the string is missing.\n");
  exit(1);
 }
 if (str[*ip] != '\0') {
  *ip += 1;
  *ncp = str[*ip];
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
static int get_next_char(char *str, int *ip, char *ncp) {
 if (!str) {
  printf("Error, the string is missing.\n");
  exit(1);
 }
 if (str[*ip] != '\0') {
  *ip += 1;
  *ncp = str[*ip];
  return 1;
 }
 else
  return 0;
}

variable_types:
ip
int *

variable_types:
ncp
char *


repo: darconeous/bf-tools

decompiled_code:
int ask_newline()
{
__int64 v0; // rax

v0 = newline_count + 1;
newline_count = v0;
if ( v0 == 80 )
{
LODWORD(v0) = fputc(10, _bss_start);
newline_count = 0LL;
}
return v0;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rax

v0 = newline_count + 1;
newline_count = v0;
if ( v0 == 80 )
{
LODWORD(v0) = fputc(10, _bss_start);
newline_count = 0LL;
}
return v0;
}

original_code:
void ask_newline()
{
 if (++newline_count == 80) {
  fputc('\n', stdout);
  newline_count = 0;
 }
}


decompiled_code:
int __fastcall print_n_times_x(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax
__int64 v4; // rbx

v2 = a1;
if ( a1 < 0 )
{
v4 = -a1;
do
{
fputc(a2 - 1, _bss_start);
result = ask_newline();
--v4;
}
while ( v4 );
}
else if ( a1 > 0 )
{
do
{
fputc(a2 + 1, _bss_start);
result = ask_newline();
--v2;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax
__int64 v4; // rbx

v2 = a1;
if ( a1 < 0 )
{
v4 = -a1;
do
{
fputc(a2 - 1, _bss_start);
result = func7();
--v4;
}
while ( v4 );
}
else if ( a1 > 0 )
{
do
{
fputc(a2 + 1, _bss_start);
result = func7();
--v2;
}
while ( v2 );
}
return result;
}

original_code:
void print_n_times_x(long n, int x)
{
 long i;
 if (n < 0) {
  for (i = -n; i > 0; i--) {
   fputc(x - 1, stdout);
   ask_newline();
  }
 }
 if (n > 0) {
  for (i = n; i > 0; i--) {
   fputc(x + 1, stdout);
   ask_newline();
  }
 }
}

variable_types: x int


Hashkey

repo: darkac/deRedundance

original_code:
inline int Hashkey(const char *str)
{
 uint64_t h = 0, g;
 const char *end = str + 64;
 while (str < end)
 {
  h = (h << 4) + *str++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24;
  h &= ~g;
 }
 return (uint32_t)(h % 15000000);
}

canonical_original_code:
inline int Hashkey(char *str)
{
 unsigned long h = 0; unsigned long g;
 char *end = str + 64;
 while (str < end)
 {
  h = (h << 4) + *str++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24;
  h &= ~g;
 }
 return (unsigned int)(h % 15000000);
}

variable_types:
h
unsigned long

variable_types:
g
unsigned long

variable_types:
end
char *


decompiled_code:
__int64 HT_Init()
{
__int64 *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = &hashTable;
do
{
v1 = malloc(0x10uLL);
*v0 = (__int64)v1;
result = CheckAndSetPointer(v1, 0LL, 16LL);
++v0;
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = &hashTable;
do
{
v1 = malloc(0x10uLL);
*v0 = (__int64)v1;
result = func12(v1, 0LL, 16LL);
++v0;
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

original_code:
void HT_Init()
{
 uint32_t i;
 for (i = 0; i < 15000000; ++i)
 {
  hashTable[i] = (hashnode_t *)malloc(sizeof(hashnode_t));
  CheckAndSetPointer(hashTable[i], 0, sizeof(hashnode_t));
 }
}

canonical_original_code:
void HT_Init()
{
 unsigned int i;
 for (i = 0; i < 15000000; ++i)
 {
  hashTable[i] = (struct hashnode *)malloc(sizeof(hashnode_t));
  CheckAndSetPointer(hashTable[i], 0, sizeof(hashnode_t));
 }
}

variable_types:
i
unsigned int

user_defined_types: struct hashnode { unsigned long m_start; struct hashnode *m_next; }


decompiled_code:
__int64 HT_Free()
{
__int64 *v0; // rbp
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rdi

v0 = &hashTable;
do
{
v2 = *(_QWORD *)(*v0 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
FreePointer(v3);
}
result = FreePointer(*v0++);
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 *v0; // rbp
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rdi

v0 = &hashTable;
do
{
v2 = *(_QWORD *)(*v0 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
func13(v3);
}
result = func13(*v0++);
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

original_code:
void HT_Free()
{
 uint32_t i;
 for (i = 0; i < 15000000; ++i)
 {
  hashnode_t *temp = hashTable[i]->m_next;
  hashnode_t *todel;
  while (temp != ((void *)0))
  {
   todel = temp;
   temp = temp->m_next;
   FreePointer(todel);
  }
  FreePointer(hashTable[i]);
 }
}

canonical_original_code:
void HT_Free()
{
 unsigned int i;
 for (i = 0; i < 15000000; ++i)
 {
  struct hashnode *temp = hashTable[i]->m_next;
  struct hashnode *todel;
  while (temp != ((void *)0))
  {
   todel = temp;
   temp = temp->m_next;
   FreePointer(todel);
  }
  FreePointer(hashTable[i]);
 }
}

variable_types: struct hashnode { unsigned long m_start; struct hashnode *m_next; } *


decompiled_code:
__int64 __fastcall HT_Insert(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // rbx
__int64 result; // rax

v2 = Hashkey((char *)(a2 + a1));
v3 = malloc(0x10uLL);
CheckAndSetPointer(v3, 0LL, 16LL);
*v3 = a2;
result = hashTable[v2];
v3[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // rbx
__int64 result; // rax

v2 = func7((char *)(a2 + a1));
v3 = malloc(0x10uLL);
func12(v3, 0LL, 16LL);
*v3 = a2;
result = hashTable[v2];
v3[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v3;
return result;
}

original_code:
void HT_Insert(const char *str, uint64_t position)
{
 int slot = Hashkey(str + position);
 hashnode_t *hnode = (hashnode_t *)malloc(sizeof(hashnode_t));
 CheckAndSetPointer(hnode, 0, sizeof(hashnode_t));
 hnode->m_start = position;
 hnode->m_next = hashTable[slot]->m_next;
 hashTable[slot]->m_next = hnode;
}

canonical_original_code:
void HT_Insert(char *str, unsigned long position)
{
 int slot = Hashkey(str + position);
 struct hashnode *hnode = (hashnode_t *)malloc(sizeof(hashnode_t));
 CheckAndSetPointer(hnode, 0, sizeof(hashnode_t));
 hnode->m_start = position;
 hnode->m_next = hashTable[slot]->m_next;
 hashTable[slot]->m_next = hnode;
}

variable_types:
position
unsigned long

variable_types: slot int


CheckAndSetPointer

decompiled_code:
void *__fastcall CheckAndSetPointer(void *a1, char a2, size_t a3)
{
if ( !a1 )
{
printf("Null pointer!");
exit(-1);
}
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func12(void *a1, char a2, size_t a3)
{
if ( !a1 )
{
printf("Null pointer!");
exit(-1);
}
return memset(a1, a2, a3);
}

original_code:
void CheckAndSetPointer(void *pointer, char content, size_t size)
{
 if (pointer == ((void *)0))
 {
  printf("Null pointer!");
  exit(-1);
 }
 memset(pointer, content, size);
}

canonical_original_code:
void CheckAndSetPointer(void *pointer, char content, unsigned long size)
{
 if (pointer == ((void *)0))
 {
  printf("Null pointer!");
  exit(-1);
 }
 memset(pointer, content, size);
}

variable_types:
pointer
void *

variable_types: content char

variable_types:
size
unsigned long


FreePointer

decompiled_code:
void __fastcall FreePointer(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func13(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void FreePointer(void *pointer)
{
 if (pointer != ((void *)0))
 {
  free(pointer);
  pointer = 0;
 }
}


IsOverlap

decompiled_code:
_BOOL8 __fastcall IsOverlap(int a1, unsigned int a2)
{
return a1 + 63 >= a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(int a1, unsigned int a2)
{
return a1 + 63 >= a2;
}

original_code:
int IsOverlap(uint32_t pf, uint32_t pp)
{
 if (pf + 64 - 1 >= pp)
  return 1;
 else
  return 0;
}

canonical_original_code:
int IsOverlap(unsigned int pf, unsigned int pp)
{
 if (pf + 64 - 1 >= pp)
  return 1;
 else
  return 0;
}

variable_types:
pf
unsigned int

variable_types:
pp
unsigned int


IsValid

decompiled_code:
__int64 __fastcall IsValid(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a2 + 64;
if ( a2 >= a2 + 64 )
return 1LL;
while ( *(_DWORD *)(a1 + 4LL * a2) != 1 )
{
if ( ++a2 == v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a2 + 64;
if ( a2 >= a2 + 64 )
return 1LL;
while ( *(_DWORD *)(a1 + 4LL * a2) != 1 )
{
if ( ++a2 == v2 )
return 1LL;
}
return 0LL;
}

original_code:
int IsValid(uint32_t marked[], uint32_t pf)
{
 uint32_t i;
 for (i = pf; i < pf + 64; ++i)
 {
  if (marked[i] == 1)
   return 0;
 }
 return 1;
}

canonical_original_code:
int IsValid(unsigned int marked[], unsigned int pf)
{
 unsigned int i;
 for (i = pf; i < pf + 64; ++i)
 {
  if (marked[i] == 1)
   return 0;
 }
 return 1;
}

variable_types:
marked
unsigned int []


identify

decompiled_code:
unsigned int __fastcall identify(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int result; // eax
__int64 *v6; // rax
__int64 v7; // r14

v4 = 0;
do
{
v6 = HT_GetNode(a1, v4);
if ( v6 )
{
v7 = *v6;
if ( !(unsigned int)IsValid(a3, *v6) )
{
result = HT_Insert(a1, v4++);
continue;
}
if ( IsOverlap(v7, v4) )
result = (unsigned int)mark(a3, (int)v7 + 64, v4 - (unsigned int)v7);
else
result = (unsigned int)mark(a3, v4, 64);
v4 += 64;
}
else
{
result = HT_Insert(a1, v4++);
}
if ( (v4 & 0xFFFFF) == 0 )
result = printf("Already processed %d MB (approximately)\n", v4 >> 20);
}
while ( v4 <= a2 - 64 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func17(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int result; // eax
__int64 *v6; // rax
__int64 v7; // r14

v4 = 0;
do
{
v6 = HT_GetNode(a1, v4);
if ( v6 )
{
v7 = *v6;
if ( !(unsigned int)func16(a3, *v6) )
{
result = func10(a1, v4++);
continue;
}
if ( func15(v7, v4) )
result = (unsigned int)mark(a3, (int)v7 + 64, v4 - (unsigned int)v7);
else
result = (unsigned int)mark(a3, v4, 64);
v4 += 64;
}
else
{
result = func10(a1, v4++);
}
if ( (v4 & 0xFFFFF) == 0 )
result = printf("Already processed %d MB (approximately)\n", v4 >> 20);
}
while ( v4 <= a2 - 64 );
return result;
}

original_code:
void identify(const char *file_buf, uint32_t dsize, uint32_t marked[])
{
 uint32_t idx = 0;
 uint32_t range = dsize - 64;
 while (idx <= range)
 {
  hashnode_t *found = HT_GetNode(file_buf, idx);
  if (found == ((void *)0))
  {
   HT_Insert(file_buf, idx);
   idx++;
  }
  else
  {
   uint32_t pf = found->m_start;
   int valid = IsValid(marked, pf);
   if (valid == 0)
   {
    HT_Insert(file_buf, idx);
    idx++;
    continue;
   }
   int overlap = IsOverlap(pf, idx);
   if (overlap == 0)
    mark(marked, idx, 64);
   else
    mark(marked, pf + 64, idx - pf);
   idx += 64;
  }
  if (idx % 1048576 == 0)
   printf("Already processed %d MB (approximately)\n", idx / 1048576);
 }
}

canonical_original_code:
void identify(char *file_buf, unsigned int dsize, unsigned int marked[])
{
 unsigned int idx = 0;
 unsigned int range = dsize - 64;
 while (idx <= range)
 {
  struct hashnode *found = HT_GetNode(file_buf, idx);
  if (found == ((void *)0))
  {
   HT_Insert(file_buf, idx);
   idx++;
  }
  else
  {
   unsigned int pf = found->m_start;
   int valid = IsValid(marked, pf);
   if (valid == 0)
   {
    HT_Insert(file_buf, idx);
    idx++;
    continue;
   }
   int overlap = IsOverlap(pf, idx);
   if (overlap == 0)
    mark(marked, idx, 64);
   else
    mark(marked, pf + 64, idx - pf);
   idx += 64;
  }
  if (idx % 1048576 == 0)
   printf("Already processed %d MB (approximately)\n", idx / 1048576);
 }
}

variable_types:
dsize
unsigned int

variable_types:
idx
unsigned int

variable_types:
range
unsigned int

variable_types: valid int

variable_types: overlap int


die

repo: darkhelmet/ntpstat

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(2);
}

original_code:
void die (char *msg) {
  fprintf (stderr,"%s\n",msg);
  exit (2);
}

canonical_original_code:
void die(char *msg) {
  fprintf (stderr,"%s\n",msg);
  exit (2);
}

variable_types:
msg
char *