tokenize

decompiled_code:
char *__fastcall tokenize(char *s)
{
int v1; // eax
char *v2; // r12
int v3; // eax
char *v4; // rbp
char *v5; // rbx
int v6; // er13
size_t v7; // rax

v1 = strlen(s);
v2 = (char *)space((unsigned int)(v1 + 1));
v3 = strlen(s);
v4 = (char *)space((unsigned int)(v3 + 1));
_isoc99_sscanf(s, "%s", v2);
*v4 = 0;
v5 = strtok(v2, "&");
v6 = strlen(v5) + 1;
do
{
strcat(v4, v5);
v5 = strtok(0LL, "&");
}
while ( v5 );
v7 = strlen(v4);
if ( v6 >= 0 && v6 <= v7 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
free(v2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
int v1; // eax
char *v2; // r12
int v3; // eax
char *v4; // rbp
char *v5; // rbx
int v6; // er13
size_t v7; // rax

v1 = strlen(s);
v2 = (char *)space((unsigned int)(v1 + 1));
v3 = strlen(s);
v4 = (char *)space((unsigned int)(v3 + 1));
_isoc99_sscanf(s, "%s", v2);
*v4 = 0;
v5 = strtok(v2, "&");
v6 = strlen(v5) + 1;
do
{
strcat(v4, v5);
v5 = strtok(0LL, "&");
}
while ( v5 );
v7 = strlen(v4);
if ( v6 >= 0 && v6 <= v7 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
free(v2);
return v4;
}

original_code:
void tokenize(char *line, char **seq1, char **seq2) {
  char *pos;
  int cut = -1;
  int i;
  pos = strchr(line, '&');
  if (pos) {
    cut = (int) (pos-line)+1;
    (*seq1) = (char *) space((cut+1)*sizeof(char));
    (*seq2) = (char *) space(((strlen(line)-cut)+2)*sizeof(char));

    if (strchr(pos+1, '&')) nrerror("more than one cut-point in input");
    *pos = '\0';
    (void) sscanf(line, "%s", *seq1);
    (void) sscanf(pos+1, "%s", *seq2);
  } else {
    (*seq1) = (char *) space((strlen(line)+1)*sizeof(char));
    (*seq2) = NULL;
    sscanf(line, "%s", *seq1);
  }

  if (cut > -1) {
    if (cut_point==-1) cut_point = cut;
    else if (cut_point != cut) {
      fprintf(stderr,"cut_point = %d cut = %d\n", cut_point, cut);
      nrerror("Sequence and Structure have different cut points.");
    }
  }
  free(line);
  return;
}

variable_types:
line
char *

variable_types: cut int


repo: marcom/dss-opt

decompiled_code:
const char *__fastcall tokenize(void *ptr)
{
int v1; // eax
const char *v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // er14
int v6; // er12
char v7; // al

v1 = strlen((const char *)ptr);
v2 = (const char *)space((unsigned int)(v1 + 1));
_isoc99_sscanf(ptr, "%s", v2);
v3 = strchr(v2, 38);
if ( v3 )
{
v4 = v3;
v5 = (_DWORD)v3 - (_DWORD)v2 + 1;
v6 = -1;
if ( v5 < strlen(v2) )
v6 = v5;
if ( strchr(v4 + 1, 38) )
nrerror("more than one cut-point in input");
if ( *v4 )
{
do
{
v7 = v4[1];
*v4++ = v7;
}
while ( v7 );
}
if ( v6 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
}
free(ptr);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func2(void *ptr)
{
int v1; // eax
const char *v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // er14
int v6; // er12
char v7; // al

v1 = strlen((const char *)ptr);
v2 = (const char *)space((unsigned int)(v1 + 1));
_isoc99_sscanf(ptr, "%s", v2);
v3 = strchr(v2, 38);
if ( v3 )
{
v4 = v3;
v5 = (_DWORD)v3 - (_DWORD)v2 + 1;
v6 = -1;
if ( v5 < strlen(v2) )
v6 = v5;
if ( strchr(v4 + 1, 38) )
nrerror("more than one cut-point in input");
if ( *v4 )
{
do
{
v7 = v4[1];
*v4++ = v7;
}
while ( v7 );
}
if ( v6 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
}
free(ptr);
return v2;
}

canonical_original_code:
void tokenize(char *line, char **seq1, char **seq2) {
  char *pos;
  int cut = -1;
  int i;
  pos = strchr(line, '&');
  if (pos) {
    cut = (int) (pos-line)+1;
    (*seq1) = (char *) space((cut+1)*sizeof(char));
    (*seq2) = (char *) space(((strlen(line)-cut)+2)*sizeof(char));

    if (strchr(pos+1, '&')) nrerror("more than one cut-point in input");
    *pos = '\0';
    (void) sscanf(line, "%s", *seq1);
    (void) sscanf(pos+1, "%s", *seq2);
  } else {
    (*seq1) = (char *) space((strlen(line)+1)*sizeof(char));
    (*seq2) = NULL;
    sscanf(line, "%s", *seq1);
  }

  if (cut > -1) {
    if (cut_point==-1) cut_point = cut;
    else if (cut_point != cut) {
      fprintf(stderr,"cut_point = %d cut = %d\n", cut_point, cut);
      nrerror("Sequence and Structure have different cut points.");
    }
  }
  free(line);
  return;
}

variable_types:
pos
char *

variable_types: i int

return_type: void


shuffle

repo: marcomorain/shuffle

original_code:
static void shuffle(line_buffer* lines) {
  sranddev();
  int n = ((*lines).n);
  for (int i = 0; i < n - 1; i++) {
    int j = i + rand() / (2147483647 / (n - i) + 1);
    char* t = ((*lines).a[(j)]);
    ((*lines).a[(j)]) = ((*lines).a[(i)]);
    ((*lines).a[(i)]) = t;
  }
}

canonical_original_code:
static void shuffle(struct line_buffer *lines) {
  sranddev();
  int n = ((*lines).n);
  for (int i = 0; i < n - 1; i++) {
    int j = i + rand() / (2147483647 / (n - i) + 1);
    char *t = ((*lines).a[(j)]);
    ((*lines).a[(j)]) = ((*lines).a[(i)]);
    ((*lines).a[(i)]) = t;
  }
}

variable_types: struct line_buffer { unsigned long n; char **a; } *

variable_types: n int

variable_types: j int

variable_types:
t
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h]

v5[1] = 0LL;
v5[0] = 0LL;
v6 = 0LL;
read_lines(stdin, (__int64)v5);
shuffle(v5);
if ( v5[0] )
{
v3 = 0LL;
do
fputs(*(const char **)(v6 + 8 * v3++), stdout);
while ( v5[0] > v3 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h]

v5[1] = 0LL;
v5[0] = 0LL;
v6 = 0LL;
func1(stdin, (__int64)v5);
func2(v5);
if ( v5[0] )
{
v3 = 0LL;
do
fputs(*(const char **)(v6 + 8 * v3++), stdout);
while ( v5[0] > v3 );
}
return 0;
}

original_code:
int main(int argc, char** argv) {
  (void)argc;
  (void)argv;
  line_buffer buffer;
  ((buffer).n = (buffer).m = 0, (buffer).a = 0);
  read_lines(stdin, &buffer);
  shuffle(&buffer);
  for (size_t i=0; i<((buffer).n); i++) {
    fputs(((buffer).a[(i)]), stdout);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  struct line_buffer buffer;
  ((buffer).n = (buffer).m = 0, (buffer).a = 0);
  read_lines(stdin, &buffer);
  shuffle(&buffer);
  for (unsigned long i = 0; i<((buffer).n); i++) {
    fputs(((buffer).a[(i)]), stdout);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct line_buffer { unsigned long n; char **a; }

variable_types:
i
unsigned long

return_type: int


exitmessage

repo: marcotaubmann/tinyjpeg-pthreads

decompiled_code:
void __fastcall __noreturn exitmessage(const char *a1)
{
puts(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
puts(a1);
exit(0);
}

original_code:
static void exitmessage(const char *message)
{
  printf("%s\n", message);
  exit(0);
}

canonical_original_code:
static void exitmessage(char *message)
{
  printf("%s\n", message);
  exit(0);
}

variable_types:
message
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n", 1uLL, 0x42uLL, stderr);
fwrite("option:\n", 1uLL, 8uLL, stderr);
fwrite(" --benchmark - Measure the timing of 1 conversion\n", 1uLL, 0x33uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
fwrite("Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n", 1uLL, 0x42uLL, stderr);
fwrite("option:\n", 1uLL, 8uLL, stderr);
fwrite(" --benchmark - Measure the timing of 1 conversion\n", 1uLL, 0x33uLL, stderr);
exit(1);
}

original_code:
static void usage(void)
{
  fprintf(stderr, "Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n");
  fprintf(stderr, "option:\n");
  fprintf(stderr, "  --benchmark - Measure the timing of 1 conversion\n");
  exit(1);
}

canonical_original_code:
static void usage()
{
  fprintf(stderr, "Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n");
  fprintf(stderr, "option:\n");
  fprintf(stderr, "  --benchmark - Measure the timing of 1 conversion\n");
  exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
__int64 v7; // rax
int i; // er10
int v9; // er9
const char *v10; // rbx
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
__int64 v14; // rcx
const char *v15; // rbp
__int64 v17; // rax
struct timeval v18; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v3 = (unsigned int)argc < 2;
v4 = argc == 2;
if ( argc <= 2 )
usage(argc, argv, envp);
v7 = 1LL;
for ( i = 0; ; i = 1 )
{
v9 = v7;
v10 = argv[v7];
v11 = "--benchmark";
v12 = 12LL;
v13 = v10;
do
{
if ( !v12 )
break;
v3 = *v13 < (unsigned int)*v11;
v4 = *v13++ == *v11++;
--v12;
}
while ( v4 );
LOBYTE(envp) = (!v3 && !v4) - v3;
v14 = v7++;
v3 = 0;
v4 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
break;
}
if ( v9 + 1 >= argc )
usage(v11, v13, envp);
v15 = argv[v14 + 1];
if ( i )
{
gettimeofday(&tv, 0LL);
convert_one_image(v10, v15);
gettimeofday(&v18, 0LL);
v17 = timevaldiff(&tv, &v18);
printf("Decoding finished in %.2fs (%ld ms)\n", (double)(int)v17 / 1000.0, v17);
}
else
{
convert_one_image(v10, argv[v14 + 1]);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
__int64 v7; // rax
int i; // er10
int v9; // er9
const char *v10; // rbx
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
__int64 v14; // rcx
const char *v15; // rbp
__int64 v17; // rax
struct timeval v18; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v3 = (unsigned int)argc < 2;
v4 = argc == 2;
if ( argc <= 2 )
func4(argc, argv, envp);
v7 = 1LL;
for ( i = 0; ; i = 1 )
{
v9 = v7;
v10 = argv[v7];
v11 = "--benchmark";
v12 = 12LL;
v13 = v10;
do
{
if ( !v12 )
break;
v3 = *v13 < (unsigned int)*v11;
v4 = *v13++ == *v11++;
--v12;
}
while ( v4 );
LOBYTE(envp) = (!v3 && !v4) - v3;
v14 = v7++;
v3 = 0;
v4 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
break;
}
if ( v9 + 1 >= argc )
func4(v11, v13, envp);
v15 = argv[v14 + 1];
if ( i )
{
gettimeofday(&tv, 0LL);
func7(v10, v15);
gettimeofday(&v18, 0LL);
v17 = timevaldiff(&tv, &v18);
printf("Decoding finished in %.2fs (%ld ms)\n", (double)(int)v17 / 1000.0, v17);
}
else
{
func7(v10, argv[v14 + 1]);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  char *output_filename, *input_filename;
  timer start, finish;
  long elapsed;
  int current_argument;
  int benchmark_mode = 0;
  if (argc < 3)
    usage();
  current_argument = 1;
  while (1)
  {
    if (strcmp(argv[current_argument], "--benchmark")==0)
      benchmark_mode = 1;
    else
      break;
    current_argument++;
  }
  if (argc < current_argument+2)
    usage();
  input_filename = argv[current_argument];
  output_filename = argv[current_argument+1];
  if(benchmark_mode)
    gettimeofday(&start, ((void *)0));;
  convert_one_image(input_filename, output_filename);
  if(benchmark_mode) {
    gettimeofday(&finish, ((void *)0));;
    elapsed = timevaldiff(&start, &finish);
    printf("Decoding finished in %.2fs (%ld ms)\n", (double)elapsed/1000, elapsed);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *output_filename; char *input_filename;
  struct timeval start; struct timeval finish;
  long elapsed;
  int current_argument;
  int benchmark_mode = 0;
  if (argc < 3)
    usage();
  current_argument = 1;
  while (1)
  {
    if (strcmp(argv[current_argument], "--benchmark")==0)
      benchmark_mode = 1;
    else
      break;
    current_argument++;
  }
  if (argc < current_argument+2)
    usage();
  input_filename = argv[current_argument];
  output_filename = argv[current_argument+1];
  if(benchmark_mode)
    gettimeofday(&start, ((void *)0));;
  convert_one_image(input_filename, output_filename);
  if(benchmark_mode) {
    gettimeofday(&finish, ((void *)0));;
    elapsed = timevaldiff(&start, &finish);
    printf("Decoding finished in %.2fs (%ld ms)\n", (double)elapsed/1000, elapsed);
  }
  return 0;
}

variable_types:
argv
char *[]

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

variable_types: elapsed long


exitmessage

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
puts(a1);
exit(0);
}


decompiled_code:
int __fastcall idct_data_buffer_init(__int64 a1)
{
pthread_mutex_t *v2; // rax
pthread_cond_t *v3; // rdi

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v2;
if ( !v2 )
exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
pthread_mutex_init(v2, 0LL);
v3 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v3;
if ( !v3 )
exitmessage("Not enough memory to alloc new cond for idct buffer\n");
return pthread_cond_init(v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
pthread_mutex_t *v2; // rax
pthread_cond_t *v3; // rdi

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v2;
if ( !v2 )
func0("Not enough memory to alloc new mutex for idct buffer\n");
pthread_mutex_init(v2, 0LL);
v3 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v3;
if ( !v3 )
func0("Not enough memory to alloc new cond for idct buffer\n");
return pthread_cond_init(v3, 0LL);
}

original_code:
void idct_data_buffer_init(struct idct_data_buffer *b){
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for idct buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

canonical_original_code:
void idct_data_buffer_init(struct idct_data_buffer *b){
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (union pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for idct buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

variable_types: struct idct_data_buffer { int elements; struct idct_data_buffer_element { enum element_type { DATA=0, FINISH=1 } type; struct idct_data { short DCT_Y[4][64]; short DCT_C[2][64]; } idata; struct idct_data_buffer_element *next; } *first; struct idct_data_buffer_element *last; 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; } *cond; } *

user_defined_types: struct idct_data_buffer { int elements; struct idct_data_buffer_element *first; struct idct_data_buffer_element *last; union pthread_mutex_t *mutex; union pthread_cond_t *cond; }

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; }

user_defined_types: struct idct_data_buffer_element { enum element_type type; struct idct_data idata; struct idct_data_buffer_element *next; }


decompiled_code:
void __fastcall idct_data_buffer_destroy(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 3));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 3));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 4));
free(ptr);
}

original_code:
void idct_data_buffer_destroy(struct idct_data_buffer *b){
 pthread_mutex_destroy(b->mutex);
 pthread_cond_destroy(b->cond);
 free(b);
}

user_defined_types: struct idct_data { short DCT_Y[4][64]; short DCT_C[2][64]; }

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; }


decompiled_code:
int __fastcall idct_data_buffer_add(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 776) = 0LL;
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24));
if ( *(_DWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 776LL) = a2;
else
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
pthread_cond_signal(*(pthread_cond_t **)(a1 + 32));
return pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 776) = 0LL;
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24));
if ( *(_DWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 776LL) = a2;
else
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
pthread_cond_signal(*(pthread_cond_t **)(a1 + 32));
return pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24));
}

