decompiled_code:
__int64 __fastcall mgetty_get_config(const char *a1)
{
__int64 v1; // rdi
__int64 v2; // rdi
__int64 result; // rax
bool v4; // cc

lprintf(5LL, "reading configuration data for port '%s'", a1);
get_config("/etc/mgetty+sendfax/mgetty.config", &c, "port", a1);
log_set_llevel(*((unsigned int *)&c + 290));
v1 = *((unsigned int *)&c + 2);
minfreespace = *((int *)&c + 254);
if ( (int)tio_check_speed(v1) < 0 )
{
lprintf(0LL, "invalid port speed: %d", *((unsigned int *)&c + 2));
LABEL_17:
exit_usage(2);
}
if ( *((_DWORD *)&c + 11) )
{
v2 = (__int64)*(&c + 4);
if ( (_DWORD)v2 )
{
if ( !*((_BYTE *)&c + 248) && (int)tio_check_speed(v2) < 0 )
{
lprintf(0LL, "invalid fax reception switch speed: %d", *((unsigned int *)&c + 8));
goto LABEL_17;
}
}
}
if ( !*((_DWORD *)&c + 128) )
{
*(&c + 64) = (_BYTE *)&loc_1;
*((_DWORD *)&c + 131) = 2;
}
if ( *((int *)&c + 176) <= 29 )
{
v4 = *((_DWORD *)&c + 122) <= 0x383u;
*(&c + 88) = algn_18 + 6;
*((_DWORD *)&c + 179) = 2;
if ( !v4 )
{
LABEL_9:
result = *((unsigned int *)&c + 83);
if ( !(_DWORD)result )
return result;
LABEL_13:
lprintf(5LL, "set modem_quirks: 0x%04x", *((unsigned int *)&c + 80));
result = (__int64)*(&c + 40);
modem_quirks = result;
return result;
}
}
else if ( *((_DWORD *)&c + 122) > 0x383u )
{
goto LABEL_9;
}
lprintf(5LL, "increasing modem_check_time to 900 sec.");
result = *((unsigned int *)&c + 83);
*(&c + 61) = (_BYTE *)(&loc_380 + 4);
*((_DWORD *)&c + 125) = 2;
if ( (_DWORD)result )
goto LABEL_13;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // rdi
__int64 v2; // rdi
__int64 result; // rax
bool v4; // cc

lprintf(5LL, "reading configuration data for port '%s'", a1);
get_config("/etc/mgetty+sendfax/mgetty.config", &c, "port", a1);
log_set_llevel(*((unsigned int *)&c + 290));
v1 = *((unsigned int *)&c + 2);
minfreespace = *((int *)&c + 254);
if ( (int)tio_check_speed(v1) < 0 )
{
lprintf(0LL, "invalid port speed: %d", *((unsigned int *)&c + 2));
LABEL_17:
func0(2);
}
if ( *((_DWORD *)&c + 11) )
{
v2 = (__int64)*(&c + 4);
if ( (_DWORD)v2 )
{
if ( !*((_BYTE *)&c + 248) && (int)tio_check_speed(v2) < 0 )
{
lprintf(0LL, "invalid fax reception switch speed: %d", *((unsigned int *)&c + 8));
goto LABEL_17;
}
}
}
if ( !*((_DWORD *)&c + 128) )
{
*(&c + 64) = (_BYTE *)&loc_1;
*((_DWORD *)&c + 131) = 2;
}
if ( *((int *)&c + 176) <= 29 )
{
v4 = *((_DWORD *)&c + 122) <= 0x383u;
*(&c + 88) = algn_18 + 6;
*((_DWORD *)&c + 179) = 2;
if ( !v4 )
{
LABEL_9:
result = *((unsigned int *)&c + 83);
if ( !(_DWORD)result )
return result;
LABEL_13:
lprintf(5LL, "set modem_quirks: 0x%04x", *((unsigned int *)&c + 80));
result = (__int64)*(&c + 40);
modem_quirks = result;
return result;
}
}
else if ( *((_DWORD *)&c + 122) > 0x383u )
{
goto LABEL_9;
}
lprintf(5LL, "increasing modem_check_time to 900 sec.");
result = *((unsigned int *)&c + 83);
*(&c + 61) = (_BYTE *)(&loc_380 + 4);
*((_DWORD *)&c + 125) = 2;
if ( (_DWORD)result )
goto LABEL_13;
return result;
}

original_code:
void mgetty_get_config (char * port)
{
    lprintf( 5, "reading configuration data for port '%s'", port );
    get_config( (("mgetty.config")[0] == '/'? ("mgetty.config") : ("/etc/mgetty+sendfax""/""mgetty.config")),
  (conf_data *)&c, "port", port );
    log_set_llevel( ((int) c.debug.d.i) );
    minfreespace = ((int) c.diskspace.d.i);
    if ( tio_check_speed( ((int) c.speed.d.i) ) < 0 )
    {
 lprintf( 0, "invalid port speed: %d", ((int) c.speed.d.i));
 exit_usage(2);
    }
    if ( ( c.switchbd.flags != C_EMPTY ) && ((int) c.switchbd.d.i) != 0 && !((boolean) c.data_only.d.i) &&
  tio_check_speed( ((int) c.switchbd.d.i) ) < 0 )
    {
 lprintf( 0, "invalid fax reception switch speed: %d",
   ((int) c.switchbd.d.i) );
 exit_usage(2);
    }
    if ( ((int) c.rings_wanted.d.i) == 0 ) { (&c.rings_wanted)->d.i = (1); (&c.rings_wanted)->flags = C_OVERRIDE; };
    if ( ((int) c.ringback_time.d.i) < 30 ) { (&c.ringback_time)->d.i = (30); (&c.ringback_time)->flags = C_OVERRIDE; };
    if ( ((int) c.modem_check_time.d.i) >= 0 &&
  ((int) c.modem_check_time.d.i) < 900 )
    {
 lprintf( 5, "increasing modem_check_time to 900 sec." );
 { (&c.modem_check_time)->d.i = (900); (&c.modem_check_time)->flags = C_OVERRIDE; };
    }
    if ( ( c.modem_quirks.flags != C_EMPTY ) )
    {
        lprintf( 5, "set modem_quirks: 0x%04x", ((int) c.modem_quirks.d.i));
 modem_quirks = ((int) c.modem_quirks.d.i);
    }
}

canonical_original_code:
void mgetty_get_config(char *port)
{
    lprintf( 5, "reading configuration data for port '%s'", port );
    get_config( (("mgetty.config")[0] == '/'? ("mgetty.config") : ("/etc/mgetty+sendfax""/""mgetty.config")),
  (struct conf_data *)&c, "port", port );
    log_set_llevel( ((int) c.debug.d.i) );
    minfreespace = ((int) c.diskspace.d.i);
    if ( tio_check_speed( ((int) c.speed.d.i) ) < 0 )
    {
 lprintf( 0, "invalid port speed: %d", ((int) c.speed.d.i));
 exit_usage(2);
    }
    if ( ( c.switchbd.flags != C_EMPTY ) && ((int) c.switchbd.d.i) != 0 && !((char) c.data_only.d.i) &&
  tio_check_speed( ((int) c.switchbd.d.i) ) < 0 )
    {
 lprintf( 0, "invalid fax reception switch speed: %d",
   ((int) c.switchbd.d.i) );
 exit_usage(2);
    }
    if ( ((int) c.rings_wanted.d.i) == 0 ) { (&c.rings_wanted)->d.i = (1); (&c.rings_wanted)->flags = C_OVERRIDE; };
    if ( ((int) c.ringback_time.d.i) < 30 ) { (&c.ringback_time)->d.i = (30); (&c.ringback_time)->flags = C_OVERRIDE; };
    if ( ((int) c.modem_check_time.d.i) >= 0 &&
  ((int) c.modem_check_time.d.i) < 900 )
    {
 lprintf( 5, "increasing modem_check_time to 900 sec." );
 { (&c.modem_check_time)->d.i = (900); (&c.modem_check_time)->flags = C_OVERRIDE; };
    }
    if ( ( c.modem_quirks.flags != C_EMPTY ) )
    {
        lprintf( 5, "set modem_quirks: 0x%04x", ((int) c.modem_quirks.d.i));
 modem_quirks = ((int) c.modem_quirks.d.i);
    }
}

variable_types:
port
char *


repo: Distrotech/mgetty

decompiled_code:
void __fastcall __noreturn exit_usage(int status)
{
lprintf(0LL, "Usage: mgetty [-x debug] [-s speed] [-r] line");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
lprintf(0LL, "Usage: mgetty [-x debug] [-s speed] [-r] line");
exit(status);
}

original_code:
void exit_usage (int code)
{
    lprintf( 0, "Usage: mgetty [-x debug] [-s speed] [-r] line" );
    exit(code);
}

canonical_original_code:
void exit_usage(int code)
{
    lprintf( 0, "Usage: mgetty [-x debug] [-s speed] [-r] line" );
    exit(code);
}

variable_types: code int

return_type: void


decompiled_code:
void __fastcall vgetty_button(int a1)
{
_BYTE v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( !a1 )
{
if ( **((_BYTE **)&cvd + 163) )
{
make_path(v1, *((_QWORD *)&cvd + 136));
voice_mode_on();
voice_execute_shell_script(v1, 0LL);
voice_mode_off();
exit(0);
}
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
_BYTE v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( !a1 )
{
if ( **((_BYTE **)&cvd + 163) )
{
make_path(v1, *((_QWORD *)&cvd + 136));
voice_mode_on();
voice_execute_shell_script(v1, 0LL);
voice_mode_off();
exit(0);
}
}
}

original_code:
void vgetty_button(int rings)
     {
     if ((rings == 0) && (strlen(cvd.button_program.d.p) != 0))
          {
          char file_name[(256)];
          make_path(file_name, cvd.voice_dir.d.p,
           cvd.button_program.d.p);
          voice_mode_on();
          voice_execute_shell_script(file_name, ((void *)0));
          voice_mode_off();
          exit(0);
          };
     }

canonical_original_code:
void vgetty_button(int rings)
     {
     if ((rings == 0) && (strlen(cvd.button_program.d.p) != 0))
          {
          char file_name[-1];
          make_path(file_name, cvd.voice_dir.d.p,
           cvd.button_program.d.p);
          voice_mode_on();
          voice_execute_shell_script(file_name, ((void *)0));
          voice_mode_off();
          exit(0);
          };
     }

variable_types: rings int


getdiskstats

decompiled_code:
__int64 __fastcall getdiskstats(const char *a1, __fsword_t *a2)
{
int v2; // er8
__int64 result; // rax
struct statfs v4; // [rsp+0h] [rbp-88h] BYREF

v2 = statfs(a1, &v4);
result = 1LL;
if ( v2 >= 0 )
{
*a2 = v4.f_bsize;
a2[1] = v4.f_blocks;
a2[4] = v4.f_files;
a2[2] = v4.f_bfree;
a2[3] = v4.f_bavail;
a2[5] = v4.f_ffree;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __fsword_t *a2)
{
int v2; // er8
__int64 result; // rax
struct statfs v4; // [rsp+0h] [rbp-88h] BYREF

v2 = statfs(a1, &v4);
result = 1LL;
if ( v2 >= 0 )
{
*a2 = v4.f_bsize;
a2[1] = v4.f_blocks;
a2[4] = v4.f_files;
a2[2] = v4.f_bfree;
a2[3] = v4.f_bavail;
a2[5] = v4.f_ffree;
result = 0LL;
}
return result;
}

original_code:
int
getdiskstats (char *path,mntinf *mi)
{
    struct statfs info;
    if (statfs(path,&info) < 0) {
 return(1);
    }
    mi->mi_bsize = info.f_bsize;
    mi->mi_blocks = info.f_blocks;
    mi->mi_files = info.f_files;
    mi->mi_bfree = info.f_bfree;
    mi->mi_bavail = info.f_bavail;
    mi->mi_ffree = info.f_ffree;
    return(0);
}

canonical_original_code:
int getdiskstats(char *path, struct mountinfo *mi)
{
    struct statfs info;
    if (statfs(path,&info) < 0) {
 return(1);
    }
    mi->mi_bsize = info.f_bsize;
    mi->mi_blocks = info.f_blocks;
    mi->mi_files = info.f_files;
    mi->mi_bfree = info.f_bfree;
    mi->mi_bavail = info.f_bavail;
    mi->mi_ffree = info.f_ffree;
    return(0);
}

variable_types:
path
char *

variable_types: struct mountinfo { long mi_bsize; long mi_blocks; long mi_bfree; long mi_bavail; long mi_files; long mi_ffree; } *

variable_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t { int __val[2]; } f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }

return_type: int

user_defined_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }


checkspace

