decompiled_code:
__int64 Supra_init()
{
_BYTE v1[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Supra 56e PRO voice modem");
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set silence_len VSP");
strcpy(s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy(s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy(s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set BDR=16");
strcpy(s, "AT#VTD=3F,3F,3F");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf(s, "AT#VSS=%1u", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 58)) / 100));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set silence threshold VSS");
strcpy(s, "ATS30=60");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set S30");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#VGT=%d", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 82)) / 100 + 128));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(2LL);
if ( *((_QWORD *)&cvd + 70) && (unsigned int)voice_command("AT&K3", &unk_868) == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
_BYTE v1[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Supra 56e PRO voice modem");
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set silence_len VSP");
strcpy(s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy(s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy(s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set BDR=16");
strcpy(s, "AT#VTD=3F,3F,3F");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf(s, "AT#VSS=%1u", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 58)) / 100));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set silence threshold VSS");
strcpy(s, "ATS30=60");
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set S30");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#VGT=%d", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 82)) / 100 + 128));
if ( (unsigned int)voice_command(s, &unk_868) != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(2LL);
if ( *((_QWORD *)&cvd + 70) && (unsigned int)voice_command("AT&K3", &unk_868) == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Supra_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Supra 56e PRO voice modem");
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence_len VSP");
     sprintf(buffer, "AT#VSD=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VSD=0");
     sprintf(buffer, "AT#VBS=4");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VBS=4");
     sprintf(buffer, "AT#BDR=16");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set BDR=16");
     sprintf(buffer, "AT#VTD=3F,3F,3F");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VTD=3F");
     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 VSS");
     sprintf(buffer, "ATS30=60");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set S30");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT#VGT=%d", (int)cvd.transmit_gain.d.i * 3 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     voice_modem->set_device((0x0002));
     if ((cvd.do_hard_flow.d.i) && (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 Supra_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Supra 56e PRO voice modem");
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence_len VSP");
     sprintf(buffer, "AT#VSD=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VSD=0");
     sprintf(buffer, "AT#VBS=4");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VBS=4");
     sprintf(buffer, "AT#BDR=16");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set BDR=16");
     sprintf(buffer, "AT#VTD=3F,3F,3F");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VTD=3F");
     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 VSS");
     sprintf(buffer, "ATS30=60");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set S30");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT#VGT=%d", (int)cvd.transmit_gain.d.i * 3 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     voice_modem->set_device((0x0002));
     if ((cvd.do_hard_flow.d.i) && (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));
     }

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


repo: Distrotech/mgetty

decompiled_code:
void fax_sig_alarm()
{
signal(14, fax_sig_alarm);
lprintf(4LL, "timeout...");
fax_timeout = 1;
}

canonical_decompiled_code:
void func0()
{
signal(14, fax_sig_alarm);
lprintf(4LL, "timeout...");
fax_timeout = 1;
}

original_code:
RETSIGTYPE fax_sig_alarm()
{
    signal( 14, fax_sig_alarm );
    lprintf( 4, "timeout..." );
    fax_timeout = (1==1);
}

canonical_original_code:
void fax_sig_alarm()
{
    signal( 14, fax_sig_alarm );
    lprintf( 4, "timeout..." );
    fax_timeout = (1==1);
}

return_type: void


decompiled_code:
void fax_sig_hangup()
{
signal(1, fax_sig_hangup);
if ( !fax_hangup )
{
lprintf(3LL, "how rude, got hangup! exiting...");
exit(5);
}
}

canonical_decompiled_code:
void func1()
{
signal(1, fax_sig_hangup);
if ( !fax_hangup )
{
lprintf(3LL, "how rude, got hangup! exiting...");
exit(5);
}
}

original_code:
RETSIGTYPE fax_sig_hangup()
{
    signal( 1, fax_sig_hangup );
    if ( ! fax_hangup )
    {
 lprintf( 3, "how rude, got hangup! exiting..." );
 exit(5);
    }
}

canonical_original_code:
void fax_sig_hangup()
{
    signal( 1, fax_sig_hangup );
    if ( ! fax_hangup )
    {
 lprintf( 3, "how rude, got hangup! exiting..." );
 exit(5);
    }
}


decompiled_code:
__int64 __fastcall fax_find_directory(void *src, void *dest, int a3)
{
int v5; // er14
__int64 result; // rax
int v7; // eax
__int64 v8; // rbx
char *v9; // rax

v5 = a3 - 1;
do
{
v7 = strlen((const char *)src) + 1;
if ( v7 >= a3 )
v7 = v5;
v8 = v7;
v9 = (char *)memccpy(dest, src, 58, v7);
if ( v9 )
{
*(v9 - 1) = 0;
src = (char *)src + 1;
}
*((_BYTE *)dest + v8) = 0;
src = (char *)src + strlen((const char *)dest);
if ( access((const char *)dest, 2) < 0 )
{
result = lprintf(1LL, "fax_find_dir: can't write to '%s'", (const char *)dest);
}
else
{
result = checkspace(dest);
if ( (int)result > 1 )
return result;
result = lprintf(3LL, "fax_find_dir: not enough disk space in '%s'", (const char *)dest);
}
}
while ( *(_BYTE *)src );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, void *dest, int a3)
{
int v5; // er14
__int64 result; // rax
int v7; // eax
__int64 v8; // rbx
char *v9; // rax

v5 = a3 - 1;
do
{
v7 = strlen((const char *)src) + 1;
if ( v7 >= a3 )
v7 = v5;
v8 = v7;
v9 = (char *)memccpy(dest, src, 58, v7);
if ( v9 )
{
*(v9 - 1) = 0;
src = (char *)src + 1;
}
*((_BYTE *)dest + v8) = 0;
src = (char *)src + strlen((const char *)dest);
if ( access((const char *)dest, 2) < 0 )
{
result = lprintf(1LL, "fax_find_dir: can't write to '%s'", (const char *)dest);
}
else
{
result = checkspace(dest);
if ( (int)result > 1 )
return result;
result = lprintf(3LL, "fax_find_dir: not enough disk space in '%s'", (const char *)dest);
}
}
while ( *(_BYTE *)src );
return result;
}

original_code:
void fax_find_directory (char * dirlist,char * directory,int size)
{
char *p, *p_help;
    p = dirlist;
    do
    {
        int l = strlen(p)+1;
 if ( l > size-1 ) l=size-1;
     p_help = memccpy( directory, p, ':', l );
 if ( p_help != ((void *)0) ) { *(p_help-1) = '\0'; p++; }
 directory[l] = '\0';
 p += strlen(directory);
 if ( access( directory, 2 ) < 0 )
 {
     lprintf( 1, "fax_find_dir: can't write to '%s'", directory);
     continue;
 }
        if ( checkspace(directory) > 1 ) { break; }
 lprintf( 3, "fax_find_dir: not enough disk space in '%s'",
   directory);
    }
    while( *p != '\0' );
}

canonical_original_code:
void fax_find_directory(char *dirlist, char *directory, int size)
{
char *p; char *p_help;
    p = dirlist;
    do
    {
        int l = strlen(p)+1;
 if ( l > size-1 ) l=size-1;
     p_help = memccpy( directory, p, ':', l );
 if ( p_help != ((void *)0) ) { *(p_help-1) = '\0'; p++; }
 directory[l] = '\0';
 p += strlen(directory);
 if ( access( directory, 2 ) < 0 )
 {
     lprintf( 1, "fax_find_dir: can't write to '%s'", directory);
     continue;
 }
        if ( checkspace(directory) > 1 ) { break; }
 lprintf( 3, "fax_find_dir: not enough disk space in '%s'",
   directory);
    }
    while( *p != '\0' );
}

variable_types:
dirlist
char *

variable_types:
directory
char *

variable_types: size int

variable_types:
p
char *

variable_types: l int


decompiled_code:
__int64 __fastcall fax_get_pages(int fd, unsigned int *a2, void *a3, __uid_t a4, __gid_t a5, __mode_t a6)
{
unsigned int v10; // ebx
unsigned int v12; // esi
int v13; // eax
char v14[1080]; // [rsp+0h] [rbp-438h] BYREF

fax_find_directory(a3, v14, 1024);
*a2 = 0;
if ( fax_hangup | fax_poll_req )
{
lprintf(4LL, "fax_get_pages: no pages to receive");
v10 = 0;
}
else
{
v10 = fax_command("AT+FDR", "CONNECT", (unsigned int)fd);
if ( v10 == -1 )
{
lprintf(3LL, "fax_get_pages: cannot start page receive");
}
else
{
while ( !(fax_poll_req | fax_hangup) )
{
lprintf(5LL, "sending DC2");
write(fd, &start_rcv_0, 1uLL);
v12 = *a2 + 1;
*a2 = v12;
v10 = fax_get_page_data(fd, v12, v14, a4, a5, a6);
if ( v10 == -1 )
{
fax_hangup_code = -1;
return v10;
}
v10 = fax_wait_for("OK", (unsigned int)fd);
if ( v10 == -1 )
return v10;
if ( (modem_quirks & 4) == 0 && fhs_details )
{
if ( fhs_lc <= 49 )
goto LABEL_7;
v13 = fhs_lc / 10 + 30;
if ( v13 > 500 )
v13 = 500;
if ( fhs_blc > v13 )
{
LABEL_7:
lprintf(3LL, "Page doesn't look good, request retrain (MPS)");
fax_command("AT+FPS=2", "OK", (unsigned int)fd);
}
}
if ( (*((_BYTE *)&modem_quirks + 1) & 1) != 0 )
{
lprintf(3LL, "teergrubing -> signalling 'page bad'");
fax_command("AT+FPS=2", "OK", (unsigned int)fd);
}
if ( (*((_BYTE *)&modem_quirks + 1) & 2) != 0 )
{
lprintf(3LL, "teergrubing -> hanging up hard");
fax_command("ATH0", "OK", (unsigned int)fd);
return (unsigned int)-1;
}
fax_send("AT+FDR", (unsigned int)fd);
v10 = fax_wait_for("CONNECT", (unsigned int)fd);
if ( v10 == -1 )
return v10;
}
v10 = 0;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, unsigned int *a2, void *a3, __uid_t a4, __gid_t a5, __mode_t a6)
{
unsigned int v10; // ebx
unsigned int v12; // esi
int v13; // eax
char v14[1080]; // [rsp+0h] [rbp-438h] BYREF

func3(a3, v14, 1024);
*a2 = 0;
if ( fax_hangup | fax_poll_req )
{
lprintf(4LL, "fax_get_pages: no pages to receive");
v10 = 0;
}
else
{
v10 = fax_command("AT+FDR", "CONNECT", (unsigned int)fd);
if ( v10 == -1 )
{
lprintf(3LL, "fax_get_pages: cannot start page receive");
}
else
{
while ( !(fax_poll_req | fax_hangup) )
{
lprintf(5LL, "sending DC2");
write(fd, &start_rcv_0, 1uLL);
v12 = *a2 + 1;
*a2 = v12;
v10 = func2(fd, v12, v14, a4, a5, a6);
if ( v10 == -1 )
{
fax_hangup_code = -1;
return v10;
}
v10 = fax_wait_for("OK", (unsigned int)fd);
if ( v10 == -1 )
return v10;
if ( (modem_quirks & 4) == 0 && fhs_details )
{
if ( fhs_lc <= 49 )
goto LABEL_7;
v13 = fhs_lc / 10 + 30;
if ( v13 > 500 )
v13 = 500;
if ( fhs_blc > v13 )
{
LABEL_7:
lprintf(3LL, "Page doesn't look good, request retrain (MPS)");
fax_command("AT+FPS=2", "OK", (unsigned int)fd);
}
}
if ( (*((_BYTE *)&modem_quirks + 1) & 1) != 0 )
{
lprintf(3LL, "teergrubing -> signalling 'page bad'");
fax_command("AT+FPS=2", "OK", (unsigned int)fd);
}
if ( (*((_BYTE *)&modem_quirks + 1) & 2) != 0 )
{
lprintf(3LL, "teergrubing -> hanging up hard");
fax_command("ATH0", "OK", (unsigned int)fd);
return (unsigned int)-1;
}
fax_send("AT+FDR", (unsigned int)fd);
v10 = fax_wait_for("CONNECT", (unsigned int)fd);
if ( v10 == -1 )
return v10;
}
v10 = 0;
}
}
return v10;
}

original_code:
int fax_get_pages (int fd,int * pagenum,char * dirlist,int uid,int gid,int mode)
{
static const char start_rcv = 022;
    char directory[1024];
    fax_find_directory( dirlist, directory, sizeof(directory) );
    *pagenum = 0;
    if ( fax_poll_req || fax_hangup )
    {
 lprintf( 4, "fax_get_pages: no pages to receive" );
 return 0;
    }
    if ( fax_command( "AT+FDR", "CONNECT", fd ) == -1 )
    {
 lprintf( 3, "fax_get_pages: cannot start page receive" );
 return -1;
    }
    while ( !fax_hangup && !fax_poll_req )
    {
 lprintf( 5, "sending DC2" );
 write( fd, &start_rcv, 1);
 if ( fax_get_page_data( fd, ++(*pagenum), directory,
           uid, gid, mode ) == -1 )
 {
     fax_hangup_code = -1;
     return -1;
 }
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 if ( ( modem_quirks & 0x04 ) == 0 &&
      fhs_details &&
      ( fhs_lc < 50 || fhs_blc > (fhs_lc/10)+30 || fhs_blc > 500 ) )
 {
     lprintf( 3, "Page doesn't look good, request retrain (MPS)" );
     fax_command( "AT+FPS=2", "OK", fd );
 }
 if ( modem_quirks & 0x100 )
 {
     lprintf( 3, "teergrubing -> signalling 'page bad'" );
     fax_command( "AT+FPS=2", "OK", fd );
 }
 if ( modem_quirks & 0x200 )
 {
     lprintf( 3, "teergrubing -> hanging up hard" );
     fax_command( "ATH0", "OK", fd );
     return -1;
 }
 fax_send( "AT+FDR", fd );
 if ( fax_wait_for( "CONNECT", fd ) == -1 ) return -1;
    }
    return 0;
}

canonical_original_code:
int fax_get_pages(int fd, int *pagenum, char *dirlist, int uid, int gid, int mode)
{
static char start_rcv = 022;
    char directory[1024];
    fax_find_directory( dirlist, directory, sizeof(directory) );
    *pagenum = 0;
    if ( fax_poll_req || fax_hangup )
    {
 lprintf( 4, "fax_get_pages: no pages to receive" );
 return 0;
    }
    if ( fax_command( "AT+FDR", "CONNECT", fd ) == -1 )
    {
 lprintf( 3, "fax_get_pages: cannot start page receive" );
 return -1;
    }
    while ( !fax_hangup && !fax_poll_req )
    {
 lprintf( 5, "sending DC2" );
 write( fd, &start_rcv, 1);
 if ( fax_get_page_data( fd, ++(*pagenum), directory,
           uid, gid, mode ) == -1 )
 {
     fax_hangup_code = -1;
     return -1;
 }
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 if ( ( modem_quirks & 0x04 ) == 0 &&
      fhs_details &&
      ( fhs_lc < 50 || fhs_blc > (fhs_lc/10)+30 || fhs_blc > 500 ) )
 {
     lprintf( 3, "Page doesn't look good, request retrain (MPS)" );
     fax_command( "AT+FPS=2", "OK", fd );
 }
 if ( modem_quirks & 0x100 )
 {
     lprintf( 3, "teergrubing -> signalling 'page bad'" );
     fax_command( "AT+FPS=2", "OK", fd );
 }
 if ( modem_quirks & 0x200 )
 {
     lprintf( 3, "teergrubing -> hanging up hard" );
     fax_command( "ATH0", "OK", fd );
     return -1;
 }
 fax_send( "AT+FDR", fd );
 if ( fax_wait_for( "CONNECT", fd ) == -1 ) return -1;
    }
    return 0;
}

variable_types: fd int

variable_types:
pagenum
int *

variable_types: uid int

variable_types: gid int

variable_types: mode int

variable_types:
directory
char [1024]

return_type: int


decompiled_code:
__int64 __fastcall V253modem_set_compression(__int64 *a1, unsigned int *a2, int *a3)
{
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
v4 = *a1;
v5 = 1;
if ( (unsigned __int64)*a1 <= 0xFF )
v5 = Kompressiontable[v4];
switch ( v4 )
{
case 0LL:
case 1LL:
case 8LL:
*a3 = 8;
break;
case 2LL:
*a3 = 2;
break;
case 4LL:
*a3 = 4;
break;
case 5LL:
*a3 = 4;
break;
case 6LL:
*a3 = 8;
break;
case 7LL:
*a3 = 8;
break;
case 9LL:
*a3 = 8;
break;
case 10LL:
*a3 = 8;
break;
case 11LL:
*a3 = 8;
break;
case 12LL:
*a3 = 16;
break;
default:
lprintf(3LL, "compression method %d is not supported -> edit voice.conf", v4);
*a3 = 8;
v5 = 1;
break;
}
if ( !*(_QWORD *)a2 )
*(_QWORD *)a2 = 8000LL;
sprintf(v9, "AT+VSM=%d,%d", v5, *a2);
if ( (unsigned int)voice_command(v9, "OK") != 4096 )
sprintf(v9, "AT+VSM=%d,%d,%d,%d", v5, *a2, 0LL, 0LL);
if ( (unsigned int)voice_command(v9, "OK") != 4096 )
{
lprintf(3LL, "can't set compression and speed");
voice_command("AT+VSM?", "OK");
}
v6 = 10 * *(_QWORD *)a2 * *a3;
v7 = v6 + 7;
if ( v6 >= 0 )
v7 = 10 * *(_QWORD *)a2 * *a3;
lprintf(5LL, "Just for info: port_speed should be greater than %d bps", v7 >> 3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, unsigned int *a2, int *a3)
{
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
v4 = *a1;
v5 = 1;
if ( (unsigned __int64)*a1 <= 0xFF )
v5 = Kompressiontable[v4];
switch ( v4 )
{
case 0LL:
case 1LL:
case 8LL:
*a3 = 8;
break;
case 2LL:
*a3 = 2;
break;
case 4LL:
*a3 = 4;
break;
case 5LL:
*a3 = 4;
break;
case 6LL:
*a3 = 8;
break;
case 7LL:
*a3 = 8;
break;
case 9LL:
*a3 = 8;
break;
case 10LL:
*a3 = 8;
break;
case 11LL:
*a3 = 8;
break;
case 12LL:
*a3 = 16;
break;
default:
lprintf(3LL, "compression method %d is not supported -> edit voice.conf", v4);
*a3 = 8;
v5 = 1;
break;
}
if ( !*(_QWORD *)a2 )
*(_QWORD *)a2 = 8000LL;
sprintf(v9, "AT+VSM=%d,%d", v5, *a2);
if ( (unsigned int)voice_command(v9, "OK") != 4096 )
sprintf(v9, "AT+VSM=%d,%d,%d,%d", v5, *a2, 0LL, 0LL);
if ( (unsigned int)voice_command(v9, "OK") != 4096 )
{
lprintf(3LL, "can't set compression and speed");
voice_command("AT+VSM?", "OK");
}
v6 = 10 * *(_QWORD *)a2 * *a3;
v7 = v6 + 7;
if ( v6 >= 0 )
v7 = 10 * *(_QWORD *)a2 * *a3;
lprintf(5LL, "Just for info: port_speed should be greater than %d bps", v7 >> 3);
return 0LL;
}

original_code:
int V253modem_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     char buffer[(256)];
     int Kompressionmethod = 1;
     int sil_sense = 0;
     int sil_clip = 0;
     reset_watchdog();
     if(*compression < sizeof(Kompressiontable)/sizeof(int) ) {
       Kompressionmethod = Kompressiontable[*compression];
     }
     switch (*compression)
     {
       case 0:
       case 1:
       case 8:
       {
          *bits=8;
          break;
       }
       case 2:
       {
         *bits = 2;
         break;
        }
       case 4:
       {
         *bits=4;
         break;
       }
       case 5:
       {
         *bits = 4;
         break;
       }
       case 6:
       {
         *bits = 8;
         break;
       }
       case 7:
       {
         *bits = 8;
         break;
       }
       case 9:
       {
          *bits=8;
          break;
       }
       case 10:
       {
          *bits=8;
          break;
       }
       case 11:
       {
          *bits=8;
          break;
       }
       case 12:
       {
  *bits=16;
  break;
       }
       default:
       {
          lprintf(3, "compression method %d is not supported -> edit voice.conf",*compression);
          Kompressionmethod = 1;
          *bits=8;
       }
     }
     if (*speed == 0)
          *speed = 8000;
     sprintf(buffer, "AT+VSM=%d,%d",Kompressionmethod, (int)*speed);
     if (voice_command(buffer, "OK")!= (0x1000))
     sprintf(buffer, "AT+VSM=%d,%d,%d,%d",Kompressionmethod, (int)*speed, sil_sense, sil_clip);
     if (voice_command(buffer, "OK")!= (0x1000))
      {
         lprintf(3, "can't set compression and speed");
         voice_command("AT+VSM?", "OK");
      }
     lprintf(5, "Just for info: port_speed should be greater than %d bps",(*bits)*(*speed)*10/8);
     return((0)) ;
     }

canonical_original_code:
int V253modem_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     int Kompressionmethod = 1;
     int sil_sense = 0;
     int sil_clip = 0;
     reset_watchdog();
     if(*compression < sizeof(Kompressiontable)/sizeof(int) ) {
       Kompressionmethod = Kompressiontable[*compression];
     }
     switch (*compression)
     {
       case 0:
       case 1:
       case 8:
       {
          *bits=8;
          break;
       }
       case 2:
       {
         *bits = 2;
         break;
        }
       case 4:
       {
         *bits=4;
         break;
       }
       case 5:
       {
         *bits = 4;
         break;
       }
       case 6:
       {
         *bits = 8;
         break;
       }
       case 7:
       {
         *bits = 8;
         break;
       }
       case 9:
       {
          *bits=8;
          break;
       }
       case 10:
       {
          *bits=8;
          break;
       }
       case 11:
       {
          *bits=8;
          break;
       }
       case 12:
       {
  *bits=16;
  break;
       }
       default:
       {
          lprintf(3, "compression method %d is not supported -> edit voice.conf",*compression);
          Kompressionmethod = 1;
          *bits=8;
       }
     }
     if (*speed == 0)
          *speed = 8000;
     sprintf(buffer, "AT+VSM=%d,%d",Kompressionmethod, (int)*speed);
     if (voice_command(buffer, "OK")!= (0x1000))
     sprintf(buffer, "AT+VSM=%d,%d,%d,%d",Kompressionmethod, (int)*speed, sil_sense, sil_clip);
     if (voice_command(buffer, "OK")!= (0x1000))
      {
         lprintf(3, "can't set compression and speed");
         voice_command("AT+VSM?", "OK");
      }
     lprintf(5, "Just for info: port_speed should be greater than %d bps",(*bits)*(*speed)*10/8);
     return((0)) ;
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]

variable_types: Kompressionmethod int


decompiled_code:
__int64 V253modem_stop_duplex()
{
voice_modem_state = 1;
return voice_command(*(_QWORD *)(voice_modem + 256LL), *(_QWORD *)(voice_modem + 264LL));
}

canonical_decompiled_code:
__int64 func1()
{
voice_modem_state = 1;
return voice_command(*(_QWORD *)(voice_modem + 256LL), *(_QWORD *)(voice_modem + 264LL));
}

original_code:
int V253modem_stop_duplex (void)
{
  voice_modem_state = (0x0001);
  return voice_command( voice_modem->stop_duplex_voice_cmnd ,
   voice_modem->stop_duplex_voice_answr );
}

canonical_original_code:
int V253modem_stop_duplex()
{
  voice_modem_state = (0x0001);
  return voice_command( voice_modem->stop_duplex_voice_cmnd ,
   voice_modem->stop_duplex_voice_answr );
}


decompiled_code:
__int64 __fastcall V253modem_set_device(unsigned int a1)
{
const char *v1; // rax
int v2; // eax
unsigned int v3; // edx
const char *v5; // rax

reset_watchdog();
v1 = (const char *)voice_device_mode_name(a1);
lprintf(6LL, "%s: %s: (%d)", (const char *)*voice_modem, v1, a1);
switch ( a1 )
{
case 1u:
v2 = voice_command("AT+VLS=0", "OK");
goto LABEL_3;
case 2u:
v2 = voice_command("AT+VLS=1", "OK");
goto LABEL_3;
case 3u:
v2 = voice_command("AT+VLS=11", "OK");
goto LABEL_3;
case 4u:
v2 = voice_command("AT+VLS=6", "OK");
goto LABEL_3;
case 5u:
v2 = voice_command("AT+VLS=8", "OK");
goto LABEL_3;
case 6u:
v2 = voice_command("AT+VLS=4", "OK");
goto LABEL_3;
case 7u:
v2 = voice_command("AT+VLS=2", "OK");
goto LABEL_3;
case 8u:
v2 = voice_command("AT+VLS=9", "OK");
goto LABEL_3;
case 9u:
v2 = voice_command("AT+VLS=5", "OK");
goto LABEL_3;
case 0xAu:
v2 = voice_command("AT+VLS=3", "OK");
goto LABEL_3;
case 0xBu:
v2 = voice_command("AT+VLS=13", "OK");
goto LABEL_3;
case 0xCu:
v2 = voice_command("AT+VLS=7", "OK");
LABEL_3:
v3 = 0;
if ( v2 != 4096 )
{
v5 = (const char *)voice_device_mode_name(a1);
lprintf(3LL, "can't set %s (modem hardware can't do that)", v5);
v3 = 16385;
}
break;
default:
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, a1);
v3 = -1;
break;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
const char *v1; // rax
int v2; // eax
unsigned int v3; // edx
const char *v5; // rax

reset_watchdog();
v1 = (const char *)voice_device_mode_name(a1);
lprintf(6LL, "%s: %s: (%d)", (const char *)*voice_modem, v1, a1);
switch ( a1 )
{
case 1u:
v2 = voice_command("AT+VLS=0", "OK");
goto LABEL_3;
case 2u:
v2 = voice_command("AT+VLS=1", "OK");
goto LABEL_3;
case 3u:
v2 = voice_command("AT+VLS=11", "OK");
goto LABEL_3;
case 4u:
v2 = voice_command("AT+VLS=6", "OK");
goto LABEL_3;
case 5u:
v2 = voice_command("AT+VLS=8", "OK");
goto LABEL_3;
case 6u:
v2 = voice_command("AT+VLS=4", "OK");
goto LABEL_3;
case 7u:
v2 = voice_command("AT+VLS=2", "OK");
goto LABEL_3;
case 8u:
v2 = voice_command("AT+VLS=9", "OK");
goto LABEL_3;
case 9u:
v2 = voice_command("AT+VLS=5", "OK");
goto LABEL_3;
case 0xAu:
v2 = voice_command("AT+VLS=3", "OK");
goto LABEL_3;
case 0xBu:
v2 = voice_command("AT+VLS=13", "OK");
goto LABEL_3;
case 0xCu:
v2 = voice_command("AT+VLS=7", "OK");
LABEL_3:
v3 = 0;
if ( v2 != 4096 )
{
v5 = (const char *)voice_device_mode_name(a1);
lprintf(3LL, "can't set %s (modem hardware can't do that)", v5);
v3 = 16385;
}
break;
default:
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, a1);
v3 = -1;
break;
}
return v3;
}

original_code:
int V253modem_set_device (int device)
     {
       int Result;
       reset_watchdog();
       lprintf(6, "%s: %s: (%d)", voice_modem->name,
        voice_device_mode_name(device), device);
     switch (device)
          {
          case (0x0001):
     Result = voice_command("AT+VLS=0", "OK");
     break;
          case (0x0002):
     Result = voice_command("AT+VLS=1", "OK");
     break;
          case (0x0003):
     Result = voice_command("AT+VLS=11", "OK");
     break;
          case (0x0004):
     Result = voice_command("AT+VLS=6", "OK");
     break;
          case (0x0006):
     Result = voice_command("AT+VLS=4", "OK");
     break;
          case (0x0005):
     Result = voice_command("AT+VLS=8", "OK");
     break;
          case (0x0007) :
     Result = voice_command("AT+VLS=2", "OK");
     break;
          case (0x0008) :
     Result = voice_command("AT+VLS=9", "OK");
     break;
          case (0x0009) :
     Result = voice_command("AT+VLS=5", "OK");
     break;
          case (0x000A) :
     Result = voice_command("AT+VLS=3", "OK");
     break;
          case (0x000B):
     Result = voice_command("AT+VLS=13", "OK");
     break;
          case (0x000C):
     Result = voice_command("AT+VLS=7", "OK");
     break;
   default:
     lprintf(3, "%s: Unknown device (%d)",
      voice_modem->name, device);
     return((-1));
          }
     if (Result != (0x1000))
       {
  lprintf(3, "can't set %s (modem hardware can't do that)",
   voice_device_mode_name(device));
  return((0x4001));
       }
     return((0));
     }

canonical_original_code:
int V253modem_set_device(int device)
     {
       int Result;
       reset_watchdog();
       lprintf(6, "%s: %s: (%d)", voice_modem->name,
        voice_device_mode_name(device), device);
     switch (device)
          {
          case (0x0001):
     Result = voice_command("AT+VLS=0", "OK");
     break;
          case (0x0002):
     Result = voice_command("AT+VLS=1", "OK");
     break;
          case (0x0003):
     Result = voice_command("AT+VLS=11", "OK");
     break;
          case (0x0004):
     Result = voice_command("AT+VLS=6", "OK");
     break;
          case (0x0006):
     Result = voice_command("AT+VLS=4", "OK");
     break;
          case (0x0005):
     Result = voice_command("AT+VLS=8", "OK");
     break;
          case (0x0007) :
     Result = voice_command("AT+VLS=2", "OK");
     break;
          case (0x0008) :
     Result = voice_command("AT+VLS=9", "OK");
     break;
          case (0x0009) :
     Result = voice_command("AT+VLS=5", "OK");
     break;
          case (0x000A) :
     Result = voice_command("AT+VLS=3", "OK");
     break;
          case (0x000B):
     Result = voice_command("AT+VLS=13", "OK");
     break;
          case (0x000C):
     Result = voice_command("AT+VLS=7", "OK");
     break;
   default:
     lprintf(3, "%s: Unknown device (%d)",
      voice_modem->name, device);
     return((-1));
          }
     if (Result != (0x1000))
       {
  lprintf(3, "can't set %s (modem hardware can't do that)",
   voice_device_mode_name(device));
  return((0x4001));
       }
     return((0));
     }

variable_types: device int

variable_types: Result int


decompiled_code:
_BOOL8 __fastcall V253_check_rmd_adequation(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "V253modem") )
v1 = strcmp(a1, "Elsa") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "V253modem") )
v1 = strcmp(a1, "Elsa") == 0;
return v1;
}

