main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
const char *v6; // r12
unsigned int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v12; // [rsp+Ch] [rbp-4Ch]
int longind[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v12 = 0;
v6 = 0LL;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, (char *const *)argv, "hVf:s:t:d:cnl", &long_options_0, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
exit(1);
case 'V':
cli_print_version();
exit(0);
case 'c':
cli_camera_summary();
break;
case 'd':
if ( v3 )
{
fprintf(stderr, "%s: `--delete-image' (`-d') option redeclared\n", "photo");
cli_print_help();
exit(1);
}
v10 = atoi(optarg);
cli_delete_image(v10);
v3 = 1;
break;
case 'f':
if ( v12 )
{
fprintf(stderr, "%s: `--filename' (`-f') option redeclared\n", "photo");
cli_print_help();
exit(1);
}
v6 = gengetopt_strdup(optarg);
test_file_name(v6);
printf("Filename input was %s\n", v6);
v12 = 1;
break;
case 'h':
cli_print_help();
exit(0);
case 'l':
cli_save_live_preview(v6);
break;
case 'n':
cli_display_numbers();
break;
case 's':
if ( v5 )
{
fprintf(stderr, "%s: `--save-image' (`-s') option redeclared\n", "photo");
cli_print_help();
exit(1);
}
v8 = atoi(optarg);
cli_save_image(v8, v6);
v5 = 1;
break;
case 't':
if ( v4 )
{
fprintf(stderr, "%s: `--save-thumbnail' (`-t') option redeclared\n", "photo");
cli_print_help();
exit(1);
}
v9 = atoi(optarg);
cli_save_thumbnail(v9, v6);
v4 = 1;
break;
default:
fprintf(stderr, "%s: option unknown: %c\n", "photo", v7);
abort();
}
}
fflush(_bss_start);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
const char *v6; // r12
unsigned int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v12; // [rsp+Ch] [rbp-4Ch]
int longind[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v12 = 0;
v6 = 0LL;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, (char *const *)argv, "hVf:s:t:d:cnl", &long_options_0, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
exit(1);
case 'V':
func8();
exit(0);
case 'c':
func11();
break;
case 'd':
if ( v3 )
{
fprintf(stderr, "%s: `--delete-image' (`-d') option redeclared\n", "photo");
func15();
exit(1);
}
v10 = atoi(optarg);
func12(v10);
v3 = 1;
break;
case 'f':
if ( v12 )
{
fprintf(stderr, "%s: `--filename' (`-f') option redeclared\n", "photo");
func15();
exit(1);
}
v6 = gengetopt_strdup(optarg);
func7(v6);
printf("Filename input was %s\n", v6);
v12 = 1;
break;
case 'h':
func15();
exit(0);
case 'l':
func14(v6);
break;
case 'n':
func13();
break;
case 's':
if ( v5 )
{
fprintf(stderr, "%s: `--save-image' (`-s') option redeclared\n", "photo");
func15();
exit(1);
}
v8 = atoi(optarg);
func9(v8, v6);
v5 = 1;
break;
case 't':
if ( v4 )
{
fprintf(stderr, "%s: `--save-thumbnail' (`-t') option redeclared\n", "photo");
func15();
exit(1);
}
v9 = atoi(optarg);
func10(v9, v6);
v4 = 1;
break;
default:
fprintf(stderr, "%s: option unknown: %c\n", "photo", v7);
abort();
}
}
fflush(_bss_start);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
  int c;
  char *filename_arg = ((void *)0);
  int save_image_arg;
  int save_thumbnail_arg;
  int delete_image_arg;
  int filename_given = 0;
  int save_image_given = 0;
  int save_thumbnail_given = 0;
  int delete_image_given = 0;
  {
    if (filename_arg != ((void *)0))
      free (filename_arg);
  }
  while (1)
    {
      int option_index = 0;
      static struct option long_options[] =
      {
 {"help", 0, ((void *)0), 'h'},
 {"version", 0, ((void *)0), 'V'},
 {"filename", 1, ((void *)0), 'f'},
 {"save-image", 1, ((void *)0), 's'},
 {"save-thumbnail", 1, ((void *)0), 't'},
 {"delete-image", 1, ((void *)0), 'd'},
 {"camera-summary", 0, ((void *)0), 'c'},
 {"number-of-pictures", 0, ((void *)0), 'n'},
 {"save-live-preview", 0, ((void *)0), 'l'},
 {((void *)0), 0, ((void *)0), 0}
      };
      c = getopt_long (argc, argv, "hVf:s:t:d:cnl",
         long_options, &option_index);
      if (c == -1)
 break;
      switch (c)
 {
 case 'h':
   ;
   cli_print_help ();
   exit (0);
 case 'V':
   ;
   cli_print_version ();
   exit (0);
 case 'f':
   if (filename_given)
     {
       fprintf (stderr, "%s: `--filename' (`-f') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   filename_given = 1;
   filename_arg = gengetopt_strdup (optarg);
   test_file_name (filename_arg);
   printf ("Filename input was %s\n", filename_arg);
   break;
 case 's':
   if (save_image_given)
     {
       fprintf (stderr, "%s: `--save-image' (`-s') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   save_image_given = 1;
   save_image_arg = atoi (optarg);
   cli_save_image (save_image_arg, filename_arg);
   break;
 case 't':
   if (save_thumbnail_given)
     {
       fprintf (stderr, "%s: `--save-thumbnail' (`-t') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   save_thumbnail_given = 1;
   save_thumbnail_arg = atoi (optarg);
   cli_save_thumbnail (save_thumbnail_arg, filename_arg);
   break;
 case 'd':
   if (delete_image_given)
     {
       fprintf (stderr, "%s: `--delete-image' (`-d') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   delete_image_given = 1;
   delete_image_arg = atoi (optarg);
   cli_delete_image (delete_image_arg);
   break;
 case 'c':
   cli_camera_summary ();
   break;
 case 'n':
   cli_display_numbers ();
   break;
 case 'l':
   cli_save_live_preview (filename_arg);
   break;
 case '?':
   exit (1);
 default:
   fprintf (stderr, "%s: option unknown: %c\n",
     "photo", c);
   abort ();
 }
    }
  fflush (stdout);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int c;
  char *filename_arg = ((void *)0);
  int save_image_arg;
  int save_thumbnail_arg;
  int delete_image_arg;
  int filename_given = 0;
  int save_image_given = 0;
  int save_thumbnail_given = 0;
  int delete_image_given = 0;
  {
    if (filename_arg != ((void *)0))
      free (filename_arg);
  }
  while (1)
    {
      int option_index = 0;
      static struct option long_options[] = {
 {"help", 0, ((void *)0), 'h'},
 {"version", 0, ((void *)0), 'V'},
 {"filename", 1, ((void *)0), 'f'},
 {"save-image", 1, ((void *)0), 's'},
 {"save-thumbnail", 1, ((void *)0), 't'},
 {"delete-image", 1, ((void *)0), 'd'},
 {"camera-summary", 0, ((void *)0), 'c'},
 {"number-of-pictures", 0, ((void *)0), 'n'},
 {"save-live-preview", 0, ((void *)0), 'l'},
 {((void *)0), 0, ((void *)0), 0}
      };
      c = getopt_long (argc, argv, "hVf:s:t:d:cnl",
         long_options, &option_index);
      if (c == -1)
 break;
      switch (c)
 {
 case 'h':
   ;
   cli_print_help ();
   exit (0);
 case 'V':
   ;
   cli_print_version ();
   exit (0);
 case 'f':
   if (filename_given)
     {
       fprintf (stderr, "%s: `--filename' (`-f') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   filename_given = 1;
   filename_arg = gengetopt_strdup (optarg);
   test_file_name (filename_arg);
   printf ("Filename input was %s\n", filename_arg);
   break;
 case 's':
   if (save_image_given)
     {
       fprintf (stderr, "%s: `--save-image' (`-s') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   save_image_given = 1;
   save_image_arg = atoi (optarg);
   cli_save_image (save_image_arg, filename_arg);
   break;
 case 't':
   if (save_thumbnail_given)
     {
       fprintf (stderr, "%s: `--save-thumbnail' (`-t') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   save_thumbnail_given = 1;
   save_thumbnail_arg = atoi (optarg);
   cli_save_thumbnail (save_thumbnail_arg, filename_arg);
   break;
 case 'd':
   if (delete_image_given)
     {
       fprintf (stderr, "%s: `--delete-image' (`-d') option redeclared\n", "photo");
       ;
       cli_print_help ();
       exit (1);
     }
   delete_image_given = 1;
   delete_image_arg = atoi (optarg);
   cli_delete_image (delete_image_arg);
   break;
 case 'c':
   cli_camera_summary ();
   break;
 case 'n':
   cli_display_numbers ();
   break;
 case 'l':
   cli_save_live_preview (filename_arg);
   break;
 case '?':
   exit (1);
 default:
   fprintf (stderr, "%s: option unknown: %c\n",
     "photo", c);
   abort ();
 }
    }
  fflush (stdout);
  return 0;
}

variable_types:
argv
char **

variable_types: c int

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


decompiled_code:
int __fastcall register_call(unsigned int a1)
{
return printf("%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("%d\n", a1);
}

original_code:
void register_call(int i)
{
 printf("%d\n",i);
}

variable_types: i int

return_type: void


remote

decompiled_code:
__int64 __fastcall remote(__int64 (__fastcall *a1)(_QWORD), unsigned int a2)
{
return a1(a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 (__fastcall *a1)(_QWORD), unsigned int a2)
{
return a1(a2);
}

original_code:
void remote(_register_call reg_func, int i)
{
 (reg_func)(i);
}

canonical_original_code:
void remote(void (*reg_func)(int), int i)
{
 (reg_func)(i);
}


original_code:
int jl2005a_decompress (unsigned char *inp, unsigned char *outp, int width,
   int height)
{
 int i,j;
 int hdiff,vdiff;
 for (i=0; i < height/2; i+=2) {
  memcpy(outp+2*i*width,inp+i*width, 2*width);
 }
 memcpy(outp+(height-2)*width,outp+(height-4)*width, 2*width);
 for (i=0; i < height/4-1; i++) {
  for (j=0; j < width; j++) {
   outp[(4*i+2)*width+j]=(inp[(2*i)*width+j]+
      inp[(2*i+2)*width+j])/2;
    outp[(4*i+3)*width+j]=(outp[(4*i+1)*width+j]+
      outp[(4*i+5)*width+j])/2;
  }
 }
 if (width == 176)
  memmove(outp+6*width, outp, (height-6)*width);
 return 0;
}

canonical_original_code:
int jl2005a_decompress(unsigned char *inp, unsigned char *outp, int width, int height)
{
 int i; int j;
 int hdiff; int vdiff;
 for (i=0; i < height/2; i+=2) {
  memcpy(outp+2*i*width,inp+i*width, 2*width);
 }
 memcpy(outp+(height-2)*width,outp+(height-4)*width, 2*width);
 for (i=0; i < height/4-1; i++) {
  for (j=0; j < width; j++) {
   outp[(4*i+2)*width+j]=(inp[(2*i)*width+j]+
      inp[(2*i+2)*width+j])/2;
    outp[(4*i+3)*width+j]=(outp[(4*i+1)*width+j]+
      outp[(4*i+5)*width+j])/2;
  }
 }
 if (width == 176)
  memmove(outp+6*width, outp, (height-6)*width);
 return 0;
}

variable_types:
inp
unsigned char *

variable_types:
outp
unsigned char *

variable_types: width int

variable_types: height int

variable_types: j int

variable_types: hdiff int

variable_types: vdiff int

return_type: int


original_code:
int get_image_info( image_info *info, int size) {
 int w, h, comp_ratio;
 switch(size) {
   case 0x318e:
   w = 176;
   h = 72;
   comp_ratio = 2;
   break;
  case 0x630e:
   w = 176;
   h = 144;
   comp_ratio = 1;
   break;
   case 0xc60e:
   w = 352;
   h = 144;
   comp_ratio = 2;
   break;
  case 0x18c0e:
   w = 352;
   h = 288;
   comp_ratio = 1;
   break;
  case 0x960e:
   w = 320;
   h = 240;
   comp_ratio = 2;
   break;
  case 0x12c0e:
   w = 320;
   h = 240;
   comp_ratio = 1;
   break;
  case 0x2580e:
   w = 640;
   h = 480;
   comp_ratio = 2;
   break;
  case 0x4b00e:
   w = 640;
   h = 480;
   comp_ratio = 1;
   break;
  default: ;
   printf("Not a JL2005A photo. Exiting.\n");
   return -1;
 }
 printf("w is %i\n", w);
 info->width = w;
 info->height= h;
 info->compression = comp_ratio;
 info->gamma = .5;
 printf("gamma is %f\n", info->gamma);
 return 0;
}

canonical_original_code:
int get_image_info(struct image_info *info, int size) {
 int w; int h; int comp_ratio;
 switch(size) {
   case 0x318e:
   w = 176;
   h = 72;
   comp_ratio = 2;
   break;
  case 0x630e:
   w = 176;
   h = 144;
   comp_ratio = 1;
   break;
   case 0xc60e:
   w = 352;
   h = 144;
   comp_ratio = 2;
   break;
  case 0x18c0e:
   w = 352;
   h = 288;
   comp_ratio = 1;
   break;
  case 0x960e:
   w = 320;
   h = 240;
   comp_ratio = 2;
   break;
  case 0x12c0e:
   w = 320;
   h = 240;
   comp_ratio = 1;
   break;
  case 0x2580e:
   w = 640;
   h = 480;
   comp_ratio = 2;
   break;
  case 0x4b00e:
   w = 640;
   h = 480;
   comp_ratio = 1;
   break;
  default: ;
   printf("Not a JL2005A photo. Exiting.\n");
   return -1;
 }
 printf("w is %i\n", w);
 info->width = w;
 info->height= h;
 info->compression = comp_ratio;
 info->gamma = .5;
 printf("gamma is %f\n", info->gamma);
 return 0;
}

variable_types: struct image_info { int width; int height; unsigned char compression; float gamma; } *

variable_types: size int

variable_types: w int

variable_types: h int


canonical_decompiled_code:
__int64 __fastcall func5(__int64 (__fastcall *a1)(_QWORD), unsigned int a2)
{
return a1(a2);
}


repo: pinkavaj/msdptool

decompiled_code:
int print_help()
{
return puts(
"sdptool [-h] [-a <addr>] <io port> <CMD>\n"
" -h - print help\n"
" -a - set device address\n"
" <addr> - rs485 address of device (1 - 31), defaults to 1\n"
" <io port> - port for comunication with SDP power supply\n"
" win: { COM1 | COM2 | ... }\n"
" Linux: { /dev/ttyS0 | /dev/ttyS1 | ... }\n"
" use \"-\" for std. in and out, output will be send to stderr\n"
" CMD := {\n"
" ccom { rs232 | rs485 } |\n"
" gcom |\n"
" gmax |\n"
" govp |\n"
" getd |\n"
" gets |\n"
" getm { 1 - 9 | all } |\n"
" getp { 0 - 19 | all } |\n"
" gpal |\n"
" volt { 0 - 99.9 } |\n"
" curr { 0 - 9.99 } |\n"
" sovp { 0 - 99.9 } |\n"
" sout { on | off } |\n"
" poww { 1 - 9 } { on | off } |\n"
" prom { 1 - 9 } { 0 - 99.9 } { 0 - 9.99 } |\n"
" prop { 0 - 19 } { 0 - 99.9 } { 0 - 9.99 } { 00:00 - 99:59 | 0 - 5999 } |\n"
" runm { 1 - 9 } |\n"
" runp { 1 - 999 | inf } |\n"
" stop }\n"
" See SDP power supply manual for detailed informations about commands");
}

canonical_decompiled_code:
int func0()
{
return puts(
"sdptool [-h] [-a <addr>] <io port> <CMD>\n"
" -h - print help\n"
" -a - set device address\n"
" <addr> - rs485 address of device (1 - 31), defaults to 1\n"
" <io port> - port for comunication with SDP power supply\n"
" win: { COM1 | COM2 | ... }\n"
" Linux: { /dev/ttyS0 | /dev/ttyS1 | ... }\n"
" use \"-\" for std. in and out, output will be send to stderr\n"
" CMD := {\n"
" ccom { rs232 | rs485 } |\n"
" gcom |\n"
" gmax |\n"
" govp |\n"
" getd |\n"
" gets |\n"
" getm { 1 - 9 | all } |\n"
" getp { 0 - 19 | all } |\n"
" gpal |\n"
" volt { 0 - 99.9 } |\n"
" curr { 0 - 9.99 } |\n"
" sovp { 0 - 99.9 } |\n"
" sout { on | off } |\n"
" poww { 1 - 9 } { on | off } |\n"
" prom { 1 - 9 } { 0 - 99.9 } { 0 - 9.99 } |\n"
" prop { 0 - 19 } { 0 - 99.9 } { 0 - 9.99 } { 00:00 - 99:59 | 0 - 5999 } |\n"
" runm { 1 - 9 } |\n"
" runp { 1 - 999 | inf } |\n"
" stop }\n"
" See SDP power supply manual for detailed informations about commands");
}

original_code:
static void print_help(void)
{
        printf("sdptool [-h] [-a <addr>] <io port> <CMD>\n"
        "        -h - print help\n"
        "        -a - set device address\n"
        "        <addr>  - rs485 address of device (1 - 31), defaults to 1\n"
        "        <io port> - port for comunication with SDP power supply\n"
        "                win: { COM1 | COM2 | ... }\n"
        "                Linux: { /dev/ttyS0 | /dev/ttyS1 | ... }\n"
        "                use \"-\" for std. in and out, output will be send to stderr\n"
        "        CMD := {\n"
        "                ccom { rs232 | rs485 } |\n"
        "                gcom |\n"
        "                gmax |\n"
        "                govp |\n"
        "                getd |\n"
        "                gets |\n"
        "                getm { 1 - 9 | all } |\n"
        "                getp { 0 - 19 | all } |\n"
        "                gpal |\n"
        "                volt { 0 - 99.9 } |\n"
        "                curr { 0 - 9.99 } |\n"
        "                sovp { 0 - 99.9 } |\n"
        "                sout { on | off } |\n"
        "                poww { 1 - 9 } { on | off } |\n"
        "                prom { 1 - 9 } { 0 - 99.9 } { 0 - 9.99 } |\n"
        "                prop { 0 - 19 } { 0 - 99.9 } { 0 - 9.99 } { 00:00 - 99:59 | 0 -  5999 } |\n"
        "                runm { 1 - 9 } |\n"
        "                runp { 1 - 999 | inf } |\n"
        "                stop }\n"
        "        See SDP power supply manual for detailed informations about commands\n");
}

canonical_original_code:
static void print_help()
{
        printf("sdptool [-h] [-a <addr>] <io port> <CMD>\n"
        "        -h - print help\n"
        "        -a - set device address\n"
        "        <addr>  - rs485 address of device (1 - 31), defaults to 1\n"
        "        <io port> - port for comunication with SDP power supply\n"
        "                win: { COM1 | COM2 | ... }\n"
        "                Linux: { /dev/ttyS0 | /dev/ttyS1 | ... }\n"
        "                use \"-\" for std. in and out, output will be send to stderr\n"
        "        CMD := {\n"
        "                ccom { rs232 | rs485 } |\n"
        "                gcom |\n"
        "                gmax |\n"
        "                govp |\n"
        "                getd |\n"
        "                gets |\n"
        "                getm { 1 - 9 | all } |\n"
        "                getp { 0 - 19 | all } |\n"
        "                gpal |\n"
        "                volt { 0 - 99.9 } |\n"
        "                curr { 0 - 9.99 } |\n"
        "                sovp { 0 - 99.9 } |\n"
        "                sout { on | off } |\n"
        "                poww { 1 - 9 } { on | off } |\n"
        "                prom { 1 - 9 } { 0 - 99.9 } { 0 - 9.99 } |\n"
        "                prop { 0 - 19 } { 0 - 99.9 } { 0 - 9.99 } { 00:00 - 99:59 | 0 -  5999 } |\n"
        "                runm { 1 - 9 } |\n"
        "                runp { 1 - 999 | inf } |\n"
        "                stop }\n"
        "        See SDP power supply manual for detailed informations about commands\n");
}


decompiled_code:
int print_help_short()
{
return puts(
"sdptool - commandline utility for remote control of SDP series power supplies\n"
" Use -h or --help for help");
}

canonical_decompiled_code:
int func1()
{
return puts(
"sdptool - commandline utility for remote control of SDP series power supplies\n"
" Use -h or --help for help");
}

original_code:
static void print_help_short(void)
{
        printf("sdptool - commandline utility for remote control of SDP series power supplies\n"
               "        Use -h or --help for help\n");
}

canonical_original_code:
static void print_help_short()
{
        printf("sdptool - commandline utility for remote control of SDP series power supplies\n"
               "        Use -h or --help for help\n");
}


printe

decompiled_code:
__int64 __fastcall printe(const char *a1)
{
fputs(a1, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
fputs(a1, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int printe(const char *str)
{
        fprintf(stderr, "%s", str);
        return -1;
}

canonical_original_code:
static int printe(char *str)
{
        fprintf(stderr, "%s", str);
        return -1;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall perror_(const char *a1, unsigned int a2)
{
const char *v2; // rax

v2 = (const char *)sdp_strerror(a2);
fprintf(stderr, "%s: %s\n", a1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, unsigned int a2)
{
const char *v2; // rax

v2 = (const char *)sdp_strerror(a2);
fprintf(stderr, "%s: %s\n", a1, v2);
return 0xFFFFFFFFLL;
}

original_code:
static int perror_(const char *str, int err)
{
        const char *errs;
        errs = sdp_strerror(err);
        fprintf(stderr, "%s: %s\n", str, errs);
        return -1;
}

canonical_original_code:
static int perror_(char *str, int err)
{
        char *errs;
        errs = sdp_strerror(err);
        fprintf(stderr, "%s: %s\n", str, errs);
        return -1;
}

variable_types: err int

variable_types:
errs
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // er13
int result; // eax
const char *v6; // rbx
__int64 v7; // r14
const char *v8; // r15
signed int v9; // eax
FILE *v10; // r15
signed int v11; // eax
const char *v12; // r12
const char **v13; // rbp
unsigned int v14; // ebx
const char *v15; // rbx
__int64 v16; // rsi
signed int v17; // eax
signed int v18; // esi
signed int v19; // eax
signed int v20; // eax
signed int v21; // eax
signed int v22; // eax
signed int v23; // eax
int v24; // er13
const char *v25; // r12
__int64 v26; // rsi
signed int v27; // esi
double *v28; // rbp
int v29; // er13
const char *v30; // r12
__int64 v31; // rsi
signed int v32; // esi
char **v33; // rbp
signed int v34; // esi
double v35; // xmm0_8
signed int v36; // esi
double v37; // xmm0_8
signed int v38; // esi
double v39; // xmm0_8
signed int v40; // esi
const char *v41; // rbp
signed int v42; // esi
unsigned int v43; // ebx
const char *v44; // rbp
unsigned int v45; // eax
__int64 v46; // rdx
signed int v47; // esi
unsigned int v48; // ebx
signed int v49; // esi
unsigned int v50; // ebx
int v51; // edx
char *v52; // rax
__int64 v53; // rsi
signed int v54; // esi
__int64 v55; // rsi
unsigned int v56; // eax
signed int v57; // esi
signed int v58; // esi
int v59; // eax
signed int v60; // esi
char *v61; // [rsp+8h] [rbp-230h] BYREF
char *endptr; // [rsp+10h] [rbp-228h] BYREF
double v63; // [rsp+18h] [rbp-220h]
double v64; // [rsp+20h] [rbp-218h]
char v65; // [rsp+28h] [rbp-210h]
double v66; // [rsp+30h] [rbp-208h]
char v67; // [rsp+38h] [rbp-200h]
int v68; // [rsp+3Ch] [rbp-1FCh]
char v69; // [rsp+40h] [rbp-1F8h]
double v70; // [rsp+48h] [rbp-1F0h]
char v71; // [rsp+50h] [rbp-1E8h]
char v72; // [rsp+52h] [rbp-1E6h]
double v73; // [rsp+58h] [rbp-1E0h]
char v74; // [rsp+60h] [rbp-1D8h]
char v75; // [rsp+62h] [rbp-1D6h]
char v76; // [rsp+69h] [rbp-1CFh]
char v77; // [rsp+6Bh] [rbp-1CDh]
char v78; // [rsp+6Ch] [rbp-1CCh]
char v79; // [rsp+6Dh] [rbp-1CBh]
char v80; // [rsp+6Eh] [rbp-1CAh]
char v81[4]; // [rsp+1F4h] [rbp-44h] BYREF
int v82; // [rsp+1F8h] [rbp-40h]
int v83; // [rsp+1FCh] [rbp-3Ch]

if ( argc <= 1 )
{
print_help_short();
return -1;
}
if ( argc == 2 )
{
v6 = argv[1];
if ( !strcmp(v6, "-h") || !strcmp(v6, "--help") )
{
print_help();
return 0;
}
return printe("Invalid or missing argument");
}
if ( strcmp(argv[1], "-a") )
{
v4 = 1;
v3 = 1;
goto LABEL_16;
}
if ( argc <= 4 )
return printe("Invalid or missing argument");
v3 = strtol(argv[2], &endptr, 0);
if ( v3 - 1 > 0x1E )
return printe("Device address out of range");
v4 = 3;
if ( *endptr )
return printe("Device address out of range");
LABEL_16:
v7 = v4;
v8 = argv[v7];
if ( !strcmp(v8, "-") )
{
v9 = sdp_openf(v81, 0xFFFFFFFFLL, v3);
if ( v9 >= 0 )
{
v82 = 0;
v83 = 1;
v10 = stderr;
goto LABEL_19;
}
return perror_("sdp_open failed", v9);
}
v9 = sdp_open(v81, v8, v3);
if ( v9 < 0 )
return perror_("sdp_open failed", v9);
v10 = stdout;
LABEL_19:
v11 = sdp_remote(v81, 1LL);
if ( v11 < 0 )
return perror_("Failed to switch to remote mode", v11);
v12 = argv[v7 + 1];
v13 = &argv[v7 + 2];
v14 = argc - (v4 + 2);
if ( !strcmp(v12, "ccom") )
{
if ( v14 == 1 )
{
v15 = *v13;
if ( !strcmp(*v13, "rs232") )
{
v16 = 0LL;
}
else
{
v16 = 1LL;
if ( strcmp(v15, "rs485") )
return printe("Invalid argument");
}
v17 = sdp_select_ifce(v81, v16);
if ( v17 < 0 )
return perror_("sdp_select_ifce failed", v17);
goto LABEL_25;
}
return printe("Invalid number of parameters");
}
if ( !strcmp(v12, "gcom") )
{
if ( !v14 )
{
v19 = sdp_get_dev_addr(v81);
if ( v19 < 0 )
return perror_("sdp_get_dev_addr failed", v19);
fprintf(v10, "%i\n", (unsigned int)v19);
goto LABEL_25;
}
return printe("Invalid number of parameters");
}
if ( !strcmp(v12, "gmax") )
{
if ( v14 )
return printe("Invalid number of parameters");
v20 = sdp_get_va_maximums(v81, &endptr);
if ( v20 < 0 )
return perror_("sdp_get_va_maximums failed", v20);
LABEL_45:
fprintf(v10, "%2.1f %1.2f\n", v63, *(double *)&endptr);
LABEL_25:
v18 = sdp_remote(v81, 0LL);
result = 0;
if ( v18 < 0 )
result = perror_("Failed to disable remote mode", v18);
return result;
}
if ( !strcmp(v12, "govp") )
{
if ( !v14 )
{
v21 = sdp_get_volt_limit(v81, &endptr);
if ( v21 < 0 )
return perror_("sdp_get_volt_limit failed", v21);
fprintf(v10, "%2.1f\n", *(double *)&endptr);
goto LABEL_25;
}
return printe("Invalid number of parameters");
}
if ( !strcmp(v12, "getd") )
{
if ( !v14 )
{
v22 = sdp_get_va_data(v81, &endptr);
if ( v22 < 0 )
return perror_("sdp_get_va_data failed", v22);
if ( LODWORD(v64) == 1 )
fprintf(v10, "%2.2f %1.3f CC\n", v63, *(double *)&endptr);
else
fprintf(v10, "%2.2f %1.3f CV\n", v63, *(double *)&endptr);
goto LABEL_25;
}
return printe("Invalid number of parameters");
}
if ( !strcmp(v12, "gets") )
{
if ( v14 )
return printe("Invalid number of parameters");
v23 = sdp_get_va_setpoint(v81, &endptr);
if ( v23 < 0 )
return perror_("sdp_get_va_setpoint failed", v23);
goto LABEL_45;
}
v24 = strcmp(v12, "getm");
if ( !v24 )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v25 = *v13;
if ( !strcmp(*v13, "all") )
{
v14 = 9;
v26 = 10LL;
}
else
{
v26 = strtol(v25, &v61, 0);
if ( !**v13 || *v61 )
return printe("Invalid preset number");
}
v27 = sdp_get_preset(v81, v26, &endptr);
v28 = (double *)&endptr;
if ( v27 < 0 )
return perror_("sdp_get_preset failed", v27);
do
{
fprintf(v10, "%2.1f %1.2f\n", v28[1], *v28);
++v24;
v28 += 2;
}
while ( v14 != v24 );
goto LABEL_25;
}
v29 = strcmp(v12, "getp");
if ( !v29 )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v30 = *v13;
if ( !strcmp(*v13, "all") )
{
v14 = 20;
v31 = 20LL;
}
else
{
v31 = strtol(v30, &v61, 0);
if ( !**v13 || *v61 )
return printe("Invalid preset number");
}
v32 = sdp_get_program(v81, v31, &endptr);
v33 = &endptr;
if ( v32 < 0 )
return perror_("sdp_get_program failed", v32);
do
{
fprintf(
v10,
"%2.1f %1.2f %02i:%02i\n",
*((double *)v33 + 1),
*(double *)v33,
(unsigned int)(*((_DWORD *)v33 + 4) / 60),
(unsigned int)(*((_DWORD *)v33 + 4) % 60));
++v29;
v33 += 3;
}
while ( v14 != v29 );
goto LABEL_25;
}
if ( strcmp(v12, "gpal") )
{
if ( !strcmp(v12, "volt") )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v35 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v36 = sdp_set_volt(v81, v35);
if ( v36 < 0 )
return perror_("sdp_set_volt failed", v36);
goto LABEL_25;
}
return printe("Invalid argument, not a number");
}
if ( !strcmp(v12, "curr") )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v37 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v38 = sdp_set_curr(v81, v37);
if ( v38 < 0 )
return perror_("sdp_set_curr failed", v38);
goto LABEL_25;
}
return printe("Invalid argument, not a number");
}
if ( !strcmp(v12, "sovp") )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v39 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v40 = sdp_set_volt_limit(v81, v39);
if ( v40 < 0 )
return perror_("sdp_set_volt_limit failed", v40);
goto LABEL_25;
}
return printe("Invalid argument, not a number");
}
if ( !strcmp(v12, "sout") )
{
if ( v14 != 1 )
return printe("Invalid number of parameters");
v41 = *v13;
if ( !strcmp(v41, "on") || (v14 = strcmp(v41, "off")) == 0 )
{
v42 = sdp_set_output(v81, v14);
if ( v42 < 0 )
return perror_("sdp_set_output failed", v42);
goto LABEL_25;
}
return printe("Expected one of on/off");
}
if ( !strcmp(v12, "poww") )
{
if ( v14 != 2 )
return printe("Invalid number of parameters");
v43 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
return printe("Expected preset number");
v44 = argv[v7 + 3];
if ( !strcmp(v44, "on") )
{
v46 = 1LL;
}
else
{
v45 = strcmp(v44, "off");
v46 = v45;
if ( v45 )
return printe("Expected one of on/off");
}
v47 = sdp_set_poweron_output(v81, v43, v46);
if ( v47 < 0 )
return perror_("sdp_set_poweron_output failed", v47);
goto LABEL_25;
}
if ( !strcmp(v12, "prom") )
{
if ( v14 != 3 )
return printe("Invalid number of parameters");
v48 = strtol(*v13, &v61, 0);
if ( !**v13 || *v61 )
return printe("Expected preset number");
v63 = strtod(argv[v7 + 3], &v61);
if ( !*v61 )
{
if ( *argv[v7 + 3] )
{
endptr = COERCE_CHAR_(strtod(argv[v7 + 4], &v61));
if ( !*v61 )
{
if ( *argv[v7 + 4] )
{
v49 = sdp_set_preset(v81, v48, &endptr);
if ( v49 < 0 )
return perror_("sdp_set_preset failed", v49);
goto LABEL_25;
}
}
}
}
return printe("Invalid argument, not a number");
}
if ( strcmp(v12, "prop") )
{
if ( !strcmp(v12, "runm") )
{
if ( v14 == 1 )
{
v53 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
return printe("Invalid preset number");
v54 = sdp_run_preset(v81, v53);
if ( v54 < 0 )
return perror_("sdp_run_preset failed", v54);
goto LABEL_25;
}
}
else if ( !strcmp(v12, "runp") )
{
if ( v14 == 1 )
{
v55 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
{
v56 = strcmp(*v13, "inf");
v55 = v56;
if ( v56 )
return printe("Expected program number");
}
v57 = sdp_run_program(v81, v55);
if ( v57 < 0 )
return perror_("sdp_run_program failed", v57);
goto LABEL_25;
}
}
else
{
if ( strcmp(v12, "stop") )
{
print_help_short();
printe("Unknown command");
return -1;
}
if ( !v14 )
{
v58 = sdp_stop(v81);
if ( v58 < 0 )
return perror_("sdp_stop failed", v58);
goto LABEL_25;
}
}
return printe("Invalid number of parameters");
}
if ( v14 != 4 )
return printe("Invalid number of parameters");
v50 = strtol(*v13, &v61, 0);
if ( !**v13 || *v61 )
return printe("Expected program number");
v63 = strtod(argv[v7 + 3], &v61);
if ( *v61 )
return printe("Invalid argument, not a number");
if ( !*argv[v7 + 3] )
return printe("Invalid argument, not a number");
endptr = COERCE_CHAR_(strtod(argv[v7 + 4], &v61));
if ( *v61 || !*argv[v7 + 4] )
return printe("Invalid argument, not a number");
v51 = strtol(argv[v7 + 5], &v61, 0);
LODWORD(v64) = v51;
if ( *argv[v7 + 5] )
{
v52 = v61;
if ( !*v61 )
goto LABEL_231;
if ( *v61 != 58 )
return printe("Invalid time format");
}
else
{
v52 = v61;
if ( *v61 != 58 )
return printe("Invalid time format");
}
v61 = v52 + 1;
LODWORD(v64) = 60 * v51;
v59 = strtol(v52 + 1, &v61, 0);
LODWORD(v64) += v59;
if ( !*argv[v7 + 5] || *v61 )
return printe("Invalid time format");
LABEL_231:
v60 = sdp_set_program(v81, v50, &endptr);
if ( v60 < 0 )
return perror_("sdp_set_program failed", v60);
goto LABEL_25;
}
if ( v14 )
return printe("Invalid number of parameters");
v34 = sdp_get_lcd_info(v81, &endptr);
if ( v34 < 0 )
return perror_("sdp_get_lcd_info failed", v34);
if ( LOBYTE(v63) )
fprintf(v10, "U: %5.2f V\n", *(double *)&endptr);
else
fwrite("U: --.--\n", 1uLL, 9uLL, v10);
if ( v65 )
fprintf(v10, "I: %5.3f A\n", v64);
else
fwrite("I: -.---\n", 1uLL, 9uLL, v10);
if ( v67 )
fprintf(v10, "P: %5.2f W\n", v66);
else
fwrite("P: --.--\n", 1uLL, 9uLL, v10);
if ( v69 )
fprintf(v10, "t: %02i:%02i sec\n", (unsigned int)(v68 / 60), (unsigned int)(v68 % 60));
else
fwrite("t: --:--\n", 1uLL, 9uLL, v10);
if ( v72 )
{
if ( v71 )
fprintf(v10, "U set: %4.1f V (CV)\n", v70);
else
fprintf(v10, "U set: %4.1f V\n", v70);
}
else
{
fwrite("U set: --.-\n", 1uLL, 0xCuLL, v10);
}
if ( v75 )
{
if ( v74 )
fprintf(v10, "I set: %4.2f A (CC)\n", v73);
else
fprintf(v10, "I set: %4.2f A\n", v73);
}
else
{
fwrite("I set: -.--\n", 1uLL, 0xCuLL, v10);
}
if ( v76 )
fwrite("running program: yes\n", 1uLL, 0x15uLL, v10);
else
fwrite("running program: no\n", 1uLL, 0x14uLL, v10);
if ( v77 )
fwrite("keypad locked: yes\n", 1uLL, 0x13uLL, v10);
else
fwrite("keypad locked: no\n", 1uLL, 0x12uLL, v10);
if ( v78 )
fwrite("fault: >> YES <<\n", 1uLL, 0x11uLL, v10);
else
fwrite("fault: no\n", 1uLL, 0xAuLL, v10);
if ( v79 )
fwrite("output: on\n", 1uLL, 0xBuLL, v10);
else
fwrite("output: off\n", 1uLL, 0xCuLL, v10);
if ( v80 )
fwrite("remote: on\n", 1uLL, 0xBuLL, v10);
else
fwrite("remote: off\n", 1uLL, 0xCuLL, v10);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // er13
int result; // eax
const char *v6; // rbx
__int64 v7; // r14
const char *v8; // r15
signed int v9; // eax
FILE *v10; // r15
signed int v11; // eax
const char *v12; // r12
const char **v13; // rbp
unsigned int v14; // ebx
const char *v15; // rbx
__int64 v16; // rsi
signed int v17; // eax
signed int v18; // esi
signed int v19; // eax
signed int v20; // eax
signed int v21; // eax
signed int v22; // eax
signed int v23; // eax
int v24; // er13
const char *v25; // r12
__int64 v26; // rsi
signed int v27; // esi
double *v28; // rbp
int v29; // er13
const char *v30; // r12
__int64 v31; // rsi
signed int v32; // esi
char **v33; // rbp
signed int v34; // esi
double v35; // xmm0_8
signed int v36; // esi
double v37; // xmm0_8
signed int v38; // esi
double v39; // xmm0_8
signed int v40; // esi
const char *v41; // rbp
signed int v42; // esi
unsigned int v43; // ebx
const char *v44; // rbp
unsigned int v45; // eax
__int64 v46; // rdx
signed int v47; // esi
unsigned int v48; // ebx
signed int v49; // esi
unsigned int v50; // ebx
int v51; // edx
char *v52; // rax
__int64 v53; // rsi
signed int v54; // esi
__int64 v55; // rsi
unsigned int v56; // eax
signed int v57; // esi
signed int v58; // esi
int v59; // eax
signed int v60; // esi
char *v61; // [rsp+8h] [rbp-230h] BYREF
char *endptr; // [rsp+10h] [rbp-228h] BYREF
double v63; // [rsp+18h] [rbp-220h]
double v64; // [rsp+20h] [rbp-218h]
char v65; // [rsp+28h] [rbp-210h]
double v66; // [rsp+30h] [rbp-208h]
char v67; // [rsp+38h] [rbp-200h]
int v68; // [rsp+3Ch] [rbp-1FCh]
char v69; // [rsp+40h] [rbp-1F8h]
double v70; // [rsp+48h] [rbp-1F0h]
char v71; // [rsp+50h] [rbp-1E8h]
char v72; // [rsp+52h] [rbp-1E6h]
double v73; // [rsp+58h] [rbp-1E0h]
char v74; // [rsp+60h] [rbp-1D8h]
char v75; // [rsp+62h] [rbp-1D6h]
char v76; // [rsp+69h] [rbp-1CFh]
char v77; // [rsp+6Bh] [rbp-1CDh]
char v78; // [rsp+6Ch] [rbp-1CCh]
char v79; // [rsp+6Dh] [rbp-1CBh]
char v80; // [rsp+6Eh] [rbp-1CAh]
char v81[4]; // [rsp+1F4h] [rbp-44h] BYREF
int v82; // [rsp+1F8h] [rbp-40h]
int v83; // [rsp+1FCh] [rbp-3Ch]

if ( argc <= 1 )
{
func1();
return -1;
}
if ( argc == 2 )
{
v6 = argv[1];
if ( !strcmp(v6, "-h") || !strcmp(v6, "--help") )
{
func0();
return 0;
}
return func2("Invalid or missing argument");
}
if ( strcmp(argv[1], "-a") )
{
v4 = 1;
v3 = 1;
goto LABEL_16;
}
if ( argc <= 4 )
return func2("Invalid or missing argument");
v3 = strtol(argv[2], &endptr, 0);
if ( v3 - 1 > 0x1E )
return func2("Device address out of range");
v4 = 3;
if ( *endptr )
return func2("Device address out of range");
LABEL_16:
v7 = v4;
v8 = argv[v7];
if ( !strcmp(v8, "-") )
{
v9 = sdp_openf(v81, 0xFFFFFFFFLL, v3);
if ( v9 >= 0 )
{
v82 = 0;
v83 = 1;
v10 = stderr;
goto LABEL_19;
}
return func3("sdp_open failed", v9);
}
v9 = sdp_open(v81, v8, v3);
if ( v9 < 0 )
return func3("sdp_open failed", v9);
v10 = stdout;
LABEL_19:
v11 = sdp_remote(v81, 1LL);
if ( v11 < 0 )
return func3("Failed to switch to remote mode", v11);
v12 = argv[v7 + 1];
v13 = &argv[v7 + 2];
v14 = argc - (v4 + 2);
if ( !strcmp(v12, "ccom") )
{
if ( v14 == 1 )
{
v15 = *v13;
if ( !strcmp(*v13, "rs232") )
{
v16 = 0LL;
}
else
{
v16 = 1LL;
if ( strcmp(v15, "rs485") )
return func2("Invalid argument");
}
v17 = sdp_select_ifce(v81, v16);
if ( v17 < 0 )
return func3("sdp_select_ifce failed", v17);
goto LABEL_25;
}
return func2("Invalid number of parameters");
}
if ( !strcmp(v12, "gcom") )
{
if ( !v14 )
{
v19 = sdp_get_dev_addr(v81);
if ( v19 < 0 )
return func3("sdp_get_dev_addr failed", v19);
fprintf(v10, "%i\n", (unsigned int)v19);
goto LABEL_25;
}
return func2("Invalid number of parameters");
}
if ( !strcmp(v12, "gmax") )
{
if ( v14 )
return func2("Invalid number of parameters");
v20 = sdp_get_va_maximums(v81, &endptr);
if ( v20 < 0 )
return func3("sdp_get_va_maximums failed", v20);
LABEL_45:
fprintf(v10, "%2.1f %1.2f\n", v63, *(double *)&endptr);
LABEL_25:
v18 = sdp_remote(v81, 0LL);
result = 0;
if ( v18 < 0 )
result = func3("Failed to disable remote mode", v18);
return result;
}
if ( !strcmp(v12, "govp") )
{
if ( !v14 )
{
v21 = sdp_get_volt_limit(v81, &endptr);
if ( v21 < 0 )
return func3("sdp_get_volt_limit failed", v21);
fprintf(v10, "%2.1f\n", *(double *)&endptr);
goto LABEL_25;
}
return func2("Invalid number of parameters");
}
if ( !strcmp(v12, "getd") )
{
if ( !v14 )
{
v22 = sdp_get_va_data(v81, &endptr);
if ( v22 < 0 )
return func3("sdp_get_va_data failed", v22);
if ( LODWORD(v64) == 1 )
fprintf(v10, "%2.2f %1.3f CC\n", v63, *(double *)&endptr);
else
fprintf(v10, "%2.2f %1.3f CV\n", v63, *(double *)&endptr);
goto LABEL_25;
}
return func2("Invalid number of parameters");
}
if ( !strcmp(v12, "gets") )
{
if ( v14 )
return func2("Invalid number of parameters");
v23 = sdp_get_va_setpoint(v81, &endptr);
if ( v23 < 0 )
return func3("sdp_get_va_setpoint failed", v23);
goto LABEL_45;
}
v24 = strcmp(v12, "getm");
if ( !v24 )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v25 = *v13;
if ( !strcmp(*v13, "all") )
{
v14 = 9;
v26 = 10LL;
}
else
{
v26 = strtol(v25, &v61, 0);
if ( !**v13 || *v61 )
return func2("Invalid preset number");
}
v27 = sdp_get_preset(v81, v26, &endptr);
v28 = (double *)&endptr;
if ( v27 < 0 )
return func3("sdp_get_preset failed", v27);
do
{
fprintf(v10, "%2.1f %1.2f\n", v28[1], *v28);
++v24;
v28 += 2;
}
while ( v14 != v24 );
goto LABEL_25;
}
v29 = strcmp(v12, "getp");
if ( !v29 )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v30 = *v13;
if ( !strcmp(*v13, "all") )
{
v14 = 20;
v31 = 20LL;
}
else
{
v31 = strtol(v30, &v61, 0);
if ( !**v13 || *v61 )
return func2("Invalid preset number");
}
v32 = sdp_get_program(v81, v31, &endptr);
v33 = &endptr;
if ( v32 < 0 )
return func3("sdp_get_program failed", v32);
do
{
fprintf(
v10,
"%2.1f %1.2f %02i:%02i\n",
*((double *)v33 + 1),
*(double *)v33,
(unsigned int)(*((_DWORD *)v33 + 4) / 60),
(unsigned int)(*((_DWORD *)v33 + 4) % 60));
++v29;
v33 += 3;
}
while ( v14 != v29 );
goto LABEL_25;
}
if ( strcmp(v12, "gpal") )
{
if ( !strcmp(v12, "volt") )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v35 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v36 = sdp_set_volt(v81, v35);
if ( v36 < 0 )
return func3("sdp_set_volt failed", v36);
goto LABEL_25;
}
return func2("Invalid argument, not a number");
}
if ( !strcmp(v12, "curr") )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v37 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v38 = sdp_set_curr(v81, v37);
if ( v38 < 0 )
return func3("sdp_set_curr failed", v38);
goto LABEL_25;
}
return func2("Invalid argument, not a number");
}
if ( !strcmp(v12, "sovp") )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v39 = strtod(*v13, &endptr);
if ( !*endptr && **v13 )
{
v40 = sdp_set_volt_limit(v81, v39);
if ( v40 < 0 )
return func3("sdp_set_volt_limit failed", v40);
goto LABEL_25;
}
return func2("Invalid argument, not a number");
}
if ( !strcmp(v12, "sout") )
{
if ( v14 != 1 )
return func2("Invalid number of parameters");
v41 = *v13;
if ( !strcmp(v41, "on") || (v14 = strcmp(v41, "off")) == 0 )
{
v42 = sdp_set_output(v81, v14);
if ( v42 < 0 )
return func3("sdp_set_output failed", v42);
goto LABEL_25;
}
return func2("Expected one of on/off");
}
if ( !strcmp(v12, "poww") )
{
if ( v14 != 2 )
return func2("Invalid number of parameters");
v43 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
return func2("Expected preset number");
v44 = argv[v7 + 3];
if ( !strcmp(v44, "on") )
{
v46 = 1LL;
}
else
{
v45 = strcmp(v44, "off");
v46 = v45;
if ( v45 )
return func2("Expected one of on/off");
}
v47 = sdp_set_poweron_output(v81, v43, v46);
if ( v47 < 0 )
return func3("sdp_set_poweron_output failed", v47);
goto LABEL_25;
}
if ( !strcmp(v12, "prom") )
{
if ( v14 != 3 )
return func2("Invalid number of parameters");
v48 = strtol(*v13, &v61, 0);
if ( !**v13 || *v61 )
return func2("Expected preset number");
v63 = strtod(argv[v7 + 3], &v61);
if ( !*v61 )
{
if ( *argv[v7 + 3] )
{
endptr = COERCE_CHAR_(strtod(argv[v7 + 4], &v61));
if ( !*v61 )
{
if ( *argv[v7 + 4] )
{
v49 = sdp_set_preset(v81, v48, &endptr);
if ( v49 < 0 )
return func3("sdp_set_preset failed", v49);
goto LABEL_25;
}
}
}
}
return func2("Invalid argument, not a number");
}
if ( strcmp(v12, "prop") )
{
if ( !strcmp(v12, "runm") )
{
if ( v14 == 1 )
{
v53 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
return func2("Invalid preset number");
v54 = sdp_run_preset(v81, v53);
if ( v54 < 0 )
return func3("sdp_run_preset failed", v54);
goto LABEL_25;
}
}
else if ( !strcmp(v12, "runp") )
{
if ( v14 == 1 )
{
v55 = strtol(*v13, &endptr, 0);
if ( !**v13 || *endptr )
{
v56 = strcmp(*v13, "inf");
v55 = v56;
if ( v56 )
return func2("Expected program number");
}
v57 = sdp_run_program(v81, v55);
if ( v57 < 0 )
return func3("sdp_run_program failed", v57);
goto LABEL_25;
}
}
else
{
if ( strcmp(v12, "stop") )
{
func1();
func2("Unknown command");
return -1;
}
if ( !v14 )
{
v58 = sdp_stop(v81);
if ( v58 < 0 )
return func3("sdp_stop failed", v58);
goto LABEL_25;
}
}
return func2("Invalid number of parameters");
}
if ( v14 != 4 )
return func2("Invalid number of parameters");
v50 = strtol(*v13, &v61, 0);
if ( !**v13 || *v61 )
return func2("Expected program number");
v63 = strtod(argv[v7 + 3], &v61);
if ( *v61 )
return func2("Invalid argument, not a number");
if ( !*argv[v7 + 3] )
return func2("Invalid argument, not a number");
endptr = COERCE_CHAR_(strtod(argv[v7 + 4], &v61));
if ( *v61 || !*argv[v7 + 4] )
return func2("Invalid argument, not a number");
v51 = strtol(argv[v7 + 5], &v61, 0);
LODWORD(v64) = v51;
if ( *argv[v7 + 5] )
{
v52 = v61;
if ( !*v61 )
goto LABEL_231;
if ( *v61 != 58 )
return func2("Invalid time format");
}
else
{
v52 = v61;
if ( *v61 != 58 )
return func2("Invalid time format");
}
v61 = v52 + 1;
LODWORD(v64) = 60 * v51;
v59 = strtol(v52 + 1, &v61, 0);
LODWORD(v64) += v59;
if ( !*argv[v7 + 5] || *v61 )
return func2("Invalid time format");
LABEL_231:
v60 = sdp_set_program(v81, v50, &endptr);
if ( v60 < 0 )
return func3("sdp_set_program failed", v60);
goto LABEL_25;
}
if ( v14 )
return func2("Invalid number of parameters");
v34 = sdp_get_lcd_info(v81, &endptr);
if ( v34 < 0 )
return func3("sdp_get_lcd_info failed", v34);
if ( LOBYTE(v63) )
fprintf(v10, "U: %5.2f V\n", *(double *)&endptr);
else
fwrite("U: --.--\n", 1uLL, 9uLL, v10);
if ( v65 )
fprintf(v10, "I: %5.3f A\n", v64);
else
fwrite("I: -.---\n", 1uLL, 9uLL, v10);
if ( v67 )
fprintf(v10, "P: %5.2f W\n", v66);
else
fwrite("P: --.--\n", 1uLL, 9uLL, v10);
if ( v69 )
fprintf(v10, "t: %02i:%02i sec\n", (unsigned int)(v68 / 60), (unsigned int)(v68 % 60));
else
fwrite("t: --:--\n", 1uLL, 9uLL, v10);
if ( v72 )
{
if ( v71 )
fprintf(v10, "U set: %4.1f V (CV)\n", v70);
else
fprintf(v10, "U set: %4.1f V\n", v70);
}
else
{
fwrite("U set: --.-\n", 1uLL, 0xCuLL, v10);
}
if ( v75 )
{
if ( v74 )
fprintf(v10, "I set: %4.2f A (CC)\n", v73);
else
fprintf(v10, "I set: %4.2f A\n", v73);
}
else
{
fwrite("I set: -.--\n", 1uLL, 0xCuLL, v10);
}
if ( v76 )
fwrite("running program: yes\n", 1uLL, 0x15uLL, v10);
else
fwrite("running program: no\n", 1uLL, 0x14uLL, v10);
if ( v77 )
fwrite("keypad locked: yes\n", 1uLL, 0x13uLL, v10);
else
fwrite("keypad locked: no\n", 1uLL, 0x12uLL, v10);
if ( v78 )
fwrite("fault: >> YES <<\n", 1uLL, 0x11uLL, v10);
else
fwrite("fault: no\n", 1uLL, 0xAuLL, v10);
if ( v79 )
fwrite("output: on\n", 1uLL, 0xBuLL, v10);
else
fwrite("output: off\n", 1uLL, 0xCuLL, v10);
if ( v80 )
fwrite("remote: on\n", 1uLL, 0xBuLL, v10);
else
fwrite("remote: off\n", 1uLL, 0xCuLL, v10);
return -1;
}

original_code:
int main()
{
        sdp_t sdp;
        if (sdp_open(&sdp, filename, 1) == -1) {
                perror("Failed to open serial port connected to SDP");
                return -1;
        }
        if (sdp_remote(&sdp, 1) == -1) {
                perror("Could not start remote control");
                return -1;
        }
        sdp_set_volt(&sdp, 1.5);
        sdp_set_curr(&sdp, 0.05);
        sdp_set_output(&sdp, 1);
        sdp_close(&sdp);
        return 0;
}

canonical_original_code:
int main()
{
        struct sdp_t sdp;
        if (sdp_open(&sdp, filename, 1) == -1) {
                perror("Failed to open serial port connected to SDP");
                return -1;
        }
        if (sdp_remote(&sdp, 1) == -1) {
                perror("Could not start remote control");
                return -1;
        }
        sdp_set_volt(&sdp, 1.5);
        sdp_set_curr(&sdp, 0.05);
        sdp_set_output(&sdp, 1);
        sdp_close(&sdp);
        return 0;
}

variable_types: struct sdp_t { unsigned char addr; int f_in; int f_out; }


repo: pippijn/reflect

decompiled_code:
__int64 __fastcall elem_free(_QWORD *a1)
{
mem_free(*a1, 8LL * a1[3]);
return mem_free(a1, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
mem_free(*a1, 8LL * a1[3]);
return mem_free(a1, 32LL);
}

original_code:
static void
elem_free (struct elem *e)
{
  mem_free (e->data, e->max * sizeof (void *));
  mem_free (e, sizeof (struct elem));
  return;
}

canonical_original_code:
static void elem_free(struct elem *e)
{
  mem_free (e->data, e->max * sizeof (void *));
  mem_free (e, sizeof (struct elem));
  return;
}

variable_types: struct elem { void **data; struct elem *prev; unsigned long size; unsigned long max; } *


original_code:
fast_stack *
fast_stack_new (void)
{
  fast_stack *self = mem_alloc (sizeof (fast_stack));
  self->last = elem_new (1);
  self->max = 1;
  self->size = 0;
  self->packed = 1;
  return self;
}

canonical_original_code:
struct fast_stack *fast_stack_new()
{
  struct fast_stack *self = mem_alloc (sizeof (fast_stack));
  self->last = elem_new (1);
  self->max = 1;
  self->size = 0;
  self->packed = 1;
  return self;
}

variable_types: struct fast_stack { struct elem { void **data; struct elem *prev; unsigned long size; unsigned long max; } *last; unsigned long size; unsigned long max; _Bool packed; } *

user_defined_types: struct fast_stack { struct elem *last; unsigned long size; unsigned long max; _Bool packed; }


decompiled_code:
__int64 __fastcall fast_stack_delete(_QWORD *a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x30u, "fast_stack_delete");
v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
elem_free(v3);
}
while ( v2 );
}
return mem_free(a1, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x30u, "fast_stack_delete");
v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
func0(v3);
}
while ( v2 );
}
return mem_free(a1, 32LL);
}

