original_code:
int jelopt_final(char **argv, int *err)
{
  int i, last=-1;
  for(i=1;argv[i];)
    {
      char *a = argv[i];
      if(*a == '-')
 {
   if(*(a+1) == '-')
     {
       if(*(a+2) == 0)
  break;
       if(err) *err |= 8;
     }
   else
     {
       if(*(a+1) == 0)
  break;
       if(err) *err |= 8;
     }
 }
      if(strcmp(argv[i], "\001\002\090"))
 i++;
      else
 rem_opt(argv, i, i);
    }
  for(i = 0;argv[i]; i++)
    last = i;
  for(i=0;argv[i];i++)
    {
      char *a = argv[i];
      if(*a == '-' && *(a+1) == '-' && *(a+2) == 0)
 {
   rem_opt(argv, i, i);
   return last;
 }
    }
  return last+1;
}

canonical_original_code:
int jelopt_final(char **argv, int *err)
{
  int i; int last = -1;
  for(i=1;argv[i];)
    {
      char *a = argv[i];
      if(*a == '-')
 {
   if(*(a+1) == '-')
     {
       if(*(a+2) == 0)
  break;
       if(err) *err |= 8;
     }
   else
     {
       if(*(a+1) == 0)
  break;
       if(err) *err |= 8;
     }
 }
      if(strcmp(argv[i], "\001\002\090"))
 i++;
      else
 rem_opt(argv, i, i);
    }
  for(i = 0;argv[i]; i++)
    last = i;
  for(i=0;argv[i];i++)
    {
      char *a = argv[i];
      if(*a == '-' && *(a+1) == '-' && *(a+2) == 0)
 {
   rem_opt(argv, i, i);
   return last;
 }
    }
  return last+1;
}

variable_types:
err
int *

variable_types: last int


repo: jelaas/eth-affinity

original_code:
int jelopt_multi(char **argv, int opt_short, char *opt_long,
   int count, char **values,
   int *err)
{
  int j,i = -1;
  int type = 0;
  if(opt_short)
    if( (i = find_short_arg(argv, opt_short)) >= 0)
      type = 1;
  if(!type && opt_long)
    if( (i = find_long_arg(argv, opt_long)) >= 0)
      type = 2;
  if(!type)
    return 0;
  if(count < 0)
    {
      if(err) *err |= 1;
      return 0;
    }
  if(count && values == ((void *)0))
    {
      if(err) *err |= 1;
      return 0;
    }
  if(type == 1)
    {
      if(count)
 {
   char *p = strchr(argv[i], opt_short);
   if(*(p+1))
     {
       *values = strdup(p+1);
       unquote(*values++);
       count--;
       *p = 0;
     }
 }
      for(j=i+1;count--;j++)
 {
   if(argv[j])
     {
       if(strcmp(argv[j], "\001\002\090"))
  *values = strdup(argv[j]);
       else
  {
    if(err) *err |= 4;
    goto err_short;
  }
     }
   else
     {
       if(err) *err |= 2;
     err_short:
       rem_short_opt(argv, opt_short, i, i);
       return 0;
     }
   unquote(*values++);
   argv[j] = "\001\002\090";
 }
      rem_short_opt(argv, opt_short, i, i);
      if(values) *values++ = 0;
      return 1;
    }
  if(type == 2)
    {
      if(count == 0)
 {
   argv[i] = "\001\002\090";
   return 1;
 }
      if(strchr(argv[i], '='))
 {
   *values = strdup(strchr(argv[i], '=')+1);
   unquote(*values++);
   count--;
 }
      for(j=i+1;count--;j++)
 {
   if(argv[j])
     {
       if(strcmp(argv[j], "\001\002\090"))
  *values = strdup(argv[j]);
       else
  {
    if(err) *err |= 4;
    goto err_long;
  }
     }
   else
     {
       if(err) *err |= 2;
     err_long:
       rem_opt(argv, i, i);
       return 0;
     }
   unquote(*values++);
   argv[j] = "\001\002\090";
 }
      argv[i] = "\001\002\090";
      *values++ = 0;
      return 1;
    }
  return 0;
}

canonical_original_code:
int jelopt_multi(char **argv, int opt_short, char *opt_long, int count, char **values, int *err)
{
  int j; int i = -1;
  int type = 0;
  if(opt_short)
    if( (i = find_short_arg(argv, opt_short)) >= 0)
      type = 1;
  if(!type && opt_long)
    if( (i = find_long_arg(argv, opt_long)) >= 0)
      type = 2;
  if(!type)
    return 0;
  if(count < 0)
    {
      if(err) *err |= 1;
      return 0;
    }
  if(count && values == ((void *)0))
    {
      if(err) *err |= 1;
      return 0;
    }
  if(type == 1)
    {
      if(count)
 {
   char *p = strchr(argv[i], opt_short);
   if(*(p+1))
     {
       *values = strdup(p+1);
       unquote(*values++);
       count--;
       *p = 0;
     }
 }
      for(j=i+1;count--;j++)
 {
   if(argv[j])
     {
       if(strcmp(argv[j], "\001\002\090"))
  *values = strdup(argv[j]);
       else
  {
    if(err) *err |= 4;
    goto err_short;
  }
     }
   else
     {
       if(err) *err |= 2;
     err_short:
       rem_short_opt(argv, opt_short, i, i);
       return 0;
     }
   unquote(*values++);
   argv[j] = "\001\002\090";
 }
      rem_short_opt(argv, opt_short, i, i);
      if(values) *values++ = 0;
      return 1;
    }
  if(type == 2)
    {
      if(count == 0)
 {
   argv[i] = "\001\002\090";
   return 1;
 }
      if(strchr(argv[i], '='))
 {
   *values = strdup(strchr(argv[i], '=')+1);
   unquote(*values++);
   count--;
 }
      for(j=i+1;count--;j++)
 {
   if(argv[j])
     {
       if(strcmp(argv[j], "\001\002\090"))
  *values = strdup(argv[j]);
       else
  {
    if(err) *err |= 4;
    goto err_long;
  }
     }
   else
     {
       if(err) *err |= 2;
     err_long:
       rem_opt(argv, i, i);
       return 0;
     }
   unquote(*values++);
   argv[j] = "\001\002\090";
 }
      argv[i] = "\001\002\090";
      *values++ = 0;
      return 1;
    }
  return 0;
}

variable_types:
argv
char **

variable_types: count int

variable_types:
values
char **

variable_types: j int

variable_types: i int

variable_types: type int

variable_types:
p
char *

return_type: int


jelopt