original_code:
void idct_data_buffer_add(
 struct idct_data_buffer *b,
 struct idct_data_buffer_element *e )
{
 e->next = ((void *)0);
 pthread_mutex_lock(b->mutex);
 if(b->elements == 0){
  b->first = e;
  b->last = e;
 } else {
  b->last->next = e;
  b->last = e;
 }
 b->elements++;
 pthread_cond_signal(b->cond);
 pthread_mutex_unlock(b->mutex);
}

canonical_original_code:
void idct_data_buffer_add(struct idct_data_buffer *b, struct idct_data_buffer_element *e)
{
 e->next = ((void *)0);
 pthread_mutex_lock(b->mutex);
 if(b->elements == 0){
  b->first = e;
  b->last = e;
 } else {
  b->last->next = e;
  b->last = e;
 }
 b->elements++;
 pthread_cond_signal(b->cond);
 pthread_mutex_unlock(b->mutex);
}

variable_types:
e
struct idct_data_buffer_element *


decompiled_code:
__int64 __fastcall idct_data_buffer_extract(int *a1)
{
int i; // eax
__int64 v2; // rbp

pthread_mutex_lock(*((pthread_mutex_t **)a1 + 3));
for ( i = *a1; !*a1; i = *a1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 4), *((pthread_mutex_t **)a1 + 3));
v2 = *((_QWORD *)a1 + 1);
if ( i == 1 )
{
*((_QWORD *)a1 + 1) = 0LL;
*((_QWORD *)a1 + 2) = 0LL;
}
else
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v2 + 776);
}
*(_QWORD *)(v2 + 776) = 0LL;
--*a1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 3));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
int i; // eax
__int64 v2; // rbp

pthread_mutex_lock(*((pthread_mutex_t **)a1 + 3));
for ( i = *a1; !*a1; i = *a1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 4), *((pthread_mutex_t **)a1 + 3));
v2 = *((_QWORD *)a1 + 1);
if ( i == 1 )
{
*((_QWORD *)a1 + 1) = 0LL;
*((_QWORD *)a1 + 2) = 0LL;
}
else
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v2 + 776);
}
*(_QWORD *)(v2 + 776) = 0LL;
--*a1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 3));
return v2;
}

original_code:
struct idct_data_buffer_element* idct_data_buffer_extract(struct idct_data_buffer *b){
 struct idct_data_buffer_element *e;
 pthread_mutex_lock(b->mutex);
 while (b->elements == 0) {
  pthread_cond_wait(b->cond, b->mutex);
 }
 e = b->first;
 if(b->elements == 1) {
  b->first = ((void *)0);
  b->last = ((void *)0);
 } else {
  b->first = b->first->next;
 }
 e->next = ((void *)0);
 b->elements--;
 pthread_mutex_unlock(b->mutex);
 return e;
}

canonical_original_code:
struct idct_data_buffer_element *idct_data_buffer_extract(struct idct_data_buffer *b){
 struct idct_data_buffer_element *e;
 pthread_mutex_lock(b->mutex);
 while (b->elements == 0) {
  pthread_cond_wait(b->cond, b->mutex);
 }
 e = b->first;
 if(b->elements == 1) {
  b->first = ((void *)0);
  b->last = ((void *)0);
 } else {
  b->first = b->first->next;
 }
 e->next = ((void *)0);
 b->elements--;
 pthread_mutex_unlock(b->mutex);
 return e;
}

variable_types: struct idct_data_buffer { int elements; struct idct_data_buffer_element *first; struct idct_data_buffer_element *last; 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; } *cond; } *

variable_types: struct idct_data_buffer_element { enum element_type { DATA=0, FINISH=1 } type; struct idct_data { short DCT_Y[4][64]; short DCT_C[2][64]; } idata; struct idct_data_buffer_element *next; } *


decompiled_code:
int __fastcall yuv_data_buffer_init(__int64 a1)
{
pthread_mutex_t *v2; // rax
pthread_cond_t *v3; // rdi

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v2;
if ( !v2 )
exitmessage("Not enough memory to alloc new mutex for yuv buffer\n");
pthread_mutex_init(v2, 0LL);
v3 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v3;
if ( !v3 )
exitmessage("Not enough memory to alloc new cond for yuv buffer\n");
return pthread_cond_init(v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
pthread_mutex_t *v2; // rax
pthread_cond_t *v3; // rdi

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v2;
if ( !v2 )
func0("Not enough memory to alloc new mutex for yuv buffer\n");
pthread_mutex_init(v2, 0LL);
v3 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v3;
if ( !v3 )
func0("Not enough memory to alloc new cond for yuv buffer\n");
return pthread_cond_init(v3, 0LL);
}

original_code:
void yuv_data_buffer_init(struct yuv_data_buffer *b) {
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for yuv buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for yuv buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

canonical_original_code:
void yuv_data_buffer_init(struct yuv_data_buffer *b) {
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for yuv buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (union pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for yuv buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

variable_types: struct yuv_data_buffer { int elements; struct yuv_data_buffer_element { enum element_type { DATA=0, FINISH=1 } type; struct yuv_data { unsigned char Y[-1]; } yuvdata; struct yuv_data_buffer_element *next; } *first; struct yuv_data_buffer_element *last; 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; } *cond; } *

user_defined_types: struct yuv_data_buffer { int elements; struct yuv_data_buffer_element *first; struct yuv_data_buffer_element *last; union pthread_mutex_t *mutex; union pthread_cond_t *cond; }

user_defined_types: struct yuv_data_buffer_element { enum element_type type; struct yuv_data yuvdata; struct yuv_data_buffer_element *next; }


decompiled_code:
void __fastcall yuv_data_buffer_destroy(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 3));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 3));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 4));
free(ptr);
}

original_code:
void yuv_data_buffer_destroy(struct yuv_data_buffer *b){
 pthread_mutex_destroy(b->mutex);
 pthread_cond_destroy(b->cond);
 free(b);
}

user_defined_types: struct yuv_data { unsigned char Y[-1]; }


decompiled_code:
int __fastcall yuv_data_buffer_add(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 392) = 0LL;
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24));
if ( *(_DWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 392LL) = a2;
else
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
pthread_cond_signal(*(pthread_cond_t **)(a1 + 32));
return pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 392) = 0LL;
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24));
if ( *(_DWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 392LL) = a2;
else
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
pthread_cond_signal(*(pthread_cond_t **)(a1 + 32));
return pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24));
}

original_code:
void yuv_data_buffer_add(
 struct yuv_data_buffer *b,
 struct yuv_data_buffer_element *e )
{
 e->next = ((void *)0);
 pthread_mutex_lock(b->mutex);
 if(b->elements == 0){
  b->first = e;
  b->last = e;
 } else {
  b->last->next = e;
  b->last = e;
 }
 b->elements++;
 pthread_cond_signal(b->cond);
 pthread_mutex_unlock(b->mutex);
}

canonical_original_code:
void yuv_data_buffer_add(struct yuv_data_buffer *b, struct yuv_data_buffer_element *e)
{
 e->next = ((void *)0);
 pthread_mutex_lock(b->mutex);
 if(b->elements == 0){
  b->first = e;
  b->last = e;
 } else {
  b->last->next = e;
  b->last = e;
 }
 b->elements++;
 pthread_cond_signal(b->cond);
 pthread_mutex_unlock(b->mutex);
}

variable_types:
e
struct yuv_data_buffer_element *


decompiled_code:
__int64 __fastcall yuv_data_buffer_extract(int *a1)
{
int i; // eax
__int64 v2; // rbp

pthread_mutex_lock(*((pthread_mutex_t **)a1 + 3));
for ( i = *a1; !*a1; i = *a1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 4), *((pthread_mutex_t **)a1 + 3));
v2 = *((_QWORD *)a1 + 1);
if ( i == 1 )
{
*((_QWORD *)a1 + 1) = 0LL;
*((_QWORD *)a1 + 2) = 0LL;
}
else
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v2 + 392);
}
*a1 = i - 1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 3));
*(_QWORD *)(v2 + 392) = 0LL;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1)
{
int i; // eax
__int64 v2; // rbp

pthread_mutex_lock(*((pthread_mutex_t **)a1 + 3));
for ( i = *a1; !*a1; i = *a1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 4), *((pthread_mutex_t **)a1 + 3));
v2 = *((_QWORD *)a1 + 1);
if ( i == 1 )
{
*((_QWORD *)a1 + 1) = 0LL;
*((_QWORD *)a1 + 2) = 0LL;
}
else
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v2 + 392);
}
*a1 = i - 1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 3));
*(_QWORD *)(v2 + 392) = 0LL;
return v2;
}