original_code:
void
fast_stack_delete (fast_stack *self)
{
  struct elem *rm, *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 48, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  while (e)
    {
      rm = e;
      e = e->prev;
      elem_free (rm);
    }
  mem_free (self, sizeof (fast_stack));
}

canonical_original_code:
void fast_stack_delete(struct fast_stack *self)
{
  struct elem *rm; struct elem *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 48, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  while (e)
    {
      rm = e;
      e = e->prev;
      elem_free (rm);
    }
  mem_free (self, sizeof (fast_stack));
}

user_defined_types: struct elem { void **data; struct elem *prev; unsigned long size; unsigned long max; }


decompiled_code:
__int64 __fastcall fast_stack_pop(__int64 a1)
{
__int64 v2; // rax
_QWORD *v3; // rdi
__int64 v4; // rax
__int64 v5; // rbp

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x66u, "fast_stack_pop");
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
_assert_fail("self->size > 0", "layer0/src/stack/fast.c", 0x67u, "fast_stack_pop");
v3 = *(_QWORD **)a1;
*(_QWORD *)(a1 + 8) = v2 - 1;
v4 = v3[2] - 1LL;
v3[2] = v4;
v5 = *(_QWORD *)(*v3 + 8 * v4);
if ( !v4 )
{
*(_QWORD *)a1 = v3[1];
elem_free(v3);
*(_BYTE *)(a1 + 24) = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rax
_QWORD *v3; // rdi
__int64 v4; // rax
__int64 v5; // rbp

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x66u, "fast_stack_pop");
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
_assert_fail("self->size > 0", "layer0/src/stack/fast.c", 0x67u, "fast_stack_pop");
v3 = *(_QWORD **)a1;
*(_QWORD *)(a1 + 8) = v2 - 1;
v4 = v3[2] - 1LL;
v3[2] = v4;
v5 = *(_QWORD *)(*v3 + 8 * v4);
if ( !v4 )
{
*(_QWORD *)a1 = v3[1];
func0(v3);
*(_BYTE *)(a1 + 24) = 0;
}
return v5;
}