decompiled_code:
__int64 __fastcall jelopt(_QWORD *a1, int a2, const char *a3, _QWORD *a4, _DWORD *a5)
{
__int64 result; // rax
char *v7; // [rsp+0h] [rbp-18h] BYREF

result = jelopt_multi(a1, a2, a3, a4 != 0LL, &v7, a5);
if ( (_DWORD)result )
{
result = 1LL;
if ( a4 )
{
*a4 = v7;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, const char *a3, _QWORD *a4, _DWORD *a5)
{
__int64 result; // rax
char *v7; // [rsp+0h] [rbp-18h] BYREF

result = func6(a1, a2, a3, a4 != 0LL, &v7, a5);
if ( (_DWORD)result )
{
result = 1LL;
if ( a4 )
{
*a4 = v7;
result = 1LL;
}
}
return result;
}

original_code:
int jelopt(char **argv, int opt_short, char *opt_long, char **value, int *err)
{
  char *cvalue[2];
  if(jelopt_multi(argv, opt_short, opt_long, value?1:0, cvalue, err))
    {
      if(value)
 *value = cvalue[0];
      return 1;
    }
  return 0;
}

variable_types:
value
char **

variable_types:
cvalue
char *[2]


decompiled_code:
__int64 __fastcall jelopt_int(_QWORD *a1, int a2, const char *a3, int *a4, _DWORD *a5)
{
__int64 result; // rax
char *v7; // rbp
char *nptr; // [rsp+8h] [rbp-20h] BYREF

result = jelopt(a1, a2, a3, &nptr, a5);
if ( (_DWORD)result )
{
v7 = nptr;
*a4 = atoi(nptr);
free(v7);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, const char *a3, int *a4, _DWORD *a5)
{
__int64 result; // rax
char *v7; // rbp
char *nptr; // [rsp+8h] [rbp-20h] BYREF

result = func7(a1, a2, a3, &nptr, a5);
if ( (_DWORD)result )
{
v7 = nptr;
*a4 = atoi(nptr);
free(v7);
result = 1LL;
}
return result;
}

original_code:
int jelopt_int(char **argv, int opt_short, char *opt_long,
        int *value, int *err)
{
  char *cvalue;
  if(jelopt(argv, opt_short, opt_long, &cvalue, err))
    {
      *value = atoi(cvalue);
      free(cvalue);
      return 1;
    }
  return 0;
}

variable_types:
value
int *

variable_types:
cvalue
char *


repo: jemk/cedrus

decompiled_code:
size_t __fastcall frame_show(_QWORD *a1)
{
unsigned int v1; // er14
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp
unsigned int v8; // eax

if ( disp_initialized_1 )
goto LABEL_4;
if ( (unsigned int)disp_open() )
{
v1 = *((unsigned __int16 *)a1 + 9);
v2 = *((unsigned __int16 *)a1 + 8);
v3 = *((_DWORD *)a1 + 5);
v4 = ve_virt2phys(a1[1]);
v5 = ve_virt2phys(*a1);
disp_set_para(v5, v4, v3, v2, v1, 0LL, 0LL, 800LL, 600LL);
disp_initialized_1 = 1;
LABEL_4:
v6 = frame_id_0++;
v7 = ve_virt2phys(a1[1]);
v8 = ve_virt2phys(*a1);
return disp_new_frame(v8, v7, v6, 24000LL);
}
return fwrite("Can't open /dev/disp\n", 1uLL, 0x15uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func2(_QWORD *a1)
{
unsigned int v1; // er14
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp
unsigned int v8; // eax

if ( disp_initialized_1 )
goto LABEL_4;
if ( (unsigned int)disp_open() )
{
v1 = *((unsigned __int16 *)a1 + 9);
v2 = *((unsigned __int16 *)a1 + 8);
v3 = *((_DWORD *)a1 + 5);
v4 = ve_virt2phys(a1[1]);
v5 = ve_virt2phys(*a1);
disp_set_para(v5, v4, v3, v2, v1, 0LL, 0LL, 800LL, 600LL);
disp_initialized_1 = 1;
LABEL_4:
v6 = frame_id_0++;
v7 = ve_virt2phys(a1[1]);
v8 = ve_virt2phys(*a1);
return disp_new_frame(v8, v7, v6, 24000LL);
}
return fwrite("Can't open /dev/disp\n", 1uLL, 0x15uLL, stderr);
}

original_code:
void frame_show(struct frame_t *frame)
{
 static int disp_initialized = 0;
 static int frame_id = 0;
 if (!disp_initialized)
 {
  if (!disp_open())
  {
   fprintf(stderr, "Can't open /dev/disp\n");
   return;
  }
  disp_set_para(ve_virt2phys(frame->luma_buffer), ve_virt2phys(frame->chroma_buffer),
   frame->color, frame->width, frame->height,
   0, 0, 800, 600);
  disp_initialized = 1;
 }
 disp_new_frame(ve_virt2phys(frame->luma_buffer), ve_virt2phys(frame->chroma_buffer),
  frame_id++, 24000);
}

variable_types: struct frame_t { void *luma_buffer; void *chroma_buffer; unsigned short width; int color; int ref_counter; } *

return_type: void


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

result = a1;
if ( a1 )
++*(_DWORD *)(a1 + 24);
return result;
}

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

result = a1;
if ( a1 )
++*(_DWORD *)(a1 + 24);
return result;
}

original_code:
struct frame_t *frame_ref(struct frame_t *frame)
{
 if (!frame)
  return ((void *)0);
 frame->ref_counter++;
 return frame;
}

variable_types:
frame
struct frame_t *

return_type: struct frame_t { void *luma_buffer; void *chroma_buffer; unsigned short width; int color; int ref_counter; } *


decompiled_code:
void __fastcall frame_unref(void *ptr)
{
int v1; // eax

if ( ptr )
{
v1 = *((_DWORD *)ptr + 6) - 1;
*((_DWORD *)ptr + 6) = v1;
if ( v1 <= 0 )
{
ve_free(*(_QWORD *)ptr);
ve_free(*((_QWORD *)ptr + 1));
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
int v1; // eax

if ( ptr )
{
v1 = *((_DWORD *)ptr + 6) - 1;
*((_DWORD *)ptr + 6) = v1;
if ( v1 <= 0 )
{
ve_free(*(_QWORD *)ptr);
ve_free(*((_QWORD *)ptr + 1));
free(ptr);
}
}
}

original_code:
void frame_unref(struct frame_t *frame)
{
 if (!frame)
  return;
 frame->ref_counter--;
 if (frame->ref_counter <= 0)
 {
  ve_free(frame->luma_buffer);
  ve_free(frame->chroma_buffer);
  free(frame);
 }
}

user_defined_types: struct frame_t { void *luma_buffer; void *chroma_buffer; unsigned short width; int color; int ref_counter; }


original_code:
void decode_mpeg(struct frame_buffers_t *frame_buffers, const struct mpeg_t * const mpeg)
{
 int input_size = (mpeg->len + 65535) & ~65535;
 uint8_t *input_buffer = ve_malloc(input_size);
 memcpy(input_buffer, mpeg->data, mpeg->len);
 ve_flush_cache(input_buffer, mpeg->len);
 void *ve_regs = ve_get(0x0, 0);
 set_quantization_tables(ve_regs, mpeg_default_intra_quant, mpeg_default_non_intra_quant);
 uint16_t width = (mpeg->width + 15) / 16;
 uint16_t height = (mpeg->height + 15) / 16;
 writel((width << 8) | height, ve_regs + 0x108);
 writel(((width * 16) << 16) | (height * 16), ve_regs + 0x10c);
 uint32_t pic_header = 0x00000000;
 pic_header |= ((mpeg->picture_coding_type & 0xf) << 28);
 pic_header |= ((mpeg->f_code[0][0] & 0xf) << 24);
 pic_header |= ((mpeg->f_code[0][1] & 0xf) << 20);
 pic_header |= ((mpeg->f_code[1][0] & 0xf) << 16);
 pic_header |= ((mpeg->f_code[1][1] & 0xf) << 12);
 pic_header |= ((mpeg->intra_dc_precision & 0x3) << 10);
 pic_header |= ((mpeg->picture_structure & 0x3) << 8);
 pic_header |= ((mpeg->top_field_first & 0x1) << 7);
 pic_header |= ((mpeg->frame_pred_frame_dct & 0x1) << 6);
 pic_header |= ((mpeg->concealment_motion_vectors & 0x1) << 5);
 pic_header |= ((mpeg->q_scale_type & 0x1) << 4);
 pic_header |= ((mpeg->intra_vlc_format & 0x1) << 3);
 pic_header |= ((mpeg->alternate_scan & 0x1) << 2);
 pic_header |= ((mpeg->full_pel_forward_vector & 0x1) << 1);
 pic_header |= ((mpeg->full_pel_backward_vector & 0x1) << 0);
 writel(pic_header, ve_regs + 0x100);
 writel(0x00000000, ve_regs + 0x100 + 0x10);
 writel(0x800001b8, ve_regs + 0x114);
 writel(0x00000000, ve_regs + 0x100 + 0xc4);
 writel(0x00000000, ve_regs + 0x100 + 0xc8);
 if (mpeg->picture_coding_type == PCT_I || mpeg->picture_coding_type == PCT_P)
 {
  frame_unref(frame_buffers->forward);
  frame_buffers->forward = frame_ref(frame_buffers->backward);
  frame_unref(frame_buffers->backward);
  frame_buffers->backward = frame_ref(frame_buffers->output);
 }
 writel(ve_virt2phys(frame_buffers->forward->luma_buffer), ve_regs + 0x150);
 writel(ve_virt2phys(frame_buffers->forward->chroma_buffer), ve_regs + 0x154);
 writel(ve_virt2phys(frame_buffers->backward->luma_buffer), ve_regs + 0x158);
 writel(ve_virt2phys(frame_buffers->backward->chroma_buffer), ve_regs + 0x15c);
 writel(ve_virt2phys(frame_buffers->output->luma_buffer), ve_regs + 0x148);
 writel(ve_virt2phys(frame_buffers->output->chroma_buffer), ve_regs + 0x14c);
 writel(ve_virt2phys(frame_buffers->output->luma_buffer), ve_regs + 0x1cc);
 writel(ve_virt2phys(frame_buffers->output->chroma_buffer), ve_regs + 0x1d0);
 writel((mpeg->pos - 4) * 8, ve_regs + 0x12c);
 writel((mpeg->len - (mpeg->pos - 4) + 16) * 8, ve_regs + 0x130);
 writel(ve_virt2phys(input_buffer) + input_size - 1, ve_regs + 0x134);
 writel(ve_virt2phys(input_buffer) | 0x50000000, ve_regs + 0x128);
 writel((mpeg->type ? 0x02000000 : 0x01000000) | 0x8000000f, ve_regs + 0x118);
 ve_wait(1);
 writel(0x0000c00f, ve_regs + 0x11c);
 ve_put();
 ve_free(input_buffer);
}

canonical_original_code:
void decode_mpeg(struct frame_buffers_t *frame_buffers, struct mpeg_t *mpeg)
{
 int input_size = (mpeg->len + 65535) & ~65535;
 unsigned char *input_buffer = ve_malloc(input_size);
 memcpy(input_buffer, mpeg->data, mpeg->len);
 ve_flush_cache(input_buffer, mpeg->len);
 void *ve_regs = ve_get(0x0, 0);
 set_quantization_tables(ve_regs, mpeg_default_intra_quant, mpeg_default_non_intra_quant);
 unsigned short width = (mpeg->width + 15) / 16;
 unsigned short height = (mpeg->height + 15) / 16;
 writel((width << 8) | height, ve_regs + 0x108);
 writel(((width * 16) << 16) | (height * 16), ve_regs + 0x10c);
 unsigned int pic_header = 0x00000000;
 pic_header |= ((mpeg->picture_coding_type & 0xf) << 28);
 pic_header |= ((mpeg->f_code[0][0] & 0xf) << 24);
 pic_header |= ((mpeg->f_code[0][1] & 0xf) << 20);
 pic_header |= ((mpeg->f_code[1][0] & 0xf) << 16);
 pic_header |= ((mpeg->f_code[1][1] & 0xf) << 12);
 pic_header |= ((mpeg->intra_dc_precision & 0x3) << 10);
 pic_header |= ((mpeg->picture_structure & 0x3) << 8);
 pic_header |= ((mpeg->top_field_first & 0x1) << 7);
 pic_header |= ((mpeg->frame_pred_frame_dct & 0x1) << 6);
 pic_header |= ((mpeg->concealment_motion_vectors & 0x1) << 5);
 pic_header |= ((mpeg->q_scale_type & 0x1) << 4);
 pic_header |= ((mpeg->intra_vlc_format & 0x1) << 3);
 pic_header |= ((mpeg->alternate_scan & 0x1) << 2);
 pic_header |= ((mpeg->full_pel_forward_vector & 0x1) << 1);
 pic_header |= ((mpeg->full_pel_backward_vector & 0x1) << 0);
 writel(pic_header, ve_regs + 0x100);
 writel(0x00000000, ve_regs + 0x100 + 0x10);
 writel(0x800001b8, ve_regs + 0x114);
 writel(0x00000000, ve_regs + 0x100 + 0xc4);
 writel(0x00000000, ve_regs + 0x100 + 0xc8);
 if (mpeg->picture_coding_type == PCT_I || mpeg->picture_coding_type == PCT_P)
 {
  frame_unref(frame_buffers->forward);
  frame_buffers->forward = frame_ref(frame_buffers->backward);
  frame_unref(frame_buffers->backward);
  frame_buffers->backward = frame_ref(frame_buffers->output);
 }
 writel(ve_virt2phys(frame_buffers->forward->luma_buffer), ve_regs + 0x150);
 writel(ve_virt2phys(frame_buffers->forward->chroma_buffer), ve_regs + 0x154);
 writel(ve_virt2phys(frame_buffers->backward->luma_buffer), ve_regs + 0x158);
 writel(ve_virt2phys(frame_buffers->backward->chroma_buffer), ve_regs + 0x15c);
 writel(ve_virt2phys(frame_buffers->output->luma_buffer), ve_regs + 0x148);
 writel(ve_virt2phys(frame_buffers->output->chroma_buffer), ve_regs + 0x14c);
 writel(ve_virt2phys(frame_buffers->output->luma_buffer), ve_regs + 0x1cc);
 writel(ve_virt2phys(frame_buffers->output->chroma_buffer), ve_regs + 0x1d0);
 writel((mpeg->pos - 4) * 8, ve_regs + 0x12c);
 writel((mpeg->len - (mpeg->pos - 4) + 16) * 8, ve_regs + 0x130);
 writel(ve_virt2phys(input_buffer) + input_size - 1, ve_regs + 0x134);
 writel(ve_virt2phys(input_buffer) | 0x50000000, ve_regs + 0x128);
 writel((mpeg->type ? 0x02000000 : 0x01000000) | 0x8000000f, ve_regs + 0x118);
 ve_wait(1);
 writel(0x0000c00f, ve_regs + 0x11c);
 ve_put();
 ve_free(input_buffer);
}

variable_types: struct frame_buffers_t { struct frame_t { void *luma_buffer; void *chroma_buffer; unsigned short width; int color; int ref_counter; } *output; struct frame_t *backward; struct frame_t *forward; } *

variable_types: struct mpeg_t { unsigned char *data; int len; int pos; unsigned int gop; enum { MPEG1=0, MPEG2=1 } type; unsigned short width; unsigned short height; unsigned short temporal_reference; enum { PCT_I=1, PCT_P=2, PCT_B=3, PCT_D=4 } picture_coding_type; unsigned char full_pel_forward_vector; unsigned char full_pel_backward_vector; unsigned char f_code[2][2]; unsigned char intra_dc_precision; unsigned char picture_structure; unsigned char top_field_first; unsigned char frame_pred_frame_dct; unsigned char concealment_motion_vectors; unsigned char q_scale_type; unsigned char intra_vlc_format; unsigned char alternate_scan; } *

variable_types:
width
unsigned short

variable_types:
height
unsigned short

user_defined_types: struct frame_buffers_t { struct frame_t *output; struct frame_t *backward; struct frame_t *forward; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
int v5; // er12
unsigned int v6; // ebx
unsigned int v7; // er14
int v8; // er13
int v9; // ebp
unsigned int v10; // ebx
const char *v11; // rax
_QWORD *v12; // rdi
__int64 v13; // r15
_QWORD *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
_QWORD *v19; // rax
unsigned int v20; // er13
__int64 v21; // rbp
void *ptr; // [rsp+0h] [rbp-138h]
__int64 v24; // [rsp+8h] [rbp-130h]
__int64 v25; // [rsp+10h] [rbp-128h]
__int64 v26; // [rsp+18h] [rbp-120h]
__int64 v27; // [rsp+20h] [rbp-118h]
__int64 v28; // [rsp+28h] [rbp-110h]
__int64 v29; // [rsp+30h] [rbp-108h]
__int64 v30; // [rsp+38h] [rbp-100h]
_QWORD *v31; // [rsp+40h] [rbp-F8h] BYREF
void *v32; // [rsp+48h] [rbp-F0h]
void *v33; // [rsp+50h] [rbp-E8h]
__int64 v34; // [rsp+60h] [rbp-D8h] BYREF
__int64 v35; // [rsp+68h] [rbp-D0h]
__int64 v36; // [rsp+70h] [rbp-C8h]
__int64 v37; // [rsp+78h] [rbp-C0h]
__int64 v38; // [rsp+80h] [rbp-B8h]
__int64 v39; // [rsp+88h] [rbp-B0h]
__int64 v40; // [rsp+90h] [rbp-A8h]
char v41[24]; // [rsp+A0h] [rbp-98h] BYREF
__int64 v42; // [rsp+B8h] [rbp-80h]
unsigned int v43; // [rsp+C0h] [rbp-78h]
int v44; // [rsp+C4h] [rbp-74h]
__int64 v45[8]; // [rsp+F8h] [rbp-40h] BYREF

v45[0] = 0LL;
if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s filename\n", *argv);
exit(1);
}
v3 = argv[1];
av_register_all(argc, argv, envp);
if ( (int)avformat_open_input(v45, v3, 0LL, 0LL) < 0 )
{
fprintf(stderr, "Could not open source file %s\n", v3);
exit(1);
}
if ( (int)avformat_find_stream_info(v45[0], 0LL) < 0 )
{
fwrite("Could not find stream information\n", 1uLL, 0x22uLL, stderr);
avformat_close_input(v45);
exit(1);
}
v4 = av_find_best_stream(v45[0], 0LL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL);
v5 = v4;
if ( v4 < 0 )
{
fwrite("Could not find video stream in input file\n", 1uLL, 0x2AuLL, stderr);
avformat_close_input(v45);
exit(1);
}
v6 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v45[0] + 48) + 8LL * v4) + 8LL) + 24LL);
if ( v6 - 1 > 1 )
{
v11 = (const char *)avcodec_get_name(v6);
fprintf(stderr, "Can't handle codec %s\n", v11);
avformat_close_input(v45);
exit(1);
}
av_init_packet(v41);
v42 = 0LL;
v43 = 0;
v34 = 0LL;
v35 = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
v40 = 0LL;
if ( v6 != 1 )
HIDWORD(v36) = 1;
if ( !(unsigned int)ve_open() )
err(1, "Can't open VE");
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
ptr = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
puts("Playing now... press Enter for next frame!");
v7 = 0;
v8 = 0;
v9 = 0;
v10 = 0;
while ( 1 )
{
v14 = (_QWORD *)v45[0];
if ( (int)av_read_frame(v45[0], v41) < 0 )
break;
v34 = v42;
v35 = v43;
if ( v44 == v5 && (unsigned int)parse_mpeg(&v34) )
{
v19 = frame_new(v37, WORD1(v37), 0);
v31 = v19;
if ( !v32 )
v32 = (void *)frame_ref((__int64)v19);
if ( !v33 )
v33 = (void *)frame_ref((__int64)v31);
decode_mpeg(&v31, (__int64)&v34);
if ( (unsigned int)v36 > v7 )
{
v9 += v8;
v7 = v36;
v8 = 0;
}
++v8;
if ( *(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)) )
{
puts("Buffer overrun!");
frame_unref(*(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)));
}
*(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)) = v31;
v12 = *(&ptr + (v10 & 7));
if ( v12 )
{
frame_show(v12);
v13 = ((_BYTE)v10 - 2) & 7;
frame_unref(*(&ptr + v13));
*(&ptr + v13) = 0LL;
++v10;
getchar();
}
}
av_free_packet(v41);
}
v20 = v9 + v8;
if ( v10 < v20 )
{
while ( 1 )
{
v14 = *(&ptr + (v10 & 7));
if ( !v14 )
break;
frame_show(v14);
v21 = ((_BYTE)v10 - 2) & 7;
v14 = *(&ptr + v21);
frame_unref(v14);
*(&ptr + v21) = 0LL;
++v10;
getchar();
if ( v10 == v20 )
{
LOBYTE(v10) = v20;
break;
}
}
}
disp_close(v14, v41, v15, v16, v17, v18, ptr, v24);
frame_unref(*(&ptr + (((_BYTE)v10 - 2) & 7)));
frame_unref(*(&ptr + (((_BYTE)v10 - 1) & 7)));
frame_unref(v33);
frame_unref(v32);
ve_close();
avformat_close_input(v45);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
int v5; // er12
unsigned int v6; // ebx
unsigned int v7; // er14
int v8; // er13
int v9; // ebp
unsigned int v10; // ebx
const char *v11; // rax
_QWORD *v12; // rdi
__int64 v13; // r15
_QWORD *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
_QWORD *v19; // rax
unsigned int v20; // er13
__int64 v21; // rbp
void *ptr; // [rsp+0h] [rbp-138h]
__int64 v24; // [rsp+8h] [rbp-130h]
__int64 v25; // [rsp+10h] [rbp-128h]
__int64 v26; // [rsp+18h] [rbp-120h]
__int64 v27; // [rsp+20h] [rbp-118h]
__int64 v28; // [rsp+28h] [rbp-110h]
__int64 v29; // [rsp+30h] [rbp-108h]
__int64 v30; // [rsp+38h] [rbp-100h]
_QWORD *v31; // [rsp+40h] [rbp-F8h] BYREF
void *v32; // [rsp+48h] [rbp-F0h]
void *v33; // [rsp+50h] [rbp-E8h]
__int64 v34; // [rsp+60h] [rbp-D8h] BYREF
__int64 v35; // [rsp+68h] [rbp-D0h]
__int64 v36; // [rsp+70h] [rbp-C8h]
__int64 v37; // [rsp+78h] [rbp-C0h]
__int64 v38; // [rsp+80h] [rbp-B8h]
__int64 v39; // [rsp+88h] [rbp-B0h]
__int64 v40; // [rsp+90h] [rbp-A8h]
char v41[24]; // [rsp+A0h] [rbp-98h] BYREF
__int64 v42; // [rsp+B8h] [rbp-80h]
unsigned int v43; // [rsp+C0h] [rbp-78h]
int v44; // [rsp+C4h] [rbp-74h]
__int64 v45[8]; // [rsp+F8h] [rbp-40h] BYREF