decompiled_code:
__int64 __fastcall checkspace(const char *a1)
{
int v1; // er8
__int64 result; // rax
unsigned int v3; // ebx
__fsword_t v4[9]; // [rsp+0h] [rbp-48h] BYREF

v1 = getdiskstats(a1, v4);
result = 1LL;
if ( !v1 )
{
v3 = *(_DWORD *)((char *)v4 + 1) * (v4[3] >> 2);
lprintf(5LL, "%d Mb free on %s", v3 >> 10, a1);
result = v3 / minfreespace;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // er8
__int64 result; // rax
unsigned int v3; // ebx
__fsword_t v4[9]; // [rsp+0h] [rbp-48h] BYREF

v1 = func0(a1, v4);
result = 1LL;
if ( !v1 )
{
v3 = *(_DWORD *)((char *)v4 + 1) * (v4[3] >> 2);
lprintf(5LL, "%d Mb free on %s", v3 >> 10, a1);
result = v3 / minfreespace;
}
return result;
}

original_code:
int checkspace (char *path)
{
    struct mountinfo mi;
    unsigned int kbytes;
    if (getdiskstats(path, &mi))
 return(1);
    kbytes = (mi.mi_bavail>>2) * (mi.mi_bsize>>8);
    lprintf( 5, "%d Mb free on %s", kbytes/1024, path );
    return( kbytes / minfreespace);
}

canonical_original_code:
int checkspace(char *path)
{
    struct mountinfo mi;
    unsigned int kbytes;
    if (getdiskstats(path, &mi))
 return(1);
    kbytes = (mi.mi_bavail>>2) * (mi.mi_bsize>>8);
    lprintf( 5, "%d Mb free on %s", kbytes/1024, path );
    return( kbytes / minfreespace);
}

variable_types: struct mountinfo { long mi_bsize; long mi_blocks; long mi_bfree; long mi_bavail; long mi_files; long mi_ffree; }

variable_types:
kbytes
unsigned int


decompiled_code:
__int64 __fastcall callback_parse_args(int argc, char **argv)
{
int v4; // eax
int v5; // eax
int v6; // eax
char *v7; // rdi
char *v8; // rax

c[19] = (char *)&def_init_chat_seq;
HIDWORD(c[20]) = 1;
while ( 1 )
{
v4 = getopt(argc, argv, "x:s:am:l:SdV");
if ( v4 == -1 )
return 0LL;
switch ( v4 )
{
case '?':
exit_usage(2);
case 'S':
v8 = ttyname(0);
HIDWORD(c[2]) = 2;
c[1] = v8;
lprintf(4LL, "using stdin for dial out, tty=%s", v8);
break;
case 'V':
printf("\nmgetty+sendfax by Gert Doering\n%s\n\n", mgetty_version);
printf("log file written to '");
printf("/var/log/mgetty.%s", "callback");
puts("'\n");
exit(0);
case 'a':
c[28] = (_BYTE *)&loc_1;
HIDWORD(c[29]) = 2;
break;
case 'd':
c[34] = (_BYTE *)&loc_1;
HIDWORD(c[35]) = 2;
lprintf(4LL, "debug mode active");
break;
case 'l':
if ( *optarg == 47 )
{
if ( memcmp(optarg, "/dev/", 5uLL) )
{
fprintf(stderr, "%s: -l: device must be located in /dev!\n", *argv);
exit(1);
}
}
c[1] = optarg;
HIDWORD(c[2]) = 2;
break;
case 'm':
v7 = optarg;
HIDWORD(c[20]) = 2;
c[19] = (char *)conf_get_chat(v7);
break;
case 's':
v6 = atoi(optarg);
HIDWORD(c[23]) = 2;
c[22] = (char *)v6;
break;
case 'x':
v5 = atoi(optarg);
HIDWORD(c[38]) = 2;
c[37] = (char *)v5;
log_set_llevel((unsigned int)v5);
break;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
int v4; // eax
int v5; // eax
int v6; // eax
char *v7; // rdi
char *v8; // rax

c[19] = (char *)&def_init_chat_seq;
HIDWORD(c[20]) = 1;
while ( 1 )
{
v4 = getopt(argc, argv, "x:s:am:l:SdV");
if ( v4 == -1 )
return 0LL;
switch ( v4 )
{
case '?':
func0(2);
case 'S':
v8 = ttyname(0);
HIDWORD(c[2]) = 2;
c[1] = v8;
lprintf(4LL, "using stdin for dial out, tty=%s", v8);
break;
case 'V':
printf("\nmgetty+sendfax by Gert Doering\n%s\n\n", mgetty_version);
printf("log file written to '");
printf("/var/log/mgetty.%s", "callback");
puts("'\n");
exit(0);
case 'a':
c[28] = (_BYTE *)&loc_1;
HIDWORD(c[29]) = 2;
break;
case 'd':
c[34] = (_BYTE *)&loc_1;
HIDWORD(c[35]) = 2;
lprintf(4LL, "debug mode active");
break;
case 'l':
if ( *optarg == 47 )
{
if ( memcmp(optarg, "/dev/", 5uLL) )
{
fprintf(stderr, "%s: -l: device must be located in /dev!\n", *argv);
exit(1);
}
}
c[1] = optarg;
HIDWORD(c[2]) = 2;
break;
case 'm':
v7 = optarg;
HIDWORD(c[20]) = 2;
c[19] = (char *)conf_get_chat(v7);
break;
case 's':
v6 = atoi(optarg);
HIDWORD(c[23]) = 2;
c[22] = (char *)v6;
break;
case 'x':
v5 = atoi(optarg);
HIDWORD(c[38]) = 2;
c[37] = (char *)v5;
log_set_llevel((unsigned int)v5);
break;
default:
continue;
}
}
}

original_code:
int callback_parse_args (int argc,char ** argv)
{
int opt;
conf_data c_a[2];
    if ( ( (char *)&c_a[1] - (char *)&c_a[0] ) !=
  ( (char *)&c.ttys_0 - (char *)&c.ttys ) )
    {
 fprintf( stderr, "ERROR: config table size mixup. contact author\n" );
 exit(99);
    }
    c.modem_init.d.p = (void *) def_init_chat_seq;
    c.modem_init.flags = C_PRESET;
    while ((opt = getopt(argc, argv, "x:s:am:l:SdV")) != (-1))
    {
 switch (opt)
 {
   case 'x':
     { (&c.debug)->d.i = (atoi(optarg)); (&c.debug)->flags = C_OVERRIDE; };
     log_set_llevel( ((int) c.debug.d.i) );
     break;
   case 's':
     { (&c.speed)->d.i = (atoi(optarg)); (&c.speed)->flags = C_OVERRIDE; };
     break;
   case 'a':
     { (&c.autobauding)->d.i = ((1==1)); (&c.autobauding)->flags = C_OVERRIDE; };
     break;
   case 'm':
     c.modem_init.flags = C_OVERRIDE;
     c.modem_init.d.p = conf_get_chat( optarg );
     break;
   case 'l':
     if ( optarg[0] == '/' &&
   strncmp( optarg, "/dev/", 5 ) != 0 )
     {
  fprintf( stderr, "%s: -l: device must be located in /dev!\n",
                   argv[0]);
  exit(1);
     }
     { (&c.ttys)->d.p = (optarg); (&c.ttys)->flags = C_OVERRIDE; };
     break;
   case 'S':
     { (&c.ttys)->d.p = (ttyname(0)); (&c.ttys)->flags = C_OVERRIDE; };
     lprintf( 4, "using stdin for dial out, tty=%s", ((char *) c.ttys.d.p));
     break;
   case 'd':
     { (&c.nodetach)->d.i = ((1==1)); (&c.nodetach)->flags = C_OVERRIDE; };
     lprintf( 4, "debug mode active" );
     break;
   case 'V':
     printf("\nmgetty+sendfax by Gert Doering\n%s\n\n",
      mgetty_version);
     printf("log file written to '");
     printf("/var/log/mgetty.%s", "callback" );
     printf("'\n\n");
     exit(0);
   case '?':
     exit_usage(2);
     break;
 }
    }
    return 0;
}

canonical_original_code:
int callback_parse_args(int argc, char **argv)
{
int opt;
struct conf_data c_a[2];
    if ( ( (char *)&c_a[1] - (char *)&c_a[0] ) !=
  ( (char *)&c.ttys_0 - (char *)&c.ttys ) )
    {
 fprintf( stderr, "ERROR: config table size mixup. contact author\n" );
 exit(99);
    }
    c.modem_init.d.p = (void *) def_init_chat_seq;
    c.modem_init.flags = C_PRESET;
    while ((opt = getopt(argc, argv, "x:s:am:l:SdV")) != (-1))
    {
 switch (opt)
 {
   case 'x':
     { (&c.debug)->d.i = (atoi(optarg)); (&c.debug)->flags = C_OVERRIDE; };
     log_set_llevel( ((int) c.debug.d.i) );
     break;
   case 's':
     { (&c.speed)->d.i = (atoi(optarg)); (&c.speed)->flags = C_OVERRIDE; };
     break;
   case 'a':
     { (&c.autobauding)->d.i = ((1==1)); (&c.autobauding)->flags = C_OVERRIDE; };
     break;
   case 'm':
     c.modem_init.flags = C_OVERRIDE;
     c.modem_init.d.p = conf_get_chat( optarg );
     break;
   case 'l':
     if ( optarg[0] == '/' &&
   strncmp( optarg, "/dev/", 5 ) != 0 )
     {
  fprintf( stderr, "%s: -l: device must be located in /dev!\n",
                   argv[0]);
  exit(1);
     }
     { (&c.ttys)->d.p = (optarg); (&c.ttys)->flags = C_OVERRIDE; };
     break;
   case 'S':
     { (&c.ttys)->d.p = (ttyname(0)); (&c.ttys)->flags = C_OVERRIDE; };
     lprintf( 4, "using stdin for dial out, tty=%s", ((char *) c.ttys.d.p));
     break;
   case 'd':
     { (&c.nodetach)->d.i = ((1==1)); (&c.nodetach)->flags = C_OVERRIDE; };
     lprintf( 4, "debug mode active" );
     break;
   case 'V':
     printf("\nmgetty+sendfax by Gert Doering\n%s\n\n",
      mgetty_version);
     printf("log file written to '");
     printf("/var/log/mgetty.%s", "callback" );
     printf("'\n\n");
     exit(0);
   case '?':
     exit_usage(2);
     break;
 }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: struct conf_data { char *key; union { long i; void *p; } d; enum { CT_INT=0, CT_STRING=1, CT_CHAT=2, CT_BOOL=3, CT_FLOWL=4, CT_ACTION=5, CT_KEYWORD=6 } type; enum { C_EMPTY=0, C_PRESET=1, C_OVERRIDE=2, C_CONF=3, C_IGNORE=4 } flags; } [2]


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

if ( a1 )
{
lprintf(5LL, "reading specific data for port '%s'", a1);
get_config("/etc/mgetty+sendfax/callback.config", (unsigned int)((_DWORD)c + 24), "port", a1);
}
else
{
lprintf(5LL, "reading default configuration");
get_config("/etc/mgetty+sendfax/callback.config", c, "port", 0LL);
}
log_set_llevel(LODWORD(c[37]));
result = tio_check_speed(LODWORD(c[22]));
if ( (int)result < 0 )
{
lprintf(0LL, "invalid port speed: %d", LODWORD(c[22]));
exit_usage(2);
}
return result;
}

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

if ( a1 )
{
lprintf(5LL, "reading specific data for port '%s'", a1);
get_config("/etc/mgetty+sendfax/callback.config", (unsigned int)((_DWORD)c + 24), "port", a1);
}
else
{
lprintf(5LL, "reading default configuration");
get_config("/etc/mgetty+sendfax/callback.config", c, "port", 0LL);
}
log_set_llevel(LODWORD(c[37]));
result = tio_check_speed(LODWORD(c[22]));
if ( (int)result < 0 )
{
lprintf(0LL, "invalid port speed: %d", LODWORD(c[22]));
func0(2);
}
return result;
}

original_code:
void callback_get_config (char * port)
{
    if ( port == ((void *)0) )
    {
 lprintf( 5, "reading default configuration" );
 get_config( (("callback.config")[0] == '/'? ("callback.config") : ("/etc/mgetty+sendfax""/""callback.config")),
      (conf_data *)&c, "port", ((void *)0) );
    }
    else
    {
 lprintf( 5, "reading specific data for port '%s'", port );
 get_config( (("callback.config")[0] == '/'? ("callback.config") : ("/etc/mgetty+sendfax""/""callback.config")),
      ((conf_data *)&c)+1, "port", port );
    }
    log_set_llevel( ((int) c.debug.d.i) );
    if ( tio_check_speed( ((int) c.speed.d.i) ) < 0 )
    {
 lprintf( 0, "invalid port speed: %d", ((int) c.speed.d.i));
 exit_usage(2);
    }
}

canonical_original_code:
void callback_get_config(char *port)
{
    if ( port == ((void *)0) )
    {
 lprintf( 5, "reading default configuration" );
 get_config( (("callback.config")[0] == '/'? ("callback.config") : ("/etc/mgetty+sendfax""/""callback.config")),
      (struct conf_data *)&c, "port", ((void *)0) );
    }
    else
    {
 lprintf( 5, "reading specific data for port '%s'", port );
 get_config( (("callback.config")[0] == '/'? ("callback.config") : ("/etc/mgetty+sendfax""/""callback.config")),
      ((struct conf_data *)&c)+1, "port", port );
    }
    log_set_llevel( ((int) c.debug.d.i) );
    if ( tio_check_speed( ((int) c.speed.d.i) ) < 0 )
    {
 lprintf( 0, "invalid port speed: %d", ((int) c.speed.d.i));
 exit_usage(2);
    }
}

user_defined_types: struct conf_data { char *key; union { long i; void *p; } d; enum { CT_INT=0, CT_STRING=1, CT_CHAT=2, CT_BOOL=3, CT_FLOWL=4, CT_ACTION=5, CT_KEYWORD=6 } type; enum { C_EMPTY=0, C_PRESET=1, C_OVERRIDE=2, C_CONF=3, C_IGNORE=4 } flags; }


decompiled_code:
void __fastcall __noreturn exit_usage(int status)
{
fwrite(
"Usage: callback [-x <debug level>] [-V] [-l <modem lines>] [-m <initstring>]\n"
" [-s <speed>] [-d] [-S] [phone number(s)...]\n",
1uLL,
0x80uLL,
stderr);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
fwrite(
"Usage: callback [-x <debug level>] [-V] [-l <modem lines>] [-m <initstring>]\n"
" [-s <speed>] [-d] [-S] [phone number(s)...]\n",
1uLL,
0x80uLL,
stderr);
exit(status);
}

original_code:
void exit_usage (int code)
{
    fprintf( stderr, "Usage: callback [-x <debug level>] [-V] [-l <modem lines>] [-m <initstring>]\n       [-s <speed>] [-d] [-S] [phone number(s)...]\n");
    exit(code);
}

canonical_original_code:
void exit_usage(int code)
{
    fprintf( stderr, "Usage: callback [-x <debug level>] [-V] [-l <modem lines>] [-m <initstring>]\n       [-s <speed>] [-d] [-S] [phone number(s)...]\n");
    exit(code);
}


decompiled_code:
int __fastcall warn_g3(const char *a1)
{
int result; // eax

result = have_warned;
if ( !have_warned )
{
result = fprintf(stderr, "WARNING: G3 file \"%s\" has incorrect line width, fixed\n", a1);
++have_warned;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
int result; // eax

result = have_warned;
if ( !have_warned )
{
result = fprintf(stderr, "WARNING: G3 file \"%s\" has incorrect line width, fixed\n", a1);
++have_warned;
}
return result;
}

original_code:
void warn_g3 (char * file)
{
    if ( have_warned ) return;
    fprintf( stderr, "WARNING: G3 file \"%s\" has incorrect line width, fixed\n",
             file );
    have_warned++;
}

canonical_original_code:
void warn_g3(char *file)
{
    if ( have_warned ) return;
    fprintf( stderr, "WARNING: G3 file \"%s\" has incorrect line width, fixed\n",
             file );
    have_warned++;
}

variable_types:
file
char *


decompiled_code:
void __fastcall __noreturn exit_usage(const char *a1)
{
fprintf(stderr, "usage: %s [-h <lines>] [-a] [-l] [-p <n>] [-w <n>] g3-file ...\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "usage: %s [-h <lines>] [-a] [-l] [-p <n>] [-w <n>] g3-file ...\n", a1);
exit(1);
}

original_code:
void exit_usage (char * program)
{
    fprintf( stderr, "usage: %s [-h <lines>] [-a] [-l] [-p <n>] [-w <n>] g3-file ...\n",
     program );
    exit(1);
}

canonical_original_code:
void exit_usage(char *program)
{
    fprintf( stderr, "usage: %s [-h <lines>] [-a] [-l] [-p <n>] [-w <n>] g3-file ...\n",
     program );
    exit(1);
}

variable_types:
program
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
int v7; // eax
int v8; // ebx
const char *v9; // rdi
int v10; // ebp
int v11; // eax
int v12; // er12
int v13; // ebx
int v14; // er15
unsigned int v15; // er13
char v16; // cl
__int64 v17; // rax
int v18; // eax
int *v19; // rax
int v20; // ecx
__off_t v21; // rax
char v22; // cl
char v23; // cl
__int64 v24; // rax
int v25; // eax
bool v26; // al
int v27; // er14
unsigned int v28; // er8
int v29; // ebx
int v30; // er12
__int64 v32; // rax
int v33; // eax
int v35; // [rsp+0h] [rbp-78h]
int v36; // [rsp+4h] [rbp-74h]
const char **v37; // [rsp+8h] [rbp-70h]
int v38; // [rsp+10h] [rbp-68h]
int v40; // [rsp+1Ch] [rbp-5Ch]
int v41; // [rsp+20h] [rbp-58h]
unsigned __int8 v42; // [rsp+27h] [rbp-51h]
int v43; // [rsp+28h] [rbp-50h]
unsigned int v44; // [rsp+2Ch] [rbp-4Ch]
int v45; // [rsp+30h] [rbp-48h]
int v46; // [rsp+34h] [rbp-44h]

v3 = 1728;
build_tree(&white, &t_white, envp);
build_tree(&white, &m_white, v4);
build_tree(&black, &t_black, v5);
build_tree(&black, &m_black, v6);
init_byte_tab(0LL, byte_tab);
init_byte_tab(0LL, &out_byte_tab);
v40 = 0;
v46 = 0;
v45 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "lah:p:w:RL:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
exit_usage(*argv);
case 'L':
v40 = atoi(optarg);
break;
case 'R':
v46 = 1;
break;
case 'a':
byte_align = 1;
break;
case 'h':
v45 = atoi(optarg);
break;
case 'l':
putblackline = 1;
break;
case 'p':
padding = atoi(optarg);
break;
case 'w':
v3 = atoi(optarg);
break;
default:
continue;
}
}
if ( (int)v3 <= 99 )
{
fprintf(stderr, "%s: line width must be >= 100 PELs\n", *argv);
exit(1);
}
v36 = optind;
if ( argc <= optind )
{
v8 = 1;
if ( !v46 )
goto LABEL_100;
write(1, &buf, buflen);
goto LABEL_105;
}
v41 = 0;
v8 = 1;
v37 = &argv[optind];
v43 = v3 + 1;
while ( 1 )
{
v9 = *v37;
if ( **v37 != 45 || v9[1] != 108 || v9[2] )
break;
putblackline = 1;
LABEL_16:
++v36;
++v37;
if ( argc == v36 )
{
if ( v46 )
goto LABEL_101;
goto LABEL_100;
}
}
if ( *v9 != 45 || (v10 = *((unsigned __int8 *)v9 + 1), v9[1]) )
{
v10 = open(v9, 0);
if ( v10 == -1 )
{
perror(*v37);
goto LABEL_16;
}
}
if ( v8 )
{
if ( byte_align || padding > 0 )
putcode(0LL, 4LL);
putcode(2048LL, 12LL);
v29 = v45 - 1;
if ( v45 <= 0 )
{
--v45;
}
else
{
v30 = v45 - 1;
do
{
putwhitespan(v3);
puteol();
}
while ( v30-- != 0 );
v45 = v30;
v41 += v29 + 1;
}
}
have_warned = 0;
v11 = read(v10, rbuf, 0x2000uLL);
rs = v11;
if ( v11 < 0 )
{
perror("read");
close(rs);
exit(8);
}
if ( v11 > 63 )
{
if ( qword_A1 ^ 0x6165736552204350LL | qword_A9 ^ 0x636E49202C686372LL || byte_B1 )
rp = 0;
else
rp = 64;
goto LABEL_26;
}
rp = 0;
if ( v11 )
{
LABEL_26:
v44 = 0;
v38 = 0;
v35 = v3;
v42 = v40 > 0;
v12 = 0;
v13 = 0;
v14 = 0;
v15 = 0;
while ( 2 )
{
while ( v14 <= 19 )
{
v16 = v14;
v14 += 8;
v17 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v17] << v16;
if ( rp >= rs )
{
v18 = read(v10, rbuf, 0x2000uLL);
rs = v18;
if ( v18 < 0 )
{
perror("read2");
break;
}
rp = 0;
if ( !v18 )
goto LABEL_31;
}
}
if ( v13 )
v19 = *(int **)(black + 8LL * (unsigned __int8)v15 + 8);
else
v19 = *(int **)(white + 8LL * (unsigned __int8)v15 + 8);
while ( 1 )
{
if ( !v19 )
{
v21 = lseek(0, 0LL, 1);
fprintf(
stderr,
"invalid code, row=%d, col=%d, file offset=%lx, skip to eol\n",
v44,
(unsigned int)v12,
rp - (__int64)rs + v21);
while ( (v15 & 0x3F) != 0 )
{
v22 = v14 - 1;
v15 >>= 1;
if ( v14 - 1 <= 19 )
{
v14 += 7;
v32 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v32] << v22;
if ( rp >= rs )
{
v33 = read(v10, rbuf, 0x2000uLL);
rs = v33;
if ( v33 < 0 )
{
perror("read4");
goto LABEL_49;
}
rp = 0;
if ( !v33 )
goto LABEL_31;
}
}
else
{
--v14;
}
}
goto LABEL_49;
}
v20 = *v19;
if ( *v19 )
break;
v15 >>= 8;
v14 -= 8;
v19 = *(int **)&v19[2 * (unsigned __int8)v15 + 2];
}
v27 = v19[1];
v15 >>= v20;
v14 -= v20;
if ( v27 != -1 )
{
if ( v27 + v12 > v35 )
{
warn_g3(*v37);
v28 = v35 - v12;
if ( v35 - v12 > 0 )
{
if ( v13 )
putblackspan(v28);
else
putwhitespan(v28);
}
v12 = v43;
}
else
{
putcode((unsigned int)v19[2], (unsigned int)v19[3]);
v12 += v27;
}
v26 = v38 <= 3;
if ( v27 < 64 )
v13 ^= 1u;
goto LABEL_69;
}
LABEL_49:
if ( v12 > 0 && v35 > v12 )
{
warn_g3(*v37);
if ( v13 )
putblackspan(0LL);
putwhitespan((unsigned int)(v35 - v12));
}
LABEL_55:
while ( (v15 & 1) == 0 )
{
while ( 1 )
{
if ( (v15 & 0xF) != 0 )
{
--v14;
v15 >>= 1;
if ( v14 > 19 )
goto LABEL_55;
}
else
{
v14 -= 4;
v15 >>= 4;
if ( v14 > 19 )
goto LABEL_55;
}
v23 = v14;
v14 += 8;
v24 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v24] << v23;
if ( rp < rs )
break;
v25 = read(v10, rbuf, 0x2000uLL);
rs = v25;
if ( v25 < 0 )
{
perror("read3");
goto LABEL_62;
}
rp = 0;
if ( !v25 )
goto LABEL_31;
if ( (v15 & 1) != 0 )
goto LABEL_62;
}
}
LABEL_62:
--v14;
v15 >>= 1;
if ( v12 )
{
++v44;
puteol();
if ( (v42 & (v40 <= ++v41)) != 0 )
{
v3 = v35;
if ( !v10 )
goto LABEL_107;
v42 &= v40 <= v41;
goto LABEL_85;
}
v38 = 0;
v26 = 1;
v12 = 0;
v13 = 0;
}
else
{
v26 = ++v38 <= 3;
v13 = 0;
}
LABEL_69:
if ( rs > 0 && v26 )
continue;
break;
}
LABEL_31:
v3 = v35;
}
else
{
v42 = v40 > 0;
}
if ( v10 )
LABEL_85:
close(v10);
if ( v40 > v41 || !v42 )
{
v8 = 0;
if ( argc - 1 != v36 )
{
putwhitespan(v3);
puteol();
if ( putblackline )
{
putwhitespan(0LL);
putblackspan(v3);
puteol();
}
v8 = 0;
putwhitespan(v3);
puteol();
}
goto LABEL_16;
}
LABEL_107:
if ( v46 )
{
write(1, &buf, buflen);
return 0;
}
v8 = 0;
LABEL_100:
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
LABEL_101:
write(1, &buf, buflen);
if ( v8 )
LABEL_105:
fprintf(stderr, "%s: warning: no input file specified, empty g3 file created\n", *argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
int v7; // eax
int v8; // ebx
const char *v9; // rdi
int v10; // ebp
int v11; // eax
int v12; // er12
int v13; // ebx
int v14; // er15
unsigned int v15; // er13
char v16; // cl
__int64 v17; // rax
int v18; // eax
int *v19; // rax
int v20; // ecx
__off_t v21; // rax
char v22; // cl
char v23; // cl
__int64 v24; // rax
int v25; // eax
bool v26; // al
int v27; // er14
unsigned int v28; // er8
int v29; // ebx
int v30; // er12
__int64 v32; // rax
int v33; // eax
int v35; // [rsp+0h] [rbp-78h]
int v36; // [rsp+4h] [rbp-74h]
const char **v37; // [rsp+8h] [rbp-70h]
int v38; // [rsp+10h] [rbp-68h]
int v40; // [rsp+1Ch] [rbp-5Ch]
int v41; // [rsp+20h] [rbp-58h]
unsigned __int8 v42; // [rsp+27h] [rbp-51h]
int v43; // [rsp+28h] [rbp-50h]
unsigned int v44; // [rsp+2Ch] [rbp-4Ch]
int v45; // [rsp+30h] [rbp-48h]
int v46; // [rsp+34h] [rbp-44h]

v3 = 1728;
build_tree(&white, &t_white, envp);
build_tree(&white, &m_white, v4);
build_tree(&black, &t_black, v5);
build_tree(&black, &m_black, v6);
init_byte_tab(0LL, byte_tab);
init_byte_tab(0LL, &out_byte_tab);
v40 = 0;
v46 = 0;
v45 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "lah:p:w:RL:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
func0(*argv);
case 'L':
v40 = atoi(optarg);
break;
case 'R':
v46 = 1;
break;
case 'a':
byte_align = 1;
break;
case 'h':
v45 = atoi(optarg);
break;
case 'l':
putblackline = 1;
break;
case 'p':
padding = atoi(optarg);
break;
case 'w':
v3 = atoi(optarg);
break;
default:
continue;
}
}
if ( (int)v3 <= 99 )
{
fprintf(stderr, "%s: line width must be >= 100 PELs\n", *argv);
exit(1);
}
v36 = optind;
if ( argc <= optind )
{
v8 = 1;
if ( !v46 )
goto LABEL_100;
write(1, &buf, buflen);
goto LABEL_105;
}
v41 = 0;
v8 = 1;
v37 = &argv[optind];
v43 = v3 + 1;
while ( 1 )
{
v9 = *v37;
if ( **v37 != 45 || v9[1] != 108 || v9[2] )
break;
putblackline = 1;
LABEL_16:
++v36;
++v37;
if ( argc == v36 )
{
if ( v46 )
goto LABEL_101;
goto LABEL_100;
}
}
if ( *v9 != 45 || (v10 = *((unsigned __int8 *)v9 + 1), v9[1]) )
{
v10 = open(v9, 0);
if ( v10 == -1 )
{
perror(*v37);
goto LABEL_16;
}
}
if ( v8 )
{
if ( byte_align || padding > 0 )
putcode(0LL, 4LL);
putcode(2048LL, 12LL);
v29 = v45 - 1;
if ( v45 <= 0 )
{
--v45;
}
else
{
v30 = v45 - 1;
do
{
putwhitespan(v3);
puteol();
}
while ( v30-- != 0 );
v45 = v30;
v41 += v29 + 1;
}
}
have_warned = 0;
v11 = read(v10, rbuf, 0x2000uLL);
rs = v11;
if ( v11 < 0 )
{
perror("read");
close(rs);
exit(8);
}
if ( v11 > 63 )
{
if ( qword_A1 ^ 0x6165736552204350LL | qword_A9 ^ 0x636E49202C686372LL || byte_B1 )
rp = 0;
else
rp = 64;
goto LABEL_26;
}
rp = 0;
if ( v11 )
{
LABEL_26:
v44 = 0;
v38 = 0;
v35 = v3;
v42 = v40 > 0;
v12 = 0;
v13 = 0;
v14 = 0;
v15 = 0;
while ( 2 )
{
while ( v14 <= 19 )
{
v16 = v14;
v14 += 8;
v17 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v17] << v16;
if ( rp >= rs )
{
v18 = read(v10, rbuf, 0x2000uLL);
rs = v18;
if ( v18 < 0 )
{
perror("read2");
break;
}
rp = 0;
if ( !v18 )
goto LABEL_31;
}
}
if ( v13 )
v19 = *(int **)(black + 8LL * (unsigned __int8)v15 + 8);
else
v19 = *(int **)(white + 8LL * (unsigned __int8)v15 + 8);
while ( 1 )
{
if ( !v19 )
{
v21 = lseek(0, 0LL, 1);
fprintf(
stderr,
"invalid code, row=%d, col=%d, file offset=%lx, skip to eol\n",
v44,
(unsigned int)v12,
rp - (__int64)rs + v21);
while ( (v15 & 0x3F) != 0 )
{
v22 = v14 - 1;
v15 >>= 1;
if ( v14 - 1 <= 19 )
{
v14 += 7;
v32 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v32] << v22;
if ( rp >= rs )
{
v33 = read(v10, rbuf, 0x2000uLL);
rs = v33;
if ( v33 < 0 )
{
perror("read4");
goto LABEL_49;
}
rp = 0;
if ( !v33 )
goto LABEL_31;
}
}
else
{
--v14;
}
}
goto LABEL_49;
}
v20 = *v19;
if ( *v19 )
break;
v15 >>= 8;
v14 -= 8;
v19 = *(int **)&v19[2 * (unsigned __int8)v15 + 2];
}
v27 = v19[1];
v15 >>= v20;
v14 -= v20;
if ( v27 != -1 )
{
if ( v27 + v12 > v35 )
{
func1(*v37);
v28 = v35 - v12;
if ( v35 - v12 > 0 )
{
if ( v13 )
putblackspan(v28);
else
putwhitespan(v28);
}
v12 = v43;
}
else
{
putcode((unsigned int)v19[2], (unsigned int)v19[3]);
v12 += v27;
}
v26 = v38 <= 3;
if ( v27 < 64 )
v13 ^= 1u;
goto LABEL_69;
}
LABEL_49:
if ( v12 > 0 && v35 > v12 )
{
func1(*v37);
if ( v13 )
putblackspan(0LL);
putwhitespan((unsigned int)(v35 - v12));
}
LABEL_55:
while ( (v15 & 1) == 0 )
{
while ( 1 )
{
if ( (v15 & 0xF) != 0 )
{
--v14;
v15 >>= 1;
if ( v14 > 19 )
goto LABEL_55;
}
else
{
v14 -= 4;
v15 >>= 4;
if ( v14 > 19 )
goto LABEL_55;
}
v23 = v14;
v14 += 8;
v24 = (unsigned __int8)rbuf[rp++];
v15 |= byte_tab[v24] << v23;
if ( rp < rs )
break;
v25 = read(v10, rbuf, 0x2000uLL);
rs = v25;
if ( v25 < 0 )
{
perror("read3");
goto LABEL_62;
}
rp = 0;
if ( !v25 )
goto LABEL_31;
if ( (v15 & 1) != 0 )
goto LABEL_62;
}
}
LABEL_62:
--v14;
v15 >>= 1;
if ( v12 )
{
++v44;
puteol();
if ( (v42 & (v40 <= ++v41)) != 0 )
{
v3 = v35;
if ( !v10 )
goto LABEL_107;
v42 &= v40 <= v41;
goto LABEL_85;
}
v38 = 0;
v26 = 1;
v12 = 0;
v13 = 0;
}
else
{
v26 = ++v38 <= 3;
v13 = 0;
}
LABEL_69:
if ( rs > 0 && v26 )
continue;
break;
}
LABEL_31:
v3 = v35;
}
else
{
v42 = v40 > 0;
}
if ( v10 )
LABEL_85:
close(v10);
if ( v40 > v41 || !v42 )
{
v8 = 0;
if ( argc - 1 != v36 )
{
putwhitespan(v3);
puteol();
if ( putblackline )
{
putwhitespan(0LL);
putblackspan(v3);
puteol();
}
v8 = 0;
putwhitespan(v3);
puteol();
}
goto LABEL_16;
}
LABEL_107:
if ( v46 )
{
write(1, &buf, buflen);
return 0;
}
v8 = 0;
LABEL_100:
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
LABEL_101:
write(1, &buf, buflen);
if ( v8 )
LABEL_105:
fprintf(stderr, "%s: warning: no input file specified, empty g3 file created\n", *argv);
return 0;
}