original_code:
struct yuv_data_buffer_element* yuv_data_buffer_extract(struct yuv_data_buffer *b){
 struct yuv_data_buffer_element *e;
 pthread_mutex_lock(b->mutex);
 while (b->elements == 0) {
  pthread_cond_wait(b->cond, b->mutex);
 }
 e = b->first;
 if(b->elements == 1) {
  b->first = ((void *)0);
  b->last = ((void *)0);
 } else {
  b->first = b->first->next;
 }
 b->elements--;
 pthread_mutex_unlock(b->mutex);
 e->next = ((void *)0);
 return e;
}

canonical_original_code:
struct yuv_data_buffer_element *yuv_data_buffer_extract(struct yuv_data_buffer *b){
 struct yuv_data_buffer_element *e;
 pthread_mutex_lock(b->mutex);
 while (b->elements == 0) {
  pthread_cond_wait(b->cond, b->mutex);
 }
 e = b->first;
 if(b->elements == 1) {
  b->first = ((void *)0);
  b->last = ((void *)0);
 } else {
  b->first = b->first->next;
 }
 b->elements--;
 pthread_mutex_unlock(b->mutex);
 e->next = ((void *)0);
 return e;
}

variable_types: struct yuv_data_buffer { int elements; struct yuv_data_buffer_element *first; struct yuv_data_buffer_element *last; 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; } *cond; } *

variable_types: struct yuv_data_buffer_element { enum element_type { DATA=0, FINISH=1 } type; struct yuv_data { unsigned char Y[-1]; } yuvdata; struct yuv_data_buffer_element *next; } *


decompiled_code:
void *tinyjpeg_get_errorstring()
{
return &error_string;
}

canonical_decompiled_code:
void *func13()
{
return &error_string;
}

original_code:
const char *tinyjpeg_get_errorstring() {
  return error_string;
}

return_type: char *


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

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = a2 - 1;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 8) = v2;
return pthread_mutex_init(v2, 0LL);
}

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

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = a2 - 1;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 8) = v2;
return pthread_mutex_init(v2, 0LL);
}

original_code:
void chunk_distributor_init (chunk_distributor_t *c, int nr_elements) {
 c->next_element = 0;
 c->last_element = nr_elements - 1;
 c->mutex = malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(c->mutex, ((void *)0));
}

canonical_original_code:
void chunk_distributor_init(struct chunk_distributor *c, int nr_elements) {
 c->next_element = 0;
 c->last_element = nr_elements - 1;
 c->mutex = malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(c->mutex, ((void *)0));
}

variable_types: struct chunk_distributor { int next_element; int last_element; 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; } *

user_defined_types: struct chunk_distributor { int next_element; int last_element; union pthread_mutex_t *mutex; }


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
int min(int a, int b) {
 return (a<b)?a:b;
}

variable_types: a int

variable_types: b int


decompiled_code:
void __fastcall chunk_distributor_destroy(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 1));
free(ptr);
}

original_code:
void chunk_distributor_destroy(chunk_distributor_t *c){
 pthread_mutex_destroy(c->mutex);
 free(c);
}

canonical_original_code:
void chunk_distributor_destroy(struct chunk_distributor *c){
 pthread_mutex_destroy(c->mutex);
 free(c);
}


original_code:
static int get_next_huffman_code(struct jdec_task *hdata, struct huffman_table *huffman_table)
{
  int value, hcode;
  unsigned int extra_nbits, nbits;
  uint16_t *slowtable;
  do { do { while (hdata->nbits_in_reservoir<(9)) { unsigned char c; if (hdata->stream >= hdata->stream_end) return -1; c = *hdata->stream++; hdata->reservoir <<= 8; if (c == 0xff && *hdata->stream == 0x00) hdata->stream++; hdata->reservoir |= c; hdata->nbits_in_reservoir+=8; } } while(0);; hcode = ((hdata->reservoir)>>(hdata->nbits_in_reservoir-(9))); } while(0);;
  value = huffman_table->lookup[hcode];
  if (value >= 0)
  {
    unsigned int code_size = huffman_table->code_size[value];
    do { hdata->nbits_in_reservoir -= (code_size); hdata->reservoir &= ((1U<<hdata->nbits_in_reservoir)-1); } while(0);;
    return value;
  }
  for (extra_nbits=0; extra_nbits<16-9; extra_nbits++)
  {
    nbits = 9 + 1 + extra_nbits;
    do { do { while (hdata->nbits_in_reservoir<(nbits)) { unsigned char c; if (hdata->stream >= hdata->stream_end) return -1; c = *hdata->stream++; hdata->reservoir <<= 8; if (c == 0xff && *hdata->stream == 0x00) hdata->stream++; hdata->reservoir |= c; hdata->nbits_in_reservoir+=8; } } while(0);; hcode = ((hdata->reservoir)>>(hdata->nbits_in_reservoir-(nbits))); } while(0);;
    slowtable = huffman_table->slowtable[extra_nbits];
    while (slowtable[0]) {
      if (slowtable[0] == hcode) {
        do { hdata->nbits_in_reservoir -= (nbits); hdata->reservoir &= ((1U<<hdata->nbits_in_reservoir)-1); } while(0);;
        return slowtable[1];
      }
      slowtable+=2;
    }
  }
  return 0;
}

canonical_original_code:
static int get_next_huffman_code(struct jdec_task *hdata, struct huffman_table *huffman_table)
{
  int value; int hcode;
  unsigned int extra_nbits; unsigned int nbits;
  unsigned short *slowtable;
  do { do { while (hdata->nbits_in_reservoir<(9)) { unsigned char c; if (hdata->stream >= hdata->stream_end) return -1; c = *hdata->stream++; hdata->reservoir <<= 8; if (c == 0xff && *hdata->stream == 0x00) hdata->stream++; hdata->reservoir |= c; hdata->nbits_in_reservoir+=8; } } while(0);; hcode = ((hdata->reservoir)>>(hdata->nbits_in_reservoir-(9))); } while(0);;
  value = huffman_table->lookup[hcode];
  if (value >= 0)
  {
    unsigned int code_size = huffman_table->code_size[value];
    do { hdata->nbits_in_reservoir -= (code_size); hdata->reservoir &= ((1U<<hdata->nbits_in_reservoir)-1); } while(0);;
    return value;
  }
  for (extra_nbits=0; extra_nbits<16-9; extra_nbits++)
  {
    nbits = 9 + 1 + extra_nbits;
    do { do { while (hdata->nbits_in_reservoir<(nbits)) { unsigned char c; if (hdata->stream >= hdata->stream_end) return -1; c = *hdata->stream++; hdata->reservoir <<= 8; if (c == 0xff && *hdata->stream == 0x00) hdata->stream++; hdata->reservoir |= c; hdata->nbits_in_reservoir+=8; } } while(0);; hcode = ((hdata->reservoir)>>(hdata->nbits_in_reservoir-(nbits))); } while(0);;
    slowtable = huffman_table->slowtable[extra_nbits];
    while (slowtable[0]) {
      if (slowtable[0] == hcode) {
        do { hdata->nbits_in_reservoir -= (nbits); hdata->reservoir &= ((1U<<hdata->nbits_in_reservoir)-1); } while(0);;
        return slowtable[1];
      }
      slowtable+=2;
    }
  }
  return 0;
}

variable_types: struct jdec_task { int id; int mcus_posx; unsigned char *stream_begin; unsigned int stream_length; unsigned char *stream; unsigned int reservoir; } *

variable_types: struct huffman_table { short lookup[-1]; unsigned char code_size[-1]; unsigned short slowtable[-1][256]; } *

variable_types: value int

variable_types: hcode int

variable_types:
nbits
unsigned int

variable_types:
slowtable
unsigned short *

variable_types:
c
unsigned char


timevaldiff

decompiled_code:
__int64 __fastcall timevaldiff(_QWORD *a1, _QWORD *a2)
{
return (a2[1] - a1[1]) / 1000LL + 1000LL * (*a2 - *a1);
}

original_code:
long timevaldiff(timer *start, timer *finish){
  long msec;
  msec = (finish->tv_sec - start->tv_sec)*1000;
  msec += (finish->tv_usec - start->tv_usec)/1000;
  return msec;
}

canonical_original_code:
long timevaldiff(struct timeval *start, struct timeval *finish){
  long msec;
  msec = (finish->tv_sec - start->tv_sec)*1000;
  msec += (finish->tv_usec - start->tv_usec)/1000;
  return msec;
}

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

variable_types:
finish
struct timeval *

variable_types: msec long

return_type: long


printtime

decompiled_code:
int __fastcall printtime(const char *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rax

v3 = timevaldiff(a2, a3);
return printf("%s finished in %.2fs (%ld ms)\n", a1, (double)(int)v3 / 1000.0, v3);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rax

v3 = func0(a2, a3);
return printf("%s finished in %.2fs (%ld ms)\n", a1, (double)(int)v3 / 1000.0, v3);
}

original_code:
void printtime(char *action, timer *start, timer *finish) {
  long elapsed = 0;
  elapsed = timevaldiff(start, finish);
  printf("%s finished in %.2fs (%ld ms)\n", action, (double)elapsed/1000, elapsed);
}

canonical_original_code:
void printtime(char *action, struct timeval *start, struct timeval *finish) {
  long elapsed = 0;
  elapsed = timevaldiff(start, finish);
  printf("%s finished in %.2fs (%ld ms)\n", action, (double)elapsed/1000, elapsed);
}

variable_types:
action
char *

variable_types: elapsed long

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


clamp

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

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

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

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

original_code:
static unsigned char clamp(int i)
{
  if (i<0)
    return 0;
  else if (i>255)
    return 255;
  else
    return i;
}

variable_types: i int

return_type: unsigned char


main

repo: marekrei/convertvec

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

if ( argc <= 3 )
{
puts("USAGE: convertvec method input_path output_path");
puts("Method is either bin2txt or txt2bin");
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "bin2txt") )
{
bin2txt(argv[2], argv[3]);
}
else if ( !strcmp(v3, "txt2bin") )
{
txt2bin(argv[2], argv[3]);
}
else
{
printf("Unknown method: %s\n", v3);
}
}
return 0;
}

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

if ( argc <= 3 )
{
puts("USAGE: convertvec method input_path output_path");
puts("Method is either bin2txt or txt2bin");
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "bin2txt") )
{
func8(argv[2], argv[3]);
}
else if ( !strcmp(v3, "txt2bin") )
{
func7(argv[2], argv[3]);
}
else
{
printf("Unknown method: %s\n", v3);
}
}
return 0;
}