v45[0] = 0LL;
if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s filename\n", *argv);
exit(1);
}
v3 = argv[1];
av_register_all(argc, argv, envp);
if ( (int)avformat_open_input(v45, v3, 0LL, 0LL) < 0 )
{
fprintf(stderr, "Could not open source file %s\n", v3);
exit(1);
}
if ( (int)avformat_find_stream_info(v45[0], 0LL) < 0 )
{
fwrite("Could not find stream information\n", 1uLL, 0x22uLL, stderr);
avformat_close_input(v45);
exit(1);
}
v4 = av_find_best_stream(v45[0], 0LL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL);
v5 = v4;
if ( v4 < 0 )
{
fwrite("Could not find video stream in input file\n", 1uLL, 0x2AuLL, stderr);
avformat_close_input(v45);
exit(1);
}
v6 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v45[0] + 48) + 8LL * v4) + 8LL) + 24LL);
if ( v6 - 1 > 1 )
{
v11 = (const char *)avcodec_get_name(v6);
fprintf(stderr, "Can't handle codec %s\n", v11);
avformat_close_input(v45);
exit(1);
}
av_init_packet(v41);
v42 = 0LL;
v43 = 0;
v34 = 0LL;
v35 = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
v40 = 0LL;
if ( v6 != 1 )
HIDWORD(v36) = 1;
if ( !(unsigned int)ve_open() )
err(1, "Can't open VE");
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
ptr = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
puts("Playing now... press Enter for next frame!");
v7 = 0;
v8 = 0;
v9 = 0;
v10 = 0;
while ( 1 )
{
v14 = (_QWORD *)v45[0];
if ( (int)av_read_frame(v45[0], v41) < 0 )
break;
v34 = v42;
v35 = v43;
if ( v44 == v5 && (unsigned int)parse_mpeg(&v34) )
{
v19 = frame_new(v37, WORD1(v37), 0);
v31 = v19;
if ( !v32 )
v32 = (void *)func3((__int64)v19);
if ( !v33 )
v33 = (void *)func3((__int64)v31);
func5(&v31, (__int64)&v34);
if ( (unsigned int)v36 > v7 )
{
v9 += v8;
v7 = v36;
v8 = 0;
}
++v8;
if ( *(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)) )
{
puts("Buffer overrun!");
func4(*(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)));
}
*(&ptr + (((_BYTE)v9 + BYTE4(v37)) & 7)) = v31;
v12 = *(&ptr + (v10 & 7));
if ( v12 )
{
func2(v12);
v13 = ((_BYTE)v10 - 2) & 7;
func4(*(&ptr + v13));
*(&ptr + v13) = 0LL;
++v10;
getchar();
}
}
av_free_packet(v41);
}
v20 = v9 + v8;
if ( v10 < v20 )
{
while ( 1 )
{
v14 = *(&ptr + (v10 & 7));
if ( !v14 )
break;
func2(v14);
v21 = ((_BYTE)v10 - 2) & 7;
v14 = *(&ptr + v21);
func4(v14);
*(&ptr + v21) = 0LL;
++v10;
getchar();
if ( v10 == v20 )
{
LOBYTE(v10) = v20;
break;
}
}
}
disp_close(v14, v41, v15, v16, v17, v18, ptr, v24);
func4(*(&ptr + (((_BYTE)v10 - 2) & 7)));
func4(*(&ptr + (((_BYTE)v10 - 1) & 7)));
func4(v33);
func4(v32);
ve_close();
avformat_close_input(v45);
return 0;
}