original_code:
void *
fast_stack_pop (fast_stack *self)
{
  void *ret;
  struct elem *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/fast.c", 103, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  self->size--;
  e->size--;
  ret = e->data[e->size];
  if (!e->size)
    {
      self->last = e->prev;
      elem_free (e);
      self->packed = 0;
    }
  return ret;
}

canonical_original_code:
void *fast_stack_pop(struct fast_stack *self)
{
  void *ret;
  struct elem *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/fast.c", 103, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  self->size--;
  e->size--;
  ret = e->data[e->size];
  if (!e->size)
    {
      self->last = e->prev;
      elem_free (e);
      self->packed = 0;
    }
  return ret;
}

variable_types:
ret
void *

return_type: void *


decompiled_code:
__int64 __fastcall fast_stack_top(_QWORD *a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x82u, "fast_stack_top");
if ( !a1[1] )
_assert_fail("self->size > 0", "layer0/src/stack/fast.c", 0x83u, "fast_stack_top");
return *(_QWORD *)(*(_QWORD *)*a1 + 8LL * *(_QWORD *)(*a1 + 16LL) - 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x82u, "fast_stack_top");
if ( !a1[1] )
_assert_fail("self->size > 0", "layer0/src/stack/fast.c", 0x83u, "fast_stack_top");
return *(_QWORD *)(*(_QWORD *)*a1 + 8LL * *(_QWORD *)(*a1 + 16LL) - 8);
}