original_code:
int main (int argc,char ** argv)
{
    int i;
    int fd;
    unsigned int data;
    int hibit;
    int cons_eol;
    int color;
    int row, col;
    struct g3_tree * p;
    int nr_pels;
    int first_file = 1;
    int empty_lines = 0;
    int line_width = 1728;
    int opt_R = 0;
    int max_length = 0;
    int lines_out = 0;
    build_tree( &white, t_white );
    build_tree( &white, m_white );
    build_tree( &black, t_black );
    build_tree( &black, m_black );
    init_byte_tab( 0, byte_tab );
    init_byte_tab( 0, out_byte_tab );
    while ( (i = getopt(argc, argv, "lah:p:w:RL:")) != (-1) )
    {
 switch (i)
 {
   case 'l': putblackline = 1; break;
   case 'a': byte_align = 1; break;
   case 'h': empty_lines = atoi( optarg ); break;
   case 'p': padding = atoi( optarg ); break;
   case 'w': line_width = atoi( optarg ); break;
   case 'R': opt_R = 1; break;
   case 'L': max_length = atoi( optarg ); break;
   case '?': exit_usage(argv[0]); break;
 }
    }
    if ( line_width < 100 )
    {
        fprintf( stderr, "%s: line width must be >= 100 PELs\n", argv[0] );
        exit(1);
    }
    for ( i=optind; i<argc; i++ )
    {
        if ( strcmp( argv[i], "-l" ) == 0)
        {
     putblackline = 1; continue;
        }
 if ( strcmp( argv[i], "-" ) == 0 )
  fd = 0;
 else
  fd = open( argv[i], 00 );
 if ( fd == -1 ) { perror( argv[i] ); continue; }
 if ( first_file )
 {
     if ( byte_align || padding > 0 ) putcode( 0, 4 );
     putcode( 0x800, 12 );
     first_file = 0;
     while ( empty_lines-- > 0 )
     {
  putwhitespan( line_width );
  puteol();
  lines_out++;
     }
 }
 hibit = 0;
 data = 0;
 cons_eol = 0;
 color = 0;
 have_warned = 0;
 rs = read( fd, rbuf, sizeof(rbuf) );
 if ( rs < 0 ) { perror( "read" ); close( rs ); exit(8); }
 rp = ( rs >= 64 && strcmp( rbuf+1, "PC Research, Inc" ) == 0 ) ? 64 : 0;
 row = col = 0;
 while ( rs > 0 && cons_eol < 4 )
 {
     while ( hibit < 20 )
     {
  data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
  hibit += 8;
  if ( rp >= rs )
  {
      rs = read( fd, rbuf, sizeof( rbuf ) );
      if ( rs < 0 ) { perror( "read2"); break; }
      rp = 0;
      if ( rs == 0 ) {
   goto do_write;}
  }
     }
     if ( color == 0 )
  p = white->nextb[ data & 0xff ];
     else
  p = black->nextb[ data & 0xff ];
     while ( p != ((void *)0) && ! ( p->nr_bits ) )
     {
  data >>= 8;
  hibit -= 8;
  p = p->nextb[ data & 0xff ];
     }
     if ( p == ((void *)0) )
     {
  fprintf( stderr, "invalid code, row=%d, col=%d, file offset=%lx, skip to eol\n",
    row, col, (unsigned long)lseek( 0, 0, 1 ) - rs + rp );
  while ( ( data & 0x03f ) != 0 )
  {
      data >>= 1; hibit--;
      if ( hibit < 20 )
      {
   data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
   hibit += 8;
   if ( rp >= rs )
   { rs = read( fd, rbuf, sizeof( rbuf ) );
       if ( rs < 0 ) { perror( "read4"); break; }
       rp = 0;
       if ( rs == 0 ) goto do_write;
   }
      }
  }
  nr_pels = -1;
     }
     else
     {
  data >>= p->nr_bits;
  hibit -= p->nr_bits;
  nr_pels = ( (struct g3code *) p ) ->nr_pels;
     }
     if ( nr_pels == -1 )
     {
  if ( col>0 && col < line_width )
  {
      warn_g3( argv[i] );
      if ( color != 0 )
   { putblackspan(0); }
      putwhitespan( line_width - col );
  }
  while ( ( data & 0x01 ) != 1 )
  {
      if ( ( data & 0xf ) == 0 )
      {
   hibit-= 4; data >>= 4;
      }
      else
      {
   hibit--; data >>= 1;
      }
      if ( hibit < 20 )
      {
   data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
   hibit += 8;
   if ( rp >= rs )
   { rs = read( fd, rbuf, sizeof( rbuf ) );
       if ( rs < 0 ) { perror( "read3"); break; }
       rp = 0;
       if ( rs == 0 ) goto do_write;
   }
      }
  }
  hibit--; data >>=1;
  color=0;
  if ( col == 0 )
      cons_eol++;
  else
  {
      row++; col=0;
      cons_eol = 0;
      puteol();
      lines_out++;
      if ( max_length > 0 &&
    lines_out >= max_length ) { goto do_write; }
  }
     }
     else
     {
      if ( col + nr_pels <= line_width )
      {
      putcode( ( (struct g3code *) p ) ->bit_code,
        ( (struct g3code *) p ) ->bit_length );
      col += nr_pels;
  }
  else
  {
      int put_pels = (line_width - col);
      warn_g3( argv[i] );
      if ( put_pels > 0 )
      {
          if ( color == 0 )
              putwhitespan( put_pels );
   else
       putblackspan( put_pels );
      }
      col = line_width+1;
  }
  if ( nr_pels < 64 ) color = !color;
     }
 }
do_write:
 if( fd != 0 ) close(fd);
 if ( max_length > 0 &&
      lines_out >= max_length ) { break; }
 if ( i != argc -1 )
 {
     putwhitespan( line_width );
     puteol();
            if ( putblackline )
  { putwhitespan( 0 );
    putblackspan( line_width );
    puteol(); }
     putwhitespan( line_width );
     puteol();
 }
    }
    if ( ! opt_R )
    {
 for ( i=0; i<6; i++ ) puteol();
    }
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    if ( first_file )
    {
 fprintf( stderr, "%s: warning: no input file specified, empty g3 file created\n", argv[0] );
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    int fd;
    unsigned int data;
    int hibit;
    int cons_eol;
    int color;
    int row; int col;
    struct g3_tree *p;
    int nr_pels;
    int first_file = 1;
    int empty_lines = 0;
    int line_width = 1728;
    int opt_R = 0;
    int max_length = 0;
    int lines_out = 0;
    build_tree( &white, t_white );
    build_tree( &white, m_white );
    build_tree( &black, t_black );
    build_tree( &black, m_black );
    init_byte_tab( 0, byte_tab );
    init_byte_tab( 0, out_byte_tab );
    while ( (i = getopt(argc, argv, "lah:p:w:RL:")) != (-1) )
    {
 switch (i)
 {
   case 'l': putblackline = 1; break;
   case 'a': byte_align = 1; break;
   case 'h': empty_lines = atoi( optarg ); break;
   case 'p': padding = atoi( optarg ); break;
   case 'w': line_width = atoi( optarg ); break;
   case 'R': opt_R = 1; break;
   case 'L': max_length = atoi( optarg ); break;
   case '?': exit_usage(argv[0]); break;
 }
    }
    if ( line_width < 100 )
    {
        fprintf( stderr, "%s: line width must be >= 100 PELs\n", argv[0] );
        exit(1);
    }
    for ( i=optind; i<argc; i++ )
    {
        if ( strcmp( argv[i], "-l" ) == 0)
        {
     putblackline = 1; continue;
        }
 if ( strcmp( argv[i], "-" ) == 0 )
  fd = 0;
 else
  fd = open( argv[i], 00 );
 if ( fd == -1 ) { perror( argv[i] ); continue; }
 if ( first_file )
 {
     if ( byte_align || padding > 0 ) putcode( 0, 4 );
     putcode( 0x800, 12 );
     first_file = 0;
     while ( empty_lines-- > 0 )
     {
  putwhitespan( line_width );
  puteol();
  lines_out++;
     }
 }
 hibit = 0;
 data = 0;
 cons_eol = 0;
 color = 0;
 have_warned = 0;
 rs = read( fd, rbuf, sizeof(rbuf) );
 if ( rs < 0 ) { perror( "read" ); close( rs ); exit(8); }
 rp = ( rs >= 64 && strcmp( rbuf+1, "PC Research, Inc" ) == 0 ) ? 64 : 0;
 row = col = 0;
 while ( rs > 0 && cons_eol < 4 )
 {
     while ( hibit < 20 )
     {
  data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
  hibit += 8;
  if ( rp >= rs )
  {
      rs = read( fd, rbuf, sizeof( rbuf ) );
      if ( rs < 0 ) { perror( "read2"); break; }
      rp = 0;
      if ( rs == 0 ) {
   goto do_write;}
  }
     }
     if ( color == 0 )
  p = white->nextb[ data & 0xff ];
     else
  p = black->nextb[ data & 0xff ];
     while ( p != ((void *)0) && ! ( p->nr_bits ) )
     {
  data >>= 8;
  hibit -= 8;
  p = p->nextb[ data & 0xff ];
     }
     if ( p == ((void *)0) )
     {
  fprintf( stderr, "invalid code, row=%d, col=%d, file offset=%lx, skip to eol\n",
    row, col, (unsigned long)lseek( 0, 0, 1 ) - rs + rp );
  while ( ( data & 0x03f ) != 0 )
  {
      data >>= 1; hibit--;
      if ( hibit < 20 )
      {
   data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
   hibit += 8;
   if ( rp >= rs )
   { rs = read( fd, rbuf, sizeof( rbuf ) );
       if ( rs < 0 ) { perror( "read4"); break; }
       rp = 0;
       if ( rs == 0 ) goto do_write;
   }
      }
  }
  nr_pels = -1;
     }
     else
     {
  data >>= p->nr_bits;
  hibit -= p->nr_bits;
  nr_pels = ( (struct g3code *) p ) ->nr_pels;
     }
     if ( nr_pels == -1 )
     {
  if ( col>0 && col < line_width )
  {
      warn_g3( argv[i] );
      if ( color != 0 )
   { putblackspan(0); }
      putwhitespan( line_width - col );
  }
  while ( ( data & 0x01 ) != 1 )
  {
      if ( ( data & 0xf ) == 0 )
      {
   hibit-= 4; data >>= 4;
      }
      else
      {
   hibit--; data >>= 1;
      }
      if ( hibit < 20 )
      {
   data |= ( byte_tab[ (int) (unsigned char) rbuf[ rp++] ] << hibit );
   hibit += 8;
   if ( rp >= rs )
   { rs = read( fd, rbuf, sizeof( rbuf ) );
       if ( rs < 0 ) { perror( "read3"); break; }
       rp = 0;
       if ( rs == 0 ) goto do_write;
   }
      }
  }
  hibit--; data >>=1;
  color=0;
  if ( col == 0 )
      cons_eol++;
  else
  {
      row++; col=0;
      cons_eol = 0;
      puteol();
      lines_out++;
      if ( max_length > 0 &&
    lines_out >= max_length ) { goto do_write; }
  }
     }
     else
     {
      if ( col + nr_pels <= line_width )
      {
      putcode( ( (struct g3code *) p ) ->bit_code,
        ( (struct g3code *) p ) ->bit_length );
      col += nr_pels;
  }
  else
  {
      int put_pels = (line_width - col);
      warn_g3( argv[i] );
      if ( put_pels > 0 )
      {
          if ( color == 0 )
              putwhitespan( put_pels );
   else
       putblackspan( put_pels );
      }
      col = line_width+1;
  }
  if ( nr_pels < 64 ) color = !color;
     }
 }
do_write:
 if( fd != 0 ) close(fd);
 if ( max_length > 0 &&
      lines_out >= max_length ) { break; }
 if ( i != argc -1 )
 {
     putwhitespan( line_width );
     puteol();
            if ( putblackline )
  { putwhitespan( 0 );
    putblackspan( line_width );
    puteol(); }
     putwhitespan( line_width );
     puteol();
 }
    }
    if ( ! opt_R )
    {
 for ( i=0; i<6; i++ ) puteol();
    }
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    if ( first_file )
    {
 fprintf( stderr, "%s: warning: no input file specified, empty g3 file created\n", argv[0] );
    }
    return 0;
}

variable_types: i int

variable_types: fd int

variable_types:
data
unsigned int

variable_types: hibit int

variable_types: color int

variable_types: row int

variable_types: col int

variable_types: struct g3_tree { int nr_bits; struct g3_tree *nextb[-1]; } *


variable_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; } *

