rdtsc

decompiled_code:
unsigned __int64 rdtsc()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func7()
{
return __rdtsc();
}

original_code:
static __inline__ unsigned long long rdtsc(void)
{
    unsigned hi, lo;
    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
    return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}

canonical_original_code:
static __inline__ unsigned long long rdtsc()
{
    unsigned int hi; unsigned int lo;
    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
    return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}

variable_types:
hi
unsigned int

variable_types:
lo
unsigned int

return_type: unsigned long long


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // rax
__int64 v5; // r12
__int64 v6; // rbx
__int64 v7; // rax
__m128i v8; // xmm6
float v9; // ebx
__int64 v10; // r13
__int64 v11; // rax
float v12; // xmm0_4
unsigned int v13; // ebx
__int64 v14; // rdi
float v15; // xmm0_4
float v16; // xmm1_4
double v17; // xmm0_8
bool v18; // cf
double v19; // xmm1_8
__int64 v20; // r14
__int64 v21; // rax
__m128i v22; // xmm0
float v23; // [rsp-1004h] [rbp-1004h]

v3 = 12;
while ( 1 )
{
v4 = malloc(0x10000uLL);
v5 = (__int64)v4;
if ( v4 )
break;
if ( !--v3 )
{
fprintf(stderr, "Error: cannot allocate array size:%d\n", 0x2000LL);
exit(2);
}
}
if ( ((unsigned __int16)v4 & 0xFFF) != 0 )
v5 = (__int64)v4 - ((unsigned __int16)v4 & 0xFFF) + 4096;
printf("Array starting address is alligned; array=%#010lx\n", v5);
v6 = rdtsc(v5);
((void (*)(void))enumerate_array)();
v7 = rdtsc(v5) - v6;
if ( v7 < 0 )
{
v22 = 0LL;
*(float *)v22.m128i_i32 = (float)(v7 & 1 | (unsigned int)((unsigned __int64)v7 >> 1))
+ (float)(v7 & 1 | (unsigned int)((unsigned __int64)v7 >> 1));
v9 = COERCE_FLOAT(_mm_cvtsi128_si32(v22));
}
else
{
v8 = 0LL;
*(float *)v8.m128i_i32 = (float)(int)v7;
v9 = COERCE_FLOAT(_mm_cvtsi128_si32(v8));
}
v10 = rdtsc(v5);
enumerate_array(v5);
v11 = rdtsc(v5) - v10;
if ( v11 < 0 )
v23 = (float)(v11 & 1 | (unsigned int)((unsigned __int64)v11 >> 1))
+ (float)(v11 & 1 | (unsigned int)((unsigned __int64)v11 >> 1));
else
v23 = (float)(int)v11;
printf("Initialize the L1D array: All array(store miss) takes %.2fus in total\n", v9);
printf("Restore the L1D array: All array(store hit) takes %.2f in total\n", v23);
v12 = v9;
v13 = 0;
printf("miss_hit_diff = %.2f; miss_hit_threshhold = %.2f\n", (float)(v12 - v23), 100.0);
sleep(2u);
v14 = (__int64)"Start receiving the data";
puts("Start receiving the data");
while ( 1 )
{
v20 = rdtsc(v14);
enumerate_array(v5);
v21 = rdtsc(v5) - v20;
if ( v21 >= 0 )
v15 = (float)(int)v21;
else
v15 = (float)(v21 & 1 | (unsigned int)((unsigned __int64)v21 >> 1))
+ (float)(v21 & 1 | (unsigned int)((unsigned __int64)v21 >> 1));
v16 = v15 - v23;
v17 = v15;
v18 = v16 < 100.0;
v19 = v16;
if ( !v18 )
v13 = 1;
printf("bit recieved is %d : latency is %.2f, diff is %.2f, miss_hit_threshold is %.2f\n", v13, v17, v19, 100.0);
printf("%d\n", v13);
sleep(1u);
v14 = 1LL;
sleep(1u);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // rax
__int64 v5; // r12
__int64 v6; // rbx
__int64 v7; // rax
__m128i v8; // xmm6
float v9; // ebx
__int64 v10; // r13
__int64 v11; // rax
float v12; // xmm0_4
unsigned int v13; // ebx
__int64 v14; // rdi
float v15; // xmm0_4
float v16; // xmm1_4
double v17; // xmm0_8
bool v18; // cf
double v19; // xmm1_8
__int64 v20; // r14
__int64 v21; // rax
__m128i v22; // xmm0
float v23; // [rsp-1004h] [rbp-1004h]

v3 = 12;
while ( 1 )
{
v4 = malloc(0x10000uLL);
v5 = (__int64)v4;
if ( v4 )
break;
if ( !--v3 )
{
fprintf(stderr, "Error: cannot allocate array size:%d\n", 0x2000LL);
exit(2);
}
}
if ( ((unsigned __int16)v4 & 0xFFF) != 0 )
v5 = (__int64)v4 - ((unsigned __int16)v4 & 0xFFF) + 4096;
printf("Array starting address is alligned; array=%#010lx\n", v5);
v6 = func7(v5);
((void (*)(void))enumerate_array)();
v7 = func7(v5) - v6;
if ( v7 < 0 )
{
v22 = 0LL;
*(float *)v22.m128i_i32 = (float)(v7 & 1 | (unsigned int)((unsigned __int64)v7 >> 1))
+ (float)(v7 & 1 | (unsigned int)((unsigned __int64)v7 >> 1));
v9 = COERCE_FLOAT(_mm_cvtsi128_si32(v22));
}
else
{
v8 = 0LL;
*(float *)v8.m128i_i32 = (float)(int)v7;
v9 = COERCE_FLOAT(_mm_cvtsi128_si32(v8));
}
v10 = func7(v5);
func8(v5);
v11 = func7(v5) - v10;
if ( v11 < 0 )
v23 = (float)(v11 & 1 | (unsigned int)((unsigned __int64)v11 >> 1))
+ (float)(v11 & 1 | (unsigned int)((unsigned __int64)v11 >> 1));
else
v23 = (float)(int)v11;
printf("Initialize the L1D array: All array(store miss) takes %.2fus in total\n", v9);
printf("Restore the L1D array: All array(store hit) takes %.2f in total\n", v23);
v12 = v9;
v13 = 0;
printf("miss_hit_diff = %.2f; miss_hit_threshhold = %.2f\n", (float)(v12 - v23), 100.0);
sleep(2u);
v14 = (__int64)"Start receiving the data";
puts("Start receiving the data");
while ( 1 )
{
v20 = func7(v14);
func8(v5);
v21 = func7(v5) - v20;
if ( v21 >= 0 )
v15 = (float)(int)v21;
else
v15 = (float)(v21 & 1 | (unsigned int)((unsigned __int64)v21 >> 1))
+ (float)(v21 & 1 | (unsigned int)((unsigned __int64)v21 >> 1));
v16 = v15 - v23;
v17 = v15;
v18 = v16 < 100.0;
v19 = v16;
if ( !v18 )
v13 = 1;
printf("bit recieved is %d : latency is %.2f, diff is %.2f, miss_hit_threshold is %.2f\n", v13, v17, v19, 100.0);
printf("%d\n", v13);
sleep(1u);
v14 = 1LL;
sleep(1u);
}
}

original_code:
void main()
{
    unsigned long* array = ((void *)0), *array_0;
    int set = 0, line = 0, k = 0;
    int start = 0, end = 0;
    struct timeval before, after;
    int bad = 0, try = 0, i = 0, tmp = 0;
    int bit = 0;
    float miss_time_all, miss_time, hit_time_all, hit_time, miss_hit_ratio, miss_hit_diff,miss_hit_threshhold, time_elapsed;
    uint32_t buffer = 0;
    unsigned long temp;
    unsigned long t_start, t_end;
    do
    {
        array_0 = (unsigned long*)malloc(sizeof(unsigned long) * (4096 * 2));
    }while( array_0 == ((void *)0) && try++ <= 10);
    if( array_0 == ((void *)0))
    {
        fprintf( stderr, "Error: cannot allocate array size:%d\n", (4096 * 2));
        exit(2);
    }
    if( ( (unsigned long)array_0 & 0x0FFFUL ) != 0)
    {
        array = (unsigned long *) ((char*)array_0 + ( 0x0FFFUL - ((unsigned long)array_0 & 0x0FFFUL) ) + 1);
    }else{
        array = array_0;
    }
    printf("Array starting address is alligned; array=%#010lx\n", (unsigned long)array);
    for(i = 0; i < 2; i++)
    {
 t_start = rdtsc();
 enumerate_array(array);
 t_end = rdtsc();
        if( i == 0 )
        {
     miss_time_all = t_end - t_start;
        }
        else
        {
     hit_time_all = t_end - t_start;
        }
    }
    miss_hit_diff = miss_time_all - hit_time_all;
    miss_hit_threshhold = 100;
    printf( "Initialize the L1D array: All array(store miss) takes %.2fus in total\n", miss_time_all );
    printf( "Restore the L1D array: All array(store hit) takes %.2f in total\n", hit_time_all );
    printf( "miss_hit_diff = %.2f; miss_hit_threshhold = %.2f\n", miss_hit_diff, miss_hit_threshhold );
    sleep(2);
    printf( "Start receiving the data\n" );
    while(1)
    {
        time_elapsed = 0;
 t_start = rdtsc();
        enumerate_array(array);
 t_end = rdtsc();
 time_elapsed = t_end - t_start;
        if( time_elapsed - hit_time_all >= miss_hit_threshhold )
        {
            bit = 1;
        }
        printf( "bit recieved is %d : latency is %.2f, diff is %.2f,  miss_hit_threshold is %.2f\n", bit, time_elapsed, time_elapsed - hit_time_all, miss_hit_threshhold );
        printf("%d\n", bit);
 sleep(1);
 sleep(1);
    }
    free(array_0);
}

canonical_original_code:
void main()
{
    unsigned long *array = ((void *)0); unsigned long *array_0;
    int set = 0; int line = 0; int k = 0;
    int start = 0; int end = 0;
    struct timeval before; struct timeval after;
    int bad = 0; int try = 0; int i = 0; int tmp = 0;
    int bit = 0;
    float miss_time_all; float miss_time; float hit_time_all; float hit_time; float miss_hit_ratio; float miss_hit_diff; float miss_hit_threshhold; float time_elapsed;
    unsigned int buffer = 0;
    unsigned long temp;
    unsigned long t_start; unsigned long t_end;
    do
    {
        array_0 = (unsigned long *)malloc(sizeof(unsigned long) * (4096 * 2));
    }while( array_0 == ((void *)0) && try++ <= 10);
    if( array_0 == ((void *)0))
    {
        fprintf( stderr, "Error: cannot allocate array size:%d\n", (4096 * 2));
        exit(2);
    }
    if( ( (unsigned long)array_0 & 0x0FFFUL ) != 0)
    {
        array = (unsigned long *) ((char *)array_0 + ( 0x0FFFUL - ((unsigned long)array_0 & 0x0FFFUL) ) + 1);
    }else{
        array = array_0;
    }
    printf("Array starting address is alligned; array=%#010lx\n", (unsigned long)array);
    for(i = 0; i < 2; i++)
    {
 t_start = rdtsc();
 enumerate_array(array);
 t_end = rdtsc();
        if( i == 0 )
        {
     miss_time_all = t_end - t_start;
        }
        else
        {
     hit_time_all = t_end - t_start;
        }
    }
    miss_hit_diff = miss_time_all - hit_time_all;
    miss_hit_threshhold = 100;
    printf( "Initialize the L1D array: All array(store miss) takes %.2fus in total\n", miss_time_all );
    printf( "Restore the L1D array: All array(store hit) takes %.2f in total\n", hit_time_all );
    printf( "miss_hit_diff = %.2f; miss_hit_threshhold = %.2f\n", miss_hit_diff, miss_hit_threshhold );
    sleep(2);
    printf( "Start receiving the data\n" );
    while(1)
    {
        time_elapsed = 0;
 t_start = rdtsc();
        enumerate_array(array);
 t_end = rdtsc();
 time_elapsed = t_end - t_start;
        if( time_elapsed - hit_time_all >= miss_hit_threshhold )
        {
            bit = 1;
        }
        printf( "bit recieved is %d : latency is %.2f, diff is %.2f,  miss_hit_threshold is %.2f\n", bit, time_elapsed, time_elapsed - hit_time_all, miss_hit_threshhold );
        printf("%d\n", bit);
 sleep(1);
 sleep(1);
    }
    free(array_0);
}

variable_types:
array
unsigned long *

variable_types: set int

variable_types: line int

variable_types: k int

variable_types: start int

variable_types: end int

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: bad int

variable_types: try int

variable_types: i int

variable_types: tmp int

variable_types: bit int

variable_types:
buffer
unsigned int

variable_types:
temp
unsigned long

return_type: void