original_code:
void *
fast_stack_top (fast_stack const *self)
{
  struct elem *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 130, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/fast.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  return e->data[e->size - 1];
}

canonical_original_code:
void *fast_stack_top(struct fast_stack *self)
{
  struct elem *e;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 130, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/fast.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  return e->data[e->size - 1];
}


decompiled_code:
__int64 __fastcall fast_stack_size(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x8Du, "fast_stack_size");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x8Du, "fast_stack_size");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t
fast_stack_size (fast_stack const *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 141, __extension__ __PRETTY_FUNCTION__); }));
  return self->size;
}

canonical_original_code:
unsigned long fast_stack_size(struct fast_stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 141, __extension__ __PRETTY_FUNCTION__); }));
  return self->size;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall fast_stack_get(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v4; // r9
unsigned __int64 v5; // r8
_QWORD *v6; // rax
unsigned __int64 v7; // rcx
_QWORD *v8; // rsi

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x9Au, "fast_stack_get");
v4 = a1[1];
if ( v4 <= a2 )
_assert_fail("index < self->size", "layer0/src/stack/fast.c", 0x9Bu, "fast_stack_get");
v5 = v4 - a2;
v6 = (_QWORD *)*a1;
v7 = 0LL;
do
{
v8 = v6;
v6 = (_QWORD *)v6[1];
v7 += v8[2];
}
while ( v5 > v7 );
return *(_QWORD *)(*v8 + 8 * (a2 - v4 + v7));
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v4; // r9
unsigned __int64 v5; // r8
_QWORD *v6; // rax
unsigned __int64 v7; // rcx
_QWORD *v8; // rsi

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0x9Au, "fast_stack_get");
v4 = a1[1];
if ( v4 <= a2 )
_assert_fail("index < self->size", "layer0/src/stack/fast.c", 0x9Bu, "fast_stack_get");
v5 = v4 - a2;
v6 = (_QWORD *)*a1;
v7 = 0LL;
do
{
v8 = v6;
v6 = (_QWORD *)v6[1];
v7 += v8[2];
}
while ( v5 > v7 );
return *(_QWORD *)(*v8 + 8 * (a2 - v4 + v7));
}