variable_types:
c
unsigned char *

variable_types:
target
short *

variable_types:
LARc
short [8]

variable_types:
Nc
short [4]

variable_types:
Mc
short [4]

variable_types:
bc
short [4]

variable_types:
xmaxc
short [4]

variable_types:
xmc
short [-1]


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

reset_watchdog();
switch ( a1 )
{
case 1u:
voice_command("AT+VLS=0", &unk_383);
result = 0LL;
break;
case 2u:
voice_command("AT+VLS=1", &unk_383);
result = 0LL;
break;
case 3u:
voice_command("AT+VLS=6", &unk_383);
result = 0LL;
break;
case 6u:
voice_command("AT+VLS=4", &unk_383);
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=2", &unk_383);
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

reset_watchdog();
switch ( a1 )
{
case 1u:
voice_command("AT+VLS=0", &unk_383);
result = 0LL;
break;
case 2u:
voice_command("AT+VLS=1", &unk_383);
result = 0LL;
break;
case 3u:
voice_command("AT+VLS=6", &unk_383);
result = 0LL;
break;
case 6u:
voice_command("AT+VLS=4", &unk_383);
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=2", &unk_383);
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static int Multitech_5634ZPX_ISA_set_device(int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0007):
               voice_command("AT+VLS=2", "OK");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=1", "OK");
               return((0));
          case (0x0006):
               voice_command("AT+VLS=4", "OK");
               return((0));
          case (0x0003):
               voice_command("AT+VLS=6", "OK");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

variable_types: device int


decompiled_code:
__int64 __fastcall Multitech_5634ZPX_ISA_beep(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
unsigned int v3; // er13
int v4; // edi
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = (unsigned int)((int)a2 >> 31);
LODWORD(v2) = (int)a2 % *(_DWORD *)(voice_modem + 48LL);
v3 = (int)a2 / *(_DWORD *)(voice_modem + 48LL);
reset_watchdog(a1, a2, v2);
sprintf(v6, *(const char **)(voice_modem + 32LL), (unsigned int)a1, (unsigned int)a1, v3);
if ( (unsigned int)voice_command(v6, &unk_3B3) )
return 0xFFFFFFFFLL;
v4 = 1000;
if ( (int)a2 >= 1000 )
v4 = a2;
delay((unsigned int)(v4 - 1000));
return (unsigned int)-((voice_command(&unk_3B3, *(_QWORD *)(voice_modem + 40LL)) & 0x1000) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
unsigned int v3; // er13
int v4; // edi
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = (unsigned int)((int)a2 >> 31);
LODWORD(v2) = (int)a2 % *(_DWORD *)(voice_modem + 48LL);
v3 = (int)a2 / *(_DWORD *)(voice_modem + 48LL);
reset_watchdog(a1, a2, v2);
sprintf(v6, *(const char **)(voice_modem + 32LL), (unsigned int)a1, (unsigned int)a1, v3);
if ( (unsigned int)voice_command(v6, &unk_3B3) )
return 0xFFFFFFFFLL;
v4 = 1000;
if ( (int)a2 >= 1000 )
v4 = a2;
delay((unsigned int)(v4 - 1000));
return (unsigned int)-((voice_command(&unk_3B3, *(_QWORD *)(voice_modem + 40LL)) & 0x1000) == 0);
}

original_code:
int Multitech_5634ZPX_ISA_beep(int frequency, int length)
     {
     char buffer[(256)];
     int true_length = length / voice_modem->beep_timeunit;
     reset_watchdog();
     sprintf(buffer, voice_modem->beep_cmnd, frequency, frequency, true_length);
     if (voice_command(buffer, "") != (0))
          return((-1));
     delay(((length - 1000) > 0) ? (length - 1000) : 0);
     if ((voice_command("", voice_modem->beep_answr) & (0x1000)) != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int Multitech_5634ZPX_ISA_beep(int frequency, int length)
     {
     char buffer[-1];
     int true_length = length / voice_modem->beep_timeunit;
     reset_watchdog();
     sprintf(buffer, voice_modem->beep_cmnd, frequency, frequency, true_length);
     if (voice_command(buffer, "") != (0))
          return((-1));
     delay(((length - 1000) > 0) ? (length - 1000) : 0);
     if ((voice_command("", voice_modem->beep_answr) & (0x1000)) != (0x1000))
          return((-1));
     return((0));
     }

variable_types: frequency int

variable_types: length int

variable_types:
buffer
char [-1]


decompiled_code:
void vgetty_create_message_flag_file()
{
int v0; // edi
char v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( **((_BYTE **)&cvd + 148) )
{
make_path(v1, *((_QWORD *)&cvd + 136));
lprintf(6LL, "%s: creating message flag file %s", program_name, v1);
v0 = creat(v1, 0x1B6u);
if ( v0 < 0 )
lprintf(3LL, "%s: could not creat message flag file %s", program_name, v1);
else
close(v0);
}
}

canonical_decompiled_code:
void func1()
{
int v0; // edi
char v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( **((_BYTE **)&cvd + 148) )
{
make_path(v1, *((_QWORD *)&cvd + 136));
lprintf(6LL, "%s: creating message flag file %s", program_name, v1);
v0 = creat(v1, 0x1B6u);
if ( v0 < 0 )
lprintf(3LL, "%s: could not creat message flag file %s", program_name, v1);
else
close(v0);
}
}

original_code:
void vgetty_create_message_flag_file(void)
     {
     if (strlen(cvd.message_flag_file.d.p) != 0)
          {
          char flag_file_name[(256)];
          int flag_file;
          make_path(flag_file_name, cvd.voice_dir.d.p,
           cvd.message_flag_file.d.p);
          lprintf(6, "%s: creating message flag file %s",
           program_name, flag_file_name);
          flag_file = creat(flag_file_name, 0666);
          if (flag_file < 0)
               lprintf(3, "%s: could not creat message flag file %s",
                program_name, flag_file_name);
          else
               close(flag_file);
          };
     }

canonical_original_code:
void vgetty_create_message_flag_file()
     {
     if (strlen(cvd.message_flag_file.d.p) != 0)
          {
          char flag_file_name[-1];
          int flag_file;
          make_path(flag_file_name, cvd.voice_dir.d.p,
           cvd.message_flag_file.d.p);
          lprintf(6, "%s: creating message flag file %s",
           program_name, flag_file_name);
          flag_file = creat(flag_file_name, 0666);
          if (flag_file < 0)
               lprintf(3, "%s: could not creat message flag file %s",
                program_name, flag_file_name);
          else
               close(flag_file);
          };
     }


decompiled_code:
__int64 voice_detect_modemtype()
{
const char **v0; // rax
char *v1; // rax
char *v2; // rbx
char v3; // bp
const unsigned __int16 *v4; // rdx
__int64 v5; // rbp
const char *v6; // r15
__int64 v7; // r13
const char *v8; // r14
__int64 v9; // rbx
const char *v11; // r13
char *v12; // rbx
const unsigned __int16 *i; // rax
char *j; // rbp
char *v15; // r14
char **v16; // rbx
const char *v17; // rdi
const char *v18; // r15
const char **v19; // rax
char *s2; // [rsp+8h] [rbp-140h]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

lprintf(4LL, "detecting voice modem type");
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(5LL, "voice modem type was set directly");
return 0LL;
}
if ( cvd[31] )
{
delay();
if ( !cvd[85] )
goto LABEL_4;
LABEL_37:
if ( (unsigned int)voice_write("ATE1") || (voice_command(&unk_71E, "OK|ATE1") & 0x1000) == 0 )
goto LABEL_88;
voice_flush(1LL);
goto LABEL_6;
}
if ( cvd[85] )
goto LABEL_37;
LABEL_4:
if ( (unsigned int)voice_write("ATE0") )
goto LABEL_88;
voice_flush(3LL);
LABEL_6:
memset(s, 0, 0x100uLL);
if ( (unsigned int)voice_command("ATI9", &unk_71E) || (unsigned int)voice_read(s) )
goto LABEL_88;
if ( cvd[91] == 1LL )
{
lprintf(5LL, "V253 forced");
voice_modem = &V253modem;
}
if ( cvd[94] == 1LL )
{
lprintf(5LL, "V253ugly forced");
v0 = (const char **)&V253ugly;
voice_modem = &V253ugly;
}
else
{
v0 = (const char **)voice_modem;
}
if ( v0 != (const char **)&no_modem
|| (*(_DWORD *)s != 1380011347 || *(_WORD *)&s[4] != 22868 || s[6] != 32 ? (v0 = (const char **)voice_modem) : (voice_modem = &Dr_Neuhaus, v0 = (const char **)&Dr_Neuhaus),
v0 != (const char **)&no_modem) )
{
lprintf(4LL, "%s detected", *v0);
lprintf(5LL, "voice modem type was set by ATI9 partial match");
return 0LL;
}
v1 = strchr(s, 40);
v2 = v1;
if ( v1 )
{
v3 = v1[1];
if ( v3 )
{
if ( v3 == 1 )
{
v2 = v1 + 3;
}
else
{
v4 = *_ctype_b_loc();
while ( 1 )
{
++v2;
if ( (v4[v3] & 0x800) == 0 && v3 != 46 )
break;
v3 = v2[1];
}
}
lprintf(5LL, "PNP String: '%s'", v2);
v5 = 0LL;
s2 = v2 + 3;
v6 = "SUP";
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
while ( v6 )
{
v7 = 4 * v5;
v8 = (const char *)qword_1748[4 * v5];
if ( v8 )
{
lprintf(6LL, "checking pnpid %s / modelid %s", v6, (const char *)qword_1748[4 * v5]);
if ( !strncmp(v6, v2, 3uLL) && !strncmp(v8, s2, 4uLL) )
{
LABEL_32:
v9 = 4LL * (int)v5;
lprintf(4LL, "PNP: found modem: %s", off_1758[v9]);
voice_modem = *(void **)((char *)&off_1750 + v9 * 8);
break;
}
}
else
{
lprintf(6LL, "checking pnpid %s / modelid %s", v6, "<none>");
if ( !strncmp(v6, v2, 3uLL) )
goto LABEL_32;
}
++v5;
if ( (_UNKNOWN *)voice_modem != &no_modem )
break;
v6 = off_1760[v7];
}
}
voice_read(s);
}
}
voice_flush(3LL);
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(5LL, "voice modem type was set by pnp id");
return 0LL;
}
if ( (unsigned int)voice_command("ATI3", &unk_71E) || (unsigned int)voice_read(s) )
goto LABEL_88;
if ( !strstr(s, "OK") && !strstr(s, "ERROR") && !(unsigned int)voice_read(s) && strstr(s, "SupraExpress 56e PRO") )
voice_modem = &Supra56ePRO;
voice_flush(1LL);
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(4LL, "%s detected", (const char *)*voice_modem);
lprintf(5LL, "voice modem type was set by using identification strings");
return 0LL;
}
if ( (unsigned int)voice_command("ATI", &unk_71E) )
{
LABEL_88:
lprintf(3LL, "modem detection failed");
LABEL_87:
exit(-1);
}
v11 = "ATI";
do
{
if ( (unsigned int)voice_read(s) )
goto LABEL_88;
v12 = &s[strlen(s) - 1];
for ( i = *_ctype_b_loc(); v12 >= s; *v12-- = 0 )
{
if ( (i[*v12] & 0x2000) == 0 )
break;
}
for ( j = s; (i[*j] & 0x2000) != 0; ++j )
;
v15 = (char *)voice_modem;
v16 = &off_FA8;
v17 = "ATI";
while ( 1 )
{
if ( v15 != (char *)&no_modem )
goto LABEL_70;
if ( !strcmp(v17, v11) && !strcmp(*v16, j) )
break;
LABEL_68:
v17 = v16[3];
v16 += 4;
if ( !v17 )
goto LABEL_75;
}
v18 = v16[1];
if ( !v18 )
{
v15 = v16[2];
voice_modem = v15;
goto LABEL_68;
}
voice_flush(1LL);
if ( (unsigned int)voice_command(v18, &unk_71E) )
goto LABEL_88;
v15 = (char *)voice_modem;
v11 = v18;
strcpy(s, "OK");
LABEL_75:
;
}
while ( v15 == (char *)&no_modem && (unsigned int)voice_analyze(s, &unk_71E, 1LL) != 0x4000 );
LABEL_70:
voice_flush(1LL);
v19 = (const char **)voice_modem;
if ( !*(_QWORD *)(voice_modem + 304LL) )
{
lprintf(3LL, "%s detected, but driver is not available", (const char *)*voice_modem);
voice_modem = &no_modem;
exit(-1);
}
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_command("AT+FCLASS=8", "OK");
if ( (unsigned int)voice_command("AT+VSM=1,8000", "OK") == 4096 )
voice_modem = &V253modem;
voice_command("AT+FCLASS=0", "OK");
v19 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_flush(1LL);
voice_modem = &no_modem;
lprintf(3LL, "no voice modem detected");
goto LABEL_87;
}
}
lprintf(4LL, "%s detected", *v19);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char **v0; // rax
char *v1; // rax
char *v2; // rbx
char v3; // bp
const unsigned __int16 *v4; // rdx
__int64 v5; // rbp
const char *v6; // r15
__int64 v7; // r13
const char *v8; // r14
__int64 v9; // rbx
const char *v11; // r13
char *v12; // rbx
const unsigned __int16 *i; // rax
char *j; // rbp
char *v15; // r14
char **v16; // rbx
const char *v17; // rdi
const char *v18; // r15
const char **v19; // rax
char *s2; // [rsp+8h] [rbp-140h]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