decompiled_code:
int __fastcall enumerate_array(_QWORD *a1)
{
int v1; // ebx
unsigned __int64 v2; // rax
__int64 v3; // rcx
int result; // eax

v1 = 100;
do
{
rdtsc();
*a1 = 1LL;
v2 = rdtsc();
result = printf("access address %#lx, latency = %lu\n", a1, v2 - v3);
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(_QWORD *a1)
{
int v1; // ebx
unsigned __int64 v2; // rax
__int64 v3; // rcx
int result; // eax

v1 = 100;
do
{
func7();
*a1 = 1LL;
v2 = func7();
result = printf("access address %#lx, latency = %lu\n", a1, v2 - v3);
--v1;
}
while ( v1 );
return result;
}

original_code:
static inline void enumerate_array(unsigned long* array)
{
    int i = 0, j;
    unsigned long t_start, t_end;
    for( j = 0; j < 100; j+=1)
    {
        t_start = rdtsc();
        array[i] = 1;
 t_end = rdtsc();
 printf("access address %#lx, latency = %lu\n",(unsigned long) (array+i), t_end-t_start);
    }
    return;
}

canonical_original_code:
static inline void enumerate_array(unsigned long *array)
{
    int i = 0; int j;
    unsigned long t_start; unsigned long t_end;
    for( j = 0; j < 100; j+=1)
    {
        t_start = rdtsc();
        array[i] = 1;
 t_end = rdtsc();
 printf("access address %#lx, latency = %lu\n",(unsigned long) (array+i), t_end-t_start);
    }
    return;
}

variable_types: j int


decompiled_code:
int get_rand_char()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
return rand();
}

canonical_decompiled_code:
int func7()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
return rand();
}

original_code:
static inline char get_rand_char()
{
    srand(time(((void *)0)));
    return (char) rand() & 0x0FF;
}

return_type: char


decompiled_code:
_BOOL8 __fastcall is_file_exist(const char *a1)
{
return access(a1, 0) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
return access(a1, 0) == 0;
}

original_code:
static inline int is_file_exist(char* filename)
{
    int err = access(filename, 0);
    if( err == 0 )
    {
        return 1;
    }else{
        return 0;
    }
}

canonical_original_code:
static inline int is_file_exist(char *filename)
{
    int err = access(filename, 0);
    if( err == 0 )
    {
        return 1;
    }else{
        return 0;
    }
}

variable_types:
filename
char *

variable_types: err int

return_type: int


decompiled_code:
__int64 __fastcall get_array_index(int a1, int a2)
{
return (unsigned int)(8 * (a1 + (a2 << 6)));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(8 * (a1 + (a2 << 6)));
}

original_code:
static inline int get_array_index(int set, int line)
{
    return set * (8) + line * (64) * (8);
}


canonical_decompiled_code:
int func9()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
return rand();
}

canonical_original_code:
static inline char get_rand_char()
{
    srand(time(((void *)0)));
    return (char) rand() & 0x0FF;
}


canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return (unsigned int)(8 * (a1 + (a2 << 6)));
}

canonical_original_code:
static inline int get_array_index(int set, int line)
{
    return set * (8) + line * (64) * (8);
}


repo: PerformanceHorizonGroup/csv-split

decompiled_code:
__int64 __fastcall write_gz_file(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
_BYTE savedregs[296]; // [rsp+0h] [rbp+0h] BYREF

if ( (_DWORD)a4 == -1 )
strncpy(savedregs, "wb", 0xFFuLL);
else
snprintf(savedregs, 0xFFuLL, "wb%d", a4);
v5 = gzopen(a1, savedregs);
if ( !v5 )
{
fprintf(stderr, "Error: Unable to open output file '%s'\n", a1);
LABEL_8:
exit(1);
}
if ( (int)gzwrite(v5, a2, (unsigned int)a3) != a3 )
{
fprintf(stderr, "Error: Unable to write all data to file '%s'\n", a1);
goto LABEL_8;
}
return gzclose(savedregs);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
_BYTE savedregs[296]; // [rsp+0h] [rbp+0h] BYREF

if ( (_DWORD)a4 == -1 )
strncpy(savedregs, "wb", 0xFFuLL);
else
snprintf(savedregs, 0xFFuLL, "wb%d", a4);
v5 = gzopen(a1, savedregs);
if ( !v5 )
{
fprintf(stderr, "Error: Unable to open output file '%s'\n", a1);
LABEL_8:
exit(1);
}
if ( (int)gzwrite(v5, a2, (unsigned int)a3) != a3 )
{
fprintf(stderr, "Error: Unable to write all data to file '%s'\n", a1);
goto LABEL_8;
}
return gzclose(savedregs);
}

original_code:
static void write_gz_file(const char *file, const char *data, size_t len, int level) {
 char mode[255];
 if(level == (-1)) {
  strncpy(mode,"wb",sizeof(mode));
 } else {
  snprintf(mode,sizeof(mode),"wb%d",level);
 }
 gzFile fp = gzopen(file,mode);
 if(!fp) {
  fprintf(stderr, "Error:  Unable to open output file '%s'\n", file);
  exit(1);
 }
 if(gzwrite(fp, data, len) != len) {
  fprintf(stderr, "Error:  Unable to write all data to file '%s'\n", file);
  exit(1);
 }
 gzclose(fp);
}

canonical_original_code:
static void write_gz_file(char *file, char *data, unsigned long len, int level) {
 char mode[255];
 if(level == (-1)) {
  strncpy(mode,"wb",sizeof(mode));
 } else {
  snprintf(mode,sizeof(mode),"wb%d",level);
 }
 struct gzFile_s *fp = gzopen(file,mode);
 if(!fp) {
  fprintf(stderr, "Error:  Unable to open output file '%s'\n", file);
  exit(1);
 }
 if(gzwrite(fp, data, len) != len) {
  fprintf(stderr, "Error:  Unable to write all data to file '%s'\n", file);
  exit(1);
 }
 gzclose(fp);
}

variable_types:
file
char *

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types: level int

variable_types:
mode
char [255]

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *


decompiled_code:
int __fastcall exec_trigger(char *command, char *value, __int64 a3)
{
int result; // eax
int *v4; // rax
int *v5; // rax
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v6, 0x28uLL, "%lu", a3);
if ( setenv("CSV_PAYLOAD_FILE", value, 1) )
{
v4 = _errno_location();
fprintf(stderr, "Couldn't set environment variable: %d\n", (unsigned int)*v4);
}
if ( setenv("CSV_ROWCOUNT", v6, 1) )
{
v5 = _errno_location();
fprintf(stderr, "Couldn't set environment variable: %d\n", (unsigned int)*v5);
}
result = system(command);
if ( result )
result = fprintf(stderr, "Error: Couldn't execute system command \"%s\"\n", command);
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *command, char *value, __int64 a3)
{
int result; // eax
int *v4; // rax
int *v5; // rax
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v6, 0x28uLL, "%lu", a3);
if ( setenv("CSV_PAYLOAD_FILE", value, 1) )
{
v4 = _errno_location();
fprintf(stderr, "Couldn't set environment variable: %d\n", (unsigned int)*v4);
}
if ( setenv("CSV_ROWCOUNT", v6, 1) )
{
v5 = _errno_location();
fprintf(stderr, "Couldn't set environment variable: %d\n", (unsigned int)*v5);
}
result = system(command);
if ( result )
result = fprintf(stderr, "Error: Couldn't execute system command \"%s\"\n", command);
return result;
}

original_code:
static void exec_trigger(const char *trigger_cmd, const char *job_file, unsigned long row_count) {
    char row_count_str[40];
    snprintf(row_count_str, sizeof(row_count_str), "%lu", row_count);
    if(setenv("CSV_PAYLOAD_FILE", job_file, 1) != 0) {
        fprintf(stderr, "Couldn't set environment variable: %d\n", (*__errno_location ()));
    }
    if(setenv("CSV_ROWCOUNT", row_count_str, 1) != 0) {
        fprintf(stderr, "Couldn't set environment variable: %d\n", (*__errno_location ()));
    }
    if(system(trigger_cmd) != 0) {
        fprintf(stderr, "Error:  Couldn't execute system command \"%s\"\n", trigger_cmd);
    }
}

canonical_original_code:
static void exec_trigger(char *trigger_cmd, char *job_file, unsigned long row_count) {
    char row_count_str[40];
    snprintf(row_count_str, sizeof(row_count_str), "%lu", row_count);
    if(setenv("CSV_PAYLOAD_FILE", job_file, 1) != 0) {
        fprintf(stderr, "Couldn't set environment variable: %d\n", (*__errno_location ()));
    }
    if(setenv("CSV_ROWCOUNT", row_count_str, 1) != 0) {
        fprintf(stderr, "Couldn't set environment variable: %d\n", (*__errno_location ()));
    }
    if(system(trigger_cmd) != 0) {
        fprintf(stderr, "Error:  Couldn't execute system command \"%s\"\n", trigger_cmd);
    }
}