original_code:
void *
fast_stack_get (fast_stack const *self, size_t index)
{
  struct elem *e, *pr;
  size_t i, rindex;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((index < self->size) ? 1 : 0), __extension__ ({ if (index < self->size) ; else __assert_fail ("index < self->size", "layer0/src/stack/fast.c", 155, __extension__ __PRETTY_FUNCTION__); }));
  rindex = self->size - index;
  ((void) sizeof ((rindex > 0) ? 1 : 0), __extension__ ({ if (rindex > 0) ; else __assert_fail ("rindex > 0", "layer0/src/stack/fast.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  for (i = 0; i < rindex; i += pr->size)
    {
      pr = e;
      e = e->prev;
    }
  return pr->data[i - rindex];
}

canonical_original_code:
void *fast_stack_get(struct fast_stack *self, unsigned long index)
{
  struct elem *e; struct elem *pr;
  unsigned long i; unsigned long rindex;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((index < self->size) ? 1 : 0), __extension__ ({ if (index < self->size) ; else __assert_fail ("index < self->size", "layer0/src/stack/fast.c", 155, __extension__ __PRETTY_FUNCTION__); }));
  rindex = self->size - index;
  ((void) sizeof ((rindex > 0) ? 1 : 0), __extension__ ({ if (rindex > 0) ; else __assert_fail ("rindex > 0", "layer0/src/stack/fast.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  e = self->last;
  for (i = 0; i < rindex; i += pr->size)
    {
      pr = e;
      e = e->prev;
    }
  return pr->data[i - rindex];
}

variable_types:
index
unsigned long

variable_types:
i
unsigned long

variable_types:
rindex
unsigned long


decompiled_code:
__int64 __fastcall fast_stack_set(_QWORD *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v6; // r10
__int64 v7; // rdx
unsigned __int64 v8; // r8
_QWORD *v9; // rax
unsigned __int64 v10; // rcx
_QWORD *v11; // rsi
__int64 *v12; // rax

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0xB1u, "fast_stack_set");
v6 = a1[1];
v7 = 0LL;
if ( v6 > a2 )
{
v8 = v6 - a2;
v9 = (_QWORD *)*a1;
v10 = 0LL;
do
{
v11 = v9;
v9 = (_QWORD *)v9[1];
v10 += v11[2];
}
while ( v8 > v10 );
v12 = (__int64 *)(*v11 + 8 * (a2 - v6 + v10));
v7 = *v12;
*v12 = a3;
}
return v7;
}

original_code:
void *
fast_stack_set (fast_stack *self, size_t index, void *data)
{
  void *ret;
  struct elem *e, *pr;
  size_t i, rindex;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  if (index >= self->size)
    {
      ret = ((void *)0);
    }
  else
    {
      rindex = self->size - index;
      ((void) sizeof ((rindex > 0) ? 1 : 0), __extension__ ({ if (rindex > 0) ; else __assert_fail ("rindex > 0", "layer0/src/stack/fast.c", 189, __extension__ __PRETTY_FUNCTION__); }));
      e = self->last;
      for (i = 0; i < rindex; i += pr->size)
        {
          pr = e;
          e = e->prev;
        }
      ret = pr->data[i - rindex];
      pr->data[i - rindex] = data;
    }
  return ret;
}

canonical_original_code:
void *fast_stack_set(struct fast_stack *self, unsigned long index, void *data)
{
  void *ret;
  struct elem *e; struct elem *pr;
  unsigned long i; unsigned long rindex;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  if (index >= self->size)
    {
      ret = ((void *)0);
    }
  else
    {
      rindex = self->size - index;
      ((void) sizeof ((rindex > 0) ? 1 : 0), __extension__ ({ if (rindex > 0) ; else __assert_fail ("rindex > 0", "layer0/src/stack/fast.c", 189, __extension__ __PRETTY_FUNCTION__); }));
      e = self->last;
      for (i = 0; i < rindex; i += pr->size)
        {
          pr = e;
          e = e->prev;
        }
      ret = pr->data[i - rindex];
      pr->data[i - rindex] = data;
    }
  return ret;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall fast_stack_raw(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0xD0u, "fast_stack_raw");
if ( !*(_QWORD *)(a1 + 8) )
return 0LL;
if ( !*(_BYTE *)(a1 + 24) )
stack_repack((__int64 *)a1);
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/fast.c", 0xD0u, "fast_stack_raw");
if ( !*(_QWORD *)(a1 + 8) )
return 0LL;
if ( !*(_BYTE *)(a1 + 24) )
func1((__int64 *)a1);
return **(_QWORD **)a1;
}

original_code:
void *const *
fast_stack_raw (fast_stack *const self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 208, __extension__ __PRETTY_FUNCTION__); }));
  if (self->size == 0)
    return ((void *)0);
  if (!self->packed)
    stack_repack (self);
  return self->last->data;
}

canonical_original_code:
void **fast_stack_raw(struct fast_stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/fast.c", 208, __extension__ __PRETTY_FUNCTION__); }));
  if (self->size == 0)
    return ((void *)0);
  if (!self->packed)
    stack_repack (self);
  return self->last->data;
}

return_type: void **


decompiled_code:
_QWORD *stack_new()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)mem_alloc(24LL);
*v0 = mem_alloc(8LL);
v0[2] = 1LL;
v0[1] = 0LL;
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)mem_alloc(24LL);
*v0 = mem_alloc(8LL);
v0[2] = 1LL;
v0[1] = 0LL;
return v0;
}

original_code:
stack *
stack_new (void)
{
  stack *self = mem_alloc (sizeof (stack));
  self->data = mem_alloc (sizeof (void *));
  self->max = 1;
  self->size = 0;
  return self;
}

canonical_original_code:
struct stack *stack_new()
{
  struct stack *self = mem_alloc (sizeof (stack));
  self->data = mem_alloc (sizeof (void *));
  self->max = 1;
  self->size = 0;
  return self;
}

variable_types: struct stack { void **data; unsigned long size; unsigned long max; } *


decompiled_code:
__int64 __fastcall stack_delete(_QWORD *a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x21u, "stack_delete");
mem_free(*a1, 8LL * a1[2]);
return mem_free(a1, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x21u, "stack_delete");
mem_free(*a1, 8LL * a1[2]);
return mem_free(a1, 24LL);
}