original_code:
int main(const int argc, const char **argv)
{
 int in;
 struct stat s;
 uint8_t *data;
 if (argc < 2)
 {
  fprintf(stderr, "Usage: %s infile.jpg\n", argv[0]);
  exit(1);
 }
 const char *filename = argv[1];
 if ((in = open(filename, 00)) == -1)
  err(1, "%s", filename);
 if (fstat(in, &s) < 0)
  err(1, "stat %s", filename);
 if (s.st_size == 0)
  errx(1, "%s empty", filename);
 if ((data = mmap(((void *)0), s.st_size, 0x1, 0x01, in, 0)) == ((void *) -1))
  err(1, "mmap %s", filename);
 struct jpeg_t jpeg ;
 memset(&jpeg, 0, sizeof(jpeg));
 if (!parse_jpeg(&jpeg, data, s.st_size))
  warnx("Can't parse JPEG");
 decode_jpeg(&jpeg);
 munmap(data, s.st_size);
 close(in);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int in;
 struct stat s;
 unsigned char *data;
 if (argc < 2)
 {
  fprintf(stderr, "Usage: %s infile.jpg\n", argv[0]);
  exit(1);
 }
 char *filename = argv[1];
 if ((in = open(filename, 00)) == -1)
  err(1, "%s", filename);
 if (fstat(in, &s) < 0)
  err(1, "stat %s", filename);
 if (s.st_size == 0)
  errx(1, "%s empty", filename);
 if ((data = mmap(((void *)0), s.st_size, 0x1, 0x01, in, 0)) == ((void *) -1))
  err(1, "mmap %s", filename);
 struct jpeg_t jpeg;
 memset(&jpeg, 0, sizeof(jpeg));
 if (!parse_jpeg(&jpeg, data, s.st_size))
  warnx("Can't parse JPEG");
 decode_jpeg(&jpeg);
 munmap(data, s.st_size);
 close(in);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: in int

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

variable_types:
data
unsigned char *

variable_types:
filename
char *

variable_types: struct jpeg_t { unsigned char bits; unsigned short width; unsigned short height; struct comp_t { unsigned char samp_h; unsigned char samp_v; unsigned char qt; unsigned char ht_ac; unsigned char ht_dc; } comp[3]; struct quant_t { unsigned char coeff[64]; } *quant[4]; struct huffman_t { unsigned char num[16]; unsigned char codes[256]; } *huffman[8]; unsigned short restart_interval; unsigned char *data; unsigned int data_len; }

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

user_defined_types: struct jpeg_t { unsigned char bits; unsigned short width; unsigned short height; struct comp_t comp[3]; struct quant_t *quant[4]; struct huffman_t *huffman[8]; unsigned short restart_interval; unsigned char *data; unsigned int data_len; }


original_code:
static int process_dht(struct jpeg_t *jpeg, const uint8_t *data, const int len)
{
 int pos = 0;
 while (pos < len)
 {
  uint8_t id = ((data[pos] & 0x03) << 1) | ((data[pos] & 0x10) >> 4);
  jpeg->huffman[id] = (struct huffman_t *)&(data[pos + 1]);
  int i;
  pos += 17;
  for (i = 0; i < 16; i++)
   pos += jpeg->huffman[id]->num[i];
 }
 return 1;
}

canonical_original_code:
static int process_dht(struct jpeg_t *jpeg, unsigned char *data, int len)
{
 int pos = 0;
 while (pos < len)
 {
  unsigned char id = ((data[pos] & 0x03) << 1) | ((data[pos] & 0x10) >> 4);
  jpeg->huffman[id] = (struct huffman_t *)&(data[pos + 1]);
  int i;
  pos += 17;
  for (i = 0; i < 16; i++)
   pos += jpeg->huffman[id]->num[i];
 }
 return 1;
}

variable_types: struct jpeg_t { unsigned char bits; unsigned short width; unsigned short height; struct comp_t { unsigned char samp_h; unsigned char samp_v; unsigned char qt; unsigned char ht_ac; unsigned char ht_dc; } comp[3]; struct quant_t { unsigned char coeff[64]; } *quant[4]; struct huffman_t { unsigned char num[16]; unsigned char codes[256]; } *huffman[8]; unsigned short restart_interval; unsigned char *data; unsigned int data_len; } *

variable_types: len int

variable_types: pos int

variable_types:
id
unsigned char

variable_types: i int


decompiled_code:
__int64 __fastcall process_dqt(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rsi
int v5; // edx

if ( a3 <= 0 )
return 1LL;
v4 = a2 + 1;
v5 = 0;
while ( !(*(_BYTE *)(v4 - 1) >> 4) )
{
*(_QWORD *)(a1 + 8LL * (*(_BYTE *)(v4 - 1) & 3) + 24) = v4;
v5 += 65;
v4 += 65LL;
if ( a3 <= v5 )
return 1LL;
}
fwrite("Only 8bit Quantization Tables supported\n", 1uLL, 0x28uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rsi
int v5; // edx

if ( a3 <= 0 )
return 1LL;
v4 = a2 + 1;
v5 = 0;
while ( !(*(_BYTE *)(v4 - 1) >> 4) )
{
*(_QWORD *)(a1 + 8LL * (*(_BYTE *)(v4 - 1) & 3) + 24) = v4;
v5 += 65;
v4 += 65LL;
if ( a3 <= v5 )
return 1LL;
}
fwrite("Only 8bit Quantization Tables supported\n", 1uLL, 0x28uLL, stderr);
return 0LL;
}

original_code:
static int process_dqt(struct jpeg_t *jpeg, const uint8_t *data, const int len)
{
 int pos;
 for (pos = 0; pos < len; pos += 65)
 {
  if ((data[pos] >> 4) != 0)
  {
   fprintf(stderr, "Only 8bit Quantization Tables supported\n");
   return 0;
  }
  jpeg->quant[data[pos] & 0x03] = (struct quant_t *)&(data[pos + 1]);
 }
 return 1;
}

canonical_original_code:
static int process_dqt(struct jpeg_t *jpeg, unsigned char *data, int len)
{
 int pos;
 for (pos = 0; pos < len; pos += 65)
 {
  if ((data[pos] >> 4) != 0)
  {
   fprintf(stderr, "Only 8bit Quantization Tables supported\n");
   return 0;
  }
  jpeg->quant[data[pos] & 0x03] = (struct quant_t *)&(data[pos + 1]);
 }
 return 1;
}

user_defined_types: struct quant_t { unsigned char coeff[64]; }

user_defined_types: struct comp_t { unsigned char samp_h; unsigned char samp_v; unsigned char qt; unsigned char ht_ac; unsigned char ht_dc; }

user_defined_types: struct huffman_t { unsigned char num[16]; unsigned char codes[256]; }


decompiled_code:
__int64 __fastcall parse_jpeg(__int64 a1, _BYTE *a2, int a3)
{
__int64 result; // rax
int v7; // ebx
_BYTE *v8; // rdi
_BYTE *v9; // rdx
int v10; // esi
__int64 v11; // rax
_BYTE *v12; // rdi
_BYTE *v13; // rdx
int v14; // esi
_BYTE *v15; // rax
_BYTE *v16; // rax
int v17; // edi
__int64 v18; // r8
char v19; // dl
__int64 v20; // rcx
unsigned __int16 v21; // ax

result = 0LL;
if ( a3 > 1 && *a2 == 0xFF )
{
v7 = 2;
if ( a2[1] == 0xD8 )
{
LABEL_20:
while ( 2 )
{
if ( a3 > v7 )
{
v16 = &a2[v7];
do
{
if ( *v16 != 0xFF )
break;
++v7;
++v16;
}
while ( a3 != v7 );
}
if ( v7 + 2 >= a3 )
{
result = 0LL;
}
else
{
v17 = v7 + 1;
v18 = v7;
v19 = a2[v7];
v20 = v7 + 1;
v21 = _byteswap_ushort(*(_WORD *)&a2[v20]);
v7 += v21 + 1;
if ( v7 >= a3 )
{
result = 0LL;
}
else
{
switch ( v19 )
{
case -64:
*(_BYTE *)a1 = a2[v17 + 2];
*(_WORD *)(a1 + 2) = _byteswap_ushort(*(_WORD *)&a2[v17 + 5]);
*(_WORD *)(a1 + 4) = _byteswap_ushort(*(_WORD *)&a2[v17 + 3]);
v12 = &a2[v17 + 7];
if ( !*v12 )
continue;
v13 = &a2[v18 + 9];
v14 = 0;
while ( (unsigned __int8)(*v13 - 1) <= 2u )
{
v15 = (_BYTE *)(a1 + 5LL * (unsigned __int8)(*v13 - 1));
v15[6] = v13[1] >> 4;
v15[7] = v13[1] & 0xF;
v15[8] = v13[2];
++v14;
v13 += 3;
if ( (unsigned __int8)*v12 <= v14 )
goto LABEL_20;
}
goto LABEL_18;
case -63:
case -62:
case -61:
case -59:
case -58:
case -57:
case -55:
case -54:
case -53:
case -51:
case -50:
case -49:
fwrite("only Baseline DCT supported (yet?)\n", 1uLL, 0x23uLL, stderr);
return 0LL;
case -60:
result = process_dht(a1, (__int64)&a2[v20 + 2], (unsigned int)v21 - 2);
if ( (_DWORD)result )
continue;
return result;
case -52:
fwrite("Arithmetic Coding unsupported\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
case -40:
case -39:
fwrite("corrupted file\n", 1uLL, 0xFuLL, stderr);
return 0LL;
case -38:
v8 = &a2[v17 + 2];
v9 = &a2[v18 + 5];
v10 = 0;
if ( !*v8 )
goto LABEL_8;
break;
case -37:
result = process_dqt(a1, (__int64)&a2[v20 + 2], (unsigned int)v21 - 2);
if ( (_DWORD)result )
continue;
return result;
case -35:
*(_WORD *)(a1 + 120) = _byteswap_ushort(*(_WORD *)&a2[v17 + 2]);
continue;
default:
continue;
}
while ( (unsigned __int8)(*(v9 - 1) - 1) <= 2u )
{
v11 = a1 + 5LL * (unsigned __int8)(*(v9 - 1) - 1);
*(_BYTE *)(v11 + 10) = *v9 >> 4;
*(_BYTE *)(v11 + 9) = *v9 & 0xF;
++v10;
v9 += 2;
if ( (unsigned __int8)*v8 <= v10 )
{
LABEL_8:
*(_QWORD *)(a1 + 128) = &a2[v7];
*(_DWORD *)(a1 + 136) = a3 - v7;
return 1LL;
}
}
LABEL_18:
fwrite("only YCbCr supported\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
}
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, int a3)
{
__int64 result; // rax
int v7; // ebx
_BYTE *v8; // rdi
_BYTE *v9; // rdx
int v10; // esi
__int64 v11; // rax
_BYTE *v12; // rdi
_BYTE *v13; // rdx
int v14; // esi
_BYTE *v15; // rax
_BYTE *v16; // rax
int v17; // edi
__int64 v18; // r8
char v19; // dl
__int64 v20; // rcx
unsigned __int16 v21; // ax

result = 0LL;
if ( a3 > 1 && *a2 == 0xFF )
{
v7 = 2;
if ( a2[1] == 0xD8 )
{
LABEL_20:
while ( 2 )
{
if ( a3 > v7 )
{
v16 = &a2[v7];
do
{
if ( *v16 != 0xFF )
break;
++v7;
++v16;
}
while ( a3 != v7 );
}
if ( v7 + 2 >= a3 )
{
result = 0LL;
}
else
{
v17 = v7 + 1;
v18 = v7;
v19 = a2[v7];
v20 = v7 + 1;
v21 = _byteswap_ushort(*(_WORD *)&a2[v20]);
v7 += v21 + 1;
if ( v7 >= a3 )
{
result = 0LL;
}
else
{
switch ( v19 )
{
case -64:
*(_BYTE *)a1 = a2[v17 + 2];
*(_WORD *)(a1 + 2) = _byteswap_ushort(*(_WORD *)&a2[v17 + 5]);
*(_WORD *)(a1 + 4) = _byteswap_ushort(*(_WORD *)&a2[v17 + 3]);
v12 = &a2[v17 + 7];
if ( !*v12 )
continue;
v13 = &a2[v18 + 9];
v14 = 0;
while ( (unsigned __int8)(*v13 - 1) <= 2u )
{
v15 = (_BYTE *)(a1 + 5LL * (unsigned __int8)(*v13 - 1));
v15[6] = v13[1] >> 4;
v15[7] = v13[1] & 0xF;
v15[8] = v13[2];
++v14;
v13 += 3;
if ( (unsigned __int8)*v12 <= v14 )
goto LABEL_20;
}
goto LABEL_18;
case -63:
case -62:
case -61:
case -59:
case -58:
case -57:
case -55:
case -54:
case -53:
case -51:
case -50:
case -49:
fwrite("only Baseline DCT supported (yet?)\n", 1uLL, 0x23uLL, stderr);
return 0LL;
case -60:
result = func0(a1, (__int64)&a2[v20 + 2], (unsigned int)v21 - 2);
if ( (_DWORD)result )
continue;
return result;
case -52:
fwrite("Arithmetic Coding unsupported\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
case -40:
case -39:
fwrite("corrupted file\n", 1uLL, 0xFuLL, stderr);
return 0LL;
case -38:
v8 = &a2[v17 + 2];
v9 = &a2[v18 + 5];
v10 = 0;
if ( !*v8 )
goto LABEL_8;
break;
case -37:
result = func1(a1, (__int64)&a2[v20 + 2], (unsigned int)v21 - 2);
if ( (_DWORD)result )
continue;
return result;
case -35:
*(_WORD *)(a1 + 120) = _byteswap_ushort(*(_WORD *)&a2[v17 + 2]);
continue;
default:
continue;
}
while ( (unsigned __int8)(*(v9 - 1) - 1) <= 2u )
{
v11 = a1 + 5LL * (unsigned __int8)(*(v9 - 1) - 1);
*(_BYTE *)(v11 + 10) = *v9 >> 4;
*(_BYTE *)(v11 + 9) = *v9 & 0xF;
++v10;
v9 += 2;
if ( (unsigned __int8)*v8 <= v10 )
{
LABEL_8:
*(_QWORD *)(a1 + 128) = &a2[v7];
*(_DWORD *)(a1 + 136) = a3 - v7;
return 1LL;
}
}
LABEL_18:
fwrite("only YCbCr supported\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
}
break;
}
}
}
return result;
}

original_code:
int parse_jpeg(struct jpeg_t *jpeg, const uint8_t *data, const int len)
{
 if (len < 2 || data[0] != 0xff || data[1] != 0xd8)
  return 0;
 int pos = 2;
 int sos = 0;
 while (!sos)
 {
  int i;
  while (pos < len && data[pos] == 0xff)
   pos++;
  if (!(pos + 2 < len))
   return 0;
  uint8_t marker = data[pos++];
  uint16_t seg_len = ((uint16_t)data[pos]) << 8 | (uint16_t)data[pos + 1];
  if (!(pos + seg_len < len))
   return 0;
  switch (marker)
  {
  case 0xdb:
   if (!process_dqt(jpeg, &data[pos + 2], seg_len - 2))
    return 0;
   break;
  case 0xc4:
   if (!process_dht(jpeg, &data[pos + 2], seg_len - 2))
    return 0;
   break;
  case 0xc0:
   jpeg->bits = data[pos + 2];
   jpeg->width = ((uint16_t)data[pos + 5]) << 8 | (uint16_t)data[pos + 6];
   jpeg->height = ((uint16_t)data[pos + 3]) << 8 | (uint16_t)data[pos + 4];
   for (i = 0; i < data[pos + 7]; i++)
   {
    uint8_t id = data[pos + 8 + 3 * i] - 1;
    if (id > 2)
    {
     fprintf(stderr, "only YCbCr supported\n");
     return 0;
    }
    jpeg->comp[id].samp_h = data[pos + 9 + 3 * i] >> 4;
    jpeg->comp[id].samp_v = data[pos + 9 + 3 * i] & 0x0f;
    jpeg->comp[id].qt = data[pos + 10 + 3 * i];
   }
   break;
  case 0xdd:
   jpeg->restart_interval = ((uint16_t)data[pos + 2]) << 8 | (uint16_t)data[pos + 3];
   break;
  case 0xda:
   for (i = 0; i < data[pos + 2]; i++)
   {
    uint8_t id = data[pos + 3 + 2 * i] - 1;
    if (id > 2)
    {
     fprintf(stderr, "only YCbCr supported\n");
     return 0;
    }
    jpeg->comp[id].ht_dc = data[pos + 4 + 2 * i] >> 4;
    jpeg->comp[id].ht_ac = data[pos + 4 + 2 * i] & 0x0f;
   }
   sos = 1;
   break;
  case 0xcc:
   fprintf(stderr, "Arithmetic Coding unsupported\n");
   return 0;
  case 0xc1:
  case 0xc2:
  case 0xc3:
  case 0xc5:
  case 0xc6:
  case 0xc7:
  case 0xc9:
  case 0xca:
  case 0xcb:
  case 0xcd:
  case 0xce:
  case 0xcf:
   fprintf(stderr, "only Baseline DCT supported (yet?)\n");
   return 0;
  case 0xd8:
  case 0xd9:
   fprintf(stderr, "corrupted file\n");
   return 0;
  default:
   break;
  }
  pos += seg_len;
 }
 jpeg->data = (uint8_t *)&(data[pos]);
 jpeg->data_len = len - pos;
 return 1;
}

canonical_original_code:
int parse_jpeg(struct jpeg_t *jpeg, unsigned char *data, int len)
{
 if (len < 2 || data[0] != 0xff || data[1] != 0xd8)
  return 0;
 int pos = 2;
 int sos = 0;
 while (!sos)
 {
  int i;
  while (pos < len && data[pos] == 0xff)
   pos++;
  if (!(pos + 2 < len))
   return 0;
  unsigned char marker = data[pos++];
  unsigned short seg_len = ((uint16_t)data[pos]) << 8 | (uint16_t)data[pos + 1];
  if (!(pos + seg_len < len))
   return 0;
  switch (marker)
  {
  case 0xdb:
   if (!process_dqt(jpeg, &data[pos + 2], seg_len - 2))
    return 0;
   break;
  case 0xc4:
   if (!process_dht(jpeg, &data[pos + 2], seg_len - 2))
    return 0;
   break;
  case 0xc0:
   jpeg->bits = data[pos + 2];
   jpeg->width = ((unsigned short)data[pos + 5]) << 8 | (unsigned short)data[pos + 6];
   jpeg->height = ((unsigned short)data[pos + 3]) << 8 | (unsigned short)data[pos + 4];
   for (i = 0; i < data[pos + 7]; i++)
   {
    unsigned char id = data[pos + 8 + 3 * i] - 1;
    if (id > 2)
    {
     fprintf(stderr, "only YCbCr supported\n");
     return 0;
    }
    jpeg->comp[id].samp_h = data[pos + 9 + 3 * i] >> 4;
    jpeg->comp[id].samp_v = data[pos + 9 + 3 * i] & 0x0f;
    jpeg->comp[id].qt = data[pos + 10 + 3 * i];
   }
   break;
  case 0xdd:
   jpeg->restart_interval = ((unsigned short)data[pos + 2]) << 8 | (unsigned short)data[pos + 3];
   break;
  case 0xda:
   for (i = 0; i < data[pos + 2]; i++)
   {
    unsigned char id = data[pos + 3 + 2 * i] - 1;
    if (id > 2)
    {
     fprintf(stderr, "only YCbCr supported\n");
     return 0;
    }
    jpeg->comp[id].ht_dc = data[pos + 4 + 2 * i] >> 4;
    jpeg->comp[id].ht_ac = data[pos + 4 + 2 * i] & 0x0f;
   }
   sos = 1;
   break;
  case 0xcc:
   fprintf(stderr, "Arithmetic Coding unsupported\n");
   return 0;
  case 0xc1:
  case 0xc2:
  case 0xc3:
  case 0xc5:
  case 0xc6:
  case 0xc7:
  case 0xc9:
  case 0xca:
  case 0xcb:
  case 0xcd:
  case 0xce:
  case 0xcf:
   fprintf(stderr, "only Baseline DCT supported (yet?)\n");
   return 0;
  case 0xd8:
  case 0xd9:
   fprintf(stderr, "corrupted file\n");
   return 0;
  default:
   break;
  }
  pos += seg_len;
 }
 jpeg->data = (unsigned char *)&(data[pos]);
 jpeg->data_len = len - pos;
 return 1;
}

variable_types: sos int

variable_types:
marker
unsigned char


decompiled_code:
int __fastcall dump_jpeg(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
const char *v2; // rbp
unsigned __int8 v3; // dl
_QWORD *v4; // r13
unsigned int i; // er14
int j; // ebp
int v7; // ebx
__int64 *v8; // r15
int v9; // er13
int l; // ebp
__int64 v11; // rdx
int v12; // ebx
int k; // [rsp+4h] [rbp-44h]

printf(
"Width: %u Height: %u Bits: %u\nRestart interval: %u\nComponents:\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
*a1,
*((unsigned __int16 *)a1 + 60));
v1 = a1 + 6;
v2 = (const char *)&comp_types;
do
{
if ( *v1 )
{
v3 = v1[1];
if ( v3 )
printf("\tType: %s Sampling: %u:%u QT: %u HT: %u/%u\n", v2, *v1, v3, v1[2], v1[4], v1[4]);
}
v1 += 5;
v2 += 3;
}
while ( v2 != (const char *)(unsigned int)((_DWORD)&comp_types + 9) );
puts("Quantization Tables:");
v4 = a1 + 24;
for ( i = 0; i != 4; ++i )
{
if ( *v4 )
{
printf("\tID: %u\n", i);
for ( j = 8; j != 72; j += 8 )
{
printf("\t\t");
v7 = j - 8;
do
printf("0x%02x ", *(unsigned __int8 *)(*v4 + v7++));
while ( v7 != j );
putchar(10);
}
}
++v4;
}
puts("Huffman Tables:");
v8 = (__int64 *)(a1 + 56);
for ( k = 0; k != 8; ++k )
{
if ( *v8 )
{
printf("\tID: %u (%cC)\n", (k >> 1) & 3, (k & 1) == 0 ? 68 : 65);
v9 = 0;
for ( l = 0; l != 16; ++l )
{
if ( *(_BYTE *)(*v8 + l) )
{
printf("\t\t%u bits:", (unsigned int)(l + 1));
v11 = *v8;
if ( *(_BYTE *)(*v8 + l) )
{
v12 = 0;
do
{
printf(" 0x%02x", *(unsigned __int8 *)(v11 + v12 + v9 + 16));
++v12;
v11 = *v8;
}
while ( *(unsigned __int8 *)(*v8 + l) > v12 );
}
putchar(10);
v9 += *(unsigned __int8 *)(*v8 + l);
}
}
}
++v8;
}
return printf("Data length: %u\n", *((unsigned int *)a1 + 34));
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
const char *v2; // rbp
unsigned __int8 v3; // dl
_QWORD *v4; // r13
unsigned int i; // er14
int j; // ebp
int v7; // ebx
__int64 *v8; // r15
int v9; // er13
int l; // ebp
__int64 v11; // rdx
int v12; // ebx
int k; // [rsp+4h] [rbp-44h]

printf(
"Width: %u Height: %u Bits: %u\nRestart interval: %u\nComponents:\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
*a1,
*((unsigned __int16 *)a1 + 60));
v1 = a1 + 6;
v2 = (const char *)&comp_types;
do
{
if ( *v1 )
{
v3 = v1[1];
if ( v3 )
printf("\tType: %s Sampling: %u:%u QT: %u HT: %u/%u\n", v2, *v1, v3, v1[2], v1[4], v1[4]);
}
v1 += 5;
v2 += 3;
}
while ( v2 != (const char *)(unsigned int)((_DWORD)&comp_types + 9) );
puts("Quantization Tables:");
v4 = a1 + 24;
for ( i = 0; i != 4; ++i )
{
if ( *v4 )
{
printf("\tID: %u\n", i);
for ( j = 8; j != 72; j += 8 )
{
printf("\t\t");
v7 = j - 8;
do
printf("0x%02x ", *(unsigned __int8 *)(*v4 + v7++));
while ( v7 != j );
putchar(10);
}
}
++v4;
}
puts("Huffman Tables:");
v8 = (__int64 *)(a1 + 56);
for ( k = 0; k != 8; ++k )
{
if ( *v8 )
{
printf("\tID: %u (%cC)\n", (k >> 1) & 3, (k & 1) == 0 ? 68 : 65);
v9 = 0;
for ( l = 0; l != 16; ++l )
{
if ( *(_BYTE *)(*v8 + l) )
{
printf("\t\t%u bits:", (unsigned int)(l + 1));
v11 = *v8;
if ( *(_BYTE *)(*v8 + l) )
{
v12 = 0;
do
{
printf(" 0x%02x", *(unsigned __int8 *)(v11 + v12 + v9 + 16));
++v12;
v11 = *v8;
}
while ( *(unsigned __int8 *)(*v8 + l) > v12 );
}
putchar(10);
v9 += *(unsigned __int8 *)(*v8 + l);
}
}
}
++v8;
}
return printf("Data length: %u\n", *((unsigned int *)a1 + 34));
}

original_code:
void dump_jpeg(const struct jpeg_t *jpeg)
{
 int i, j, k;
 printf("Width: %u  Height: %u  Bits: %u\nRestart interval: %u\nComponents:\n", jpeg->width, jpeg->height, jpeg->bits, jpeg->restart_interval);
 for (i = 0; i < 3; i++)
 {
  if (jpeg->comp[i].samp_h && jpeg->comp[i].samp_v)
   printf("\tType: %s  Sampling: %u:%u  QT: %u  HT: %u/%u\n", comp_types[i], jpeg->comp[i].samp_h, jpeg->comp[i].samp_v, jpeg->comp[i].qt, jpeg->comp[i].ht_dc, jpeg->comp[i].ht_dc);
 }
 printf("Quantization Tables:\n");
 for (i = 0; i < 4; i++)
 {
  if (jpeg->quant[i])
  {
   printf("\tID: %u\n", i);
   for (j = 0; j < 64 / 8; j++)
   {
    printf("\t\t");
    for (k = 0; k < 8; k++)
    {
     printf("0x%02x ", jpeg->quant[i]->coeff[j * 8 + k]);
    }
    printf("\n");
   }
  }
 }
 printf("Huffman Tables:\n");
 for (i = 0; i < 8; i++)
 {
  if (jpeg->huffman[i])
  {
   printf("\tID: %u (%cC)\n", (i & 0x06) >> 1, i & 0x01 ? 'A' : 'D');
   int sum = 0;
   for (j = 0; j < 16; j++)
   {
    if (jpeg->huffman[i]->num[j])
    {
     printf("\t\t%u bits:", j + 1);
     for (k = 0; k < jpeg->huffman[i]->num[j]; k++)
     {
      printf(" 0x%02x", jpeg->huffman[i]->codes[sum + k]);
     }
     printf("\n");
     sum += jpeg->huffman[i]->num[j];
    }
   }
  }
 }
 printf("Data length: %u\n", jpeg->data_len);
}

canonical_original_code:
void dump_jpeg(struct jpeg_t *jpeg)
{
 int i; int j; int k;
 printf("Width: %u  Height: %u  Bits: %u\nRestart interval: %u\nComponents:\n", jpeg->width, jpeg->height, jpeg->bits, jpeg->restart_interval);
 for (i = 0; i < 3; i++)
 {
  if (jpeg->comp[i].samp_h && jpeg->comp[i].samp_v)
   printf("\tType: %s  Sampling: %u:%u  QT: %u  HT: %u/%u\n", comp_types[i], jpeg->comp[i].samp_h, jpeg->comp[i].samp_v, jpeg->comp[i].qt, jpeg->comp[i].ht_dc, jpeg->comp[i].ht_dc);
 }
 printf("Quantization Tables:\n");
 for (i = 0; i < 4; i++)
 {
  if (jpeg->quant[i])
  {
   printf("\tID: %u\n", i);
   for (j = 0; j < 64 / 8; j++)
   {
    printf("\t\t");
    for (k = 0; k < 8; k++)
    {
     printf("0x%02x ", jpeg->quant[i]->coeff[j * 8 + k]);
    }
    printf("\n");
   }
  }
 }
 printf("Huffman Tables:\n");
 for (i = 0; i < 8; i++)
 {
  if (jpeg->huffman[i])
  {
   printf("\tID: %u (%cC)\n", (i & 0x06) >> 1, i & 0x01 ? 'A' : 'D');
   int sum = 0;
   for (j = 0; j < 16; j++)
   {
    if (jpeg->huffman[i]->num[j])
    {
     printf("\t\t%u bits:", j + 1);
     for (k = 0; k < jpeg->huffman[i]->num[j]; k++)
     {
      printf(" 0x%02x", jpeg->huffman[i]->codes[sum + k]);
     }
     printf("\n");
     sum += jpeg->huffman[i]->num[j];
    }
   }
  }
 }
 printf("Data length: %u\n", jpeg->data_len);
}

variable_types: j int

variable_types: k int

variable_types: sum int


original_code:
static int parse_sequence_header(struct mpeg_t * const mpeg)
{
 const uint8_t * const data = mpeg->data + mpeg->pos;
 if ((mpeg->pos += 8) > mpeg->len)
  return 0;
 mpeg->width = (data[0] << 4) | (data[1] >> 4);
 mpeg->height = ((data[1] & 0x0f) << 8) | data[2];
 return 1;
}

canonical_original_code:
static int parse_sequence_header(struct mpeg_t *mpeg)
{
 unsigned char *data = mpeg->data + mpeg->pos;
 if ((mpeg->pos += 8) > mpeg->len)
  return 0;
 mpeg->width = (data[0] << 4) | (data[1] >> 4);
 mpeg->height = ((data[1] & 0x0f) << 8) | data[2];
 return 1;
}

variable_types: struct mpeg_t { unsigned char *data; int len; int pos; unsigned int gop; enum { MPEG1=0, MPEG2=1 } type; unsigned short width; unsigned short height; unsigned short temporal_reference; enum { PCT_I=1, PCT_P=2, PCT_B=3, PCT_D=4 } picture_coding_type; unsigned char full_pel_forward_vector; unsigned char full_pel_backward_vector; unsigned char f_code[2][2]; unsigned char intra_dc_precision; unsigned char picture_structure; unsigned char top_field_first; unsigned char frame_pred_frame_dct; unsigned char concealment_motion_vectors; unsigned char q_scale_type; unsigned char intra_vlc_format; unsigned char alternate_scan; } *


original_code:
static int parse_gop(struct mpeg_t * const mpeg)
{
 if ((mpeg->pos += 4) > mpeg->len)
  return 0;
 mpeg->gop++;
 return 1;
}

canonical_original_code:
static int parse_gop(struct mpeg_t *mpeg)
{
 if ((mpeg->pos += 4) > mpeg->len)
  return 0;
 mpeg->gop++;
 return 1;
}

user_defined_types: struct mpeg_t { unsigned char *data; int len; int pos; unsigned int gop; enum { MPEG1=0, MPEG2=1 } type; unsigned short width; unsigned short height; unsigned short temporal_reference; enum { PCT_I=1, PCT_P=2, PCT_B=3, PCT_D=4 } picture_coding_type; unsigned char full_pel_forward_vector; unsigned char full_pel_backward_vector; unsigned char f_code[2][2]; unsigned char intra_dc_precision; unsigned char picture_structure; unsigned char top_field_first; unsigned char frame_pred_frame_dct; unsigned char concealment_motion_vectors; unsigned char q_scale_type; unsigned char intra_vlc_format; unsigned char alternate_scan; }


original_code:
static int parse_picture(struct mpeg_t * const mpeg)
{
 const uint8_t * const data = mpeg->data + mpeg->pos;
 if ((mpeg->pos += 4) > mpeg->len)
  return 0;
 mpeg->temporal_reference = (data[0] << 2) | (data[1] >> 6);
 mpeg->picture_coding_type = ((data[1] & 0x38) >> 3);
 if (mpeg->picture_coding_type == 2 || mpeg->picture_coding_type == 3)
 {
  if (mpeg->pos++ > mpeg->len)
   return 0;
  mpeg->full_pel_forward_vector = ((data[3] & 0x04) >> 2);
  mpeg->f_code[0][0] = mpeg->f_code[0][1] = ((data[3] & 0x03) << 1) | ((data[4] & 0x80) >> 7);
  if (mpeg->picture_coding_type == 3)
  {
   mpeg->full_pel_backward_vector = ((data[4] & 0x40) >> 6);
   mpeg->f_code[1][0] = mpeg->f_code[1][1] = ((data[4] & 0x38) >> 3);
  }
 }
 else
 {
  mpeg->full_pel_forward_vector = mpeg->full_pel_backward_vector = 0;
  mpeg->f_code[0][0] = mpeg->f_code[0][1] = 0;
  mpeg->f_code[1][0] = mpeg->f_code[1][1] = 0;
 }
 mpeg->picture_structure = 0x3;
 mpeg->top_field_first = 0x1;
 mpeg->frame_pred_frame_dct = 0x1;
 return 1;
}

canonical_original_code:
static int parse_picture(struct mpeg_t *mpeg)
{
 unsigned char *data = mpeg->data + mpeg->pos;
 if ((mpeg->pos += 4) > mpeg->len)
  return 0;
 mpeg->temporal_reference = (data[0] << 2) | (data[1] >> 6);
 mpeg->picture_coding_type = ((data[1] & 0x38) >> 3);
 if (mpeg->picture_coding_type == 2 || mpeg->picture_coding_type == 3)
 {
  if (mpeg->pos++ > mpeg->len)
   return 0;
  mpeg->full_pel_forward_vector = ((data[3] & 0x04) >> 2);
  mpeg->f_code[0][0] = mpeg->f_code[0][1] = ((data[3] & 0x03) << 1) | ((data[4] & 0x80) >> 7);
  if (mpeg->picture_coding_type == 3)
  {
   mpeg->full_pel_backward_vector = ((data[4] & 0x40) >> 6);
   mpeg->f_code[1][0] = mpeg->f_code[1][1] = ((data[4] & 0x38) >> 3);
  }
 }
 else
 {
  mpeg->full_pel_forward_vector = mpeg->full_pel_backward_vector = 0;
  mpeg->f_code[0][0] = mpeg->f_code[0][1] = 0;
  mpeg->f_code[1][0] = mpeg->f_code[1][1] = 0;
 }
 mpeg->picture_structure = 0x3;
 mpeg->top_field_first = 0x1;
 mpeg->frame_pred_frame_dct = 0x1;
 return 1;
}


original_code:
static int parse_extension(struct mpeg_t * const mpeg)
{
 const uint8_t * const data = mpeg->data + mpeg->pos;
 if (mpeg->pos > mpeg->len)
  return 0;
 switch (data[0] >> 4)
 {
 case 0x1:
  if ((mpeg->pos += 6)> mpeg->len)
   return 0;
  mpeg->width |= ((data[1] & 0x01) << 13) | ((data[2] & 0x80) << 5);
  mpeg->height |= ((data[2] & 0x60) << 7);
  return 1;
 case 0x2:
  return 1;
 case 0x8:
  if ((mpeg->pos += 5)> mpeg->len)
   return 0;
  mpeg->f_code[0][0] = (data[0] & 0x0f);
  mpeg->f_code[0][1] = ((data[1] & 0xf0) >> 4);
  mpeg->f_code[1][0] = (data[1] & 0x0f);
  mpeg->f_code[1][1] = ((data[2] & 0xf0) >> 4);
  mpeg->intra_dc_precision = ((data[2] & 0x0c) >> 2);
  mpeg->picture_structure = (data[2] & 0x03);
  mpeg->top_field_first = ((data[3] & 0x80) >> 7);
  mpeg->frame_pred_frame_dct = ((data[3] & 0x40) >> 6);
  mpeg->concealment_motion_vectors = ((data[3] & 0x20) >> 5);
  mpeg->q_scale_type = ((data[3] & 0x10) >> 4);
  mpeg->intra_vlc_format = ((data[3] & 0x08) >> 3);
  mpeg->alternate_scan = ((data[3] & 0x04) >> 2);
  return 1;
 default:
  fprintf(stderr, "unhandled extension: %01x\n", data[0] >> 4);
  break;
 }
 return 0;
}

canonical_original_code:
static int parse_extension(struct mpeg_t *mpeg)
{
 unsigned char *data = mpeg->data + mpeg->pos;
 if (mpeg->pos > mpeg->len)
  return 0;
 switch (data[0] >> 4)
 {
 case 0x1:
  if ((mpeg->pos += 6)> mpeg->len)
   return 0;
  mpeg->width |= ((data[1] & 0x01) << 13) | ((data[2] & 0x80) << 5);
  mpeg->height |= ((data[2] & 0x60) << 7);
  return 1;
 case 0x2:
  return 1;
 case 0x8:
  if ((mpeg->pos += 5)> mpeg->len)
   return 0;
  mpeg->f_code[0][0] = (data[0] & 0x0f);
  mpeg->f_code[0][1] = ((data[1] & 0xf0) >> 4);
  mpeg->f_code[1][0] = (data[1] & 0x0f);
  mpeg->f_code[1][1] = ((data[2] & 0xf0) >> 4);
  mpeg->intra_dc_precision = ((data[2] & 0x0c) >> 2);
  mpeg->picture_structure = (data[2] & 0x03);
  mpeg->top_field_first = ((data[3] & 0x80) >> 7);
  mpeg->frame_pred_frame_dct = ((data[3] & 0x40) >> 6);
  mpeg->concealment_motion_vectors = ((data[3] & 0x20) >> 5);
  mpeg->q_scale_type = ((data[3] & 0x10) >> 4);
  mpeg->intra_vlc_format = ((data[3] & 0x08) >> 3);
  mpeg->alternate_scan = ((data[3] & 0x04) >> 2);
  return 1;
 default:
  fprintf(stderr, "unhandled extension: %01x\n", data[0] >> 4);
  break;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall parse_mpeg(__int64 *a1)
{
int v2; // edi
__int64 v3; // rax
__int64 v4; // r8
int v5; // esi
__int64 result; // rax
char v7; // cl
__int64 v8; // rdx
int v9; // eax
unsigned __int8 v10; // al

v2 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) >= v2 )
return 0LL;
while ( 2 )
{
LODWORD(v3) = *((_DWORD *)a1 + 3);
if ( (int)v3 >= v2 )
goto LABEL_12;
v4 = *a1;
v3 = (int)v3;
v5 = 0;
while ( 1 )
{
v7 = *(_BYTE *)(v4 + v3);
if ( !v7 )
{
++v5;
goto LABEL_8;
}
if ( v5 > 1 && v7 == 1 )
break;
v5 = 0;
LABEL_8:
*((_DWORD *)a1 + 3) = ++v3;
if ( v2 <= (int)v3 )
goto LABEL_12;
}
*((_DWORD *)a1 + 3) = v3 + 1;
LABEL_12:
v8 = *a1;
v9 = *((_DWORD *)a1 + 3);
*((_DWORD *)a1 + 3) = v9 + 1;
v10 = *(_BYTE *)(v8 + v9);
if ( v10 == 0xB5 )
{
result = parse_extension((__int64)a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else if ( v10 > 0xB5u )
{
if ( v10 != 0xB8 )
{
LABEL_28:
fprintf(stderr, "unhandled startcode: %02x\n", v10);
LABEL_17:
v2 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) >= v2 )
return 0LL;
continue;
}
result = parse_gop(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else if ( v10 )
{
if ( v10 == 0xB3 )
{
result = parse_sequence_header(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else
{
if ( (unsigned __int8)(v10 - 1) > 0xAEu )
goto LABEL_28;
result = 1LL;
}
}
else
{
result = parse_picture(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
int v2; // edi
__int64 v3; // rax
__int64 v4; // r8
int v5; // esi
__int64 result; // rax
char v7; // cl
__int64 v8; // rdx
int v9; // eax
unsigned __int8 v10; // al

v2 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) >= v2 )
return 0LL;
while ( 2 )
{
LODWORD(v3) = *((_DWORD *)a1 + 3);
if ( (int)v3 >= v2 )
goto LABEL_12;
v4 = *a1;
v3 = (int)v3;
v5 = 0;
while ( 1 )
{
v7 = *(_BYTE *)(v4 + v3);
if ( !v7 )
{
++v5;
goto LABEL_8;
}
if ( v5 > 1 && v7 == 1 )
break;
v5 = 0;
LABEL_8:
*((_DWORD *)a1 + 3) = ++v3;
if ( v2 <= (int)v3 )
goto LABEL_12;
}
*((_DWORD *)a1 + 3) = v3 + 1;
LABEL_12:
v8 = *a1;
v9 = *((_DWORD *)a1 + 3);
*((_DWORD *)a1 + 3) = v9 + 1;
v10 = *(_BYTE *)(v8 + v9);
if ( v10 == 0xB5 )
{
result = func3((__int64)a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else if ( v10 > 0xB5u )
{
if ( v10 != 0xB8 )
{
LABEL_28:
fprintf(stderr, "unhandled startcode: %02x\n", v10);
LABEL_17:
v2 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) >= v2 )
return 0LL;
continue;
}
result = func1(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else if ( v10 )
{
if ( v10 == 0xB3 )
{
result = func0(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
else
{
if ( (unsigned __int8)(v10 - 1) > 0xAEu )
goto LABEL_28;
result = 1LL;
}
}
else
{
result = func2(a1);
if ( (_DWORD)result )
goto LABEL_17;
}
return result;
}
}

original_code:
int parse_mpeg(struct mpeg_t * const mpeg)
{
 while (mpeg->pos < mpeg->len)
 {
  int zeros = 0;
  for ( ; mpeg->pos < mpeg->len; mpeg->pos++)
  {
   if (mpeg->data[mpeg->pos] == 0x00)
    zeros++;
   else if (mpeg->data[mpeg->pos] == 0x01 && zeros >= 2)
   {
    mpeg->pos++;
    break;
   }
   else
    zeros = 0;
  }
  uint8_t marker = mpeg->data[mpeg->pos++];
  switch (marker)
  {
  case 0x00:
   if (!parse_picture(mpeg))
    return 0;
   break;
  case 0xb3:
   if (!parse_sequence_header(mpeg))
    return 0;
   break;
  case 0xb5:
   if (!parse_extension(mpeg))
    return 0;
   break;
  case 0xb8:
   if (!parse_gop(mpeg))
    return 0;
   break;
  default:
   if (marker >= 0x01 && marker <= 0xaf)
    return 1;
   fprintf(stderr, "unhandled startcode: %02x\n", marker);
   break;
  }
 }
 return 0;
}

canonical_original_code:
int parse_mpeg(struct mpeg_t *mpeg)
{
 while (mpeg->pos < mpeg->len)
 {
  int zeros = 0;
  for ( ; mpeg->pos < mpeg->len; mpeg->pos++)
  {
   if (mpeg->data[mpeg->pos] == 0x00)
    zeros++;
   else if (mpeg->data[mpeg->pos] == 0x01 && zeros >= 2)
   {
    mpeg->pos++;
    break;
   }
   else
    zeros = 0;
  }
  unsigned char marker = mpeg->data[mpeg->pos++];
  switch (marker)
  {
  case 0x00:
   if (!parse_picture(mpeg))
    return 0;
   break;
  case 0xb3:
   if (!parse_sequence_header(mpeg))
    return 0;
   break;
  case 0xb5:
   if (!parse_extension(mpeg))
    return 0;
   break;
  case 0xb8:
   if (!parse_gop(mpeg))
    return 0;
   break;
  default:
   if (marker >= 0x01 && marker <= 0xaf)
    return 1;
   fprintf(stderr, "unhandled startcode: %02x\n", marker);
   break;
  }
 }
 return 0;
}

variable_types: zeros int


decompiled_code:
__int64 __fastcall read_frame(int fd, __int64 a2, int a3)
{
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // edx

if ( a3 <= 0 )
return 1LL;
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
v6 = v5;
if ( !v5 )
break;
v4 += v5;
if ( a3 <= v4 )
return 1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, int a3)
{
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // edx

if ( a3 <= 0 )
return 1LL;
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
v6 = v5;
if ( !v5 )
break;
v4 += v5;
if ( a3 <= v4 )
return 1;
}
return v6;
}

original_code:
static int read_frame(int fd, void *buffer, int size)
{
 int total = 0, len;
 while (total < size)
 {
  len = read(fd, buffer + total, size - total);
  if (len == 0)
   return 0;
  total += len;
 }
 return 1;
}

canonical_original_code:
static int read_frame(int fd, void *buffer, int size)
{
 int total = 0; int len;
 while (total < size)
 {
  len = read(fd, buffer + total, size - total);
  if (len == 0)
   return 0;
  total += len;
 }
 return 1;
}

variable_types: fd int

variable_types:
buffer
void *

variable_types: size int

variable_types: total int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // er12
int v5; // er13
const char *v6; // r14
int v7; // ebp
int v8; // er14
__int64 v9; // rax
__int64 v10; // rbx
const void *v11; // r15
int v12; // er12
__int64 v13; // r13
unsigned int v14; // eax
int v15[2]; // [rsp+0h] [rbp-68h] BYREF
unsigned int v16; // [rsp+8h] [rbp-60h]
unsigned int v17; // [rsp+Ch] [rbp-5Ch]
int v18; // [rsp+10h] [rbp-58h]
int v19; // [rsp+14h] [rbp-54h]
int v20; // [rsp+18h] [rbp-50h]
int v21; // [rsp+1Ch] [rbp-4Ch]
int v22; // [rsp+20h] [rbp-48h]
int v23; // [rsp+24h] [rbp-44h]

if ( argc == 5 )
{
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( (unsigned int)ve_open() )
{
v6 = argv[1];
v7 = strcmp(v6, "-");
if ( v7 && (v7 = open(v6, 0), v7 == -1) )
{
puts("could not open input file");
result = 1;
}
else
{
v8 = open(argv[4], 578, 420LL);
if ( v8 == -1 )
{
puts("could not open output file");
result = 1;
}
else
{
v16 = (v4 + 15) & 0xFFFFFFF0;
v15[0] = v4;
v17 = (v5 + 15) & 0xFFFFFFF0;
v15[1] = v5;
v18 = 0;
v19 = 77;
v20 = 41;
v21 = 1;
v22 = 24;
v23 = 25;
v9 = h264enc_new(v15);
v10 = v9;
if ( v9 )
{
v11 = (const void *)h264enc_get_bytestream_buffer(v9);
v12 = v16 * (v17 + (v17 >> 1));
v13 = h264enc_get_input_buffer(v10);
while ( (unsigned int)read_frame(v7, v13, v12) )
{
if ( (unsigned int)h264enc_encode_picture(v10) )
{
v14 = h264enc_get_bytestream_length(v10);
write(v8, v11, v14);
}
else
{
puts("encoding error");
}
}
h264enc_free(v10);
}
else
{
puts("could not create encoder");
}
ve_close();
close(v8);
close(v7);
result = 0;
}
}
}
else
{
result = 1;
}
}
else
{
printf("Usage: %s <infile> <width> <height> <outfile>\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // er12
int v5; // er13
const char *v6; // r14
int v7; // ebp
int v8; // er14
__int64 v9; // rax
__int64 v10; // rbx
const void *v11; // r15
int v12; // er12
__int64 v13; // r13
unsigned int v14; // eax
int v15[2]; // [rsp+0h] [rbp-68h] BYREF
unsigned int v16; // [rsp+8h] [rbp-60h]
unsigned int v17; // [rsp+Ch] [rbp-5Ch]
int v18; // [rsp+10h] [rbp-58h]
int v19; // [rsp+14h] [rbp-54h]
int v20; // [rsp+18h] [rbp-50h]
int v21; // [rsp+1Ch] [rbp-4Ch]
int v22; // [rsp+20h] [rbp-48h]
int v23; // [rsp+24h] [rbp-44h]

if ( argc == 5 )
{
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( (unsigned int)ve_open() )
{
v6 = argv[1];
v7 = strcmp(v6, "-");
if ( v7 && (v7 = open(v6, 0), v7 == -1) )
{
puts("could not open input file");
result = 1;
}
else
{
v8 = open(argv[4], 578, 420LL);
if ( v8 == -1 )
{
puts("could not open output file");
result = 1;
}
else
{
v16 = (v4 + 15) & 0xFFFFFFF0;
v15[0] = v4;
v17 = (v5 + 15) & 0xFFFFFFF0;
v15[1] = v5;
v18 = 0;
v19 = 77;
v20 = 41;
v21 = 1;
v22 = 24;
v23 = 25;
v9 = h264enc_new(v15);
v10 = v9;
if ( v9 )
{
v11 = (const void *)h264enc_get_bytestream_buffer(v9);
v12 = v16 * (v17 + (v17 >> 1));
v13 = h264enc_get_input_buffer(v10);
while ( (unsigned int)func0(v7, v13, v12) )
{
if ( (unsigned int)h264enc_encode_picture(v10) )
{
v14 = h264enc_get_bytestream_length(v10);
write(v8, v11, v14);
}
else
{
puts("encoding error");
}
}
h264enc_free(v10);
}
else
{
puts("could not create encoder");
}
ve_close();
close(v8);
close(v7);
result = 0;
}
}
}
else
{
result = 1;
}
}
else
{
printf("Usage: %s <infile> <width> <height> <outfile>\n", *argv);
result = 1;
}
return result;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: in int

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

variable_types:
data
unsigned char *

variable_types:
filename
char *

variable_types: struct jpeg_t { unsigned char bits; unsigned short width; unsigned short height; struct comp_t { unsigned char samp_h; unsigned char samp_v; unsigned char qt; unsigned char ht_ac; unsigned char ht_dc; } comp[3]; struct quant_t { unsigned char coeff[64]; } *quant[4]; struct huffman_t { unsigned char num[16]; unsigned char codes[256]; } *huffman[8]; unsigned short restart_interval; unsigned char *data; unsigned int data_len; }


repo: jemofthewest/ad

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v5[5]; // [rsp+0h] [rbp-28h] BYREF

v5[0] = 0x3FDD3E4EF0281BA8LL;
v5[1] = 0x3FD937B4A2339C0FLL;
v5[2] = 0xBFE66299524BFD2FLL;
v5[3] = 0x3FED8BFC2224EDF6LL;
*(_QWORD *)&v3 = rosenbrock((double *)v5, 4);
printf("f is %f\n", v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  double x[] = { 0.456928, 0.394025, -0.699536, 0.923338 };
  int n = sizeof(x) / sizeof(x[0]);
  double f;
  f = rosenbrock(x,n);
  printf("f is %f\n", f);
  return 0;
}

variable_types:
x
double []

variable_types: n int

variable_types: f double


repo: jeremie-koenig/hurd

decompiled_code:
void flush_problems()
{
if ( problems )
{
*(_QWORD *)(fail_0((const char **)problems) + 8) = free_problems;
free_problems = (char **)problems;
}
}

canonical_decompiled_code:
void func1()
{
if ( problems )
{
*(_QWORD *)(func0((const char **)problems) + 8) = free_problems;
free_problems = (char **)problems;
}
}

original_code:
static void
flush_problems ()
{
  struct problem *fail (struct problem *prob)
    {
      struct problem *last = prob->prev ? fail (prob->prev) : prob;
      if (preen && device_name)
 printf ("%s: %s\n", device_name, prob->desc);
      else
 puts (prob->desc);
      free (prob->desc);
      return last;
    }
  if (problems)
    {
      fail (problems)->prev = free_problems;
      free_problems = problems;
    }
}

canonical_original_code:
static void flush_problems()
{
  struct problem *fail (struct problem *prob)
    {
      struct problem *last = prob->prev ? fail (prob->prev) : prob;
      if (preen && device_name)
 printf ("%s: %s\n", device_name, prob->desc);
      else
 puts (prob->desc);
      free (prob->desc);
      return last;
    }
  if (problems)
    {
      fail (problems)->prev = free_problems;
      free_problems = problems;
    }
}

variable_types: struct problem { char *desc; struct problem *prev; } *


retch

decompiled_code:
__int64 __fastcall retch(const char *a1)
{
flush_problems();
error(99, 0, "(internal error) %s!", a1);
return resolve_problem();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
func1();
error(99, 0, "(internal error) %s!", a1);
return func3();
}

original_code:
static void
retch (char *reason)
{
  flush_problems ();
  error (99, 0, "(internal error) %s!", reason);
}

canonical_original_code:
static void retch(char *reason)
{
  flush_problems ();
  error (99, 0, "(internal error) %s!", reason);
}

variable_types:
reason
char *


decompiled_code:
void __fastcall resolve_problem(const char *a1)
{
void **v2; // rbx

v2 = (void **)problems;
if ( problems )
{
problems = *(_QWORD *)(problems + 8);
v2[1] = free_problems;
if ( preen && device_name )
{
printf("%s: %s", device_name, (const char *)*v2);
goto LABEL_7;
}
}
else
{
retch("no more problems");
}
printf("%s", (const char *)*v2);
LABEL_7:
if ( a1 )
printf(" (%s)\n", a1);
else
putchar(10);
free(*v2);
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
void **v2; // rbx

v2 = (void **)problems;
if ( problems )
{
problems = *(_QWORD *)(problems + 8);
v2[1] = free_problems;
if ( preen && device_name )
{
printf("%s: %s", device_name, (const char *)*v2);
goto LABEL_7;
}
}
else
{
func2("no more problems");
}
printf("%s", (const char *)*v2);
LABEL_7:
if ( a1 )
printf(" (%s)\n", a1);
else
putchar(10);
free(*v2);
}

original_code:
static void
resolve_problem (char *fix)
{
  struct problem *prob = problems;
  if (! prob)
    retch ("no more problems");
  problems = prob->prev;
  prob->prev = free_problems;
  if (preen && device_name)
    printf ("%s: %s", device_name, prob->desc);
  else
    printf ("%s", prob->desc);
  if (fix)
    printf (" (%s)\n", fix);
  else
    putchar ('\n');
  free (prob->desc);
}

canonical_original_code:
static void resolve_problem(char *fix)
{
  struct problem *prob = problems;
  if (! prob)
    retch ("no more problems");
  problems = prob->prev;
  prob->prev = free_problems;
  if (preen && device_name)
    printf ("%s: %s", device_name, prob->desc);
  else
    printf ("%s", prob->desc);
  if (fix)
    printf (" (%s)\n", fix);
  else
    putchar ('\n');
  free (prob->desc);
}

variable_types:
fix
char *

user_defined_types: struct problem { char *desc; struct problem *prev; }


decompiled_code:
__int64 __fastcall push_problem(char *f, __gnuc_va_list arg)
{
char **v2; // rbx
__int64 result; // rax

v2 = free_problems;
if ( free_problems )
{
problems = (__int64)free_problems[1];
}
else
{
v2 = (char **)malloc(0x10uLL);
if ( !v2 )
{
retch("malloc failed");
goto LABEL_7;
}
}
if ( vasprintf(v2, f, arg) >= 0 )
{
result = problems;
v2[1] = (char *)problems;
problems = (__int64)v2;
return result;
}
LABEL_7:
retch("vasprintf failed");
return allocblk();
}

canonical_decompiled_code:
__int64 __fastcall func4(char *f, __gnuc_va_list arg)
{
char **v2; // rbx
__int64 result; // rax

v2 = free_problems;
if ( free_problems )
{
problems = (__int64)free_problems[1];
}
else
{
v2 = (char **)malloc(0x10uLL);
if ( !v2 )
{
func2("malloc failed");
goto LABEL_7;
}
}
if ( vasprintf(v2, f, arg) >= 0 )
{
result = problems;
v2[1] = (char *)problems;
problems = (__int64)v2;
return result;
}
LABEL_7:
func2("vasprintf failed");
return func5();
}

original_code:
static void
push_problem (char *fmt, va_list args)
{
  struct problem *prob = free_problems;
  if (! prob)
    prob = malloc (sizeof (struct problem));
  else
    problems = prob->prev;
  if (! prob)
    retch ("malloc failed");
  if (vasprintf (&prob->desc, fmt, args) < 0)
    retch ("vasprintf failed");
  prob->prev = problems;
  problems = prob;
}

canonical_original_code:
static void push_problem(char *fmt, __builtin_va_list args)
{
  struct problem *prob = free_problems;
  if (! prob)
    prob = malloc (sizeof (struct problem));
  else
    problems = prob->prev;
  if (! prob)
    retch ("malloc failed");
  if (vasprintf (&prob->desc, fmt, args) < 0)
    retch ("vasprintf failed");
  prob->prev = problems;
  problems = prob;
}

variable_types:
fmt
char *


allocblk

original_code:
daddr_t
allocblk (int nfrags)
{
  daddr_t i;
  int j, k;
  if (nfrags <= 0 || nfrags > sblock->fs_frag)
    return 0;
  for (i = 0; i < maxfsblock - sblock->fs_frag; i += sblock->fs_frag)
    {
      for (j = 0; j <= sblock->fs_frag - nfrags; j++)
 {
   for (k = 0; k < nfrags; k++)
     if (((blockmap)[(i + j + k)/8] & (1<<((i + j + k)%8))))
       break;
   if (k < nfrags)
     {
       j += k;
       continue;
     }
   for (k = 0; k < nfrags; k++)
     ((blockmap)[(i + j + k)/8] |= 1<<((i + j + k)%8));
   return (i + j);
 }
    }
  return 0;
}

canonical_original_code:
int allocblk(int nfrags)
{
  int i;
  int j; int k;
  if (nfrags <= 0 || nfrags > sblock->fs_frag)
    return 0;
  for (i = 0; i < maxfsblock - sblock->fs_frag; i += sblock->fs_frag)
    {
      for (j = 0; j <= sblock->fs_frag - nfrags; j++)
 {
   for (k = 0; k < nfrags; k++)
     if (((blockmap)[(i + j + k)/8] & (1<<((i + j + k)%8))))
       break;
   if (k < nfrags)
     {
       j += k;
       continue;
     }
   for (k = 0; k < nfrags; k++)
     ((blockmap)[(i + j + k)/8] |= 1<<((i + j + k)%8));
   return (i + j);
 }
    }
  return 0;
}

variable_types: nfrags int

variable_types: i int

variable_types: j int

variable_types: k int


decompiled_code:
_BOOL8 __fastcall check_range(int a1, int a2)
{
int v2; // esi
_BOOL8 result; // rax
__int64 v4; // r8
__int64 v5; // rax
__int64 v6; // rdx

v2 = a1 + a2;
result = 1LL;
if ( (unsigned int)v2 <= maxfsblock )
{
v4 = *(_QWORD *)(sblock + 360LL);
v5 = a1 / v4;
v6 = (int)v5 * (int)v4 + *(_QWORD *)(sblock + 32LL) * ((int)v5 & ~*(_QWORD *)(sblock + 40LL));
if ( a1 >= v6 + *(int *)(sblock + 28LL) )
result = v2 > (int)v4 * ((int)v5 + 1);
else
result = v2 > *(int *)(sblock + 16LL) + v6;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1, int a2)
{
int v2; // esi
_BOOL8 result; // rax
__int64 v4; // r8
__int64 v5; // rax
__int64 v6; // rdx

v2 = a1 + a2;
result = 1LL;
if ( (unsigned int)v2 <= maxfsblock )
{
v4 = *(_QWORD *)(sblock + 360LL);
v5 = a1 / v4;
v6 = (int)v5 * (int)v4 + *(_QWORD *)(sblock + 32LL) * ((int)v5 & ~*(_QWORD *)(sblock + 40LL));
if ( a1 >= v6 + *(int *)(sblock + 28LL) )
result = v2 > (int)v4 * ((int)v5 + 1);
else
result = v2 > *(int *)(sblock + 16LL) + v6;
}
return result;
}

original_code:
int
check_range (daddr_t blk, int cnt)
{
  int c;
  if ((unsigned)(blk + cnt) > maxfsblock)
    return 1;
  c = ((blk) / (sblock)->fs_fpg);
  if (blk < ((((daddr_t)((sblock)->fs_fpg * (c))) + (sblock)->fs_cgoffset * ((c) & ~((sblock)->fs_cgmask))) + (sblock)->fs_dblkno))
    {
      if (blk + cnt > ((((daddr_t)((sblock)->fs_fpg * (c))) + (sblock)->fs_cgoffset * ((c) & ~((sblock)->fs_cgmask))) + (sblock)->fs_sblkno))
 return 1;
    }
  else
    {
      if (blk + cnt > ((daddr_t)((sblock)->fs_fpg * (c + 1))))
 return 1;
    }
  return 0;
}

canonical_original_code:
int check_range(int blk, int cnt)
{
  int c;
  if ((unsigned int)(blk + cnt) > maxfsblock)
    return 1;
  c = ((blk) / (sblock)->fs_fpg);
  if (blk < ((((daddr_t)((sblock)->fs_fpg * (c))) + (sblock)->fs_cgoffset * ((c) & ~((sblock)->fs_cgmask))) + (sblock)->fs_dblkno))
    {
      if (blk + cnt > ((((daddr_t)((sblock)->fs_fpg * (c))) + (sblock)->fs_cgoffset * ((c) & ~((sblock)->fs_cgmask))) + (sblock)->fs_sblkno))
 return 1;
    }
  else
    {
      if (blk + cnt > ((daddr_t)((sblock)->fs_fpg * (c + 1))))
 return 1;
    }
  return 0;
}

variable_types: blk int

variable_types: cnt int

variable_types: c int


errexit

decompiled_code:
void __noreturn errexit(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

flush_problems();
if ( preen )
{
if ( device_name )
printf("%s: ", device_name);
}
va_start(arg, format);
vprintf(format, arg);
putchar(10);
exit(8);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

func1();
if ( preen )
{
if ( device_name )
printf("%s: ", device_name);
}
va_start(arg, format);
vprintf(format, arg);
putchar(10);
exit(8);
}

original_code:
void
errexit (char *fmt, ...)
{
  va_list args;
  flush_problems ();
  if (preen && device_name)
    printf ("%s: ", device_name);
  __builtin_va_start(args,fmt);
  vprintf (fmt, args);
  __builtin_va_end(args);
  putchar ('\n');
  exit (8);
}

canonical_original_code:
void errexit(char *fmt, ...)
{
  __builtin_va_list args;
  flush_problems ();
  if (preen && device_name)
    printf ("%s: ", device_name);
  __builtin_va_start(args,fmt);
  vprintf (fmt, args);
  __builtin_va_end(args);
  putchar ('\n');
  exit (8);
}


readblock

decompiled_code:
ssize_t __fastcall readblock(unsigned int a1, void *buf, size_t nbytes)
{
ssize_t result; // rax

if ( lseek64(readfd, (int)(a1 << 9), 0) == -1 )
errexit("CANNOT SEEK TO BLOCK %ld", a1);
result = read(readfd, buf, nbytes);
if ( result != nbytes )
errexit("CANNOT READ BLOCK %ld", a1);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(unsigned int a1, void *buf, size_t nbytes)
{
ssize_t result; // rax

if ( lseek64(readfd, (int)(a1 << 9), 0) == -1 )
func7("CANNOT SEEK TO BLOCK %ld", a1);
result = read(readfd, buf, nbytes);
if ( result != nbytes )
func7("CANNOT READ BLOCK %ld", a1);
return result;
}

original_code:
void
readblock (daddr_t addr, void *buf, size_t size)
{
  if (lseek (readfd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (read (readfd, buf, size) != size)
    errexit ("CANNOT READ BLOCK %ld", addr);
}

canonical_original_code:
void readblock(int addr, void *buf, unsigned long size)
{
  if (lseek (readfd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (read (readfd, buf, size) != size)
    errexit ("CANNOT READ BLOCK %ld", addr);
}

variable_types: addr int

variable_types:
buf
void *

variable_types:
size
unsigned long


getinode

decompiled_code:
void *__fastcall getinode(unsigned __int64 a1, void *a2)
{
int v2; // ebx

if ( !lastifrag )
lastifrag = malloc(*(_QWORD *)(sblock + 80LL));
v2 = *(_DWORD *)(sblock + 32LL) * ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL))
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / *(_QWORD *)(sblock + 224LL)) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v2 )
readblock(v2 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
lastifragaddr = v2;
return memmove(a2, (char *)lastifrag + 192 * (a1 % *(_QWORD *)(sblock + 224LL)), 0xC0uLL);
}

canonical_decompiled_code:
void *__fastcall func9(unsigned __int64 a1, void *a2)
{
int v2; // ebx

if ( !lastifrag )
lastifrag = malloc(*(_QWORD *)(sblock + 80LL));
v2 = *(_DWORD *)(sblock + 32LL) * ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL))
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / *(_QWORD *)(sblock + 224LL)) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v2 )
func8(v2 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
lastifragaddr = v2;
return memmove(a2, (char *)lastifrag + 192 * (a1 % *(_QWORD *)(sblock + 224LL)), 0xC0uLL);
}

original_code:
void
getinode (ino_t ino, struct dinode *di)
{
  daddr_t iblk;
  if (!lastifrag)
    lastifrag = malloc (sblock->fs_bsize);
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  di, sizeof (struct dinode));
}

canonical_original_code:
void getinode(unsigned long ino, struct dinode *di)
{
  int iblk;
  if (!lastifrag)
    lastifrag = malloc (sblock->fs_bsize);
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  di, sizeof (struct dinode));
}

variable_types:
ino
unsigned long

variable_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec { long tv_sec; long tv_nsec; } di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; } *

variable_types: iblk int

user_defined_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; }


writeblock

decompiled_code:
ssize_t __fastcall writeblock(unsigned int a1, void *buf, size_t n)
{
ssize_t result; // rax

if ( lseek64(writefd, (int)(a1 << 9), 0) == -1 )
errexit("CANNOT SEEK TO BLOCK %ld", a1);
result = write(writefd, buf, n);
if ( result != n )
errexit("CANNOT WRITE BLOCK %ld", a1);
fsmodified = 1;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(unsigned int a1, void *buf, size_t n)
{
ssize_t result; // rax

if ( lseek64(writefd, (int)(a1 << 9), 0) == -1 )
func7("CANNOT SEEK TO BLOCK %ld", a1);
result = write(writefd, buf, n);
if ( result != n )
func7("CANNOT WRITE BLOCK %ld", a1);
fsmodified = 1;
return result;
}

original_code:
void
writeblock (daddr_t addr, void *buf, size_t size)
{
  if (lseek (writefd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (write (writefd, buf, size) != size)
    errexit ("CANNOT WRITE BLOCK %ld", addr);
  fsmodified = 1;
}

canonical_original_code:
void writeblock(int addr, void *buf, unsigned long size)
{
  if (lseek (writefd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (write (writefd, buf, size) != size)
    errexit ("CANNOT WRITE BLOCK %ld", addr);
  fsmodified = 1;
}


decompiled_code:
ssize_t __fastcall write_inode(unsigned __int64 a1, const void *a2)
{
int v2; // ebx
void *v3; // r13

v2 = *(_DWORD *)(sblock + 32LL) * ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL))
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / *(_QWORD *)(sblock + 224LL)) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v2 )
readblock(v2 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
lastifragaddr = v2;
v3 = lastifrag;
memmove((char *)lastifrag + 192 * (a1 % *(_QWORD *)(sblock + 224LL)), a2, 0xC0uLL);
return writeblock(v2 << *(_QWORD *)(sblock + 184LL), v3, *(_QWORD *)(sblock + 80LL));
}

canonical_decompiled_code:
ssize_t __fastcall func11(unsigned __int64 a1, const void *a2)
{
int v2; // ebx
void *v3; // r13

v2 = *(_DWORD *)(sblock + 32LL) * ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL))
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / *(_QWORD *)(sblock + 224LL)) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v2 )
func8(v2 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
lastifragaddr = v2;
v3 = lastifrag;
memmove((char *)lastifrag + 192 * (a1 % *(_QWORD *)(sblock + 224LL)), a2, 0xC0uLL);
return func10(v2 << *(_QWORD *)(sblock + 184LL), v3, *(_QWORD *)(sblock + 80LL));
}

original_code:
void
write_inode (ino_t ino, struct dinode *di)
{
  daddr_t iblk;
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (di, lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  sizeof (struct dinode));
  writeblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
}

canonical_original_code:
void write_inode(unsigned long ino, struct dinode *di)
{
  int iblk;
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (di, lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  sizeof (struct dinode));
  writeblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
}

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


decompiled_code:
ssize_t __fastcall clear_inode(unsigned __int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[23] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 192) >> 3));
return write_inode(a1, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func12(unsigned __int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[23] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 192) >> 3));
return func11(a1, a2);
}

original_code:
void
clear_inode (ino_t ino, struct dinode *di)
{
  bzero (di, sizeof (struct dinode));
  write_inode (ino, di);
}

canonical_original_code:
void clear_inode(unsigned long ino, struct dinode *di)
{
  bzero (di, sizeof (struct dinode));
  write_inode (ino, di);
}


problem

decompiled_code:
__int64 problem(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
push_problem(a2, arg);
return no_preen(a1);
}

canonical_decompiled_code:
__int64 func13(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
func4(a2, arg);
return func15(a1);
}

original_code:
void
problem (int severe, char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
}

canonical_original_code:
void problem(int severe, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
}

variable_types: severe int


decompiled_code:
void __fastcall no_preen(int a1)
{
if ( a1 )
{
if ( preen )
punt("PLEASE RUN fsck MANUALLY");
}
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
if ( a1 )
{
if ( preen )
func14("PLEASE RUN fsck MANUALLY");
}
}

original_code:
static void
no_preen (int severe)
{
  if (severe && preen)
    punt ("PLEASE RUN fsck MANUALLY");
}

canonical_original_code:
static void no_preen(int severe)
{
  if (severe && preen)
    punt ("PLEASE RUN fsck MANUALLY");
}


pextend

decompiled_code:
void pextend(char *f, ...)
{
const char **v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
const char *v5; // rax
const char *v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (const char **)problems;
if ( !problems )
{
retch("No pending problem to add to");
goto LABEL_6;
}
va_start(arg, f);
if ( vasprintf(&s, f, arg) < 0 )
{
LABEL_6:
retch("vasprintf failed");
goto LABEL_7;
}
v2 = (char *)*v1;
v3 = strlen(*v1);
v4 = strlen(s);
v5 = (const char *)realloc(v2, v3 + v4 + 2);
v6 = v5;
if ( v5 )
{
v7 = strlen(v5);
strcpy((char *)&v6[v7], s);
*v1 = v6;
free(s);
return;
}
LABEL_7:
retch("realloc failed");
warning();
}

canonical_decompiled_code:
void func16(char *f, ...)
{
const char **v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
const char *v5; // rax
const char *v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (const char **)problems;
if ( !problems )
{
func2("No pending problem to add to");
goto LABEL_6;
}
va_start(arg, f);
if ( vasprintf(&s, f, arg) < 0 )
{
LABEL_6:
func2("vasprintf failed");
goto LABEL_7;
}
v2 = (char *)*v1;
v3 = strlen(*v1);
v4 = strlen(s);
v5 = (const char *)realloc(v2, v3 + v4 + 2);
v6 = v5;
if ( v5 )
{
v7 = strlen(v5);
strcpy((char *)&v6[v7], s);
*v1 = v6;
free(s);
return;
}
LABEL_7:
func2("realloc failed");
func17();
}

original_code:
void
pextend (char *fmt, ...)
{
  va_list args;
  char *more, *concat;
  struct problem *prob = problems;
  if (! prob)
    retch ("No pending problem to add to");
  __builtin_va_start(args,fmt);
  if (vasprintf (&more, fmt, args) < 0)
    retch ("vasprintf failed");
  __builtin_va_end(args);
  concat = realloc (prob->desc, strlen (prob->desc) + 1 + strlen (more) + 1);
  if (! concat)
    retch ("realloc failed");
  strcpy (concat + strlen (concat), more);
  prob->desc = concat;
  free (more);
}

canonical_original_code:
void pextend(char *fmt, ...)
{
  __builtin_va_list args;
  char *more; char *concat;
  struct problem *prob = problems;
  if (! prob)
    retch ("No pending problem to add to");
  __builtin_va_start(args,fmt);
  if (vasprintf (&more, fmt, args) < 0)
    retch ("vasprintf failed");
  __builtin_va_end(args);
  concat = realloc (prob->desc, strlen (prob->desc) + 1 + strlen (more) + 1);
  if (! concat)
    retch ("realloc failed");
  strcpy (concat + strlen (concat), more);
  prob->desc = concat;
  free (more);
}

variable_types:
more
char *

variable_types:
concat
char *

variable_types: struct problem { char *desc; struct problem *prev; } *


warning

decompiled_code:
void warning(int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
push_problem(a2, arg);
no_preen(a1);
resolve_problem(0LL);
}

canonical_decompiled_code:
void func17(int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
func4(a2, arg);
func15(a1);
func3(0LL);
}

original_code:
void
warning (int severe, char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
  resolve_problem (0);
}

canonical_original_code:
void warning(int severe, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
  resolve_problem (0);
}

variable_types:
fmt
char *


pinode

decompiled_code:
void pinode(int a1, unsigned __int64 a2, char *a3, ...)
{
const char *v4; // rsi
struct passwd *v5; // rax
char *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-188h] BYREF
time_t timer; // [rsp+28h] [rbp-160h] BYREF
__uid_t uid[2]; // [rsp+A0h] [rbp-E8h]
unsigned __int16 v10; // [rsp+B0h] [rbp-D8h]

if ( a3 )
{
va_start(va, a3);
push_problem(a3, va);
}
if ( a2 > 1 && maxino >= a2 )
{
getinode(a2, va);
v4 = "DIR";
if ( (va[0].gp_offset & 0xF000) != 0x4000 )
v4 = "FILE";
pextend(" %s I=%Ld", v4, a2);
v5 = getpwuid(uid[0]);
if ( v5 )
pextend(" O=%s", v5->pw_name);
else
pextend(" O=%lu", *(_QWORD *)uid);
pextend(" M=0%o", LOWORD(va[0].gp_offset) | (v10 << 16));
pextend(" SZ=%llu", va[0].reg_save_area);
v6 = ctime(&timer);
pextend(" MT=%12.12s %4.4s", v6 + 4, v6 + 20);
}
else
{
pextend(" (BOGUS INODE) I=%Ld", a2);
}
no_preen(a1);
}

canonical_decompiled_code:
void func18(int a1, unsigned __int64 a2, char *a3, ...)
{
const char *v4; // rsi
struct passwd *v5; // rax
char *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-188h] BYREF
time_t timer; // [rsp+28h] [rbp-160h] BYREF
__uid_t uid[2]; // [rsp+A0h] [rbp-E8h]
unsigned __int16 v10; // [rsp+B0h] [rbp-D8h]

if ( a3 )
{
va_start(va, a3);
func4(a3, va);
}
if ( a2 > 1 && maxino >= a2 )
{
func9(a2, va);
v4 = "DIR";
if ( (va[0].gp_offset & 0xF000) != 0x4000 )
v4 = "FILE";
func16(" %s I=%Ld", v4, a2);
v5 = getpwuid(uid[0]);
if ( v5 )
func16(" O=%s", v5->pw_name);
else
func16(" O=%lu", *(_QWORD *)uid);
func16(" M=0%o", LOWORD(va[0].gp_offset) | (v10 << 16));
func16(" SZ=%llu", va[0].reg_save_area);
v6 = ctime(&timer);
func16(" MT=%12.12s %4.4s", v6 + 4, v6 + 20);
}
else
{
func16(" (BOGUS INODE) I=%Ld", a2);
}
func15(a1);
}

original_code:
void
pinode (int severe, ino_t ino, char *fmt, ...)
{
  if (fmt)
    {
      va_list args;
      __builtin_va_start(args,fmt);
      push_problem (fmt, args);
      __builtin_va_end(args);
    }
  if (ino < ((ino_t)2) || ino > maxino)
    pextend (" (BOGUS INODE) I=%Ld", ino);
  else
    {
      char *p;
      struct dinode dino;
      struct passwd *pw;
      getinode (ino, &dino);
      pextend (" %s I=%Ld", ((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000 ? "DIR" : "FILE",
      ino);
      pw = getpwuid (dino.di_uid);
      if (pw)
 pextend (" O=%s", pw->pw_name);
      else
 pextend (" O=%lu", dino.di_uid);
      pextend (" M=0%o", (((&dino)->di_modeh << 16) | (&dino)->di_model));
      pextend (" SZ=%llu", dino.di_size);
      p = ctime (&dino.di_mtime.tv_sec);
      pextend (" MT=%12.12s %4.4s", &p[4], &p[20]);
    }
  no_preen (severe);
}

canonical_original_code:
void pinode(int severe, unsigned long ino, char *fmt, ...)
{
  if (fmt)
    {
      __builtin_va_list args;
      __builtin_va_start(args,fmt);
      push_problem (fmt, args);
      __builtin_va_end(args);
    }
  if (ino < ((unsigned long)2) || ino > maxino)
    pextend (" (BOGUS INODE) I=%Ld", ino);
  else
    {
      char *p;
      struct dinode dino;
      struct passwd *pw;
      getinode (ino, &dino);
      pextend (" %s I=%Ld", ((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000 ? "DIR" : "FILE",
      ino);
      pw = getpwuid (dino.di_uid);
      if (pw)
 pextend (" O=%s", pw->pw_name);
      else
 pextend (" O=%lu", dino.di_uid);
      pextend (" M=0%o", (((&dino)->di_modeh << 16) | (&dino)->di_model));
      pextend (" SZ=%llu", dino.di_size);
      p = ctime (&dino.di_mtime.tv_sec);
      pextend (" MT=%12.12s %4.4s", &p[4], &p[20]);
    }
  no_preen (severe);
}

variable_types:
p
char *

variable_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec { long tv_sec; long tv_nsec; } di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; }

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


pfix

decompiled_code:
void __fastcall pfix(const char *a1)
{
if ( preen )
{
if ( !a1 )
a1 = "FIXED";
resolve_problem(a1);
}
}

canonical_decompiled_code:
void __fastcall func19(const char *a1)
{
if ( preen )
{
if ( !a1 )
a1 = "FIXED";
func3(a1);
}
}

original_code:
void
pfix (char *fix)
{
  if (preen)
    resolve_problem (fix ?: "FIXED");
}

canonical_original_code:
void pfix(char *fix)
{
  if (preen)
    resolve_problem (fix ?: "FIXED");
}

variable_types:
fix
char *


pfail

decompiled_code:
void __fastcall pfail(const char *a1)
{
if ( preen )
resolve_problem(a1);
}

canonical_decompiled_code:
void __fastcall func20(const char *a1)
{
if ( preen )
func3(a1);
}

original_code:
void
pfail (char *failure)
{
  if (preen)
    resolve_problem (failure);
}

canonical_original_code:
void pfail(char *failure)
{
  if (preen)
    resolve_problem (failure);
}

variable_types:
failure
char *


reply

decompiled_code:
__int64 __fastcall reply(const char *a1)
{
unsigned int v2; // er13
char v3; // bp

v2 = preen;
if ( preen )
{
retch("Got to reply() in preen mode");
goto LABEL_8;
}
resolve_problem(0LL);
if ( !strcmp(a1, "CONTINUE") )
{
if ( __PAIR64__(nowrite, noquery) )
{
LABEL_20:
printf("%s? yes\n\n", a1);
return 1;
}
goto LABEL_11;
}
if ( nowrite || writefd < 0 )
{
LABEL_8:
fix_denied = 1;
printf("%s? no\n\n", a1);
return v2;
}
if ( noquery )
goto LABEL_20;
LABEL_11:
while ( 2 )
{
printf("%s? [yn] ", a1);
fflush(stdout);
v3 = getchar();
while ( 1 )
{
if ( v3 == 10 )
goto LABEL_11;
if ( getchar() == 10 )
break;
if ( feof(stdin) )
{
fix_denied = 1;
return v2;
}
}
if ( (v3 & 0xDF) == 89 )
{
putchar(10);
v2 = 1;
}
else
{
if ( (v3 & 0xDF) != 78 )
continue;
putchar(10);
fix_denied = 1;
}
return v2;
}
}

canonical_decompiled_code:
__int64 __fastcall func21(const char *a1)
{
unsigned int v2; // er13
char v3; // bp

v2 = preen;
if ( preen )
{
func2("Got to reply() in preen mode");
goto LABEL_8;
}
func3(0LL);
if ( !strcmp(a1, "CONTINUE") )
{
if ( __PAIR64__(nowrite, noquery) )
{
LABEL_20:
printf("%s? yes\n\n", a1);
return 1;
}
goto LABEL_11;
}
if ( nowrite || writefd < 0 )
{
LABEL_8:
fix_denied = 1;
printf("%s? no\n\n", a1);
return v2;
}
if ( noquery )
goto LABEL_20;
LABEL_11:
while ( 2 )
{
printf("%s? [yn] ", a1);
fflush(stdout);
v3 = getchar();
while ( 1 )
{
if ( v3 == 10 )
goto LABEL_11;
if ( getchar() == 10 )
break;
if ( feof(stdin) )
{
fix_denied = 1;
return v2;
}
}
if ( (v3 & 0xDF) == 89 )
{
putchar(10);
v2 = 1;
}
else
{
if ( (v3 & 0xDF) != 78 )
continue;
putchar(10);
fix_denied = 1;
}
return v2;
}
}

original_code:
int
reply (char *question)
{
  int persevere;
  char c;
  if (preen)
    retch ("Got to reply() in preen mode");
  resolve_problem (0);
  persevere = !strcmp (question, "CONTINUE");
  if (!persevere && (nowrite || writefd < 0))
    {
      fix_denied = 1;
      printf ("%s? no\n\n", question);
      return 0;
    }
  else if (noquery || (persevere && nowrite))
    {
      printf ("%s? yes\n\n", question);
      return 1;
    }
 else
    {
      do
 {
   printf ("%s? [yn] ", question);
   fflush (stdout);
   c = getchar ();
   while (c != '\n' && getchar () != '\n')
     if (feof (stdin))
       {
  fix_denied = 1;
  return 0;
       }
 }
      while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
      putchar ('\n');
      if (c == 'y' || c == 'Y')
 return 1;
      else
 {
   fix_denied = 1;
   return 0;
 }
    }
}

canonical_original_code:
int reply(char *question)
{
  int persevere;
  char c;
  if (preen)
    retch ("Got to reply() in preen mode");
  resolve_problem (0);
  persevere = !strcmp (question, "CONTINUE");
  if (!persevere && (nowrite || writefd < 0))
    {
      fix_denied = 1;
      printf ("%s? no\n\n", question);
      return 0;
    }
  else if (noquery || (persevere && nowrite))
    {
      printf ("%s? yes\n\n", question);
      return 1;
    }
 else
    {
      do
 {
   printf ("%s? [yn] ", question);
   fflush (stdout);
   c = getchar ();
   while (c != '\n' && getchar () != '\n')
     if (feof (stdin))
       {
  fix_denied = 1;
  return 0;
       }
 }
      while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
      putchar ('\n');
      if (c == 'y' || c == 'Y')
 return 1;
      else
 {
   fix_denied = 1;
   return 0;
 }
    }
}

variable_types:
question
char *

variable_types: persevere int

variable_types: c char