lprintf(4LL, "detecting voice modem type");
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(5LL, "voice modem type was set directly");
return 0LL;
}
if ( cvd[31] )
{
delay();
if ( !cvd[85] )
goto LABEL_4;
LABEL_37:
if ( (unsigned int)voice_write("ATE1") || (voice_command(&unk_71E, "OK|ATE1") & 0x1000) == 0 )
goto LABEL_88;
voice_flush(1LL);
goto LABEL_6;
}
if ( cvd[85] )
goto LABEL_37;
LABEL_4:
if ( (unsigned int)voice_write("ATE0") )
goto LABEL_88;
voice_flush(3LL);
LABEL_6:
memset(s, 0, 0x100uLL);
if ( (unsigned int)voice_command("ATI9", &unk_71E) || (unsigned int)voice_read(s) )
goto LABEL_88;
if ( cvd[91] == 1LL )
{
lprintf(5LL, "V253 forced");
voice_modem = &V253modem;
}
if ( cvd[94] == 1LL )
{
lprintf(5LL, "V253ugly forced");
v0 = (const char **)&V253ugly;
voice_modem = &V253ugly;
}
else
{
v0 = (const char **)voice_modem;
}
if ( v0 != (const char **)&no_modem
|| (*(_DWORD *)s != 1380011347 || *(_WORD *)&s[4] != 22868 || s[6] != 32 ? (v0 = (const char **)voice_modem) : (voice_modem = &Dr_Neuhaus, v0 = (const char **)&Dr_Neuhaus),
v0 != (const char **)&no_modem) )
{
lprintf(4LL, "%s detected", *v0);
lprintf(5LL, "voice modem type was set by ATI9 partial match");
return 0LL;
}
v1 = strchr(s, 40);
v2 = v1;
if ( v1 )
{
v3 = v1[1];
if ( v3 )
{
if ( v3 == 1 )
{
v2 = v1 + 3;
}
else
{
v4 = *_ctype_b_loc();
while ( 1 )
{
++v2;
if ( (v4[v3] & 0x800) == 0 && v3 != 46 )
break;
v3 = v2[1];
}
}
lprintf(5LL, "PNP String: '%s'", v2);
v5 = 0LL;
s2 = v2 + 3;
v6 = "SUP";
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
while ( v6 )
{
v7 = 4 * v5;
v8 = (const char *)qword_1748[4 * v5];
if ( v8 )
{
lprintf(6LL, "checking pnpid %s / modelid %s", v6, (const char *)qword_1748[4 * v5]);
if ( !strncmp(v6, v2, 3uLL) && !strncmp(v8, s2, 4uLL) )
{
LABEL_32:
v9 = 4LL * (int)v5;
lprintf(4LL, "PNP: found modem: %s", off_1758[v9]);
voice_modem = *(void **)((char *)&off_1750 + v9 * 8);
break;
}
}
else
{
lprintf(6LL, "checking pnpid %s / modelid %s", v6, "<none>");
if ( !strncmp(v6, v2, 3uLL) )
goto LABEL_32;
}
++v5;
if ( (_UNKNOWN *)voice_modem != &no_modem )
break;
v6 = off_1760[v7];
}
}
voice_read(s);
}
}
voice_flush(3LL);
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(5LL, "voice modem type was set by pnp id");
return 0LL;
}
if ( (unsigned int)voice_command("ATI3", &unk_71E) || (unsigned int)voice_read(s) )
goto LABEL_88;
if ( !strstr(s, "OK") && !strstr(s, "ERROR") && !(unsigned int)voice_read(s) && strstr(s, "SupraExpress 56e PRO") )
voice_modem = &Supra56ePRO;
voice_flush(1LL);
if ( (_UNKNOWN *)voice_modem != &no_modem )
{
lprintf(4LL, "%s detected", (const char *)*voice_modem);
lprintf(5LL, "voice modem type was set by using identification strings");
return 0LL;
}
if ( (unsigned int)voice_command("ATI", &unk_71E) )
{
LABEL_88:
lprintf(3LL, "modem detection failed");
LABEL_87:
exit(-1);
}
v11 = "ATI";
do
{
if ( (unsigned int)voice_read(s) )
goto LABEL_88;
v12 = &s[strlen(s) - 1];
for ( i = *_ctype_b_loc(); v12 >= s; *v12-- = 0 )
{
if ( (i[*v12] & 0x2000) == 0 )
break;
}
for ( j = s; (i[*j] & 0x2000) != 0; ++j )
;
v15 = (char *)voice_modem;
v16 = &off_FA8;
v17 = "ATI";
while ( 1 )
{
if ( v15 != (char *)&no_modem )
goto LABEL_70;
if ( !strcmp(v17, v11) && !strcmp(*v16, j) )
break;
LABEL_68:
v17 = v16[3];
v16 += 4;
if ( !v17 )
goto LABEL_75;
}
v18 = v16[1];
if ( !v18 )
{
v15 = v16[2];
voice_modem = v15;
goto LABEL_68;
}
voice_flush(1LL);
if ( (unsigned int)voice_command(v18, &unk_71E) )
goto LABEL_88;
v15 = (char *)voice_modem;
v11 = v18;
strcpy(s, "OK");
LABEL_75:
;
}
while ( v15 == (char *)&no_modem && (unsigned int)voice_analyze(s, &unk_71E, 1LL) != 0x4000 );
LABEL_70:
voice_flush(1LL);
v19 = (const char **)voice_modem;
if ( !*(_QWORD *)(voice_modem + 304LL) )
{
lprintf(3LL, "%s detected, but driver is not available", (const char *)*voice_modem);
voice_modem = &no_modem;
exit(-1);
}
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_command("AT+FCLASS=8", "OK");
if ( (unsigned int)voice_command("AT+VSM=1,8000", "OK") == 4096 )
voice_modem = &V253modem;
voice_command("AT+FCLASS=0", "OK");
v19 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_flush(1LL);
voice_modem = &no_modem;
lprintf(3LL, "no voice modem detected");
goto LABEL_87;
}
}
lprintf(4LL, "%s detected", *v19);
return 0LL;
}