original_code:
int V253_check_rmd_adequation(char *rmd_name)
{
   return !strncmp(rmd_name,
                   "V253modem",
                   sizeof("V253modem"))
          || !strncmp(rmd_name,
                      "Elsa",
                      sizeof("Elsa"));
}


decompiled_code:
__int64 V253_init_compression_table()
{
__int64 v0; // rdx
__int64 v1; // rax
__int64 result; // rax

memset(Kompressiontable, 1u, sizeof(Kompressiontable));
v0 = cvd[106];
Kompressiontable[0] = v0;
Kompressiontable[1] = v0;
Kompressiontable[2] = cvd[115];
Kompressiontable[4] = cvd[118];
Kompressiontable[5] = cvd[121];
v1 = cvd[109];
Kompressiontable[6] = v1;
Kompressiontable[7] = v1;
Kompressiontable[8] = v0;
Kompressiontable[9] = cvd[100];
Kompressiontable[10] = v1;
Kompressiontable[11] = cvd[112];
result = cvd[103];
Kompressiontable[12] = result;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdx
__int64 v1; // rax
__int64 result; // rax

memset(Kompressiontable, 1u, sizeof(Kompressiontable));
v0 = cvd[106];
Kompressiontable[0] = v0;
Kompressiontable[1] = v0;
Kompressiontable[2] = cvd[115];
Kompressiontable[4] = cvd[118];
Kompressiontable[5] = cvd[121];
v1 = cvd[109];
Kompressiontable[6] = v1;
Kompressiontable[7] = v1;
Kompressiontable[8] = v0;
Kompressiontable[9] = cvd[100];
Kompressiontable[10] = v1;
Kompressiontable[11] = cvd[112];
result = cvd[103];
Kompressiontable[12] = result;
return result;
}

