DateStrToDMY

decompiled_code:
__int64 __fastcall DateStrToDMY(char *nptr, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
__int64 result; // rax
int *v7; // r14
const char *v8; // rbx
const char *v9; // rbx
char *endptr[6]; // [rsp+0h] [rbp-30h] BYREF

result = 0xFFFFFFFFLL;
if ( nptr )
{
v7 = _errno_location();
*v7 = 0;
*a2 = strtoul(nptr, endptr, 10);
result = 0xFFFFFFFFLL;
if ( endptr[0] > nptr && *endptr[0] == 45 )
{
v8 = endptr[0] + 1;
*v7 = 0;
*a3 = strtoul(v8, endptr, 10);
result = 0xFFFFFFFFLL;
if ( endptr[0] > v8 && *endptr[0] == 45 )
{
v9 = endptr[0] + 1;
*v7 = 0;
*a4 = strtoul(v9, endptr, 10);
result = v9 < endptr[0] ? 1 : -1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *nptr, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
__int64 result; // rax
int *v7; // r14
const char *v8; // rbx
const char *v9; // rbx
char *endptr[6]; // [rsp+0h] [rbp-30h] BYREF

result = 0xFFFFFFFFLL;
if ( nptr )
{
v7 = _errno_location();
*v7 = 0;
*a2 = strtoul(nptr, endptr, 10);
result = 0xFFFFFFFFLL;
if ( endptr[0] > nptr && *endptr[0] == 45 )
{
v8 = endptr[0] + 1;
*v7 = 0;
*a3 = strtoul(v8, endptr, 10);
result = 0xFFFFFFFFLL;
if ( endptr[0] > v8 && *endptr[0] == 45 )
{
v9 = endptr[0] + 1;
*v7 = 0;
*a4 = strtoul(v9, endptr, 10);
result = v9 < endptr[0] ? 1 : -1;
}
}
}
return result;
}

original_code:
int DateStrToDMY(char* DateStr, unsigned int* Year, unsigned int* Month, unsigned int* Day)
{
 char* DateStr1;
 char* DateStr2;
 if (DateStr == ((void *)0))
 {
  return -1;
 }
 DateStr1 = DateStr; (*__errno_location ()) = 0;
 *Year = strtoul(DateStr1, &DateStr2, 10);
 if (DateStr1 < DateStr2 && *DateStr2 == '-')
 {
  DateStr1 = DateStr2 + 1; (*__errno_location ()) = 0;
  *Month = strtoul(DateStr1, &DateStr2, 10);
  if (DateStr1 < DateStr2 && *DateStr2 == '-')
  {
   DateStr1 = DateStr2 + 1; (*__errno_location ()) = 0;
   *Day = strtoul(DateStr1, &DateStr2, 10);
   if (DateStr1 < DateStr2)
   {
    return 1;
   }
  }
 }
 return -1;
}

canonical_original_code:
int DateStrToDMY(char *DateStr, unsigned int *Year, unsigned int *Month, unsigned int *Day)
{
 char *DateStr1;
 char *DateStr2;
 if (DateStr == ((void *)0))
 {
  return -1;
 }
 DateStr1 = DateStr; (*__errno_location ()) = 0;
 *Year = strtoul(DateStr1, &DateStr2, 10);
 if (DateStr1 < DateStr2 && *DateStr2 == '-')
 {
  DateStr1 = DateStr2 + 1; (*__errno_location ()) = 0;
  *Month = strtoul(DateStr1, &DateStr2, 10);
  if (DateStr1 < DateStr2 && *DateStr2 == '-')
  {
   DateStr1 = DateStr2 + 1; (*__errno_location ()) = 0;
   *Day = strtoul(DateStr1, &DateStr2, 10);
   if (DateStr1 < DateStr2)
   {
    return 1;
   }
  }
 }
 return -1;
}

variable_types:
DateStr
char *

variable_types:
Year
unsigned int *

variable_types:
Month
unsigned int *

variable_types:
Day
unsigned int *


repo: avgo/avgmoney

decompiled_code:
void FormCategories_TreeViewCategoriesRowActivated()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void FormCategories_TreeViewCategoriesRowActivated(unsigned int id, char* Desc, void* arg)
{
}

canonical_original_code:
void FormCategories_TreeViewCategoriesRowActivated(unsigned int id, char *Desc, void *arg)
{
}

variable_types:
id
unsigned int

variable_types:
Desc
char *

variable_types:
arg
void *

return_type: void


Calc

decompiled_code:
__int64 __fastcall Calc(const char *a1, double *a2)
{
__int64 v2; // rbx
char *v3; // rax
char *v4; // rax
char v5; // dl
__int64 result; // rax
char *v7; // rdi
char *v8; // rax
double v9; // xmm0_8
char *v10; // rax
double v11; // [rsp+8h] [rbp-30h]
char *v12; // [rsp+10h] [rbp-28h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

*a2 = 0.0;
v11 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
if ( *endptr == 32 )
{
v3 = endptr + 1;
do
endptr = v3++;
while ( *(v3 - 1) == 32 );
}
v4 = endptr;
v5 = *endptr;
if ( *endptr )
{
while ( 1 )
{
if ( v5 == 43 )
{
endptr = v4 + 1;
v2 = LC0;
}
else if ( v5 == 45 )
{
endptr = v4 + 1;
v2 = LC1;
}
v7 = endptr;
v8 = endptr + 1;
if ( *endptr == 32 )
{
do
{
v7 = v8;
endptr = v8++;
}
while ( *(v8 - 1) == 32 );
}
v9 = strtod(v7, &v12);
if ( endptr == v12 )
break;
v11 = v9 * *(double *)&v2 + v11;
endptr = v12;
if ( *v12 == 32 )
{
v10 = v12 + 1;
do
endptr = v10++;
while ( *(v10 - 1) == 32 );
}
v4 = endptr;
v5 = *endptr;
if ( !*endptr )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_6:
*a2 = v11;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, double *a2)
{
__int64 v2; // rbx
char *v3; // rax
char *v4; // rax
char v5; // dl
__int64 result; // rax
char *v7; // rdi
char *v8; // rax
double v9; // xmm0_8
char *v10; // rax
double v11; // [rsp+8h] [rbp-30h]
char *v12; // [rsp+10h] [rbp-28h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

*a2 = 0.0;
v11 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
if ( *endptr == 32 )
{
v3 = endptr + 1;
do
endptr = v3++;
while ( *(v3 - 1) == 32 );
}
v4 = endptr;
v5 = *endptr;
if ( *endptr )
{
while ( 1 )
{
if ( v5 == 43 )
{
endptr = v4 + 1;
v2 = LC0;
}
else if ( v5 == 45 )
{
endptr = v4 + 1;
v2 = LC1;
}
v7 = endptr;
v8 = endptr + 1;
if ( *endptr == 32 )
{
do
{
v7 = v8;
endptr = v8++;
}
while ( *(v8 - 1) == 32 );
}
v9 = strtod(v7, &v12);
if ( endptr == v12 )
break;
v11 = v9 * *(double *)&v2 + v11;
endptr = v12;
if ( *v12 == 32 )
{
v10 = v12 + 1;
do
endptr = v10++;
while ( *(v10 - 1) == 32 );
}
v4 = endptr;
v5 = *endptr;
if ( !*endptr )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_6:
*a2 = v11;
result = 1LL;
}
return result;
}

original_code:
int Calc(const char* Str, double* Result)
{
 char* cp1;
 char* cp2;
 double d1, d2, sign;
 *Result = 0;
 d2 = strtod(Str, &cp1);
 if (cp1 == Str)
 {
  return -1;
 }
 while (*cp1 == ' ')
 {
  ++cp1;
 }
 while (*cp1 != '\0')
 {
  if (*cp1 == '+')
  {
   sign = 1;
   ++cp1;
  }
  else
  if (*cp1 == '-')
  {
   sign = -1;
   ++cp1;
  }
  while (*cp1 == ' ')
  {
   ++cp1;
  }
  d1 = strtod(cp1, &cp2);
  if (cp1 == cp2)
  {
   return -1;
  }
  d2 = d2 + sign * d1;
  cp1 = cp2;
  while (*cp1 == ' ')
  {
   ++cp1;
  }
 }
 *Result = d2; return 1;
}

canonical_original_code:
int Calc(char *Str, double *Result)
{
 char *cp1;
 char *cp2;
 double d1; double d2; double sign;
 *Result = 0;
 d2 = strtod(Str, &cp1);
 if (cp1 == Str)
 {
  return -1;
 }
 while (*cp1 == ' ')
 {
  ++cp1;
 }
 while (*cp1 != '\0')
 {
  if (*cp1 == '+')
  {
   sign = 1;
   ++cp1;
  }
  else
  if (*cp1 == '-')
  {
   sign = -1;
   ++cp1;
  }
  while (*cp1 == ' ')
  {
   ++cp1;
  }
  d1 = strtod(cp1, &cp2);
  if (cp1 == cp2)
  {
   return -1;
  }
  d2 = d2 + sign * d1;
  cp1 = cp2;
  while (*cp1 == ' ')
  {
   ++cp1;
  }
 }
 *Result = d2; return 1;
}

variable_types:
Str
char *

variable_types:
Result
double *

variable_types: sign double

return_type: int


repo: avsej/vcprompt

decompiled_code:
int __fastcall parse_args(int argc, char **argv, __int64 a3)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "f:d");
if ( result == -1 )
break;
if ( result == 100 )
{
*(_DWORD *)a3 = 1;
}
else if ( result == 102 )
{
*(_QWORD *)(a3 + 8) = optarg;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv, __int64 a3)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "f:d");
if ( result == -1 )
break;
if ( result == 100 )
{
*(_DWORD *)a3 = 1;
}
else if ( result == 102 )
{
*(_QWORD *)(a3 + 8) = optarg;
}
}
return result;
}

original_code:
void parse_args(int argc, char** argv, options_t* options)
{
    int opt;
    while ((opt = getopt(argc, argv, "f:d")) != -1) {
        switch (opt) {
            case 'f':
                options->format = optarg;
                break;
            case 'd':
                options->debug = 1;
                break;
        }
    }
}

canonical_original_code:
void parse_args(int argc, char **argv, struct options_t *options)
{
    int opt;
    while ((opt = getopt(argc, argv, "f:d")) != -1) {
        switch (opt) {
            case 'f':
                options->format = optarg;
                break;
            case 'd':
                options->debug = 1;
                break;
        }
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *

variable_types: opt int


decompiled_code:
size_t __fastcall parse_format(__int64 a1)
{
const char *v1; // r12
int i; // ebx
size_t result; // rax
char v4; // dl

*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 24) = 0;
*(_DWORD *)(a1 + 28) = 0;
v1 = *(const char **)(a1 + 8);
for ( i = 0; ; ++i )
{
result = strlen(v1);
if ( i >= result )
break;
if ( v1[i] != 37 )
continue;
v4 = v1[++i];
if ( v4 > 117 )
{
LABEL_14:
fprintf(stderr, "error: invalid format string: %%%c\n", (unsigned int)v4);
continue;
}
if ( v4 <= 97 )
{
if ( v4 && v4 != 37 )
goto LABEL_14;
}
else
{
switch ( v4 )
{
case 'b':
*(_DWORD *)(a1 + 16) = 1;
break;
case 'm':
*(_DWORD *)(a1 + 28) = 1;
break;
case 'n':
continue;
case 'r':
*(_DWORD *)(a1 + 20) = 1;
break;
case 'u':
*(_DWORD *)(a1 + 24) = 1;
break;
default:
goto LABEL_14;
}
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1)
{
const char *v1; // r12
int i; // ebx
size_t result; // rax
char v4; // dl

*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 24) = 0;
*(_DWORD *)(a1 + 28) = 0;
v1 = *(const char **)(a1 + 8);
for ( i = 0; ; ++i )
{
result = strlen(v1);
if ( i >= result )
break;
if ( v1[i] != 37 )
continue;
v4 = v1[++i];
if ( v4 > 117 )
{
LABEL_14:
fprintf(stderr, "error: invalid format string: %%%c\n", (unsigned int)v4);
continue;
}
if ( v4 <= 97 )
{
if ( v4 && v4 != 37 )
goto LABEL_14;
}
else
{
switch ( v4 )
{
case 'b':
*(_DWORD *)(a1 + 16) = 1;
break;
case 'm':
*(_DWORD *)(a1 + 28) = 1;
break;
case 'n':
continue;
case 'r':
*(_DWORD *)(a1 + 20) = 1;
break;
case 'u':
*(_DWORD *)(a1 + 24) = 1;
break;
default:
goto LABEL_14;
}
}
}
return result;
}

original_code:
void parse_format(options_t* options)
{
    int i;
    options->show_branch = 0;
    options->show_unknown = 0;
    options->show_modified = 0;
    char* format = options->format;
    for (i = 0; i < strlen(format); i++) {
        if (format[i] == '%') {
            i++;
            switch (format[i]) {
                case '\0':
                    break;
                case 'b':
                    options->show_branch = 1;
                    break;
                case 'r':
                    options->show_revision = 1;
                    break;
                case 'u':
                    options->show_unknown = 1;
                    break;
                case 'm':
                    options->show_modified = 1;
                    break;
                case 'n':
                case '%':
                    break;
                default:
                    fprintf(stderr,
                            "error: invalid format string: %%%c\n",
                            format[i]);
                    break;
            }
        }
    }
}

canonical_original_code:
void parse_format(struct options_t *options)
{
    int i;
    options->show_branch = 0;
    options->show_unknown = 0;
    options->show_modified = 0;
    char *format = options->format;
    for (i = 0; i < strlen(format); i++) {
        if (format[i] == '%') {
            i++;
            switch (format[i]) {
                case '\0':
                    break;
                case 'b':
                    options->show_branch = 1;
                    break;
                case 'r':
                    options->show_revision = 1;
                    break;
                case 'u':
                    options->show_unknown = 1;
                    break;
                case 'm':
                    options->show_modified = 1;
                    break;
                case 'n':
                case '%':
                    break;
                default:
                    fprintf(stderr,
                            "error: invalid format string: %%%c\n",
                            format[i]);
                    break;
            }
        }
    }
}

variable_types: i int

variable_types:
format
char *

user_defined_types: struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; }


decompiled_code:
size_t __fastcall print_result(const char **a1, __int64 a2, __int64 a3)
{
const char *v5; // rbp
int i; // ebx
const char *v7; // rdi
size_t result; // rax
char v9; // di

v5 = *(const char **)(a2 + 8);
for ( i = 0; ; ++i )
{
result = strlen(v5);
if ( i >= result )
break;
v9 = v5[i];
if ( v9 != 37 )
goto LABEL_14;
v9 = v5[++i];
if ( v9 > 117 )
goto LABEL_14;
if ( v9 <= 97 )
{
if ( v9 == 37 || v9 == 48 )
{
putc(37, stdout);
continue;
}
LABEL_14:
putc(v9, stdout);
continue;
}
switch ( v9 )
{
case 'b':
v7 = *(const char **)a3;
if ( *(_QWORD *)a3 )
goto LABEL_6;
continue;
case 'm':
if ( *(_DWORD *)(a3 + 20) )
putc(33, stdout);
continue;
case 'n':
fputs(*a1, stdout);
continue;
case 'r':
v7 = *(const char **)(a3 + 8);
if ( v7 )
LABEL_6:
fputs(v7, stdout);
break;
case 'u':
if ( *(_DWORD *)(a3 + 16) )
putc(63, stdout);
break;
default:
goto LABEL_14;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(const char **a1, __int64 a2, __int64 a3)
{
const char *v5; // rbp
int i; // ebx
const char *v7; // rdi
size_t result; // rax
char v9; // di

v5 = *(const char **)(a2 + 8);
for ( i = 0; ; ++i )
{
result = strlen(v5);
if ( i >= result )
break;
v9 = v5[i];
if ( v9 != 37 )
goto LABEL_14;
v9 = v5[++i];
if ( v9 > 117 )
goto LABEL_14;
if ( v9 <= 97 )
{
if ( v9 == 37 || v9 == 48 )
{
putc(37, stdout);
continue;
}
LABEL_14:
putc(v9, stdout);
continue;
}
switch ( v9 )
{
case 'b':
v7 = *(const char **)a3;
if ( *(_QWORD *)a3 )
goto LABEL_6;
continue;
case 'm':
if ( *(_DWORD *)(a3 + 20) )
putc(33, stdout);
continue;
case 'n':
fputs(*a1, stdout);
continue;
case 'r':
v7 = *(const char **)(a3 + 8);
if ( v7 )
LABEL_6:
fputs(v7, stdout);
break;
case 'u':
if ( *(_DWORD *)(a3 + 16) )
putc(63, stdout);
break;
default:
goto LABEL_14;
}
}
return result;
}

original_code:
void print_result(vccontext_t* context, options_t* options, result_t* result)
{
    int i;
    char* format = options->format;
    for (i = 0; i < strlen(format); i++) {
        if (format[i] == '%') {
            i++;
            switch (format[i]) {
                case '0':
                case '%':
                    putc('%', stdout);
                    break;
                case 'b':
                    if (result->branch != ((void *)0))
                        fputs(result->branch, stdout);
                    break;
                case 'r':
                    if (result->revision != ((void *)0))
                        fputs(result->revision, stdout);
                    break;
                case 'u':
                    if (result->unknown)
                        putc('?', stdout);
                    break;
                case 'm':
                    if (result->modified)
                        putc('!', stdout);
                    break;
                case 'n':
                    fputs(context->name, stdout);
                    break;
                default:
                    putc(format[i], stdout);
            }
        }
        else {
            putc(format[i], stdout);
        }
    }
}

canonical_original_code:
void print_result(struct vccontext_t *context, struct options_t *options, struct result_t *result)
{
    int i;
    char *format = options->format;
    for (i = 0; i < strlen(format); i++) {
        if (format[i] == '%') {
            i++;
            switch (format[i]) {
                case '0':
                case '%':
                    putc('%', stdout);
                    break;
                case 'b':
                    if (result->branch != ((void *)0))
                        fputs(result->branch, stdout);
                    break;
                case 'r':
                    if (result->revision != ((void *)0))
                        fputs(result->revision, stdout);
                    break;
                case 'u':
                    if (result->unknown)
                        putc('?', stdout);
                    break;
                case 'm':
                    if (result->modified)
                        putc('!', stdout);
                    break;
                case 'n':
                    fputs(context->name, stdout);
                    break;
                default:
                    putc(format[i], stdout);
            }
        }
        else {
            putc(format[i], stdout);
        }
    }
}

variable_types: struct vccontext_t { char *name; struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *options; int (*probe)(struct vccontext_t *); struct result_t { char *branch; char *revision; int unknown; int modified; } *(*get_info)(struct vccontext_t *); } *

variable_types:
options
struct options_t *

variable_types:
result
struct result_t *

user_defined_types: struct vccontext_t { char *name; struct options_t *options; int (*probe)(struct vccontext_t *); struct result_t *(*get_info)(struct vccontext_t *); }


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

if ( a2 <= 0 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *v2;
if ( (*(unsigned int (__fastcall **)(_QWORD))(*v2 + 16LL))(*v2) )
break;
if ( ++v2 == &a1[(unsigned int)(a2 - 1) + 1] )
return 0LL;
}
return v3;
}

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

if ( a2 <= 0 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *v2;
if ( (*(unsigned int (__fastcall **)(_QWORD))(*v2 + 16LL))(*v2) )
break;
if ( ++v2 == &a1[(unsigned int)(a2 - 1) + 1] )
return 0LL;
}
return v3;
}

original_code:
vccontext_t* probe_all(vccontext_t** contexts, int num_contexts)
{
    int idx;
    for (idx = 0; idx < num_contexts; idx++) {
        vccontext_t* ctx = contexts[idx];
        if (ctx->probe(ctx)) {
            return ctx;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct vccontext_t *probe_all(struct vccontext_t **contexts, int num_contexts)
{
    int idx;
    for (idx = 0; idx < num_contexts; idx++) {
        struct vccontext_t *ctx = contexts[idx];
        if (ctx->probe(ctx)) {
            return ctx;
        }
    }
    return ((void *)0);
}

variable_types:
contexts
struct vccontext_t **

variable_types: idx int

return_type: struct vccontext_t { char *name; struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *options; int (*probe)(struct vccontext_t *); struct result_t { char *branch; char *revision; int unknown; int modified; } *(*get_info)(struct vccontext_t *); } *


decompiled_code:
__int64 __fastcall probe_parents(_QWORD *a1, int a2)
{
__int64 v3; // rbx
struct stat v4; // [rsp+0h] [rbp-138h] BYREF
struct stat v5; // [rsp+90h] [rbp-A8h] BYREF

debug("no context claimed current dir: walking up the tree");
stat("/", &v5);
while ( 1 )
{
v3 = probe_all(a1, a2);
if ( v3 )
break;
stat(".", &v4);
if ( v5.st_dev == v4.st_dev && v5.st_ino == v4.st_ino || chdir("..") == -1 )
return v3;
}
debug("found a context");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
__int64 v3; // rbx
struct stat v4; // [rsp+0h] [rbp-138h] BYREF
struct stat v5; // [rsp+90h] [rbp-A8h] BYREF

debug("no context claimed current dir: walking up the tree");
stat("/", &v5);
while ( 1 )
{
v3 = func3(a1, a2);
if ( v3 )
break;
stat(".", &v4);
if ( v5.st_dev == v4.st_dev && v5.st_ino == v4.st_ino || chdir("..") == -1 )
return v3;
}
debug("found a context");
return v3;
}

original_code:
vccontext_t* probe_parents(vccontext_t** contexts, int num_contexts)
{
    vccontext_t* context;
    struct stat rootdir;
    struct stat curdir;
    debug("no context claimed current dir: walking up the tree");
    stat("/", &rootdir);
    while (1) {
        context = probe_all(contexts, num_contexts);
        if (context != ((void *)0)) {
            debug("found a context");
            return context;
        }
        stat(".", &curdir);
        int isroot = (rootdir.st_dev == curdir.st_dev &&
                      rootdir.st_ino == curdir.st_ino);
        if (isroot || (-1 == chdir(".."))) {
            return ((void *)0);
        }
    }
}

canonical_original_code:
struct vccontext_t *probe_parents(struct vccontext_t **contexts, int num_contexts)
{
    struct vccontext_t *context;
    struct stat rootdir;
    struct stat curdir;
    debug("no context claimed current dir: walking up the tree");
    stat("/", &rootdir);
    while (1) {
        context = probe_all(contexts, num_contexts);
        if (context != ((void *)0)) {
            debug("found a context");
            return context;
        }
        stat(".", &curdir);
        int isroot = (rootdir.st_dev == curdir.st_dev &&
                      rootdir.st_ino == curdir.st_ino);
        if (isroot || (-1 == chdir(".."))) {
            return ((void *)0);
        }
    }
}

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

variable_types: isroot int

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

user_defined_types: struct result_t { char *branch; char *revision; int unknown; int modified; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
const char **v4; // rbx
__int64 v5; // rax
__int64 v6; // rbp
__int64 v8[6]; // [rsp+0h] [rbp-68h] BYREF
__int64 v9[2]; // [rsp+30h] [rbp-38h] BYREF
int v10; // [rsp+40h] [rbp-28h]
int v11; // [rsp+44h] [rbp-24h]
__int64 v12; // [rsp+48h] [rbp-20h]

v9[0] = 0LL;
v12 = 1LL;
v9[1] = (__int64)"[%n:%b%r%m%u] ";
v10 = 1;
v11 = 1;
parse_args(argc, (char **)argv, (__int64)v9);
parse_format((__int64)v9);
set_options(v9);
v8[0] = get_cvs_context(v9);
v8[1] = get_git_context(v9);
v8[2] = get_hg_context(v9);
v8[3] = get_svn_context(v9);
v8[4] = get_bzr_context(v9);
v3 = probe_parents(v8, 5);
if ( v3 )
{
v4 = (const char **)v3;
v5 = (*(__int64 (__fastcall **)(__int64))(v3 + 24))(v3);
v6 = v5;
if ( v5 )
{
print_result(v4, (__int64)v9, v5);
free_result(v6);
if ( LODWORD(v9[0]) )
putc(10, stdout);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
const char **v4; // rbx
__int64 v5; // rax
__int64 v6; // rbp
__int64 v8[6]; // [rsp+0h] [rbp-68h] BYREF
__int64 v9[2]; // [rsp+30h] [rbp-38h] BYREF
int v10; // [rsp+40h] [rbp-28h]
int v11; // [rsp+44h] [rbp-24h]
__int64 v12; // [rsp+48h] [rbp-20h]

v9[0] = 0LL;
v12 = 1LL;
v9[1] = (__int64)"[%n:%b%r%m%u] ";
v10 = 1;
v11 = 1;
func0(argc, (char **)argv, (__int64)v9);
func1((__int64)v9);
set_options(v9);
v8[0] = get_cvs_context(v9);
v8[1] = get_git_context(v9);
v8[2] = get_hg_context(v9);
v8[3] = get_svn_context(v9);
v8[4] = get_bzr_context(v9);
v3 = func4(v8, 5);
if ( v3 )
{
v4 = (const char **)v3;
v5 = (*(__int64 (__fastcall **)(__int64))(v3 + 24))(v3);
v6 = v5;
if ( v5 )
{
func2(v4, (__int64)v9, v5);
free_result(v6);
if ( LODWORD(v9[0]) )
putc(10, stdout);
}
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
    options_t options = { 0,
                          "[%n:%b%r%m%u] ",
                          1,
                          1,
                          1,
    };
    parse_args(argc, argv, &options);
    parse_format(&options);
    set_options(&options);
    vccontext_t* contexts[] = {
        get_cvs_context(&options),
        get_git_context(&options),
        get_hg_context(&options),
        get_svn_context(&options),
        get_bzr_context(&options),
    };
    int num_contexts = sizeof(contexts) / sizeof(vccontext_t*);
    result_t* result = ((void *)0);
    vccontext_t* context = ((void *)0);
    context = probe_parents(contexts, num_contexts);
    if (context == ((void *)0)) {
        return 0;
    }
    result = context->get_info(context);
    if (result != ((void *)0)) {
        print_result(context, &options, result);
        free_result(result);
        if (options.debug)
            putc('\n', stdout);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct options_t options = { 0,
                          "[%n:%b%r%m%u] ",
                          1,
                          1,
                          1,
    };
    parse_args(argc, argv, &options);
    parse_format(&options);
    set_options(&options);
    struct vccontext_t *contexts[] = {
        get_cvs_context(&options),
        get_git_context(&options),
        get_hg_context(&options),
        get_svn_context(&options),
        get_bzr_context(&options),
    };
    int num_contexts = sizeof(contexts) / sizeof(vccontext_t*);
    struct result_t *result = ((void *)0);
    struct vccontext_t *context = ((void *)0);
    context = probe_parents(contexts, num_contexts);
    if (context == ((void *)0)) {
        return 0;
    }
    result = context->get_info(context);
    if (result != ((void *)0)) {
        print_result(context, &options, result);
        free_result(result);
        if (options.debug)
            putc('\n', stdout);
    }
    return 0;
}

variable_types: struct vccontext_t { char *name; struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *options; int (*probe)(struct vccontext_t *); struct result_t { char *branch; char *revision; int unknown; int modified; } *(*get_info)(struct vccontext_t *); } *[]


decompiled_code:
__int64 svn_probe()
{
return isdir(".svn");
}

canonical_decompiled_code:
__int64 func1()
{
return isdir(".svn");
}

original_code:
static int
svn_probe(vccontext_t* context)
{
    return isdir(".svn");
}

canonical_original_code:
static int svn_probe(struct vccontext_t *context)
{
    return isdir(".svn");
}


decompiled_code:
__int64 __fastcall get_svn_context(__int64 a1)
{
return init_context("svn", a1, svn_probe, svn_get_info);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return init_context("svn", a1, svn_probe, svn_get_info);
}

original_code:
vccontext_t* get_svn_context(options_t* options)
{
    return init_context("svn", options, svn_probe, svn_get_info);
}

canonical_original_code:
struct vccontext_t *get_svn_context(struct options_t *options)
{
    return init_context("svn", options, svn_probe, svn_get_info);
}


decompiled_code:
char **cvs_get_info()
{
char **v0; // rbx
char v2; // [rsp+0h] [rbp-408h] BYREF
char s[1031]; // [rsp+1h] [rbp-407h] BYREF

v0 = (char **)init_result();
if ( (unsigned int)read_first_line("CVS/Tag", &v2, 1024LL) )
{
debug("read first line of CVS/Tag: '%s'", &v2);
if ( v2 == 84 )
*v0 = strdup(s);
else
*v0 = "(unknown)";
}
else
{
debug("unable to read CVS/Tag: assuming trunk");
*v0 = "trunk";
}
return v0;
}

canonical_decompiled_code:
char **func0()
{
char **v0; // rbx
char v2; // [rsp+0h] [rbp-408h] BYREF
char s[1031]; // [rsp+1h] [rbp-407h] BYREF

v0 = (char **)init_result();
if ( (unsigned int)read_first_line("CVS/Tag", &v2, 1024LL) )
{
debug("read first line of CVS/Tag: '%s'", &v2);
if ( v2 == 84 )
*v0 = strdup(s);
else
*v0 = "(unknown)";
}
else
{
debug("unable to read CVS/Tag: assuming trunk");
*v0 = "trunk";
}
return v0;
}

original_code:
static result_t*
cvs_get_info(vccontext_t* context)
{
    result_t* result = init_result();
    char buf[1024];
    if (!read_first_line("CVS/Tag", buf, 1024)) {
        debug("unable to read CVS/Tag: assuming trunk");
        result->branch = "trunk";
    }
    else {
        debug("read first line of CVS/Tag: '%s'", buf);
        if (buf[0] == 'T') {
            result->branch = strdup(buf+1);
        }
        else {
            result->branch = "(unknown)";
        }
    }
    return result;
}

canonical_original_code:
static struct result_t *cvs_get_info(struct vccontext_t *context)
{
    struct result_t *result = init_result();
    char buf[1024];
    if (!read_first_line("CVS/Tag", buf, 1024)) {
        debug("unable to read CVS/Tag: assuming trunk");
        result->branch = "trunk";
    }
    else {
        debug("read first line of CVS/Tag: '%s'", buf);
        if (buf[0] == 'T') {
            result->branch = strdup(buf+1);
        }
        else {
            result->branch = "(unknown)";
        }
    }
    return result;
}

variable_types: struct vccontext_t { char *name; struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *options; int (*probe)(struct vccontext_t *); struct result_t *(*get_info)(struct vccontext_t *); } *

variable_types: struct result_t { char *branch; char *revision; int unknown; int modified; } *

variable_types:
buf
char [1024]


decompiled_code:
__int64 cvs_probe()
{
return isdir("CVS");
}

canonical_decompiled_code:
__int64 func1()
{
return isdir("CVS");
}

original_code:
static int
cvs_probe(vccontext_t* context)
{
    return isdir("CVS");
}

canonical_original_code:
static int cvs_probe(struct vccontext_t *context)
{
    return isdir("CVS");
}


decompiled_code:
__int64 __fastcall get_cvs_context(__int64 a1)
{
return init_context("cvs", a1, cvs_probe, cvs_get_info);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return init_context("cvs", a1, cvs_probe, cvs_get_info);
}

original_code:
vccontext_t* get_cvs_context(options_t* options)
{
    return init_context("cvs", options, cvs_probe, cvs_get_info);
}

canonical_original_code:
struct vccontext_t *get_cvs_context(struct options_t *options)
{
    return init_context("cvs", options, cvs_probe, cvs_get_info);
}


decompiled_code:
__int64 git_get_info()
{
__int64 v0; // rbx
char *v2; // rax
char v3[16]; // [rsp+0h] [rbp-408h] BYREF
char s[1016]; // [rsp+10h] [rbp-3F8h] BYREF

v0 = init_result();
if ( (unsigned int)read_first_line(".git/HEAD", v3, 1024LL) )
{
if ( !memcmp("ref: refs/heads/", v3, 0x10uLL) )
{
debug("read a head ref from .git/HEAD: '%s'", v3);
*(_QWORD *)v0 = strdup(s);
}
else
{
debug(".git/HEAD doesn't look like a head ref: unknown branch");
v2 = (char *)malloc(9uLL);
*(_QWORD *)v0 = v2;
strncpy(v2, v3, 8uLL);
*(_BYTE *)(*(_QWORD *)v0 + 8LL) = 0;
}
}
else
{
debug("unable to read .git/HEAD: assuming not a git repo");
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
char *v2; // rax
char v3[16]; // [rsp+0h] [rbp-408h] BYREF
char s[1016]; // [rsp+10h] [rbp-3F8h] BYREF

v0 = init_result();
if ( (unsigned int)read_first_line(".git/HEAD", v3, 1024LL) )
{
if ( !memcmp("ref: refs/heads/", v3, 0x10uLL) )
{
debug("read a head ref from .git/HEAD: '%s'", v3);
*(_QWORD *)v0 = strdup(s);
}
else
{
debug(".git/HEAD doesn't look like a head ref: unknown branch");
v2 = (char *)malloc(9uLL);
*(_QWORD *)v0 = v2;
strncpy(v2, v3, 8uLL);
*(_BYTE *)(*(_QWORD *)v0 + 8LL) = 0;
}
}
else
{
debug("unable to read .git/HEAD: assuming not a git repo");
v0 = 0LL;
}
return v0;
}

original_code:
static result_t*
git_get_info(vccontext_t* context)
{
    result_t* result = init_result();
    char buf[1024];
    if (!read_first_line(".git/HEAD", buf, 1024)) {
        debug("unable to read .git/HEAD: assuming not a git repo");
        return ((void *)0);
    }
    else {
        char* prefix = "ref: refs/heads/";
        int prefixlen = strlen(prefix);
        if (strncmp(prefix, buf, prefixlen) == 0) {
            debug("read a head ref from .git/HEAD: '%s'", buf);
            result->branch = strdup(buf+prefixlen);
        }
        else {
            debug(".git/HEAD doesn't look like a head ref: unknown branch");
            result->branch = malloc(sizeof(char) * 9);
            strncpy(result->branch, buf, 8);
            result->branch[8] = '\0';
        }
    }
    return result;
}

canonical_original_code:
static struct result_t *git_get_info(struct vccontext_t *context)
{
    struct result_t *result = init_result();
    char buf[1024];
    if (!read_first_line(".git/HEAD", buf, 1024)) {
        debug("unable to read .git/HEAD: assuming not a git repo");
        return ((void *)0);
    }
    else {
        char *prefix = "ref: refs/heads/";
        int prefixlen = strlen(prefix);
        if (strncmp(prefix, buf, prefixlen) == 0) {
            debug("read a head ref from .git/HEAD: '%s'", buf);
            result->branch = strdup(buf+prefixlen);
        }
        else {
            debug(".git/HEAD doesn't look like a head ref: unknown branch");
            result->branch = malloc(sizeof(char) * 9);
            strncpy(result->branch, buf, 8);
            result->branch[8] = '\0';
        }
    }
    return result;
}

variable_types:
prefix
char *

variable_types: prefixlen int

return_type: struct result_t { char *branch; char *revision; int unknown; int modified; } *


decompiled_code:
__int64 git_probe()
{
return isdir(".git");
}

canonical_decompiled_code:
__int64 func1()
{
return isdir(".git");
}

original_code:
static int
git_probe(vccontext_t* context)
{
    return isdir(".git");
}

canonical_original_code:
static int git_probe(struct vccontext_t *context)
{
    return isdir(".git");
}


decompiled_code:
__int64 __fastcall get_git_context(__int64 a1)
{
return init_context("git", a1, git_probe, git_get_info);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return init_context("git", a1, git_probe, git_get_info);
}

original_code:
vccontext_t* get_git_context(options_t* options)
{
    return init_context("git", options, git_probe, git_get_info);
}

canonical_original_code:
struct vccontext_t *get_git_context(struct options_t *options)
{
    return init_context("git", options, git_probe, git_get_info);
}


decompiled_code:
void *init_result()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
result_t* init_result()
{
    return (result_t*) calloc(1, sizeof(result_t));
}

canonical_original_code:
struct result_t *init_result()
{
    return (struct result_t *) calloc(1, sizeof(result_t));
}


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

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

original_code:
void free_result(result_t* result)
{
    free(result);
}

canonical_original_code:
void free_result(struct result_t *result)
{
    free(result);
}


decompiled_code:
void __fastcall set_options(__int64 a1)
{
options = a1;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
options = a1;
}

original_code:
void set_options(options_t* options)
{
    _options = options;
}

canonical_original_code:
void set_options(struct options_t *options)
{
    _options = options;
}

variable_types: struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *


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

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

original_code:
void free_context(vccontext_t* context)
{
    free(context);
}

canonical_original_code:
void free_context(struct vccontext_t *context)
{
    free(context);
}


debug

decompiled_code:
int debug(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = options;
if ( *(_DWORD *)options )
{
va_start(arg, format);
fwrite("vcprompt: debug: ", 1uLL, 0x11uLL, stdout);
vfprintf(stdout, format, arg);
result = fputc(10, stdout);
}
return result;
}

canonical_decompiled_code:
int func4(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = options;
if ( *(_DWORD *)options )
{
va_start(arg, format);
fwrite("vcprompt: debug: ", 1uLL, 0x11uLL, stdout);
vfprintf(stdout, format, arg);
result = fputc(10, stdout);
}
return result;
}

original_code:
void debug(char* fmt, ...)
{
    va_list args;
    if (!_options->debug)
        return;
    __builtin_va_start(args,fmt);
    fputs("vcprompt: debug: ", stdout);
    vfprintf(stdout, fmt, args);
    fputc('\n', stdout);
    __builtin_va_end(args);
}

canonical_original_code:
void debug(char *fmt, ...)
{
    __builtin_va_list args;
    if (!_options->debug)
        return;
    __builtin_va_start(args,fmt);
    fputs("vcprompt: debug: ", stdout);
    vfprintf(stdout, fmt, args);
    fputc('\n', stdout);
    __builtin_va_end(args);
}

variable_types:
fmt
char *


isdir

decompiled_code:
__int64 __fastcall isdir(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
debug("failed to stat() '%s': %s", a1, v4);
v1 = 0;
}
else
{
v1 = 1;
if ( (v5.st_mode & 0xF000) != 0x4000 )
{
debug("'%s' not a directory", a1);
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
func4("failed to stat() '%s': %s", a1, v4);
v1 = 0;
}
else
{
v1 = 1;
if ( (v5.st_mode & 0xF000) != 0x4000 )
{
func4("'%s' not a directory", a1);
v1 = 0;
}
}
return v1;
}

original_code:
int isdir(char* name)
{
    struct stat statbuf;
    if (stat(name, &statbuf) < 0) {
        debug("failed to stat() '%s': %s", name, strerror((*__errno_location ())));
        return 0;
    }
    if (!((((statbuf.st_mode)) & 0170000) == (0040000))) {
        debug("'%s' not a directory", name);
        return 0;
    }
    return 1;
}

canonical_original_code:
int isdir(char *name)
{
    struct stat statbuf;
    if (stat(name, &statbuf) < 0) {
        debug("failed to stat() '%s': %s", name, strerror((*__errno_location ())));
        return 0;
    }
    if (!((((statbuf.st_mode)) & 0170000) == (0040000))) {
        debug("'%s' not a directory", name);
        return 0;
    }
    return 1;
}

variable_types:
name
char *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
const char *__fastcall chop_newline(const char *a1)
{
const char *result; // rax

result = &a1[(int)strlen(a1) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(const char *a1)
{
const char *result; // rax

result = &a1[(int)strlen(a1) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

original_code:
void chop_newline(char* buf)
{
    int len = strlen(buf);
    if (buf[len-1] == '\n')
        buf[len-1] = '\0';
}

canonical_original_code:
void chop_newline(char *buf)
{
    int len = strlen(buf);
    if (buf[len-1] == '\n')
        buf[len-1] = '\0';
}

variable_types:
buf
char *

variable_types: len int


decompiled_code:
char **hg_get_info()
{
char **v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = (char **)init_result();
if ( (unsigned int)read_first_line(".hg/branch", v2, 1024LL) )
{
debug("read first line from .hg/branch: '%s'", v2);
*v0 = strdup(v2);
}
else
{
debug("failed to read from .hg/branch: assuming not an hg repo");
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
char **func0()
{
char **v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = (char **)init_result();
if ( (unsigned int)read_first_line(".hg/branch", v2, 1024LL) )
{
debug("read first line from .hg/branch: '%s'", v2);
*v0 = strdup(v2);
}
else
{
debug("failed to read from .hg/branch: assuming not an hg repo");
v0 = 0LL;
}
return v0;
}

original_code:
static result_t*
hg_get_info(vccontext_t* context)
{
    result_t* result = init_result();
    char buf[1024];
    if (read_first_line(".hg/branch", buf, 1024)) {
        debug("read first line from .hg/branch: '%s'", buf);
        result->branch = strdup(buf);
    }
    else {
        debug("failed to read from .hg/branch: assuming not an hg repo");
        return ((void *)0);
    }
    return result;
}

canonical_original_code:
static struct result_t *hg_get_info(struct vccontext_t *context)
{
    struct result_t *result = init_result();
    char buf[1024];
    if (read_first_line(".hg/branch", buf, 1024)) {
        debug("read first line from .hg/branch: '%s'", buf);
        result->branch = strdup(buf);
    }
    else {
        debug("failed to read from .hg/branch: assuming not an hg repo");
        return ((void *)0);
    }
    return result;
}


decompiled_code:
__int64 hg_probe()
{
return isdir(".hg");
}

canonical_decompiled_code:
__int64 func1()
{
return isdir(".hg");
}

original_code:
static int
hg_probe(vccontext_t* context)
{
    return isdir(".hg");
}

canonical_original_code:
static int hg_probe(struct vccontext_t *context)
{
    return isdir(".hg");
}

variable_types: struct vccontext_t { char *name; struct options_t { int debug; char *format; int show_branch; int show_revision; int show_unknown; int show_modified; } *options; int (*probe)(struct vccontext_t *); struct result_t { char *branch; char *revision; int unknown; int modified; } *(*get_info)(struct vccontext_t *); } *


decompiled_code:
__int64 __fastcall get_hg_context(__int64 a1)
{
return init_context("hg", a1, hg_probe, hg_get_info);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return init_context("hg", a1, hg_probe, hg_get_info);
}

original_code:
vccontext_t* get_hg_context(options_t* options)
{
    return init_context("hg", options, hg_probe, hg_get_info);
}

canonical_original_code:
struct vccontext_t *get_hg_context(struct options_t *options)
{
    return init_context("hg", options, hg_probe, hg_get_info);
}

variable_types:
options
struct options_t *


decompiled_code:
__int64 bzr_get_info()
{
__int64 v0; // rbx
char *v1; // rax
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = init_result();
if ( (unsigned int)read_first_line(".bzr/branch/last-revision", v3, 1024LL) )
{
debug("read first line from .bzr/branch/last-revision: '%s'", v3);
v1 = strdup(v3);
*(_QWORD *)(v0 + 8) = v1;
*strchr(v1, 32) = 0;
}
else
{
debug("failed to read from .bzr/branch/last-revision: assuming not an bzr repo");
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
char *v1; // rax
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = init_result();
if ( (unsigned int)read_first_line(".bzr/branch/last-revision", v3, 1024LL) )
{
debug("read first line from .bzr/branch/last-revision: '%s'", v3);
v1 = strdup(v3);
*(_QWORD *)(v0 + 8) = v1;
*strchr(v1, 32) = 0;
}
else
{
debug("failed to read from .bzr/branch/last-revision: assuming not an bzr repo");
v0 = 0LL;
}
return v0;
}

original_code:
static result_t*
bzr_get_info(vccontext_t* context)
{
    result_t* result = init_result();
    char buf[1024];
    if (read_first_line(".bzr/branch/last-revision", buf, 1024)) {
        debug("read first line from .bzr/branch/last-revision: '%s'", buf);
        result->revision = strdup(buf);
        *(strchr(result->revision, ' ')) = '\0';
    }
    else {
        debug("failed to read from .bzr/branch/last-revision: assuming not an bzr repo");
        return ((void *)0);
    }
    return result;
}

canonical_original_code:
static struct result_t *bzr_get_info(struct vccontext_t *context)
{
    struct result_t *result = init_result();
    char buf[1024];
    if (read_first_line(".bzr/branch/last-revision", buf, 1024)) {
        debug("read first line from .bzr/branch/last-revision: '%s'", buf);
        result->revision = strdup(buf);
        *(strchr(result->revision, ' ')) = '\0';
    }
    else {
        debug("failed to read from .bzr/branch/last-revision: assuming not an bzr repo");
        return ((void *)0);
    }
    return result;
}


decompiled_code:
__int64 bzr_probe()
{
return isdir(".bzr");
}

canonical_decompiled_code:
__int64 func1()
{
return isdir(".bzr");
}

original_code:
static int
bzr_probe(vccontext_t* context)
{
    return isdir(".bzr");
}

canonical_original_code:
static int bzr_probe(struct vccontext_t *context)
{
    return isdir(".bzr");
}


decompiled_code:
__int64 __fastcall get_bzr_context(__int64 a1)
{
return init_context("bzr", a1, bzr_probe, bzr_get_info);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return init_context("bzr", a1, bzr_probe, bzr_get_info);
}

original_code:
vccontext_t* get_bzr_context(options_t* options)
{
    return init_context("bzr", options, bzr_probe, bzr_get_info);
}

canonical_original_code:
struct vccontext_t *get_bzr_context(struct options_t *options)
{
    return init_context("bzr", options, bzr_probe, bzr_get_info);
}


repo: avz/flap

decompiled_code:
void *__fastcall Server__connectionPollerThread(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 0x80000;
while ( 1 )
{
v1 = accept(*(_DWORD *)a1, 0LL, 0LL);
v2 = v1;
if ( v1 < 0 )
break;
setsockopt(v1, 1, 7, optval, 4u);
ServerClientsPool_lock((char *)a1 + 8);
ServerClientsPool_attachClient((char *)a1 + 8, v2, 0LL, 0LL);
ServerClientsPool_unlock((char *)a1 + 8);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 0x80000;
while ( 1 )
{
v1 = accept(*(_DWORD *)a1, 0LL, 0LL);
v2 = v1;
if ( v1 < 0 )
break;
setsockopt(v1, 1, 7, optval, 4u);
ServerClientsPool_lock((char *)a1 + 8);
ServerClientsPool_attachClient((char *)a1 + 8, v2, 0LL, 0LL);
ServerClientsPool_unlock((char *)a1 + 8);
}
return 0LL;
}

original_code:
static void *Server__connectionPollerThread(void *serverPtr) {
 struct Server *server = (struct Server *)serverPtr;
 int s;
 int bufSize = 1024 * 512;
 while((s = accept(server->sock, ((void *)0), ((void *)0))) >= 0) {
  setsockopt(s, 1, 7, &bufSize, (socklen_t)sizeof(bufSize));
  ServerClientsPool_lock(&server->pool);
  ServerClientsPool_attachClient(&server->pool, s, 00, 0);
  ServerClientsPool_unlock(&server->pool);
 }
 return ((void *)0);
}

canonical_original_code:
static void *Server__connectionPollerThread(void *serverPtr) {
 struct Server *server = (struct Server *)serverPtr;
 int s;
 int bufSize = 1024 * 512;
 while((s = accept(server->sock, ((void *)0), ((void *)0))) >= 0) {
  setsockopt(s, 1, 7, &bufSize, (unsigned int)sizeof(bufSize));
  ServerClientsPool_lock(&server->pool);
  ServerClientsPool_attachClient(&server->pool, s, 00, 0);
  ServerClientsPool_unlock(&server->pool);
 }
 return ((void *)0);
}

variable_types:
serverPtr
void *

variable_types: struct Server { int sock; struct ServerClientsPool { struct ServerClient { int sock; int mode; int flags; } **clients; unsigned long clientsAllocated; unsigned long clientsCount; 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; } pool; unsigned long connectionPollerThread; } *

variable_types: s int

variable_types: bufSize int

return_type: void *

user_defined_types: struct Server { int sock; struct ServerClientsPool pool; unsigned long connectionPollerThread; }

user_defined_types: struct ServerClientsPool { struct ServerClient **clients; unsigned long clientsAllocated; unsigned long clientsCount; union pthread_mutex_t mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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; }


decompiled_code:
__int64 __fastcall Server_init(_DWORD *a1)
{
*a1 = -1;
return ServerClientsPool_init(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
*a1 = -1;
return ServerClientsPool_init(a1 + 2);
}

original_code:
void Server_init(struct Server *server) {
 server->sock = -1;
 ServerClientsPool_init(&server->pool);
}

user_defined_types: struct ServerClient { int sock; int mode; int flags; }

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


decompiled_code:
int __fastcall Server_bindUnix(void *arg, char *s, int a3)
{
int v4; // eax
int *v5; // rbp
int result; // eax
int *v7; // rbx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
struct sockaddr v12[8]; // [rsp+0h] [rbp-88h] BYREF

if ( strlen(s) > 0x6B )
{
v7 = _errno_location();
*v7 = 36;
perror(s);
exit(*v7);
}
v4 = socket(1, 1, 0);
*(_DWORD *)arg = v4;
if ( v4 == -1 )
{
perror("socket(AF_UNIX, SOCK_STREAM, 0)");
v8 = _errno_location();
exit(*v8);
}
strncpy(v12[0].sa_data, s, 0x6CuLL);
v12[0].sa_family = 1;
if ( a3 )
{
if ( unlink(v12[0].sa_data) )
{
v5 = _errno_location();
if ( *v5 != 2 )
{
perror(v12[0].sa_data);
exit(*v5);
}
}
}
if ( bind(*(_DWORD *)arg, v12, 0x6Eu) )
{
perror(v12[0].sa_data);
v9 = _errno_location();
exit(*v9);
}
if ( listen(*(_DWORD *)arg, 32) )
{
perror("listen()");
v10 = _errno_location();
exit(*v10);
}
result = pthread_create((pthread_t *)arg + 9, 0LL, Server__connectionPollerThread, arg);
if ( result )
{
perror("pthread_create(Server__connectionPollerThread)");
v11 = _errno_location();
exit(*v11);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(void *arg, char *s, int a3)
{
int v4; // eax
int *v5; // rbp
int result; // eax
int *v7; // rbx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
struct sockaddr v12[8]; // [rsp+0h] [rbp-88h] BYREF

if ( strlen(s) > 0x6B )
{
v7 = _errno_location();
*v7 = 36;
perror(s);
exit(*v7);
}
v4 = socket(1, 1, 0);
*(_DWORD *)arg = v4;
if ( v4 == -1 )
{
perror("socket(AF_UNIX, SOCK_STREAM, 0)");
v8 = _errno_location();
exit(*v8);
}
strncpy(v12[0].sa_data, s, 0x6CuLL);
v12[0].sa_family = 1;
if ( a3 )
{
if ( unlink(v12[0].sa_data) )
{
v5 = _errno_location();
if ( *v5 != 2 )
{
perror(v12[0].sa_data);
exit(*v5);
}
}
}
if ( bind(*(_DWORD *)arg, v12, 0x6Eu) )
{
perror(v12[0].sa_data);
v9 = _errno_location();
exit(*v9);
}
if ( listen(*(_DWORD *)arg, 32) )
{
perror("listen()");
v10 = _errno_location();
exit(*v10);
}
result = pthread_create((pthread_t *)arg + 9, 0LL, Server__connectionPollerThread, arg);
if ( result )
{
perror("pthread_create(Server__connectionPollerThread)");
v11 = _errno_location();
exit(*v11);
}
return result;
}

original_code:
void Server_bindUnix(struct Server *server, const char *path, int forceReuse) {
 struct sockaddr_un addr;
 if(strlen(path) >= sizeof(addr.sun_path)) {
  (*__errno_location ()) = 36;
  perror(path);
  exit((*__errno_location ()));
 }
 server->sock = socket(1, SOCK_STREAM, 0);
 if(server->sock == -1) {
  perror("socket(AF_UNIX, SOCK_STREAM, 0)");
  exit((*__errno_location ()));
 }
 strncpy(addr.sun_path, path, sizeof(addr.sun_path));
 addr.sun_family = 1;
 if(forceReuse) {
  if(unlink(addr.sun_path) != 0 && (*__errno_location ()) != 2) {
   perror(addr.sun_path);
   exit((*__errno_location ()));
  }
 }
 if(bind(server->sock, (struct sockaddr *)&addr, (socklen_t)sizeof(addr)) != 0) {
  perror(addr.sun_path);
  exit((*__errno_location ()));
 }
 if(listen(server->sock, 32) != 0) {
  perror("listen()");
  exit((*__errno_location ()));
 }
 if(pthread_create(&server->connectionPollerThread, ((void *)0), Server__connectionPollerThread, server) != 0) {
  perror("pthread_create(Server__connectionPollerThread)");
  exit((*__errno_location ()));
 }
}

canonical_original_code:
void Server_bindUnix(struct Server *server, char *path, int forceReuse) {
 struct sockaddr_un addr;
 if(strlen(path) >= sizeof(addr.sun_path)) {
  (*__errno_location ()) = 36;
  perror(path);
  exit((*__errno_location ()));
 }
 server->sock = socket(1, SOCK_STREAM, 0);
 if(server->sock == -1) {
  perror("socket(AF_UNIX, SOCK_STREAM, 0)");
  exit((*__errno_location ()));
 }
 strncpy(addr.sun_path, path, sizeof(addr.sun_path));
 addr.sun_family = 1;
 if(forceReuse) {
  if(unlink(addr.sun_path) != 0 && (*__errno_location ()) != 2) {
   perror(addr.sun_path);
   exit((*__errno_location ()));
  }
 }
 if(bind(server->sock, (struct sockaddr *)&addr, (unsigned int)sizeof(addr)) != 0) {
  perror(addr.sun_path);
  exit((*__errno_location ()));
 }
 if(listen(server->sock, 32) != 0) {
  perror("listen()");
  exit((*__errno_location ()));
 }
 if(pthread_create(&server->connectionPollerThread, ((void *)0), Server__connectionPollerThread, server) != 0) {
  perror("pthread_create(Server__connectionPollerThread)");
  exit((*__errno_location ()));
 }
}

variable_types:
path
char *

variable_types: forceReuse int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


decompiled_code:
__int64 __fastcall Server_write(__int64 a1)
{
return ServerClientsPool_write(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return ServerClientsPool_write(a1 + 8);
}

original_code:
void Server_write(struct Server *server, const void *buf, ssize_t len) {
 ServerClientsPool_write(&server->pool, buf, len);
}

canonical_original_code:
void Server_write(struct Server *server, void *buf, long len) {
 ServerClientsPool_write(&server->pool, buf, len);
}

variable_types:
buf
void *

variable_types: len long


decompiled_code:
__int64 __fastcall Server_destroy(__int64 a1)
{
int v2; // edi

v2 = *(_DWORD *)a1;
if ( v2 >= 0 )
close(v2);
pthread_cancel(*(_QWORD *)(a1 + 72));
return ServerClientsPool_destroy(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v2; // edi

v2 = *(_DWORD *)a1;
if ( v2 >= 0 )
close(v2);
pthread_cancel(*(_QWORD *)(a1 + 72));
return ServerClientsPool_destroy(a1 + 8);
}

original_code:
void Server_destroy(struct Server *server) {
 if(server->sock >= 0)
  close(server->sock);
 pthread_cancel(server->connectionPollerThread);
 ServerClientsPool_destroy(&server->pool);
}


usageAndExit

decompiled_code:
void __fastcall __noreturn usageAndExit(const char *a1)
{
fprintf(stderr, "Usage: %s (-s|-c) /path/to/socket.sock\n\t-s: server mode\n\t-c: client mode (read-only)\n", a1);
exit(255);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Usage: %s (-s|-c) /path/to/socket.sock\n\t-s: server mode\n\t-c: client mode (read-only)\n", a1);
exit(255);
}

original_code:
void usageAndExit(const char *cmd) {
 fprintf(stderr,
  "Usage: %s (-s|-c) /path/to/socket.sock\n"
  "	-s: server mode\n"
  "	-c: client mode (read-only)\n"
  , cmd
 );
 exit(255);
}

canonical_original_code:
void usageAndExit(char *cmd) {
 fprintf(stderr,
  "Usage: %s (-s|-c) /path/to/socket.sock\n"
  "	-s: server mode\n"
  "	-c: client mode (read-only)\n"
  , cmd
 );
 exit(255);
}

variable_types:
cmd
char *


runClientMode

decompiled_code:
__int64 __fastcall runClientMode(char *s)
{
int v1; // er12
unsigned int v2; // er13
ssize_t v3; // rax
ssize_t v4; // rbp
int *v5; // rbp
int *v6; // rax
__int64 v8; // rbx
ssize_t v9; // rax
int optval; // [rsp+Ch] [rbp-409Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4098h] BYREF
char buf[16424]; // [rsp+80h] [rbp-4028h] BYREF

optval = 0x80000;
if ( strlen(s) > 0x6B )
{
v5 = _errno_location();
*v5 = 36;
perror(s);
exit(*v5);
}
v1 = socket(1, 1, 0);
if ( v1 == -1 )
{
perror("socket(AF_UNIX, SOCK_STREAM, 0)");
v6 = _errno_location();
exit(*v6);
}
strncpy(addr.sa_data, s, 0x6CuLL);
addr.sa_family = 1;
v2 = connect(v1, &addr, 0x6Eu);
if ( v2 )
{
perror(s);
v2 = *_errno_location();
}
else
{
setsockopt(v1, 1, 7, &optval, 4u);
LABEL_5:
while ( 1 )
{
v3 = read(v1, buf, 0x4000uLL);
v4 = v3;
if ( v3 > 0 )
break;
if ( v3 >= 0 )
return v2;
if ( *_errno_location() != 4 )
return (unsigned int)*_errno_location();
}
v8 = 0LL;
while ( 1 )
{
v9 = write(1, &buf[v8], v4 - v8);
if ( v9 <= 0 )
break;
v8 += v9;
if ( v4 <= v8 )
goto LABEL_5;
}
perror("read(STDIN_FILENO)");
v2 = *_errno_location();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s)
{
int v1; // er12
unsigned int v2; // er13
ssize_t v3; // rax
ssize_t v4; // rbp
int *v5; // rbp
int *v6; // rax
__int64 v8; // rbx
ssize_t v9; // rax
int optval; // [rsp+Ch] [rbp-409Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4098h] BYREF
char buf[16424]; // [rsp+80h] [rbp-4028h] BYREF

optval = 0x80000;
if ( strlen(s) > 0x6B )
{
v5 = _errno_location();
*v5 = 36;
perror(s);
exit(*v5);
}
v1 = socket(1, 1, 0);
if ( v1 == -1 )
{
perror("socket(AF_UNIX, SOCK_STREAM, 0)");
v6 = _errno_location();
exit(*v6);
}
strncpy(addr.sa_data, s, 0x6CuLL);
addr.sa_family = 1;
v2 = connect(v1, &addr, 0x6Eu);
if ( v2 )
{
perror(s);
v2 = *_errno_location();
}
else
{
setsockopt(v1, 1, 7, &optval, 4u);
LABEL_5:
while ( 1 )
{
v3 = read(v1, buf, 0x4000uLL);
v4 = v3;
if ( v3 > 0 )
break;
if ( v3 >= 0 )
return v2;
if ( *_errno_location() != 4 )
return (unsigned int)*_errno_location();
}
v8 = 0LL;
while ( 1 )
{
v9 = write(1, &buf[v8], v4 - v8);
if ( v9 <= 0 )
break;
v8 += v9;
if ( v4 <= v8 )
goto LABEL_5;
}
perror("read(STDIN_FILENO)");
v2 = *_errno_location();
}
return v2;
}

original_code:
int runClientMode(const char *sockPath) {
 char buf[16 * 1024];
 struct sockaddr_un addr;
 int sock;
 int sockBufSize = 1024 * 512;
 if(strlen(sockPath) >= sizeof(addr.sun_path)) {
  (*__errno_location ()) = 36;
  perror(sockPath);
  exit((*__errno_location ()));
 }
 sock = socket(1, SOCK_STREAM, 0);
 if(sock == -1) {
  perror("socket(AF_UNIX, SOCK_STREAM, 0)");
  exit((*__errno_location ()));
 }
 strncpy(addr.sun_path, sockPath, sizeof(addr.sun_path));
 addr.sun_family = 1;
 if(connect(sock, (struct sockaddr *)&addr, (socklen_t)sizeof(addr)) != 0) {
  perror(sockPath);
  return (*__errno_location ());
 }
 setsockopt(sock, 1, 7, &sockBufSize, (socklen_t)sizeof(sockBufSize));
 while(1) {
  ssize_t written = 0;
  ssize_t r = read(sock, buf, sizeof(buf));
  if(r <= 0) {
   if(r < 0 && (*__errno_location ()) == 4)
    continue;
   return r ? (*__errno_location ()) : 0;
  }
  while(written < r) {
   ssize_t w = write(1, buf + written, (size_t)(r - written));
   if(w <= 0) {
    perror("read(STDIN_FILENO)");
    return (*__errno_location ());
   } else {
    written += w;
   }
  }
 }
 return 0;
}

canonical_original_code:
int runClientMode(char *sockPath) {
 char buf[-1];
 struct sockaddr_un addr;
 int sock;
 int sockBufSize = 1024 * 512;
 if(strlen(sockPath) >= sizeof(addr.sun_path)) {
  (*__errno_location ()) = 36;
  perror(sockPath);
  exit((*__errno_location ()));
 }
 sock = socket(1, SOCK_STREAM, 0);
 if(sock == -1) {
  perror("socket(AF_UNIX, SOCK_STREAM, 0)");
  exit((*__errno_location ()));
 }
 strncpy(addr.sun_path, sockPath, sizeof(addr.sun_path));
 addr.sun_family = 1;
 if(connect(sock, (struct sockaddr *)&addr, (unsigned int)sizeof(addr)) != 0) {
  perror(sockPath);
  return (*__errno_location ());
 }
 setsockopt(sock, 1, 7, &sockBufSize, (unsigned int)sizeof(sockBufSize));
 while(1) {
  long written = 0;
  long r = read(sock, buf, sizeof(buf));
  if(r <= 0) {
   if(r < 0 && (*__errno_location ()) == 4)
    continue;
   return r ? (*__errno_location ()) : 0;
  }
  while(written < r) {
   long w = write(1, buf + written, (size_t)(r - written));
   if(w <= 0) {
    perror("read(STDIN_FILENO)");
    return (*__errno_location ());
   } else {
    written += w;
   }
  }
 }
 return 0;
}

variable_types:
sockPath
char *

variable_types:
buf
char [-1]

variable_types: sock int

variable_types: sockBufSize int

variable_types: written long

variable_types: r long

variable_types: w long

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


runServerMode

decompiled_code:
__int64 __fastcall runServerMode(__int64 a1)
{
ssize_t v1; // rax
ssize_t v2; // rbp
int *v3; // rbx
__int64 v5; // rbx
ssize_t v6; // rax
char v7; // bl
_BYTE v8[80]; // [rsp+0h] [rbp-8068h] BYREF
char buf[32792]; // [rsp+50h] [rbp-8018h] BYREF

signal(13, (__sighandler_t)((char *)usageAndExit + 1));
Server_init(v8);
Server_bindUnix(v8, a1, 1LL);
while ( 2 )
{
while ( 1 )
{
v1 = read(0, buf, 0x8000uLL);
v2 = v1;
if ( v1 > 0 )
break;
if ( !v1 )
goto LABEL_14;
v3 = _errno_location();
if ( *v3 != 4 )
{
perror("read(STDIN_FILENO)");
return (unsigned int)*v3;
}
}
v5 = 0LL;
while ( 1 )
{
v6 = write(1, &buf[v5], v2 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
if ( v2 <= v5 )
{
v7 = 0;
goto LABEL_13;
}
}
if ( v6 != -1 || *_errno_location() != 32 )
{
perror("write(STDOUT_FILENO)");
return (unsigned int)*_errno_location();
}
v7 = 1;
LABEL_13:
Server_write(v8, buf, v2);
if ( !v7 )
continue;
break;
}
LABEL_14:
Server_destroy(v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
ssize_t v1; // rax
ssize_t v2; // rbp
int *v3; // rbx
__int64 v5; // rbx
ssize_t v6; // rax
char v7; // bl
_BYTE v8[80]; // [rsp+0h] [rbp-8068h] BYREF
char buf[32792]; // [rsp+50h] [rbp-8018h] BYREF

signal(13, (__sighandler_t)((char *)usageAndExit + 1));
Server_init(v8);
Server_bindUnix(v8, a1, 1LL);
while ( 2 )
{
while ( 1 )
{
v1 = read(0, buf, 0x8000uLL);
v2 = v1;
if ( v1 > 0 )
break;
if ( !v1 )
goto LABEL_14;
v3 = _errno_location();
if ( *v3 != 4 )
{
perror("read(STDIN_FILENO)");
return (unsigned int)*v3;
}
}
v5 = 0LL;
while ( 1 )
{
v6 = write(1, &buf[v5], v2 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
if ( v2 <= v5 )
{
v7 = 0;
goto LABEL_13;
}
}
if ( v6 != -1 || *_errno_location() != 32 )
{
perror("write(STDOUT_FILENO)");
return (unsigned int)*_errno_location();
}
v7 = 1;
LABEL_13:
Server_write(v8, buf, v2);
if ( !v7 )
continue;
break;
}
LABEL_14:
Server_destroy(v8);
return 0LL;
}

original_code:
int runServerMode(const char *sockPath) {
 char buf[32 * 1024];
 struct Server server;
 char eof = 0;
 signal(13, ((__sighandler_t) 1));
 Server_init(&server);
 Server_bindUnix(&server, sockPath, 1);
 while(!eof) {
  ssize_t r = read(0, buf, sizeof(buf));
  ssize_t written = 0;
  if(r <= 0) {
   if(r == 0)
    break;
   if((*__errno_location ()) == 4)
    continue;
   perror("read(STDIN_FILENO)");
   return (*__errno_location ());
  }
  while(written < r && !eof) {
   ssize_t w = write(1, buf + written, (size_t)(r - written));
   if(w <= 0) {
    if(w == -1 && (*__errno_location ()) == 32) {
     eof = 1;
     break;
    }
    perror("write(STDOUT_FILENO)");
    return (*__errno_location ());
   } else {
    written += w;
   }
  }
  Server_write(&server, buf, r);
 }
 Server_destroy(&server);
 return 0;
}

canonical_original_code:
int runServerMode(char *sockPath) {
 char buf[-1];
 struct Server server;
 char eof = 0;
 signal(13, ((void (*)(int)) 1));
 Server_init(&server);
 Server_bindUnix(&server, sockPath, 1);
 while(!eof) {
  long r = read(0, buf, sizeof(buf));
  long written = 0;
  if(r <= 0) {
   if(r == 0)
    break;
   if((*__errno_location ()) == 4)
    continue;
   perror("read(STDIN_FILENO)");
   return (*__errno_location ());
  }
  while(written < r && !eof) {
   long w = write(1, buf + written, (size_t)(r - written));
   if(w <= 0) {
    if(w == -1 && (*__errno_location ()) == 32) {
     eof = 1;
     break;
    }
    perror("write(STDOUT_FILENO)");
    return (*__errno_location ());
   } else {
    written += w;
   }
  }
  Server_write(&server, buf, r);
 }
 Server_destroy(&server);
 return 0;
}

variable_types: struct Server { int sock; struct ServerClientsPool { struct ServerClient { int sock; int mode; int flags; } **clients; unsigned long clientsAllocated; unsigned long clientsCount; 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; } pool; unsigned long connectionPollerThread; }

variable_types: eof char


main

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

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "sc");
if ( v5 == -1 )
break;
if ( v5 == 99 )
{
v3 = 1;
}
else
{
if ( v5 != 115 )
usageAndExit(*argv);
v4 = 1;
}
}
if ( optind > argc )
usageAndExit(*argv);
if ( v4 && v3 || !((unsigned __int8)v4 | (unsigned __int8)v3) )
usageAndExit(*argv);
if ( v4 )
runServerMode((__int64)argv[optind]);
else
runClientMode((char *)argv[optind]);
return 0;
}

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

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "sc");
if ( v5 == -1 )
break;
if ( v5 == 99 )
{
v3 = 1;
}
else
{
if ( v5 != 115 )
func0(*argv);
v4 = 1;
}
}
if ( optind > argc )
func0(*argv);
if ( v4 && v3 || !((unsigned __int8)v4 | (unsigned __int8)v3) )
func0(*argv);
if ( v4 )
func2((__int64)argv[optind]);
else
func1((char *)argv[optind]);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int opt;
 char serverMode = 0;
 char clientMode = 0;
 while((opt = getopt(argc, argv, "sc")) != -1) {
  switch(opt) {
   case 's':
    serverMode = 1;
   break;
   case 'c':
    clientMode = 1;
   break;
   default:
    usageAndExit(argv[0]);
  }
 }
 if(optind > argc)
  usageAndExit(argv[0]);
 if((serverMode && clientMode) || (!serverMode && !clientMode))
  usageAndExit(argv[0]);
 if(serverMode) {
  runServerMode(argv[optind]);
 } else if(clientMode) {
  runClientMode(argv[optind]);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: serverMode char

variable_types: clientMode char


decompiled_code:
void *__fastcall ServerClientsPool__enlarge(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // r12
void *v3; // rbp
void *result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = 2 * v1;
if ( !(2 * v1) )
v2 = 2LL;
v3 = malloc(8 * v2);
result = memset(v3, 0, 8 * v2);
if ( *(_QWORD *)a1 )
result = memcpy(v3, *(const void **)a1, 8 * v1);
*(_QWORD *)a1 = v3;
*(_QWORD *)(a1 + 8) = v2;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // r12
void *v3; // rbp
void *result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = 2 * v1;
if ( !(2 * v1) )
v2 = 2LL;
v3 = malloc(8 * v2);
result = memset(v3, 0, 8 * v2);
if ( *(_QWORD *)a1 )
result = memcpy(v3, *(const void **)a1, 8 * v1);
*(_QWORD *)a1 = v3;
*(_QWORD *)(a1 + 8) = v2;
return result;
}

original_code:
static void ServerClientsPool__enlarge(struct ServerClientsPool *pool) {
 struct ServerClient **newArray;
 size_t newSize = pool->clientsAllocated * 2;
 if(!newSize)
  newSize = 2;
 newArray = (struct ServerClient **)malloc(sizeof(*newArray) * newSize);
 memset(newArray, 0, (sizeof(*newArray) * newSize));
 if(pool->clients)
  memcpy(newArray, pool->clients, pool->clientsAllocated * sizeof(*pool->clients));
 pool->clients = newArray;
 pool->clientsAllocated = newSize;
}

canonical_original_code:
static void ServerClientsPool__enlarge(struct ServerClientsPool *pool) {
 struct ServerClient **newArray;
 unsigned long newSize = pool->clientsAllocated * 2;
 if(!newSize)
  newSize = 2;
 newArray = (struct ServerClient **)malloc(sizeof(*newArray) * newSize);
 memset(newArray, 0, (sizeof(*newArray) * newSize));
 if(pool->clients)
  memcpy(newArray, pool->clients, pool->clientsAllocated * sizeof(*pool->clients));
 pool->clients = newArray;
 pool->clientsAllocated = newSize;
}

variable_types: struct ServerClientsPool { struct ServerClient { int sock; int mode; int flags; } **clients; unsigned long clientsAllocated; unsigned long clientsCount; 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; } *

variable_types:
newSize
unsigned long


decompiled_code:
void *__fastcall ServerClientsPool_init(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(a1 + 24), 0LL);
return ServerClientsPool__enlarge(a1);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(a1 + 24), 0LL);
return func0(a1);
}

original_code:
void ServerClientsPool_init(struct ServerClientsPool *pool) {
 pool->clients = ((void *)0);
 pool->clientsAllocated = 0;
 pool->clientsCount = 0;
 pthread_mutex_init(&pool->mutex, ((void *)0));
 ServerClientsPool__enlarge(pool);
}


decompiled_code:
int __fastcall ServerClientsPool_destroy(__int64 a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
int result; // eax

if ( *(_QWORD *)a1 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
if ( v3 )
{
ServerClient_destroy(v3);
free(*(void **)(*(_QWORD *)a1 + 8 * v2));
}
++v2;
}
while ( *(_QWORD *)(a1 + 8) > v2 );
}
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
result = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
int result; // eax

if ( *(_QWORD *)a1 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
if ( v3 )
{
ServerClient_destroy(v3);
free(*(void **)(*(_QWORD *)a1 + 8 * v2));
}
++v2;
}
while ( *(_QWORD *)(a1 + 8) > v2 );
}
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
result = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
}
return result;
}

original_code:
void ServerClientsPool_destroy(struct ServerClientsPool *pool) {
 size_t i;
 if(!pool->clients)
  return;
 for(i = 0; i < pool->clientsAllocated; i++) {
  if(!pool->clients[i])
   continue;
  ServerClient_destroy(pool->clients[i]);
  free(pool->clients[i]);
 }
 free(pool->clients);
 pool->clients = ((void *)0);
 pool->clientsAllocated = 0;
 pool->clientsCount = 0;
 pthread_mutex_destroy(&pool->mutex);
}

canonical_original_code:
void ServerClientsPool_destroy(struct ServerClientsPool *pool) {
 unsigned long i;
 if(!pool->clients)
  return;
 for(i = 0; i < pool->clientsAllocated; i++) {
  if(!pool->clients[i])
   continue;
  ServerClient_destroy(pool->clients[i]);
  free(pool->clients[i]);
 }
 free(pool->clients);
 pool->clients = ((void *)0);
 pool->clientsAllocated = 0;
 pool->clientsCount = 0;
 pthread_mutex_destroy(&pool->mutex);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall ServerClientsPool_attachClient(_QWORD *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
void *v6; // rbp
__int64 v7; // rcx
_QWORD *v8; // rax
__int64 v9; // rdx
__int64 result; // rax

if ( (unsigned int)fcntl64(a2, 4LL, 2048LL) == -1 )
{
perror("fcntl(sock, F_SETFL, O_NONBLOCK)");
result = (unsigned int)*_errno_location();
}
else
{
if ( (unsigned __int64)(a1[2] + 1LL) > a1[1] )
ServerClientsPool__enlarge((__int64)a1);
v6 = malloc(0xCuLL);
ServerClient_init(v6, a2, a3, a4);
v7 = a1[1];
if ( v7 )
{
v8 = (_QWORD *)*a1;
v9 = 0LL;
while ( *v8 )
{
++v9;
++v8;
if ( v9 == v7 )
goto LABEL_11;
}
*v8 = v6;
}
LABEL_11:
++a1[2];
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
void *v6; // rbp
__int64 v7; // rcx
_QWORD *v8; // rax
__int64 v9; // rdx
__int64 result; // rax

if ( (unsigned int)fcntl64(a2, 4LL, 2048LL) == -1 )
{
perror("fcntl(sock, F_SETFL, O_NONBLOCK)");
result = (unsigned int)*_errno_location();
}
else
{
if ( (unsigned __int64)(a1[2] + 1LL) > a1[1] )
func0((__int64)a1);
v6 = malloc(0xCuLL);
ServerClient_init(v6, a2, a3, a4);
v7 = a1[1];
if ( v7 )
{
v8 = (_QWORD *)*a1;
v9 = 0LL;
while ( *v8 )
{
++v9;
++v8;
if ( v9 == v7 )
goto LABEL_11;
}
*v8 = v6;
}
LABEL_11:
++a1[2];
result = 0LL;
}
return result;
}

original_code:
int ServerClientsPool_attachClient(struct ServerClientsPool *pool, int sock, int mode, int flags) {
 size_t i;
 struct ServerClient *client;
 if(fcntl(sock, 4, 04000) == -1) {
  perror("fcntl(sock, F_SETFL, O_NONBLOCK)");
  return (*__errno_location ());
 }
 if(pool->clientsCount + 1 > pool->clientsAllocated)
  ServerClientsPool__enlarge(pool);
 client = malloc(sizeof(*client));
 ServerClient_init(client, sock, mode, flags);
 for(i = 0; i < pool->clientsAllocated; i++) {
  if(!pool->clients[i]) {
   pool->clients[i] = client;
   break;
  }
 }
 pool->clientsCount++;
 return 0;
}

canonical_original_code:
int ServerClientsPool_attachClient(struct ServerClientsPool *pool, int sock, int mode, int flags) {
 unsigned long i;
 struct ServerClient *client;
 if(fcntl(sock, 4, 04000) == -1) {
  perror("fcntl(sock, F_SETFL, O_NONBLOCK)");
  return (*__errno_location ());
 }
 if(pool->clientsCount + 1 > pool->clientsAllocated)
  ServerClientsPool__enlarge(pool);
 client = malloc(sizeof(*client));
 ServerClient_init(client, sock, mode, flags);
 for(i = 0; i < pool->clientsAllocated; i++) {
  if(!pool->clients[i]) {
   pool->clients[i] = client;
   break;
  }
 }
 pool->clientsCount++;
 return 0;
}

variable_types: mode int

variable_types: flags int

variable_types: struct ServerClient { int sock; int mode; int flags; } *


decompiled_code:
int __fastcall ServerClientsPool_lock(__int64 a1)
{
int result; // eax
int *v2; // rax

result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( result )
{
perror("pthread_mutex_lock()");
v2 = _errno_location();
exit(*v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
int *v2; // rax

result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( result )
{
perror("pthread_mutex_lock()");
v2 = _errno_location();
exit(*v2);
}
return result;
}

original_code:
void ServerClientsPool_lock(struct ServerClientsPool *pool) {
 if(pthread_mutex_lock(&pool->mutex) != 0) {
  perror("pthread_mutex_lock()");
  exit((*__errno_location ()));
 }
}


decompiled_code:
int __fastcall ServerClientsPool_unlock(__int64 a1)
{
int result; // eax
int *v2; // rax

result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
if ( result )
{
perror("pthread_mutex_unlock()");
v2 = _errno_location();
exit(*v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
int *v2; // rax

result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
if ( result )
{
perror("pthread_mutex_unlock()");
v2 = _errno_location();
exit(*v2);
}
return result;
}

original_code:
void ServerClientsPool_unlock(struct ServerClientsPool *pool) {
 if(pthread_mutex_unlock(&pool->mutex) != 0) {
  perror("pthread_mutex_unlock()");
  exit((*__errno_location ()));
 }
}


decompiled_code:
int __fastcall ServerClientsPool_write(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v4; // r12
unsigned __int64 i; // rbx
int *v7; // rax
int v8; // eax

ServerClientsPool_lock((__int64)a1);
v4 = 0LL;
for ( i = 0LL; a1[1] > i; ++i )
{
if ( a1[2] <= v4 )
break;
v7 = *(int **)(*a1 + 8 * i);
if ( v7 )
{
++v4;
if ( write(*v7, a2, a3) == -1 )
{
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
ServerClientsPool__removeClient(a1, *(void **)(*a1 + 8 * i));
}
}
}
return ServerClientsPool_unlock((__int64)a1);
}

original_code:
void ServerClientsPool_write(struct ServerClientsPool *pool, const void *buf, ssize_t size) {
 size_t i;
 ssize_t w;
 size_t count = 0;
 ServerClientsPool_lock(pool);
 for(i = 0; i < pool->clientsAllocated && count < pool->clientsCount; i++) {
  if(!pool->clients[i])
   continue;
  count++;
  w = write(pool->clients[i]->sock, buf, (size_t)size);
  if(w == -1) {
   if((*__errno_location ()) == 4 || (*__errno_location ()) == 11 || (*__errno_location ()) == 11)
    continue;
   ServerClientsPool__removeClient(pool, pool->clients[i]);
  }
 }
 ServerClientsPool_unlock(pool);
}

canonical_original_code:
void ServerClientsPool_write(struct ServerClientsPool *pool, void *buf, long size) {
 unsigned long i;
 long w;
 unsigned long count = 0;
 ServerClientsPool_lock(pool);
 for(i = 0; i < pool->clientsAllocated && count < pool->clientsCount; i++) {
  if(!pool->clients[i])
   continue;
  count++;
  w = write(pool->clients[i]->sock, buf, (unsigned long)size);
  if(w == -1) {
   if((*__errno_location ()) == 4 || (*__errno_location ()) == 11 || (*__errno_location ()) == 11)
    continue;
   ServerClientsPool__removeClient(pool, pool->clients[i]);
  }
 }
 ServerClientsPool_unlock(pool);
}

variable_types:
buf
void *

variable_types: size long

variable_types:
count
unsigned long


decompiled_code:
int __fastcall ServerClient_destroy(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 >= 0 )
result = close(v2);
*a1 = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 >= 0 )
result = close(v2);
*a1 = -1;
return result;
}

original_code:
void ServerClient_destroy(struct ServerClient *client) {
 if(client->sock >= 0)
  close(client->sock);
 client->sock = -1;
}


gettimed

repo: avz/pp

decompiled_code:
double gettimed()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
static double gettimed() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
}

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

return_type: double


decompiled_code:
__int64 __fastcall get_terminal_width(int a1)
{
int v1; // edx
__int64 result; // rax
char v3[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+Ah] [rbp-Eh]

v1 = ioctl(a1, 0x5413uLL, v3);
result = 80LL;
if ( v1 >= 0 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // edx
__int64 result; // rax
char v3[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+Ah] [rbp-Eh]

v1 = ioctl(a1, 0x5413uLL, v3);
result = 80LL;
if ( v1 >= 0 )
result = v4;
return result;
}

original_code:
static size_t get_terminal_width(int fd) {
 size_t width = 80;
 struct winsize wsz;
 if(ioctl(fd, 0x5413, &wsz) < 0) {
 } else {
  width = wsz.ws_col;
 }
 return width;
}

canonical_original_code:
static unsigned long get_terminal_width(int fd) {
 unsigned long width = 80;
 struct winsize wsz;
 if(ioctl(fd, 0x5413, &wsz) < 0) {
 } else {
  width = wsz.ws_col;
 }
 return width;
}

variable_types: fd int

variable_types:
width
unsigned long

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

return_type: unsigned long


checkPtr

repo: awblocker/rowavedt

decompiled_code:
void __fastcall checkPtr(__int64 a1, const char *a2)
{
if ( !a1 )
{
fprintf(stderr, "Error -- %s\n", a2);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, const char *a2)
{
if ( !a1 )
{
fprintf(stderr, "Error -- %s\n", a2);
exit(1);
}
}

original_code:
void checkPtr(const void * ptr, const char * msg)
{
  if (ptr==((void *)0))
  {
    fprintf(stderr, "Error -- %s\n", msg);
    exit(1);
  }
}

canonical_original_code:
void checkPtr(void *ptr, char *msg)
{
  if (ptr==((void *)0))
  {
    fprintf(stderr, "Error -- %s\n", msg);
    exit(1);
  }
}

variable_types:
ptr
void *

variable_types:
msg
char *


arrayMinMax

decompiled_code:
__int64 __fastcall arrayMinMax(double *a1, int a2, double *a3, double *a4)
{
double v4; // xmm0_8
double *v5; // rax
__int64 v6; // rsi
double v7; // xmm0_8

v4 = *a1;
*a3 = *a1;
*a4 = v4;
if ( a2 > 1 )
{
v5 = a1 + 1;
v6 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
do
{
v7 = *v5;
if ( *v5 <= *a4 )
{
if ( *a3 > v7 )
*a3 = v7;
}
else
{
*a4 = v7;
}
++v5;
}
while ( v5 != (double *)v6 );
}
return 0LL;
}

original_code:
int arrayMinMax(double * X, int n, double * min, double * max)
{
  *min = X[0];
  *max = X[0];
  if (n > 1)
  {
    int i;
    for (i=1; i<n; i++)
    {
      if (X[i] > *max)
      {
        *max = X[i];
      }
      else if (X[i] < *min)
      {
        *min = X[i];
      }
    }
  }
  return 0;
}

canonical_original_code:
int arrayMinMax(double *X, int n, double *min, double *max)
{
  *min = X[0];
  *max = X[0];
  if (n > 1)
  {
    int i;
    for (i=1; i<n; i++)
    {
      if (X[i] > *max)
      {
        *max = X[i];
      }
      else if (X[i] < *min)
      {
        *min = X[i];
      }
    }
  }
  return 0;
}

variable_types:
X
double *

variable_types: n int

variable_types:
min
double *

variable_types:
max
double *

variable_types: i int


allocateMatrix

decompiled_code:
__int64 __fastcall allocateMatrix(_QWORD *a1, int a2, int a3)
{
void *v4; // rax
size_t v5; // r14
__int64 v6; // rbx
void **v7; // r12

v4 = malloc(8LL * a2);
*a1 = v4;
if ( !v4 )
return 1LL;
if ( a2 <= 0 )
return 0LL;
v5 = 8LL * a3;
v6 = 0LL;
while ( 1 )
{
v7 = (void **)(*a1 + v6);
*v7 = malloc(v5);
if ( !*(_QWORD *)(*a1 + v6) )
break;
v6 += 8LL;
if ( v6 == 8LL * (unsigned int)a2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2, int a3)
{
void *v4; // rax
size_t v5; // r14
__int64 v6; // rbx
void **v7; // r12

v4 = malloc(8LL * a2);
*a1 = v4;
if ( !v4 )
return 1LL;
if ( a2 <= 0 )
return 0LL;
v5 = 8LL * a3;
v6 = 0LL;
while ( 1 )
{
v7 = (void **)(*a1 + v6);
*v7 = malloc(v5);
if ( !*(_QWORD *)(*a1 + v6) )
break;
v6 += 8LL;
if ( v6 == 8LL * (unsigned int)a2 )
return 0LL;
}
return 1LL;
}

original_code:
int allocateMatrix(double*** matrix, int nRows, int nCols)
{
  int i;
  (*matrix) = malloc(nRows * sizeof(double*));
  if ((*matrix) == ((void *)0))
    return 1;
  for (i=0; i<nRows; i++)
  {
    (*matrix)[i] = malloc(nCols * sizeof(double));
    if ((*matrix)[i] == ((void *)0))
      return 1;
  }
  return 0;
}

canonical_original_code:
int allocateMatrix(double ***matrix, int nRows, int nCols)
{
  int i;
  (*matrix) = malloc(nRows * sizeof(double *));
  if ((*matrix) == ((void *)0))
    return 1;
  for (i=0; i<nRows; i++)
  {
    (*matrix)[i] = malloc(nCols * sizeof(double));
    if ((*matrix)[i] == ((void *)0))
      return 1;
  }
  return 0;
}

variable_types:
matrix
double ***

variable_types: nRows int

variable_types: nCols int


freeMatrix

decompiled_code:
void __fastcall freeMatrix(void **a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx

if ( a3 > 0 )
{
v3 = 8LL * (unsigned int)a3;
v4 = 0LL;
do
{
free(*(void **)((char *)*a1 + v4));
v4 += 8LL;
}
while ( v4 != v3 );
}
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(void **a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx

if ( a3 > 0 )
{
v3 = 8LL * (unsigned int)a3;
v4 = 0LL;
do
{
free(*(void **)((char *)*a1 + v4));
v4 += 8LL;
}
while ( v4 != v3 );
}
free(*a1);
*a1 = 0LL;
}

original_code:
void freeMatrix(double*** matrix, int nRows, int nCols)
{
  int i;
  for (i=0; i<nCols; i++)
  {
    free((*matrix)[i]);
  }
  free(*matrix);
  *matrix = ((void *)0);
}

canonical_original_code:
void freeMatrix(double ***matrix, int nRows, int nCols)
{
  int i;
  for (i=0; i<nCols; i++)
  {
    free((*matrix)[i]);
  }
  free(*matrix);
  *matrix = ((void *)0);
}


bisect

decompiled_code:
double __fastcall bisect(__int64 a1, int a2, int a3, double a4)
{
int v5; // ecx
int v7; // eax
double v8; // xmm0_8

v5 = a3;
if ( a2 > a3 )
return (double)(v5 + a2) * 0.5;
while ( 1 )
{
v7 = (a2 + v5) / 2;
v8 = *(double *)(a1 + 8LL * v7);
if ( v8 > a4 )
{
v5 = v7 - 1;
goto LABEL_5;
}
if ( a4 <= v8 )
return (double)v7;
a2 = v7 + 1;
LABEL_5:
if ( a2 > v5 )
return (double)(v5 + a2) * 0.5;
}
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, int a2, int a3, double a4)
{
int v5; // ecx
int v7; // eax
double v8; // xmm0_8

v5 = a3;
if ( a2 > a3 )
return (double)(v5 + a2) * 0.5;
while ( 1 )
{
v7 = (a2 + v5) / 2;
v8 = *(double *)(a1 + 8LL * v7);
if ( v8 > a4 )
{
v5 = v7 - 1;
goto LABEL_5;
}
if ( a4 <= v8 )
return (double)v7;
a2 = v7 + 1;
LABEL_5:
if ( a2 > v5 )
return (double)(v5 + a2) * 0.5;
}
}

original_code:
double bisect(double x, double data[], int start, int end)
{
  int mid;
  while (start <= end) {
    mid = (start + end)/2;
    if (x < data[mid])
      end = mid - 1;
    else if (x > data[mid])
      start = mid + 1;
    else
      return mid;
  }
  return (double) (start+end)/2;
}

variable_types: x double

variable_types:
data
double []

variable_types: start int

variable_types: end int

variable_types: mid int


decompiled_code:
double __fastcall quantile_int(double *a1, int a2, double a3)
{
if ( *a1 > a3 )
return 0.0;
if ( a3 < a1[a2 - 1] )
return bisect((__int64)a1, 0, a2, a3) + 1.0;
return (double)a2;
}

canonical_decompiled_code:
double __fastcall func6(double *a1, int a2, double a3)
{
if ( *a1 > a3 )
return 0.0;
if ( a3 < a1[a2 - 1] )
return func4((__int64)a1, 0, a2, a3) + 1.0;
return (double)a2;
}

original_code:
double quantile_int(double x, double data[], int n)
{
  if (x < data[0])
    return 0;
  else if (x >= data[n-1])
    return n;
  return (1+bisect(x, data, 0, n));
}


decompiled_code:
__int64 __fastcall compare_dbl(double *a1, double *a2)
{
return (unsigned int)(int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(double *a1, double *a2)
{
return (unsigned int)(int)(*a1 - *a2);
}

original_code:
int compare_dbl(const void * a, const void * b)
{
  return (*(double*)a - *(double*)b);
}

canonical_original_code:
int compare_dbl(void *a, void *b)
{
  return (*(double *)a - *(double *)b);
}

variable_types:
a
void *

variable_types:
b
void *