original_code:
void
stack_delete (stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  mem_free (self->data, self->max * sizeof (void *));
  mem_free (self, sizeof (stack));
}

canonical_original_code:
void stack_delete(struct stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  mem_free (self->data, self->max * sizeof (void *));
  mem_free (self, sizeof (stack));
}

user_defined_types: struct stack { void **data; unsigned long size; unsigned long max; }


decompiled_code:
__int64 __fastcall stack_pop(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x40u, "stack_pop");
v1 = a1[1];
if ( !v1 )
_assert_fail("self->size > 0", "layer0/src/stack/array.c", 0x41u, "stack_pop");
v2 = v1 - 1;
a1[1] = v2;
return *(_QWORD *)(*a1 + 8 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x40u, "stack_pop");
v1 = a1[1];
if ( !v1 )
_assert_fail("self->size > 0", "layer0/src/stack/array.c", 0x41u, "stack_pop");
v2 = v1 - 1;
a1[1] = v2;
return *(_QWORD *)(*a1 + 8 * v2);
}

original_code:
void *
stack_pop (stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/array.c", 65, __extension__ __PRETTY_FUNCTION__); }));
  self->size--;
  return self->data[self->size];
}

canonical_original_code:
void *stack_pop(struct stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/array.c", 65, __extension__ __PRETTY_FUNCTION__); }));
  self->size--;
  return self->data[self->size];
}


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

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x53u, "stack_top");
v1 = a1[1];
if ( !v1 )
_assert_fail("self->size > 0", "layer0/src/stack/array.c", 0x54u, "stack_top");
return *(_QWORD *)(*a1 + 8 * v1 - 8);
}

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

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x53u, "stack_top");
v1 = a1[1];
if ( !v1 )
_assert_fail("self->size > 0", "layer0/src/stack/array.c", 0x54u, "stack_top");
return *(_QWORD *)(*a1 + 8 * v1 - 8);
}

original_code:
void *
stack_top (stack const *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/array.c", 84, __extension__ __PRETTY_FUNCTION__); }));
  return self->data[self->size - 1];
}

canonical_original_code:
void *stack_top(struct stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((self->size > 0) ? 1 : 0), __extension__ ({ if (self->size > 0) ; else __assert_fail ("self->size > 0", "layer0/src/stack/array.c", 84, __extension__ __PRETTY_FUNCTION__); }));
  return self->data[self->size - 1];
}


decompiled_code:
__int64 __fastcall stack_size(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x5Cu, "stack_size");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x5Cu, "stack_size");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t
stack_size (stack const *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  return self->size;
}

canonical_original_code:
unsigned long stack_size(struct stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  return self->size;
}


decompiled_code:
__int64 __fastcall stack_get(_QWORD *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x66u, "stack_get");
if ( a1[1] <= a2 )
_assert_fail("index < self->size", "layer0/src/stack/array.c", 0x67u, "stack_get");
return *(_QWORD *)(*a1 + 8 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x66u, "stack_get");
if ( a1[1] <= a2 )
_assert_fail("index < self->size", "layer0/src/stack/array.c", 0x67u, "stack_get");
return *(_QWORD *)(*a1 + 8 * a2);
}

original_code:
void *
stack_get (stack const *self, size_t index)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((index < self->size) ? 1 : 0), __extension__ ({ if (index < self->size) ; else __assert_fail ("index < self->size", "layer0/src/stack/array.c", 103, __extension__ __PRETTY_FUNCTION__); }));
  return self->data[index];
}

canonical_original_code:
void *stack_get(struct stack *self, unsigned long index)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((index < self->size) ? 1 : 0), __extension__ ({ if (index < self->size) ; else __assert_fail ("index < self->size", "layer0/src/stack/array.c", 103, __extension__ __PRETTY_FUNCTION__); }));
  return self->data[index];
}


decompiled_code:
__int64 __fastcall stack_set(_QWORD *a1, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 *v4; // rcx

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x71u, "stack_set");
result = 0LL;
if ( a1[1] > a2 )
{
v4 = (__int64 *)(*a1 + 8 * a2);
result = *v4;
*v4 = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 *v4; // rcx

if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x71u, "stack_set");
result = 0LL;
if ( a1[1] > a2 )
{
v4 = (__int64 *)(*a1 + 8 * a2);
result = *v4;
*v4 = a3;
}
return result;
}

original_code:
void *
stack_set (stack *self, size_t index, void *data)
{
  void *ret;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  if (index >= self->size)
    {
      ret = ((void *)0);
    }
  else
    {
      ret = self->data[index];
      self->data[index] = data;
    }
  return ret;
}

canonical_original_code:
void *stack_set(struct stack *self, unsigned long index, void *data)
{
  void *ret;
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  if (index >= self->size)
    {
      ret = ((void *)0);
    }
  else
    {
      ret = self->data[index];
      self->data[index] = data;
    }
  return ret;
}


decompiled_code:
__int64 __fastcall stack_raw(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x86u, "stack_raw");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
if ( !a1 )
_assert_fail("self != NULL", "layer0/src/stack/array.c", 0x86u, "stack_raw");
return *(_QWORD *)a1;
}

original_code:
void *const *
stack_raw (stack *const self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  return self->data;
}

canonical_original_code:
void **stack_raw(struct stack *self)
{
  ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "layer0/src/stack/array.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  return self->data;
}


original_code:
static void
init_chars (void)
{
  unsigned char c;
  static _Bool initialised = 0;
  if (initialised)
    return;
  for (c = 0; c < (0x7f * 2 + 1); c++)
    {
      int i = 0;
      chars[c][i++] = '\'';
      if (c == '\\' || c == '\'')
        chars[c][i++] = '\\';
      chars[c][i++] = c;
      chars[c][i++] = '\'';
    }
  initialised = 1;
}

canonical_original_code:
static void init_chars()
{
  unsigned char c;
  static _Bool initialised = 0;
  if (initialised)
    return;
  for (c = 0; c < (0x7f * 2 + 1); c++)
    {
      int i = 0;
      chars[c][i++] = '\'';
      if (c == '\\' || c == '\'')
        chars[c][i++] = '\\';
      chars[c][i++] = c;
      chars[c][i++] = '\'';
    }
  initialised = 1;
}

variable_types:
c
unsigned char

variable_types: i int


strcmp

decompiled_code:
__int64 __fastcall strcmp(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 i; // al
unsigned int v3; // edx

for ( i = *a1; *a1; i = *a1 )
{
if ( *a2 != i )
break;
++a1;
++a2;
}
v3 = -1;
if ( *a2 <= i )
v3 = *a2 < i;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 i; // al
unsigned int v3; // edx

for ( i = *a1; *a1; i = *a1 )
{
if ( *a2 != i )
break;
++a1;
++a2;
}
v3 = -1;
if ( *a2 <= i )
v3 = *a2 < i;
return v3;
}

original_code:
int
(strcmp) (char const *s1, char const *s2)
{
  unsigned char uc1, uc2;
  while (*s1 != '\0' && *s1 == *s2)
    {
      s1++;
      s2++;
    }
  uc1 = *(unsigned char const *)s1;
  uc2 = *(unsigned char const *)s2;
  return uc1 < uc2 ? -1 : uc1 > uc2;
}

canonical_original_code:
int strcmp(char *s1, char *s2)
{
  unsigned char uc1; unsigned char uc2;
  while (*s1 != '\0' && *s1 == *s2)
    {
      s1++;
      s2++;
    }
  uc1 = *(unsigned char *)s1;
  uc2 = *(unsigned char *)s2;
  return uc1 < uc2 ? -1 : uc1 > uc2;
}


strncpy

decompiled_code:
__int64 __fastcall strncpy(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rax
char v5; // dl
_BYTE *v6; // rax
_BYTE *v7; // rcx

v4 = 0LL;
if ( a3 )
{
while ( 1 )
{
v5 = *(_BYTE *)(a2 + v4);
if ( !v5 )
break;
*(_BYTE *)(a1 + v4++) = v5;
if ( a3 == v4 )
return a1;
}
if ( a3 > v4 )
{
v6 = (_BYTE *)(a1 + v4);
v7 = (_BYTE *)(a1 + a3);
do
*v6++ = 0;
while ( v6 != v7 );
}
}
return a1;
}

original_code:
char *
(strncpy) (char *dest, const char *src, size_t n)
{
  size_t i;
  for (i = 0; i < n && src[i] != '\0'; i++)
    dest[i] = src[i];
  for (; i < n; i++)
    dest[i] = '\0';
  return dest;
}