original_code:
int voice_detect_modemtype(void)
     {
     char buffer[(256)];
     char *cmnd;
     lprintf(4, "detecting voice modem type");
     if (voice_modem != &no_modem)
          {
          lprintf(5, "voice modem type was set directly");
          return((0));
          }
     else
          {
          int i;
          char *s;
   if (cvd.command_delay.d.i != 0)
   delay(cvd.command_delay.d.i);
          if (cvd.enable_command_echo.d.i)
               {
               if (voice_write("ATE1") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               if ((voice_command("", "OK|ATE1") & (0x1000)) == (0x1000))
                    voice_flush(1);
               else
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               }
          else
               {
               if (voice_write("ATE0") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               voice_flush(3);
               }
   memset( buffer, '\0', sizeof(buffer) );
   cmnd=(char *)ati9;
   if (voice_command(cmnd, "") != (0))
               {
               lprintf(3, "modem detection failed");
               exit((-1));
               }
   if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
   }
          if((0==0)==cvd.forceV253.d.i)
          {
             lprintf(5, "V253 forced");
             voice_modem = &V253modem;
          }
          if((0==0)==cvd.forceV253subset.d.i)
          {
             lprintf(5, "V253ugly forced");
             voice_modem = &V253ugly;
          }
          i = 0;
          while ((voice_modem == &no_modem) && (pnp_partial_matches[i].s)) {
             if (!strncmp(pnp_partial_matches[i].s,
                          buffer,
                          strlen(pnp_partial_matches[i].s))) {
                voice_modem = pnp_partial_matches[i].modem_type;
             }
             i++;
          }
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5,
                     "voice modem type was set by ATI9 partial match");
             return((0));
          }
   s = strchr(buffer, '(');
   if ( s && s[1] != '\0' )
   {
       if ( s[1] == '\1' )
    s+=3;
       else
           do { s++; } while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISdigit) || *s == '.' );
       lprintf(5, "PNP String: '%s'", s);
       i = 0;
       while (voice_modem == &no_modem &&
       pnp_modem_database[i].pnpid)
       {
     lprintf(6, "checking pnpid %s / modelid %s",
          pnp_modem_database[i].pnpid,
          pnp_modem_database[i].modelid ?
       pnp_modem_database[i].modelid : "<none>");
     if (strncmp(pnp_modem_database[i].pnpid, s, 3) == 0)
     {
         if (pnp_modem_database[i].modelid == ((void *)0) ||
      strncmp(pnp_modem_database[i].modelid, s+3, 4) == 0)
         {
      lprintf( 4, "PNP: found modem: %s",
     pnp_modem_database[i].verbose );
      voice_modem = pnp_modem_database[i].modem_type;
      break;
         }
     }
     i++;
        }
        voice_read(buffer);
   }
   voice_flush(3);
   if (voice_modem != &no_modem)
    {
           lprintf(5, "voice modem type was set by pnp id");
           return((0));
          }
   cmnd = (char *) ati3;
   if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if (voice_read(buffer) != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if ((strstr(buffer, "OK") == ((void *)0))
              && (strstr(buffer, "ERROR") == ((void *)0))) {
             if (voice_read(buffer) == (0)) {
                if (strstr(buffer, "SupraExpress 56e PRO")) {
                   voice_modem = &Supra56ePRO;
                }
             }
          }
          voice_flush(1);
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5, "voice modem type was set by using                               identification strings");
             return((0));
          }
          cmnd = (char *) ati;
          if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               s = buffer + strlen(buffer) - 1;
               while ((s >= buffer) && ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) )
                    *s-- = '\0';
               s = buffer;
        while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) ) s++;
               for (i = 0; ((modem_database[i].at_cmnd != ((void *)0)) &&
                (voice_modem == &no_modem)); i++)
                    {
                    if ((strcmp(modem_database[i].at_cmnd, cmnd) == 0) &&
                     (strcmp(modem_database[i].at_answr, s) == 0))
                         {
                         if (modem_database[i].next_cmnd != ((void *)0))
                              {
                              voice_flush(1);
                              cmnd = (char *) modem_database[i].next_cmnd;
                              if (voice_command(cmnd, "") != (0))
                                   {
                                   lprintf(3, "modem detection failed");
                                   exit((-1));
                                   }
                              sprintf(buffer, "OK");
                              break;
                              }
                         else
                              voice_modem = modem_database[i].modem_type;
                         }
                    }
               }
          while ((voice_modem == &no_modem) &&
           (voice_analyze(buffer, "", (0==0)) != (0x4000)));
          voice_flush(1);
          }
     if (voice_modem->init == ((void *)0))
          {
          lprintf(3, "%s detected, but driver is not available",
           voice_modem->name);
          voice_modem = &no_modem;
          exit((-1));
          };
     if (voice_modem == &no_modem) {
        voice_command("AT+FCLASS=8", "OK");
        if (voice_command("AT+VSM=1,8000", "OK")== (0x1000)) {
           voice_modem=&V253modem;
        }
        voice_command("AT+FCLASS=0", "OK");
     }
     if (voice_modem != &no_modem)
          {
          lprintf(4, "%s detected", voice_modem->name);
          return((0));
          };
     voice_flush(1);
     voice_modem = &no_modem;
     lprintf(3, "no voice modem detected");
     exit((-1));
     }