original_code:
int main(int argc, char **argv) {
 if (argc < 4) {
  printf("USAGE: convertvec method input_path output_path\n");
  printf("Method is either bin2txt or txt2bin\n");
  return 0;
 }
 if(strcmp(argv[1], "bin2txt") == 0)
  bin2txt(argv[2], argv[3]);
 else if(strcmp(argv[1], "txt2bin") == 0)
  txt2bin(argv[2], argv[3]);
 else
  printf("Unknown method: %s\n", argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: mariokonrad/grib

decompiled_code:
__int64 __fastcall grib1_write_raw(const char *a1, unsigned int a2, unsigned int (__fastcall *a3)(const char *, __int64, __int64), __int64 a4)
{
char v7[43]; // [rsp+1h] [rbp-2Bh] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
if ( a3("GRIB", 4LL, a4) != 4 )
return 0xFFFFFFFFLL;
set_bits(v7, a2 + 12, 0LL, 24LL);
if ( a3(v7, 3LL, a4) != 3 )
return 0xFFFFFFFFLL;
v7[0] = 1;
if ( a3(v7, 1LL, a4) != 1 )
return 0xFFFFFFFFLL;
if ( a3(a1, a2, a4) == a2 )
return (unsigned int)-(a3("7777", 4LL, a4) != 4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2, unsigned int (__fastcall *a3)(const char *, __int64, __int64), __int64 a4)
{
char v7[43]; // [rsp+1h] [rbp-2Bh] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
if ( a3("GRIB", 4LL, a4) != 4 )
return 0xFFFFFFFFLL;
set_bits(v7, a2 + 12, 0LL, 24LL);
if ( a3(v7, 3LL, a4) != 3 )
return 0xFFFFFFFFLL;
v7[0] = 1;
if ( a3(v7, 1LL, a4) != 1 )
return 0xFFFFFFFFLL;
if ( a3(a1, a2, a4) == a2 )
return (unsigned int)-(a3("7777", 4LL, a4) != 4);
return 0xFFFFFFFFLL;
}

original_code:
int grib1_write_raw(unsigned char * buf, unsigned int len, int (*write_func)(const void *, unsigned int, void *), void * ptr)
{
 const char * HEAD = "GRIB";
 const char * TAIL = "7777";
 unsigned char tmp[3];
 if (write_func == ((void *)0)) {
  return -1;
 }
 if (write_func(HEAD, 4, ptr) != 4) {
  return -1;
 }
 set_bits(tmp, len + 12, 0, 24);
 if (write_func(tmp, 3, ptr) != 3) {
  return -1;
 }
 tmp[0] = 1;
 if (write_func(tmp, 1, ptr) != 1) {
  return -1;
 }
 if (write_func(buf, len, ptr) != len) {
  return -1;
 }
 if (write_func(TAIL, 4, ptr) != 4) {
  return -1;
 }
 return 0;
}

canonical_original_code:
int grib1_write_raw(unsigned char *buf, unsigned int len, int (*write_func)(void *, unsigned int, void *), void *ptr)
{
 char *HEAD = "GRIB";
 char *TAIL = "7777";
 unsigned char tmp[3];
 if (write_func == ((void *)0)) {
  return -1;
 }
 if (write_func(HEAD, 4, ptr) != 4) {
  return -1;
 }
 set_bits(tmp, len + 12, 0, 24);
 if (write_func(tmp, 3, ptr) != 3) {
  return -1;
 }
 tmp[0] = 1;
 if (write_func(tmp, 1, ptr) != 1) {
  return -1;
 }
 if (write_func(buf, len, ptr) != len) {
  return -1;
 }
 if (write_func(TAIL, 4, ptr) != 4) {
  return -1;
 }
 return 0;
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
ptr
void *

variable_types:
HEAD
char *

variable_types:
TAIL
char *

variable_types:
tmp
unsigned char [3]


decompiled_code:
__int64 __fastcall grib1_write(__int64 a1, __int64 a2)
{
return (unsigned int)-(a1 == 0 || a2 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return (unsigned int)-(a1 == 0 || a2 == 0);
}

original_code:
int grib1_write(GRIBRecord * grib, int (*write_func)(const void *, unsigned int, void *), void * ptr)
{
 if (grib == ((void *)0)) {
  return -1;
 }
 if (write_func == ((void *)0)) {
  return -1;
 }
 return 0;
}

canonical_original_code:
int grib1_write(struct GRIBRecord *grib, int (*write_func)(void *, unsigned int, void *), void *ptr)
{
 if (grib == ((void *)0)) {
  return -1;
 }
 if (write_func == ((void *)0)) {
  return -1;
 }
 return 0;
}

variable_types: struct GRIBRecord { int total_len; int pds_len; int pds_ext_len; int gds_len; int bds_len; int ed_num; int table_ver; int center_id; int gen_proc; int grid_type; int param; int level_type; int lvl1; int lvl2; int fcst_units; int p1; int p2; int t_range; int navg; int nmiss; int sub_center_id; int bds_flag; int pack_width; int gds_included; int bms_included; int yr; int mo; int dy; int time; int offset; int D; int data_rep; int nx; int ny; int rescomp; int scan_mode; int proj; double slat; double slon; double elat; double elon; double lainc; double loinc; double olon; int xlen; int ylen; unsigned char *buffer; unsigned char *pds_ext; double ref_val; double **gridpoints; int ngy; } *


decompiled_code:
double __fastcall ibm2real(__int64 a1, unsigned int a2)
{
double v2; // rbx
int v4; // [rsp+4h] [rbp-24h] BYREF
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

get_bits(a1, v6, a2, 1LL);
get_bits(a1, &v5, a2 + 1, 7LL);
get_bits(a1, &v4, a2 + 8, 24LL);
if ( v6[0] )
v2 = (double)-v4;
else
v2 = (double)v4;
return v2 * 0.00000005960464477539062 * pow(16.0, (double)v5 - 64.0);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, unsigned int a2)
{
double v2; // rbx
int v4; // [rsp+4h] [rbp-24h] BYREF
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

get_bits(a1, v6, a2, 1LL);
get_bits(a1, &v5, a2 + 1, 7LL);
get_bits(a1, &v4, a2 + 8, 24LL);
if ( v6[0] )
v2 = (double)-v4;
else
v2 = (double)v4;
return v2 * 0.00000005960464477539062 * pow(16.0, (double)v5 - 64.0);
}

original_code:
double ibm2real(const unsigned char * buf, unsigned int off)
{
 int s;
 int e;
 int b;
 get_bits(buf, &s, off + 0, 1);
 get_bits(buf, &e, off + 1, 7);
 get_bits(buf, &b, off + 8, 24);
 return pow(2.0, -24.0) * (double)(s ? -b : b) * pow(16.0, (double)e - 64);
}

canonical_original_code:
double ibm2real(unsigned char *buf, unsigned int off)
{
 int s;
 int e;
 int b;
 get_bits(buf, &s, off + 0, 1);
 get_bits(buf, &e, off + 1, 7);
 get_bits(buf, &b, off + 8, 24);
 return pow(2.0, -24.0) * (double)(s ? -b : b) * pow(16.0, (double)e - 64);
}

variable_types:
off
unsigned int

variable_types: s int

variable_types: e int

variable_types: b int

return_type: double


original_code:
int32_t ieee2ibm(double ieee)
{
 int32_t ibm_real = 0;
 unsigned char * ir = (unsigned char *)&ibm_real;
 int s = 0;
 int b = 0;
 int e = 64;
 const double full = 0xffffff;
 unsigned int off = 0;
 if (ieee != 0.0) {
  if (ieee < 0.0) {
   s = 1;
   ieee = -ieee;
  }
  ieee /= pow(2.0, -24.0);
  while (e > 0 && ieee < full) {
   ieee *= 16.0;
   e--;
  }
  while (ieee > full) {
   ieee /= 16.0;
   e++;
  }
  b = ieee + 0.5;
  set_bits(ir, s, off + 0, 1);
  set_bits(ir, e, off + 1, 7);
  set_bits(ir, b, off + 8, 24);
 }
 return ibm_real;
}

canonical_original_code:
int ieee2ibm(double ieee)
{
 int ibm_real = 0;
 unsigned char *ir = (unsigned char *)&ibm_real;
 int s = 0;
 int b = 0;
 int e = 64;
 double full = 0xffffff;
 unsigned int off = 0;
 if (ieee != 0.0) {
  if (ieee < 0.0) {
   s = 1;
   ieee = -ieee;
  }
  ieee /= pow(2.0, -24.0);
  while (e > 0 && ieee < full) {
   ieee *= 16.0;
   e--;
  }
  while (ieee > full) {
   ieee /= 16.0;
   e++;
  }
  b = ieee + 0.5;
  set_bits(ir, s, off + 0, 1);
  set_bits(ir, e, off + 1, 7);
  set_bits(ir, b, off + 8, 24);
 }
 return ibm_real;
}

variable_types: ieee double

variable_types:
ir
unsigned char *

variable_types: full double


original_code:
int get_bits(const unsigned char * buf, int * loc, size_t off, size_t bits)
{
 unsigned char bmask;
 int lmask;
 int temp;
 size_t buf_size = sizeof(unsigned char) * 8;
 size_t loc_size = sizeof(int) * 8;
 size_t wskip;
 int rshift;
 size_t n;
 if (bits == 0) return 0;
 if (bits > loc_size) {
  fprintf(stderr,"Error: unpacking %d bits into a %d-bit field\n", bits, loc_size);
  return -1;
 } else {
  bmask = 1;
  for (n = 1; n < buf_size; n++) {
   bmask <<= 1;
   bmask++;
  }
  lmask = 1;
  for (n = 1; n < loc_size; n++) {
   lmask <<= 1;
   lmask++;
  }
  wskip = off / buf_size;
  rshift = buf_size - (off % buf_size) - bits;
  if (rshift < 0) {
   *loc = 0;
   while (rshift < 0) {
    temp = buf[wskip++];
    *loc += (temp<<-rshift);
    rshift += buf_size;
   }
   if (rshift != 0) {
    *loc += (buf[wskip] >> rshift) &~ (bmask << (buf_size-rshift));
   } else {
    *loc += buf[wskip];
   }
  } else {
   *loc = (buf[wskip] >> rshift);
  }
  if (bits != loc_size) {
   *loc &= ~(lmask << bits);
  }
 }
 return 0;
}

canonical_original_code:
int get_bits(unsigned char *buf, int *loc, unsigned long off, unsigned long bits)
{
 unsigned char bmask;
 int lmask;
 int temp;
 unsigned long buf_size = sizeof(unsigned char) * 8;
 unsigned long loc_size = sizeof(int) * 8;
 unsigned long wskip;
 int rshift;
 unsigned long n;
 if (bits == 0) return 0;
 if (bits > loc_size) {
  fprintf(stderr,"Error: unpacking %d bits into a %d-bit field\n", bits, loc_size);
  return -1;
 } else {
  bmask = 1;
  for (n = 1; n < buf_size; n++) {
   bmask <<= 1;
   bmask++;
  }
  lmask = 1;
  for (n = 1; n < loc_size; n++) {
   lmask <<= 1;
   lmask++;
  }
  wskip = off / buf_size;
  rshift = buf_size - (off % buf_size) - bits;
  if (rshift < 0) {
   *loc = 0;
   while (rshift < 0) {
    temp = buf[wskip++];
    *loc += (temp<<-rshift);
    rshift += buf_size;
   }
   if (rshift != 0) {
    *loc += (buf[wskip] >> rshift) &~ (bmask << (buf_size-rshift));
   } else {
    *loc += buf[wskip];
   }
  } else {
   *loc = (buf[wskip] >> rshift);
  }
  if (bits != loc_size) {
   *loc &= ~(lmask << bits);
  }
 }
 return 0;
}

variable_types:
loc
int *

variable_types:
off
unsigned long

variable_types:
bits
unsigned long

variable_types:
bmask
unsigned char

variable_types: lmask int

variable_types: temp int

variable_types:
wskip
unsigned long

variable_types: rshift int

variable_types:
n
unsigned long


original_code:
int set_bits(unsigned char * buf, int src, size_t off, size_t bits)
{
 unsigned char bmask;
 unsigned char left;
 unsigned char right;
 int smask;
 size_t buf_size = sizeof(unsigned char) * 8;
 size_t src_size = sizeof(int) * 8;
 size_t wskip;
 size_t bskip;
 size_t lclear;
 size_t rclear;
 size_t more;
 size_t n;
 if (bits == 0) return 0;
 if (bits > src_size) {
  fprintf(stderr,"Error: packing %d bits from a %d-bit field\n",bits,src_size);
  return -1;
 } else {
  bmask = 1;
  for (n = 1; n < buf_size; n++) {
   bmask <<= 1;
   bmask++;
  }
  smask = 1;
  for (n = 1; n < src_size; n++) {
   smask <<= 1;
   smask++;
  }
  wskip = off / buf_size;
  bskip = off % buf_size;
  lclear = bskip + bits;
  rclear = buf_size - bskip;
  left = (rclear != buf_size) ? (buf[wskip] & (bmask << rclear)) : 0;
  if (lclear <= buf_size) {
   right= (lclear != buf_size) ? (buf[wskip]&~(bmask<<(buf_size-lclear))) : 0;
   buf[wskip] = (src_size != bits) ? src & ~(smask << bits) : src;
   buf[wskip] = left | right | (buf[wskip] << (rclear - bits));
  } else {
   more = bits - rclear;
   buf[wskip] = left | ((src >> more) & ~(smask << (bits - more)));
   while (more > buf_size) {
    more -= buf_size;
    buf[++wskip] = (src >> more) & ~(smask << (src_size - more));
   }
   wskip++;
   more = buf_size - more;
   right = (more != buf_size) ? (buf[wskip] & ~(bmask << more)) : 0;
   buf[wskip] = (buf_size > src_size) ? src & ~(bmask << src_size) : src;
   buf[wskip] = right | (buf[wskip] << more);
  }
 }
 return 0;
}

canonical_original_code:
int set_bits(unsigned char *buf, int src, unsigned long off, unsigned long bits)
{
 unsigned char bmask;
 unsigned char left;
 unsigned char right;
 int smask;
 unsigned long buf_size = sizeof(unsigned char) * 8;
 unsigned long src_size = sizeof(int) * 8;
 unsigned long wskip;
 unsigned long bskip;
 unsigned long lclear;
 unsigned long rclear;
 unsigned long more;
 unsigned long n;
 if (bits == 0) return 0;
 if (bits > src_size) {
  fprintf(stderr,"Error: packing %d bits from a %d-bit field\n",bits,src_size);
  return -1;
 } else {
  bmask = 1;
  for (n = 1; n < buf_size; n++) {
   bmask <<= 1;
   bmask++;
  }
  smask = 1;
  for (n = 1; n < src_size; n++) {
   smask <<= 1;
   smask++;
  }
  wskip = off / buf_size;
  bskip = off % buf_size;
  lclear = bskip + bits;
  rclear = buf_size - bskip;
  left = (rclear != buf_size) ? (buf[wskip] & (bmask << rclear)) : 0;
  if (lclear <= buf_size) {
   right= (lclear != buf_size) ? (buf[wskip]&~(bmask<<(buf_size-lclear))) : 0;
   buf[wskip] = (src_size != bits) ? src & ~(smask << bits) : src;
   buf[wskip] = left | right | (buf[wskip] << (rclear - bits));
  } else {
   more = bits - rclear;
   buf[wskip] = left | ((src >> more) & ~(smask << (bits - more)));
   while (more > buf_size) {
    more -= buf_size;
    buf[++wskip] = (src >> more) & ~(smask << (src_size - more));
   }
   wskip++;
   more = buf_size - more;
   right = (more != buf_size) ? (buf[wskip] & ~(bmask << more)) : 0;
   buf[wskip] = (buf_size > src_size) ? src & ~(bmask << src_size) : src;
   buf[wskip] = right | (buf[wskip] << more);
  }
 }
 return 0;
}

variable_types:
buf
unsigned char *

variable_types: src int

variable_types:
left
unsigned char

variable_types:
right
unsigned char

variable_types: smask int

variable_types:
bskip
unsigned long

variable_types:
lclear
unsigned long

variable_types:
rclear
unsigned long

variable_types:
more
unsigned long


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

v3 = a3;
result = set_bits(*(_QWORD *)a1, a2, *(unsigned int *)(a1 + 12), a3);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 12) += v3;
return result;
}

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

v3 = a3;
result = func1(*(_QWORD *)a1, a2, *(unsigned int *)(a1 + 12), a3);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 12) += v3;
return result;
}

original_code:
int append_bits(buffer_t * buf, int src, size_t bits)
{
 if (set_bits(buf->buffer, src, buf->offset, bits) != 0) return -1;
 buf->offset += bits;
 return 0;
}

canonical_original_code:
int append_bits(struct buffer_t *buf, int src, unsigned long bits)
{
 if (set_bits(buf->buffer, src, buf->offset, bits) != 0) return -1;
 buf->offset += bits;
 return 0;
}

variable_types: struct buffer_t { unsigned char *buffer; unsigned int length; unsigned int offset; } *


original_code:
void buffer_free(buffer_t * buf)
{
 if (buf == ((void *)0)) return;
 if (buf->buffer != ((void *)0)) {
  free(buf->buffer);
  buf->buffer = ((void *)0);
 }
 buf->length = 0;
 buf->offset = 0;
}

canonical_original_code:
void buffer_free(struct buffer_t *buf)
{
 if (buf == ((void *)0)) return;
 if (buf->buffer != ((void *)0)) {
  free(buf->buffer);
  buf->buffer = ((void *)0);
 }
 buf->length = 0;
 buf->offset = 0;
}

user_defined_types: struct buffer_t { unsigned char *buffer; unsigned int length; unsigned int offset; }


decompiled_code:
__int64 __fastcall buffer_alloc(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
buffer_free(a1);
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)a1 = malloc(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
func3(a1);
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)a1 = malloc(a2);
return 0LL;
}