canonical_original_code:
char *strncpy(char *dest, char *src, unsigned long n)
{
  unsigned long i;
  for (i = 0; i < n && src[i] != '\0'; i++)
    dest[i] = src[i];
  for (; i < n; i++)
    dest[i] = '\0';
  return dest;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long

return_type: char *


repo: piratfm/eti-tools

decompiled_code:
__int64 __fastcall read_16b(unsigned __int8 *a1)
{
return (*a1 << 8) | (unsigned int)a1[1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return (*a1 << 8) | (unsigned int)a1[1];
}

original_code:
static inline uint16_t read_16b(const uint8_t *buf){
    uint16_t value = ((uint16_t)buf[0]) << 8 | buf[1];
    return value;
}

canonical_original_code:
static inline unsigned short read_16b(unsigned char *buf){
    unsigned short value = ((uint16_t)buf[0]) << 8 | buf[1];
    return value;
}

variable_types:
buf
unsigned char *

variable_types:
value
unsigned short

return_type: unsigned short


original_code:
static inline uint32_t read_24b(const uint8_t *buf){
    uint32_t value = ((uint32_t) buf[0]) << 16 | ((uint16_t)buf[1]) << 8 | buf[2];
    return value;
}

canonical_original_code:
static inline unsigned int read_24b(unsigned char *buf){
    unsigned int value = ((uint32_t) buf[0]) << 16 | ((uint16_t)buf[1]) << 8 | buf[2];
    return value;
}

variable_types:
value
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall read_32b(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

original_code:
static inline uint32_t read_32b(const uint8_t *buf){
    uint32_t value = ((uint32_t)buf[0]) << 24 | ((uint32_t)buf[1]) << 16 | ((uint16_t)buf[2]) << 8 | buf[3];
    return value;
}

canonical_original_code:
static inline unsigned int read_32b(unsigned char *buf){
    unsigned int value = ((uint32_t)buf[0]) << 24 | ((uint32_t)buf[1]) << 16 | ((uint16_t)buf[2]) << 8 | buf[3];
    return value;
}


decompiled_code:
__int64 __fastcall decode_starptr(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // er12
unsigned __int16 v4; // r13
__int64 result; // rax

if ( a3 == 8 )
{
v3 = read_32b((unsigned int *)a2);
v4 = read_16b((unsigned __int8 *)(a2 + 4));
*(_BYTE *)(a1 + 432) = (v3 == 1145394249) & (((unsigned __int16)read_16b((unsigned __int8 *)(a2 + 6)) | v4) == 0);
result = 1LL;
}
else
{
msg_Log("EDI: Incorrect length %02x for *PTR", a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // er12
unsigned __int16 v4; // r13
__int64 result; // rax

if ( a3 == 8 )
{
v3 = func2((unsigned int *)a2);
v4 = func0((unsigned __int8 *)(a2 + 4));
*(_BYTE *)(a1 + 432) = (v3 == 1145394249) & (((unsigned __int16)func0((unsigned __int8 *)(a2 + 6)) | v4) == 0);
result = 1LL;
}
else
{
msg_Log("EDI: Incorrect length %02x for *PTR", a3);
result = 0LL;
}
return result;
}

original_code:
_Bool decode_starptr(edi_handler_t *h, const uint8_t *value, uint32_t bytelength)
{
    if (bytelength != 0x40 / 8) {
     msg_Log("EDI: Incorrect length %02x for *PTR", bytelength);
        return 0;
    }
    uint32_t proto = read_32b(value);
    uint16_t major = read_16b(value + 4);
    uint16_t minor = read_16b(value + 6);
   h->eti.is_eti = (proto == 0x44455449 && major == 0 && minor == 0);
    return 1;
}

canonical_original_code:
_Bool decode_starptr(struct edi_handler_t *h, unsigned char *value, unsigned int bytelength)
{
    if (bytelength != 0x40 / 8) {
     msg_Log("EDI: Incorrect length %02x for *PTR", bytelength);
        return 0;
    }
    unsigned int proto = read_32b(value);
    unsigned short major = read_16b(value + 4);
    unsigned short minor = read_16b(value + 6);
   h->eti.is_eti = (proto == 0x44455449 && major == 0 && minor == 0);
    return 1;
}

variable_types: struct edi_handler_t { int eti_format; unsigned short m_last_seq; struct pfPkt { unsigned short sync; unsigned short _Pseq; unsigned int _Findex; unsigned int _Fcount; unsigned short _FEC; unsigned short _Addr; unsigned short _Plen; unsigned char _RSk; unsigned char _RSz; unsigned short _Source; unsigned short _Dest; _Bool _valid; unsigned char *_payload; unsigned short _MaxLen; } pf; struct afPkt { unsigned short m_last_seq; } af; struct afBuilders { unsigned short Pseq_newest; unsigned short Pseq_oldest; _Bool isInitial; unsigned int PktLost; unsigned int errorsCorrected; unsigned int PktCount; unsigned int Fcount; unsigned short Plen; _Bool FEC; _Bool Addr; unsigned char RSk; unsigned char RSz; unsigned short Source; unsigned short Dest; unsigned int _rxmin; unsigned int _cmax; struct afSingleCollector { unsigned short Pseq_this; unsigned int bytesCollected; unsigned int fragmentsCollected; unsigned char *packetReceived; unsigned char *pfPackets; _Bool packetsIsProcessed; } pfCollectors[8]; unsigned char *rs_block; unsigned char *afPacket; void *m_rs_handler; } afb; struct etiBuilder { _Bool is_eti; unsigned char m_err; unsigned short m_mnsc; _Bool m_time_valid; unsigned int m_utco; unsigned int m_seconds; unsigned char fic_length; unsigned char fic[128]; unsigned short m_rfu; struct eti_stc_data { unsigned char stream_index; unsigned char scid; unsigned short sad; unsigned char tpl; unsigned char *mst; unsigned short mst_size; } m_stc[64]; unsigned char NST; _Bool m_fc_valid; struct eti_fc_data { _Bool atstf; unsigned int tsta; _Bool ficf; unsigned char nst; unsigned short dflc; unsigned char mid; unsigned char fp; } m_fc; } eti; void (*write_cb)(void *privData, void *etiData, int etiLen); void *write_cb_priv; } *

variable_types:
value
unsigned char *

variable_types:
bytelength
unsigned int

variable_types:
proto
unsigned int

variable_types:
major
unsigned short

variable_types:
minor
unsigned short

user_defined_types: struct edi_handler_t { int eti_format; unsigned short m_last_seq; struct pfPkt pf; struct afPkt af; struct afBuilders afb; struct etiBuilder eti; void (*write_cb)(void *privData, void *etiData, int etiLen); void *write_cb_priv; }

user_defined_types: struct afBuilders { unsigned short Pseq_newest; unsigned short Pseq_oldest; _Bool isInitial; unsigned int PktLost; unsigned int errorsCorrected; unsigned int PktCount; unsigned int Fcount; unsigned short Plen; _Bool FEC; _Bool Addr; unsigned char RSk; unsigned char RSz; unsigned short Source; unsigned short Dest; unsigned int _rxmin; unsigned int _cmax; struct afSingleCollector pfCollectors[8]; unsigned char *rs_block; unsigned char *afPacket; void *m_rs_handler; }

user_defined_types: struct etiBuilder { _Bool is_eti; unsigned char m_err; unsigned short m_mnsc; _Bool m_time_valid; unsigned int m_utco; unsigned int m_seconds; unsigned char fic_length; unsigned char fic[128]; unsigned short m_rfu; struct eti_stc_data m_stc[64]; unsigned char NST; _Bool m_fc_valid; struct eti_fc_data m_fc; }


original_code:
_Bool decode_deti(edi_handler_t *h, const uint8_t *value, uint32_t bytelength)
{
    uint16_t detiHeader = read_16b(value);
    h->eti.m_fc.atstf = (detiHeader >> 15) & 0x1;
    h->eti.m_fc.ficf = (detiHeader >> 14) & 0x1;
    _Bool rfudf = (detiHeader >> 13) & 0x1;
    uint8_t fcth = (detiHeader >> 8) & 0x1F;
    uint8_t fct = detiHeader & 0xFF;
    h->eti.m_fc.dflc = fcth * 250 + fct;
    uint32_t etiHeader = read_32b(value + 2);
    h->eti.m_err = (etiHeader >> 24) & 0xFF;
    h->eti.m_fc.mid = (etiHeader >> 22) & 0x03;
    h->eti.m_fc.fp = (etiHeader >> 19) & 0x07;
    uint8_t rfa = (etiHeader >> 17) & 0x3;
    if (rfa != 0) {
     msg_Log("EDI: EDI deti TAG: rfa non-zero");
    }
    _Bool rfu = (etiHeader >> 16) & 0x1;
    h->eti.m_mnsc = rfu ? 0xFFFF : etiHeader & 0xFFFF;
    const uint32_t fic_length_words = (h->eti.m_fc.ficf ? (h->eti.m_fc.mid == 3 ? 32 : 24) : 0);
    const uint32_t fic_length = 4 * fic_length_words;
    const uint32_t expected_length = 2 + 4 +
        (h->eti.m_fc.atstf ? 1 + 4 + 3 : 0) +
        fic_length +
        (rfudf ? 3 : 0);
    if (bytelength != expected_length) {
     msg_Log("EDI deti: Assertion error:"
                "value.size() != expected_length: %u != %u", bytelength, expected_length);
     return 0;
    }
    size_t i = 2 + 4;
    h->eti.m_time_valid = 0;
    h->eti.m_utco = 0;
    h->eti.m_seconds = 0;
    if (h->eti.m_fc.atstf) {
        uint8_t utco = value[i];
        i++;
        uint32_t seconds = read_32b(value + i);
        i += 4;
        h->eti.m_utco = utco;
        h->eti.m_seconds = seconds;
        h->eti.m_time_valid = 1;
        h->eti.m_fc.tsta = read_24b(value + i);
        i += 3;
    }
    else {
     h->eti.m_fc.tsta = 0xFFFFFF;
    }
    if (h->eti.m_fc.ficf) {
     h->eti.fic_length = fic_length;
     memcpy(h->eti.fic, value+i, fic_length);
        i += fic_length;
    }
    h->eti.m_rfu = 0xffff;
    if (rfudf) {
        uint32_t rfud = read_24b(value + i);
        h->eti.m_rfu = rfud >> 8;
        if ((rfud & 0xFF) != 0xFF) {
         msg_Log("EDI: RFU in TIST not supported");
        }
        i += 3;
    }
    h->eti.m_fc_valid = 0;
    if (!h->eti.m_fc.ficf) {
     msg_Log("FIC must be present");
    }
    if (h->eti.m_fc.mid > 4) {
     msg_Log("Invalid MID");
    }
    if (h->eti.m_fc.fp > 7) {
     msg_Log("Invalid FP");
    }
    h->eti.m_fc_valid = 1;
 return 1;
}

canonical_original_code:
_Bool decode_deti(struct edi_handler_t *h, unsigned char *value, unsigned int bytelength)
{
    unsigned short detiHeader = read_16b(value);
    h->eti.m_fc.atstf = (detiHeader >> 15) & 0x1;
    h->eti.m_fc.ficf = (detiHeader >> 14) & 0x1;
    _Bool rfudf = (detiHeader >> 13) & 0x1;
    unsigned char fcth = (detiHeader >> 8) & 0x1F;
    unsigned char fct = detiHeader & 0xFF;
    h->eti.m_fc.dflc = fcth * 250 + fct;
    unsigned int etiHeader = read_32b(value + 2);
    h->eti.m_err = (etiHeader >> 24) & 0xFF;
    h->eti.m_fc.mid = (etiHeader >> 22) & 0x03;
    h->eti.m_fc.fp = (etiHeader >> 19) & 0x07;
    unsigned char rfa = (etiHeader >> 17) & 0x3;
    if (rfa != 0) {
     msg_Log("EDI: EDI deti TAG: rfa non-zero");
    }
    _Bool rfu = (etiHeader >> 16) & 0x1;
    h->eti.m_mnsc = rfu ? 0xFFFF : etiHeader & 0xFFFF;
    unsigned int fic_length_words = (h->eti.m_fc.ficf ? (h->eti.m_fc.mid == 3 ? 32 : 24) : 0);
    unsigned int fic_length = 4 * fic_length_words;
    unsigned int expected_length = 2 + 4 +
        (h->eti.m_fc.atstf ? 1 + 4 + 3 : 0) +
        fic_length +
        (rfudf ? 3 : 0);
    if (bytelength != expected_length) {
     msg_Log("EDI deti: Assertion error:"
                "value.size() != expected_length: %u != %u", bytelength, expected_length);
     return 0;
    }
    unsigned long i = 2 + 4;
    h->eti.m_time_valid = 0;
    h->eti.m_utco = 0;
    h->eti.m_seconds = 0;
    if (h->eti.m_fc.atstf) {
        unsigned char utco = value[i];
        i++;
        unsigned int seconds = read_32b(value + i);
        i += 4;
        h->eti.m_utco = utco;
        h->eti.m_seconds = seconds;
        h->eti.m_time_valid = 1;
        h->eti.m_fc.tsta = read_24b(value + i);
        i += 3;
    }
    else {
     h->eti.m_fc.tsta = 0xFFFFFF;
    }
    if (h->eti.m_fc.ficf) {
     h->eti.fic_length = fic_length;
     memcpy(h->eti.fic, value+i, fic_length);
        i += fic_length;
    }
    h->eti.m_rfu = 0xffff;
    if (rfudf) {
        unsigned int rfud = read_24b(value + i);
        h->eti.m_rfu = rfud >> 8;
        if ((rfud & 0xFF) != 0xFF) {
         msg_Log("EDI: RFU in TIST not supported");
        }
        i += 3;
    }
    h->eti.m_fc_valid = 0;
    if (!h->eti.m_fc.ficf) {
     msg_Log("FIC must be present");
    }
    if (h->eti.m_fc.mid > 4) {
     msg_Log("Invalid MID");
    }
    if (h->eti.m_fc.fp > 7) {
     msg_Log("Invalid FP");
    }
    h->eti.m_fc_valid = 1;
 return 1;
}

variable_types:
detiHeader
unsigned short

variable_types:
fcth
unsigned char

variable_types:
fct
unsigned char

variable_types:
etiHeader
unsigned int

variable_types:
rfa
unsigned char

variable_types:
i
unsigned long

variable_types:
utco
unsigned char

variable_types:
seconds
unsigned int

variable_types:
rfud
unsigned int

user_defined_types: struct pfPkt { unsigned short sync; unsigned short _Pseq; unsigned int _Findex; unsigned int _Fcount; unsigned short _FEC; unsigned short _Addr; unsigned short _Plen; unsigned char _RSk; unsigned char _RSz; unsigned short _Source; unsigned short _Dest; _Bool _valid; unsigned char *_payload; unsigned short _MaxLen; }

user_defined_types: struct afPkt { unsigned short m_last_seq; }

user_defined_types: struct eti_fc_data { _Bool atstf; unsigned int tsta; _Bool ficf; unsigned char nst; unsigned short dflc; unsigned char mid; unsigned char fp; }

user_defined_types: struct afSingleCollector { unsigned short Pseq_this; unsigned int bytesCollected; unsigned int fragmentsCollected; unsigned char *packetReceived; unsigned char *pfPackets; _Bool packetsIsProcessed; }

user_defined_types: struct eti_stc_data { unsigned char stream_index; unsigned char scid; unsigned short sad; unsigned char tpl; unsigned char *mst; unsigned short mst_size; }


original_code:
_Bool decode_estn(edi_handler_t *h, const uint8_t *value, uint32_t bytelength, uint8_t n)
{
    uint32_t sstc = read_24b(value);
    if(n>64 || n==0) {
     msg_Log("EDI: number of streams is invalid:%u", n);
     return 0;
    }
    struct eti_stc_data *stc = &h->eti.m_stc[n-1];
    uint32_t old_size = stc->mst_size;
    stc->stream_index = n - 1;
    stc->scid = (sstc >> 18) & 0x3F;
    stc->sad = (sstc >> 8) & 0x3FF;
    stc->tpl = (sstc >> 2) & 0x3F;
    uint8_t rfa = sstc & 0x3;
    if (rfa != 0) {
     msg_Log("EDI: rfa field in ESTn tag non-null");
    }
    if(bytelength < 3) {
     msg_Log("EDI: est%d bad length", n);
    }
    stc->mst_size = bytelength - 3;
    if(verbosity > 1)
     msg_Log("EDI: est%d length:%u", n, stc->mst_size);
    if(!stc->mst)
     stc->mst=malloc(stc->mst_size);
    else if(stc->mst_size != old_size)
     stc->mst=realloc(stc->mst, stc->mst_size);
    memcpy(stc->mst, value+3, stc->mst_size);
    h->eti.m_fc.nst++;
 return 1;
}

canonical_original_code:
_Bool decode_estn(struct edi_handler_t *h, unsigned char *value, unsigned int bytelength, unsigned char n)
{
    unsigned int sstc = read_24b(value);
    if(n>64 || n==0) {
     msg_Log("EDI: number of streams is invalid:%u", n);
     return 0;
    }
    struct eti_stc_data *stc = &h->eti.m_stc[n-1];
    unsigned int old_size = stc->mst_size;
    stc->stream_index = n - 1;
    stc->scid = (sstc >> 18) & 0x3F;
    stc->sad = (sstc >> 8) & 0x3FF;
    stc->tpl = (sstc >> 2) & 0x3F;
    unsigned char rfa = sstc & 0x3;
    if (rfa != 0) {
     msg_Log("EDI: rfa field in ESTn tag non-null");
    }
    if(bytelength < 3) {
     msg_Log("EDI: est%d bad length", n);
    }
    stc->mst_size = bytelength - 3;
    if(verbosity > 1)
     msg_Log("EDI: est%d length:%u", n, stc->mst_size);
    if(!stc->mst)
     stc->mst=malloc(stc->mst_size);
    else if(stc->mst_size != old_size)
     stc->mst=realloc(stc->mst, stc->mst_size);
    memcpy(stc->mst, value+3, stc->mst_size);
    h->eti.m_fc.nst++;
 return 1;
}

variable_types:
n
unsigned char

variable_types:
sstc
unsigned int

variable_types: struct eti_stc_data { unsigned char stream_index; unsigned char scid; unsigned short sad; unsigned char tpl; unsigned char *mst; unsigned short mst_size; } *


decompiled_code:
__int64 decode_stardmy()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 1LL;
}

original_code:
_Bool decode_stardmy(edi_handler_t *h, uint8_t *tag_value, uint32_t taglength)
{
 return 1;
}

canonical_original_code:
_Bool decode_stardmy(struct edi_handler_t *h, unsigned char *tag_value, unsigned int taglength)
{
 return 1;
}

variable_types: struct edi_handler_t { int eti_format; unsigned short m_last_seq; struct pfPkt { unsigned short sync; unsigned short _Pseq; unsigned int _Findex; unsigned int _Fcount; unsigned short _FEC; unsigned short _Addr; unsigned short _Plen; unsigned char _RSk; unsigned char _RSz; unsigned short _Source; unsigned short _Dest; _Bool _valid; unsigned char *_payload; unsigned short _MaxLen; } pf; struct afPkt { unsigned short m_last_seq; } af; struct afBuilders { unsigned short Pseq_newest; unsigned short Pseq_oldest; _Bool isInitial; unsigned int PktLost; unsigned int errorsCorrected; unsigned int PktCount; unsigned int Fcount; unsigned short Plen; _Bool FEC; _Bool Addr; unsigned char RSk; unsigned char RSz; unsigned short Source; unsigned short Dest; unsigned int _rxmin; unsigned int _cmax; struct afSingleCollector { unsigned short Pseq_this; unsigned int bytesCollected; unsigned int fragmentsCollected; unsigned char *packetReceived; unsigned char *pfPackets; _Bool packetsIsProcessed; } pfCollectors[8]; unsigned char *rs_block; unsigned char *afPacket; void *m_rs_handler; } afb; struct etiBuilder { _Bool is_eti; unsigned char m_err; unsigned short m_mnsc; _Bool m_time_valid; unsigned int m_utco; unsigned int m_seconds; unsigned char fic_length; unsigned char fic[128]; unsigned short m_rfu; struct eti_stc_data { unsigned char stream_index; unsigned char scid; unsigned short sad; unsigned char tpl; unsigned char *mst; unsigned short mst_size; } m_stc[64]; unsigned char NST; _Bool m_fc_valid; struct eti_fc_data { _Bool atstf; unsigned int tsta; _Bool ficf; unsigned char nst; unsigned short dflc; unsigned char mid; unsigned char fp; } m_fc; } eti; void (*write_cb)(void *privData, void *etiData, int etiLen); void *write_cb_priv; } *

variable_types:
taglength
unsigned int


decompiled_code:
__int64 __fastcall decode_tagpacket(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // r9
unsigned int v7; // ebx
unsigned __int8 *v8; // rsi
unsigned int v9; // eax
unsigned __int8 v10; // al
unsigned __int8 *v11; // r15
unsigned int v12; // ebp
__int64 v13; // rbx
const unsigned __int16 **v14; // rax
__int64 v15; // rcx
unsigned __int8 v16; // bp
unsigned __int64 v18; // [rsp+8h] [rbp-40h]

*(_BYTE *)(a1 + 2133) = 0;
v18 = a3;
if ( a3 <= 8 )
return 1;
v4 = 0LL;
v5 = 8LL;
do
{
v11 = (unsigned __int8 *)(a2 + v4);
v12 = read_32b((unsigned int *)(a2 + v4));
v13 = (unsigned int)read_32b((unsigned int *)(a2 + v4 + 4));
if ( verbosity > 2 )
{
v14 = _ctype_b_loc();
LOBYTE(v6) = *(_BYTE *)(a2 + v4 + 3);
v15 = (unsigned __int8)v6;
if ( ((*v14)[v15] & 0x4000) != 0 )
{
v6 = (unsigned __int8)v6;
}
else
{
v6 = (unsigned int)(unsigned __int8)v6 + 48;
if ( ((*v14)[v15 + 48] & 0x4000) == 0 )
v6 = 46LL;
}
msg_Log(
"EDI: tag %08x (%c%c%c%c) len:%u",
v12,
*v11,
*(unsigned __int8 *)(a2 + v4 + 1),
*(unsigned __int8 *)(a2 + v4 + 2),
v6,
v13);
}
if ( (v13 & 7) != 0 )
{
msg_Log("EDI: Invalid tag length!");
return 1;
}
v7 = (unsigned int)v13 >> 3;
v8 = (unsigned __int8 *)(a2 + v5);
if ( v12 == 712012914 )
{
v10 = decode_starptr(a1, (__int64)v8, v7);
}
else if ( v12 == 1684370537 )
{
v10 = decode_deti(a1, (__int64)v8, v7);
}
else
{
v9 = v12;
LOBYTE(v9) = 0;
if ( v9 == 1702065152 )
{
v10 = decode_estn(a1, v8, v7, v12);
}
else
{
if ( v12 != 711224697 )
{
msg_Log(
"EDI: Unknown TAG %c%c%c%c",
*v11,
*(unsigned __int8 *)(a2 + v4 + 1),
*(unsigned __int8 *)(a2 + v4 + 2),
*(unsigned __int8 *)(a2 + v4 + 3));
return 1;
}
v10 = decode_stardmy(a1, v8, v7);
}
}
if ( !v10 )
{
v16 = 0;
msg_Log(
"EDI: Error decoding TAG %c%c%c%c",
*v11,
*(unsigned __int8 *)(a2 + v4 + 1),
*(unsigned __int8 *)(a2 + v4 + 2),
*(unsigned __int8 *)(a2 + v4 + 3));
return v16;
}
v4 += v7 + 8;
v5 = v4 + 8;
}
while ( v4 + 8 < v18 );
return v10;
}

original_code:
int decode_tagpacket(edi_handler_t *h, uint8_t *tag_pkt, uint32_t tagsize)
{
    size_t i, length = 0;
    _Bool success = 1;
    h->eti.m_fc.nst=0;
    for (i = 0; i + 8 < tagsize; i += 8 + length) {
        uint32_t tagId = read_32b(tag_pkt + i);
        uint32_t taglength = read_32b(tag_pkt + i + 4);
        if(verbosity > 2)
         msg_Log("EDI: tag %08x (%c%c%c%c) len:%u",
           tagId, tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2],
     ((*__ctype_b_loc ())[(int) ((tag_pkt[i+3]))] & (unsigned short int) _ISprint) ? tag_pkt[i+3] : (((*__ctype_b_loc ())[(int) ((tag_pkt[i+3]+0x30))] & (unsigned short int) _ISprint) ? (tag_pkt[i+3]+0x30) : '.'),
     taglength);
        if (taglength % 8 != 0) {
         msg_Log("EDI: Invalid tag length!");
            break;
        }
        taglength /= 8;
        length = taglength;
        uint8_t *tag_value = tag_pkt + i+8;
        _Bool tagsuccess = 0;
        if (tagId == 0x2a707472 ) {
            tagsuccess = decode_starptr(h, tag_value, taglength);
        }
        else if (tagId == 0x64657469 ) {
            tagsuccess = decode_deti(h, tag_value, taglength);
        }
        else if ((tagId & 0xFFFFFF00) == 0x65737400 ) {
            uint8_t n = tagId & 0x000000FF;
            tagsuccess = decode_estn(h, tag_value, taglength, n);
        }
        else if (tagId == 0x2a646d79 ) {
            tagsuccess = decode_stardmy(h, tag_value, taglength);
        }
        else {
         msg_Log("EDI: Unknown TAG %c%c%c%c", tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2], tag_pkt[i+3]);
            break;
        }
        if (!tagsuccess) {
         msg_Log("EDI: Error decoding TAG %c%c%c%c",tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2], tag_pkt[i+3]);
            success = tagsuccess;
            break;
        }
    }
    return success;
}

canonical_original_code:
int decode_tagpacket(struct edi_handler_t *h, unsigned char *tag_pkt, unsigned int tagsize)
{
    unsigned long i; unsigned long length = 0;
    _Bool success = 1;
    h->eti.m_fc.nst=0;
    for (i = 0; i + 8 < tagsize; i += 8 + length) {
        unsigned int tagId = read_32b(tag_pkt + i);
        unsigned int taglength = read_32b(tag_pkt + i + 4);
        if(verbosity > 2)
         msg_Log("EDI: tag %08x (%c%c%c%c) len:%u",
           tagId, tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2],
     ((*__ctype_b_loc ())[(int) ((tag_pkt[i+3]))] & (unsigned short) _ISprint) ? tag_pkt[i+3] : (((*__ctype_b_loc ())[(int) ((tag_pkt[i+3]+0x30))] & (unsigned short) _ISprint) ? (tag_pkt[i+3]+0x30) : '.'),
     taglength);
        if (taglength % 8 != 0) {
         msg_Log("EDI: Invalid tag length!");
            break;
        }
        taglength /= 8;
        length = taglength;
        unsigned char *tag_value = tag_pkt + i+8;
        _Bool tagsuccess = 0;
        if (tagId == 0x2a707472 ) {
            tagsuccess = decode_starptr(h, tag_value, taglength);
        }
        else if (tagId == 0x64657469 ) {
            tagsuccess = decode_deti(h, tag_value, taglength);
        }
        else if ((tagId & 0xFFFFFF00) == 0x65737400 ) {
            unsigned char n = tagId & 0x000000FF;
            tagsuccess = decode_estn(h, tag_value, taglength, n);
        }
        else if (tagId == 0x2a646d79 ) {
            tagsuccess = decode_stardmy(h, tag_value, taglength);
        }
        else {
         msg_Log("EDI: Unknown TAG %c%c%c%c", tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2], tag_pkt[i+3]);
            break;
        }
        if (!tagsuccess) {
         msg_Log("EDI: Error decoding TAG %c%c%c%c",tag_pkt[i], tag_pkt[i+1], tag_pkt[i+2], tag_pkt[i+3]);
            success = tagsuccess;
            break;
        }
    }
    return success;
}