decompiled_code:
void *__fastcall io_worker(void *a1)
{
char *v2; // rdi
unsigned int *v3; // rbp
void *ptr; // [rsp+8h] [rbp-420h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

while ( !(unsigned int)fq_get(a1, &ptr) )
{
v3 = (unsigned int *)ptr;
if ( *((_DWORD *)ptr + 72) )
{
snprintf(s, 0x400uLL, "%s.gz", (const char *)ptr);
write_gz_file((__int64)s, *((_QWORD *)v3 + 34), *((_QWORD *)v3 + 35), v3[72]);
}
else
{
strncpy(s, (const char *)ptr, 0x400uLL);
write_file(s, *((const void **)v3 + 34), *((_QWORD *)v3 + 35));
}
v2 = (char *)*((_QWORD *)v3 + 32);
if ( v2 )
exec_trigger(v2, s, *((_QWORD *)v3 + 33));
free(*((void **)v3 + 34));
free(v3);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
char *v2; // rdi
unsigned int *v3; // rbp
void *ptr; // [rsp+8h] [rbp-420h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

while ( !(unsigned int)fq_get(a1, &ptr) )
{
v3 = (unsigned int *)ptr;
if ( *((_DWORD *)ptr + 72) )
{
snprintf(s, 0x400uLL, "%s.gz", (const char *)ptr);
func0((__int64)s, *((_QWORD *)v3 + 34), *((_QWORD *)v3 + 35), v3[72]);
}
else
{
strncpy(s, (const char *)ptr, 0x400uLL);
func1(s, *((const void **)v3 + 34), *((_QWORD *)v3 + 35));
}
v2 = (char *)*((_QWORD *)v3 + 32);
if ( v2 )
func2(v2, s, *((_QWORD *)v3 + 33));
free(*((void **)v3 + 34));
free(v3);
}
return 0LL;
}

original_code:
void *io_worker(void *arg) {
    fqueue *queue = (fqueue*)arg;
    struct q_flush_item *item;
    void *itm_ptr;
    char out_file[1024];
    while(!fq_get(queue, &itm_ptr)) {
        item = itm_ptr;
        if(item->gzip) {
            snprintf(out_file, sizeof(out_file),"%s.gz", item->out_file);
            write_gz_file(out_file, item->str, item->len, item->gzip);
        } else {
         strncpy(out_file, item->out_file, sizeof(out_file));
         write_file(out_file, item->str, item->len);
        }
        if(item->trigger_cmd) {
            exec_trigger(item->trigger_cmd, out_file, item->row_count);
        }
        free(item->str);
        free(item);
    }
    return ((void *)0);
}

canonical_original_code:
void *io_worker(void *arg) {
    struct _fqueue *queue = (fqueue*)arg;
    struct q_flush_item *item;
    void *itm_ptr;
    char out_file[1024];
    while(!fq_get(queue, &itm_ptr)) {
        item = itm_ptr;
        if(item->gzip) {
            snprintf(out_file, sizeof(out_file),"%s.gz", item->out_file);
            write_gz_file(out_file, item->str, item->len, item->gzip);
        } else {
         strncpy(out_file, item->out_file, sizeof(out_file));
         write_file(out_file, item->str, item->len);
        }
        if(item->trigger_cmd) {
            exec_trigger(item->trigger_cmd, out_file, item->row_count);
        }
        free(item->str);
        free(item);
    }
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct _fqueue { struct queue_item { void *data; struct queue_item *next; } *items; struct queue_item *first; unsigned int max_len; unsigned int len; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } full; union pthread_cond_t empty; } *

variable_types: struct q_flush_item { char out_file[255]; char *trigger_cmd; unsigned long row_count; char *str; unsigned long len; int gzip; } *

return_type: void *

user_defined_types: struct _fqueue { struct queue_item *items; struct queue_item *first; unsigned int max_len; unsigned int len; union pthread_mutex_t mutex; union pthread_cond_t full; union pthread_cond_t empty; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


original_code:
void flush_file(struct csv_context *ctx, unsigned int use_ovr) {
    struct q_flush_item *q_item = malloc(sizeof(struct q_flush_item));
    size_t flush_len = use_ovr && ctx->opos ? ctx->opos : (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
    sprintf(q_item->out_file, "%s%s.%05d", ctx->out_path, ctx->in_prefix, ++ctx->on_file);
    if(*ctx->trigger_cmd) {
     q_item->trigger_cmd = (const char *)ctx->trigger_cmd;
    } else {
     q_item->trigger_cmd = ((void *)0);
    }
    q_item->row_count = ctx->row;
    q_item->str = cbuf_duplen(ctx->csv_buf, &flush_len);
    q_item->len = flush_len;
    q_item->gzip = ctx->gzip;
    (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos=ctx->header_len);
    ctx->row = ctx->count_header ? 1 : 0;
    ctx->opos = 0;
    fq_add(&ctx->io_queue, (void*)q_item);
}

canonical_original_code:
void flush_file(struct csv_context *ctx, unsigned int use_ovr) {
    struct q_flush_item *q_item = malloc(sizeof(struct q_flush_item));
    unsigned long flush_len = use_ovr && ctx->opos ? ctx->opos : (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
    sprintf(q_item->out_file, "%s%s.%05d", ctx->out_path, ctx->in_prefix, ++ctx->on_file);
    if(*ctx->trigger_cmd) {
     q_item->trigger_cmd = (char *)ctx->trigger_cmd;
    } else {
     q_item->trigger_cmd = ((void *)0);
    }
    q_item->row_count = ctx->row;
    q_item->str = cbuf_duplen(ctx->csv_buf, &flush_len);
    q_item->len = flush_len;
    q_item->gzip = ctx->gzip;
    (((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos=ctx->header_len);
    ctx->row = ctx->count_header ? 1 : 0;
    ctx->opos = 0;
    fq_add(&ctx->io_queue, (void *)q_item);
}

variable_types: struct csv_context { char in_file[255]; char *in_prefix; char trigger_cmd[255]; int from_stdin; unsigned int on_file; unsigned long row; unsigned long max_rows; unsigned long opos; int gcol; int gzip; unsigned short use_header; unsigned short count_header; unsigned int header_len; unsigned int put_comma; char *gcol_buf; char *csv_buf; struct _fqueue { struct queue_item { void *data; struct queue_item *next; } *items; struct queue_item *first; unsigned int max_len; unsigned int len; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } full; union pthread_cond_t empty; } io_queue; unsigned int thread_count; unsigned long *io_threads; struct csv_parser { int pstate; int quoted; unsigned long spaces; unsigned char *entry_buf; unsigned long entry_pos; unsigned long entry_size; int status; unsigned char options; unsigned char quote_char; unsigned char delim_char; int (*is_space)(unsigned char); int (*is_term)(unsigned char); unsigned long blk_size; void *(*malloc_func)(unsigned long); void *(*realloc_func)(void *, unsigned long); void (*free_func)(void *); } parser; } *

user_defined_types: struct csv_context { char in_file[255]; char *in_prefix; char trigger_cmd[255]; int from_stdin; unsigned int on_file; unsigned long row; unsigned long max_rows; unsigned long opos; int gcol; int gzip; unsigned short use_header; unsigned short count_header; unsigned int header_len; unsigned int put_comma; char *gcol_buf; char *csv_buf; struct _fqueue io_queue; unsigned int thread_count; unsigned long *io_threads; struct csv_parser parser; }

user_defined_types: struct q_flush_item { char out_file[255]; char *trigger_cmd; unsigned long row_count; char *str; unsigned long len; int gzip; }

user_defined_types: struct _cbufhdr { unsigned long size; unsigned long pos; char buf[]; }


original_code:
void cb_row(int c, void *data) {
    struct csv_context *ctx = (struct csv_context*)data;
    ctx->csv_buf = cbuf_putc(ctx->csv_buf, '\n');
    if(ctx->use_header && !ctx->header_len) {
        ctx->header_len = (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
        if(ctx->count_header) {
            ctx->row++;
        }
    } else {
        ctx->row++;
    }
    if(ctx->row >= ctx->max_rows) {
        if(ctx->gcol >= 0) {
            ctx->opos = (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
        } else {
            flush_file(ctx, 0);
        }
    }
    ctx->col=0;
    ctx->put_comma = 0;
}

canonical_original_code:
void cb_row(int c, void *data) {
    struct csv_context *ctx = (struct csv_context*)data;
    ctx->csv_buf = cbuf_putc(ctx->csv_buf, '\n');
    if(ctx->use_header && !ctx->header_len) {
        ctx->header_len = (((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
        if(ctx->count_header) {
            ctx->row++;
        }
    } else {
        ctx->row++;
    }
    if(ctx->row >= ctx->max_rows) {
        if(ctx->gcol >= 0) {
            ctx->opos = (((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos);
        } else {
            flush_file(ctx, 0);
        }
    }
    ctx->col=0;
    ctx->put_comma = 0;
}

variable_types: c int

variable_types:
data
void *

user_defined_types: struct csv_parser { int pstate; int quoted; unsigned long spaces; unsigned char *entry_buf; unsigned long entry_pos; unsigned long entry_size; int status; unsigned char options; unsigned char quote_char; unsigned char delim_char; int (*is_space)(unsigned char); int (*is_term)(unsigned char); unsigned long blk_size; void *(*malloc_func)(unsigned long); void *(*realloc_func)(void *, unsigned long); void (*free_func)(void *); }

user_defined_types: struct queue_item { void *data; struct queue_item *next; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
static inline void cb_col(void *s, size_t len, void *data) {
    struct csv_context *ctx = (struct csv_context *)data;
    size_t cnt;
    if(ctx->put_comma) {
        ctx->csv_buf = cbuf_putc(ctx->csv_buf, ',');
    }
    ctx->put_comma = 1;
    if(ctx->gcol > -1 && ctx->col == ctx->gcol) {
        if(!ctx->use_header || ctx->header_len) {
            if(ctx->gcol_buf && ctx->opos && memcmp(ctx->gcol_buf, s, len) != 0) {
                flush_file(ctx, 1);
            } else if(!ctx->gcol_buf) {
                ctx->gcol_buf = cbuf_init(len);
            }
            ctx->gcol_buf = cbuf_setlen(ctx->gcol_buf, (const char*)s, len);
        }
    }
    while((cnt = csv_write(((((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->buf)+(((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)), ((((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->size)-(((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)), s, len)) > ((((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->size)-(((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos))) {
        ctx->csv_buf = cbuf_double(ctx->csv_buf);
    }
    (((cbufhdr*)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)+=cnt;
    ctx->col++;
}

canonical_original_code:
static inline void cb_col(void *s, unsigned long len, void *data) {
    struct csv_context *ctx = (struct csv_context *)data;
    unsigned long cnt;
    if(ctx->put_comma) {
        ctx->csv_buf = cbuf_putc(ctx->csv_buf, ',');
    }
    ctx->put_comma = 1;
    if(ctx->gcol > -1 && ctx->col == ctx->gcol) {
        if(!ctx->use_header || ctx->header_len) {
            if(ctx->gcol_buf && ctx->opos && memcmp(ctx->gcol_buf, s, len) != 0) {
                flush_file(ctx, 1);
            } else if(!ctx->gcol_buf) {
                ctx->gcol_buf = cbuf_init(len);
            }
            ctx->gcol_buf = cbuf_setlen(ctx->gcol_buf, (char *)s, len);
        }
    }
    while((cnt = csv_write(((((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->buf)+(((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)), ((((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->size)-(((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)), s, len)) > ((((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->size)-(((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos))) {
        ctx->csv_buf = cbuf_double(ctx->csv_buf);
    }
    (((struct _cbufhdr *)(ctx->csv_buf-(sizeof(cbufhdr))))->pos)+=cnt;
    ctx->col++;
}

variable_types:
s
void *

variable_types:
cnt
unsigned long


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("Usage: %s [options] FILE\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("Usage: %s [options] FILE\n", a1);
}

original_code:
void print_usage(char *exec) {
    printf("Usage:  %s [options] FILE\n", exec);
}

variable_types:
exec
char *


decompiled_code:
__int64 __fastcall parse_args(char *s, int argc, char **argv)
{
char *v3; // r13
int v6; // eax
char *v7; // rdi
unsigned int v8; // eax
int v9; // eax
int v10; // eax
char *v11; // rdi
__int64 v12; // rax
char *v13; // rsi
char *v14; // rax
bool v15; // zf
char *v16; // rax
const char *v17; // rsi
char *v19; // rax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = s + 520;
while ( 1 )
{
v6 = getopt_long(argc, argv, "g:n:v:i:z::hd::", &g_long_opts, longind);
if ( v6 == -1 )
break;
if ( v6 )
{
switch ( v6 )
{
case '?':
case 'h':
print_usage(*argv);
exit(1);
case 'd':
v11 = optarg;
*((_WORD *)s + 412) = 1;
if ( v11 )
*((_WORD *)s + 413) = atoi(v11) != 0;
break;
case 'g':
*((_DWORD *)s + 204) = atoi(optarg);
break;
case 'i':
if ( optarg )
{
v10 = atoi(optarg);
if ( (unsigned int)(v10 - 1) > 9 )
{
fprintf(stderr, "Thread count must be in range %d - %d\n", 1LL, 10LL);
exit(1);
}
*((_DWORD *)s + 256) = v10;
}
break;
case 'n':
v9 = atoi(optarg);
if ( v9 <= 0 )
{
fwrite("Number of lines per file must be a positive integer!\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
*((_QWORD *)s + 100) = v9;
break;
case 't':
strncpy(v3, optarg, 0xFFuLL);
break;
case 'v':
puts("csv-split 0.1.1");
exit(0);
case 'z':
v7 = optarg;
*((_DWORD *)s + 205) = -1;
if ( v7 )
{
v8 = atoi(v7);
if ( v8 - 1 > 8 )
fprintf(stderr, "Unknown compression level: %d\n", v8);
else
*((_DWORD *)s + 205) = v8;
}
break;
default:
continue;
}
}
else if ( !strcmp("stdin", *(&g_long_opts.name + 4 * longind[0])) )
{
*((_DWORD *)s + 194) = 1;
}
}
v12 = *((_QWORD *)s + 100);
if ( !v12 )
{
fwrite("Must specify the --num-rows (-n) argument!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( *((_WORD *)s + 413) && v12 == 1 )
{
fwrite("--num-rows must be > 1 if we're counting headers as rows!\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
v13 = argv[optind];
if ( !v13 || !*v13 )
{
fwrite("Must specify a file to process or a prefix to use if reading from STDIN!\n", 1uLL, 0x49uLL, stderr);
exit(1);
}
++optind;
strcpy(s, v13);
v14 = strrchr(s, 47);
v15 = v14 == 0LL;
v16 = v14 + 1;
if ( v15 )
v16 = s;
*((_QWORD *)s + 64) = v16;
v17 = argv[optind];
if ( v17 )
{
if ( *v17 )
{
v19 = stpcpy(s + 255, v17);
if ( *v19 != 48 )
*(_WORD *)v19 = 47;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, int argc, char **argv)
{
char *v3; // r13
int v6; // eax
char *v7; // rdi
unsigned int v8; // eax
int v9; // eax
int v10; // eax
char *v11; // rdi
__int64 v12; // rax
char *v13; // rsi
char *v14; // rax
bool v15; // zf
char *v16; // rax
const char *v17; // rsi
char *v19; // rax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = s + 520;
while ( 1 )
{
v6 = getopt_long(argc, argv, "g:n:v:i:z::hd::", &g_long_opts, longind);
if ( v6 == -1 )
break;
if ( v6 )
{
switch ( v6 )
{
case '?':
case 'h':
func7(*argv);
exit(1);
case 'd':
v11 = optarg;
*((_WORD *)s + 412) = 1;
if ( v11 )
*((_WORD *)s + 413) = atoi(v11) != 0;
break;
case 'g':
*((_DWORD *)s + 204) = atoi(optarg);
break;
case 'i':
if ( optarg )
{
v10 = atoi(optarg);
if ( (unsigned int)(v10 - 1) > 9 )
{
fprintf(stderr, "Thread count must be in range %d - %d\n", 1LL, 10LL);
exit(1);
}
*((_DWORD *)s + 256) = v10;
}
break;
case 'n':
v9 = atoi(optarg);
if ( v9 <= 0 )
{
fwrite("Number of lines per file must be a positive integer!\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
*((_QWORD *)s + 100) = v9;
break;
case 't':
strncpy(v3, optarg, 0xFFuLL);
break;
case 'v':
puts("csv-split 0.1.1");
exit(0);
case 'z':
v7 = optarg;
*((_DWORD *)s + 205) = -1;
if ( v7 )
{
v8 = atoi(v7);
if ( v8 - 1 > 8 )
fprintf(stderr, "Unknown compression level: %d\n", v8);
else
*((_DWORD *)s + 205) = v8;
}
break;
default:
continue;
}
}
else if ( !strcmp("stdin", *(&g_long_opts.name + 4 * longind[0])) )
{
*((_DWORD *)s + 194) = 1;
}
}
v12 = *((_QWORD *)s + 100);
if ( !v12 )
{
fwrite("Must specify the --num-rows (-n) argument!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( *((_WORD *)s + 413) && v12 == 1 )
{
fwrite("--num-rows must be > 1 if we're counting headers as rows!\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
v13 = argv[optind];
if ( !v13 || !*v13 )
{
fwrite("Must specify a file to process or a prefix to use if reading from STDIN!\n", 1uLL, 0x49uLL, stderr);
exit(1);
}
++optind;
strcpy(s, v13);
v14 = strrchr(s, 47);
v15 = v14 == 0LL;
v16 = v14 + 1;
if ( v15 )
v16 = s;
*((_QWORD *)s + 64) = v16;
v17 = argv[optind];
if ( v17 )
{
if ( *v17 )
{
v19 = stpcpy(s + 255, v17);
if ( *v19 != 48 )
*(_WORD *)v19 = 47;
}
}
return 0LL;
}

original_code:
int parse_args(struct csv_context *ctx, int argc, char **argv) {
    int opt, opt_idx, intval;
    char *ptr;
    while((opt = getopt_long(argc, argv, "g:n:v:i:z::hd::", g_long_opts, &opt_idx)) != -1) {
        switch(opt) {
            case 't':
                strncpy(ctx->trigger_cmd, optarg, sizeof(ctx->trigger_cmd));
          break;
            case 'g':
                ctx->gcol = atoi(optarg);
                break;
            case 'n':
                intval = atoi(optarg);
                if(intval < 1) {
                    fprintf(stderr, "Number of lines per file must be a positive integer!\n");
                    exit(1);
                }
                ctx->max_rows = intval;
                break;
            case 'i':
                if(optarg) {
                 intval = atoi(optarg);
                 if(intval < 1 || intval > 10) {
                  fprintf(stderr, "Thread count must be in range %d - %d\n",
                    1, 10);
                  exit(1);
                 }
                 ctx->thread_count = intval;
                }
                break;
            case 'z':
             ctx->gzip = (-1);
             if(optarg) {
              intval = atoi(optarg);
              if(intval >= 1 && intval <= 9) {
               ctx->gzip = intval;
              } else {
               fprintf(stderr, "Unknown compression level: %d\n", intval);
              }
             }
             break;
            case 'd':
                ctx->use_header = 1;
                if(optarg) {
                    intval = atoi(optarg);
                    ctx->count_header = intval != 0;
                }
                break;
            case 'h':
            case '?':
                print_usage(argv[0]);
                exit(1);
            case 'v':
                printf("csv-split " "0.1.1" "\n");
                exit(0);
            case 0:
                if(!strcmp("stdin", g_long_opts[opt_idx].name)) {
                    ctx->from_stdin = 1;
                }
                break;
        }
    }
    if(!ctx->max_rows) {
        fprintf(stderr, "Must specify the --num-rows (-n) argument!\n");
        exit(1);
    }
    if(ctx->count_header && ctx->max_rows < 2) {
        fprintf(stderr, "--num-rows must be > 1 if we're counting headers as rows!\n");
        exit(1);
    }
    if(!argv[optind] || !*argv[optind]) {
        fprintf(stderr, "Must specify a file to process or a prefix to use if reading from STDIN!\n");
        exit(1);
    }
    strcpy(ctx->in_file, argv[optind++]);
    if((ptr = strrchr(ctx->in_file, '/'))) {
        ctx->in_prefix = ptr+1;
    } else {
        ctx->in_prefix = ctx->in_file;
    }
    if(argv[optind] && *argv[optind]) {
     strcpy(ctx->out_path, argv[optind]);
     if(ctx->out_path[strlen(ctx->out_path)]-1 != '/') {
      strcat(ctx->out_path, "/");
     }
    }
    return 0;
}

canonical_original_code:
int parse_args(struct csv_context *ctx, int argc, char **argv) {
    int opt; int opt_idx; int intval;
    char *ptr;
    while((opt = getopt_long(argc, argv, "g:n:v:i:z::hd::", g_long_opts, &opt_idx)) != -1) {
        switch(opt) {
            case 't':
                strncpy(ctx->trigger_cmd, optarg, sizeof(ctx->trigger_cmd));
          break;
            case 'g':
                ctx->gcol = atoi(optarg);
                break;
            case 'n':
                intval = atoi(optarg);
                if(intval < 1) {
                    fprintf(stderr, "Number of lines per file must be a positive integer!\n");
                    exit(1);
                }
                ctx->max_rows = intval;
                break;
            case 'i':
                if(optarg) {
                 intval = atoi(optarg);
                 if(intval < 1 || intval > 10) {
                  fprintf(stderr, "Thread count must be in range %d - %d\n",
                    1, 10);
                  exit(1);
                 }
                 ctx->thread_count = intval;
                }
                break;
            case 'z':
             ctx->gzip = (-1);
             if(optarg) {
              intval = atoi(optarg);
              if(intval >= 1 && intval <= 9) {
               ctx->gzip = intval;
              } else {
               fprintf(stderr, "Unknown compression level: %d\n", intval);
              }
             }
             break;
            case 'd':
                ctx->use_header = 1;
                if(optarg) {
                    intval = atoi(optarg);
                    ctx->count_header = intval != 0;
                }
                break;
            case 'h':
            case '?':
                print_usage(argv[0]);
                exit(1);
            case 'v':
                printf("csv-split " "0.1.1" "\n");
                exit(0);
            case 0:
                if(!strcmp("stdin", g_long_opts[opt_idx].name)) {
                    ctx->from_stdin = 1;
                }
                break;
        }
    }
    if(!ctx->max_rows) {
        fprintf(stderr, "Must specify the --num-rows (-n) argument!\n");
        exit(1);
    }
    if(ctx->count_header && ctx->max_rows < 2) {
        fprintf(stderr, "--num-rows must be > 1 if we're counting headers as rows!\n");
        exit(1);
    }
    if(!argv[optind] || !*argv[optind]) {
        fprintf(stderr, "Must specify a file to process or a prefix to use if reading from STDIN!\n");
        exit(1);
    }
    strcpy(ctx->in_file, argv[optind++]);
    if((ptr = strrchr(ctx->in_file, '/'))) {
        ctx->in_prefix = ptr+1;
    } else {
        ctx->in_prefix = ctx->in_file;
    }
    if(argv[optind] && *argv[optind]) {
     strcpy(ctx->out_path, argv[optind]);
     if(ctx->out_path[strlen(ctx->out_path)]-1 != '/') {
      strcat(ctx->out_path, "/");
     }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: intval int

variable_types:
ptr
char *


decompiled_code:
int __fastcall spool_threads(__int64 a1)
{
int result; // eax
__int64 v2; // rbx

result = *(_DWORD *)(a1 + 1024);
if ( result )
{
v2 = 0LL;
do
{
result = pthread_create((pthread_t *)(*(_QWORD *)(a1 + 1032) + 8 * v2), 0LL, io_worker, (void *)(a1 + 856));
if ( result )
{
fwrite("Couldn't start background IO threads!\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
++v2;
}
while ( *(_DWORD *)(a1 + 1024) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
__int64 v2; // rbx

result = *(_DWORD *)(a1 + 1024);
if ( result )
{
v2 = 0LL;
do
{
result = pthread_create((pthread_t *)(*(_QWORD *)(a1 + 1032) + 8 * v2), 0LL, io_worker, (void *)(a1 + 856));
if ( result )
{
fwrite("Couldn't start background IO threads!\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
++v2;
}
while ( *(_DWORD *)(a1 + 1024) > (unsigned int)v2 );
}
return result;
}

original_code:
void spool_threads(struct csv_context *ctx) {
    int i;
    for(i=0;i<ctx->thread_count;i++) {
        if(pthread_create(&ctx->io_threads[i], ((void *)0), io_worker, (void*)&ctx->io_queue) != 0) {
            fprintf(stderr, "Couldn't start background IO threads!\n");
            exit(1);
        }
    }
}

canonical_original_code:
void spool_threads(struct csv_context *ctx) {
    int i;
    for(i=0;i<ctx->thread_count;i++) {
        if(pthread_create(&ctx->io_threads[i], ((void *)0), io_worker, (void *)&ctx->io_queue) != 0) {
            fprintf(stderr, "Couldn't start background IO threads!\n");
            exit(1);
        }
    }
}

variable_types: i int


decompiled_code:
int __fastcall join_threads(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
pthread_t v4; // rdi

result = *(_DWORD *)(a1 + 1024);
if ( result )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 1032) + 8 * v3++);
result = pthread_join(v4, 0LL);
}
while ( *(_DWORD *)(a1 + 1024) > (unsigned int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
pthread_t v4; // rdi

result = *(_DWORD *)(a1 + 1024);
if ( result )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 1032) + 8 * v3++);
result = pthread_join(v4, 0LL);
}
while ( *(_DWORD *)(a1 + 1024) > (unsigned int)v3 );
}
return result;
}

original_code:
void join_threads(struct csv_context *ctx) {
    int i=0;
    for(i=0;i<ctx->thread_count;i++) {
        pthread_join(ctx->io_threads[i], ((void *)0));
    }
}

canonical_original_code:
void join_threads(struct csv_context *ctx) {
    int i = 0;
    for(i=0;i<ctx->thread_count;i++) {
        pthread_join(ctx->io_threads[i], ((void *)0));
    }
}


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

*(_QWORD *)(a1 + 848) = cbuf_init(10240000LL);
fq_init(a1 + 856, 20LL);
if ( (unsigned int)csv_init(a1 + 1040, 0LL) )
{
fwrite("Couldn't initialize CSV parser!\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
csv_set_blk_size(a1 + 1040, 1024LL);
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 1024) = 1;
*(_QWORD *)(a1 + 816) = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 824) = 0LL;
return result;
}

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

*(_QWORD *)(a1 + 848) = cbuf_init(10240000LL);
fq_init(a1 + 856, 20LL);
if ( (unsigned int)csv_init(a1 + 1040, 0LL) )
{
fwrite("Couldn't initialize CSV parser!\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
csv_set_blk_size(a1 + 1040, 1024LL);
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 1024) = 1;
*(_QWORD *)(a1 + 816) = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 824) = 0LL;
return result;
}

original_code:
void context_init(struct csv_context *ctx) {
    ctx->csv_buf = cbuf_init(1024*1000*10);
    fq_init(&ctx->io_queue, 20);
    if(csv_init(&ctx->parser, 0) != 0) {
        fprintf(stderr, "Couldn't initialize CSV parser!\n");
        exit(1);
    }
    csv_set_blk_size(&ctx->parser, 1024);
    ctx->thread_count = 1;
    ctx->gcol = -1;
    ctx->gzip = 0;
    ctx->use_header = 0;
    ctx->count_header = 0;
    ctx->header_len = 0;
}


original_code:
void context_free(struct csv_context *ctx) {
    cbuf_free(ctx->csv_buf);
    if(ctx->gcol_buf) {
        cbuf_free(ctx->gcol_buf);
    }
    fq_free(&ctx->io_queue);
    csv_free(&ctx->parser);
    free(ctx->io_threads);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 _0[145]; // [rsp+0h] [rbp+0h] BYREF

memset(_0, 0, 0x470uLL);
context_init((__int64)_0);
parse_args((char *)_0, argc, (char **)argv);
_0[129] = (__int64)malloc(8LL * LODWORD(_0[128]));
if ( !_0[129] )
{
fwrite("Error: Couldn't allocate thread storage.\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
spool_threads((__int64)_0);
process_csv((__int64)_0);
fq_fin(&_0[107]);
join_threads((__int64)_0);
exec_trigger((char *)&_0[65], (char *)&value, 0LL);
context_free((__int64)_0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 _0[145]; // [rsp+0h] [rbp+0h] BYREF

memset(_0, 0, 0x470uLL);
func11((__int64)_0);
func8((char *)_0, argc, (char **)argv);
_0[129] = (__int64)malloc(8LL * LODWORD(_0[128]));
if ( !_0[129] )
{
fwrite("Error: Couldn't allocate thread storage.\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
func9((__int64)_0);
func13((__int64)_0);
fq_fin(&_0[107]);
func10((__int64)_0);
func2((char *)&_0[65], (char *)&value, 0LL);
func12((__int64)_0);
return 0;
}

original_code:
int main(int argc, char **argv) {
 struct csv_context ctx;
    memset(&ctx, 0, sizeof(struct csv_context));
    context_init(&ctx);
    parse_args(&ctx, argc, argv);
    ctx.io_threads = malloc(ctx.thread_count * sizeof *ctx.io_threads);
    if(!ctx.io_threads) {
        fprintf(stderr, "Error:  Couldn't allocate thread storage.\n");
        exit(1);
    }
    spool_threads(&ctx);
    process_csv(&ctx);
    fq_fin(&ctx.io_queue);
    join_threads(&ctx);
    exec_trigger(ctx.trigger_cmd, "", 0);
    context_free(&ctx);
    return 0;
}

variable_types: struct csv_context { char in_file[255]; char *in_prefix; char trigger_cmd[255]; int from_stdin; unsigned int on_file; unsigned long row; unsigned long max_rows; unsigned long opos; int gcol; int gzip; unsigned short use_header; unsigned short count_header; unsigned int header_len; unsigned int put_comma; char *gcol_buf; char *csv_buf; struct _fqueue { struct queue_item { void *data; struct queue_item *next; } *items; struct queue_item *first; unsigned int max_len; unsigned int len; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } full; union pthread_cond_t empty; } io_queue; unsigned int thread_count; unsigned long *io_threads; struct csv_parser { int pstate; int quoted; unsigned long spaces; unsigned char *entry_buf; unsigned long entry_pos; unsigned long entry_size; int status; unsigned char options; unsigned char quote_char; unsigned char delim_char; int (*is_space)(unsigned char); int (*is_term)(unsigned char); unsigned long blk_size; void *(*malloc_func)(unsigned long); void *(*realloc_func)(void *, unsigned long); void (*free_func)(void *); } parser; }


decompiled_code:
void __fastcall cbuf_free(__int64 a1)
{
if ( a1 )
free((void *)(a1 - 16));
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( a1 )
free((void *)(a1 - 16));
}

original_code:
void cbuf_free(cbuf buf) {
 if(buf == ((void *)0)) return;
 free(buf-sizeof(cbufhdr));
}

canonical_original_code:
void cbuf_free(char *buf) {
 if(buf == ((void *)0)) return;
 free(buf-sizeof(cbufhdr));
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall cbuf_size(__int64 a1)
{
return *(_QWORD *)(a1 - 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 - 16);
}

original_code:
size_t cbuf_size(cbuf buf) {
 cbufhdr *ch = (cbufhdr*)(buf-sizeof(cbufhdr));
 return ch->size;
}

canonical_original_code:
unsigned long cbuf_size(char *buf) {
 struct _cbufhdr *ch = (cbufhdr*)(buf-sizeof(cbufhdr));
 return ch->size;
}

variable_types: struct _cbufhdr { unsigned long size; unsigned long pos; char buf[]; } *

return_type: unsigned long


decompiled_code:
void *__fastcall cbuf_dup(void *src, size_t *a2)
{
size_t v2; // r12
void *v3; // rax

if ( !src )
return 0LL;
v2 = *((_QWORD *)src - 1);
v3 = malloc(v2);
*a2 = v2;
return memcpy(v3, src, *((_QWORD *)src - 1));
}

canonical_decompiled_code:
void *__fastcall func2(void *src, size_t *a2)
{
size_t v2; // r12
void *v3; // rax

if ( !src )
return 0LL;
v2 = *((_QWORD *)src - 1);
v3 = malloc(v2);
*a2 = v2;
return memcpy(v3, src, *((_QWORD *)src - 1));
}

original_code:
char *cbuf_dup(cbuf buf, size_t *size) {
 if(!buf) return ((void *)0);
 char *ret = (char*)malloc((((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos));
 *size = (((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos);
 memcpy(ret, buf, (((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos));
 return ret;
}

canonical_original_code:
char *cbuf_dup(char *buf, unsigned long *size) {
 if(!buf) return ((void *)0);
 char *ret = (char*)malloc((((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos));
 *size = (((struct _cbufhdr *)(buf-(sizeof(cbufhdr))))->pos);
 memcpy(ret, buf, (((struct _cbufhdr *)(buf-(sizeof(cbufhdr))))->pos));
 return ret;
}

variable_types:
size
unsigned long *

variable_types:
ret
char *

return_type: char *


decompiled_code:
void *__fastcall cbuf_duplen(void *src, size_t *a2)
{
size_t v2; // r12
size_t v3; // rax
void *v4; // rax

if ( !src )
return 0LL;
v2 = *a2;
v3 = *((_QWORD *)src - 1);
if ( *a2 > v3 )
{
*a2 = v3;
v2 = v3;
}
v4 = malloc(v2);
return memcpy(v4, src, v2);
}

canonical_decompiled_code:
void *__fastcall func3(void *src, size_t *a2)
{
size_t v2; // r12
size_t v3; // rax
void *v4; // rax

if ( !src )
return 0LL;
v2 = *a2;
v3 = *((_QWORD *)src - 1);
if ( *a2 > v3 )
{
*a2 = v3;
v2 = v3;
}
v4 = malloc(v2);
return memcpy(v4, src, v2);
}

original_code:
char *cbuf_duplen(cbuf buf, size_t *len) {
    if(!buf) return ((void *)0);
    if(*len > (((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos)) {
        *len = (((cbufhdr*)(buf-(sizeof(cbufhdr))))->pos);
    }
    char *ret = (char*)malloc(*len);
    memcpy(ret, buf, *len);
    return ret;
}

canonical_original_code:
char *cbuf_duplen(char *buf, unsigned long *len) {
    if(!buf) return ((void *)0);
    if(*len > (((struct _cbufhdr *)(buf-(sizeof(cbufhdr))))->pos)) {
        *len = (((struct _cbufhdr *)(buf-(sizeof(cbufhdr))))->pos);
    }
    char *ret = (char*)malloc(*len);
    memcpy(ret, buf, *len);
    return ret;
}

variable_types:
len
unsigned long *


decompiled_code:
__int64 __fastcall fq_init(__int64 a1, int a2)
{
__int64 v3; // rdi
unsigned int v4; // er12
unsigned int v6; // er12

if ( !a1 )
return 22LL;
*(_QWORD *)a1 = 0LL;
v3 = a1 + 8;
*(_QWORD *)(v3 + 152) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 168) >> 3));
*(_DWORD *)(a1 + 24) = a2;
v4 = pthread_cond_init((pthread_cond_t *)(a1 + 120), 0LL);
if ( v4 )
return v4;
v6 = pthread_cond_init((pthread_cond_t *)(a1 + 72), 0LL);
if ( !v6 )
{
v4 = pthread_mutex_init((pthread_mutex_t *)(a1 + 32), 0LL);
if ( v4 )
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
pthread_cond_destroy((pthread_cond_t *)(a1 + 72));
}
return v4;
}
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // rdi
unsigned int v4; // er12
unsigned int v6; // er12

if ( !a1 )
return 22LL;
*(_QWORD *)a1 = 0LL;
v3 = a1 + 8;
*(_QWORD *)(v3 + 152) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 168) >> 3));
*(_DWORD *)(a1 + 24) = a2;
v4 = pthread_cond_init((pthread_cond_t *)(a1 + 120), 0LL);
if ( v4 )
return v4;
v6 = pthread_cond_init((pthread_cond_t *)(a1 + 72), 0LL);
if ( !v6 )
{
v4 = pthread_mutex_init((pthread_mutex_t *)(a1 + 32), 0LL);
if ( v4 )
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
pthread_cond_destroy((pthread_cond_t *)(a1 + 72));
}
return v4;
}
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
return v6;
}

original_code:
int fq_init(fqueue *queue, size_t max_len) {
    int ret = 0;
    if(queue == ((void *)0)) {
        return 22;
    }
    memset(queue, 0, sizeof(fqueue));
    queue->max_len = max_len;
    if((ret = pthread_cond_init(&queue->empty, ((void *)0)))) {
        return ret;
    }
    if((ret = pthread_cond_init(&queue->full, ((void *)0)))) {
        pthread_cond_destroy(&queue->empty);
        return ret;
    }
    if((ret = pthread_mutex_init(&queue->mutex, ((void *)0)))) {
        pthread_cond_destroy(&queue->empty);
        pthread_cond_destroy(&queue->full);
        return ret;
    }
    return 0;
}

canonical_original_code:
int fq_init(struct _fqueue *queue, unsigned long max_len) {
    int ret = 0;
    if(queue == ((void *)0)) {
        return 22;
    }
    memset(queue, 0, sizeof(fqueue));
    queue->max_len = max_len;
    if((ret = pthread_cond_init(&queue->empty, ((void *)0)))) {
        return ret;
    }
    if((ret = pthread_cond_init(&queue->full, ((void *)0)))) {
        pthread_cond_destroy(&queue->empty);
        return ret;
    }
    if((ret = pthread_mutex_init(&queue->mutex, ((void *)0)))) {
        pthread_cond_destroy(&queue->empty);
        pthread_cond_destroy(&queue->full);
        return ret;
    }
    return 0;
}

variable_types: struct _fqueue { struct queue_item { void *data; struct queue_item *next; } *items; struct queue_item *first; unsigned int max_len; unsigned int len; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } full; union pthread_cond_t empty; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall fq_add(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r12
int i; // ebp
_QWORD *v4; // rax
__int64 v5; // rdx

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
for ( i = *(_DWORD *)(a1 + 28); i == *(_DWORD *)(a1 + 24); i = *(_DWORD *)(a1 + 28) )
pthread_cond_wait((pthread_cond_t *)(a1 + 72), v2);
v4 = malloc(0x10uLL);
v5 = *(_QWORD *)(a1 + 16);
*v4 = a2;
v4[1] = 0LL;
if ( v5 )
{
*(_QWORD *)(v5 + 8) = v4;
*(_QWORD *)(a1 + 16) = v4;
}
else
{
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 8) = v4;
}
if ( !i )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 120));
++*(_DWORD *)(a1 + 28);
pthread_mutex_unlock(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r12
int i; // ebp
_QWORD *v4; // rax
__int64 v5; // rdx

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
for ( i = *(_DWORD *)(a1 + 28); i == *(_DWORD *)(a1 + 24); i = *(_DWORD *)(a1 + 28) )
pthread_cond_wait((pthread_cond_t *)(a1 + 72), v2);
v4 = malloc(0x10uLL);
v5 = *(_QWORD *)(a1 + 16);
*v4 = a2;
v4[1] = 0LL;
if ( v5 )
{
*(_QWORD *)(v5 + 8) = v4;
*(_QWORD *)(a1 + 16) = v4;
}
else
{
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 8) = v4;
}
if ( !i )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 120));
++*(_DWORD *)(a1 + 28);
pthread_mutex_unlock(v2);
return 0LL;
}

original_code:
int fq_add(fqueue *queue, void *data) {
    struct queue_item *item;
    pthread_mutex_lock(&queue->mutex);
    while(queue->len == queue->max_len) {
        pthread_cond_wait(&queue->full, &queue->mutex);
    }
    item = malloc(sizeof(struct queue_item));
    item->data = data;
    item->next = ((void *)0);
    if(queue->last == ((void *)0)) {
        queue->last = item;
        queue->first = item;
    } else {
        queue->last->next = item;
        queue->last = item;
    }
    if(queue->len == 0) {
        pthread_cond_broadcast(&queue->empty);
    }
    queue->len++;
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int fq_add(struct _fqueue *queue, void *data) {
    struct queue_item *item;
    pthread_mutex_lock(&queue->mutex);
    while(queue->len == queue->max_len) {
        pthread_cond_wait(&queue->full, &queue->mutex);
    }
    item = malloc(sizeof(struct queue_item));
    item->data = data;
    item->next = ((void *)0);
    if(queue->last == ((void *)0)) {
        queue->last = item;
        queue->first = item;
    } else {
        queue->last->next = item;
        queue->last = item;
    }
    if(queue->len == 0) {
        pthread_cond_broadcast(&queue->empty);
    }
    queue->len++;
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types:
data
void *

variable_types: struct queue_item { void *data; struct queue_item *next; } *


original_code:
int fq_get(fqueue *queue, void **data) {
    if(queue == ((void *)0)) {
        return 22;
    }
    pthread_mutex_lock(&queue->mutex);
    while(queue->first == ((void *)0)) {
        pthread_cond_wait(&queue->empty, &queue->mutex);
    }
    if(queue->first->data) {
     *data = queue->first->data;
     struct queue_item *tmp = queue->first;
     queue->first = queue->first->next;
     queue->len--;
     free(tmp);
     if(queue->first == ((void *)0)) {
      queue->last = ((void *)0);
      queue->len = 0;
     }
    } else {
        *data = ((void *)0);
    }
    if(queue->len == queue->max_len - 1) {
     pthread_cond_broadcast(&queue->full);
    }
    pthread_mutex_unlock(&queue->mutex);
    return *data == ((void *)0);
}

canonical_original_code:
int fq_get(struct _fqueue *queue, void **data) {
    if(queue == ((void *)0)) {
        return 22;
    }
    pthread_mutex_lock(&queue->mutex);
    while(queue->first == ((void *)0)) {
        pthread_cond_wait(&queue->empty, &queue->mutex);
    }
    if(queue->first->data) {
     *data = queue->first->data;
     struct queue_item *tmp = queue->first;
     queue->first = queue->first->next;
     queue->len--;
     free(tmp);
     if(queue->first == ((void *)0)) {
      queue->last = ((void *)0);
      queue->len = 0;
     }
    } else {
        *data = ((void *)0);
    }
    if(queue->len == queue->max_len - 1) {
     pthread_cond_broadcast(&queue->full);
    }
    pthread_mutex_unlock(&queue->mutex);
    return *data == ((void *)0);
}

variable_types:
data
void **


decompiled_code:
__int64 __fastcall fq_fin(__int64 a1)
{
return fq_add(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func1(a1, 0LL);
}

original_code:
int fq_fin(fqueue *queue) {
    return fq_add(queue, ((void *)0));
}

canonical_original_code:
int fq_fin(struct _fqueue *queue) {
    return fq_add(queue, ((void *)0));
}


decompiled_code:
__int64 __fastcall fq_free(__int64 a1)
{
pthread_mutex_t *v1; // r12
_QWORD *v3; // rbx
void *v4; // rdi

if ( !a1 )
return 22LL;
v1 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = *(_QWORD **)(a1 + 8);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
pthread_mutex_unlock(v1);
pthread_mutex_destroy(v1);
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
pthread_cond_destroy((pthread_cond_t *)(a1 + 72));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
pthread_mutex_t *v1; // r12
_QWORD *v3; // rbx
void *v4; // rdi

if ( !a1 )
return 22LL;
v1 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = *(_QWORD **)(a1 + 8);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
pthread_mutex_unlock(v1);
pthread_mutex_destroy(v1);
pthread_cond_destroy((pthread_cond_t *)(a1 + 120));
pthread_cond_destroy((pthread_cond_t *)(a1 + 72));
return 0LL;
}

original_code:
int fq_free(fqueue *queue) {
    if(queue == ((void *)0)) {
        return 22;
    }
    pthread_mutex_lock(&queue->mutex);
    struct queue_item *cur = queue->first, *next;
    while(cur) {
        next = cur->next;
        free(cur);
        cur = next;
    }
    pthread_mutex_unlock(&queue->mutex);
    pthread_mutex_destroy(&queue->mutex);
    pthread_cond_destroy(&queue->empty);
    pthread_cond_destroy(&queue->full);
    return 0;
}

canonical_original_code:
int fq_free(struct _fqueue *queue) {
    if(queue == ((void *)0)) {
        return 22;
    }
    pthread_mutex_lock(&queue->mutex);
    struct queue_item *cur = queue->first; struct queue_item *next;
    while(cur) {
        next = cur->next;
        free(cur);
        cur = next;
    }
    pthread_mutex_unlock(&queue->mutex);
    pthread_mutex_destroy(&queue->mutex);
    pthread_cond_destroy(&queue->empty);
    pthread_cond_destroy(&queue->full);
    return 0;
}


ChckPreIndex

repo: PerseusDL/morpheus

decompiled_code:
__int64 __fastcall ChckPreIndex(__int64 a1, const char *a2, unsigned int a3, unsigned int a4, __int64 a5)
{
int v8; // eax
__int64 v9; // r8
char dest[49]; // [rsp+7h] [rbp-31h] BYREF

if ( (int)Xstrlen(a2) > 8 )
a4 = 0;
strncpy(dest, a2, 8uLL);
dest[8] = 0;
v8 = binlook(a1, dest, a3, 24LL, a4, a5);
if ( v8 < 0 )
return -1LL;
v9 = 0LL;
if ( !v8 )
return v9;
return *(_QWORD *)(a1 + 24LL * v8 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, unsigned int a3, unsigned int a4, __int64 a5)
{
int v8; // eax
__int64 v9; // r8
char dest[49]; // [rsp+7h] [rbp-31h] BYREF

if ( (int)Xstrlen(a2) > 8 )
a4 = 0;
strncpy(dest, a2, 8uLL);
dest[8] = 0;
v8 = binlook(a1, dest, a3, 24LL, a4, a5);
if ( v8 < 0 )
return -1LL;
v9 = 0LL;
if ( !v8 )
return v9;
return *(_QWORD *)(a1 + 24LL * v8 + 16);
}

original_code:
long
ChckPreIndex(endtags *etags, char *tag, int ntags, int exact_match, int (*scmp )())
{
 int rval;
 long roff;
 char curtag[8 +1];
 if( Xstrlen(tag) > 8 ) exact_match = 0;
 strncpy(curtag,tag,8);
 curtag[8] = 0;
 rval = binlook( (char *)etags , curtag , ntags , (int)sizeof *etags , exact_match ,scmp );
 if( rval < 0 )
  return((long) -1 );
 if( ! rval )
  roff = 0;
 else
  roff = (etags+rval)->tagoffset;
return( roff );
}

canonical_original_code:
long ChckPreIndex(struct endtags *etags, char *tag, int ntags, int exact_match, int (*scmp)())
{
 int rval;
 long roff;
 char curtag[-1];
 if( Xstrlen(tag) > 8 ) exact_match = 0;
 strncpy(curtag,tag,8);
 curtag[8] = 0;
 rval = binlook( (char *)etags , curtag , ntags , (int)sizeof *etags , exact_match ,scmp );
 if( rval < 0 )
  return((long) -1 );
 if( ! rval )
  roff = 0;
 else
  roff = (etags+rval)->tagoffset;
return( roff );
}

variable_types: struct endtags { char tagstring[-1]; long tagoffset; } *

variable_types:
tag
char *

variable_types: ntags int

variable_types:
scmp
int (*)()

variable_types: rval int

variable_types: roff long

variable_types:
curtag
char [-1]

return_type: long


decompiled_code:
__int64 __fastcall new_person(__int64 a1, char a2)
{
__int64 result; // rax

result = 8 * (a2 & 7u);
*(_BYTE *)(a1 + 1) = (8 * (a2 & 7)) | *(_BYTE *)(a1 + 1) & 0xC7;
return result;
}

original_code:
void
new_person(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_person = (val);
}

canonical_original_code:
void new_person(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_person = (val);
}

variable_types: struct gk_string { struct word_form { unsigned int f_voice; unsigned int f_mood; unsigned int f_tense; unsigned int f_person; unsigned int f_number; unsigned int f_case; unsigned int f_degree; unsigned int f_gender; } gs_forminfo; unsigned int gs_steminfo; unsigned int gs_derivtype; short gs_dialect; unsigned int gs_geogregion; unsigned char gs_morphflags[12]; char st_domains[-1]; char gs_gkstring[60]; } *

variable_types:
val
unsigned long

user_defined_types: struct gk_string { struct word_form gs_forminfo; unsigned int gs_steminfo; unsigned int gs_derivtype; short gs_dialect; unsigned int gs_geogregion; unsigned char gs_morphflags[12]; char st_domains[-1]; char gs_gkstring[60]; }


decompiled_code:
__int64 __fastcall new_number(_DWORD *a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)(a2 & 7) << 14;
*a1 = result | *a1 & 0xFFFE3FFF;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)(a2 & 7) << 14;
*a1 = result | *a1 & 0xFFFE3FFF;
return result;
}

original_code:
void
new_number(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_number = (val);
}

canonical_original_code:
void new_number(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_number = (val);
}

user_defined_types: struct word_form { unsigned int f_voice; unsigned int f_mood; unsigned int f_tense; unsigned int f_person; unsigned int f_number; unsigned int f_case; unsigned int f_degree; unsigned int f_gender; }


original_code:
void
new_case(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_case |= val;
}

canonical_original_code:
void new_case(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_case |= val;
}


decompiled_code:
__int64 __fastcall new_tense(_WORD *a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)(a2 & 0xF) << 7;
*a1 = ((a2 & 0xF) << 7) | *a1 & 0xF87F;
return result;
}

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

result = (unsigned __int8)(a2 & 0xF) << 7;
*a1 = ((a2 & 0xF) << 7) | *a1 & 0xF87F;
return result;
}

original_code:
void
new_tense(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_tense = (val);
}

canonical_original_code:
void new_tense(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_tense = (val);
}


decompiled_code:
__int64 __fastcall new_mood(_BYTE *a1, char a2)
{
__int64 result; // rax

result = 8 * (a2 & 0xFu);
*a1 = (8 * (a2 & 0xF)) | *a1 & 0x87;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, char a2)
{
__int64 result; // rax

result = 8 * (a2 & 0xFu);
*a1 = (8 * (a2 & 0xF)) | *a1 & 0x87;
return result;
}

original_code:
void
new_mood(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_mood = (val);
}

canonical_original_code:
void new_mood(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_mood = (val);
}


decompiled_code:
__int64 __fastcall new_degree(__int64 a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)(a2 & 3) << 7;
*(_WORD *)(a1 + 2) = ((a2 & 3) << 7) | *(_WORD *)(a1 + 2) & 0xFE7F;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)(a2 & 3) << 7;
*(_WORD *)(a1 + 2) = ((a2 & 3) << 7) | *(_WORD *)(a1 + 2) & 0xFE7F;
return result;
}

original_code:
void
new_degree(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_degree = (val);
}

canonical_original_code:
void new_degree(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_degree = (val);
}


original_code:
void
new_gender(gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_gender |= val;
}

canonical_original_code:
void new_gender(struct gk_string *gstr, unsigned long val)
{
  ((gstr)->gs_forminfo).f_gender |= val;
}


decompiled_code:
void __fastcall new_dialect(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 12) |= a2;
}

original_code:
void
new_dialect(gk_string *gstr, unsigned long val)
{
  (gstr)->gs_dialect |= (Dialect)val;
}

canonical_original_code:
void new_dialect(struct gk_string *gstr, unsigned long val)
{
  (gstr)->gs_dialect |= (short)val;
}


decompiled_code:
void __fastcall new_region(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) |= a2;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) |= a2;
}

original_code:
void
new_region(gk_string *gstr, unsigned long val)
{
  (gstr)->gs_geogregion |= (GeogRegion)val;
}

canonical_original_code:
void new_region(struct gk_string *gstr, unsigned long val)
{
  (gstr)->gs_geogregion |= (unsigned int)val;
}


decompiled_code:
__int64 __fastcall new_morphflags(__int64 a1)
{
return add_morphflag(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return add_morphflag(a1 + 20);
}

original_code:
void
new_morphflags(gk_string *gstr, unsigned long val)
{
  add_morphflag((gstr)->gs_morphflags,(int)val);
}

canonical_original_code:
void new_morphflags(struct gk_string *gstr, unsigned long val)
{
  add_morphflag((gstr)->gs_morphflags,(int)val);
}


decompiled_code:
void __fastcall new_stemtype(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) = a2;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) = a2;
}

original_code:
void
new_stemtype(gk_string *gstr, unsigned long val)
{
  (gstr)->gs_steminfo = (Stemtype)val;
}

canonical_original_code:
void new_stemtype(struct gk_string *gstr, unsigned long val)
{
  (gstr)->gs_steminfo = (unsigned int)val;
}


decompiled_code:
__int64 new_domain()
{
return add_domain();
}

canonical_decompiled_code:
__int64 func12()
{
return add_domain();
}

original_code:
void
new_domain(gk_string *gstr, unsigned long val)
{
  add_domain(gstr,(int)val);
}

canonical_original_code:
void new_domain(struct gk_string *gstr, unsigned long val)
{
  add_domain(gstr,(int)val);
}


decompiled_code:
void __fastcall new_derivtype(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

original_code:
void
new_derivtype(gk_string *gstr, unsigned long val)
{
  (gstr)->gs_derivtype = (Derivtype)val;
}

canonical_original_code:
void new_derivtype(struct gk_string *gstr, unsigned long val)
{
  (gstr)->gs_derivtype = (unsigned int)val;
}


parsefield

decompiled_code:
const char *__fastcall parsefield(const char *a1, char *a2, int a3, int a4)
{
const char *v6; // r12
char *v7; // rbp
char v8; // bl
const unsigned __int16 **v9; // r13
__int64 v10; // rcx
const char *v11; // r12
unsigned int v13; // eax
__int64 i; // rax

v6 = a1;
v7 = a2;
*a2 = 0;
v8 = *a1;
v9 = _ctype_b_loc();
if ( v8 )
{
while ( v8 != a3 && ((*v9)[v8] & 0x2000) == 0 )
{
++v6;
*v7++ = v8;
if ( a4 <= ~(_DWORD)a1 + (int)v6 )
{
v13 = Xstrlen(v6);
fprintf(stderr, "Hey %d chars; %d s [%s] left!\n", (unsigned int)a4, v13, v6);
*v7 = 0;
for ( i = *v6; (_BYTE)i; i = *++v6 )
{
if ( ((*v9)[i] & 0x2000) != 0 )
break;
}
break;
}
v8 = *v6;
if ( !*v6 )
break;
}
}
*v7 = 0;
v10 = *v6;
if ( ((*v9)[v10] & 0x2000) != 0 )
v11 = (const char *)&unk_8A0;
else
v11 = &v6[-((_BYTE)v10 == 0) + 1];
return v11;
}

original_code:
char *
parsefield(char *s, char *buf, int c, int len)
{
 int i;
 *buf = 0;
 for(i=0;*s&&*s!=c&&!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace);i++) {
  *buf++ = *s++;
  if( i >= len ) {
   fprintf(stderr,"Hey %d chars; %d s [%s] left!\n", len , Xstrlen(s) ,s );
   *buf = 0;
   while(*s&&!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace)) s++;
   break;
  }
 }
 *buf = 0;
 if( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) ) return("");
 if(*s) s++;
 return(s);
}

canonical_original_code:
char *parsefield(char *s, char *buf, int c, int len)
{
 int i;
 *buf = 0;
 for(i=0;*s&&*s!=c&&!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace);i++) {
  *buf++ = *s++;
  if( i >= len ) {
   fprintf(stderr,"Hey %d chars; %d s [%s] left!\n", len , Xstrlen(s) ,s );
   *buf = 0;
   while(*s&&!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace)) s++;
   break;
  }
 }
 *buf = 0;
 if( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) ) return("");
 if(*s) s++;
 return(s);
}

variable_types:
s
char *

variable_types:
buf
char *

variable_types: c int

variable_types: len int

variable_types: i int


comstemtypes

decompiled_code:
_BOOL8 __fastcall comstemtypes(__int64 a1, const char *a2)
{
bool v2; // zf
const char *v3; // rbx
const unsigned __int16 **v4; // r13
const unsigned __int16 *v5; // rcx
__int64 v6; // rax
__int16 v7; // dx
__int64 v8; // rdx
char v10[64]; // [rsp+0h] [rbp-CB8h] BYREF
char v11[64]; // [rsp+40h] [rbp-C78h] BYREF
char v12[1024]; // [rsp+80h] [rbp-C38h] BYREF
char v13[1024]; // [rsp+480h] [rbp-838h] BYREF
char v14[1080]; // [rsp+880h] [rbp-438h] BYREF

v2 = *a2 == 0;
v12[0] = 0;
v14[0] = 0;
if ( !v2 )
{
v3 = a2;
v4 = _ctype_b_loc();
do
{
setstemvars(v3, v10, v11, v13, v14);
if ( wantcurstemtype() )
{
if ( v12[0] )
Xstrncat(v12, &unk_8A1, 1024LL);
Xstrncat(v12, v11, 1024LL);
Xstrncat(v12, &unk_8A3, 1024LL);
if ( v10[0] )
Xstrncat(v12, v10, 1024LL);
else
Xstrncat(v12, a1, 1024LL);
Xstrncat(v12, &unk_8A3, 1024LL);
Xstrncat(v12, v13, 1024LL);
Xstrncat(v12, &unk_8A3, 1024LL);
if ( v14[0] )
Xstrncat(v12, v14, 1024LL);
}
v5 = *v4;
while ( 1 )
{
v6 = *v3;
v7 = v5[v6] & 0x2000;
if ( !(_BYTE)v6 )
break;
if ( v7 )
goto LABEL_15;
++v3;
}
if ( !v7 )
continue;
do
{
LABEL_15:
v8 = *++v3;
LOBYTE(v6) = v8;
}
while ( (v5[v8] & 0x2000) != 0 );
}
while ( (_BYTE)v6 );
}
Xstrncpy(a2, v12, 1024LL);
return *a2 != 0;
}

original_code:
int
comstemtypes(char *stem, char *stemkeys, char *endkeys)
{
 register char * s, *p;
 char tmp[1024];
 char cstemtype[1024];
 char cstem[60];
 char clemma[60];
 char stembuf[1024];
 s = stemkeys;
 p = tmp;
 stembuf[0] = tmp[0] = 0;
 while(*s) {
  setstemvars(s,cstem,clemma,cstemtype,stembuf);
  if( wantcurstemtype(cstemtype,endkeys) ) {
   if( tmp[0] ) Xstrncat(tmp," ",(int)1024);
   Xstrncat(tmp,clemma,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   if( cstem[0] ) Xstrncat(tmp,cstem,(int)1024);
   else Xstrncat(tmp,stem,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   Xstrncat(tmp,cstemtype,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   if(*stembuf)
    Xstrncat(tmp,stembuf,(int)1024);
  }
  while(! ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) && *s ) s++;
  while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) ) s++;
 }
 Xstrncpy((char *)stemkeys,(char *)p,(size_t)1024);
 if( *stemkeys )
  return(1);
 else
  return(0);
}

canonical_original_code:
int comstemtypes(char *stem, char *stemkeys, char *endkeys)
{
 register char *s; register char *p;
 char tmp[1024];
 char cstemtype[1024];
 char cstem[60];
 char clemma[60];
 char stembuf[1024];
 s = stemkeys;
 p = tmp;
 stembuf[0] = tmp[0] = 0;
 while(*s) {
  setstemvars(s,cstem,clemma,cstemtype,stembuf);
  if( wantcurstemtype(cstemtype,endkeys) ) {
   if( tmp[0] ) Xstrncat(tmp," ",(int)1024);
   Xstrncat(tmp,clemma,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   if( cstem[0] ) Xstrncat(tmp,cstem,(int)1024);
   else Xstrncat(tmp,stem,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   Xstrncat(tmp,cstemtype,(int)1024);
   Xstrncat(tmp,":",(int)1024);
   if(*stembuf)
    Xstrncat(tmp,stembuf,(int)1024);
  }
  while(! ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) && *s ) s++;
  while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) ) s++;
 }
 Xstrncpy((char *)stemkeys,(char *)p,(unsigned long)1024);
 if( *stemkeys )
  return(1);
 else
  return(0);
}

variable_types:
stem
char *

variable_types:
stemkeys
char *

variable_types:
endkeys
char *

variable_types:
p
char *

variable_types:
tmp
char [1024]

variable_types:
cstemtype
char [1024]

variable_types:
cstem
char [60]

variable_types:
clemma
char [60]

variable_types:
stembuf
char [1024]


getsyll

decompiled_code:
__int64 __fastcall getsyll(unsigned __int64 a1, unsigned int a2)
{
_BYTE *v3; // r12
__int64 v4; // r14
int v5; // ebx

if ( a2 > 2 )
return -1LL;
v3 = (_BYTE *)(a1 + (int)Xstrlen() - 1);
if ( a1 > (unsigned __int64)v3 )
return -1LL;
v4 = 0x50419100504191LL;
v5 = 0;
while ( 1 )
{
if ( (unsigned __int8)(*v3 - 65) > 0x36u || !_bittest64(&v4, (unsigned int)(unsigned __int8)*v3 - 65) )
goto LABEL_6;
if ( a2 == v5 )
return (__int64)v3;
v5 += is_diphth(v3, a1) == 0;
LABEL_6:
if ( a1 > (unsigned __int64)--v3 )
return -1LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, unsigned int a2)
{
_BYTE *v3; // r12
__int64 v4; // r14
int v5; // ebx

if ( a2 > 2 )
return -1LL;
v3 = (_BYTE *)(a1 + (int)Xstrlen() - 1);
if ( a1 > (unsigned __int64)v3 )
return -1LL;
v4 = 0x50419100504191LL;
v5 = 0;
while ( 1 )
{
if ( (unsigned __int8)(*v3 - 65) > 0x36u || !_bittest64(&v4, (unsigned int)(unsigned __int8)*v3 - 65) )
goto LABEL_6;
if ( a2 == v5 )
return (__int64)v3;
v5 += is_diphth(v3, a1) == 0;
LABEL_6:
if ( a1 > (unsigned __int64)--v3 )
return -1LL;
}
}

variable_types:
word
char *

variable_types: syll int

variable_types: syllcount int


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

if ( !(unsigned int)nsylls() )
return a1;
v3 = getsyll(a1, a2);
if ( v3 == -1 )
result = -1LL;
else
result = ((unsigned int)is_diphth(v3, a1) == 0) + v3 - 1;
return result;
}

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

if ( !(unsigned int)nsylls() )
return a1;
v3 = func0(a1, a2);
if ( v3 == -1 )
result = -1LL;
else
result = ((unsigned int)is_diphth(v3, a1) == 0) + v3 - 1;
return result;
}

original_code:
char *getsyll2(char *word, int syll)
{
 char * p;
 if( nsylls(word) == 0 ) return(word);
 p = getsyll(word,syll);
 if( p == (char *) -1 ) return(p);
 if( is_diphth(p,word) )
  return(p-1);
 else
  return(p);
}

canonical_original_code:
char *getsyll2(char *word, int syll)
{
 char *p;
 if( nsylls(word) == 0 ) return(word);
 p = getsyll(word,syll);
 if( p == (char *) -1 ) return(p);
 if( is_diphth(p,word) )
  return(p-1);
 else
  return(p);
}


decompiled_code:
__int64 __fastcall load_ccontr(__int64 a1)
{
return load_euph_tab("rule_files/conseuph.table", a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return load_euph_tab("rule_files/conseuph.table", a1, 1LL);
}

original_code:
gk_string *
load_ccontr(int *gotno)
{
 return(load_euph_tab("rule_files/conseuph.table",gotno,1));
}

canonical_original_code:
struct gk_string *load_ccontr(int *gotno)
{
 return(load_euph_tab("rule_files/conseuph.table",gotno,1));
}

variable_types:
gotno
int *

return_type: struct gk_string { struct word_form { unsigned int f_voice; unsigned int f_mood; unsigned int f_tense; unsigned int f_person; unsigned int f_number; unsigned int f_case; unsigned int f_degree; unsigned int f_gender; } gs_forminfo; unsigned int gs_steminfo; unsigned int gs_derivtype; short gs_dialect; unsigned int gs_geogregion; unsigned char gs_morphflags[12]; char st_domains[-1]; char gs_gkstring[60]; } *


decompiled_code:
__int64 __fastcall load_vcontr(__int64 a1)
{
return load_euph_tab("rule_files/vowcontr.table", a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return load_euph_tab("rule_files/vowcontr.table", a1, 1LL);
}

original_code:
gk_string *
load_vcontr(int *gotno)
{
 return(load_euph_tab("rule_files/vowcontr.table",gotno,1));
}

canonical_original_code:
struct gk_string *load_vcontr(int *gotno)
{
 return(load_euph_tab("rule_files/vowcontr.table",gotno,1));
}


decompiled_code:
__int64 init_dict()
{
if ( Use_hqdict )
{
vbindex = "hqdict/indices/stindex";
nomindex = "hqdict/indices/stindex";
}
return init_preind();
}

canonical_decompiled_code:
__int64 func0()
{
if ( Use_hqdict )
{
vbindex = "hqdict/indices/stindex";
nomindex = "hqdict/indices/stindex";
}
return init_preind();
}

original_code:
endtags *
init_dict(char *fname, int *ntags)
{
 if( Use_hqdict ) {
  fname = "hqdict/indices/stindex";
  vbindex = "hqdict/indices/stindex";
  nomindex = "hqdict/indices/stindex";
 }
 return(init_preind(fname,ntags));
}

canonical_original_code:
struct endtags *init_dict(char *fname, int *ntags)
{
 if( Use_hqdict ) {
  fname = "hqdict/indices/stindex";
  vbindex = "hqdict/indices/stindex";
  nomindex = "hqdict/indices/stindex";
 }
 return(init_preind(fname,ntags));
}

variable_types:
fname
char *

variable_types:
ntags
int *

return_type: struct endtags { char tagstring[-1]; long tagoffset; } *


getaccp

decompiled_code:
__int64 getaccp()
{
__int64 v0; // rax
__int64 v1; // r8
char v2; // al

v0 = getsyll();
if ( v0 == -1 )
return -1LL;
v1 = v0 + 1;
v2 = *(_BYTE *)(v0 + 1);
if ( (unsigned __int8)(v2 - 40) > 1u )
goto LABEL_4;
do
{
do
v2 = *(_BYTE *)++v1;
while ( (unsigned __int8)(v2 - 40) <= 1u );
LABEL_4:
;
}
while ( (unsigned __int8)(v2 - 94) <= 1u );
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // r8
char v2; // al

v0 = getsyll();
if ( v0 == -1 )
return -1LL;
v1 = v0 + 1;
v2 = *(_BYTE *)(v0 + 1);
if ( (unsigned __int8)(v2 - 40) > 1u )
goto LABEL_4;
do
{
do
v2 = *(_BYTE *)++v1;
while ( (unsigned __int8)(v2 - 40) <= 1u );
LABEL_4:
;
}
while ( (unsigned __int8)(v2 - 94) <= 1u );
return v1;
}


decompiled_code:
__int64 __fastcall skip_to_syll(__int64 a1)
{
if ( (int)nsylls(a1) > 3 || (unsigned int)nsylls(a1) == 1 )
return a1;
if ( (unsigned int)nsylls(a1) != 3 )
{
if ( (unsigned int)nsylls(a1) == 2 )
return getsyll2(a1, 0LL);
return a1;
}
return getsyll2(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( (int)nsylls(a1) > 3 || (unsigned int)nsylls(a1) == 1 )
return a1;
if ( (unsigned int)nsylls(a1) != 3 )
{
if ( (unsigned int)nsylls(a1) == 2 )
return getsyll2(a1, 0LL);
return a1;
}
return getsyll2(a1, 1LL);
}

original_code:
char *
skip_to_syll(char *s, int nsyll)
{
 if( nsylls(s) > 3 || nsylls(s) == 1) {
  return(s);
 } else if( nsylls(s) == 3 ) {
  return(getsyll2(s,1));
 }
 else if( nsylls(s) == 2 ) {
  return(getsyll2(s,0));
 } else
  return(s);
}

canonical_original_code:
char *skip_to_syll(char *s, int nsyll)
{
 if( nsylls(s) > 3 || nsylls(s) == 1) {
  return(s);
 } else if( nsylls(s) == 3 ) {
  return(getsyll2(s,1));
 }
 else if( nsylls(s) == 2 ) {
  return(getsyll2(s,0));
 } else
  return(s);
}

variable_types:
s
char *

variable_types: nsyll int


variable_types: changed int


decompiled_code:
__int64 __fastcall do_mu(__int64 a1)
{
_BYTE *v1; // rax
int v2; // edx
unsigned int v3; // er8
__int64 result; // rax
__int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rcx

v1 = (_BYTE *)(a1 + (int)Xstrlen(a1) - 1);
v2 = (unsigned __int8)*v1;
if ( (*v1 & 0xFB) == 98 || (_BYTE)v2 == 112 )
{
if ( *(v1 - 1) != 109 )
{
*v1 = 109;
return 1;
}
*v1 = 0;
result = 1LL;
}
else if ( (unsigned __int8)(v2 - 99) <= 0x15u && (v5 = 2097425LL, _bittest64(&v5, (unsigned int)(v2 - 99))) )
{
v3 = 0;
if ( (_BYTE)v2 == 103 )
return v3;
*v1 = 103;
result = 1LL;
}
else
{
v6 = (unsigned int)(v2 - 100);
v3 = 0;
if ( (unsigned __int8)v6 > 0x16u )
return v3;
v7 = 4268033LL;
if ( !_bittest64(&v7, v6) )
return v3;
*v1 = 115;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_BYTE *v1; // rax
int v2; // edx
unsigned int v3; // er8
__int64 result; // rax
__int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rcx

v1 = (_BYTE *)(a1 + (int)Xstrlen(a1) - 1);
v2 = (unsigned __int8)*v1;
if ( (*v1 & 0xFB) == 98 || (_BYTE)v2 == 112 )
{
if ( *(v1 - 1) != 109 )
{
*v1 = 109;
return 1;
}
*v1 = 0;
result = 1LL;
}
else if ( (unsigned __int8)(v2 - 99) <= 0x15u && (v5 = 2097425LL, _bittest64(&v5, (unsigned int)(v2 - 99))) )
{
v3 = 0;
if ( (_BYTE)v2 == 103 )
return v3;
*v1 = 103;
result = 1LL;
}
else
{
v6 = (unsigned int)(v2 - 100);
v3 = 0;
if ( (unsigned __int8)v6 > 0x16u )
return v3;
v7 = 4268033LL;
if ( !_bittest64(&v7, v6) )
return v3;
*v1 = 115;
result = 1LL;
}
return result;
}


getquantity

decompiled_code:
__int64 __fastcall getquantity(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v7; // rax
char v8; // al
__int64 result; // rax

v7 = getsyll();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = *(_BYTE *)(v7 + 1);
if ( (unsigned __int8)(v8 - 94) > 1u )
result = quantprim(a1, a2, a4, a5);
else
result = v8 == 95;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v7; // rax
char v8; // al
__int64 result; // rax

v7 = getsyll();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = *(_BYTE *)(v7 + 1);
if ( (unsigned __int8)(v8 - 94) > 1u )
result = quantprim(a1, a2, a4, a5);
else
result = v8 == 95;
return result;
}

original_code:
int getquantity(char *word, int syll, char *nom, bool is_ending, bool is_oblique)
{
 register char *p;
 p = getsyll(word,syll);
 if (p == (char *) -1)
  return (-1);
 p++;
 if ((((*p)=='_') || ((*p)=='^'))) {
  if ( (*p)=='_')
   return (1);
  else if ( (*p)=='^')
   return (0);
  else {
   if (nom == 0)
    return (0);
   else if (getaccent(nom,1)=='/')
    return (1);
   else
    return (0);
   }
  }
 else
  return (quantprim(word,syll,is_ending,is_oblique));
}

canonical_original_code:
int getquantity(char *word, int syll, char *nom, int is_ending, int is_oblique)
{
 register char *p;
 p = getsyll(word,syll);
 if (p == (char *) -1)
  return (-1);
 p++;
 if ((((*p)=='_') || ((*p)=='^'))) {
  if ( (*p)=='_')
   return (1);
  else if ( (*p)=='^')
   return (0);
  else {
   if (nom == 0)
    return (0);
   else if (getaccent(nom,1)=='/')
    return (1);
   else
    return (0);
   }
  }
 else
  return (quantprim(word,syll,is_ending,is_oblique));
}

variable_types:
nom
char *


getaccent

decompiled_code:
__int64 getaccent()
{
char *v0; // rax
unsigned int v1; // eax
unsigned int v2; // er8

v0 = (char *)getaccp();
if ( v0 == (char *)-1LL )
return (unsigned int)-1;
v1 = *v0;
v2 = 32;
if ( (unsigned __int8)(v1 - 47) <= 0x2Du && ((0x200000004001uLL >> ((unsigned __int8)v1 - 47)) & 1) != 0 )
v2 = v1;
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rax
unsigned int v1; // eax
unsigned int v2; // er8

v0 = (char *)getaccp();
if ( v0 == (char *)-1LL )
return (unsigned int)-1;
v1 = *v0;
v2 = 32;
if ( (unsigned __int8)(v1 - 47) <= 0x2Du && ((0x200000004001uLL >> ((unsigned __int8)v1 - 47)) & 1) != 0 )
v2 = v1;
return v2;
}

original_code:
int getaccent(char *word, int syll)
{
 register char *p;
 p = getaccp(word,syll);
 if (p == (char *) -1)
  return ((char) -1);
 if (((*p)=='/')||((*p)=='\\')||((*p)=='='))
  return (*p);
 return (' ');
}


CheckEndCache

decompiled_code:
__int64 __fastcall CheckEndCache(__int64 a1)
{
__int64 *v1; // rax

cacheconsistent();
v1 = EndingCache;
do
{
if ( !*v1 || *(_DWORD *)(*v1 + 4) == *(_DWORD *)(a1 + 4) )
return *v1;
++v1;
}
while ( v1 != &EndingCache[45] );
return 0LL;
}

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

func0();
v1 = EndingCache;
do
{
if ( !*v1 || *(_DWORD *)(*v1 + 4) == *(_DWORD *)(a1 + 4) )
return *v1;
++v1;
}
while ( v1 != &EndingCache[45] );
return 0LL;
}

original_code:
gk_string *
CheckEndCache(gk_string *gstr)
{
 int i;
cacheconsistent();
 for(i=0;i<45;i++) {
  if(! EndingCache[i] ) break;
  if( (EndingCache[i])->gs_steminfo == (gstr)->gs_steminfo)
   return(EndingCache[i]);
 }
 return(((void *)0));
}

canonical_original_code:
struct gk_string *CheckEndCache(struct gk_string *gstr)
{
 int i;
cacheconsistent();
 for(i=0;i<45;i++) {
  if(! EndingCache[i] ) break;
  if( (EndingCache[i])->gs_steminfo == (gstr)->gs_steminfo)
   return(EndingCache[i]);
 }
 return(((void *)0));
}

variable_types:
gstr
struct gk_string *

variable_types: i int


gkstrlen

decompiled_code:
__int64 __fastcall gkstrlen(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned int v2; // er8
int v3; // eax
__int64 v4; // rcx

v1 = a1;
v2 = Xstrlen();
v3 = *a1;
if ( (_BYTE)v3 == 33 )
{
v3 = a1[1];
--v2;
v1 = a1 + 1;
}
if ( (_BYTE)v3 )
{
v4 = 0x200000004001LL;
while ( (unsigned __int8)(v3 - 47) > 0x2Du )
{
if ( (unsigned __int8)(v3 - 94) > 1u )
goto LABEL_6;
LABEL_9:
v3 = *++v1;
if ( !(_BYTE)v3 )
return v2;
}
if ( !_bittest64(&v4, (unsigned int)(v3 - 47)) )
{
LABEL_6:
if ( (_BYTE)v3 != 124 && (_BYTE)v3 != 43 && (unsigned __int8)(v3 - 40) > 1u )
goto LABEL_9;
}
--v2;
goto LABEL_9;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned int v2; // er8
int v3; // eax
__int64 v4; // rcx

v1 = a1;
v2 = Xstrlen();
v3 = *a1;
if ( (_BYTE)v3 == 33 )
{
v3 = a1[1];
--v2;
v1 = a1 + 1;
}
if ( (_BYTE)v3 )
{
v4 = 0x200000004001LL;
while ( (unsigned __int8)(v3 - 47) > 0x2Du )
{
if ( (unsigned __int8)(v3 - 94) > 1u )
goto LABEL_6;
LABEL_9:
v3 = *++v1;
if ( !(_BYTE)v3 )
return v2;
}
if ( !_bittest64(&v4, (unsigned int)(v3 - 47)) )
{
LABEL_6:
if ( (_BYTE)v3 != 124 && (_BYTE)v3 != 43 && (unsigned __int8)(v3 - 40) > 1u )
goto LABEL_9;
}
--v2;
goto LABEL_9;
}
return v2;
}

variable_types: n int


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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 61 )
*a1 = 95;
++a1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 61 )
*a1 = 95;
++a1;
}
return result;
}

original_code:
void mark_long(char* word)
{
 char* p_pos = word;
 for ( ; *p_pos; p_pos ++)
 {
   if (*p_pos == '=')
     *p_pos = '_';
 }
}

canonical_original_code:
void mark_long(char *word)
{
 char *p_pos = word;
 for ( ; *p_pos; p_pos ++)
 {
   if (*p_pos == '=')
     *p_pos = '_';
 }
}


decompiled_code:
__int64 __fastcall get_all_syllables(unsigned __int64 a1, int a2)
{
__int64 v3; // r13
int v4; // ebx
_BYTE *i; // r12
__int64 v6; // rdi

v3 = 0x50419100504191LL;
v4 = 0;
for ( i = (_BYTE *)(a1 + (int)Xstrlen() - 1); a1 <= (unsigned __int64)i; --i )
{
v6 = (unsigned int)(char)*i;
if ( (unsigned __int8)(*i - 65) <= 0x36u && _bittest64(&v3, (unsigned int)(v6 - 65)) )
{
if ( a2 == v4 )
return (__int64)i;
v4 += is_diphth(v6, a1) == 0;
}
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, int a2)
{
__int64 v3; // r13
int v4; // ebx
_BYTE *i; // r12
__int64 v6; // rdi

v3 = 0x50419100504191LL;
v4 = 0;
for ( i = (_BYTE *)(a1 + (int)Xstrlen() - 1); a1 <= (unsigned __int64)i; --i )
{
v6 = (unsigned int)(char)*i;
if ( (unsigned __int8)(*i - 65) <= 0x36u && _bittest64(&v3, (unsigned int)(v6 - 65)) )
{
if ( a2 == v4 )
return (__int64)i;
v4 += is_diphth(v6, a1) == 0;
}
}
return -1LL;
}

variable_types: which int


decompiled_code:
__int64 __fastcall basic_quantity(__int64 a1, unsigned __int8 *a2)
{
int v3; // ebx
__int64 v4; // rsi
const unsigned __int16 *v5; // rcx
unsigned __int8 *v6; // rax
int v8; // er12
bool v9; // zf
int v10; // eax
unsigned __int64 v11; // rax
__int64 v12; // rdx
int v13; // ebx
__int64 v14; // r14
unsigned __int8 *v15; // rbp
__int64 v16; // r13
unsigned __int64 v17; // rbx
int v18; // ebx
char v19; // al

if ( a2 == (unsigned __int8 *)-1LL )
return 0xFFFFFFFFLL;
v3 = *a2;
if ( !(_BYTE)v3 )
{
LABEL_10:
if ( (unsigned int)long_by_isub(a2) )
return 1LL;
v8 = is_diphth(a2, a1);
if ( v8 )
return 1LL;
v9 = (unsigned int)cur_lang() == 0;
v10 = *a2;
if ( v9 && ((v10 & 0xDF) == 72 || (v10 & 0xDF) == 87) )
return 1LL;
v11 = (unsigned int)(v10 - 65);
if ( (unsigned __int8)v11 > 0x34u )
return 0xFFFFFFFFLL;
v12 = 0x10411100104111LL;
if ( !_bittest64(&v12, v11) )
return 0xFFFFFFFFLL;
v13 = a2[1];
if ( (_BYTE)v13 == 124 )
return 1LL;
if ( !(_BYTE)v13 )
return v8 > 1;
v14 = 0x70439100704391LL;
v15 = a2 + 2;
v16 = 0x10000000200083LL;
while ( 1 )
{
if ( (unsigned __int8)(v13 - 40) <= 0x34u && _bittest64(&v16, (unsigned int)(v13 - 40)) )
goto LABEL_21;
if ( ((*_ctype_b_loc())[(char)v13] & 0x400) == 0 )
return v8 > 1;
v17 = (unsigned int)(v13 - 65);
if ( (unsigned __int8)v17 <= 0x36u )
{
if ( _bittest64(&v14, v17) )
return v8 > 1;
}
v18 = v8 + 1;
if ( (unsigned int)cur_lang() )
{
if ( (unsigned int)cur_lang() != 0x8000 || *(v15 - 1) != 120 )
goto LABEL_29;
}
else
{
v19 = *(v15 - 1);
if ( v19 != 99 && v19 != 121 )
goto LABEL_29;
}
v18 = v8 + 2;
LABEL_29:
v8 = v18;
LABEL_21:
v13 = *v15++;
if ( !(_BYTE)v13 )
return v8 > 1;
}
}
v4 = 0x70439100704391LL;
v5 = *_ctype_b_loc();
v6 = a2;
while ( 1 )
{
if ( (v5[(char)v3] & 0x400) != 0
&& ((unsigned __int8)(v3 - 65) > 0x36u || !_bittest64(&v4, (unsigned int)(v3 - 65))) )
{
goto LABEL_10;
}
if ( (_BYTE)v3 == 95 )
return 1LL;
if ( (_BYTE)v3 == 94 )
return 0LL;
v3 = *++v6;
if ( !(_BYTE)v3 )
goto LABEL_10;
}
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2)
{
int v3; // ebx
__int64 v4; // rsi
const unsigned __int16 *v5; // rcx
unsigned __int8 *v6; // rax
int v8; // er12
bool v9; // zf
int v10; // eax
unsigned __int64 v11; // rax
__int64 v12; // rdx
int v13; // ebx
__int64 v14; // r14
unsigned __int8 *v15; // rbp
__int64 v16; // r13
unsigned __int64 v17; // rbx
int v18; // ebx
char v19; // al

if ( a2 == (unsigned __int8 *)-1LL )
return 0xFFFFFFFFLL;
v3 = *a2;
if ( !(_BYTE)v3 )
{
LABEL_10:
if ( (unsigned int)long_by_isub(a2) )
return 1LL;
v8 = is_diphth(a2, a1);
if ( v8 )
return 1LL;
v9 = (unsigned int)cur_lang() == 0;
v10 = *a2;
if ( v9 && ((v10 & 0xDF) == 72 || (v10 & 0xDF) == 87) )
return 1LL;
v11 = (unsigned int)(v10 - 65);
if ( (unsigned __int8)v11 > 0x34u )
return 0xFFFFFFFFLL;
v12 = 0x10411100104111LL;
if ( !_bittest64(&v12, v11) )
return 0xFFFFFFFFLL;
v13 = a2[1];
if ( (_BYTE)v13 == 124 )
return 1LL;
if ( !(_BYTE)v13 )
return v8 > 1;
v14 = 0x70439100704391LL;
v15 = a2 + 2;
v16 = 0x10000000200083LL;
while ( 1 )
{
if ( (unsigned __int8)(v13 - 40) <= 0x34u && _bittest64(&v16, (unsigned int)(v13 - 40)) )
goto LABEL_21;
if ( ((*_ctype_b_loc())[(char)v13] & 0x400) == 0 )
return v8 > 1;
v17 = (unsigned int)(v13 - 65);
if ( (unsigned __int8)v17 <= 0x36u )
{
if ( _bittest64(&v14, v17) )
return v8 > 1;
}
v18 = v8 + 1;
if ( (unsigned int)cur_lang() )
{
if ( (unsigned int)cur_lang() != 0x8000 || *(v15 - 1) != 120 )
goto LABEL_29;
}
else
{
v19 = *(v15 - 1);
if ( v19 != 99 && v19 != 121 )
goto LABEL_29;
}
v18 = v8 + 2;
LABEL_29:
v8 = v18;
LABEL_21:
v13 = *v15++;
if ( !(_BYTE)v13 )
return v8 > 1;
}
}
v4 = 0x70439100704391LL;
v5 = *_ctype_b_loc();
v6 = a2;
while ( 1 )
{
if ( (v5[(char)v3] & 0x400) != 0
&& ((unsigned __int8)(v3 - 65) > 0x36u || !_bittest64(&v4, (unsigned int)(v3 - 65))) )
{
goto LABEL_10;
}
if ( (_BYTE)v3 == 95 )
return 1LL;
if ( (_BYTE)v3 == 94 )
return 0LL;
v3 = *++v6;
if ( !(_BYTE)v3 )
goto LABEL_10;
}
}