canonical_original_code:
int voice_detect_modemtype()
     {
     char buffer[-1];
     char *cmnd;
     lprintf(4, "detecting voice modem type");
     if (voice_modem != &no_modem)
          {
          lprintf(5, "voice modem type was set directly");
          return((0));
          }
     else
          {
          int i;
          char *s;
   if (cvd.command_delay.d.i != 0)
   delay(cvd.command_delay.d.i);
          if (cvd.enable_command_echo.d.i)
               {
               if (voice_write("ATE1") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               if ((voice_command("", "OK|ATE1") & (0x1000)) == (0x1000))
                    voice_flush(1);
               else
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               }
          else
               {
               if (voice_write("ATE0") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               voice_flush(3);
               }
   memset( buffer, '\0', sizeof(buffer) );
   cmnd=(char *)ati9;
   if (voice_command(cmnd, "") != (0))
               {
               lprintf(3, "modem detection failed");
               exit((-1));
               }
   if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
   }
          if((0==0)==cvd.forceV253.d.i)
          {
             lprintf(5, "V253 forced");
             voice_modem = &V253modem;
          }
          if((0==0)==cvd.forceV253subset.d.i)
          {
             lprintf(5, "V253ugly forced");
             voice_modem = &V253ugly;
          }
          i = 0;
          while ((voice_modem == &no_modem) && (pnp_partial_matches[i].s)) {
             if (!strncmp(pnp_partial_matches[i].s,
                          buffer,
                          strlen(pnp_partial_matches[i].s))) {
                voice_modem = pnp_partial_matches[i].modem_type;
             }
             i++;
          }
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5,
                     "voice modem type was set by ATI9 partial match");
             return((0));
          }
   s = strchr(buffer, '(');
   if ( s && s[1] != '\0' )
   {
       if ( s[1] == '\1' )
    s+=3;
       else
           do { s++; } while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISdigit) || *s == '.' );
       lprintf(5, "PNP String: '%s'", s);
       i = 0;
       while (voice_modem == &no_modem &&
       pnp_modem_database[i].pnpid)
       {
     lprintf(6, "checking pnpid %s / modelid %s",
          pnp_modem_database[i].pnpid,
          pnp_modem_database[i].modelid ?
       pnp_modem_database[i].modelid : "<none>");
     if (strncmp(pnp_modem_database[i].pnpid, s, 3) == 0)
     {
         if (pnp_modem_database[i].modelid == ((void *)0) ||
      strncmp(pnp_modem_database[i].modelid, s+3, 4) == 0)
         {
      lprintf( 4, "PNP: found modem: %s",
     pnp_modem_database[i].verbose );
      voice_modem = pnp_modem_database[i].modem_type;
      break;
         }
     }
     i++;
        }
        voice_read(buffer);
   }
   voice_flush(3);
   if (voice_modem != &no_modem)
    {
           lprintf(5, "voice modem type was set by pnp id");
           return((0));
          }
   cmnd = (char *) ati3;
   if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if (voice_read(buffer) != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if ((strstr(buffer, "OK") == ((void *)0))
              && (strstr(buffer, "ERROR") == ((void *)0))) {
             if (voice_read(buffer) == (0)) {
                if (strstr(buffer, "SupraExpress 56e PRO")) {
                   voice_modem = &Supra56ePRO;
                }
             }
          }
          voice_flush(1);
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5, "voice modem type was set by using                               identification strings");
             return((0));
          }
          cmnd = (char *) ati;
          if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               s = buffer + strlen(buffer) - 1;
               while ((s >= buffer) && ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) )
                    *s-- = '\0';
               s = buffer;
        while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) ) s++;
               for (i = 0; ((modem_database[i].at_cmnd != ((void *)0)) &&
                (voice_modem == &no_modem)); i++)
                    {
                    if ((strcmp(modem_database[i].at_cmnd, cmnd) == 0) &&
                     (strcmp(modem_database[i].at_answr, s) == 0))
                         {
                         if (modem_database[i].next_cmnd != ((void *)0))
                              {
                              voice_flush(1);
                              cmnd = (char *) modem_database[i].next_cmnd;
                              if (voice_command(cmnd, "") != (0))
                                   {
                                   lprintf(3, "modem detection failed");
                                   exit((-1));
                                   }
                              sprintf(buffer, "OK");
                              break;
                              }
                         else
                              voice_modem = modem_database[i].modem_type;
                         }
                    }
               }
          while ((voice_modem == &no_modem) &&
           (voice_analyze(buffer, "", (0==0)) != (0x4000)));
          voice_flush(1);
          }
     if (voice_modem->init == ((void *)0))
          {
          lprintf(3, "%s detected, but driver is not available",
           voice_modem->name);
          voice_modem = &no_modem;
          exit((-1));
          };
     if (voice_modem == &no_modem) {
        voice_command("AT+FCLASS=8", "OK");
        if (voice_command("AT+VSM=1,8000", "OK")== (0x1000)) {
           voice_modem=&V253modem;
        }
        voice_command("AT+FCLASS=0", "OK");
     }
     if (voice_modem != &no_modem)
          {
          lprintf(4, "%s detected", voice_modem->name);
          return((0));
          };
     voice_flush(1);
     voice_modem = &no_modem;
     lprintf(3, "no voice modem detected");
     exit((-1));
     }

variable_types:
cmnd
char *

variable_types: i int

variable_types:
s
char *


mydup

decompiled_code:
void *__fastcall mydup(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
if ( !v2 )
{
lprintf(1LL, "mydup can't malloc");
exit(1);
}
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
if ( !v2 )
{
lprintf(1LL, "mydup can't malloc");
exit(1);
}
return memcpy(v2, src, v1);
}

original_code:
char * mydup (register char *s)
{
    register char *p = (char *) malloc(strlen(s) + 1);
    if (!p) {
 lprintf(1, "mydup can't malloc");
 exit(1);
    }
    strcpy(p, s);
    return(p);
}

canonical_original_code:
char *mydup(char *s)
{
    register char *p = (char *) malloc(strlen(s) + 1);
    if (!p) {
 lprintf(1, "mydup can't malloc");
 exit(1);
    }
    strcpy(p, s);
    return(p);
}

variable_types:
p
char *

return_type: char *


faxinit

decompiled_code:
void faxinit()
{
FillTable((__int64)&MainTable, 7, Pass, 1);
FillTable((__int64)&MainTable, 7, Horiz, 2);
FillTable((__int64)&MainTable, 7, V0, 3);
FillTable((__int64)&MainTable, 7, VR, 4);
FillTable((__int64)&MainTable, 7, VL, 5);
FillTable((__int64)&MainTable, 7, (unsigned __int16 *)ExtV, 6);
FillTable((__int64)&MainTable, 7, EOLV, 12);
FillTable((__int64)&WhiteTable, 12, MakeUpW, 9);
FillTable((__int64)&WhiteTable, 12, MakeUp, 11);
FillTable((__int64)&WhiteTable, 12, TermW, 7);
FillTable((__int64)&WhiteTable, 12, ExtH, 6);
FillTable((__int64)&WhiteTable, 12, EOLH, 12);
FillTable((__int64)&BlackTable, 13, MakeUpB, 10);
FillTable((__int64)&BlackTable, 13, MakeUp, 11);
FillTable((__int64)&BlackTable, 13, TermB, 8);
FillTable((__int64)&BlackTable, 13, ExtH, 6);
FillTable((__int64)&BlackTable, 13, EOLH, 12);
}

canonical_decompiled_code:
void func1()
{
func0((__int64)&MainTable, 7, Pass, 1);
func0((__int64)&MainTable, 7, Horiz, 2);
func0((__int64)&MainTable, 7, V0, 3);
func0((__int64)&MainTable, 7, VR, 4);
func0((__int64)&MainTable, 7, VL, 5);
func0((__int64)&MainTable, 7, (unsigned __int16 *)ExtV, 6);
func0((__int64)&MainTable, 7, EOLV, 12);
func0((__int64)&WhiteTable, 12, MakeUpW, 9);
func0((__int64)&WhiteTable, 12, MakeUp, 11);
func0((__int64)&WhiteTable, 12, TermW, 7);
func0((__int64)&WhiteTable, 12, ExtH, 6);
func0((__int64)&WhiteTable, 12, EOLH, 12);
func0((__int64)&BlackTable, 13, MakeUpB, 10);
func0((__int64)&BlackTable, 13, MakeUp, 11);
func0((__int64)&BlackTable, 13, TermB, 8);
func0((__int64)&BlackTable, 13, ExtH, 6);
func0((__int64)&BlackTable, 13, EOLH, 12);
}

original_code:
void
faxinit(void)
{
    FillTable(MainTable, 7, Pass, 1);
    FillTable(MainTable, 7, Horiz, 2);
    FillTable(MainTable, 7, V0, 3);
    FillTable(MainTable, 7, VR, 4);
    FillTable(MainTable, 7, VL, 5);
    FillTable(MainTable, 7, ExtV, 6);
    FillTable(MainTable, 7, EOLV, 12);
    FillTable(WhiteTable, 12, MakeUpW, 9);
    FillTable(WhiteTable, 12, MakeUp, 11);
    FillTable(WhiteTable, 12, TermW, 7);
    FillTable(WhiteTable, 12, ExtH, 6);
    FillTable(WhiteTable, 12, EOLH, 12);
    FillTable(BlackTable, 13, MakeUpB, 10);
    FillTable(BlackTable, 13, MakeUp, 11);
    FillTable(BlackTable, 13, TermB, 8);
    FillTable(BlackTable, 13, ExtH, 6);
    FillTable(BlackTable, 13, EOLH, 12);
}

canonical_original_code:
void faxinit()
{
    FillTable(MainTable, 7, Pass, 1);
    FillTable(MainTable, 7, Horiz, 2);
    FillTable(MainTable, 7, V0, 3);
    FillTable(MainTable, 7, VR, 4);
    FillTable(MainTable, 7, VL, 5);
    FillTable(MainTable, 7, ExtV, 6);
    FillTable(MainTable, 7, EOLV, 12);
    FillTable(WhiteTable, 12, MakeUpW, 9);
    FillTable(WhiteTable, 12, MakeUp, 11);
    FillTable(WhiteTable, 12, TermW, 7);
    FillTable(WhiteTable, 12, ExtH, 6);
    FillTable(WhiteTable, 12, EOLH, 12);
    FillTable(BlackTable, 13, MakeUpB, 10);
    FillTable(BlackTable, 13, MakeUp, 11);
    FillTable(BlackTable, 13, TermB, 8);
    FillTable(BlackTable, 13, ExtH, 6);
    FillTable(BlackTable, 13, EOLH, 12);
}


decompiled_code:
__int64 __fastcall gsm_option(__int64 a1, int a2, _DWORD *a3)
{
__int64 result; // rax

if ( a2 != 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)*(char *)(a1 + 654);
if ( a3 )
*(_BYTE *)(a1 + 654) = *a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, _DWORD *a3)
{
__int64 result; // rax

if ( a2 != 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)*(char *)(a1 + 654);
if ( a3 )
*(_BYTE *)(a1 + 654) = *a3;
return result;
}

original_code:
int gsm_option (gsm r, int opt, int * val)
{
     int result = -1;
     switch (opt) {
     case 3:
          break;
     case 1:
          result = r->verbose;
          if (val) r->verbose = *val;
          break;
     case 2:
          break;
     default:
          break;
     }
     return result;
}

canonical_original_code:
int gsm_option(struct gsm_state *r, int opt, int *val)
{
     int result = -1;
     switch (opt) {
     case 3:
          break;
     case 1:
          result = r->verbose;
          if (val) r->verbose = *val;
          break;
     case 2:
          break;
     default:
          break;
     }
     return result;
}

variable_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; } *

variable_types: opt int

variable_types:
val
int *

variable_types: result int


timeout

decompiled_code:
void timeout()
{
has_timeout = 1;
}

canonical_decompiled_code:
void func0()
{
has_timeout = 1;
}

original_code:
static RETSIGTYPE timeout()
{
    has_timeout = (1==1);
}

canonical_original_code:
static void timeout()
{
    has_timeout = (1==1);
}