variable_types:
tagsize
unsigned int

variable_types:
length
unsigned long

variable_types:
tagId
unsigned int


decompiled_code:
__int64 __fastcall ts_get_transporterror(__int64 a1)
{
return *(_BYTE *)(a1 + 1) >> 7;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_BYTE *)(a1 + 1) >> 7;
}

original_code:
static inline _Bool ts_get_transporterror(const uint8_t *p_ts)
{
    return !!(p_ts[1] & 0x80);
}

canonical_original_code:
static inline _Bool ts_get_transporterror(unsigned char *p_ts)
{
    return !!(p_ts[1] & 0x80);
}


decompiled_code:
__int64 __fastcall ts_get_pid(__int64 a1)
{
int v1; // eax

v1 = *(unsigned __int8 *)(a1 + 1) << 8;
LOWORD(v1) = v1 & 0x1F00;
return *(unsigned __int8 *)(a1 + 2) | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // eax

v1 = *(unsigned __int8 *)(a1 + 1) << 8;
LOWORD(v1) = v1 & 0x1F00;
return *(unsigned __int8 *)(a1 + 2) | (unsigned int)v1;
}

original_code:
static inline uint16_t ts_get_pid(const uint8_t *p_ts)
{
    return ((p_ts[1] & 0x1f) << 8) | p_ts[2];
}

canonical_original_code:
static inline unsigned short ts_get_pid(unsigned char *p_ts)
{
    return ((p_ts[1] & 0x1f) << 8) | p_ts[2];
}


decompiled_code:
__int64 __fastcall ts_get_cc(__int64 a1)
{
return *(_BYTE *)(a1 + 3) & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(_BYTE *)(a1 + 3) & 0xF;
}

original_code:
static inline uint8_t ts_get_cc(const uint8_t *p_ts)
{
    return p_ts[3] & 0xf;
}

canonical_original_code:
static inline unsigned char ts_get_cc(unsigned char *p_ts)
{
    return p_ts[3] & 0xf;
}

return_type: unsigned char


decompiled_code:
_BOOL8 __fastcall ts_has_payload(__int64 a1)
{
return (*(_BYTE *)(a1 + 3) & 0x10) != 0;
}

original_code:
static inline _Bool ts_has_payload(const uint8_t *p_ts)
{
    return !!(p_ts[3] & 0x10);
}

canonical_original_code:
static inline _Bool ts_has_payload(unsigned char *p_ts)
{
    return !!(p_ts[3] & 0x10);
}


decompiled_code:
_BOOL8 __fastcall ts_has_adaptation(__int64 a1)
{
return (*(_BYTE *)(a1 + 3) & 0x20) != 0;
}

original_code:
static inline _Bool ts_has_adaptation(const uint8_t *p_ts)
{
    return !!(p_ts[3] & 0x20);
}

canonical_original_code:
static inline _Bool ts_has_adaptation(unsigned char *p_ts)
{
    return !!(p_ts[3] & 0x20);
}


decompiled_code:
__int64 __fastcall ts_get_adaptation(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 4);
}

original_code:
static inline uint8_t ts_get_adaptation(const uint8_t *p_ts)
{
    return p_ts[4];
}

canonical_original_code:
static inline unsigned char ts_get_adaptation(unsigned char *p_ts)
{
    return p_ts[4];
}


decompiled_code:
__int64 __fastcall ts_payload(__int64 a1)
{
if ( !ts_has_payload(a1) )
return a1 + 188;
if ( ts_has_adaptation(a1) )
return a1 + (unsigned __int8)ts_get_adaptation(a1) + 5;
return a1 + 4;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
if ( !func10(a1) )
return a1 + 188;
if ( func11(a1) )
return a1 + (unsigned __int8)func12(a1) + 5;
return a1 + 4;
}

original_code:
static inline uint8_t *ts_payload(uint8_t *p_ts)
{
    if (!ts_has_payload(p_ts))
        return p_ts + 188;
    if (!ts_has_adaptation(p_ts))
        return p_ts + 4;
    return p_ts + 4 + 1 + ts_get_adaptation(p_ts);
}

canonical_original_code:
static inline unsigned char *ts_payload(unsigned char *p_ts)
{
    if (!ts_has_payload(p_ts))
        return p_ts + 188;
    if (!ts_has_adaptation(p_ts))
        return p_ts + 4;
    return p_ts + 4 + 1 + ts_get_adaptation(p_ts);
}

return_type: unsigned char *