original_code:
int buffer_alloc(buffer_t * buf, unsigned int length)
{
 if (buf == ((void *)0)) return -1;
 buffer_free(buf);
 buf->length = length;
 buf->offset = 0;
 buf->buffer = (unsigned char *)malloc(length);
 return 0;
}

canonical_original_code:
int buffer_alloc(struct buffer_t *buf, unsigned int length)
{
 if (buf == ((void *)0)) return -1;
 buffer_free(buf);
 buf->length = length;
 buf->offset = 0;
 buf->buffer = (unsigned char *)malloc(length);
 return 0;
}

variable_types:
length
unsigned int


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

if ( argc == 3 )
{
ifp = fopen(argv[1], "rb");
ofp = fopen(argv[2], "wb");
grib2_to_grib1_conv(read_func, 0LL, write_func, 0LL);
fclose(ifp);
fclose(ofp);
result = 0;
}
else
{
fprintf(stderr, "usage: %s GRIB2_file_name GRIB1_file_name\n", *argv);
result = -1;
}
return result;
}

original_code:
int main(int argc, char ** argv)
{
 if (argc != 3) {
  fprintf(stderr, "usage: %s GRIB2_file_name GRIB1_file_name\n", argv[0]);
  return -1;
 }
 ifp = fopen(argv[1], "rb");
 ofp = fopen(argv[2], "wb");
 grib2_to_grib1_conv(read_func, ((void *)0), write_func, ((void *)0));
 fclose(ifp);
 fclose(ofp);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc != 3) {
  fprintf(stderr, "usage: %s GRIB2_file_name GRIB1_file_name\n", argv[0]);
  return -1;
 }
 ifp = fopen(argv[1], "rb");
 ofp = fopen(argv[2], "wb");
 grib2_to_grib1_conv(read_func, ((void *)0), write_func, ((void *)0));
 fclose(ifp);
 fclose(ofp);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
size_t __fastcall write_func(const void *a1, unsigned int a2)
{
size_t result; // rax

result = 0LL;
if ( ofp )
result = fwrite(a1, 1uLL, a2, ofp);
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const void *a1, unsigned int a2)
{
size_t result; // rax

result = 0LL;
if ( ofp )
result = fwrite(a1, 1uLL, a2, ofp);
return result;
}

original_code:
static int write_func(const void * buf, unsigned int len, void * ptr)
{
 (void)(ptr);
 return ofp == ((void *)0)
  ? 0
  : fwrite(buf, 1, len, ofp);
}

canonical_original_code:
static int write_func(void *buf, unsigned int len, void *ptr)
{
 (void)(ptr);
 return ofp == ((void *)0)
  ? 0
  : fwrite(buf, 1, len, ofp);
}

variable_types:
buf
void *

variable_types:
len
unsigned int

variable_types:
ptr
void *


decompiled_code:
size_t __fastcall read_func(void *a1, unsigned int a2)
{
size_t result; // rax

result = 0LL;
if ( ifp )
result = fread(a1, 1uLL, a2, ifp);
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(void *a1, unsigned int a2)
{
size_t result; // rax

result = 0LL;
if ( ifp )
result = fread(a1, 1uLL, a2, ifp);
return result;
}

original_code:
static int read_func(void * buf, unsigned int len, void * ptr)
{
 (void)(ptr);
 return ifp == ((void *)0)
  ? 0
  : fread(buf, 1, len, ifp);
}

canonical_original_code:
static int read_func(void *buf, unsigned int len, void *ptr)
{
 (void)(ptr);
 return ifp == ((void *)0)
  ? 0
  : fread(buf, 1, len, ifp);
}


decompiled_code:
size_t __fastcall read_func(void *a1, unsigned int a2, void *a3)
{
if ( !a1 )
return 0LL;
if ( a3 )
return fread(a1, 1uLL, a2, (FILE *)a3);
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func0(void *a1, unsigned int a2, void *a3)
{
if ( !a1 )
return 0LL;
if ( a3 )
return fread(a1, 1uLL, a2, (FILE *)a3);
return 0LL;
}


repo: mariokonrad/httpd

decompiled_code:
__int64 __fastcall query_next(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = *(_QWORD *)(a1 + 152);
if ( v1 > 7 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 152) = v1 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = *(_QWORD *)(a1 + 152);
if ( v1 > 7 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 152) = v1 + 1;
return 0LL;
}

original_code:
static int query_next(struct request_t * r)
{
 if (r->nquery >= sizeof(r->query) / sizeof(struct query_t))
  return -1;
 r->nquery++;
 return 0;
}

canonical_original_code:
static int query_next(struct request_t *r)
{
 if (r->nquery >= sizeof(r->query) / sizeof(struct query_t))
  return -1;
 r->nquery++;
 return 0;
}

variable_types: struct request_t { char method[8]; char protocol[12]; char url[128]; unsigned long nquery; struct query_t { char val[24]; } query[8]; int content_length; } *

user_defined_types: struct request_t { char method[8]; char protocol[12]; char url[128]; unsigned long nquery; struct query_t query[8]; int content_length; }


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

*a1 = 0LL;
a1[31] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 256) >> 3));
return result;
}

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

*a1 = 0LL;
a1[31] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 256) >> 3));
return result;
}

original_code:
static void response_init(struct response_t * res)
{
 memset(res->head, 0, sizeof(res->head));
}

canonical_original_code:
static void response_init(struct response_t *res)
{
 memset(res->head, 0, sizeof(res->head));
}

variable_types:
res
struct response_t { char head[256]; } *


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

*a1 = 0LL;
a1[44] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 360) >> 3));
return result;
}

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

*a1 = 0LL;
a1[44] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 360) >> 3));
return result;
}

original_code:
static void request_clear(struct request_t * r)
{
 memset(r, 0, sizeof(struct request_t));
}

canonical_original_code:
static void request_clear(struct request_t *r)
{
 memset(r, 0, sizeof(struct request_t));
}


clear

