decompiled_code:
void __fastcall __noreturn exit_usage(const char *a1)
{
fprintf(stderr, "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n", a1);
exit(1);
}

original_code:
void exit_usage (char * name)
{
    fprintf( stderr,
      "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n",
       name );
    exit(1);
}

canonical_original_code:
void exit_usage(char *name)
{
    fprintf( stderr,
      "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n",
       name );
    exit(1);
}

variable_types:
name
char *


main

canonical_name: main

repo: Distrotech/mgetty

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // eax
__int64 v6; // rdx
int v7; // er15
int v8; // er14
int i; // ebx
char *file; // [rsp+8h] [rbp-40h]

init_byte_tab(0LL, &out_byte_tab, envp);
v3 = 1728;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "h:w:dar");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
byte_align = 1;
break;
case 'd':
continue;
case 'h':
v4 = atoi(optarg);
break;
case 'r':
init_byte_tab(1LL, &out_byte_tab, v6);
break;
case 'w':
v3 = atoi(optarg);
break;
default:
exit_usage(*argv);
}
}
v7 = optind;
if ( optind == argc )
{
v8 = 0;
}
else
{
file = (char *)argv[optind];
v8 = strcmp(file, "-");
if ( v8 )
{
if ( v7 != argc - 1 )
exit_usage(*argv);
v8 = open(file, 0);
if ( v8 == -1 )
{
fprintf(stderr, "%s: cannot open %s: ", *argv, argv[optind]);
perror(&s);
exit(2);
}
}
}
pbm_getheader(v8);
if ( pbm_type )
{
if ( pbm_xsize != -1 && pbm_ysize != -1 )
{
if ( pbm_type != 2 && pbm_type != 5 )
{
if ( pbm_type != 3 && pbm_type != 6 )
{
if ( !v3 )
v3 = pbm_xsize;
if ( pbm_type == 4 && (int)((pbm_xsize + 7) & 0xFFFFFFF8) > v3 )
v3 = (v3 + 7) & 0xFFFFFFF8;
puteol();
for ( i = 0; i < v4; ++i )
{
putwhitespan((unsigned int)v3);
puteol();
}
if ( pbm_type == 1 )
convert_pbm(v8, v3);
else
convert_pbm_raw(v8, v3);
close(v8);
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
write(1, &buf, buflen);
exit(0);
}
fprintf(stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", *argv);
exit(3);
}
fprintf(stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", *argv);
exit(3);
}
fprintf(stderr, "%s: error reading PBM header\n", *argv);
exit(4);
}
fprintf(stderr, "%s: input file type unknown\n", *argv);
exit(3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // eax
__int64 v6; // rdx
int v7; // er15
int v8; // er14
int i; // ebx
char *file; // [rsp+8h] [rbp-40h]

init_byte_tab(0LL, &out_byte_tab, envp);
v3 = 1728;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "h:w:dar");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
byte_align = 1;
break;
case 'd':
continue;
case 'h':
v4 = atoi(optarg);
break;
case 'r':
init_byte_tab(1LL, &out_byte_tab, v6);
break;
case 'w':
v3 = atoi(optarg);
break;
default:
func2(*argv);
}
}
v7 = optind;
if ( optind == argc )
{
v8 = 0;
}
else
{
file = (char *)argv[optind];
v8 = strcmp(file, "-");
if ( v8 )
{
if ( v7 != argc - 1 )
func2(*argv);
v8 = open(file, 0);
if ( v8 == -1 )
{
fprintf(stderr, "%s: cannot open %s: ", *argv, argv[optind]);
perror(&s);
exit(2);
}
}
}
func1(v8);
if ( pbm_type )
{
if ( pbm_xsize != -1 && pbm_ysize != -1 )
{
if ( pbm_type != 2 && pbm_type != 5 )
{
if ( pbm_type != 3 && pbm_type != 6 )
{
if ( !v3 )
v3 = pbm_xsize;
if ( pbm_type == 4 && (int)((pbm_xsize + 7) & 0xFFFFFFF8) > v3 )
v3 = (v3 + 7) & 0xFFFFFFF8;
puteol();
for ( i = 0; i < v4; ++i )
{
putwhitespan((unsigned int)v3);
puteol();
}
if ( pbm_type == 1 )
func4(v8, v3);
else
func3(v8, v3);
close(v8);
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
write(1, &buf, buflen);
exit(0);
}
fprintf(stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", *argv);
exit(3);
}
fprintf(stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", *argv);
exit(3);
}
fprintf(stderr, "%s: error reading PBM header\n", *argv);
exit(4);
}
fprintf(stderr, "%s: input file type unknown\n", *argv);
exit(3);
}

original_code:
int main (int argc,char ** argv)
{
    int c, fd, i;
    int empty_lines = 0;
    int g3_page_width = 1728;
    int digifax_header = 0;
    init_byte_tab( 0, out_byte_tab );
    while ( (c = getopt(argc, argv, "h:w:dar") ) != (-1))
    {
 switch (c)
 {
   case 'h': empty_lines = atoi( optarg ); break;
   case 'w': g3_page_width = atoi( optarg ); break;
   case 'd': digifax_header = 1; break;
   case 'a': byte_align = 1; break;
   case 'r': init_byte_tab( 1, out_byte_tab ); break;
   default: exit_usage( argv[0] );
 }
    }
    if ( optind == argc ||
  strcmp( argv[optind], "-" ) == 0 )
    {
 fd = 0;
    }
    else
    {
 if ( optind != argc -1 ) exit_usage( argv[0] );
 fd = open( argv[optind], 00 );
 if ( fd == -1 )
 {
     fprintf( stderr, "%s: cannot open %s: ", argv[0], argv[optind] );
     perror( "" );
     exit(2);
 }
    }
    pbm_getheader( fd );
    if ( pbm_type == unknown )
    {
 fprintf( stderr, "%s: input file type unknown\n", argv[0] );
 exit(3);
    }
    if ( pbm_xsize == -1 || pbm_ysize == -1 )
    {
 fprintf( stderr, "%s: error reading PBM header\n", argv[0] );
 exit(4);
    }
    if ( pbm_type == pgm || pbm_type == pgm_raw )
    {
 fprintf( stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( pbm_type == ppm || pbm_type == ppm_raw )
    {
 fprintf( stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( g3_page_width == 0 ) g3_page_width = pbm_xsize;
    if ( pbm_type == pbm_raw && g3_page_width < ( ( pbm_xsize+7 ) & ~7) )
    {
 g3_page_width = ( g3_page_width + 7 ) & ~7;
    }
    puteol();
    for ( i=0; i<empty_lines; i++ )
    {
 putwhitespan( g3_page_width ); puteol();
    }
    if ( pbm_type == pbm )
    {
 convert_pbm( fd, g3_page_width );
    }
    else
    {
 convert_pbm_raw( fd, g3_page_width );
    }
    close( fd );
    for ( i=0; i<6; i++ ) puteol();
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int c; int fd; int i;
    int empty_lines = 0;
    int g3_page_width = 1728;
    int digifax_header = 0;
    init_byte_tab( 0, out_byte_tab );
    while ( (c = getopt(argc, argv, "h:w:dar") ) != (-1))
    {
 switch (c)
 {
   case 'h': empty_lines = atoi( optarg ); break;
   case 'w': g3_page_width = atoi( optarg ); break;
   case 'd': digifax_header = 1; break;
   case 'a': byte_align = 1; break;
   case 'r': init_byte_tab( 1, out_byte_tab ); break;
   default: exit_usage( argv[0] );
 }
    }
    if ( optind == argc ||
  strcmp( argv[optind], "-" ) == 0 )
    {
 fd = 0;
    }
    else
    {
 if ( optind != argc -1 ) exit_usage( argv[0] );
 fd = open( argv[optind], 00 );
 if ( fd == -1 )
 {
     fprintf( stderr, "%s: cannot open %s: ", argv[0], argv[optind] );
     perror( "" );
     exit(2);
 }
    }
    pbm_getheader( fd );
    if ( pbm_type == unknown )
    {
 fprintf( stderr, "%s: input file type unknown\n", argv[0] );
 exit(3);
    }
    if ( pbm_xsize == -1 || pbm_ysize == -1 )
    {
 fprintf( stderr, "%s: error reading PBM header\n", argv[0] );
 exit(4);
    }
    if ( pbm_type == pgm || pbm_type == pgm_raw )
    {
 fprintf( stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( pbm_type == ppm || pbm_type == ppm_raw )
    {
 fprintf( stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( g3_page_width == 0 ) g3_page_width = pbm_xsize;
    if ( pbm_type == pbm_raw && g3_page_width < ( ( pbm_xsize+7 ) & ~7) )
    {
 g3_page_width = ( g3_page_width + 7 ) & ~7;
    }
    puteol();
    for ( i=0; i<empty_lines; i++ )
    {
 putwhitespan( g3_page_width ); puteol();
    }
    if ( pbm_type == pbm )
    {
 convert_pbm( fd, g3_page_width );
    }
    else
    {
 convert_pbm_raw( fd, g3_page_width );
    }
    close( fd );
    for ( i=0; i<6; i++ ) puteol();
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: fd int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall conf_get_flow(const char *a1, __int64 a2)
{
bool v4; // zf
__int64 result; // rax

if ( !memcmp(a1, "rts", 3uLL) || !memcmp(a1, "hard", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 1LL;
result = 0LL;
}
else if ( !memcmp(a1, "xon", 3uLL) || !memcmp(a1, "soft", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 6LL;
result = 0LL;
}
else
{
v4 = strcmp(a1, "both") == 0;
result = !v4;
if ( v4 )
{
*(_QWORD *)(a2 + 8) = 7LL;
}
else
{
v4 = strcmp(a1, "none") == 0;
result = !v4;
if ( v4 )
{
*(_QWORD *)(a2 + 8) = 0LL;
}
else
{
lprintf(3LL, "conf_get_flow: unknown keyword '%s'", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
bool v4; // zf
__int64 result; // rax

if ( !memcmp(a1, "rts", 3uLL) || !memcmp(a1, "hard", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 1LL;
result = 0LL;
}
else if ( !memcmp(a1, "xon", 3uLL) || !memcmp(a1, "soft", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 6LL;
result = 0LL;
}
else
{
v4 = strcmp(a1, "both") == 0;
result = !v4;
if ( v4 )
{
*(_QWORD *)(a2 + 8) = 7LL;
}
else
{
v4 = strcmp(a1, "none") == 0;
result = !v4;
if ( v4 )
{
*(_QWORD *)(a2 + 8) = 0LL;
}
else
{
lprintf(3LL, "conf_get_flow: unknown keyword '%s'", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int conf_get_flow (char * line,conf_data * cp)
{
    if ( strncmp( line, "rts", 3 ) == 0 ||
  strncmp( line, "hard", 4 ) == 0 )
    {
 cp->d.i = 0x01; return 0;
    }
    if ( strncmp( line, "xon", 3 ) == 0 ||
         strncmp( line, "soft", 4 ) == 0 )
    {
 cp->d.i = (0x02 | 0x04); return 0;
    }
    if ( strcmp( line, "both" ) == 0 )
    {
 cp->d.i = (0x01 | (0x02 | 0x04) ); return 0;
    }
    if ( strcmp( line, "none" ) == 0 )
    {
 cp->d.i = 0x00; return 0;
    }
    lprintf( 3, "conf_get_flow: unknown keyword '%s'", line);
    return -1;
}

canonical_original_code:
int conf_get_flow(char *line, struct conf_data *cp)
{
    if ( strncmp( line, "rts", 3 ) == 0 ||
  strncmp( line, "hard", 4 ) == 0 )
    {
 cp->d.i = 0x01; return 0;
    }
    if ( strncmp( line, "xon", 3 ) == 0 ||
         strncmp( line, "soft", 4 ) == 0 )
    {
 cp->d.i = (0x02 | 0x04); return 0;
    }
    if ( strcmp( line, "both" ) == 0 )
    {
 cp->d.i = (0x01 | (0x02 | 0x04) ); return 0;
    }
    if ( strcmp( line, "none" ) == 0 )
    {
 cp->d.i = 0x00; return 0;
    }
    lprintf( 3, "conf_get_flow: unknown keyword '%s'", line);
    return -1;
}

variable_types:
line
char *

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


decompiled_code:
void __fastcall display_cd(const char **a1)
{
const char *v1; // rdx
const char **v2; // rbx
int v3; // eax
const char *v4; // rsi
const char *v5; // rbp
__int64 i; // rsi
char v7[136]; // [rsp-88h] [rbp-88h] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
lprintf(5LL, "key: '%s', type=%d, flags=%d, data=", v1, *((unsigned int *)v2 + 4), *((unsigned int *)v2 + 5));
v3 = *((_DWORD *)v2 + 5);
if ( v3 )
{
if ( v3 == 4 )
{
lputs(5LL, "(ignored)");
}
else
{
switch ( *((_DWORD *)v2 + 4) )
{
case 0:
case 4:
sprintf(v7, "%ld", v2[1]);
lputs(5LL, v7);
break;
case 1:
lputs(5LL, v2[1]);
break;
case 2:
v5 = v2[1];
for ( i = *(_QWORD *)v5; *(_QWORD *)v5; i = *(_QWORD *)v5 )
{
lputs(5LL, i);
lputc(5LL, 32LL);
v5 += 8;
}
break;
case 3:
v4 = "FALSE";
if ( v2[1] )
v4 = "TRUE";
lputs(5LL, v4);
break;
default:
lputs(5LL, "**unprintable**");
break;
}
}
}
else
{
lputs(5LL, "(empty)");
}
v2 += 3;
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(const char **a1)
{
const char *v1; // rdx
const char **v2; // rbx
int v3; // eax
const char *v4; // rsi
const char *v5; // rbp
__int64 i; // rsi
char v7[136]; // [rsp-88h] [rbp-88h] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
lprintf(5LL, "key: '%s', type=%d, flags=%d, data=", v1, *((unsigned int *)v2 + 4), *((unsigned int *)v2 + 5));
v3 = *((_DWORD *)v2 + 5);
if ( v3 )
{
if ( v3 == 4 )
{
lputs(5LL, "(ignored)");
}
else
{
switch ( *((_DWORD *)v2 + 4) )
{
case 0:
case 4:
sprintf(v7, "%ld", v2[1]);
lputs(5LL, v7);
break;
case 1:
lputs(5LL, v2[1]);
break;
case 2:
v5 = v2[1];
for ( i = *(_QWORD *)v5; *(_QWORD *)v5; i = *(_QWORD *)v5 )
{
lputs(5LL, i);
lputc(5LL, 32LL);
v5 += 8;
}
break;
case 3:
v4 = "FALSE";
if ( v2[1] )
v4 = "TRUE";
lputs(5LL, v4);
break;
default:
lputs(5LL, "**unprintable**");
break;
}
}
}
else
{
lputs(5LL, "(empty)");
}
v2 += 3;
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void display_cd (conf_data * cd)
{
conf_data * cp;
char ** p;
    cp = cd;
    while ( cp->key != ((void *)0) )
    {
    char buf[100];
 lprintf( 5, "key: '%s', type=%d, flags=%d, data=",
  cp->key, cp->type, cp->flags );
 if ( cp->flags == C_EMPTY )
  lputs( 5, "(empty)" );
 else
 if ( cp->flags == C_IGNORE )
  lputs( 5, "(ignored)" );
 else
   switch ( cp->type )
 {
     case CT_FLOWL:
     case CT_INT: sprintf( buf, "%ld", cp->d.i );
    lputs( 5, buf );
    break;
     case CT_STRING:
    lputs( 5, (char *) cp->d.p );
    break;
     case CT_BOOL:
    lputs( 5, cp->d.i ? "TRUE" : "FALSE" );
    break;
     case CT_CHAT:
    p = (char **) cp->d.p;
    while ( *p != ((void *)0) )
    {
        lputs( 5, *p ); lputc( 5, ' ');
        p++;
    }
    break;
     default:
    lputs( 5, "**unprintable**" );
    break;
 }
 cp++;
    }
}

canonical_original_code:
void display_cd(struct conf_data *cd)
{
struct conf_data *cp;
char **p;
    cp = cd;
    while ( cp->key != ((void *)0) )
    {
    char buf[100];
 lprintf( 5, "key: '%s', type=%d, flags=%d, data=",
  cp->key, cp->type, cp->flags );
 if ( cp->flags == C_EMPTY )
  lputs( 5, "(empty)" );
 else
 if ( cp->flags == C_IGNORE )
  lputs( 5, "(ignored)" );
 else
   switch ( cp->type )
 {
     case CT_FLOWL:
     case CT_INT: sprintf( buf, "%ld", cp->d.i );
    lputs( 5, buf );
    break;
     case CT_STRING:
    lputs( 5, (char *) cp->d.p );
    break;
     case CT_BOOL:
    lputs( 5, cp->d.i ? "TRUE" : "FALSE" );
    break;
     case CT_CHAT:
    p = (char **) cp->d.p;
    while ( *p != ((void *)0) )
    {
        lputs( 5, *p ); lputc( 5, ' ');
        p++;
    }
    break;
     default:
    lputs( 5, "**unprintable**" );
    break;
 }
 cp++;
    }
}

variable_types:
p
char **

variable_types:
buf
char [100]

return_type: void

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:
__int64 __fastcall UMC_switch_to_data_fax(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
sprintf(v2, "AT#CLS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
sprintf(v2, "AT#CLS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

original_code:
int UMC_switch_to_data_fax(char *mode)
     {
     char buffer[(256)];
     reset_watchdog();
     sprintf(buffer, "AT#CLS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int UMC_switch_to_data_fax(char *mode)
     {
     char buffer[-1];
     reset_watchdog();
     sprintf(buffer, "AT#CLS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types:
mode
char *

variable_types:
buffer
char [-1]


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

reset_watchdog();
if ( current_device >= 0 && current_device != a1 )
voice_command("ATH0", "VCON|OK");
current_device = a1;
voice_command("AT#CLS=8", "OK");
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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 func1(unsigned int a1)
{
__int64 result; // rax

reset_watchdog();
if ( current_device >= 0 && current_device != a1 )
voice_command("ATH0", "VCON|OK");
current_device = a1;
voice_command("AT#CLS=8", "OK");
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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 UMC_set_device(int device)
     {
     reset_watchdog();
     if ((current_device != device) && (current_device >= 0))
          voice_command("ATH0","VCON|OK");
     current_device=device;
     voice_command("AT#CLS=8", "OK");
     switch (device)
          {
          case (0x0001):
               voice_command("AT#VLS=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT#VLS=4", "OK");
               return((0));
          case (0x0003):
               voice_command("AT#VLS=3", "VCON");
               return((0));
          case (0x0006):
               voice_command("AT#VLS=2", "VCON");
               return((0));
          case (0x0007):
               voice_command("AT#VLS=1","VCON");
               return((0));
          }
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

variable_types: device int


decompiled_code:
__int64 __fastcall UMC_set_compression(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

reset_watchdog();
if ( *a1 )
{
if ( *a2 )
goto LABEL_6;
}
else
{
*a1 = 4LL;
if ( *a2 )
{
LABEL_3:
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=4", "OK") != 4096);
}
}
*a2 = 7200LL;
LABEL_6:
v5 = *a1;
if ( *a1 == 3 )
{
*a3 = 3;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=3", "OK") != 4096);
}
else
{
if ( v5 == 4 )
goto LABEL_3;
if ( v5 == 2 )
{
*a3 = 2;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=2", "OK") != 4096);
}
else
{
lprintf(3LL, "UMC handle event: Illegal voice compression method (%d)", v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

reset_watchdog();
if ( *a1 )
{
if ( *a2 )
goto LABEL_6;
}
else
{
*a1 = 4LL;
if ( *a2 )
{
LABEL_3:
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=4", "OK") != 4096);
}
}
*a2 = 7200LL;
LABEL_6:
v5 = *a1;
if ( *a1 == 3 )
{
*a3 = 3;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=3", "OK") != 4096);
}
else
{
if ( v5 == 4 )
goto LABEL_3;
if ( v5 == 2 )
{
*a3 = 2;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=2", "OK") != 4096);
}
else
{
lprintf(3LL, "UMC handle event: Illegal voice compression method (%d)", v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int UMC_set_compression(p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 7200;
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 3:
               *bits=3;
               if (voice_command("AT#VBS=3", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "UMC handle event: Illegal voice compression method (%d)",
      (int)*compression);
     return((-1));
     }

canonical_original_code:
static int UMC_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 7200;
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 3:
               *bits=3;
               if (voice_command("AT#VBS=3", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "UMC handle event: Illegal voice compression method (%d)",
      (int)*compression);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


decompiled_code:
__int64 __fastcall UMC_beep(unsigned int a1, int a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( a2 > 4000 )
lprintf(
3LL,
"%s->%s: Warning beeps longer than 4000 ms might not be supported.",
program_name,
(const char *)*voice_modem);
lprintf(
6LL,
"%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
program_name,
(const char *)*voice_modem);
sprintf(v3, "AT#VTS=[%d,0,%d]", a1, (unsigned int)(a2 / 100));
return (unsigned int)-((unsigned int)voice_command(v3, "OK") != 4096);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( a2 > 4000 )
lprintf(
3LL,
"%s->%s: Warning beeps longer than 4000 ms might not be supported.",
program_name,
(const char *)*voice_modem);
lprintf(
6LL,
"%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
program_name,
(const char *)*voice_modem);
sprintf(v3, "AT#VTS=[%d,0,%d]", a1, (unsigned int)(a2 / 100));
return (unsigned int)-((unsigned int)voice_command(v3, "OK") != 4096);
}

original_code:
static int UMC_beep(int frequency, int length)
     {
     char buffer[(256)];
     reset_watchdog();
     if (length > 4000 )
          lprintf(3, "%s->%s: Warning beeps longer than 4000 ms might not be supported.",
    program_name, voice_modem->name);
     lprintf(6, "%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
      program_name, voice_modem->name);
     sprintf(buffer, "AT#VTS=[%d,0,%d]", frequency, length / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
static int UMC_beep(int frequency, int length)
     {
     char buffer[-1];
     reset_watchdog();
     if (length > 4000 )
          lprintf(3, "%s->%s: Warning beeps longer than 4000 ms might not be supported.",
    program_name, voice_modem->name);
     lprintf(6, "%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
      program_name, voice_modem->name);
     sprintf(buffer, "AT#VTS=[%d,0,%d]", frequency, length / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 UMC_init()
{
unsigned __int64 v0; // rax
__int64 result; // rax
_BYTE v2[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing UMC voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v0 = *((_QWORD *)&cvd + 58);
if ( v0 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v0 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int64 v0; // rax
__int64 result; // rax
_BYTE v2[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing UMC voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v0 = *((_QWORD *)&cvd + 58);
if ( v0 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v0 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

original_code:
static int UMC_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     lprintf(4, "initializing UMC voice modem");
     voice_modem_state = (0x0002);
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period");
     if (voice_command("AT#VSD=0", "OK") != (0x1000))
         lprintf(3, "can't disable silence deletion");
    if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
         lprintf(3, "can't set DLE responses");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          TIO tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int UMC_init()
     {
     char buffer[-1];
     reset_watchdog();
     lprintf(4, "initializing UMC voice modem");
     voice_modem_state = (0x0002);
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period");
     if (voice_command("AT#VSD=0", "OK") != (0x1000))
         lprintf(3, "can't disable silence deletion");
    if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
         lprintf(3, "can't set DLE responses");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          struct termios tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
void fax_send_timeout()
{
signal(14, fax_send_timeout);
lprintf(3LL, "fax_send: timeout");
fax_sendpg_timeout = 1;
}

canonical_decompiled_code:
void func0()
{
signal(14, fax_send_timeout);
lprintf(3LL, "fax_send: timeout");
fax_sendpg_timeout = 1;
}

original_code:
static RETSIGTYPE fax_send_timeout()
{
    signal( 14, fax_send_timeout );
    lprintf( 3, "fax_send: timeout" );
    fax_sendpg_timeout = (1==1);
}

canonical_original_code:
static void fax_send_timeout()
{
    signal( 14, fax_send_timeout );
    lprintf( 3, "fax_send: timeout" );
    fax_sendpg_timeout = (1==1);
}


decompiled_code:
void __fastcall __noreturn fax_send_panic_exit(int fd)
{
lprintf(0LL, "PANIC: timeout sending fax page data, trying force modem reset\n");
alarm(5u);
tio_flush_queue((unsigned int)fd, 2LL);
alarm(5u);
tio_flow((unsigned int)fd, 1LL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, "AT+FK\r\n", 7uLL);
alarm(5u);
write(fd, "ATH0\r\n", 6uLL);
alarm(0xAu);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
alarm(5u);
write(fd, "ATH0Z\r\n", 7uLL);
delay(500LL);
alarm(0);
rmlocks();
exit(15);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int fd)
{
lprintf(0LL, "PANIC: timeout sending fax page data, trying force modem reset\n");
alarm(5u);
tio_flush_queue((unsigned int)fd, 2LL);
alarm(5u);
tio_flow((unsigned int)fd, 1LL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, "AT+FK\r\n", 7uLL);
alarm(5u);
write(fd, "ATH0\r\n", 6uLL);
alarm(0xAu);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
alarm(5u);
write(fd, "ATH0Z\r\n", 7uLL);
delay(500LL);
alarm(0);
rmlocks();
exit(15);
}

original_code:
static void fax_send_panic_exit (int fd)
{
    lprintf( 0, "PANIC: timeout sending fax page data, trying force modem reset\n" );
    alarm( 5 ); tio_flush_queue( fd, 0x02 );
    alarm( 5 ); tio_flow( fd, (1==1) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, "AT+FK\r\n", 7 );
    alarm( 5 ); write( fd, "ATH0\r\n", 6 );
    alarm( 10 );
    tio_toggle_dtr( fd, 500 );
    delay(500);
    tio_toggle_dtr( fd, 500 );
    delay(500);
    alarm( 5 ); write( fd, "ATH0Z\r\n", 7 );
    delay(500);
    alarm( 0 );
    rmlocks();
    exit(15);
}

canonical_original_code:
static void fax_send_panic_exit(int fd)
{
    lprintf( 0, "PANIC: timeout sending fax page data, trying force modem reset\n" );
    alarm( 5 ); tio_flush_queue( fd, 0x02 );
    alarm( 5 ); tio_flow( fd, (1==1) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, "AT+FK\r\n", 7 );
    alarm( 5 ); write( fd, "ATH0\r\n", 6 );
    alarm( 10 );
    tio_toggle_dtr( fd, 500 );
    delay(500);
    tio_toggle_dtr( fd, 500 );
    delay(500);
    alarm( 5 ); write( fd, "ATH0Z\r\n", 7 );
    delay(500);
    alarm( 0 );
    rmlocks();
    exit(15);
}


decompiled_code:
__int64 __fastcall fax_send_ppm(int fd, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v6; // bl
const char *v7; // rax
const char *v8; // rbx
const char *v9; // rax
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

alarm(0x78u);
if ( modem_type == 5 )
{
if ( a3 == 1 )
{
v6 = 59;
}
else if ( a3 == 2 )
{
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
v6 = 46;
}
else
{
if ( a3 )
{
LABEL_5:
lprintf(3LL, "ppm type %d not implemented", a3);
return 0xFFFFFFFFLL;
}
v6 = 44;
}
lprintf(4LL, "sending DLE '");
lputc(4LL, (unsigned int)v6);
lputc(4LL, 39LL);
buf[0] = 16;
buf[1] = v6;
if ( write(fd, buf, 2uLL) == 2 )
{
while ( 1 )
{
v7 = (const char *)mdm_get_line((unsigned int)fd);
v8 = v7;
if ( !v7 )
break;
if ( !memcmp(v7, "+FHS:", 5uLL) )
{
fax_hangup = 1;
signal(1, (__sighandler_t)((char *)fax_send_timeout + 1));
_isoc99_sscanf(v8 + 5, "%d", &fax_hangup_code);
lprintf(4LL, "connection hangup: '%s'", v8);
v9 = (const char *)fax_strerror(fax_hangup_code);
lprintf(5LL, "(%s)", v9);
}
if ( !strcmp(v8, "OK") || !strcmp(v8, "ERROR") )
{
lprintf(4LL, "got response: '%s'", v8);
fax_page_tx_status = 1 - ((strcmp(v8, "OK") == 0) - 1);
return 0LL;
}
}
result = 0xFFFFFFFFLL;
}
else
{
lprintf(1LL, "cannot write PPM");
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(4LL, "sending DLE ETX...");
write(fd, &fax_end_of_page, 2uLL);
result = fax_wait_for("OK", (unsigned int)fd);
if ( (_DWORD)result != -1 )
{
if ( a3 == 1 )
{
result = fax_command("AT+FET=1", "OK", (unsigned int)fd);
}
else if ( a3 == 2 )
{
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
result = fax_command("AT+FET=2", "OK", (unsigned int)fd);
}
else
{
if ( a3 )
goto LABEL_5;
result = fax_command("AT+FET=0", "OK", (unsigned int)fd);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v6; // bl
const char *v7; // rax
const char *v8; // rbx
const char *v9; // rax
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

alarm(0x78u);
if ( modem_type == 5 )
{
if ( a3 == 1 )
{
v6 = 59;
}
else if ( a3 == 2 )
{
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
v6 = 46;
}
else
{
if ( a3 )
{
LABEL_5:
lprintf(3LL, "ppm type %d not implemented", a3);
return 0xFFFFFFFFLL;
}
v6 = 44;
}
lprintf(4LL, "sending DLE '");
lputc(4LL, (unsigned int)v6);
lputc(4LL, 39LL);
buf[0] = 16;
buf[1] = v6;
if ( write(fd, buf, 2uLL) == 2 )
{
while ( 1 )
{
v7 = (const char *)mdm_get_line((unsigned int)fd);
v8 = v7;
if ( !v7 )
break;
if ( !memcmp(v7, "+FHS:", 5uLL) )
{
fax_hangup = 1;
signal(1, (__sighandler_t)((char *)fax_send_timeout + 1));
_isoc99_sscanf(v8 + 5, "%d", &fax_hangup_code);
lprintf(4LL, "connection hangup: '%s'", v8);
v9 = (const char *)fax_strerror(fax_hangup_code);
lprintf(5LL, "(%s)", v9);
}
if ( !strcmp(v8, "OK") || !strcmp(v8, "ERROR") )
{
lprintf(4LL, "got response: '%s'", v8);
fax_page_tx_status = 1 - ((strcmp(v8, "OK") == 0) - 1);
return 0LL;
}
}
result = 0xFFFFFFFFLL;
}
else
{
lprintf(1LL, "cannot write PPM");
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(4LL, "sending DLE ETX...");
write(fd, &fax_end_of_page, 2uLL);
result = fax_wait_for("OK", (unsigned int)fd);
if ( (_DWORD)result != -1 )
{
if ( a3 == 1 )
{
result = fax_command("AT+FET=1", "OK", (unsigned int)fd);
}
else if ( a3 == 2 )
{
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
result = fax_command("AT+FET=2", "OK", (unsigned int)fd);
}
else
{
if ( a3 )
goto LABEL_5;
result = fax_command("AT+FET=0", "OK", (unsigned int)fd);
}
}
}
return result;
}

original_code:
int fax_send_ppm (int fd,TIO * tio,Post_page_messages ppm)
{
    int rc;
    alarm( 120 );
    if ( modem_type == Mt_class2_0 )
    {
 char ppm_char, ppm_buf[2], *ppm_r;
 switch( ppm )
 {
   case pp_mps:
     ppm_char = 0x2c; break;
   case pp_eom:
     ppm_char = 0x3b; break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     ppm_char = 0x2e; break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     return -1;
 }
 lprintf( 4, "sending DLE '" );
 lputc( 4, ppm_char ); lputc( 4, '\'' );
 ppm_buf[0] = 020; ppm_buf[1] = ppm_char;
 if ( write( fd, ppm_buf, 2 ) != 2 )
 {
     lprintf( 1, "cannot write PPM" );
     return -1;
 }
 do
 {
     ppm_r = mdm_get_line( fd );
     if ( ppm_r == ((void *)0) ) return -1;
     if ( strncmp( ppm_r, "+FHS:", 5 ) == 0 )
     {
  fax_hangup = 1;
  signal( 1, ((__sighandler_t) 1) );
  sscanf( &ppm_r[5], "%d", &fax_hangup_code );
  lprintf( 4, "connection hangup: '%s'", ppm_r );
  lprintf( 5,"(%s)", fax_strerror( fax_hangup_code ));
     }
 }
 while ( strcmp( ppm_r, "OK" ) != 0 &&
         strcmp( ppm_r, "ERROR" ) != 0 );
 lprintf( 4, "got response: '%s'", ppm_r );
 fax_page_tx_status = ( strcmp( ppm_r, "OK" ) == 0 ) ? 1: 2;
 return 0;
    }
    else
    {
 lprintf( 4, "sending DLE ETX..." );
 write( fd, fax_end_of_page, sizeof( fax_end_of_page ));
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 switch ( ppm )
 {
   case pp_mps:
     rc = fax_command( "AT+FET=0", "OK", fd );
     break;
   case pp_eom:
     rc = fax_command( "AT+FET=1", "OK", fd );
     break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     rc = fax_command( "AT+FET=2", "OK", fd );
     break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     rc = -1;
 }
 return rc;
    }
}

canonical_original_code:
int fax_send_ppm(int fd, struct termios *tio, enum Post_page_messages ppm)
{
    int rc;
    alarm( 120 );
    if ( modem_type == Mt_class2_0 )
    {
 char ppm_char; char ppm_buf[2]; char *ppm_r;
 switch( ppm )
 {
   case pp_mps:
     ppm_char = 0x2c; break;
   case pp_eom:
     ppm_char = 0x3b; break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     ppm_char = 0x2e; break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     return -1;
 }
 lprintf( 4, "sending DLE '" );
 lputc( 4, ppm_char ); lputc( 4, '\'' );
 ppm_buf[0] = 020; ppm_buf[1] = ppm_char;
 if ( write( fd, ppm_buf, 2 ) != 2 )
 {
     lprintf( 1, "cannot write PPM" );
     return -1;
 }
 do
 {
     ppm_r = mdm_get_line( fd );
     if ( ppm_r == ((void *)0) ) return -1;
     if ( strncmp( ppm_r, "+FHS:", 5 ) == 0 )
     {
  fax_hangup = 1;
  signal( 1, ((void (*)(int)) 1) );
  sscanf( &ppm_r[5], "%d", &fax_hangup_code );
  lprintf( 4, "connection hangup: '%s'", ppm_r );
  lprintf( 5,"(%s)", fax_strerror( fax_hangup_code ));
     }
 }
 while ( strcmp( ppm_r, "OK" ) != 0 &&
         strcmp( ppm_r, "ERROR" ) != 0 );
 lprintf( 4, "got response: '%s'", ppm_r );
 fax_page_tx_status = ( strcmp( ppm_r, "OK" ) == 0 ) ? 1: 2;
 return 0;
    }
    else
    {
 lprintf( 4, "sending DLE ETX..." );
 write( fd, fax_end_of_page, sizeof( fax_end_of_page ));
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 switch ( ppm )
 {
   case pp_mps:
     rc = fax_command( "AT+FET=0", "OK", fd );
     break;
   case pp_eom:
     rc = fax_command( "AT+FET=1", "OK", fd );
     break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     rc = fax_command( "AT+FET=2", "OK", fd );
     break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     rc = -1;
 }
 return rc;
    }
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *

variable_types: enum Post_page_messages { pp_mps=0, pp_eom=1, pp_eop=2, pp_pri_mps=3, pp_pri_eom=4, pp_pri_eop=5 }

variable_types: rc int


decompiled_code:
__int64 __fastcall fax_send_page(char *file, _DWORD *a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // r15
char v7; // r15
int v8; // er14
unsigned int v9; // ebx
const char *v10; // rcx
const char *v11; // rdx
int v12; // er12
bool v13; // zf
unsigned int v14; // ebx
__int64 v15; // rax
char v16; // dl
unsigned int v17; // ecx
int fd; // [rsp+4h] [rbp-3D4h]
unsigned int v21; // [rsp+18h] [rbp-3C0h]
char buf[96]; // [rsp+20h] [rbp-3B8h] BYREF
int v24; // [rsp+80h] [rbp-358h]
char v25[512]; // [rsp+90h] [rbp-348h] BYREF
unsigned __int8 v26; // [rsp+290h] [rbp-148h] BYREF
char v27[28]; // [rsp+291h] [rbp-147h] BYREF
char v28; // [rsp+2ADh] [rbp-12Bh]
char v29[57]; // [rsp+39Fh] [rbp-39h] BYREF

v5 = a3;
lprintf(5LL, "fax_send_page(\"%s\") started...", file);
tio_set_flow_control(a5, v5, 1LL);
tio_set(a5, v5);
if ( (unsigned int)fax_command("AT+FDT", "CONNECT", a5) == -1 || fax_hangup )
{
lprintf(3LL, "AT+FDT -> some error (%d), abort fax send!", fax_hangup_code);
return (unsigned int)-1;
}
signal(14, (__sighandler_t)fax_send_timeout);
if ( modem_type == 4 && (modem_quirks & 8) == 0 )
{
lprintf(5LL, "waiting for XON, got:");
alarm(0x14u);
do
{
if ( (unsigned int)mdm_read_byte(a5, v29) != 1 )
{
lprintf(1LL, "timeout waiting for XON");
fwrite("error waiting for XON!\n", 1uLL, 0x17uLL, stderr);
close(a5);
exit(11);
}
lputc(5LL, (unsigned int)v29[0]);
}
while ( v29[0] != 17 );
alarm(0);
}
tio_set_flow_control(a5, a3, 5LL);
tio_set(a5, a3);
lprintf(4LL, "sending %s...", file);
fd = open(file, 0);
if ( fd == -1 )
{
lprintf(1LL, "cannot open %s", file);
lprintf(3LL, "have to send empty page instead");
v21 = 0;
goto LABEL_57;
}
if ( (modem_quirks & 0x10) != 0 )
{
lprintf(4LL, "send %d 0-bytes (pad before first EOL)...", 100LL);
memset(buf, 0, sizeof(buf));
v24 = 0;
write(a5, buf, 0x64uLL);
}
alarm(0x28u);
v7 = 1;
v8 = 0;
v21 = 0;
LABEL_27:
while ( 1 )
{
v12 = read(fd, &v26, 0x40uLL);
if ( v12 <= 0 )
break;
if ( v8 > 1000 )
{
v8 -= 1000;
alarm(0x1Eu);
}
if ( !v7 )
goto LABEL_41;
if ( v12 <= 63 )
{
if ( v12 <= 1 )
goto LABEL_38;
LABEL_33:
if ( v26 == 73 )
{
if ( v27[0] == 73 )
goto LABEL_44;
LABEL_38:
if ( v12 <= 9 || v26 )
{
lprintf(
3LL,
"file looks 'suspicious', buf=%02x %02x %02x %02x...",
v26,
(unsigned __int8)v27[0],
(unsigned __int8)v27[1],
(unsigned __int8)v27[2]);
fwrite("WARNING: are you sure that this is a G3 fax file? Doesn't seem to be...\n", 1uLL, 0x48uLL, stderr);
}
}
else
{
if ( v26 != 77 || v27[0] != 77 )
goto LABEL_38;
LABEL_44:
lprintf(3LL, "file may be 'tiffg3' - TIFF is *not* a valid input format");
fwrite("WARNING: file may be 'tiffg3' - TIFF file format is *not* supported!\n", 1uLL, 0x45uLL, stderr);
fwrite(" Thus, fax transmission will most propably fail\n", 1uLL, 0x38uLL, stderr);
}
LABEL_41:
LODWORD(v15) = 0;
goto LABEL_42;
}
v13 = strcmp(v27, "PC Research, Inc") == 0;
v14 = !v13;
if ( !v13 )
goto LABEL_33;
lprintf(4LL, "skipping over GhostScript header");
if ( (fax_par_d != 0) != (v28 != 0) )
{
v10 = "fine";
if ( !v28 )
v10 = "normal";
v11 = "fine";
if ( !fax_par_d )
v11 = "normal";
fprintf(stderr, "WARNING: sending in %s mode, fax data is %s mode\n", v11, v10);
lprintf(3LL, "resolution mismatch");
}
if ( v12 <= 64 )
goto LABEL_23;
LODWORD(v15) = 64;
LABEL_42:
v15 = (int)v15;
v14 = 0;
do
{
v16 = *((_BYTE *)&fax_send_swaptable + *(&v26 + v15));
v25[v14] = v16;
v17 = v14 + 1;
if ( v16 == 16 )
{
v14 += 2;
v25[v17] = 16;
}
else
{
++v14;
}
++v15;
}
while ( v12 > (int)v15 );
LABEL_23:
lprintf(6LL, "read %d, write %d", (unsigned int)v12, v14);
if ( write(a5, v25, (int)v14) != v14 )
lprintf(1LL, "could not write all %d bytes", v14);
v7 = fax_sendpg_timeout;
if ( fax_sendpg_timeout )
fax_send_panic_exit(a5);
v21 += v14;
v8 += v14;
if ( (unsigned __int8)check_for_input(a5) )
{
lprintf(5LL, "input: got ");
while ( read(a5, v29, 1uLL) == 1 )
{
lputc(5LL, (unsigned int)v29[0]);
if ( !(unsigned __int8)check_for_input(a5) )
goto LABEL_27;
}
lprintf(1LL, "read failed");
}
}
close(fd);
LABEL_57:
lprintf(4LL, "page complete, %d bytes sent", v21);
if ( a2 )
*a2 += v21;
v9 = fax_send_ppm(a5, a3, a4);
alarm(0);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *file, _DWORD *a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // r15
char v7; // r15
int v8; // er14
unsigned int v9; // ebx
const char *v10; // rcx
const char *v11; // rdx
int v12; // er12
bool v13; // zf
unsigned int v14; // ebx
__int64 v15; // rax
char v16; // dl
unsigned int v17; // ecx
int fd; // [rsp+4h] [rbp-3D4h]
unsigned int v21; // [rsp+18h] [rbp-3C0h]
char buf[96]; // [rsp+20h] [rbp-3B8h] BYREF
int v24; // [rsp+80h] [rbp-358h]
char v25[512]; // [rsp+90h] [rbp-348h] BYREF
unsigned __int8 v26; // [rsp+290h] [rbp-148h] BYREF
char v27[28]; // [rsp+291h] [rbp-147h] BYREF
char v28; // [rsp+2ADh] [rbp-12Bh]
char v29[57]; // [rsp+39Fh] [rbp-39h] BYREF

v5 = a3;
lprintf(5LL, "fax_send_page(\"%s\") started...", file);
tio_set_flow_control(a5, v5, 1LL);
tio_set(a5, v5);
if ( (unsigned int)fax_command("AT+FDT", "CONNECT", a5) == -1 || fax_hangup )
{
lprintf(3LL, "AT+FDT -> some error (%d), abort fax send!", fax_hangup_code);
return (unsigned int)-1;
}
signal(14, (__sighandler_t)fax_send_timeout);
if ( modem_type == 4 && (modem_quirks & 8) == 0 )
{
lprintf(5LL, "waiting for XON, got:");
alarm(0x14u);
do
{
if ( (unsigned int)mdm_read_byte(a5, v29) != 1 )
{
lprintf(1LL, "timeout waiting for XON");
fwrite("error waiting for XON!\n", 1uLL, 0x17uLL, stderr);
close(a5);
exit(11);
}
lputc(5LL, (unsigned int)v29[0]);
}
while ( v29[0] != 17 );
alarm(0);
}
tio_set_flow_control(a5, a3, 5LL);
tio_set(a5, a3);
lprintf(4LL, "sending %s...", file);
fd = open(file, 0);
if ( fd == -1 )
{
lprintf(1LL, "cannot open %s", file);
lprintf(3LL, "have to send empty page instead");
v21 = 0;
goto LABEL_57;
}
if ( (modem_quirks & 0x10) != 0 )
{
lprintf(4LL, "send %d 0-bytes (pad before first EOL)...", 100LL);
memset(buf, 0, sizeof(buf));
v24 = 0;
write(a5, buf, 0x64uLL);
}
alarm(0x28u);
v7 = 1;
v8 = 0;
v21 = 0;
LABEL_27:
while ( 1 )
{
v12 = read(fd, &v26, 0x40uLL);
if ( v12 <= 0 )
break;
if ( v8 > 1000 )
{
v8 -= 1000;
alarm(0x1Eu);
}
if ( !v7 )
goto LABEL_41;
if ( v12 <= 63 )
{
if ( v12 <= 1 )
goto LABEL_38;
LABEL_33:
if ( v26 == 73 )
{
if ( v27[0] == 73 )
goto LABEL_44;
LABEL_38:
if ( v12 <= 9 || v26 )
{
lprintf(
3LL,
"file looks 'suspicious', buf=%02x %02x %02x %02x...",
v26,
(unsigned __int8)v27[0],
(unsigned __int8)v27[1],
(unsigned __int8)v27[2]);
fwrite("WARNING: are you sure that this is a G3 fax file? Doesn't seem to be...\n", 1uLL, 0x48uLL, stderr);
}
}
else
{
if ( v26 != 77 || v27[0] != 77 )
goto LABEL_38;
LABEL_44:
lprintf(3LL, "file may be 'tiffg3' - TIFF is *not* a valid input format");
fwrite("WARNING: file may be 'tiffg3' - TIFF file format is *not* supported!\n", 1uLL, 0x45uLL, stderr);
fwrite(" Thus, fax transmission will most propably fail\n", 1uLL, 0x38uLL, stderr);
}
LABEL_41:
LODWORD(v15) = 0;
goto LABEL_42;
}
v13 = strcmp(v27, "PC Research, Inc") == 0;
v14 = !v13;
if ( !v13 )
goto LABEL_33;
lprintf(4LL, "skipping over GhostScript header");
if ( (fax_par_d != 0) != (v28 != 0) )
{
v10 = "fine";
if ( !v28 )
v10 = "normal";
v11 = "fine";
if ( !fax_par_d )
v11 = "normal";
fprintf(stderr, "WARNING: sending in %s mode, fax data is %s mode\n", v11, v10);
lprintf(3LL, "resolution mismatch");
}
if ( v12 <= 64 )
goto LABEL_23;
LODWORD(v15) = 64;
LABEL_42:
v15 = (int)v15;
v14 = 0;
do
{
v16 = *((_BYTE *)&fax_send_swaptable + *(&v26 + v15));
v25[v14] = v16;
v17 = v14 + 1;
if ( v16 == 16 )
{
v14 += 2;
v25[v17] = 16;
}
else
{
++v14;
}
++v15;
}
while ( v12 > (int)v15 );
LABEL_23:
lprintf(6LL, "read %d, write %d", (unsigned int)v12, v14);
if ( write(a5, v25, (int)v14) != v14 )
lprintf(1LL, "could not write all %d bytes", v14);
v7 = fax_sendpg_timeout;
if ( fax_sendpg_timeout )
func1(a5);
v21 += v14;
v8 += v14;
if ( (unsigned __int8)check_for_input(a5) )
{
lprintf(5LL, "input: got ");
while ( read(a5, v29, 1uLL) == 1 )
{
lputc(5LL, (unsigned int)v29[0]);
if ( !(unsigned __int8)check_for_input(a5) )
goto LABEL_27;
}
lprintf(1LL, "read failed");
}
}
close(fd);
LABEL_57:
lprintf(4LL, "page complete, %d bytes sent", v21);
if ( a2 )
*a2 += v21;
v9 = func2(a5, a3, a4);
alarm(0);
return v9;
}

original_code:
int fax_send_page (char * g3_file,int * bytes_sent,TIO * tio,Post_page_messages ppm,int fd)
{
    int g3fd;
    char ch;
    char buf[256];
    char wbuf[ sizeof(buf) * 2 ];
    int w_total = 0;
    int rc;
    lprintf( 5, "fax_send_page(\"%s\") started...", g3_file );
    tio_set_flow_control( fd, tio, (0x01 | (0x02 | 0x04)) & 0x01 );
    tio_set( fd, tio );
    if ( fax_command( "AT+FDT", "CONNECT", fd ) == -1 ||
  fax_hangup != 0 )
    {
 lprintf( 3, "AT+FDT -> some error (%d), abort fax send!",
   fax_hangup_code );
 return -1;
    }
    signal( 14, fax_send_timeout );
    if ( modem_type == Mt_class2 &&
  ( modem_quirks & 0x08 ) == 0 )
    {
 lprintf( 5, "waiting for XON, got:" );
 alarm( 20 );
 do
 {
     if ( mdm_read_byte( fd, &ch ) != 1 )
     {
  lprintf( 1, "timeout waiting for XON" );
  fprintf( stderr, "error waiting for XON!\n" );
  close( fd );
  exit(11);
     }
     lputc( 5, ch );
 }
 while ( ch != 021 );
 alarm(0);
    }
    tio_set_flow_control( fd, tio, (0x01 | (0x02 | 0x04)) & (0x01|0x04));
    tio_set( fd, tio );
    lprintf( 4, "sending %s...", g3_file );
    g3fd = open( g3_file, 00 );
    if ( g3fd == -1 )
    {
 lprintf( 1, "cannot open %s", g3_file );
 lprintf( 3, "have to send empty page instead" );
    }
    else
    {
 int r, i, w;
 int w_refresh = 0;
 boolean first = (1==1);
 if ( modem_quirks & 0x10 )
 {
     char nbuf[100];
     lprintf( 4, "send %d 0-bytes (pad before first EOL)...", sizeof(nbuf) );
     bzero( nbuf, sizeof(nbuf) );
     write( fd, nbuf, sizeof(nbuf) );
 }
 alarm( 40 );
 while ( ( r = read( g3fd, buf, 64 ) ) > 0 )
 {
     if ( w_refresh > 1000 )
     {
  w_refresh -= 1000;
  alarm( 30 );
     }
     i = 0;
     if ( first )
     {
  first = (1==0);
  if ( r >= 64 && strcmp( buf+1,
     "PC Research, Inc" ) == 0 )
  {
      lprintf( 4, "skipping over GhostScript header" );
      i = 64;
      if ( ( fax_par_d.vr != 0 ) != ( buf[29] != 0 ) )
      {
   fprintf( stderr, "WARNING: sending in %s mode, fax data is %s mode\n",
     fax_par_d.vr? "fine" : "normal",
     buf[29] ? "fine" : "normal" );
   lprintf( 3, "resolution mismatch" );
      }
  }
                else
                if ( r >= 2 && ( ( buf[0] == 0x49 && buf[1] == 0x49 ) ||
                                 ( buf[0] == 0x4d && buf[1] == 0x4d ) ) )
  {
      lprintf( 3, "file may be 'tiffg3' - TIFF is *not* a valid input format" );
      fprintf( stderr, "WARNING: file may be 'tiffg3' - TIFF file format is *not* supported!\n" );
      fprintf( stderr, "         Thus, fax transmission will most propably fail\n" );
  }
                else
                if ( r < 10 || buf[0] != 0 )
  {
      lprintf( 3, "file looks 'suspicious', buf=%02x %02x %02x %02x...", buf[0] &0xff, buf[1] &0xff, buf[2] &0xff, buf[3] &0xff );
                    fprintf( stderr, "WARNING: are you sure that this is a G3 fax file? Doesn't seem to be...\n" );
  }
     }
     for ( w = 0; i < r; i++ )
     {
  wbuf[ w ] = fax_send_swaptable[ (unsigned char) buf[i] ];
  if ( wbuf[ w++ ] == 020 ) wbuf[ w++ ] = 020;
     }
     lprintf( 6, "read %d, write %d", r, w );
     if ( write( fd, wbuf, w ) != w )
     {
  lprintf( 1, "could not write all %d bytes", w );
     }
     if ( fax_sendpg_timeout )
     {
  fax_send_panic_exit( fd );
     }
     w_total += w;
     w_refresh += w;
     if ( check_for_input( fd ) )
     {
  lprintf( 5, "input: got " );
  do
  {
      if ( read( fd, &ch, 1 ) != 1 )
      {
   lprintf( 1, "read failed" );
   break;
      }
      else
   lputc( 5, ch );
  }
  while ( check_for_input( fd ) );
     }
 }
 close(g3fd);
    }
    lprintf( 4, "page complete, %d bytes sent", w_total );
    if ( bytes_sent != ((void *)0) )
            *bytes_sent += w_total;
    rc = fax_send_ppm( fd, tio, ppm );
    alarm(0);
    return rc;
}

canonical_original_code:
int fax_send_page(char *g3_file, int *bytes_sent, struct termios *tio, enum Post_page_messages ppm, int fd)
{
    int g3fd;
    char ch;
    char buf[256];
    char wbuf[-1];
    int w_total = 0;
    int rc;
    lprintf( 5, "fax_send_page(\"%s\") started...", g3_file );
    tio_set_flow_control( fd, tio, (0x01 | (0x02 | 0x04)) & 0x01 );
    tio_set( fd, tio );
    if ( fax_command( "AT+FDT", "CONNECT", fd ) == -1 ||
  fax_hangup != 0 )
    {
 lprintf( 3, "AT+FDT -> some error (%d), abort fax send!",
   fax_hangup_code );
 return -1;
    }
    signal( 14, fax_send_timeout );
    if ( modem_type == Mt_class2 &&
  ( modem_quirks & 0x08 ) == 0 )
    {
 lprintf( 5, "waiting for XON, got:" );
 alarm( 20 );
 do
 {
     if ( mdm_read_byte( fd, &ch ) != 1 )
     {
  lprintf( 1, "timeout waiting for XON" );
  fprintf( stderr, "error waiting for XON!\n" );
  close( fd );
  exit(11);
     }
     lputc( 5, ch );
 }
 while ( ch != 021 );
 alarm(0);
    }
    tio_set_flow_control( fd, tio, (0x01 | (0x02 | 0x04)) & (0x01|0x04));
    tio_set( fd, tio );
    lprintf( 4, "sending %s...", g3_file );
    g3fd = open( g3_file, 00 );
    if ( g3fd == -1 )
    {
 lprintf( 1, "cannot open %s", g3_file );
 lprintf( 3, "have to send empty page instead" );
    }
    else
    {
 int r; int i; int w;
 int w_refresh = 0;
 char first = (1==1);
 if ( modem_quirks & 0x10 )
 {
     char nbuf[100];
     lprintf( 4, "send %d 0-bytes (pad before first EOL)...", sizeof(nbuf) );
     bzero( nbuf, sizeof(nbuf) );
     write( fd, nbuf, sizeof(nbuf) );
 }
 alarm( 40 );
 while ( ( r = read( g3fd, buf, 64 ) ) > 0 )
 {
     if ( w_refresh > 1000 )
     {
  w_refresh -= 1000;
  alarm( 30 );
     }
     i = 0;
     if ( first )
     {
  first = (1==0);
  if ( r >= 64 && strcmp( buf+1,
     "PC Research, Inc" ) == 0 )
  {
      lprintf( 4, "skipping over GhostScript header" );
      i = 64;
      if ( ( fax_par_d.vr != 0 ) != ( buf[29] != 0 ) )
      {
   fprintf( stderr, "WARNING: sending in %s mode, fax data is %s mode\n",
     fax_par_d.vr? "fine" : "normal",
     buf[29] ? "fine" : "normal" );
   lprintf( 3, "resolution mismatch" );
      }
  }
                else
                if ( r >= 2 && ( ( buf[0] == 0x49 && buf[1] == 0x49 ) ||
                                 ( buf[0] == 0x4d && buf[1] == 0x4d ) ) )
  {
      lprintf( 3, "file may be 'tiffg3' - TIFF is *not* a valid input format" );
      fprintf( stderr, "WARNING: file may be 'tiffg3' - TIFF file format is *not* supported!\n" );
      fprintf( stderr, "         Thus, fax transmission will most propably fail\n" );
  }
                else
                if ( r < 10 || buf[0] != 0 )
  {
      lprintf( 3, "file looks 'suspicious', buf=%02x %02x %02x %02x...", buf[0] &0xff, buf[1] &0xff, buf[2] &0xff, buf[3] &0xff );
                    fprintf( stderr, "WARNING: are you sure that this is a G3 fax file? Doesn't seem to be...\n" );
  }
     }
     for ( w = 0; i < r; i++ )
     {
  wbuf[ w ] = fax_send_swaptable[ (unsigned char) buf[i] ];
  if ( wbuf[ w++ ] == 020 ) wbuf[ w++ ] = 020;
     }
     lprintf( 6, "read %d, write %d", r, w );
     if ( write( fd, wbuf, w ) != w )
     {
  lprintf( 1, "could not write all %d bytes", w );
     }
     if ( fax_sendpg_timeout )
     {
  fax_send_panic_exit( fd );
     }
     w_total += w;
     w_refresh += w;
     if ( check_for_input( fd ) )
     {
  lprintf( 5, "input: got " );
  do
  {
      if ( read( fd, &ch, 1 ) != 1 )
      {
   lprintf( 1, "read failed" );
   break;
      }
      else
   lputc( 5, ch );
  }
  while ( check_for_input( fd ) );
     }
 }
 close(g3fd);
    }
    lprintf( 4, "page complete, %d bytes sent", w_total );
    if ( bytes_sent != ((void *)0) )
            *bytes_sent += w_total;
    rc = fax_send_ppm( fd, tio, ppm );
    alarm(0);
    return rc;
}

variable_types: fd int

variable_types: ch char

variable_types:
buf
char [256]

variable_types:
wbuf
char [-1]

variable_types: r int

variable_types: i int

variable_types: w int

variable_types: first char

variable_types:
nbuf
char [100]

user_defined_types: enum Post_page_messages { pp_mps=0, pp_eom=1, pp_eop=2, pp_pri_mps=3, pp_pri_eom=4, pp_pri_eop=5 }

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


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

reset_watchdog();
if ( current_device_1 >= 0 && current_device_1 != a1 )
voice_command("ATH0", "VCON|OK");
current_device_1 = a1;
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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();
if ( current_device_1 >= 0 && current_device_1 != a1 )
voice_command("ATH0", "VCON|OK");
current_device_1 = a1;
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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_5600ZDXv_set_device (int device)
{
  static int current_device = -1;
  reset_watchdog();
  if ((current_device != device) && (current_device >= 0)) {
    voice_command("ATH0","VCON|OK");
  }
  current_device=device;
  switch (device) {
    case (0x0001):
      voice_command("AT#VLS=0", "OK");
      break;
    case (0x0002):
      voice_command("AT#VLS=4", "OK");
      break;
    case (0x0003):
      voice_command("AT#VLS=3", "VCON");
      break;
    case (0x0006):
      voice_command("AT#VLS=2", "VCON");
      break;
    case (0x0007):
      voice_command("AT#VLS=1","VCON");
      break;
    default:
      lprintf(3, "%s: Unknown output device (%d)",
              voice_modem->name, device);
      return((-1));
  }
  return((0));
}

canonical_original_code:
static int Multitech_5600ZDXv_set_device(int device)
{
  static int current_device = -1;
  reset_watchdog();
  if ((current_device != device) && (current_device >= 0)) {
    voice_command("ATH0","VCON|OK");
  }
  current_device=device;
  switch (device) {
    case (0x0001):
      voice_command("AT#VLS=0", "OK");
      break;
    case (0x0002):
      voice_command("AT#VLS=4", "OK");
      break;
    case (0x0003):
      voice_command("AT#VLS=3", "VCON");
      break;
    case (0x0006):
      voice_command("AT#VLS=2", "VCON");
      break;
    case (0x0007):
      voice_command("AT#VLS=1","VCON");
      break;
    default:
      lprintf(3, "%s: Unknown output device (%d)",
              voice_modem->name, device);
      return((-1));
  }
  return((0));
}

variable_types: device int


decompiled_code:
__int64 __fastcall Multitech_5600ZDXv_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v6; // rdx
__int64 v7; // rdx
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
v4 = *a2;
if ( *a2 != 7200 && v4 != 11025 )
{
if ( v4 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
*a2 = 7200LL;
}
sprintf(v8, "AT#VSR=%d", *a2);
if ( (unsigned int)voice_command(v8, "OK") != 4096 )
return 0xFFFFFFFFLL;
v6 = *a1;
if ( *a1 == 2 )
{
LABEL_11:
v7 = *a1;
*a3 = *a1;
sprintf(v8, "AT#VBS=%d", v7);
return (unsigned int)-((unsigned int)voice_command(v8, "OK") != 4096);
}
if ( *a1 > 2 )
{
if ( ((v6 - 4) & 0xFFFFFFFFFFFFFFFBLL) == 0 )
goto LABEL_11;
}
else if ( !v6 )
{
*a1 = 2LL;
goto LABEL_11;
}
lprintf(3LL, "ROCKWELL handle event: Illegal voice compression method (%d)", v6);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v6; // rdx
__int64 v7; // rdx
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
v4 = *a2;
if ( *a2 != 7200 && v4 != 11025 )
{
if ( v4 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
*a2 = 7200LL;
}
sprintf(v8, "AT#VSR=%d", *a2);
if ( (unsigned int)voice_command(v8, "OK") != 4096 )
return 0xFFFFFFFFLL;
v6 = *a1;
if ( *a1 == 2 )
{
LABEL_11:
v7 = *a1;
*a3 = *a1;
sprintf(v8, "AT#VBS=%d", v7);
return (unsigned int)-((unsigned int)voice_command(v8, "OK") != 4096);
}
if ( *a1 > 2 )
{
if ( ((v6 - 4) & 0xFFFFFFFFFFFFFFFBLL) == 0 )
goto LABEL_11;
}
else if ( !v6 )
{
*a1 = 2LL;
goto LABEL_11;
}
lprintf(3LL, "ROCKWELL handle event: Illegal voice compression method (%d)", v6);
return 0xFFFFFFFFLL;
}

original_code:
static int
Multitech_5600ZDXv_set_compression (p_int *compression, p_int *speed, int *bits)
{
  char buf[(256)];
  reset_watchdog();
  switch (*speed) {
    case 0:
      *speed = 7200;
    case 7200:
    case 11025:
      break;
    default:
      lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name, (int)*speed);
      return((-1));
  }
  if (sprintf(buf, "AT#VSR=%d", (int)*speed) == -1) {
    lprintf(1, "%s: Command too long", __FUNCTION__);
  }
  if (voice_command(buf, "OK") != (0x1000)) {
    return((-1));
  }
  switch (*compression) {
    case 0:
      *compression = 2;
    case 2:
    case 4:
    case 8:
      *bits = *compression;
      break;
    default:
      lprintf(3,
              "ROCKWELL handle event: Illegal voice compression method (%d)",
              *compression);
      return((-1));
  }
  if (sprintf(buf, "AT#VBS=%d", *bits) == -1) {
    lprintf(1, "%s: Command too long", __FUNCTION__);
  }
  if (voice_command(buf, "OK") != (0x1000)) {
    return((-1));
  }
  return ((0));
}

canonical_original_code:
static int Multitech_5600ZDXv_set_compression(long *compression, long *speed, int *bits)
{
  char buf[-1];
  reset_watchdog();
  switch (*speed) {
    case 0:
      *speed = 7200;
    case 7200:
    case 11025:
      break;
    default:
      lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name, (int)*speed);
      return((-1));
  }
  if (sprintf(buf, "AT#VSR=%d", (int)*speed) == -1) {
    lprintf(1, "%s: Command too long", __FUNCTION__);
  }
  if (voice_command(buf, "OK") != (0x1000)) {
    return((-1));
  }
  switch (*compression) {
    case 0:
      *compression = 2;
    case 2:
    case 4:
    case 8:
      *bits = *compression;
      break;
    default:
      lprintf(3,
              "ROCKWELL handle event: Illegal voice compression method (%d)",
              *compression);
      return((-1));
  }
  if (sprintf(buf, "AT#VBS=%d", *bits) == -1) {
    lprintf(1, "%s: Command too long", __FUNCTION__);
  }
  if (voice_command(buf, "OK") != (0x1000)) {
    return((-1));
  }
  return ((0));
}

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buf
char [-1]


decompiled_code:
__int64 Multitech_5600ZDXv_init()
{
unsigned __int64 v0; // rax
__int64 result; // rax
_BYTE v2[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing Multitech MT5600ZDXv voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v0 = *((_QWORD *)&cvd + 58);
if ( v0 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v0 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT&K3", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned __int64 v0; // rax
__int64 result; // rax
_BYTE v2[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing Multitech MT5600ZDXv voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v0 = *((_QWORD *)&cvd + 58);
if ( v0 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v0 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT&K3", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

original_code:
static int
Multitech_5600ZDXv_init(void)
{
  char buffer[(256)];
  reset_watchdog();
  lprintf(4, "initializing Multitech MT5600ZDXv voice modem");
  voice_modem_state = (0x0002);
  sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
  if (voice_command(buffer, "OK") != (0x1000))
    lprintf(3, "can't set silence period");
  if (voice_command("AT#VSD=0", "OK") != (0x1000))
    lprintf(3, "can't disable silence deletion");
  if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
    lprintf(3, "can't set DLE responses");
  if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0)) {
    lprintf(3, "Invalid threshold value.");
    return(-1);
  }
  sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
  if (voice_command(buffer, "OK") != (0x1000))
    lprintf(3, "can't set silence threshold");
  if (voice_command("AT&K3", "OK") == (0x1000)) {
    TIO tio;
    tio_get(voice_fd, &tio);
    tio_set_flow_control(voice_fd, &tio, 0x01);
    tio_set(voice_fd, &tio);
  } else {
    lprintf(3, "can't turn on hardware flow control");
  }
  voice_modem_state = (0x0001);
  return((0));
}

canonical_original_code:
static int Multitech_5600ZDXv_init()
{
  char buffer[-1];
  reset_watchdog();
  lprintf(4, "initializing Multitech MT5600ZDXv voice modem");
  voice_modem_state = (0x0002);
  sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
  if (voice_command(buffer, "OK") != (0x1000))
    lprintf(3, "can't set silence period");
  if (voice_command("AT#VSD=0", "OK") != (0x1000))
    lprintf(3, "can't disable silence deletion");
  if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
    lprintf(3, "can't set DLE responses");
  if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0)) {
    lprintf(3, "Invalid threshold value.");
    return(-1);
  }
  sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
  if (voice_command(buffer, "OK") != (0x1000))
    lprintf(3, "can't set silence threshold");
  if (voice_command("AT&K3", "OK") == (0x1000)) {
    struct termios tio;
    tio_get(voice_fd, &tio);
    tio_set_flow_control(voice_fd, &tio, 0x01);
    tio_set(voice_fd, &tio);
  } else {
    lprintf(3, "can't turn on hardware flow control");
  }
  voice_modem_state = (0x0001);
  return((0));
}

variable_types:
buffer
char [-1]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall Multitech_5600ZDXv_handle_dle(char a1)
{
__int64 v2; // rax

if ( a1 != 116 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8200LL);
return queue_event(v2);
}

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

if ( a1 != 116 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8200LL);
return queue_event(v2);
}

original_code:
static int
Multitech_5600ZDXv_handle_dle(char data)
{
  switch (data) {
    case 't':
      return(queue_event(create_event((0x2008))));
  }
  return(IS_101_handle_dle(data));
}

variable_types: data char


decompiled_code:
char *__fastcall make_path(char *dest, const char *a2, const char *a3)
{
if ( *a3 == 47 )
return strcpy(dest, a3);
strcpy(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 47;
return strcat(dest, a3);
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, const char *a2, const char *a3)
{
if ( *a3 == 47 )
return strcpy(dest, a3);
strcpy(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 47;
return strcat(dest, a3);
}

original_code:
void make_path(char *result, char *path, char *name)
     {
     if (name[0] == '/')
          {
          strcpy(result, name);
          }
     else
          {
          strcpy(result, path);
          strcat(result, "/");
          strcat(result, name);
          };
     }

variable_types:
result
char *

variable_types:
path
char *

variable_types:
name
char *


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

if ( a1 > 8210 )
{
if ( a1 > 16387 )
{
result = 4294967294LL;
if ( (unsigned int)(a1 - 16389) > 1 )
return result;
}
else
{
result = 4294967294LL;
if ( a1 <= 16385 )
return result;
}
LABEL_9:
voice_stop_current_action();
hangup_requested = 1;
return 0LL;
}
if ( a1 <= 0x2000 )
return 4294967294LL;
switch ( a1 )
{
case 8193:
case 8195:
case 8200:
goto LABEL_9;
case 8196:
voice_stop_current_action();
answer_mode = answer_mode & 1;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8198:
voice_stop_current_action();
answer_mode = answer_mode & 2;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8199:
result = 0LL;
break;
case 8206:
voice_stop_current_action();
answer_mode = answer_mode & 3;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8209:
if ( a2 == 42 )
{
first_dtmf = 0;
dtmf_code = 0;
result = 0LL;
if ( voice_modem_state == 5 )
{
(*(void (**)(void))(voice_modem + 392LL))();
result = 0LL;
}
}
else if ( a2 == 35 )
{
first_dtmf = 0;
voice_stop_current_action();
if ( dtmf_code )
execute_dtmf_script = 1;
else
hangup_requested = 1;
result = 0LL;
}
else if ( first_dtmf && voice_modem_state == 5 )
{
first_dtmf = 0;
(*(void (**)(void))(voice_modem + 392LL))();
answer_mode = answer_mode & 3;
switch_to_data_fax_mode = 1;
result = 0LL;
}
else
{
first_dtmf = 0;
v3 = strlen(&dtmf_code);
if ( v3 > 254 )
{
voice_stop_current_action();
hangup_requested = 1;
}
else
{
execute_dtmf_script = 1;
*(&dtmf_code + v3 + 1) = 0;
*(&dtmf_code + v3) = a2;
}
result = 0LL;
}
break;
case 8210:
voice_stop_current_action();
result = 0LL;
break;
default:
result = 4294967294LL;
break;
}
return result;
}

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

if ( a1 > 8210 )
{
if ( a1 > 16387 )
{
result = 4294967294LL;
if ( (unsigned int)(a1 - 16389) > 1 )
return result;
}
else
{
result = 4294967294LL;
if ( a1 <= 16385 )
return result;
}
LABEL_9:
voice_stop_current_action();
hangup_requested = 1;
return 0LL;
}
if ( a1 <= 0x2000 )
return 4294967294LL;
switch ( a1 )
{
case 8193:
case 8195:
case 8200:
goto LABEL_9;
case 8196:
voice_stop_current_action();
answer_mode = answer_mode & 1;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8198:
voice_stop_current_action();
answer_mode = answer_mode & 2;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8199:
result = 0LL;
break;
case 8206:
voice_stop_current_action();
answer_mode = answer_mode & 3;
switch_to_data_fax_mode = 1;
result = 0LL;
break;
case 8209:
if ( a2 == 42 )
{
first_dtmf = 0;
dtmf_code = 0;
result = 0LL;
if ( voice_modem_state == 5 )
{
(*(void (**)(void))(voice_modem + 392LL))();
result = 0LL;
}
}
else if ( a2 == 35 )
{
first_dtmf = 0;
voice_stop_current_action();
if ( dtmf_code )
execute_dtmf_script = 1;
else
hangup_requested = 1;
result = 0LL;
}
else if ( first_dtmf && voice_modem_state == 5 )
{
first_dtmf = 0;
(*(void (**)(void))(voice_modem + 392LL))();
answer_mode = answer_mode & 3;
switch_to_data_fax_mode = 1;
result = 0LL;
}
else
{
first_dtmf = 0;
v3 = strlen(&dtmf_code);
if ( v3 > 254 )
{
voice_stop_current_action();
hangup_requested = 1;
}
else
{
execute_dtmf_script = 1;
*(&dtmf_code + v3 + 1) = 0;
*(&dtmf_code + v3) = a2;
}
result = 0LL;
}
break;
case 8210:
voice_stop_current_action();
result = 0LL;
break;
default:
result = 4294967294LL;
break;
}
return result;
}

original_code:
int vgetty_handle_event(int event, event_data data)
     {
     switch (event)
          {
          case (0x2007):
               return((0));
          case (0x2001):
          case (0x2003):
          case (0x2008):
          case (0x4002):
          case (0x4003):
          case (0x4005):
          case (0x4006):
               voice_stop_current_action();
               hangup_requested = (0==0);
               return((0));
          case (0x2004):
               voice_stop_current_action();
               answer_mode = answer_mode & (1);
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x2006):
               voice_stop_current_action();
               answer_mode = answer_mode & (2);
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x200e):
               voice_stop_current_action();
               answer_mode = answer_mode & ((1) | (2));
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x2011):
               {
               int length;
               if (data.c == '*')
                    {
                    first_dtmf = (0==1);
                    dtmf_code[0] = 0x00;
                    if (voice_modem_state == (0x0005))
                         voice_modem->stop_playing();
                    return((0));
                    };
               if (data.c == '#')
                    {
                    first_dtmf = (0==1);
                    voice_stop_current_action();
                    if (strlen(dtmf_code) == 0)
                         hangup_requested = (0==0);
                    else
                         execute_dtmf_script = (0==0);
                    return((0));
                    };
               if ((first_dtmf) && (voice_modem_state == (0x0005)))
                    {
                    first_dtmf = (0==1);
                    voice_modem->stop_playing();
                    answer_mode = answer_mode & ((1) | (2));
                    switch_to_data_fax_mode = (0==0);
                    return((0));
                    };
               first_dtmf = (0==1);
               length = strlen(dtmf_code);
               if (length >= ((256) - 1)) {
                    voice_stop_current_action();
                    hangup_requested = (0==0);
                    return((0));
               }
               execute_dtmf_script = (0==0);
               dtmf_code[length + 1] = 0x00;
               dtmf_code[length] = data.c;
               return((0));
               };
          case (0x2012):
               voice_stop_current_action();
               return((0));
          };
     return((-2));
     }

canonical_original_code:
int vgetty_handle_event(int event, union event_data data)
     {
     switch (event)
          {
          case (0x2007):
               return((0));
          case (0x2001):
          case (0x2003):
          case (0x2008):
          case (0x4002):
          case (0x4003):
          case (0x4005):
          case (0x4006):
               voice_stop_current_action();
               hangup_requested = (0==0);
               return((0));
          case (0x2004):
               voice_stop_current_action();
               answer_mode = answer_mode & (1);
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x2006):
               voice_stop_current_action();
               answer_mode = answer_mode & (2);
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x200e):
               voice_stop_current_action();
               answer_mode = answer_mode & ((1) | (2));
               switch_to_data_fax_mode = (0==0);
               return((0));
          case (0x2011):
               {
               int length;
               if (data.c == '*')
                    {
                    first_dtmf = (0==1);
                    dtmf_code[0] = 0x00;
                    if (voice_modem_state == (0x0005))
                         voice_modem->stop_playing();
                    return((0));
                    };
               if (data.c == '#')
                    {
                    first_dtmf = (0==1);
                    voice_stop_current_action();
                    if (strlen(dtmf_code) == 0)
                         hangup_requested = (0==0);
                    else
                         execute_dtmf_script = (0==0);
                    return((0));
                    };
               if ((first_dtmf) && (voice_modem_state == (0x0005)))
                    {
                    first_dtmf = (0==1);
                    voice_modem->stop_playing();
                    answer_mode = answer_mode & ((1) | (2));
                    switch_to_data_fax_mode = (0==0);
                    return((0));
                    };
               first_dtmf = (0==1);
               length = strlen(dtmf_code);
               if (length >= ((256) - 1)) {
                    voice_stop_current_action();
                    hangup_requested = (0==0);
                    return((0));
               }
               execute_dtmf_script = (0==0);
               dtmf_code[length + 1] = 0x00;
               dtmf_code[length] = data.c;
               return((0));
               };
          case (0x2012):
               voice_stop_current_action();
               return((0));
          };
     return((-2));
     }

variable_types: event int

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

variable_types: length int


decompiled_code:
__int64 __fastcall voice_analyze(char *s1, char *s, int a3)
{
__int64 result; // rax
char *v4; // rbp
int v6; // er13
const char *v7; // rbx
__int64 v8; // rbp
size_t v9; // rax
char *v10; // rbx
int v11; // edx

result = 8194LL;
if ( *s1 )
{
v4 = s;
v6 = 0;
if ( s )
{
while ( *v4 )
{
v10 = strchr(v4, 124);
v11 = (_DWORD)v10 - (_DWORD)v4;
if ( !v10 )
v11 = strlen(v4);
if ( a3 )
{
if ( !strncmp(s1, v4, v11) )
return (unsigned int)(v6 + 4096);
}
else if ( (unsigned int)wildmat(s1, v4) )
{
return (unsigned int)(v6 + 4096);
}
if ( !v10 )
break;
v4 = v10 + 1;
++v6;
}
}
v7 = modem_answers;
v8 = 0LL;
result = 0x4000LL;
if ( modem_answers )
{
while ( 1 )
{
v9 = strlen(v7);
if ( !strncmp(s1, v7, v9) )
break;
++v8;
v7 = (&modem_answers)[2 * v8];
if ( !v7 )
return 0x4000LL;
}
result = LODWORD((&modem_answers)[2 * (int)v8 + 1]);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, char *s, int a3)
{
__int64 result; // rax
char *v4; // rbp
int v6; // er13
const char *v7; // rbx
__int64 v8; // rbp
size_t v9; // rax
char *v10; // rbx
int v11; // edx

result = 8194LL;
if ( *s1 )
{
v4 = s;
v6 = 0;
if ( s )
{
while ( *v4 )
{
v10 = strchr(v4, 124);
v11 = (_DWORD)v10 - (_DWORD)v4;
if ( !v10 )
v11 = strlen(v4);
if ( a3 )
{
if ( !strncmp(s1, v4, v11) )
return (unsigned int)(v6 + 4096);
}
else if ( (unsigned int)wildmat(s1, v4) )
{
return (unsigned int)(v6 + 4096);
}
if ( !v10 )
break;
v4 = v10 + 1;
++v6;
}
}
v7 = modem_answers;
v8 = 0LL;
result = 0x4000LL;
if ( modem_answers )
{
while ( 1 )
{
v9 = strlen(v7);
if ( !strncmp(s1, v7, v9) )
break;
++v8;
v7 = (&modem_answers)[2 * v8];
if ( !v7 )
return 0x4000LL;
}
result = LODWORD((&modem_answers)[2 * (int)v8 + 1]);
}
}
return result;
}

original_code:
int voice_analyze(char *buffer, char *expected_answers, int exact_match)
     {
     int current;
     char *user_answer;
     char *new_user_answer;
     int user_answer_length;
     user_answer = expected_answers;
     if (strlen(buffer) == 0)
          return((0x2002));
     for(current = 0; ((user_answer != ((void *)0)) && (strlen(user_answer) > 0));
      current++)
          {
          new_user_answer = strstr(user_answer, "|");
          if (new_user_answer == ((void *)0))
               user_answer_length = strlen(user_answer);
          else
               user_answer_length = (int) (new_user_answer - user_answer);
          if (exact_match)
               {
               if (strncmp(buffer, user_answer, user_answer_length) == 0)
                    return(current + (0x1000));
               }
          else
               {
               if (wildmat(buffer, user_answer, user_answer_length) != 0)
                    return(current + (0x1000));
               }
          if (new_user_answer == ((void *)0))
               user_answer = ((void *)0);
          else
               user_answer = new_user_answer + 1;
          };
     for(current = 0; modem_answers[current].answer != ((void *)0); current++)
          if (strncmp(buffer, modem_answers[current].answer,
           strlen(modem_answers[current].answer)) == 0)
               return(modem_answers[current].value);
     return((0x4000));
     }

variable_types:
buffer
char *

variable_types: current int


decompiled_code:
const char *__fastcall wav_format_str(int a1)
{
char v1; // cf
char v2; // zf
const char *result; // rax

if ( !(v1 | v2) )
return "Unknown";
switch ( a1 )
{
case 0:
result = "Microsoft Official Unknown";
break;
case 1:
result = "Microsoft PCM";
break;
case 2:
result = "Microsoft ADPCM";
break;
case 3:
case 4:
case 5:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 17:
case 18:
case 19:
case 20:
return "Unknown";
case 6:
result = "Microsoft A-law";
break;
case 7:
result = "Microsoft U-law";
break;
case 16:
result = "OKI ADPCM format.";
break;
case 21:
result = "Digistd format.";
break;
case 22:
result = "Digifix format.";
break;
default:
result = "IBM A-law";
if ( a1 != 258 )
{
if ( a1 == 259 )
{
result = "IBM ADPCM";
}
else
{
result = "Unknown";
if ( a1 == 257 )
result = "IBM U-law format.";
}
}
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
char v1; // cf
char v2; // zf
const char *result; // rax

if ( !(v1 | v2) )
return "Unknown";
switch ( a1 )
{
case 0:
result = "Microsoft Official Unknown";
break;
case 1:
result = "Microsoft PCM";
break;
case 2:
result = "Microsoft ADPCM";
break;
case 3:
case 4:
case 5:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 17:
case 18:
case 19:
case 20:
return "Unknown";
case 6:
result = "Microsoft A-law";
break;
case 7:
result = "Microsoft U-law";
break;
case 16:
result = "OKI ADPCM format.";
break;
case 21:
result = "Digistd format.";
break;
case 22:
result = "Digifix format.";
break;
default:
result = "IBM A-law";
if ( a1 != 258 )
{
if ( a1 == 259 )
{
result = "IBM ADPCM";
}
else
{
result = "Unknown";
if ( a1 == 257 )
result = "IBM U-law format.";
}
}
break;
}
return result;
}

original_code:
static char * wav_format_str(unsigned wFormatTag)
     {
     switch (wFormatTag)
          {
          case (0x0000):
               return "Microsoft Official Unknown";
          case (0x0001):
               return "Microsoft PCM";
          case (0x0002):
               return "Microsoft ADPCM";
          case (0x0006):
               return "Microsoft A-law";
          case (0x0007):
               return "Microsoft U-law";
          case (0x0010):
               return "OKI ADPCM format.";
          case (0x0015):
               return "Digistd format.";
          case (0x0016):
               return "Digifix format.";
          case (0x0101):
               return "IBM U-law format.";
          case (0x0102):
               return "IBM A-law";
          case (0x0103):
               return "IBM ADPCM";
          default:
               return "Unknown";
          }
     }

canonical_original_code:
static char *wav_format_str(unsigned int wFormatTag)
     {
     switch (wFormatTag)
          {
          case (0x0000):
               return "Microsoft Official Unknown";
          case (0x0001):
               return "Microsoft PCM";
          case (0x0002):
               return "Microsoft ADPCM";
          case (0x0006):
               return "Microsoft A-law";
          case (0x0007):
               return "Microsoft U-law";
          case (0x0010):
               return "OKI ADPCM format.";
          case (0x0015):
               return "Digistd format.";
          case (0x0016):
               return "Digifix format.";
          case (0x0101):
               return "IBM U-law format.";
          case (0x0102):
               return "IBM A-law";
          case (0x0103):
               return "IBM ADPCM";
          default:
               return "Unknown";
          }
     }

variable_types:
wFormatTag
unsigned int

return_type: char *


decompiled_code:
__int64 ZyXEL_Omni56K_voice_mode_on()
{
unsigned int v0; // ebx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)IS_101_voice_mode_on() )
return (unsigned int)-1;
v0 = 0;
if ( (unsigned int)voice_command("AT+VIT=100", &unk_770) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v2, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v2, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v2, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
sprintf(v2, "AT+VRA=%d+VRN=%d", *((unsigned int *)&cvd + 398), *((unsigned int *)&cvd + 404));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)IS_101_voice_mode_on() )
return (unsigned int)-1;
v0 = 0;
if ( (unsigned int)voice_command("AT+VIT=100", &unk_770) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v2, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v2, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v2, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
sprintf(v2, "AT+VRA=%d+VRN=%d", *((unsigned int *)&cvd + 398), *((unsigned int *)&cvd + 404));
if ( (unsigned int)voice_command(v2, &unk_770) != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
return v0;
}

original_code:
static int ZyXEL_Omni56K_voice_mode_on (void)
     {
     char buffer[(256)];
     if (IS_101_voice_mode_on())
          return((-1));
     if (voice_command("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     sprintf(buffer, "AT+VRA=%d+VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     return((0));
     }

canonical_original_code:
static int ZyXEL_Omni56K_voice_mode_on()
     {
     char buffer[-1];
     if (IS_101_voice_mode_on())
          return((-1));
     if (voice_command("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     sprintf(buffer, "AT+VRA=%d+VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     return((0));
     }


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

reset_watchdog();
switch ( a1 )
{
case 2u:
voice_command("AT+VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=1", "VCON");
result = 0LL;
break;
case 1u:
voice_command("AT+VLS=0", &unk_770);
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 func1(unsigned int a1)
{
__int64 result; // rax

reset_watchdog();
switch ( a1 )
{
case 2u:
voice_command("AT+VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=1", "VCON");
result = 0LL;
break;
case 1u:
voice_command("AT+VLS=0", &unk_770);
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 ZyXEL_Omni56K_set_device (int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0007):
               voice_command("AT+VLS=1", "VCON");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=2", "VCON");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

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

variable_types: device int


decompiled_code:
__int64 __fastcall ZyXEL_Omni56K_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx

reset_watchdog();
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
}
v5 = *a1;
if ( !*a1 )
{
*a1 = 4LL;
LABEL_5:
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=4,9600", &unk_770) != 4096);
}
if ( v5 == 4 )
goto LABEL_5;
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx

reset_watchdog();
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
}
v5 = *a1;
if ( !*a1 )
{
*a1 = 4LL;
LABEL_5:
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=4,9600", &unk_770) != 4096);
}
if ( v5 == 4 )
goto LABEL_5;
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
return 0xFFFFFFFFLL;
}

original_code:
static int ZyXEL_Omni56K_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          };
     if (*compression == 0)
          *compression = 4;
     if (*compression != 4)
          {
          lprintf(3, "%s: Illegal voice compression method (%d)",
           voice_modem->name, (int)*compression);
          return((-1));
          };
     *bits = 4;
     if (voice_command("AT+VSM=4,9600", "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
static int ZyXEL_Omni56K_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          };
     if (*compression == 0)
          *compression = 4;
     if (*compression != 4)
          {
          lprintf(3, "%s: Illegal voice compression method (%d)",
           voice_modem->name, (int)*compression);
          return((-1));
          };
     *bits = 4;
     if (voice_command("AT+VSM=4,9600", "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types:
compression
long *


decompiled_code:
__int64 ZyXEL_Omni56K_init()
{
reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing ZyXEL Omni 56K voice modem");
if ( (unsigned int)voice_command("ATS40.3=1S40.4=1S40.5=1S40.6=1", &unk_770) != 4096 )
lprintf(3LL, "couldn't initialize distinctive RING");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing ZyXEL Omni 56K voice modem");
if ( (unsigned int)voice_command("ATS40.3=1S40.4=1S40.5=1S40.6=1", &unk_770) != 4096 )
lprintf(3LL, "couldn't initialize distinctive RING");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int ZyXEL_Omni56K_init (void)
     {
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL Omni 56K voice modem");
     if (voice_command("ATS40.3=1S40.4=1S40.5=1S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int ZyXEL_Omni56K_init()
     {
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL Omni 56K voice modem");
     if (voice_command("ATS40.3=1S40.4=1S40.5=1S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     voice_modem_state = (0x0001);
     return((0));
     }