decompiled_code:
const char *__fastcall voice_device_mode_name(int a1)
{
const char *result; // rax
__int64 v2[14]; // [rsp+0h] [rbp-70h]

v2[0] = (__int64)"undefined";
result = "undefined";
v2[1] = (__int64)"No Device";
v2[2] = (__int64)"Dialup Line";
v2[3] = (__int64)"Ext. Microphone";
v2[4] = (__int64)"Int. Microphone";
v2[5] = (__int64)"Ext. Speaker";
v2[6] = (__int64)"Int. Speaker";
v2[7] = (__int64)"Local Handset";
v2[8] = (__int64)"Dialup Line and Ext. Speaker";
v2[9] = (__int64)"Dialup Line and Int. Speaker";
v2[10] = (__int64)"Dialup Line and Local Handset";
v2[11] = (__int64)"Dialup Line, Ext. Mic. and Ext. Speaker";
v2[12] = (__int64)"Dialup Line, Int. Mic. and Int. Speaker";
if ( a1 <= 12 )
result = (const char *)v2[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax
__int64 v2[14]; // [rsp+0h] [rbp-70h]

v2[0] = (__int64)"undefined";
result = "undefined";
v2[1] = (__int64)"No Device";
v2[2] = (__int64)"Dialup Line";
v2[3] = (__int64)"Ext. Microphone";
v2[4] = (__int64)"Int. Microphone";
v2[5] = (__int64)"Ext. Speaker";
v2[6] = (__int64)"Int. Speaker";
v2[7] = (__int64)"Local Handset";
v2[8] = (__int64)"Dialup Line and Ext. Speaker";
v2[9] = (__int64)"Dialup Line and Int. Speaker";
v2[10] = (__int64)"Dialup Line and Local Handset";
v2[11] = (__int64)"Dialup Line, Ext. Mic. and Ext. Speaker";
v2[12] = (__int64)"Dialup Line, Int. Mic. and Int. Speaker";
if ( a1 <= 12 )
result = (const char *)v2[a1];
return result;
}

original_code:
char *voice_device_mode_name(int device_number)
     {
       char* device_name[(0x000C)+1] =
       {"undefined",
 "No Device",
 "Dialup Line",
 "Ext. Microphone",
 "Int. Microphone",
 "Ext. Speaker",
 "Int. Speaker",
 "Local Handset",
 "Dialup Line and Ext. Speaker",
 "Dialup Line and Int. Speaker",
 "Dialup Line and Local Handset",
 "Dialup Line, Ext. Mic. and Ext. Speaker",
 "Dialup Line, Int. Mic. and Int. Speaker"};
     if (device_number > (0x000C))
       {
  return(device_name[0]);
       }
     else
       {
  return(device_name[device_number]);
       };
     }

canonical_original_code:
char *voice_device_mode_name(int device_number)
     {
       char *device_name[-1] = {"undefined",
 "No Device",
 "Dialup Line",
 "Ext. Microphone",
 "Int. Microphone",
 "Ext. Speaker",
 "Int. Speaker",
 "Local Handset",
 "Dialup Line and Ext. Speaker",
 "Dialup Line and Int. Speaker",
 "Dialup Line and Local Handset",
 "Dialup Line, Ext. Mic. and Ext. Speaker",
 "Dialup Line, Int. Mic. and Int. Speaker"};
     if (device_number > (0x000C))
       {
  return(device_name[0]);
       }
     else
       {
  return(device_name[device_number]);
       };
     }


decompiled_code:
__int64 voice_close_device()
{
unsigned int v0; // er12

lprintf(4LL, "closing voice modem device");
v0 = voice_fd;
if ( voice_fd == -1 )
{
lprintf(3LL, "no voice modem device open");
}
else
{
v0 = 0;
close(voice_fd);
voice_fd = -1;
rmlocks();
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12

lprintf(4LL, "closing voice modem device");
v0 = voice_fd;
if ( voice_fd == -1 )
{
lprintf(3LL, "no voice modem device open");
}
else
{
v0 = 0;
close(voice_fd);
voice_fd = -1;
rmlocks();
}
return v0;
}

original_code:
int voice_close_device(void)
     {
     lprintf(4, "closing voice modem device");
     if (voice_fd == (-1))
          {
          lprintf(3, "no voice modem device open");
          return((-1));
          };
     close(voice_fd);
     voice_fd = (-1);
     rmlocks();
     return((0));
     }

canonical_original_code:
int voice_close_device()
     {
     lprintf(4, "closing voice modem device");
     if (voice_fd == (-1))
          {
          lprintf(3, "no voice modem device open");
          return((-1));
          };
     close(voice_fd);
     voice_fd = (-1);
     rmlocks();
     return((0));
     }


decompiled_code:
__int64 __fastcall handle_event(int a1, char a2)
{
__int64 result; // rax
int v3; // eax
size_t v4; // rax

if ( use_on_hook_off_hook )
{
if ( a1 == 8200 )
{
if ( voice_modem_state == 7 )
{
(*(void (**)(void))(voice_modem + 408LL))();
result = 0LL;
start_action = 1;
return result;
}
}
else
{
if ( !use_on_hook_off_hook || a1 != 8199 )
goto LABEL_5;
v3 = voice_modem_state;
if ( voice_modem_state == 6 )
{
(*(void (**)(void))(voice_modem + 400LL))();
if ( !use_on_hook_off_hook )
return 0LL;
v3 = voice_modem_state;
}
if ( v3 == 5 )
{
(*(void (**)(void))(voice_modem + 392LL))();
return 0LL;
}
}
return 0LL;
}
LABEL_5:
if ( (unsigned int)(a1 - 8199) <= 1 )
return 0LL;
if ( a1 == 8209 )
{
result = dtmf_mode;
if ( dtmf_mode == 1 )
{
printf("%c\n", (unsigned int)a2);
voice_stop_current_action();
result = 0LL;
}
else if ( dtmf_mode == 2 )
{
if ( a2 == 42 )
{
dtmf_string_buffer = 0;
result = 0LL;
}
else
{
v4 = strlen(&dtmf_string_buffer);
if ( a2 == 35 || v4 == 255 )
{
puts(&dtmf_string_buffer);
voice_stop_current_action();
result = 0LL;
}
else
{
*(&dtmf_string_buffer + (int)v4 + 1) = 0;
*(&dtmf_string_buffer + (int)v4) = a2;
result = 0LL;
}
}
}
else if ( dtmf_mode )
{
result = 4294967294LL;
}
}
else if ( a1 == 16387 )
{
result = voice_stop_current_action();
}
else
{
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2)
{
__int64 result; // rax
int v3; // eax
size_t v4; // rax

if ( use_on_hook_off_hook )
{
if ( a1 == 8200 )
{
if ( voice_modem_state == 7 )
{
(*(void (**)(void))(voice_modem + 408LL))();
result = 0LL;
start_action = 1;
return result;
}
}
else
{
if ( !use_on_hook_off_hook || a1 != 8199 )
goto LABEL_5;
v3 = voice_modem_state;
if ( voice_modem_state == 6 )
{
(*(void (**)(void))(voice_modem + 400LL))();
if ( !use_on_hook_off_hook )
return 0LL;
v3 = voice_modem_state;
}
if ( v3 == 5 )
{
(*(void (**)(void))(voice_modem + 392LL))();
return 0LL;
}
}
return 0LL;
}
LABEL_5:
if ( (unsigned int)(a1 - 8199) <= 1 )
return 0LL;
if ( a1 == 8209 )
{
result = dtmf_mode;
if ( dtmf_mode == 1 )
{
printf("%c\n", (unsigned int)a2);
voice_stop_current_action();
result = 0LL;
}
else if ( dtmf_mode == 2 )
{
if ( a2 == 42 )
{
dtmf_string_buffer = 0;
result = 0LL;
}
else
{
v4 = strlen(&dtmf_string_buffer);
if ( a2 == 35 || v4 == 255 )
{
puts(&dtmf_string_buffer);
voice_stop_current_action();
result = 0LL;
}
else
{
*(&dtmf_string_buffer + (int)v4 + 1) = 0;
*(&dtmf_string_buffer + (int)v4) = a2;
result = 0LL;
}
}
}
else if ( dtmf_mode )
{
result = 4294967294LL;
}
}
else if ( a1 == 16387 )
{
result = voice_stop_current_action();
}
else
{
result = 4294967294LL;
}
return result;
}

original_code:
int handle_event(int event, event_data data)
     {
     if ((use_on_hook_off_hook) && (event == (0x2008)) &&
      (voice_modem_state == (0x0007)))
          {
          voice_modem->stop_waiting();
          start_action = (0==0);
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
      (voice_modem_state == (0x0006)))
          {
          voice_modem->stop_recording();
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
   (voice_modem_state == (0x0005)))
          {
          voice_modem->stop_playing();
          };
     if ((event == (0x2008)) || (event == (0x2007)))
          return((0));
     if (event == (0x2011))
          switch (dtmf_mode)
               {
               case (0):
                    return((0));
               case (1):
                    printf("%c\n", data.c);
                    voice_stop_current_action();
                    return((0));
               case (2):
      {
                       int length;
         if (data.c == '*')
       {
       dtmf_string_buffer[0] = 0x00;
       return((0));
       };
         length = strlen(dtmf_string_buffer);
         if ((data.c != '#') && (length < ((256) - 1)))
       {
       dtmf_string_buffer[length + 1] = 0x00;
       dtmf_string_buffer[length] = data.c;
       return((0));
       };
         printf("%s\n", dtmf_string_buffer);
         voice_stop_current_action();
         return((0));
                    }
               };
     if (event == (0x4003))
          return(voice_stop_current_action());
     return((-2));
     }

canonical_original_code:
int handle_event(int event, union event_data data)
     {
     if ((use_on_hook_off_hook) && (event == (0x2008)) &&
      (voice_modem_state == (0x0007)))
          {
          voice_modem->stop_waiting();
          start_action = (0==0);
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
      (voice_modem_state == (0x0006)))
          {
          voice_modem->stop_recording();
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
   (voice_modem_state == (0x0005)))
          {
          voice_modem->stop_playing();
          };
     if ((event == (0x2008)) || (event == (0x2007)))
          return((0));
     if (event == (0x2011))
          switch (dtmf_mode)
               {
               case (0):
                    return((0));
               case (1):
                    printf("%c\n", data.c);
                    voice_stop_current_action();
                    return((0));
               case (2):
      {
                       int length;
         if (data.c == '*')
       {
       dtmf_string_buffer[0] = 0x00;
       return((0));
       };
         length = strlen(dtmf_string_buffer);
         if ((data.c != '#') && (length < ((256) - 1)))
       {
       dtmf_string_buffer[length + 1] = 0x00;
       dtmf_string_buffer[length] = data.c;
       return((0));
       };
         printf("%s\n", dtmf_string_buffer);
         voice_stop_current_action();
         return((0));
                    }
               };
     if (event == (0x4003))
          return(voice_stop_current_action());
     return((-2));
     }

variable_types: event int

variable_types: union event_data { char c; int i; void *p; struct { int frequency; int length; } beep; }


decompiled_code:
__int64 __fastcall voice_command(const char *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v5; // eax
__int64 v6; // rdx
const char *v7; // rsi
_BYTE v8[296]; // [rsp+0h] [rbp-128h] BYREF

lprintf(5LL, "voice command: '%s' -> '%s'", a1, a2);
if ( cvd[31] )
delay();
v2 = 0x4000;
if ( *a1 )
{
v2 = voice_write("%s", a1);
if ( v2 )
{
LABEL_10:
v2 = 0x4000;
voice_flush(1LL);
return v2;
}
if ( cvd[85] )
{
while ( 1 )
{
if ( (unsigned int)voice_read(v8) )
goto LABEL_10;
v5 = voice_analyze(v8, a1, 1LL);
if ( v5 == 0x4000 )
break;
if ( v5 == 8195 )
{
LABEL_20:
v6 = program_name;
v7 = "%s: Modem returned ERROR";
LABEL_21:
v2 = 0x4000;
lprintf(3LL, v7, v6);
voice_flush(1LL);
return v2;
}
if ( v5 == 4096 )
goto LABEL_4;
}
v6 = program_name;
v7 = "%s: Modem did not echo the command";
goto LABEL_21;
}
}
LABEL_4:
if ( *a2 )
{
while ( !(unsigned int)voice_read(v8) )
{
v3 = voice_analyze(v8, a2, 0LL);
v2 = v3;
if ( v3 == 0x4000 )
{
lprintf(3LL, "%s: Invalid modem answer", program_name);
voice_flush(1LL);
return v2;
}
if ( v3 == 8195 )
goto LABEL_20;
if ( (v3 & 0x1000) != 0 )
return v2;
}
goto LABEL_10;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v5; // eax
__int64 v6; // rdx
const char *v7; // rsi
_BYTE v8[296]; // [rsp+0h] [rbp-128h] BYREF

lprintf(5LL, "voice command: '%s' -> '%s'", a1, a2);
if ( cvd[31] )
delay();
v2 = 0x4000;
if ( *a1 )
{
v2 = voice_write("%s", a1);
if ( v2 )
{
LABEL_10:
v2 = 0x4000;
voice_flush(1LL);
return v2;
}
if ( cvd[85] )
{
while ( 1 )
{
if ( (unsigned int)voice_read(v8) )
goto LABEL_10;
v5 = voice_analyze(v8, a1, 1LL);
if ( v5 == 0x4000 )
break;
if ( v5 == 8195 )
{
LABEL_20:
v6 = program_name;
v7 = "%s: Modem returned ERROR";
LABEL_21:
v2 = 0x4000;
lprintf(3LL, v7, v6);
voice_flush(1LL);
return v2;
}
if ( v5 == 4096 )
goto LABEL_4;
}
v6 = program_name;
v7 = "%s: Modem did not echo the command";
goto LABEL_21;
}
}
LABEL_4:
if ( *a2 )
{
while ( !(unsigned int)voice_read(v8) )
{
v3 = voice_analyze(v8, a2, 0LL);
v2 = v3;
if ( v3 == 0x4000 )
{
lprintf(3LL, "%s: Invalid modem answer", program_name);
voice_flush(1LL);
return v2;
}
if ( v3 == 8195 )
goto LABEL_20;
if ( (v3 & 0x1000) != 0 )
return v2;
}
goto LABEL_10;
}
return v2;
}

original_code:
int voice_command(char *command, char *expected_answer)
     {
     char buffer[(256)];
     int result = (0x4000);
     lprintf(5, "voice command: '%s' -> '%s'", command,
      expected_answer);
     if (cvd.command_delay.d.i != 0)
          delay(cvd.command_delay.d.i);
     if (strlen(command) != 0)
          {
          if (voice_write("%s", command) != (0))
               {
               voice_flush(1);
               return((0x4000));
               };
          if (cvd.enable_command_echo.d.i)
               do
                    {
                    if (voice_read(buffer) != (0))
                         {
                         voice_flush(1);
                         return((0x4000));
                         };
                    result = voice_analyze(buffer, command, (0==0));
                    if (result == (0x4000))
                         {
                         lprintf(3,
                          "%s: Modem did not echo the command", program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    if (result == (0x2003))
                         {
                         lprintf(3, "%s: Modem returned ERROR",
                          program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    }
               while (result != (0x1000));
          result = (0);
          };
     if (strlen(expected_answer) != 0)
          {
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    voice_flush(1);
                    return((0x4000));
                    };
               result = voice_analyze(buffer, expected_answer, (0==1));
               if (result == (0x4000))
                    {
                    lprintf(3, "%s: Invalid modem answer",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               if (result == (0x2003))
                    {
                    lprintf(3, "%s: Modem returned ERROR",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               }
          while ((result & (0x1000)) != (0x1000));
          };
     return(result);
     }

canonical_original_code:
int voice_command(char *command, char *expected_answer)
     {
     char buffer[-1];
     int result = (0x4000);
     lprintf(5, "voice command: '%s' -> '%s'", command,
      expected_answer);
     if (cvd.command_delay.d.i != 0)
          delay(cvd.command_delay.d.i);
     if (strlen(command) != 0)
          {
          if (voice_write("%s", command) != (0))
               {
               voice_flush(1);
               return((0x4000));
               };
          if (cvd.enable_command_echo.d.i)
               do
                    {
                    if (voice_read(buffer) != (0))
                         {
                         voice_flush(1);
                         return((0x4000));
                         };
                    result = voice_analyze(buffer, command, (0==0));
                    if (result == (0x4000))
                         {
                         lprintf(3,
                          "%s: Modem did not echo the command", program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    if (result == (0x2003))
                         {
                         lprintf(3, "%s: Modem returned ERROR",
                          program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    }
               while (result != (0x1000));
          result = (0);
          };
     if (strlen(expected_answer) != 0)
          {
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    voice_flush(1);
                    return((0x4000));
                    };
               result = voice_analyze(buffer, expected_answer, (0==1));
               if (result == (0x4000))
                    {
                    lprintf(3, "%s: Invalid modem answer",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               if (result == (0x2003))
                    {
                    lprintf(3, "%s: Modem returned ERROR",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               }
          while ((result & (0x1000)) != (0x1000));
          };
     return(result);
     }

variable_types:
command
char *