original_code:
void V253_init_compression_table() {
  memset( Kompressiontable, 1, sizeof(Kompressiontable) );
  Kompressiontable[0]=cvd.compression_8bit_linear_unsigned.d.i;
  Kompressiontable[1]=cvd.compression_8bit_linear_unsigned.d.i;
  Kompressiontable[2]=cvd.compression_2bit_adpcm.d.i;
  Kompressiontable[4]=cvd.compression_4bit_adpcm.d.i;
  Kompressiontable[5]=cvd.compression_4bit_ima_adpcm.d.i;
  Kompressiontable[6]=cvd.compression_8bit_ulaw.d.i;
  Kompressiontable[7]=cvd.compression_8bit_ulaw.d.i;
  Kompressiontable[8]=cvd.compression_8bit_linear_unsigned.d.i;
  Kompressiontable[9]=cvd.compression_8bit_linear_signed.d.i;
  Kompressiontable[10]=cvd.compression_8bit_ulaw.d.i;
  Kompressiontable[11]=cvd.compression_8bit_alaw.d.i;
  Kompressiontable[12]=cvd.compression_16bit_linear_signed.d.i;
}


decompiled_code:
char V253_querry_compressions()
{
char result; // al
__int64 v1; // rax
bool v2; // zf
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

memset(v9, 0, 0x100uLL);
if ( !cvd[97] )
return lprintf(5LL, "voice compression querry disabled");
if ( !(unsigned int)voice_command("AT+VSM=?", &unk_180A) )
{
while ( !(unsigned int)voice_read(v9) )
{
if ( strstr(v9, "\"SIGNED PCM\",8") )
{
v1 = strtol(v9, 0LL, 10);
Kompressiontable[9] = v1;
lprintf(5LL, "Mapped signed PCM, 9 -> %d", v1);
}
else if ( strstr(v9, "\"SIGNED PCM\",16") )
{
v3 = strtol(v9, 0LL, 10);
Kompressiontable[12] = v3;
lprintf(5LL, "Mapped signed PCM, 12 -> %d", v3);
}
else if ( strstr(v9, "UNSIGNED PCM\",8") || strstr(v9, "8-BIT LINEAR") )
{
v4 = strtol(v9, 0LL, 10);
Kompressiontable[8] = v4;
Kompressiontable[1] = v4;
Kompressiontable[0] = v4;
lprintf(5LL, "Mapped default (8 bit linear), 0 -> %d", v4);
lprintf(5LL, "Mapped unsigned PCM, 1 -> %d", (unsigned int)Kompressiontable[1]);
lprintf(5LL, "Mapped 8 bit linear, 8 -> %d", (unsigned int)Kompressiontable[8]);
}
else if ( strstr(v9, "IMA ADPCM\",4") || strstr(v9, "4-BIT ADPCM") )
{
v5 = strtol(v9, 0LL, 10);
Kompressiontable[5] = v5;
lprintf(5LL, "Mapped 4 bit IMA ADPCM, 5 -> %d", v5);
}
else if ( strstr(v9, "ULAW") )
{
v6 = strtol(v9, 0LL, 10);
Kompressiontable[10] = v6;
lprintf(5LL, "Mapped ulaw, 10 -> %d", v6);
}
else if ( strstr(v9, "ALAW") )
{
v7 = strtol(v9, 0LL, 10);
Kompressiontable[11] = v7;
lprintf(5LL, "Mapped alaw, 11 -> %d", v7);
}
else if ( strstr(v9, "16-BIT LINEAR") )
{
v8 = strtol(v9, 0LL, 10);
Kompressiontable[13] = v8;
lprintf(5LL, "Mapped 16 bit linear, 13 -> %d", v8);
}
else
{
lprintf(5LL, "Unknown: %s", v9);
}
v2 = memcmp("OK", v9, 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
}
}
return lprintf(3LL, "voice compression querry failed");
}

canonical_decompiled_code:
char func6()
{
char result; // al
__int64 v1; // rax
bool v2; // zf
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

memset(v9, 0, 0x100uLL);
if ( !cvd[97] )
return lprintf(5LL, "voice compression querry disabled");
if ( !(unsigned int)voice_command("AT+VSM=?", &unk_180A) )
{
while ( !(unsigned int)voice_read(v9) )
{
if ( strstr(v9, "\"SIGNED PCM\",8") )
{
v1 = strtol(v9, 0LL, 10);
Kompressiontable[9] = v1;
lprintf(5LL, "Mapped signed PCM, 9 -> %d", v1);
}
else if ( strstr(v9, "\"SIGNED PCM\",16") )
{
v3 = strtol(v9, 0LL, 10);
Kompressiontable[12] = v3;
lprintf(5LL, "Mapped signed PCM, 12 -> %d", v3);
}
else if ( strstr(v9, "UNSIGNED PCM\",8") || strstr(v9, "8-BIT LINEAR") )
{
v4 = strtol(v9, 0LL, 10);
Kompressiontable[8] = v4;
Kompressiontable[1] = v4;
Kompressiontable[0] = v4;
lprintf(5LL, "Mapped default (8 bit linear), 0 -> %d", v4);
lprintf(5LL, "Mapped unsigned PCM, 1 -> %d", (unsigned int)Kompressiontable[1]);
lprintf(5LL, "Mapped 8 bit linear, 8 -> %d", (unsigned int)Kompressiontable[8]);
}
else if ( strstr(v9, "IMA ADPCM\",4") || strstr(v9, "4-BIT ADPCM") )
{
v5 = strtol(v9, 0LL, 10);
Kompressiontable[5] = v5;
lprintf(5LL, "Mapped 4 bit IMA ADPCM, 5 -> %d", v5);
}
else if ( strstr(v9, "ULAW") )
{
v6 = strtol(v9, 0LL, 10);
Kompressiontable[10] = v6;
lprintf(5LL, "Mapped ulaw, 10 -> %d", v6);
}
else if ( strstr(v9, "ALAW") )
{
v7 = strtol(v9, 0LL, 10);
Kompressiontable[11] = v7;
lprintf(5LL, "Mapped alaw, 11 -> %d", v7);
}
else if ( strstr(v9, "16-BIT LINEAR") )
{
v8 = strtol(v9, 0LL, 10);
Kompressiontable[13] = v8;
lprintf(5LL, "Mapped 16 bit linear, 13 -> %d", v8);
}
else
{
lprintf(5LL, "Unknown: %s", v9);
}
v2 = memcmp("OK", v9, 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
}
}
return lprintf(3LL, "voice compression querry failed");
}

original_code:
void V253_querry_compressions() {
     char buffer[(256)];
     memset( buffer, '\0', sizeof(buffer) );
     if (!cvd.enable_compression_mapping_querry.d.i) {
       lprintf(5, "voice compression querry disabled");
       return;
     }
     if (voice_command("AT+VSM=?", "") != (0))
       {
  lprintf(3, "voice compression querry failed");
  return;
       }
     do {
       if (voice_read(buffer) != (0))
  {
    lprintf(3, "voice compression querry failed");
    break;
   }
       if(strstr(buffer,"\"SIGNED PCM\",8")) {
  Kompressiontable[9]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped signed PCM, 9 -> %d",Kompressiontable[9]);
       } else if(strstr(buffer,"\"SIGNED PCM\",16")) {
  Kompressiontable[12]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped signed PCM, 12 -> %d",Kompressiontable[12]);
       } else if(strstr(buffer,"UNSIGNED PCM\",8")) {
  Kompressiontable[0]=
    Kompressiontable[1]=
    Kompressiontable[8]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped default (8 bit linear), 0 -> %d",Kompressiontable[0]);
  lprintf(5, "Mapped unsigned PCM, 1 -> %d",Kompressiontable[1]);
  lprintf(5, "Mapped 8 bit linear, 8 -> %d",Kompressiontable[8]);
       } else if(strstr(buffer,"8-BIT LINEAR")) {
  Kompressiontable[0]=
    Kompressiontable[1]=
    Kompressiontable[8]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped default (8 bit linear), 0 -> %d",Kompressiontable[0]);
  lprintf(5, "Mapped unsigned PCM, 1 -> %d",Kompressiontable[1]);
  lprintf(5, "Mapped 8 bit linear, 8 -> %d",Kompressiontable[8]);
       } else if(strstr(buffer,"IMA ADPCM\",4")) {
  Kompressiontable[5]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 4 bit IMA ADPCM, 5 -> %d",Kompressiontable[5]);
       } else if(strstr(buffer,"4-BIT ADPCM")) {
  Kompressiontable[5]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 4 bit IMA ADPCM, 5 -> %d",Kompressiontable[5]);
       } else if(strstr(buffer,"ULAW")) {
  Kompressiontable[10]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped ulaw, 10 -> %d",Kompressiontable[10]);
       } else if(strstr(buffer,"ALAW")) {
  Kompressiontable[11]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped alaw, 11 -> %d",Kompressiontable[11]);
       } else if(strstr(buffer,"16-BIT LINEAR")) {
  Kompressiontable[13]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 16 bit linear, 13 -> %d",Kompressiontable[13]);
       } else
  {
    lprintf(5, "Unknown: %s",buffer);
  }
     } while (strncmp("OK",buffer,2));
}

canonical_original_code:
void V253_querry_compressions() {
     char buffer[-1];
     memset( buffer, '\0', sizeof(buffer) );
     if (!cvd.enable_compression_mapping_querry.d.i) {
       lprintf(5, "voice compression querry disabled");
       return;
     }
     if (voice_command("AT+VSM=?", "") != (0))
       {
  lprintf(3, "voice compression querry failed");
  return;
       }
     do {
       if (voice_read(buffer) != (0))
  {
    lprintf(3, "voice compression querry failed");
    break;
   }
       if(strstr(buffer,"\"SIGNED PCM\",8")) {
  Kompressiontable[9]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped signed PCM, 9 -> %d",Kompressiontable[9]);
       } else if(strstr(buffer,"\"SIGNED PCM\",16")) {
  Kompressiontable[12]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped signed PCM, 12 -> %d",Kompressiontable[12]);
       } else if(strstr(buffer,"UNSIGNED PCM\",8")) {
  Kompressiontable[0]=
    Kompressiontable[1]=
    Kompressiontable[8]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped default (8 bit linear), 0 -> %d",Kompressiontable[0]);
  lprintf(5, "Mapped unsigned PCM, 1 -> %d",Kompressiontable[1]);
  lprintf(5, "Mapped 8 bit linear, 8 -> %d",Kompressiontable[8]);
       } else if(strstr(buffer,"8-BIT LINEAR")) {
  Kompressiontable[0]=
    Kompressiontable[1]=
    Kompressiontable[8]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped default (8 bit linear), 0 -> %d",Kompressiontable[0]);
  lprintf(5, "Mapped unsigned PCM, 1 -> %d",Kompressiontable[1]);
  lprintf(5, "Mapped 8 bit linear, 8 -> %d",Kompressiontable[8]);
       } else if(strstr(buffer,"IMA ADPCM\",4")) {
  Kompressiontable[5]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 4 bit IMA ADPCM, 5 -> %d",Kompressiontable[5]);
       } else if(strstr(buffer,"4-BIT ADPCM")) {
  Kompressiontable[5]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 4 bit IMA ADPCM, 5 -> %d",Kompressiontable[5]);
       } else if(strstr(buffer,"ULAW")) {
  Kompressiontable[10]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped ulaw, 10 -> %d",Kompressiontable[10]);
       } else if(strstr(buffer,"ALAW")) {
  Kompressiontable[11]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped alaw, 11 -> %d",Kompressiontable[11]);
       } else if(strstr(buffer,"16-BIT LINEAR")) {
  Kompressiontable[13]= strtol(buffer, ((void *)0), 10);
  lprintf(5, "Mapped 16 bit linear, 13 -> %d",Kompressiontable[13]);
       } else
  {
    lprintf(5, "Unknown: %s",buffer);
  }
     } while (strncmp("OK",buffer,2));
}


decompiled_code:
__int64 V253modem_init()
{
_BYTE v1[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing V253 voice modem");
V253_init_compression_table();
strcpy(s, "AT+FCLASS=8");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "could not set +FCLASS=8");
V253_querry_compressions();
sprintf(s, "AT+VSD=%d,%d", LODWORD(cvd[58]), LODWORD(cvd[55]));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold VSD");
if ( cvd[82] == -1LL )
cvd[82] = 50LL;
sprintf(s, "AT+VGT=%d", (unsigned int)((int)(255 * cvd[82]) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( cvd[79] == -1LL )
cvd[79] = 50LL;
sprintf(s, "AT+VGR=%d", (unsigned int)((int)(255 * cvd[79]) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(s, "AT+VRA=%d;+VRN=%d", LODWORD(cvd[199]), (unsigned int)((int)cvd[202] / 10));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
if ( cvd[70] && (unsigned int)voice_command("AT+IFC=2,2", "OK") == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_command("AT+VCID=1", "OK");
voice_command("AT+VNH=0", "OK");
voice_command("AT+VIT=0", "OK");
sprintf(s, "AT+VDR=1,%d", LODWORD(cvd[205]));
voice_command(s, "OK");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_BYTE v1[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing V253 voice modem");
func5();
strcpy(s, "AT+FCLASS=8");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "could not set +FCLASS=8");
func6();
sprintf(s, "AT+VSD=%d,%d", LODWORD(cvd[58]), LODWORD(cvd[55]));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold VSD");
if ( cvd[82] == -1LL )
cvd[82] = 50LL;
sprintf(s, "AT+VGT=%d", (unsigned int)((int)(255 * cvd[82]) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( cvd[79] == -1LL )
cvd[79] = 50LL;
sprintf(s, "AT+VGR=%d", (unsigned int)((int)(255 * cvd[79]) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(s, "AT+VRA=%d;+VRN=%d", LODWORD(cvd[199]), (unsigned int)((int)cvd[202] / 10));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
if ( cvd[70] && (unsigned int)voice_command("AT+IFC=2,2", "OK") == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_command("AT+VCID=1", "OK");
voice_command("AT+VNH=0", "OK");
voice_command("AT+VIT=0", "OK");
sprintf(s, "AT+VDR=1,%d", LODWORD(cvd[205]));
voice_command(s, "OK");
voice_modem_state = 1;
return 0LL;
}

original_code:
int V253modem_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing V253 voice modem");
     V253_init_compression_table();
     sprintf(buffer, "AT+FCLASS=8");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "could not set +FCLASS=8");
     V253_querry_compressions();
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i , (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold VSD");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 255 / 100 );
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 255 / 100 );
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set record volume");
     sprintf(buffer,
             "AT+VRA=%d;+VRN=%d",
             (int)cvd.ringback_goes_away.d.i,
             (int)cvd.ringback_never_came.d.i/10);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting ringback delay didn't work");
     if ((cvd.do_hard_flow.d.i) && (voice_command("AT+IFC=2,2", "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_command("AT+VCID=1", "OK");
     voice_command("AT+VNH=0", "OK");
     voice_command("AT+VIT=0", "OK");
     sprintf(buffer, "AT+VDR=1,%d", (int)cvd.ring_report_delay.d.i);
     voice_command(buffer, "OK");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
int V253modem_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing V253 voice modem");
     V253_init_compression_table();
     sprintf(buffer, "AT+FCLASS=8");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "could not set +FCLASS=8");
     V253_querry_compressions();
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i , (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold VSD");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 255 / 100 );
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 255 / 100 );
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set record volume");
     sprintf(buffer,
             "AT+VRA=%d;+VRN=%d",
             (int)cvd.ringback_goes_away.d.i,
             (int)cvd.ringback_never_came.d.i/10);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting ringback delay didn't work");
     if ((cvd.do_hard_flow.d.i) && (voice_command("AT+IFC=2,2", "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_command("AT+VCID=1", "OK");
     voice_command("AT+VNH=0", "OK");
     voice_command("AT+VIT=0", "OK");
     sprintf(buffer, "AT+VDR=1,%d", (int)cvd.ring_report_delay.d.i);
     voice_command(buffer, "OK");
     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; }


oops

decompiled_code:
void oops()
{
got_interrupt = 1;
}

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

original_code:
RETSIGTYPE oops()
  { got_interrupt=(1==1); }

canonical_original_code:
void oops()
  { got_interrupt=(1==1); }


lprintf

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

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

original_code: int lprintf(int level, const char *format, ...) { return 0; }

canonical_original_code: int lprintf(int level, char *format, ...) { return 0; }

variable_types: level int

variable_types:
format
char *


lputs

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

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

original_code: int lputs( int level, char * string ) { return 0; }

canonical_original_code: int lputs(int level, char *string) { return 0; }

variable_types:
string
char *


decompiled_code:
void __fastcall __noreturn exit_usage(const char *a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "%s: %s\n", a1, a2);
fwrite("valid options: -m, -M <mailaddr>, -f <file>, -Q, -s <speed>\n", 1uLL, 0x3CuLL, stderr);
exit(99);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "%s: %s\n", a1, a2);
fwrite("valid options: -m, -M <mailaddr>, -f <file>, -Q, -s <speed>\n", 1uLL, 0x3CuLL, stderr);
exit(99);
}

original_code:
void exit_usage( char * program, char * msg )
{
    if ( msg != ((void *)0) )
 fprintf( stderr, "%s: %s\n", program, msg );
    fprintf( stderr, "valid options: -m, -M <mailaddr>, -f <file>, -Q, -s <speed>\n" );
    exit(99);
}

canonical_original_code:
void exit_usage(char *program, char *msg)
{
    if ( msg != ((void *)0) )
 fprintf( stderr, "%s: %s\n", program, msg );
    fprintf( stderr, "valid options: -m, -M <mailaddr>, -f <file>, -Q, -s <speed>\n" );
    exit(99);
}

variable_types:
program
char *

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall Elsa_set_device(unsigned int a1)
{
const char *v1; // rax
unsigned int v2; // ebp
__int64 result; // rax
const char *v4; // rax

reset_watchdog();
v1 = (const char *)voice_device_mode_name(a1);
lprintf(6LL, "%s: %s: (%d)", (const char *)*voice_modem, v1, a1);
switch ( a1 )
{
case 1u:
case 2u:
v2 = voice_command("AT#VLS=0", "OK|VCON");
goto LABEL_3;
case 4u:
v2 = voice_command("AT#VLS=3", "OK|VCON");
goto LABEL_3;
case 6u:
v2 = voice_command("AT#VLS=2", "OK|VCON");
goto LABEL_3;
case 7u:
v2 = voice_command("AT#VLS=1", "OK|VCON");
goto LABEL_3;
case 9u:
v2 = voice_command("AT#VLS=4", "OK|VCON");
goto LABEL_3;
case 0xCu:
v2 = voice_command("AT#VLS=5", "OK|VCON");
LABEL_3:
result = 0LL;
if ( v2 - 4096 > 1 )
{
v4 = (const char *)voice_device_mode_name(a1);
lprintf(3LL, "can't set %s (modem hardware can't do that), error 0x%x", v4, v2);
result = 16385LL;
}
break;
default:
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
const char *v1; // rax
unsigned int v2; // ebp
__int64 result; // rax
const char *v4; // rax

reset_watchdog();
v1 = (const char *)voice_device_mode_name(a1);
lprintf(6LL, "%s: %s: (%d)", (const char *)*voice_modem, v1, a1);
switch ( a1 )
{
case 1u:
case 2u:
v2 = voice_command("AT#VLS=0", "OK|VCON");
goto LABEL_3;
case 4u:
v2 = voice_command("AT#VLS=3", "OK|VCON");
goto LABEL_3;
case 6u:
v2 = voice_command("AT#VLS=2", "OK|VCON");
goto LABEL_3;
case 7u:
v2 = voice_command("AT#VLS=1", "OK|VCON");
goto LABEL_3;
case 9u:
v2 = voice_command("AT#VLS=4", "OK|VCON");
goto LABEL_3;
case 0xCu:
v2 = voice_command("AT#VLS=5", "OK|VCON");
LABEL_3:
result = 0LL;
if ( v2 - 4096 > 1 )
{
v4 = (const char *)voice_device_mode_name(a1);
lprintf(3LL, "can't set %s (modem hardware can't do that), error 0x%x", v4, v2);
result = 16385LL;
}
break;
default:
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static int Elsa_set_device (int device)
     {
       int Result;
       reset_watchdog();
       lprintf(6, "%s: %s: (%d)", voice_modem->name,
        voice_device_mode_name(device), device);
       switch (device)
  {
  case (0x0001):
    Result = voice_command("AT#VLS=0", "OK|VCON");
    break;
  case (0x0002):
    Result = voice_command("AT#VLS=0", "OK|VCON");
    break;
  case (0x0009):
    Result = voice_command("AT#VLS=4", "OK|VCON");
    break;
  case (0x0004):
    Result = voice_command("AT#VLS=3", "OK|VCON");
    break;
  case (0x0006):
    Result = voice_command("AT#VLS=2", "OK|VCON");
    break;
  case (0x000C):
    Result = voice_command("AT#VLS=5", "OK|VCON");
    break;
  case (0x0007):
    Result = voice_command("AT#VLS=1", "OK|VCON");
    break;
  default:
    lprintf(3, "%s: Unknown device (%d)",
     voice_modem->name, device);
    return((-1));
          }
       if ((Result != (0x1000)) && (Result != (0x1001)))
  {
    lprintf(3,
     "can't set %s (modem hardware can't do that), error 0x%x",
     voice_device_mode_name(device),
     Result);
    return((0x4001));
  }
       return((0));
     }

canonical_original_code:
static int Elsa_set_device(int device)
     {
       int Result;
       reset_watchdog();
       lprintf(6, "%s: %s: (%d)", voice_modem->name,
        voice_device_mode_name(device), device);
       switch (device)
  {
  case (0x0001):
    Result = voice_command("AT#VLS=0", "OK|VCON");
    break;
  case (0x0002):
    Result = voice_command("AT#VLS=0", "OK|VCON");
    break;
  case (0x0009):
    Result = voice_command("AT#VLS=4", "OK|VCON");
    break;
  case (0x0004):
    Result = voice_command("AT#VLS=3", "OK|VCON");
    break;
  case (0x0006):
    Result = voice_command("AT#VLS=2", "OK|VCON");
    break;
  case (0x000C):
    Result = voice_command("AT#VLS=5", "OK|VCON");
    break;
  case (0x0007):
    Result = voice_command("AT#VLS=1", "OK|VCON");
    break;
  default:
    lprintf(3, "%s: Unknown device (%d)",
     voice_modem->name, device);
    return((-1));
          }
       if ((Result != (0x1000)) && (Result != (0x1001)))
  {
    lprintf(3,
     "can't set %s (modem hardware can't do that), error 0x%x",
     voice_device_mode_name(device),
     Result);
    return((0x4001));
  }
       return((0));
     }


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

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 7200 )
{
lprintf(3LL, "%s: Illegal sample speed (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 7200LL;
}
v5 = *a1;
if ( *a1 == 2 )
{
voice_command("AT#VBS=2", "OK");
*a3 = 2;
result = 0LL;
}
else if ( v5 == 3 )
{
voice_command("AT#VBS=3", "OK");
*a3 = 3;
result = 0LL;
}
else if ( v5 == 4 )
{
voice_command("AT#VBS=4", "OK");
*a3 = 4;
result = 0LL;
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

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

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 7200 )
{
lprintf(3LL, "%s: Illegal sample speed (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 7200LL;
}
v5 = *a1;
if ( *a1 == 2 )
{
voice_command("AT#VBS=2", "OK");
*a3 = 2;
result = 0LL;
}
else if ( v5 == 3 )
{
voice_command("AT#VBS=3", "OK");
*a3 = 3;
result = 0LL;
}
else if ( v5 == 4 )
{
voice_command("AT#VBS=4", "OK");
*a3 = 4;
result = 0LL;
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Elsa_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 7200;
     if (*speed != 7200)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, *speed);
          return((-1));
          };
     if (*compression == 2)
          {
          voice_command("AT#VBS=2", "OK");
          *bits = 2;
          return((0));
          }
     if (*compression == 3)
          {
          voice_command("AT#VBS=3", "OK");
          *bits = 3;
          return((0));
          }
     if (*compression == 4)
          {
          voice_command("AT#VBS=4", "OK");
          *bits = 4;
          return((0));
          }
     lprintf(3, "%s: Illegal voice compression method (%d)",
      voice_modem->name, *compression);
     return((-1));
     }

canonical_original_code:
static int Elsa_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 7200;
     if (*speed != 7200)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, *speed);
          return((-1));
          };
     if (*compression == 2)
          {
          voice_command("AT#VBS=2", "OK");
          *bits = 2;
          return((0));
          }
     if (*compression == 3)
          {
          voice_command("AT#VBS=3", "OK");
          *bits = 3;
          return((0));
          }
     if (*compression == 4)
          {
          voice_command("AT#VBS=4", "OK");
          *bits = 4;
          return((0));
          }
     lprintf(3, "%s: Illegal voice compression method (%d)",
      voice_modem->name, *compression);
     return((-1));
     }


decompiled_code:
__int64 Elsa_init()
{
_BYTE v1[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Elsa voice modem");
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence_len VSP");
strcpy(s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy(s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy(s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set BDR=16");
strcpy(s, "AT#VTD=3F,3F,3F");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf(s, "AT#VSS=%1u", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 58)) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold VSS");
strcpy(s, "ATS30=60");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set S30");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#VGT=%d", (unsigned int)((int)(127 * *((_QWORD *)&cvd + 82)) / 100 + 128));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(s, "AT#VGR=%d", (unsigned int)((int)(127 * *((_QWORD *)&cvd + 79)) / 100 + 128));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(s, "AT+VRA=%d;+VRN=%d", *((unsigned int *)&cvd + 398), (unsigned int)((int)*((_QWORD *)&cvd + 202) / 10));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(2LL);
if ( *((_QWORD *)&cvd + 70) )
{
if ( (unsigned int)voice_command(Elsa_hardflow_cmnd, "OK") != 4096 )
{
if ( (unsigned int)voice_command(Elsa_hardflow_cmnd_alternate, "OK") != 4096 )
{
lprintf(3LL, "can't turn on hardware flow control");
goto LABEL_26;
}
Elsa[7] = Elsa_hardflow_cmnd_alternate;
}
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
LABEL_26:
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Elsa voice modem");
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence_len VSP");
strcpy(s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy(s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy(s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set BDR=16");
strcpy(s, "AT#VTD=3F,3F,3F");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf(s, "AT#VSS=%1u", (unsigned int)((int)(3 * *((_QWORD *)&cvd + 58)) / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold VSS");
strcpy(s, "ATS30=60");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set S30");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#VGT=%d", (unsigned int)((int)(127 * *((_QWORD *)&cvd + 82)) / 100 + 128));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(s, "AT#VGR=%d", (unsigned int)((int)(127 * *((_QWORD *)&cvd + 79)) / 100 + 128));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(s, "AT+VRA=%d;+VRN=%d", *((unsigned int *)&cvd + 398), (unsigned int)((int)*((_QWORD *)&cvd + 202) / 10));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(2LL);
if ( *((_QWORD *)&cvd + 70) )
{
if ( (unsigned int)voice_command(Elsa_hardflow_cmnd, "OK") != 4096 )
{
if ( (unsigned int)voice_command(Elsa_hardflow_cmnd_alternate, "OK") != 4096 )
{
lprintf(3LL, "can't turn on hardware flow control");
goto LABEL_26;
}
Elsa[7] = Elsa_hardflow_cmnd_alternate;
}
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
LABEL_26:
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Elsa_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Elsa voice modem");
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence_len VSP");
     sprintf(buffer, "AT#VSD=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VSD=0");
     sprintf(buffer, "AT#VBS=4");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VBS=4");
     sprintf(buffer, "AT#BDR=16");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set BDR=16");
     sprintf(buffer, "AT#VTD=3F,3F,3F");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VTD=3F");
     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 VSS");
     sprintf(buffer, "ATS30=60");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set S30");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT#VGT=%d", (int)cvd.transmit_gain.d.i * 127 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT#VGR=%d", (int)cvd.receive_gain.d.i * 127 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set record volume");
     sprintf(buffer,
             "AT+VRA=%d;+VRN=%d",
             (int)cvd.ringback_goes_away.d.i,
             (int)cvd.ringback_never_came.d.i/10);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting ringback delay didn't work");
     voice_modem->set_device((0x0002));
     if (cvd.do_hard_flow.d.i) {
       int succeeded = 0;
       if (voice_command(Elsa_hardflow_cmnd, "OK") == (0x1000)) {
          succeeded = 1;
       }
       else {
  if (voice_command(Elsa_hardflow_cmnd_alternate, "OK") == (0x1000)) {
            Elsa.hardflow_cmnd = Elsa_hardflow_cmnd_alternate;
            succeeded = 1;
         }
       }
       if (succeeded) {
  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 Elsa_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Elsa voice modem");
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence_len VSP");
     sprintf(buffer, "AT#VSD=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VSD=0");
     sprintf(buffer, "AT#VBS=4");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VBS=4");
     sprintf(buffer, "AT#BDR=16");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set BDR=16");
     sprintf(buffer, "AT#VTD=3F,3F,3F");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set VTD=3F");
     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 VSS");
     sprintf(buffer, "ATS30=60");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set S30");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT#VGT=%d", (int)cvd.transmit_gain.d.i * 127 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set speaker volume");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT#VGR=%d", (int)cvd.receive_gain.d.i * 127 / 100 + 128);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set record volume");
     sprintf(buffer,
             "AT+VRA=%d;+VRN=%d",
             (int)cvd.ringback_goes_away.d.i,
             (int)cvd.ringback_never_came.d.i/10);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting ringback delay didn't work");
     voice_modem->set_device((0x0002));
     if (cvd.do_hard_flow.d.i) {
       int succeeded = 0;
       if (voice_command(Elsa_hardflow_cmnd, "OK") == (0x1000)) {
          succeeded = 1;
       }
       else {
  if (voice_command(Elsa_hardflow_cmnd_alternate, "OK") == (0x1000)) {
            Elsa.hardflow_cmnd = Elsa_hardflow_cmnd_alternate;
            succeeded = 1;
         }
       }
       if (succeeded) {
  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: succeeded int


delay

decompiled_code:
int __fastcall delay(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
return usleep(1000 * a1);
}

original_code:
void delay (int waittime)
{
    usleep( waittime * 1000 );
}

canonical_original_code:
void delay(int waittime)
{
    usleep( waittime * 1000 );
}

variable_types: waittime int


decompiled_code:
bool __fastcall check_for_input(int a1)
{
int v1; // ebx
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v3.tv_usec = 0LL;
v3.tv_sec = 0LL;
v1 = select(1024, &readfds, 0LL, 0LL, &v3);
if ( v1 < 0 )
lprintf(1LL, "poll / select failed");
return v1 > 0;
}

canonical_decompiled_code:
bool __fastcall func1(int a1)
{
int v1; // ebx
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v3.tv_usec = 0LL;
v3.tv_sec = 0LL;
v1 = select(1024, &readfds, 0LL, 0LL, &v3);
if ( v1 < 0 )
lprintf(1LL, "poll / select failed");
return v1 > 0;
}

original_code:
boolean check_for_input (int filedes)
{
    fd_set readfds;
    struct timeval timeout;
    int ret;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((filedes) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((filedes) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = timeout.tv_usec = 0;
    ret = select( 1024 , &readfds, ((void *)0), ((void *)0), &timeout );
    if ( ret < 0 ) lprintf( 1, "poll / select failed" );
    return ( ret > 0 );
}

canonical_original_code:
char check_for_input(int filedes)
{
    struct fd_set readfds;
    struct timeval timeout;
    int ret;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((filedes) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((filedes) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = timeout.tv_usec = 0;
    ret = select( 1024 , &readfds, ((void *)0), ((void *)0), &timeout );
    if ( ret < 0 ) lprintf( 1, "poll / select failed" );
    return ( ret > 0 );
}

variable_types: filedes int

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }

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

variable_types: ret int

return_type: char


decompiled_code:
bool __fastcall wait_for_input(int a1, int a2)
{
struct timeval *v2; // r8
int v3; // ebx
__int64 v5[2]; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v2 = 0LL;
if ( a2 >= 0 )
{
v5[0] = a2 / 1000;
v5[1] = 1000 * (a2 % 1000);
v2 = (struct timeval *)v5;
}
v3 = select(1024, &readfds, 0LL, 0LL, v2);
lprintf(6LL, "select returned %d", (unsigned int)v3);
return v3 > 0;
}

canonical_decompiled_code:
bool __fastcall func2(int a1, int a2)
{
struct timeval *v2; // r8
int v3; // ebx
__int64 v5[2]; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v2 = 0LL;
if ( a2 >= 0 )
{
v5[0] = a2 / 1000;
v5[1] = 1000 * (a2 % 1000);
v2 = (struct timeval *)v5;
}
v3 = select(1024, &readfds, 0LL, 0LL, v2);
lprintf(6LL, "select returned %d", (unsigned int)v3);
return v3 > 0;
}

original_code:
boolean wait_for_input (int fd,int msecs)
{
    fd_set readfds;
    struct timeval timeout, *tptr;
    int slct;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if ( msecs >= 0 )
    {
 timeout.tv_sec = msecs / 1000;
 timeout.tv_usec = (msecs % 1000) * 1000;
 tptr = &timeout;
    }
    else
        tptr = ((void *)0);
    slct = select( 1024, &readfds, ((void *)0), ((void *)0), tptr );
    lprintf( 6, "select returned %d", slct );
    return ( slct>0 );
}

canonical_original_code:
char wait_for_input(int fd, int msecs)
{
    struct fd_set readfds;
    struct timeval timeout; struct timeval *tptr;
    int slct;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if ( msecs >= 0 )
    {
 timeout.tv_sec = msecs / 1000;
 timeout.tv_usec = (msecs % 1000) * 1000;
 tptr = &timeout;
    }
    else
        tptr = ((void *)0);
    slct = select( 1024, &readfds, ((void *)0), ((void *)0), tptr );
    lprintf( 6, "select returned %d", slct );
    return ( slct>0 );
}

variable_types: fd int

variable_types: msecs int

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

variable_types: slct int


decompiled_code:
void __fastcall fax_notify_program(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx
__pid_t v3; // eax

if ( !fax_file_names )
fax_file_names = (char *)&unk_DE1;
v1 = (char *)malloc(fax_fn_size + 138LL);
v2 = v1;
if ( v1 )
{
sprintf(
v1,
"%s %d '%s' %d %s >%s 2>&1 </dev/null",
"/usr/local/lib/mgetty+sendfax/new_fax",
fax_hangup_code,
(const char *)&fax_remote_id,
a1,
fax_file_names,
"/dev/console");
lprintf(5LL, "notify: '%.320s'", v2);
v3 = fork();
if ( v3 == -1 )
{
lprintf(1LL, "fork() failed");
}
else if ( !v3 )
{
close(0);
close(1);
close(2);
setpgrp();
setup_environment();
if ( system(v2) )
lprintf(1LL, "system() failed");
exit(0);
}
free(v2);
}
else
{
lprintf(1LL, "fax_notify_program: cannot malloc");
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx
__pid_t v3; // eax

if ( !fax_file_names )
fax_file_names = (char *)&unk_DE1;
v1 = (char *)malloc(fax_fn_size + 138LL);
v2 = v1;
if ( v1 )
{
sprintf(
v1,
"%s %d '%s' %d %s >%s 2>&1 </dev/null",
"/usr/local/lib/mgetty+sendfax/new_fax",
fax_hangup_code,
(const char *)&fax_remote_id,
a1,
fax_file_names,
"/dev/console");
lprintf(5LL, "notify: '%.320s'", v2);
v3 = fork();
if ( v3 == -1 )
{
lprintf(1LL, "fork() failed");
}
else if ( !v3 )
{
close(0);
close(1);
close(2);
setpgrp();
setup_environment();
if ( system(v2) )
lprintf(1LL, "system() failed");
exit(0);
}
free(v2);
}
else
{
lprintf(1LL, "fax_notify_program: cannot malloc");
}
}

original_code:
void fax_notify_program (int pagenum)
{
int r;
char * line;
    if ( fax_file_names == ((void *)0) ) fax_file_names="";
    line = malloc( fax_fn_size + sizeof( "/usr/local/lib/mgetty+sendfax/new_fax") + 100 );
    if ( line == ((void *)0) )
    {
 lprintf( 1, "fax_notify_program: cannot malloc" );
 return;
    }
    sprintf( line, "%s %d '%s' %d %s >%s 2>&1 </dev/null",
      "/usr/local/lib/mgetty+sendfax/new_fax",
      fax_hangup_code,
      fax_remote_id,
      pagenum,
      fax_file_names,
      "/dev/console");
    lprintf( 5, "notify: '%.320s'", line );
    switch( fork() )
    {
 case 0:
     close( 0 ); close( 1 ); close( 2 );
     setpgrp();
     setup_environment();
     r = system( line );
     if ( r != 0 )
  lprintf( 1, "system() failed" );
     exit(0);
 case -1:
     lprintf( 1, "fork() failed" );
     break;
    }
    free( line );
}

canonical_original_code:
void fax_notify_program(int pagenum)
{
int r;
char *line;
    if ( fax_file_names == ((void *)0) ) fax_file_names="";
    line = malloc( fax_fn_size + sizeof( "/usr/local/lib/mgetty+sendfax/new_fax") + 100 );
    if ( line == ((void *)0) )
    {
 lprintf( 1, "fax_notify_program: cannot malloc" );
 return;
    }
    sprintf( line, "%s %d '%s' %d %s >%s 2>&1 </dev/null",
      "/usr/local/lib/mgetty+sendfax/new_fax",
      fax_hangup_code,
      fax_remote_id,
      pagenum,
      fax_file_names,
      "/dev/console");
    lprintf( 5, "notify: '%.320s'", line );
    switch( fork() )
    {
 case 0:
     close( 0 ); close( 1 ); close( 2 );
     setpgrp();
     setup_environment();
     r = system( line );
     if ( r != 0 )
  lprintf( 1, "system() failed" );
     exit(0);
 case -1:
     lprintf( 1, "fork() failed" );
     break;
    }
    free( line );
}

variable_types: pagenum int

variable_types: r int

variable_types:
line
char *


decompiled_code:
int __fastcall fax2_highlevel_receive(__int64 a1, __int64 a2, _DWORD *a3, __int64 a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
int result; // eax
_BYTE v13[120]; // [rsp+0h] [rbp-78h] BYREF

tio_get(a1, v13);
if ( a5 )
{
tio_set_speed(v13, a5);
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", a5);
if ( a5 == 19200 )
lprintf(3LL, ">> try using 'switchbd 0'");
else
lprintf(3LL, ">> try using 'switchbd 19200' or 'switchbd 0'");
}
else
{
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", 0LL);
lprintf(3LL, ">> try using 'switchbd 19200'");
}
fax_hangup = 1;
LABEL_3:
make_utmp_wtmp(Device, 7LL, "fax_inc", &fax_remote_id);
tio_set_flow_control((unsigned int)a1, v13, 3LL);
tio_set((unsigned int)a1, v13);
fax_set_flowcontrol((unsigned int)a1, 1LL);
result = fax_get_pages((unsigned int)a1, a2, a4, a6, a7, a8);
if ( faxpoll_server_file )
{
if ( fax_poll_req )
{
lprintf(4LL, "starting fax poll send...");
result = faxpoll_send_pages(a1, a3, (__int64)v13, (const char *)faxpoll_server_file);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2, _DWORD *a3, __int64 a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
int result; // eax
_BYTE v13[120]; // [rsp+0h] [rbp-78h] BYREF

tio_get(a1, v13);
if ( a5 )
{
tio_set_speed(v13, a5);
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", a5);
if ( a5 == 19200 )
lprintf(3LL, ">> try using 'switchbd 0'");
else
lprintf(3LL, ">> try using 'switchbd 19200' or 'switchbd 0'");
}
else
{
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", 0LL);
lprintf(3LL, ">> try using 'switchbd 19200'");
}
fax_hangup = 1;
LABEL_3:
make_utmp_wtmp(Device, 7LL, "fax_inc", &fax_remote_id);
tio_set_flow_control((unsigned int)a1, v13, 3LL);
tio_set((unsigned int)a1, v13);
fax_set_flowcontrol((unsigned int)a1, 1LL);
result = fax_get_pages((unsigned int)a1, a2, a4, a6, a7, a8);
if ( faxpoll_server_file )
{
if ( fax_poll_req )
{
lprintf(4LL, "starting fax poll send...");
result = func2(a1, a3, (__int64)v13, (const char *)faxpoll_server_file);
}
}
return result;
}

original_code:
void fax2_highlevel_receive
     (int fd,int * pn,int * ppn,char * spool_in,unsigned int switchbd,int uid,int gid,int mode)
{
TIO tio;
    tio_get( fd, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    fax_wait_for( "OK", 0 );
    if ( fax_hangup_code == -6 )
    {
 lprintf( 3, ">> The problem seen above might be caused by a wrong value of the" );
 lprintf( 3, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", switchbd );
 if ( switchbd > 0 && switchbd != 19200 )
  lprintf( 3, ">> try using 'switchbd 19200' or 'switchbd 0'");
 else if ( switchbd > 0 )
  lprintf( 3, ">> try using 'switchbd 0'" );
 else lprintf( 3, ">> try using 'switchbd 19200'" );
 fax_hangup = 1;
    }
    make_utmp_wtmp( Device, 7, "fax_inc", fax_remote_id );
    tio_set_flow_control( fd, &tio,
    (0x01 | (0x02 | 0x04)) & (0x01|0x02) );
    tio_set( fd, &tio );
    fax_set_flowcontrol( fd, (0x01 | (0x02 | 0x04)) & 0x01 );
    fax_get_pages( fd, pn, spool_in, uid, gid, mode );
    if ( faxpoll_server_file != ((void *)0) && fax_poll_req )
    {
 lprintf( 4, "starting fax poll send..." );
 faxpoll_send_pages( fd, ppn, &tio, faxpoll_server_file );
    }
}

canonical_original_code:
void fax2_highlevel_receive(int fd, int *pn, int *ppn, char *spool_in, unsigned int switchbd, int uid, int gid, int mode)
{
struct termios tio;
    tio_get( fd, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    fax_wait_for( "OK", 0 );
    if ( fax_hangup_code == -6 )
    {
 lprintf( 3, ">> The problem seen above might be caused by a wrong value of the" );
 lprintf( 3, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", switchbd );
 if ( switchbd > 0 && switchbd != 19200 )
  lprintf( 3, ">> try using 'switchbd 19200' or 'switchbd 0'");
 else if ( switchbd > 0 )
  lprintf( 3, ">> try using 'switchbd 0'" );
 else lprintf( 3, ">> try using 'switchbd 19200'" );
 fax_hangup = 1;
    }
    make_utmp_wtmp( Device, 7, "fax_inc", fax_remote_id );
    tio_set_flow_control( fd, &tio,
    (0x01 | (0x02 | 0x04)) & (0x01|0x02) );
    tio_set( fd, &tio );
    fax_set_flowcontrol( fd, (0x01 | (0x02 | 0x04)) & 0x01 );
    fax_get_pages( fd, pn, spool_in, uid, gid, mode );
    if ( faxpoll_server_file != ((void *)0) && fax_poll_req )
    {
 lprintf( 4, "starting fax poll send..." );
 faxpoll_send_pages( fd, ppn, &tio, faxpoll_server_file );
    }
}

variable_types:
pn
int *

variable_types:
ppn
int *

variable_types:
switchbd
unsigned int

variable_types: uid int

variable_types: gid int

variable_types: mode int

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


faxrec

decompiled_code:
__int64 __fastcall faxrec(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, const char *a6)
{
char *v10; // rax
__int64 v11; // rbx
__int64 v12; // r15
__int64 v13; // r14
__int64 v14; // r13
const char *v15; // r12
const char *v16; // rbp
unsigned int v17; // eax
unsigned int v19; // [rsp+8h] [rbp-40h] BYREF
unsigned int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v20[0] = 0;
v19 = 0;
lprintf(5LL, "fax receiver: entry");
fax_fn_size = 4096;
v10 = (char *)malloc(0x1000uLL);
fax_file_names = v10;
if ( v10 )
*v10 = 0;
if ( (unsigned int)(modem_type - 4) > 1 )
return lprintf(1LL, "faxrec: required modem driver (%d) not compiled in, abort", modem_type);
fax2_highlevel_receive(0LL, (__int64)v20, &v19, a1, a2, a3, a4, a5);
call_done = time(0LL);
lprintf(5LL, "fax receiver: hangup & end");
if ( a6 )
{
if ( *a6 )
fax_notify_mail(v20[0], v19, a6);
}
fax_notify_program(v20[0]);
call_done -= call_start;
v11 = call_done;
v12 = v19;
v13 = v20[0];
v14 = fax_hangup_code;
v15 = (const char *)CallName;
v16 = (const char *)CallerId;
v17 = getpid();
return lprintf(
2LL,
"fax dev=%s, pid=%d, caller='%s', name='%s', id='%s', +FHNG=%03d, pages=%d/%d, time=%02d:%02d:%02d\n",
Device,
v17,
v16,
v15,
(const char *)&fax_remote_id,
v14,
v13,
v12,
v11 / 3600,
v11 / 60 % 60,
v11 % 60);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, const char *a6)
{
char *v10; // rax
__int64 v11; // rbx
__int64 v12; // r15
__int64 v13; // r14
__int64 v14; // r13
const char *v15; // r12
const char *v16; // rbp
unsigned int v17; // eax
unsigned int v19; // [rsp+8h] [rbp-40h] BYREF
unsigned int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v20[0] = 0;
v19 = 0;
lprintf(5LL, "fax receiver: entry");
fax_fn_size = 4096;
v10 = (char *)malloc(0x1000uLL);
fax_file_names = v10;
if ( v10 )
*v10 = 0;
if ( (unsigned int)(modem_type - 4) > 1 )
return lprintf(1LL, "faxrec: required modem driver (%d) not compiled in, abort", modem_type);
func3(0LL, (__int64)v20, &v19, a1, a2, a3, a4, a5);
call_done = time(0LL);
lprintf(5LL, "fax receiver: hangup & end");
if ( a6 )
{
if ( *a6 )
func0(v20[0], v19, a6);
}
func1(v20[0]);
call_done -= call_start;
v11 = call_done;
v12 = v19;
v13 = v20[0];
v14 = fax_hangup_code;
v15 = (const char *)CallName;
v16 = (const char *)CallerId;
v17 = getpid();
return lprintf(
2LL,
"fax dev=%s, pid=%d, caller='%s', name='%s', id='%s', +FHNG=%03d, pages=%d/%d, time=%02d:%02d:%02d\n",
Device,
v17,
v16,
v15,
(const char *)&fax_remote_id,
v14,
v13,
v12,
v11 / 3600,
v11 / 60 % 60,
v11 % 60);
}

original_code:
void faxrec (char * spool_in,unsigned int switchbd,int uid,int gid,int mode,char * mail_to)
{
int pagenum = 0, ppagenum = 0;
    lprintf( 5, "fax receiver: entry" );
    fax_file_names = malloc( fax_fn_size = 1024 * 4 );
    if ( fax_file_names != ((void *)0) ) fax_file_names[0] = 0;
    if ( modem_type == Mt_class2 || modem_type == Mt_class2_0 )
 fax2_highlevel_receive( 0, &pagenum, &ppagenum, spool_in,
    switchbd, uid, gid, mode );
    else
 { lprintf( 1, "faxrec: required modem driver (%d) not compiled in, abort", (int) modem_type ); return ; }
    call_done = time(((void *)0));
    lprintf( 5, "fax receiver: hangup & end" );
    if ( mail_to != ((void *)0) && strlen(mail_to) != 0 )
        fax_notify_mail( pagenum, ppagenum, mail_to );
    fax_notify_program( pagenum );
    call_done = call_done - call_start;
    lprintf( 2,
"fax dev=%s, pid=%d, caller='%s', name='%s', id='%s', +FHNG=%03d, pages=%d/%d, time=%02d:%02d:%02d\n",
 Device, getpid(), CallerId, CallName, fax_remote_id,
 fax_hangup_code, pagenum, ppagenum,
 call_done / 3600, (call_done / 60) % 60, call_done % 60);
}

canonical_original_code:
void faxrec(char *spool_in, unsigned int switchbd, int uid, int gid, int mode, char *mail_to)
{
int pagenum = 0; int ppagenum = 0;
    lprintf( 5, "fax receiver: entry" );
    fax_file_names = malloc( fax_fn_size = 1024 * 4 );
    if ( fax_file_names != ((void *)0) ) fax_file_names[0] = 0;
    if ( modem_type == Mt_class2 || modem_type == Mt_class2_0 )
 fax2_highlevel_receive( 0, &pagenum, &ppagenum, spool_in,
    switchbd, uid, gid, mode );
    else
 { lprintf( 1, "faxrec: required modem driver (%d) not compiled in, abort", (int) modem_type ); return ; }
    call_done = time(((void *)0));
    lprintf( 5, "fax receiver: hangup & end" );
    if ( mail_to != ((void *)0) && strlen(mail_to) != 0 )
        fax_notify_mail( pagenum, ppagenum, mail_to );
    fax_notify_program( pagenum );
    call_done = call_done - call_start;
    lprintf( 2,
"fax dev=%s, pid=%d, caller='%s', name='%s', id='%s', +FHNG=%03d, pages=%d/%d, time=%02d:%02d:%02d\n",
 Device, getpid(), CallerId, CallName, fax_remote_id,
 fax_hangup_code, pagenum, ppagenum,
 call_done / 3600, (call_done / 60) % 60, call_done % 60);
}

variable_types: ppagenum int


decompiled_code:
__int64 voice_read_byte()
{
int v0; // eax
int v2; // eax

if ( input_pos < input_count )
goto LABEL_2;
v2 = read(voice_fd, input_buffer, 0x400uLL);
input_count = v2;
if ( v2 < 0 )
return (unsigned int)-*_errno_location();
if ( v2 )
{
input_pos = 0;
LABEL_2:
v0 = input_pos++;
return (unsigned __int8)input_buffer[v0];
}
return 4294967285LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v2; // eax

if ( input_pos < input_count )
goto LABEL_2;
v2 = read(voice_fd, input_buffer, 0x400uLL);
input_count = v2;
if ( v2 < 0 )
return (unsigned int)-*_errno_location();
if ( v2 )
{
input_pos = 0;
LABEL_2:
v0 = input_pos++;
return (unsigned __int8)input_buffer[v0];
}
return 4294967285LL;
}

original_code:
int voice_read_byte(void)
     {
     if (input_pos >= input_count)
          {
          input_count = read(voice_fd, input_buffer, sizeof(input_buffer));
          if (input_count < 0)
               return(-(*__errno_location ()));
          if (input_count == 0)
               return(-11);
          input_pos = 0;
          }
     return(input_buffer[input_pos++]);
     }

canonical_original_code:
int voice_read_byte()
     {
     if (input_pos >= input_count)
          {
          input_count = read(voice_fd, input_buffer, sizeof(input_buffer));
          if (input_count < 0)
               return(-(*__errno_location ()));
          if (input_count == 0)
               return(-11);
          input_pos = 0;
          }
     return(input_buffer[input_pos++]);
     }


decompiled_code:
__int64 voice_read_char()
{
time_t v0; // rbx
__int64 result; // rax

v0 = *((_QWORD *)&cvd + 25) + time(0LL);
while ( time(0LL) <= v0 )
{
result = voice_read_byte();
if ( (int)result >= 0 )
return result;
if ( (_DWORD)result != -4 && (_DWORD)result != -11 )
{
lprintf(3LL, "%s: could not read character from voice modem", program_name);
return 0xFFFFFFFFLL;
}
delay(*((unsigned int *)&cvd + 176));
}
lprintf(3LL, "%s: timeout while reading character from voice modem", program_name);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
time_t v0; // rbx
__int64 result; // rax

v0 = *((_QWORD *)&cvd + 25) + time(0LL);
while ( time(0LL) <= v0 )
{
result = func0();
if ( (int)result >= 0 )
return result;
if ( (_DWORD)result != -4 && (_DWORD)result != -11 )
{
lprintf(3LL, "%s: could not read character from voice modem", program_name);
return 0xFFFFFFFFLL;
}
delay(*((unsigned int *)&cvd + 176));
}
lprintf(3LL, "%s: timeout while reading character from voice modem", program_name);
return 0xFFFFFFFFLL;
}

original_code:
int voice_read_char(void)
     {
     time_t timeout;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while (timeout >= time(((void *)0)))
          {
          int result;
          result = voice_read_byte();
          if (result >= 0)
               return(result);
          if ((result < 0) && ((result != -4) && (result != -11)))
               {
               lprintf(3, "%s: could not read character from voice modem", program_name);
               return((-1));
               };
          delay(cvd.poll_interval.d.i);
          };
     lprintf(3, "%s: timeout while reading character from voice modem", program_name);
     return((-1));
     }

canonical_original_code:
int voice_read_char()
     {
     long timeout;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while (timeout >= time(((void *)0)))
          {
          int result;
          result = voice_read_byte();
          if (result >= 0)
               return(result);
          if ((result < 0) && ((result != -4) && (result != -11)))
               {
               lprintf(3, "%s: could not read character from voice modem", program_name);
               return((-1));
               };
          delay(cvd.poll_interval.d.i);
          };
     lprintf(3, "%s: timeout while reading character from voice modem", program_name);
     return((-1));
     }

variable_types: timeout long

variable_types: result int


decompiled_code:
__int64 __fastcall voice_read(_BYTE *a1)
{
_BYTE *v1; // r13
int v2; // er12
unsigned int v3; // ebx
unsigned int v4; // eax
bool v5; // bp

v1 = a1;
lprintf(6LL, "%s: ", (const char *)*voice_modem);
*a1 = 0;
v2 = 0;
while ( 1 )
{
v4 = voice_read_char();
v3 = v4;
if ( v4 == -1 )
break;
if ( v4 == 16 )
{
v3 = voice_read_char();
if ( v3 != -1 )
{
lputs(6LL, "<DLE> <");
lputc(6LL, (unsigned int)(char)v3);
lputc(6LL, 62LL);
(*(void (__fastcall **)(_QWORD))(voice_modem + 296LL))((unsigned int)(char)v3);
lprintf(6LL, "%s: ", (const char *)*voice_modem);
v3 = 0;
}
return v3;
}
v5 = v4 != 10;
if ( v4 != 13 && v4 != 10 && (v4 & 0xFFFFFFFD) != 17 )
{
*v1++ = v4;
++v2;
lputc(6LL, (unsigned int)(char)v4);
}
if ( !v5 && v2 != 0 || v2 > 254 )
{
*v1 = 0;
return 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
_BYTE *v1; // r13
int v2; // er12
unsigned int v3; // ebx
unsigned int v4; // eax
bool v5; // bp

v1 = a1;
lprintf(6LL, "%s: ", (const char *)*voice_modem);
*a1 = 0;
v2 = 0;
while ( 1 )
{
v4 = func1();
v3 = v4;
if ( v4 == -1 )
break;
if ( v4 == 16 )
{
v3 = func1();
if ( v3 != -1 )
{
lputs(6LL, "<DLE> <");
lputc(6LL, (unsigned int)(char)v3);
lputc(6LL, 62LL);
(*(void (__fastcall **)(_QWORD))(voice_modem + 296LL))((unsigned int)(char)v3);
lprintf(6LL, "%s: ", (const char *)*voice_modem);
v3 = 0;
}
return v3;
}
v5 = v4 != 10;
if ( v4 != 13 && v4 != 10 && (v4 & 0xFFFFFFFD) != 17 )
{
*v1++ = v4;
++v2;
lputc(6LL, (unsigned int)(char)v4);
}
if ( !v5 && v2 != 0 || v2 > 254 )
{
*v1 = 0;
return 0;
}
}
return v3;
}

original_code:
int voice_read(char *buffer)
     {
     int char_read;
     int number_chars = 0;
     lprintf(6, "%s: ", voice_modem->name);
     strcpy(buffer, "");
     do
          {
          if ((char_read = voice_read_char()) == (-1))
               return((-1));
          if (char_read == (0x10))
               {
               if ((char_read = voice_read_char()) == (-1))
                    return((-1));
               lputs(6, "<DLE> <");
               lputc(6, char_read);
               lputc(6, '>');
               voice_modem->handle_dle(char_read);
               lprintf(6, "%s: ", voice_modem->name);
               return((0));
               }
          else
               if ((char_read != (0x0a)) && (char_read != (0x0d)) && (char_read != (0x11)) && (char_read != (0x13)))
                    {
                    *buffer = char_read;
                    buffer++;
                    number_chars++;
                    lputc(6, char_read);
                    };
          }
     while (((char_read != (0x0a)) || (number_chars == 0)) && (number_chars < ((256) - 1)));
     *buffer = 0x00;
     return((0));
     }

variable_types:
buffer
char *


decompiled_code:
__int64 voice_check_for_input()
{
__int64 result; // rax

result = 1LL;
if ( input_pos >= input_count )
{
input_count = read(voice_fd, input_buffer, 0x400uLL);
result = 0LL;
if ( input_count > 0 )
{
input_pos = 0;
result = 1LL;
}
}
return result;
}

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

result = 1LL;
if ( input_pos >= input_count )
{
input_count = read(voice_fd, input_buffer, 0x400uLL);
result = 0LL;
if ( input_count > 0 )
{
input_pos = 0;
result = 1LL;
}
}
return result;
}

original_code:
int voice_check_for_input(void)
     {
     if (input_pos < input_count)
          return((0==0));
     input_count = read(voice_fd, input_buffer, sizeof(input_buffer));
     if (input_count <= 0)
          return((0==1));
     input_pos = 0;
     return((0==0));
     }

canonical_original_code:
int voice_check_for_input()
     {
     if (input_pos < input_count)
          return((0==0));
     input_count = read(voice_fd, input_buffer, sizeof(input_buffer));
     if (input_count <= 0)
          return((0==1));
     input_pos = 0;
     return((0==0));
     }


decompiled_code:
__int64 __fastcall Dolphin_set_device(unsigned int a1)
{
unsigned int v1; // ebx

reset_watchdog();
switch ( a1 )
{
case 2u:
voice_command("AT+VLS=2", "VCON");
v1 = 0;
break;
case 6u:
voice_command("AT+VLS=16", "VCON");
v1 = 0;
break;
case 1u:
v1 = voice_write("AT+VLS=0");
if ( v1 )
{
v1 = -1;
}
else if ( (unsigned int)voice_command(&unk_43E, "AT+VLS=0|OK") == 4096 )
{
voice_command(&unk_43E, "OK");
}
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
v1 = -1;
break;
}
return v1;
}

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

reset_watchdog();
switch ( a1 )
{
case 2u:
voice_command("AT+VLS=2", "VCON");
v1 = 0;
break;
case 6u:
voice_command("AT+VLS=16", "VCON");
v1 = 0;
break;
case 1u:
v1 = voice_write("AT+VLS=0");
if ( v1 )
{
v1 = -1;
}
else if ( (unsigned int)voice_command(&unk_43E, "AT+VLS=0|OK") == 4096 )
{
voice_command(&unk_43E, "OK");
}
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
v1 = -1;
break;
}
return v1;
}

original_code:
static int Dolphin_set_device (int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               if (voice_write("AT+VLS=0") != (0))
                    return((-1));
               if (voice_command("", "AT+VLS=0|OK") == (0x1000))
                    voice_command("", "OK");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=2", "VCON");
               return((0));
          case (0x0006):
               voice_command("AT+VLS=16", "VCON");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

canonical_original_code:
static int Dolphin_set_device(int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               if (voice_write("AT+VLS=0") != (0))
                    return((-1));
               if (voice_command("", "AT+VLS=0|OK") == (0x1000))
                    voice_command("", "OK");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=2", "VCON");
               return((0));
          case (0x0006):
               voice_command("AT+VLS=16", "VCON");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

variable_types: device int