decompiled_code:
void *__fastcall clear(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

original_code:
static void clear(char * s, size_t len)
{
 memset(s, 0, len);
}

canonical_original_code:
static void clear(char *s, unsigned long len)
{
 memset(s, 0, len);
}

variable_types:
s
char *

variable_types:
len
unsigned long


decompiled_code:
void *__fastcall clear_header_property(__int64 a1)
{
clear((void *)a1, 0x20uLL);
return clear((void *)(a1 + 32), 0x80uLL);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
func3((void *)a1, 0x20uLL);
return func3((void *)(a1 + 32), 0x80uLL);
}

original_code:
static void clear_header_property(struct header_property_t * prop)
{
 clear(prop->key, sizeof(prop->key));
 clear(prop->value, sizeof(prop->value));
}

canonical_original_code:
static void clear_header_property(struct header_property_t *prop)
{
 clear(prop->key, sizeof(prop->key));
 clear(prop->value, sizeof(prop->value));
}

variable_types: struct header_property_t { char key[32]; char value[128]; } *


decompiled_code:
__int64 __fastcall str_append(const char *a1, size_t a2, char a3)
{
size_t v4; // rax

v4 = strlen(a1);
if ( v4 >= a2 )
return 0xFFFFFFFFLL;
a1[v4] = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, size_t a2, char a3)
{
size_t v4; // rax

v4 = strlen(a1);
if ( v4 >= a2 )
return 0xFFFFFFFFLL;
a1[v4] = a3;
return 0LL;
}

original_code:
static int str_append(char * s, size_t len, char c)
{
 size_t l = strlen(s);
 if (l < len) {
  s[l]= c;
  return 0;
 }
 return -1;
}

canonical_original_code:
static int str_append(char *s, unsigned long len, char c)
{
 unsigned long l = strlen(s);
 if (l < len) {
  s[l]= c;
  return 0;
 }
 return -1;
}

variable_types: c char

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall method_append(const char *a1, char a2)
{
return str_append(a1, 7uLL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, char a2)
{
return func5(a1, 7uLL, a2);
}

original_code:
static int method_append(struct request_t * r, char c)
{
 return str_append(r->method, sizeof(r->method)-1, c);
}

canonical_original_code:
static int method_append(struct request_t *r, char c)
{
 return str_append(r->method, sizeof(r->method)-1, c);
}


decompiled_code:
__int64 __fastcall url_append(__int64 a1, char a2)
{
return str_append((const char *)(a1 + 20), 0x7FuLL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
return func5((const char *)(a1 + 20), 0x7FuLL, a2);
}

original_code:
static int url_append(struct request_t * r, char c)
{
 return str_append(r->url, sizeof(r->url)-1, c);
}

canonical_original_code:
static int url_append(struct request_t *r, char c)
{
 return str_append(r->url, sizeof(r->url)-1, c);
}


decompiled_code:
__int64 __fastcall protocol_append(__int64 a1, char a2)
{
return str_append((const char *)(a1 + 8), 0xBuLL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char a2)
{
return func5((const char *)(a1 + 8), 0xBuLL, a2);
}

original_code:
static int protocol_append(struct request_t * r, char c)
{
 return str_append(r->protocol, sizeof(r->protocol)-1, c);
}

canonical_original_code:
static int protocol_append(struct request_t *r, char c)
{
 return str_append(r->protocol, sizeof(r->protocol)-1, c);
}


append

decompiled_code:
__int64 __fastcall append(const char *a1, size_t a2, char a3)
{
return str_append(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, size_t a2, char a3)
{
return func5(a1, a2, a3);
}

original_code:
static int append(char * s, size_t len, char c)
{
 return str_append(s, len, c);
}

canonical_original_code:
static int append(char *s, unsigned long len, char c)
{
 return str_append(s, len, c);
}


decompiled_code:
__int64 __fastcall query_append(__int64 a1, char a2)
{
unsigned __int64 v2; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 152);
if ( v2 > 7 )
result = 0xFFFFFFFFLL;
else
result = str_append((const char *)(a1 + 24 * v2 + 160), 0x17uLL, a2);
return result;
}

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

v2 = *(_QWORD *)(a1 + 152);
if ( v2 > 7 )
result = 0xFFFFFFFFLL;
else
result = func5((const char *)(a1 + 24 * v2 + 160), 0x17uLL, a2);
return result;
}

original_code:
static int query_append(struct request_t * r, char c)
{
 if (r->nquery >= sizeof(r->query) / sizeof(struct query_t))
  return -1;
 return str_append(r->query[r->nquery].val, sizeof(r->query[r->nquery].val)-1, c);
}

canonical_original_code:
static int query_append(struct request_t *r, char c)
{
 if (r->nquery >= sizeof(r->query) / sizeof(struct query_t))
  return -1;
 return str_append(r->query[r->nquery].val, sizeof(r->query[r->nquery].val)-1, c);
}


decompiled_code:
__int64 __fastcall request_bad(int a1)
{
return (unsigned int)-(write(
a1,
"HTTP/1.1 400 Bad Request\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"\r\n"
"Bad Request\r\n",
0x9AuLL) != 154);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return (unsigned int)-(write(
a1,
"HTTP/1.1 400 Bad Request\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"\r\n"
"Bad Request\r\n",
0x9AuLL) != 154);
}

original_code:
static int request_bad(int sock, const struct request_t * req)
{
 static const char * RESPONSE =
  "HTTP/1.1 400 Bad Request\r\n"
  "Content-Type: text/html\r\n"
  "Pragma: no-cache\r\n"
  "Cache-Control: no-cache\r\n"
  "Connection: close\r\n"
  "\r\n"
  "Bad Request\r\n";
 int length = 0;
 ((void)req);
 length = strlen(RESPONSE);
 return write(sock, RESPONSE, length) == length ? 0 : -1;
}

canonical_original_code:
static int request_bad(int sock, struct request_t *req)
{
 static char *RESPONSE = "HTTP/1.1 400 Bad Request\r\n"
  "Content-Type: text/html\r\n"
  "Pragma: no-cache\r\n"
  "Cache-Control: no-cache\r\n"
  "Connection: close\r\n"
  "\r\n"
  "Bad Request\r\n";
 int length = 0;
 ((void)req);
 length = strlen(RESPONSE);
 return write(sock, RESPONSE, length) == length ? 0 : -1;
}

variable_types: sock int

variable_types:
RESPONSE
char *

variable_types: length int


decompiled_code:
__int64 __fastcall request_response(int fd, __int64 a2)
{
__int64 result; // rax

if ( !strcmp((const char *)(a2 + 20), "/") )
result = request_send_file(fd, a2, "index.html");
else
result = (unsigned int)-(write(
fd,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"\r\n"
"Welcome (default response)\r\n",
0xA0uLL) != 160);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int fd, __int64 a2)
{
__int64 result; // rax

if ( !strcmp((const char *)(a2 + 20), "/") )
result = func19(fd, a2, "index.html");
else
result = (unsigned int)-(write(
fd,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"\r\n"
"Welcome (default response)\r\n",
0xA0uLL) != 160);
return result;
}

original_code:
static int request_response(int sock, const struct request_t * req)
{
 static const char * RESPONSE =
  "HTTP/1.1 200 OK\r\n"
  "Content-Type: text/html\r\n"
  "Pragma: no-cache\r\n"
  "Cache-Control: no-cache\r\n"
  "Connection: close\r\n"
  "\r\n"
  "Welcome (default response)\r\n";
 int length = 0;
 ((void)req);
 if (strcmp(req->url, "/") == 0) {
  return request_send_file(sock, req, "index.html");
 } else {
  length = strlen(RESPONSE);
  return (write(sock, RESPONSE, length) == length) ? 0 : -1;
 }
}

canonical_original_code:
static int request_response(int sock, struct request_t *req)
{
 static char *RESPONSE = "HTTP/1.1 200 OK\r\n"
  "Content-Type: text/html\r\n"
  "Pragma: no-cache\r\n"
  "Cache-Control: no-cache\r\n"
  "Connection: close\r\n"
  "\r\n"
  "Welcome (default response)\r\n";
 int length = 0;
 ((void)req);
 if (strcmp(req->url, "/") == 0) {
  return request_send_file(sock, req, "index.html");
 } else {
  length = strlen(RESPONSE);
  return (write(sock, RESPONSE, length) == length) ? 0 : -1;
 }
}


parse

decompiled_code:
__int64 __fastcall parse(int fd, char *a2)
{
int v2; // er15
int v3; // ebp
char v4; // r12
int v5; // eax
int v6; // ebx
int v7; // eax
unsigned int v8; // edx
const unsigned __int16 *v9; // rcx
__int16 v10; // dx
__int16 v11; // dx
const unsigned __int16 *v12; // rcx
__int16 v13; // dx
char v15[32]; // [rsp+0h] [rbp-E8h] BYREF
char nptr[128]; // [rsp+20h] [rbp-C8h] BYREF
__int64 buf[9]; // [rsp+A0h] [rbp-48h] BYREF

request_clear(a2);
clear_header_property((__int64)v15);
if ( fd < 0 )
return (unsigned int)-99;
v2 = -1;
v3 = 16;
v4 = 0;
v5 = 1;
v6 = 0;
while ( 2 )
{
if ( v5 )
{
if ( v3 > 15 )
{
buf[0] = 0LL;
buf[1] = 0LL;
v7 = read(fd, buf, 0x10uLL);
v8 = v7;
if ( v7 < 0 )
return (unsigned int)-99;
if ( !v7 )
return v8;
v3 = 0;
}
v4 = *((_BYTE *)buf + v3++);
}
switch ( v6 )
{
case 0:
v9 = *_ctype_b_loc();
v5 = 1;
if ( (v9[v4] & 0x2000) == 0 )
{
v5 = v6;
v6 = 1;
}
continue;
case 1:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 2;
}
else
{
if ( (unsigned int)method_append(a2, v4) )
return (unsigned int)-1;
v5 = v6;
}
continue;
case 2:
v10 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v10 != 0;
if ( !v10 )
v6 = 3;
continue;
case 3:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 5;
}
else if ( v4 == 63 )
{
v5 = 1;
v6 = 4;
}
else
{
if ( (unsigned int)url_append((__int64)a2, v4) )
return (unsigned int)-3;
v5 = 1;
}
continue;
case 4:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = query_next((__int64)a2);
if ( v5 )
return (unsigned int)-4;
v6 = 5;
}
else if ( v4 == 38 )
{
if ( (unsigned int)query_next((__int64)a2) )
return (unsigned int)-4;
v5 = 1;
}
else
{
if ( (unsigned int)query_append((__int64)a2, v4) )
return (unsigned int)-4;
v5 = 1;
}
continue;
case 5:
v11 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v11 != 0;
if ( !v11 )
v6 = 6;
continue;
case 6:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 7;
}
else
{
if ( (unsigned int)protocol_append((__int64)a2, v4) )
return (unsigned int)-6;
v5 = 1;
}
continue;
case 7:
v12 = *_ctype_b_loc();
v5 = 1;
if ( (v12[v4] & 0x2000) == 0 )
{
clear_header_property((__int64)v15);
v5 = 0;
v6 = 8;
}
continue;
case 8:
if ( v4 == 58 )
{
v5 = 1;
v6 = 9;
}
else
{
if ( (unsigned int)append(v15, 0x1FuLL, v4) )
return (unsigned int)-8;
v5 = 1;
}
continue;
case 9:
v13 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v13 != 0;
if ( !v13 )
v6 = 10;
continue;
case 10:
if ( v4 == 13 )
{
if ( !strcmp("Content-Length", v15) )
v2 = strtol(nptr, 0LL, 0);
clear_header_property((__int64)v15);
v5 = 1;
v6 = 11;
}
else
{
if ( (unsigned int)append(nptr, 0x7FuLL, v4) )
return (unsigned int)-10;
v5 = 1;
}
continue;
case 11:
v5 = 1;
if ( v4 != 10 )
{
v5 = v4 == 13;
v6 = 4 * v5 + 8;
}
continue;
case 12:
v5 = 0;
v6 = 8;
if ( v4 != 10 )
continue;
if ( v2 <= 0 )
return 0;
v5 = 1;
v6 = 13;
continue;
case 13:
switch ( v4 )
{
case 38:
if ( (unsigned int)query_next((__int64)a2) )
return (unsigned int)-13;
v5 = 1;
continue;
case 13:
if ( (unsigned int)query_next((__int64)a2) )
return (unsigned int)-13;
v5 = 1;
continue;
case 10:
v5 = 1;
continue;
}
if ( v4 )
{
if ( (unsigned int)query_append((__int64)a2, v4) )
return (unsigned int)-13;
v5 = 1;
continue;
}
v8 = query_next((__int64)a2);
if ( v8 )
v8 = -13;
return v8;
default:
v5 = 0;
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func23(int fd, char *a2)
{
int v2; // er15
int v3; // ebp
char v4; // r12
int v5; // eax
int v6; // ebx
int v7; // eax
unsigned int v8; // edx
const unsigned __int16 *v9; // rcx
__int16 v10; // dx
__int16 v11; // dx
const unsigned __int16 *v12; // rcx
__int16 v13; // dx
char v15[32]; // [rsp+0h] [rbp-E8h] BYREF
char nptr[128]; // [rsp+20h] [rbp-C8h] BYREF
__int64 buf[9]; // [rsp+A0h] [rbp-48h] BYREF

func2(a2);
func4((__int64)v15);
if ( fd < 0 )
return (unsigned int)-99;
v2 = -1;
v3 = 16;
v4 = 0;
v5 = 1;
v6 = 0;
while ( 2 )
{
if ( v5 )
{
if ( v3 > 15 )
{
buf[0] = 0LL;
buf[1] = 0LL;
v7 = read(fd, buf, 0x10uLL);
v8 = v7;
if ( v7 < 0 )
return (unsigned int)-99;
if ( !v7 )
return v8;
v3 = 0;
}
v4 = *((_BYTE *)buf + v3++);
}
switch ( v6 )
{
case 0:
v9 = *_ctype_b_loc();
v5 = 1;
if ( (v9[v4] & 0x2000) == 0 )
{
v5 = v6;
v6 = 1;
}
continue;
case 1:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 2;
}
else
{
if ( (unsigned int)func6(a2, v4) )
return (unsigned int)-1;
v5 = v6;
}
continue;
case 2:
v10 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v10 != 0;
if ( !v10 )
v6 = 3;
continue;
case 3:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 5;
}
else if ( v4 == 63 )
{
v5 = 1;
v6 = 4;
}
else
{
if ( (unsigned int)func7((__int64)a2, v4) )
return (unsigned int)-3;
v5 = 1;
}
continue;
case 4:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = func0((__int64)a2);
if ( v5 )
return (unsigned int)-4;
v6 = 5;
}
else if ( v4 == 38 )
{
if ( (unsigned int)func0((__int64)a2) )
return (unsigned int)-4;
v5 = 1;
}
else
{
if ( (unsigned int)func10((__int64)a2, v4) )
return (unsigned int)-4;
v5 = 1;
}
continue;
case 5:
v11 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v11 != 0;
if ( !v11 )
v6 = 6;
continue;
case 6:
if ( ((*_ctype_b_loc())[v4] & 0x2000) != 0 )
{
v5 = 0;
v6 = 7;
}
else
{
if ( (unsigned int)func8((__int64)a2, v4) )
return (unsigned int)-6;
v5 = 1;
}
continue;
case 7:
v12 = *_ctype_b_loc();
v5 = 1;
if ( (v12[v4] & 0x2000) == 0 )
{
func4((__int64)v15);
v5 = 0;
v6 = 8;
}
continue;
case 8:
if ( v4 == 58 )
{
v5 = 1;
v6 = 9;
}
else
{
if ( (unsigned int)func9(v15, 0x1FuLL, v4) )
return (unsigned int)-8;
v5 = 1;
}
continue;
case 9:
v13 = (*_ctype_b_loc())[v4] & 0x2000;
v5 = v13 != 0;
if ( !v13 )
v6 = 10;
continue;
case 10:
if ( v4 == 13 )
{
if ( !strcmp("Content-Length", v15) )
v2 = strtol(nptr, 0LL, 0);
func4((__int64)v15);
v5 = 1;
v6 = 11;
}
else
{
if ( (unsigned int)func9(nptr, 0x7FuLL, v4) )
return (unsigned int)-10;
v5 = 1;
}
continue;
case 11:
v5 = 1;
if ( v4 != 10 )
{
v5 = v4 == 13;
v6 = 4 * v5 + 8;
}
continue;
case 12:
v5 = 0;
v6 = 8;
if ( v4 != 10 )
continue;
if ( v2 <= 0 )
return 0;
v5 = 1;
v6 = 13;
continue;
case 13:
switch ( v4 )
{
case 38:
if ( (unsigned int)func0((__int64)a2) )
return (unsigned int)-13;
v5 = 1;
continue;
case 13:
if ( (unsigned int)func0((__int64)a2) )
return (unsigned int)-13;
v5 = 1;
continue;
case 10:
v5 = 1;
continue;
}
if ( v4 )
{
if ( (unsigned int)func10((__int64)a2, v4) )
return (unsigned int)-13;
v5 = 1;
continue;
}
v8 = func0((__int64)a2);
if ( v8 )
v8 = -13;
return v8;
default:
v5 = 0;
continue;
}
}
}

original_code:
static int parse(int client_sock, struct request_t * r)
{
 int state = 0;
 int read_next = 1;
 char c = 0;
 char buffer[16];
 int buffer_index = sizeof(buffer);
 int content_length = -1;
 struct header_property_t prop;
 request_clear(r);
 clear_header_property(&prop);
 while (client_sock >= 0) {
  if (read_next) {
   if (buffer_index >= (int)sizeof(buffer)) {
    int rc;
    memset(buffer, 0, sizeof(buffer));
    rc = read(client_sock, buffer, sizeof(buffer));
    if (rc < 0)
     return -99;
    if (rc == 0)
     return 0;
    buffer_index = 0;
   }
   c = buffer[buffer_index];
   ++buffer_index;
   read_next = 0;
  }
  switch (state) {
   case 0:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     read_next = 1;
    } else {
     state = 1;
    }
    break;
   case 1:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     state = 2;
    } else {
     if (method_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 2:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     read_next = 1;
    } else {
     state = 3;
    }
    break;
   case 3:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     state = 5;
    } else if (c == '?') {
     read_next = 1;
     state = 4;
    } else {
     if (url_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 4:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     if (query_next(r))
      return -state;
     state = 5;
    } else if (c == '&') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else {
     if (query_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 5:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     read_next = 1;
    } else {
     state = 6;
    }
    break;
   case 6:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     state = 7;
    } else {
     if (protocol_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 7:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     read_next = 1;
    } else {
     clear_header_property(&prop);
     state = 8;
    }
    break;
   case 8:
    if (c == ':') {
     state = 9;
     read_next = 1;
    } else {
     if (append(prop.key, sizeof(prop.key)-1, c))
      return -state;
     read_next = 1;
    }
    break;
   case 9:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
     read_next = 1;
    } else {
     state = 10;
    }
    break;
   case 10:
    if (c == '\r') {
     if (strcmp("Content-Length", prop.key) == 0)
      content_length = strtol(prop.value, 0, 0);
     clear_header_property(&prop);
     state = 11;
     read_next = 1;
    } else {
     if (append(prop.value, sizeof(prop.value)-1, c))
      return -state;
     read_next = 1;
    }
    break;
   case 11:
    if (c == '\n') {
     read_next = 1;
    } else if (c == '\r') {
     state = 12;
     read_next = 1;
    } else {
     state = 8;
    }
    break;
   case 12:
    if (c == '\n') {
     if (content_length > 0) {
      state = 13;
      read_next = 1;
     } else {
      return 0;
     }
    } else {
     state = 8;
    }
    break;
   case 13:
    if (c == '&') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else if (c == '\r') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else if (c == '\n') {
     read_next = 1;
    } else if (c == '\0') {
     if (query_next(r))
      return -state;
     return 0;
    } else {
     if (query_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
  }
 }
 return -99;
}

canonical_original_code:
static int parse(int client_sock, struct request_t *r)
{
 int state = 0;
 int read_next = 1;
 char c = 0;
 char buffer[16];
 int buffer_index = sizeof(buffer);
 int content_length = -1;
 struct header_property_t prop;
 request_clear(r);
 clear_header_property(&prop);
 while (client_sock >= 0) {
  if (read_next) {
   if (buffer_index >= (int)sizeof(buffer)) {
    int rc;
    memset(buffer, 0, sizeof(buffer));
    rc = read(client_sock, buffer, sizeof(buffer));
    if (rc < 0)
     return -99;
    if (rc == 0)
     return 0;
    buffer_index = 0;
   }
   c = buffer[buffer_index];
   ++buffer_index;
   read_next = 0;
  }
  switch (state) {
   case 0:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     read_next = 1;
    } else {
     state = 1;
    }
    break;
   case 1:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     state = 2;
    } else {
     if (method_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 2:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     read_next = 1;
    } else {
     state = 3;
    }
    break;
   case 3:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     state = 5;
    } else if (c == '?') {
     read_next = 1;
     state = 4;
    } else {
     if (url_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 4:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     if (query_next(r))
      return -state;
     state = 5;
    } else if (c == '&') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else {
     if (query_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 5:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     read_next = 1;
    } else {
     state = 6;
    }
    break;
   case 6:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     state = 7;
    } else {
     if (protocol_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
   case 7:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     read_next = 1;
    } else {
     clear_header_property(&prop);
     state = 8;
    }
    break;
   case 8:
    if (c == ':') {
     state = 9;
     read_next = 1;
    } else {
     if (append(prop.key, sizeof(prop.key)-1, c))
      return -state;
     read_next = 1;
    }
    break;
   case 9:
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
     read_next = 1;
    } else {
     state = 10;
    }
    break;
   case 10:
    if (c == '\r') {
     if (strcmp("Content-Length", prop.key) == 0)
      content_length = strtol(prop.value, 0, 0);
     clear_header_property(&prop);
     state = 11;
     read_next = 1;
    } else {
     if (append(prop.value, sizeof(prop.value)-1, c))
      return -state;
     read_next = 1;
    }
    break;
   case 11:
    if (c == '\n') {
     read_next = 1;
    } else if (c == '\r') {
     state = 12;
     read_next = 1;
    } else {
     state = 8;
    }
    break;
   case 12:
    if (c == '\n') {
     if (content_length > 0) {
      state = 13;
      read_next = 1;
     } else {
      return 0;
     }
    } else {
     state = 8;
    }
    break;
   case 13:
    if (c == '&') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else if (c == '\r') {
     if (query_next(r))
      return -state;
     read_next = 1;
    } else if (c == '\n') {
     read_next = 1;
    } else if (c == '\0') {
     if (query_next(r))
      return -state;
     return 0;
    } else {
     if (query_append(r, c))
      return -state;
     read_next = 1;
    }
    break;
  }
 }
 return -99;
}

variable_types: state int

variable_types:
buffer
char [16]

variable_types: struct header_property_t { char key[32]; char value[128]; }

variable_types: rc int


decompiled_code:
int __fastcall print_req(unsigned int a1, __int64 a2)
{
const char *v3; // rbp
unsigned __int64 v4; // rbx

if ( a1 )
{
printf("\nERROR: invalid request: %d", a1);
}
else
{
printf("MET:[%s]\n", (const char *)a2);
printf("PRT:[%s]\n", (const char *)(a2 + 8));
printf("URL:[%s]\n", (const char *)(a2 + 20));
if ( *(_QWORD *)(a2 + 152) )
{
v3 = (const char *)(a2 + 160);
v4 = 0LL;
do
{
printf("QRY:[%s]\n", v3);
++v4;
v3 += 24;
}
while ( *(_QWORD *)(a2 + 152) > v4 );
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func24(unsigned int a1, __int64 a2)
{
const char *v3; // rbp
unsigned __int64 v4; // rbx

if ( a1 )
{
printf("\nERROR: invalid request: %d", a1);
}
else
{
printf("MET:[%s]\n", (const char *)a2);
printf("PRT:[%s]\n", (const char *)(a2 + 8));
printf("URL:[%s]\n", (const char *)(a2 + 20));
if ( *(_QWORD *)(a2 + 152) )
{
v3 = (const char *)(a2 + 160);
v4 = 0LL;
do
{
printf("QRY:[%s]\n", v3);
++v4;
v3 += 24;
}
while ( *(_QWORD *)(a2 + 152) > v4 );
}
}
return putchar(10);
}

original_code:
static void print_req(int rc, struct request_t * r)
{
 size_t i;
 if (rc) {
  printf("\nERROR: invalid request: %d", rc);
 } else {
  printf("MET:[%s]\n", r->method);
  printf("PRT:[%s]\n", r->protocol);
  printf("URL:[%s]\n", r->url);
  for (i = 0; i < r->nquery; ++i) printf("QRY:[%s]\n", r->query[i].val);
 }
 printf("\n");
}

canonical_original_code:
static void print_req(int rc, struct request_t *r)
{
 unsigned long i;
 if (rc) {
  printf("\nERROR: invalid request: %d", rc);
 } else {
  printf("MET:[%s]\n", r->method);
  printf("PRT:[%s]\n", r->protocol);
  printf("URL:[%s]\n", r->url);
  for (i = 0; i < r->nquery; ++i) printf("QRY:[%s]\n", r->query[i].val);
 }
 printf("\n");
}

variable_types:
i
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
*(_QWORD *)&server_7 = 0xFFFFFFFFLL;
qword_BC8 = 0LL;
qword_BD0 = 0LL;
qword_BD8 = 0LL;
qword_BE0 = 0LL;
v3 = socket(2, 1, 0);
server_7 = v3;
if ( v3 < 0 )
{
perror("socket");
result = -1;
}
else
{
v4 = v3;
*(__int64 *)((char *)&qword_BC8 + 4) = 0LL;
*((_WORD *)&server_7 + 2) = 2;
*((_WORD *)&server_7 + 3) = _bswap_16(8080);
LODWORD(qword_BC8) = _bswap_32(0);
if ( bind(v4, (const struct sockaddr *)(&server_7 + 1), 0x10u) < 0 )
{
perror("bind");
result = -1;
}
else if ( setsockopt(server_7, 1, 2, optval, 4u) < 0 )
{
perror("setsockopt");
result = -1;
}
else if ( listen(server_7, 2) < 0 )
{
perror("listen");
result = -1;
}
else
{
qword_BD8 = (__int64)request_bad;
qword_BE0 = (__int64)request_response;
result = run_server((__int64)&server_7);
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
*(_QWORD *)&server_7 = 0xFFFFFFFFLL;
qword_BC8 = 0LL;
qword_BD0 = 0LL;
qword_BD8 = 0LL;
qword_BE0 = 0LL;
v3 = socket(2, 1, 0);
server_7 = v3;
if ( v3 < 0 )
{
perror("socket");
result = -1;
}
else
{
v4 = v3;
*(__int64 *)((char *)&qword_BC8 + 4) = 0LL;
*((_WORD *)&server_7 + 2) = 2;
*((_WORD *)&server_7 + 3) = func21(8080);
LODWORD(qword_BC8) = func22(0);
if ( bind(v4, (const struct sockaddr *)(&server_7 + 1), 0x10u) < 0 )
{
perror("bind");
result = -1;
}
else if ( setsockopt(server_7, 1, 2, optval, 4u) < 0 )
{
perror("setsockopt");
result = -1;
}
else if ( listen(server_7, 2) < 0 )
{
perror("listen");
result = -1;
}
else
{
qword_BD8 = (__int64)request_bad;
qword_BE0 = (__int64)request_response;
result = func25((__int64)&server_7);
}
}
return result;
}

original_code:
int main()
{
 static struct server_t server;
 const int reuse = 1;
 memset(&server, 0, sizeof(server));
 server.sock = -1;
 server.sock = socket(2, SOCK_STREAM, 0);
 if (server.sock < 0) {
  perror("socket");
  return -1;
 }
 memset(&server.addr, 0, sizeof(server.addr));
 server.addr.sin_family = 2;
 server.addr.sin_port = htons(8080);
 server.addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 if (bind(server.sock, (const struct sockaddr *)&server.addr, sizeof(server.addr)) < 0) {
  perror("bind");
  return -1;
 }
 if (setsockopt(server.sock, 1, 2, &reuse, sizeof(reuse)) < 0) {
  perror("setsockopt");
  return -1;
 }
 if (listen(server.sock, 2) < 0) {
  perror("listen");
  return -1;
 }
 server.func_bad_request = request_bad;
 server.func_request = request_response;
 return run_server(&server);
}

canonical_original_code:
int main()
{
 static struct server_t server;
 int reuse = 1;
 memset(&server, 0, sizeof(server));
 server.sock = -1;
 server.sock = socket(2, SOCK_STREAM, 0);
 if (server.sock < 0) {
  perror("socket");
  return -1;
 }
 memset(&server.addr, 0, sizeof(server.addr));
 server.addr.sin_family = 2;
 server.addr.sin_port = htons(8080);
 server.addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 if (bind(server.sock, (struct sockaddr *)&server.addr, sizeof(server.addr)) < 0) {
  perror("bind");
  return -1;
 }
 if (setsockopt(server.sock, 1, 2, &reuse, sizeof(reuse)) < 0) {
  perror("setsockopt");
  return -1;
 }
 if (listen(server.sock, 2) < 0) {
  perror("listen");
  return -1;
 }
 server.func_bad_request = request_bad;
 server.func_request = request_response;
 return run_server(&server);
}

variable_types: struct server_t { int sock; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; int (*func_bad_request)(int, struct request_t { char method[8]; char protocol[12]; char url[128]; unsigned long nquery; struct query_t { char val[24]; } query[8]; int content_length; } *); int (*func_request)(int, struct request_t *); }

variable_types: reuse int

user_defined_types: struct server_t { int sock; struct sockaddr_in addr; int (*func_bad_request)(int, struct request_t *); int (*func_request)(int, struct request_t *); }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


repo: mariotaku/dlmirror-android

decompiled_code:
__int64 __fastcall get_byte_per_pixel(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
case 2u:
case 5u:
result = 4LL;
break;
case 3u:
result = a1;
break;
case 4u:
case 6u:
case 7u:
result = 2LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
case 2u:
case 5u:
result = 4LL;
break;
case 3u:
result = a1;
break;
case 4u:
case 6u:
case 7u:
result = 2LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int get_byte_per_pixel(int format) {
 switch (format) {
  case 5:
  case 1:
  case 2:
   return 4;
  case 3:
   return 3;
  case 7:
  case 6:
  case 4:
   return 2;
  default:
   return 0;
 }
}

variable_types: format int


repo: mariuswol/polsl

decompiled_code:
__int64 rw_truncate()
{
return 0LL;
}

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

original_code:
static int rw_truncate(const char *path, off_t size)
{
   return 0;
}

canonical_original_code:
static int rw_truncate(char *path, long size)
{
   return 0;
}

variable_types:
path
char *

variable_types: size long


decompiled_code:
__int64 rw_release()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
static int rw_release(const char *path, struct fuse_file_info *finfo)
{
  return 0;
}

canonical_original_code:
static int rw_release(char *path, struct fuse_file_info *finfo)
{
  return 0;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
__int64 rw_fsync()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
static int rw_fsync(const char *path, int crap, struct fuse_file_info *finfo)
{
  return 0;
}

canonical_original_code:
static int rw_fsync(char *path, int crap, struct fuse_file_info *finfo)
{
  return 0;
}

variable_types: crap int

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }


original_code:
static int rw_mknod(const char *path, mode_t mode, dev_t rdev)
{
  return -38;
}

canonical_original_code:
static int rw_mknod(char *path, unsigned int mode, unsigned long rdev)
{
  return -38;
}

variable_types:
mode
unsigned int

variable_types:
rdev
unsigned long


original_code:
static int rw_mkdir(const char *path, mode_t mode)
{
  return -38;
}

canonical_original_code:
static int rw_mkdir(char *path, unsigned int mode)
{
  return -38;
}


original_code:
static int rw_unlink(const char *path)
{
  return -38;
}

canonical_original_code:
static int rw_unlink(char *path)
{
  return -38;
}


original_code:
static int rw_rmdir(const char *path)
{
  return -38;
}

canonical_original_code:
static int rw_rmdir(char *path)
{
  return -38;
}


decompiled_code:
__int64 rw_symlink()
{
return 4294967258LL;
}

original_code:
static int rw_symlink(const char *from, const char *to)
{
  return -38;
}

canonical_original_code:
static int rw_symlink(char *from, char *to)
{
  return -38;
}

variable_types:
from
char *

variable_types:
to
char *


original_code:
static int rw_rename(const char *from, const char *to)
{
  return -38;
}

canonical_original_code:
static int rw_rename(char *from, char *to)
{
  return -38;
}


original_code:
static int rw_link(const char *from, const char *to)
{
  return -38;
}

canonical_original_code:
static int rw_link(char *from, char *to)
{
  return -38;
}


original_code:
static int rw_chmod(const char *path, mode_t mode)
{
  return -38;
}

canonical_original_code:
static int rw_chmod(char *path, unsigned int mode)
{
  return -38;
}


original_code:
static int rw_chown(const char *path, uid_t uid, gid_t gid)
{
  return -38;
}

canonical_original_code:
static int rw_chown(char *path, unsigned int uid, unsigned int gid)
{
  return -38;
}

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int


original_code:
static int rw_utime(const char *path, struct utimbuf *buf)
{
   return -38;
}

canonical_original_code:
static int rw_utime(char *path, struct utimbuf *buf)
{
   return -38;
}

variable_types: struct utimbuf { long actime; long modtime; } *


decompiled_code:
__int64 rw_setxattr()
{
return 4294967258LL;
}

original_code:
static int rw_setxattr(const char *path, const char *name, const char *value, size_t size, int flags)
{
 return -38;
}

canonical_original_code:
static int rw_setxattr(char *path, char *name, char *value, unsigned long size, int flags)
{
 return -38;
}

variable_types:
name
char *

variable_types:
value
char *

variable_types:
size
unsigned long

variable_types: flags int


decompiled_code:
__int64 rw_getxattr()
{
return 4294967258LL;
}

original_code:
static int rw_getxattr(const char *path, const char *name, char *value, size_t size)
{
 return -38;
}

canonical_original_code:
static int rw_getxattr(char *path, char *name, char *value, unsigned long size)
{
 return -38;
}


decompiled_code:
__int64 rw_listxattr()
{
return 4294967258LL;
}

original_code:
static int rw_listxattr(const char *path, char *list, size_t size)
{
 return -38;
}

canonical_original_code:
static int rw_listxattr(char *path, char *list, unsigned long size)
{
 return -38;
}

variable_types:
list
char *


decompiled_code:
__int64 rw_removexattr()
{
return 4294967258LL;
}

original_code:
static int rw_removexattr(const char *path, const char *name)
{
   return -38;
}

canonical_original_code:
static int rw_removexattr(char *path, char *name)
{
   return -38;
}


decompiled_code:
char *__fastcall translate_path(char *src)
{
size_t v1; // rbx
const char *v2; // r12
size_t v3; // rax
char *v4; // rbx
char *v5; // rax

v1 = strlen(src);
v2 = rw_path;
v3 = strlen(rw_path);
v4 = (char *)malloc(v1 + v3 + 1);
strcpy(v4, v2);
v5 = &v4[strlen(v4) - 1];
if ( *v5 == 47 )
*v5 = 0;
return strcat(v4, src);
}

canonical_decompiled_code:
char *__fastcall func17(char *src)
{
size_t v1; // rbx
const char *v2; // r12
size_t v3; // rax
char *v4; // rbx
char *v5; // rax

v1 = strlen(src);
v2 = rw_path;
v3 = strlen(rw_path);
v4 = (char *)malloc(v1 + v3 + 1);
strcpy(v4, v2);
v5 = &v4[strlen(v4) - 1];
if ( *v5 == 47 )
*v5 = 0;
return strcat(v4, src);
}

original_code:
static char* translate_path(const char* path)
{
    char *rPath= malloc(sizeof(char)*(strlen(path)+strlen(rw_path)+1));
    strcpy(rPath,rw_path);
    if (rPath[strlen(rPath)-1]=='/') {
        rPath[strlen(rPath)-1]='\0';
    }
    strcat(rPath,path);
    return rPath;
}

canonical_original_code:
static char *translate_path(char *path)
{
    char *rPath = malloc(sizeof(char)*(strlen(path)+strlen(rw_path)+1));
    strcpy(rPath,rw_path);
    if (rPath[strlen(rPath)-1]=='/') {
        rPath[strlen(rPath)-1]='\0';
    }
    strcat(rPath,path);
    return rPath;
}

variable_types:
rPath
char *


decompiled_code:
__int64 __fastcall rw_access(char *a1, int a2)
{
char *v2; // rbp
unsigned int v3; // ebx

v2 = translate_path(a1);
v3 = access(v2, a2);
free(v2);
if ( v3 == -1 )
v3 = -*_errno_location();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func18(char *a1, int a2)
{
char *v2; // rbp
unsigned int v3; // ebx

v2 = func17(a1);
v3 = access(v2, a2);
free(v2);
if ( v3 == -1 )
v3 = -*_errno_location();
return v3;
}

original_code:
static int rw_access(const char *path, int mode)
{
 int res;
   char *lpath=translate_path(path);
   res = access(lpath, mode);
 free(lpath);
   if (res == -1) {
     return -(*__errno_location ());
   }
   return res;
}

canonical_original_code:
static int rw_access(char *path, int mode)
{
 int res;
   char *lpath = translate_path(path);
   res = access(lpath, mode);
 free(lpath);
   if (res == -1) {
     return -(*__errno_location ());
   }
   return res;
}

variable_types:
path
char *

variable_types: mode int

variable_types: res int

variable_types:
lpath
char *