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


repo: Distrotech/mgetty

decompiled_code:
__int64 Elsa_init()
{
__int64 v0; // rdx
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
_BYTE v5[64]; // [rsp+0h] [rbp-148h] BYREF
__m128i s[16]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Elsa voice modem");
sprintf((char *)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((char *)s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy((char *)s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy((char *)s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set BDR=16");
s[0] = _mm_load_si128((const __m128i *)&LC33);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf((char *)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((char *)s, "ATS30=60");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set S30");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 == -1 )
{
*((_QWORD *)&cvd + 82) = 50LL;
v1 = 191LL;
}
else
{
v1 = (unsigned int)(127 * (int)v0 / 100 + 128);
}
sprintf((char *)s, "AT#VGT=%d", v1);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
v2 = *((_QWORD *)&cvd + 79);
if ( v2 == -1 )
{
*((_QWORD *)&cvd + 79) = 50LL;
v3 = 191LL;
}
else
{
v3 = (unsigned int)(127 * (int)v2 / 100 + 128);
}
sprintf((char *)s, "AT#VGR=%d", v3);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(
(char *)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, v5);
tio_set_flow_control(voice_fd, v5, 1LL);
tio_set(voice_fd, v5);
}
LABEL_26:
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdx
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
_BYTE v5[64]; // [rsp+0h] [rbp-148h] BYREF
__m128i s[16]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Elsa voice modem");
sprintf((char *)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((char *)s, "AT#VSD=0");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VSD=0");
strcpy((char *)s, "AT#VBS=4");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VBS=4");
strcpy((char *)s, "AT#BDR=16");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set BDR=16");
s[0] = _mm_load_si128((const __m128i *)&LC33);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set VTD=3F");
sprintf((char *)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((char *)s, "ATS30=60");
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set S30");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 == -1 )
{
*((_QWORD *)&cvd + 82) = 50LL;
v1 = 191LL;
}
else
{
v1 = (unsigned int)(127 * (int)v0 / 100 + 128);
}
sprintf((char *)s, "AT#VGT=%d", v1);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set speaker volume");
v2 = *((_QWORD *)&cvd + 79);
if ( v2 == -1 )
{
*((_QWORD *)&cvd + 79) = 50LL;
v3 = 191LL;
}
else
{
v3 = (unsigned int)(127 * (int)v2 / 100 + 128);
}
sprintf((char *)s, "AT#VGR=%d", v3);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record volume");
sprintf(
(char *)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, v5);
tio_set_flow_control(voice_fd, v5, 1LL);
tio_set(voice_fd, v5);
}
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:
buffer
char [-1]

variable_types: succeeded 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; }

return_type: 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

return_type: void


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));
v3.tv_usec = 0LL;
v3.tv_sec = 0LL;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
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));
v3.tv_usec = 0LL;
v3.tv_sec = 0LL;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
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));
v2 = 0LL;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( a2 >= 0 )
{
v2 = (struct timeval *)v5;
v5[0] = a2 / 1000;
v5[1] = 1000 * (a2 % 1000);
}
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));
v2 = 0LL;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( a2 >= 0 )
{
v2 = (struct timeval *)v5;
v5[0] = a2 / 1000;
v5[1] = 1000 * (a2 % 1000);
}
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
__int64 v2; // rdx
__int64 v3; // rcx
char *v4; // rbp
__pid_t v5; // eax
__int64 v6; // [rsp-10h] [rbp-28h]

if ( !fax_file_names )
fax_file_names = (char *)&unk_DF1;
v1 = (char *)malloc(fax_fn_size + 138LL);
v4 = 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'", v4);
v5 = fork();
if ( v5 == -1 )
{
lprintf(1LL, "fork() failed", v6);
}
else if ( !v5 )
{
close(0);
close(1);
close(2);
setpgrp();
setup_environment();
if ( system(v4) )
lprintf(1LL, "system() failed");
exit(0);
}
free(v4);
}
else
{
lprintf(1LL, "fax_notify_program: cannot malloc", v2, v3);
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1)
{
char *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
char *v4; // rbp
__pid_t v5; // eax
__int64 v6; // [rsp-10h] [rbp-28h]

if ( !fax_file_names )
fax_file_names = (char *)&unk_DF1;
v1 = (char *)malloc(fax_fn_size + 138LL);
v4 = 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'", v4);
v5 = fork();
if ( v5 == -1 )
{
lprintf(1LL, "fork() failed", v6);
}
else if ( !v5 )
{
close(0);
close(1);
close(2);
setpgrp();
setup_environment();
if ( system(v4) )
lprintf(1LL, "system() failed");
exit(0);
}
free(v4);
}
else
{
lprintf(1LL, "fax_notify_program: cannot malloc", v2, v3);
}
}

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

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


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; // r15
__int64 v12; // rbx
__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

v19 = 0;
v20[0] = 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)&v19, v20, a1, a2, a3, a4, a5);
call_done = time(0LL);
lprintf(5LL, "fax receiver: hangup & end");
if ( a6 )
{
if ( *a6 )
fax_notify_mail(v19, v20[0], a6);
}
fax_notify_program(v19);
v11 = v20[0];
v13 = v19;
v14 = fax_hangup_code;
v15 = (const char *)CallName;
call_done -= call_start;
v12 = call_done;
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,
v11,
v12 / 3600,
v12 / 60 % 60,
v12 % 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; // r15
__int64 v12; // rbx
__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

v19 = 0;
v20[0] = 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)&v19, v20, a1, a2, a3, a4, a5);
call_done = time(0LL);
lprintf(5LL, "fax receiver: hangup & end");
if ( a6 )
{
if ( *a6 )
func0(v19, v20[0], a6);
}
func1(v19);
v11 = v20[0];
v13 = v19;
v14 = fax_hangup_code;
v15 = (const char *)CallName;
call_done -= call_start;
v12 = call_done;
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,
v11,
v12 / 3600,
v12 / 60 % 60,
v12 % 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 v1; // eax

if ( input_pos < input_count )
return (unsigned __int8)input_buffer[input_pos++];
v1 = read(voice_fd, input_buffer, 0x400uLL);
input_count = v1;
if ( v1 < 0 )
return (unsigned int)-*_errno_location();
if ( !v1 )
return 4294967285LL;
input_pos = 1;
return (unsigned __int8)input_buffer[0];
}

canonical_decompiled_code:
__int64 func0()
{
int v1; // eax

if ( input_pos < input_count )
return (unsigned __int8)input_buffer[input_pos++];
v1 = read(voice_fd, input_buffer, 0x400uLL);
input_count = v1;
if ( v1 < 0 )
return (unsigned int)-*_errno_location();
if ( !v1 )
return 4294967285LL;
input_pos = 1;
return (unsigned __int8)input_buffer[0];
}

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 ( 1 )
{
if ( time(0LL) > v0 )
{
lprintf(3LL, "%s: timeout while reading character from voice modem", program_name);
return 0xFFFFFFFFLL;
}
result = voice_read_byte();
if ( (int)result >= 0 )
return result;
if ( (_DWORD)result != -4 && (_DWORD)result != -11 )
break;
delay(*((unsigned int *)&cvd + 176));
}
lprintf(3LL, "%s: could not read 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 ( 1 )
{
if ( time(0LL) > v0 )
{
lprintf(3LL, "%s: timeout while reading character from voice modem", program_name);
return 0xFFFFFFFFLL;
}
result = func0();
if ( (int)result >= 0 )
return result;
if ( (_DWORD)result != -4 && (_DWORD)result != -11 )
break;
delay(*((unsigned int *)&cvd + 176));
}
lprintf(3LL, "%s: could not read 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; // rbp
int v2; // ebx
int v3; // eax
int v5; // eax
unsigned int v6; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
_BYTE *v1; // rbp
int v2; // ebx
int v3; // eax
int v5; // eax
unsigned int v6; // ebp

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

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; // er12
__int64 result; // rax

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

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

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

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


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

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

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

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

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

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


decompiled_code:
__int64 Dolphin_init()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Dolphin voice modem");
if ( (unsigned int)voice_command("AT+VNH=1", "OK") != 4096 )
lprintf(3LL, "disabling automatic hangup didn't work");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Dolphin voice modem");
if ( (unsigned int)voice_command("AT+VNH=1", "OK") != 4096 )
lprintf(3LL, "disabling automatic hangup didn't work");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Dolphin_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Dolphin voice modem");
     if (voice_command("AT+VNH=1", "OK") != (0x1000))
          lprintf(3, "disabling automatic hangup didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i * 31 / 100,
      (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Dolphin_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Dolphin voice modem");
     if (voice_command("AT+VNH=1", "OK") != (0x1000))
          lprintf(3, "disabling automatic hangup didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i * 31 / 100,
      (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

variable_types:
buffer
char [-1]


variable_types: sample int

variable_types: sign int

variable_types: exponent int

variable_types: mantissa int

variable_types:
ulawbyte
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall ulaw2linear(char a1)
{
char v1; // di
unsigned __int8 v2; // dl
__int64 result; // rax
unsigned int v4; // edx

v1 = ~a1;
v2 = ((unsigned __int8)v1 >> 4) & 7;
result = exp_lut_2[v2] + ((unsigned __int8)(v1 & 0xF) << (v2 + 3));
v4 = -(exp_lut_2[v2] + ((v1 & 0xF) << (v2 + 3)));
if ( v1 < 0 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
char v1; // di
unsigned __int8 v2; // dl
__int64 result; // rax
unsigned int v4; // edx

v1 = ~a1;
v2 = ((unsigned __int8)v1 >> 4) & 7;
result = exp_lut_2[v2] + ((unsigned __int8)(v1 & 0xF) << (v2 + 3));
v4 = -(exp_lut_2[v2] + ((v1 & 0xF) << (v2 + 3)));
if ( v1 < 0 )
result = v4;
return result;
}

original_code:
int ulaw2linear (unsigned char ulawbyte)
     {
     static int exp_lut[8] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
     int sign;
     int exponent;
     int mantissa;
     int sample;
     ulawbyte = ~ulawbyte;
     sign = (ulawbyte & 0x80);
     exponent = (ulawbyte >> 4) & 0x07;
     mantissa = ulawbyte & 0x0f;
     sample = exp_lut[exponent] + (mantissa << (exponent + 3));
     if (sign != 0)
          sample = -sample;
     return(sample);
     }

canonical_original_code:
int ulaw2linear(unsigned char ulawbyte)
     {
     static int exp_lut[8] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
     int sign;
     int exponent;
     int mantissa;
     int sample;
     ulawbyte = ~ulawbyte;
     sign = (ulawbyte & 0x80);
     exponent = (ulawbyte >> 4) & 0x07;
     mantissa = ulawbyte & 0x0f;
     sample = exp_lut[exponent] + (mantissa << (exponent + 3));
     if (sign != 0)
          sample = -sample;
     return(sample);
     }


decompiled_code:
__int64 __fastcall ulaw2alaw(unsigned __int8 a1)
{
return (unsigned __int8)ulaw_to_alaw_1[a1];
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return (unsigned __int8)ulaw_to_alaw_1[a1];
}


decompiled_code:
__int64 __fastcall alaw2ulaw(unsigned __int8 a1)
{
return (unsigned __int8)alaw_to_ulaw_0[a1];
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
return (unsigned __int8)alaw_to_ulaw_0[a1];
}

variable_types:
alawbyte
unsigned char


decompiled_code:
__int64 voice_mode_on()
{
lprintf(5LL, "%s: entering voice mode", program_name);
tio_set(voice_fd, &voice_tio);
voice_install_signal_handler();
(*(void (**)(void))(voice_modem + 432LL))();
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
lprintf(5LL, "%s: entering voice mode", program_name);
tio_set(voice_fd, &voice_tio);
voice_install_signal_handler();
(*(void (**)(void))(voice_modem + 432LL))();
return 0LL;
}

original_code:
int voice_mode_on(void)
     {
     lprintf(5, "%s: entering voice mode", program_name);
     tio_set(voice_fd, &voice_tio);
     voice_install_signal_handler();
     voice_modem->voice_mode_on();
     return((0));
     }

canonical_original_code:
int voice_mode_on()
     {
     lprintf(5, "%s: entering voice mode", program_name);
     tio_set(voice_fd, &voice_tio);
     voice_install_signal_handler();
     voice_modem->voice_mode_on();
     return((0));
     }


decompiled_code:
__int64 voice_mode_off()
{
lprintf(5LL, "%s: leaving voice mode", program_name);
(*(void (**)(void))(voice_modem + 424LL))();
voice_restore_signal_handler();
tio_set(voice_fd, &tio_save);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
lprintf(5LL, "%s: leaving voice mode", program_name);
(*(void (**)(void))(voice_modem + 424LL))();
voice_restore_signal_handler();
tio_set(voice_fd, &tio_save);
return 0LL;
}

original_code:
int voice_mode_off(void)
     {
     lprintf(5, "%s: leaving voice mode", program_name);
     voice_modem->voice_mode_off();
     voice_restore_signal_handler();
     tio_set(voice_fd, &tio_save);
     return((0));
     }

canonical_original_code:
int voice_mode_off()
     {
     lprintf(5, "%s: leaving voice mode", program_name);
     voice_modem->voice_mode_off();
     voice_restore_signal_handler();
     tio_set(voice_fd, &tio_save);
     return((0));
     }


decompiled_code:
__int64 __fastcall enter_data_fax_mode(char a1)
{
__int64 v1; // rbx
const char *v2; // rcx
const char *v3; // r9
int v5; // edi
int v6; // ebx
unsigned int v7; // ebp
const char *v8; // rdx
const char *v10; // r12
__int64 v11; // [rsp-8h] [rbp-18h]

v2 = (const char *)&unk_390;
v3 = "FAX";
if ( (a1 & 2) == 0 )
v3 = (const char *)&unk_390;
v11 = v1;
v5 = a1 & 1;
v6 = a1 & 3;
v7 = v5;
if ( v6 == 3 )
{
if ( v5 )
{
lprintf(6LL, "%s: asked %s%s%s", program_name, "DATA", "/", v3);
v8 = (const char *)program_name;
if ( modem_type == 4 )
{
v10 = "2";
v7 = 0;
}
else
{
if ( modem_type != 5 )
goto LABEL_10;
v10 = "2.0";
}
goto LABEL_23;
}
lprintf(6LL, "%s: asked %s%s%s", program_name, (const char *)&unk_390, "/", v3);
}
else
{
if ( v5 )
v2 = "DATA";
lprintf(6LL, "%s: asked %s%s%s", program_name, v2, &unk_390, v3, v11);
if ( !v6 )
{
lprintf(5LL, "%s: answer mode is set to not accept data or fax connections", program_name);
return 0xFFFFFFFFLL;
}
}
v8 = (const char *)program_name;
if ( modem_type == 4 )
{
v10 = "2";
v7 = 0;
LABEL_18:
if ( v6 == 2 )
{
lprintf(6LL, "%s: trying fax connection", program_name);
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))(v10) != -1
&& (unsigned int)voice_command("AT+FAA=0", "OK") == 4096 )
{
LABEL_21:
tio_set(voice_fd, &tio_save);
voice_restore_signal_handler();
fax_set_bor(voice_fd, v7);
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( v6 != 3 )
goto LABEL_10;
LABEL_23:
lprintf(6LL, "%s: trying data and fax connection", v8);
if ( modem_type == 4 )
{
v10 = "2";
if ( (modem_quirks & 1) == 0 )
v10 = "0";
}
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))(v10) != -1
&& (unsigned int)voice_command("AT+FAA=1", "OK") == 4096 )
{
goto LABEL_21;
}
return 0xFFFFFFFFLL;
}
if ( modem_type == 5 )
{
v10 = "2.0";
v7 = 1;
goto LABEL_18;
}
if ( v5 )
{
LABEL_10:
lprintf(6LL, "%s: trying data connection", v8);
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))("0") != -1
&& (unsigned int)voice_command("AT+FAA=0", "OK") == 4096 )
{
tio_set(voice_fd, &tio_save);
voice_restore_signal_handler();
return 0LL;
}
return 0xFFFFFFFFLL;
}
lprintf(5LL, "%s: modem does not support wanted mode", program_name);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
__int64 v1; // rbx
const char *v2; // rcx
const char *v3; // r9
int v5; // edi
int v6; // ebx
unsigned int v7; // ebp
const char *v8; // rdx
const char *v10; // r12
__int64 v11; // [rsp-8h] [rbp-18h]

v2 = (const char *)&unk_390;
v3 = "FAX";
if ( (a1 & 2) == 0 )
v3 = (const char *)&unk_390;
v11 = v1;
v5 = a1 & 1;
v6 = a1 & 3;
v7 = v5;
if ( v6 == 3 )
{
if ( v5 )
{
lprintf(6LL, "%s: asked %s%s%s", program_name, "DATA", "/", v3);
v8 = (const char *)program_name;
if ( modem_type == 4 )
{
v10 = "2";
v7 = 0;
}
else
{
if ( modem_type != 5 )
goto LABEL_10;
v10 = "2.0";
}
goto LABEL_23;
}
lprintf(6LL, "%s: asked %s%s%s", program_name, (const char *)&unk_390, "/", v3);
}
else
{
if ( v5 )
v2 = "DATA";
lprintf(6LL, "%s: asked %s%s%s", program_name, v2, &unk_390, v3, v11);
if ( !v6 )
{
lprintf(5LL, "%s: answer mode is set to not accept data or fax connections", program_name);
return 0xFFFFFFFFLL;
}
}
v8 = (const char *)program_name;
if ( modem_type == 4 )
{
v10 = "2";
v7 = 0;
LABEL_18:
if ( v6 == 2 )
{
lprintf(6LL, "%s: trying fax connection", program_name);
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))(v10) != -1
&& (unsigned int)voice_command("AT+FAA=0", "OK") == 4096 )
{
LABEL_21:
tio_set(voice_fd, &tio_save);
voice_restore_signal_handler();
fax_set_bor(voice_fd, v7);
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( v6 != 3 )
goto LABEL_10;
LABEL_23:
lprintf(6LL, "%s: trying data and fax connection", v8);
if ( modem_type == 4 )
{
v10 = "2";
if ( (modem_quirks & 1) == 0 )
v10 = "0";
}
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))(v10) != -1
&& (unsigned int)voice_command("AT+FAA=1", "OK") == 4096 )
{
goto LABEL_21;
}
return 0xFFFFFFFFLL;
}
if ( modem_type == 5 )
{
v10 = "2.0";
v7 = 1;
goto LABEL_18;
}
if ( v5 )
{
LABEL_10:
lprintf(6LL, "%s: trying data connection", v8);
if ( (*(unsigned int (__fastcall **)(const char *))(voice_modem + 416LL))("0") != -1
&& (unsigned int)voice_command("AT+FAA=0", "OK") == 4096 )
{
tio_set(voice_fd, &tio_save);
voice_restore_signal_handler();
return 0LL;
}
return 0xFFFFFFFFLL;
}
lprintf(5LL, "%s: modem does not support wanted mode", program_name);
return 0xFFFFFFFFLL;
}

original_code:
int enter_data_fax_mode(int answer_mode)
     {
     int bit_order = 0;
     char *fax_mode = ((void *)0);
     lprintf(6, "%s: asked %s%s%s",
             program_name,
             (answer_mode & (1)) ? "DATA" : "",
             ((answer_mode & ((1)|(2)))
              == ((1)|(2))) ? "/" : "",
             (answer_mode & (2)) ? "FAX" : "");
     answer_mode &= ((1) | (2));
     if (answer_mode == 0)
          {
          lprintf(5,
           "%s: answer mode is set to not accept data or fax connections",
           program_name);
          return ((-1));
          };
     if (modem_type == Mt_class2)
          {
          bit_order = 0;
          fax_mode = "2";
          };
     if (modem_type == Mt_class2_0)
          {
          bit_order = 1;
          fax_mode = "2.0";
          };
     if ((modem_type == Mt_data) || (fax_mode == ((void *)0)))
          answer_mode &= (1);
     if (answer_mode == 0)
          {
          lprintf(5, "%s: modem does not support wanted mode",
           program_name);
          return((-1));
          };
     switch (answer_mode)
          {
          case (1) | (2):
               lprintf(6, "%s: trying data and fax connection",
                program_name);
               if (modem_type == Mt_class2)
                    fax_mode = ( modem_quirks & 0x01 ) ? "2": "0";
               if (voice_modem->switch_to_data_fax(fax_mode) == (-1))
                    return((-1));
               if (voice_command("AT+FAA=1", "OK") != (0x1000))
                    return((-1));
               tio_set(voice_fd, &tio_save);
               voice_restore_signal_handler();
               fax_set_bor(voice_fd, bit_order);
               break;
          case (1):
               lprintf(6, "%s: trying data connection", program_name);
               if (voice_modem->switch_to_data_fax("0") == (-1))
                    return((-1));
               if (voice_command("AT+FAA=0", "OK") != (0x1000))
                    return((-1));
               tio_set(voice_fd, &tio_save);
               voice_restore_signal_handler();
               break;
          case (2):
               lprintf(6, "%s: trying fax connection", program_name);
               if (voice_modem->switch_to_data_fax(fax_mode) == (-1))
                    return((-1));
               if (voice_command("AT+FAA=0", "OK") != (0x1000))
                    return((-1));
               tio_set(voice_fd, &tio_save);
               voice_restore_signal_handler();
               fax_set_bor(voice_fd, bit_order);
               break;
          };
     return((0));
     }


decompiled_code:
__int64 get_current_users()
{
unsigned int v0; // er12
struct utmp *v1; // rax

v0 = 0;
setutent();
while ( 1 )
{
v1 = getutent();
if ( !v1 )
break;
v0 += v1->ut_type == 7;
}
endutent();
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
struct utmp *v1; // rax

v0 = 0;
setutent();
while ( 1 )
{
v1 = getutent();
if ( !v1 )
break;
v0 += v1->ut_type == 7;
}
endutent();
return v0;
}

original_code:
int get_current_users (void)
{
    struct utmp * utmp;
    int Nusers = 0;
    setutent();
    while ((utmp = getutent()) != (struct utmp *) ((void *)0))
    {
 if (utmp->ut_type == 7)
 {
     Nusers++;
 }
    }
    endutent();
    return Nusers;
}

canonical_original_code:
int get_current_users()
{
    struct utmp *utmp;
    int Nusers = 0;
    setutent();
    while ((utmp = getutent()) != (struct utmp *) ((void *)0))
    {
 if (utmp->ut_type == 7)
 {
     Nusers++;
 }
    }
    endutent();
    return Nusers;
}

variable_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status { short e_termination; short e_exit; } ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; } *

variable_types: Nusers int

user_defined_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; }


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

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

original_code: int fax1_set_fdcc( int fd, int fine, int max, int min ) { return 0; }

canonical_original_code: int fax1_set_fdcc(int fd, int fine, int max, int min) { return 0; }

variable_types: fd int

variable_types: fine int

variable_types: max int

variable_types: min int


decompiled_code:
// attributes: thunk
__int64 fax1_set_l_id()
{
return lputs();
}

canonical_decompiled_code:
__int64 func5()
{
return func1();
}

original_code: int fax1_set_l_id( int fd, char * fax_id ) { return 0; }

canonical_original_code: int fax1_set_l_id(int fd, char *fax_id) { return 0; }


lputc

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

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

original_code: int lputc( int level, char ch ) { return 0; }

canonical_original_code: int lputc(int level, char ch) { return 0; }

variable_types: level int

variable_types: ch char


lputs

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

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

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

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

variable_types:
s
char *


lprintf

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

canonical_decompiled_code:
__int64 func2()
{
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:
format
char *


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

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

original_code: char * fax_strerror( int h ) { return ((void *)0); }

canonical_original_code: char *fax_strerror(int h) { return ((void *)0); }

variable_types: h int

return_type: char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // er12
int v5; // eax
int i; // eax

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:r");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'p':
v4 = atoi(optarg);
break;
case 'r':
v3 = 1;
break;
case '?':
fwrite("options: -p <padbytes>, -r\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
}
fax_init_swaptable(v3 ^ 1u, &fax_send_swaptable);
for ( i = optind; i < argc; optind = i )
{
if ( (int)g3_open_read(argv[i]) < 0 )
{
perror("g3_open");
exit(2);
}
if ( (unsigned int)g3_send_file(&g3_rf_chunk, 1LL, 0LL, 0LL, v4, 0xFFFFFFFFLL) )
{
perror("g3_send_file");
exit(3);
}
i = optind + 1;
}
exit(0);
}

original_code:
int main( int argc, char ** argv )
{
int opt;
int pad_bytes = 0;
int reverse = (1==0);
    while( (opt = getopt(argc, argv, "p:r" )) != (-1) )
    {
 switch(opt)
 {
   case 'p':
     pad_bytes = atoi(optarg);
     break;
   case 'r':
     reverse = (1==1);
     break;
   case '?':
     fprintf( stderr, "options: -p <padbytes>, -r\n" );
     exit(1);
 }
    }
    fax_init_swaptable( !reverse, fax_send_swaptable );
    while( optind < argc )
    {
        if ( g3_open_read( argv[optind] ) < 0 )
 {
     perror( "g3_open" ); exit(2);
 }
 if ( g3_send_file( g3_rf_chunk, 1, (1==0),
                       (1==0), pad_bytes, -1 ) )
 {
     perror( "g3_send_file" ); exit(3);
 }
 optind++;
    }
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
int opt;
int pad_bytes = 0;
int reverse = (1==0);
    while( (opt = getopt(argc, argv, "p:r" )) != (-1) )
    {
 switch(opt)
 {
   case 'p':
     pad_bytes = atoi(optarg);
     break;
   case 'r':
     reverse = (1==1);
     break;
   case '?':
     fprintf( stderr, "options: -p <padbytes>, -r\n" );
     exit(1);
 }
    }
    fax_init_swaptable( !reverse, fax_send_swaptable );
    while( optind < argc )
    {
        if ( g3_open_read( argv[optind] ) < 0 )
 {
     perror( "g3_open" ); exit(2);
 }
 if ( g3_send_file( g3_rf_chunk, 1, (1==0),
                       (1==0), pad_bytes, -1 ) )
 {
     perror( "g3_send_file" ); exit(3);
 }
 optind++;
    }
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: reverse int


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

result = 3LL;
if ( a1 <= 99 )
{
result = 0LL;
if ( a1 )
result = (unsigned int)((3 * a1 / 10 + 10) / 10);
}
return result;
}

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

result = 3LL;
if ( a1 <= 99 )
{
result = 0LL;
if ( a1 )
result = (unsigned int)((3 * a1 / 10 + 10) / 10);
}
return result;
}

original_code:
static int silence_threshold_compute(int threshold) {
   if (threshold >= 100) {
      return 3;
   }
   else if (threshold) {
      return (((threshold * 3 / 10) + 10) / 10);
   }
   else {
      return 0;
   }
}

variable_types: threshold int


decompiled_code:
__int64 USR_voice_mode_on()
{
unsigned int v0; // er12
unsigned int v2; // eax

v0 = IS_101_voice_mode_on();
if ( v0 )
return v0;
v2 = silence_threshold_compute(cvd[116]);
sprintf(buffer_1, "AT#VTD=3F,3F,3F#VSD=1#VSS=%d#VSP=%d#VRA=%d#VRN=%d", v2, cvd[110], cvd[398], cvd[404]);
if ( (unsigned int)voice_command(buffer_1, "OK") == 4096 )
return v0;
lprintf(3LL, "setting voice preferences didn't work");
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
unsigned int v2; // eax

v0 = IS_101_voice_mode_on();
if ( v0 )
return v0;
v2 = func0(cvd[116]);
sprintf(buffer_1, "AT#VTD=3F,3F,3F#VSD=1#VSS=%d#VSP=%d#VRA=%d#VRN=%d", v2, cvd[110], cvd[398], cvd[404]);
if ( (unsigned int)voice_command(buffer_1, "OK") == 4096 )
return v0;
lprintf(3LL, "setting voice preferences didn't work");
return v0;
}

original_code:
static int USR_voice_mode_on(void)
     {
     int ret;
     static char buffer[(256)];
     if( (ret=IS_101_voice_mode_on( )) != (0) )
          return( ret );
     sprintf(buffer, "AT#VTD=3F,3F,3F#VSD=1#VSS=%d#VSP=%d#VRA=%d#VRN=%d",
             silence_threshold_compute(cvd.rec_silence_threshold.d.i),
             (int)cvd.rec_silence_len.d.i,
             (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting voice preferences didn't work");
     return((0));
     }

canonical_original_code:
static int USR_voice_mode_on()
     {
     int ret;
     static char buffer[-1];
     if( (ret=IS_101_voice_mode_on( )) != (0) )
          return( ret );
     sprintf(buffer, "AT#VTD=3F,3F,3F#VSD=1#VSS=%d#VSP=%d#VRA=%d#VRN=%d",
             silence_threshold_compute(cvd.rec_silence_threshold.d.i),
             (int)cvd.rec_silence_len.d.i,
             (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting voice preferences didn't work");
     return((0));
     }

variable_types: ret int

variable_types:
buffer
char [-1]


decompiled_code:
__int64 __fastcall USR_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
int v5; // ecx
int v7; // eax
__int64 v8; // rdx
int v9; // esi
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !*a1 )
*a1 = 1LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 8000 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 8000LL;
}
if ( !probed_for_adpcm )
{
if ( *a1 == 1 )
{
LABEL_7:
v5 = supports_adpcm;
*a3 = 8;
if ( v5 && in_adpcm_mode )
{
if ( (unsigned int)voice_command("AT#VSM=128,8000", "OK") != 0x4000 )
{
in_adpcm_mode = 0;
return 0LL;
}
return 0x4000LL;
}
return 0LL;
}
v7 = voice_command("AT#VSM=129,8000", "OK");
supports_adpcm = v7 == 4096;
if ( v7 == 4096 )
in_adpcm_mode = 1;
else
lprintf(3LL, "%s: Ignore the above error!", program_name);
probed_for_adpcm = 1;
}
v8 = *a1;
if ( *a1 )
{
if ( v8 == 1 )
goto LABEL_7;
if ( (unsigned __int64)(v8 - 2) > 2 )
{
lprintf(3LL, "Illegal voice compression method (%d)", v8);
return 0xFFFFFFFFLL;
}
v9 = supports_adpcm;
*a3 = v8;
if ( !v9 )
goto LABEL_24;
}
else
{
if ( !supports_adpcm )
{
*a1 = 1LL;
*a3 = 8;
return 0LL;
}
*a1 = 2LL;
*a3 = 2;
}
if ( !in_adpcm_mode )
{
if ( (unsigned int)voice_command("AT#VSM=129,8000", "OK") == 0x4000 )
return 0x4000LL;
in_adpcm_mode = 1;
}
v8 = *a1;
LABEL_24:
sprintf(v10, "AT#VBS=%1d", v8);
if ( (unsigned int)voice_command(v10, "OK") != 0x4000 )
return 0LL;
return 0x4000LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
int v5; // ecx
int v7; // eax
__int64 v8; // rdx
int v9; // esi
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !*a1 )
*a1 = 1LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 8000 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 8000LL;
}
if ( !probed_for_adpcm )
{
if ( *a1 == 1 )
{
LABEL_7:
v5 = supports_adpcm;
*a3 = 8;
if ( v5 && in_adpcm_mode )
{
if ( (unsigned int)voice_command("AT#VSM=128,8000", "OK") != 0x4000 )
{
in_adpcm_mode = 0;
return 0LL;
}
return 0x4000LL;
}
return 0LL;
}
v7 = voice_command("AT#VSM=129,8000", "OK");
supports_adpcm = v7 == 4096;
if ( v7 == 4096 )
in_adpcm_mode = 1;
else
lprintf(3LL, "%s: Ignore the above error!", program_name);
probed_for_adpcm = 1;
}
v8 = *a1;
if ( *a1 )
{
if ( v8 == 1 )
goto LABEL_7;
if ( (unsigned __int64)(v8 - 2) > 2 )
{
lprintf(3LL, "Illegal voice compression method (%d)", v8);
return 0xFFFFFFFFLL;
}
v9 = supports_adpcm;
*a3 = v8;
if ( !v9 )
goto LABEL_24;
}
else
{
if ( !supports_adpcm )
{
*a1 = 1LL;
*a3 = 8;
return 0LL;
}
*a1 = 2LL;
*a3 = 2;
}
if ( !in_adpcm_mode )
{
if ( (unsigned int)voice_command("AT#VSM=129,8000", "OK") == 0x4000 )
return 0x4000LL;
in_adpcm_mode = 1;
}
v8 = *a1;
LABEL_24:
sprintf(v10, "AT#VBS=%1d", v8);
if ( (unsigned int)voice_command(v10, "OK") != 0x4000 )
return 0LL;
return 0x4000LL;
}

original_code:
static int USR_set_compression(p_int *compression, p_int *speed, int *bits)
     {
     char buffer[(256)];
     if (*compression == 0)
          *compression = 1;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)",
           voice_modem->name, (int)*speed);
          return((-1));
          };
     if ((!probed_for_adpcm) && (*compression != 1))
          {
          if (!(supports_adpcm =
           (voice_command("AT#VSM=129,8000", "OK") == (0x1000))))
               lprintf(3,"%s: Ignore the above error!", program_name);
          else
               in_adpcm_mode = (0==0);
          probed_for_adpcm = (0==0);
          }
     if (*compression == 0)
          {
          if (supports_adpcm)
               *compression = 2;
          else
               *compression = 1;
          }
     switch (*compression)
          {
          case 1:
               *bits = 8;
               if ((supports_adpcm) && (in_adpcm_mode))
                    {
                    if (voice_command("AT#VSM=128,8000", "OK") != (0x4000))
                         {
                         in_adpcm_mode = (0==1);
                         return((0));
                         }
                    else
                         return((0x4000));
                    }
               return((0));
          case 2:
          case 3:
          case 4:
               *bits = *compression;
               if ((supports_adpcm) && (!in_adpcm_mode))
                    {
                    if (voice_command("AT#VSM=129,8000", "OK") == (0x4000))
                         return((0x4000));
                    in_adpcm_mode = (0==0);
                    }
               sprintf(buffer,"AT#VBS=%1d", (int)*compression);
               if (voice_command(buffer, "OK") != (0x4000))
                    return((0));
               else
                    return((0x4000));
          }
     lprintf(3,"Illegal voice compression method (%d)", *compression);
     return((-1));
     }

canonical_original_code:
static int USR_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     if (*compression == 0)
          *compression = 1;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)",
           voice_modem->name, (int)*speed);
          return((-1));
          };
     if ((!probed_for_adpcm) && (*compression != 1))
          {
          if (!(supports_adpcm =
           (voice_command("AT#VSM=129,8000", "OK") == (0x1000))))
               lprintf(3,"%s: Ignore the above error!", program_name);
          else
               in_adpcm_mode = (0==0);
          probed_for_adpcm = (0==0);
          }
     if (*compression == 0)
          {
          if (supports_adpcm)
               *compression = 2;
          else
               *compression = 1;
          }
     switch (*compression)
          {
          case 1:
               *bits = 8;
               if ((supports_adpcm) && (in_adpcm_mode))
                    {
                    if (voice_command("AT#VSM=128,8000", "OK") != (0x4000))
                         {
                         in_adpcm_mode = (0==1);
                         return((0));
                         }
                    else
                         return((0x4000));
                    }
               return((0));
          case 2:
          case 3:
          case 4:
               *bits = *compression;
               if ((supports_adpcm) && (!in_adpcm_mode))
                    {
                    if (voice_command("AT#VSM=129,8000", "OK") == (0x4000))
                         return((0x4000));
                    in_adpcm_mode = (0==0);
                    }
               sprintf(buffer,"AT#VBS=%1d", (int)*compression);
               if (voice_command(buffer, "OK") != (0x4000))
                    return((0));
               else
                    return((0x4000));
          }
     lprintf(3,"Illegal voice compression method (%d)", *compression);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


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

reset_watchdog();
(*(void (**)(void))(voice_modem + 424LL))();
sprintf(v2, "AT+FCLASS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

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

reset_watchdog();
(*(void (**)(void))(voice_modem + 424LL))();
sprintf(v2, "AT+FCLASS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

original_code:
static int USR_switch_to_data_fax (char *mode)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem->voice_mode_off();
     sprintf(buffer, "AT+FCLASS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
static int USR_switch_to_data_fax(char *mode)
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem->voice_mode_off();
     sprintf(buffer, "AT+FCLASS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types:
mode
char *


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

reset_watchdog();
internal_speaker_used = 0;
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0H0", "OK|VCON");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=0", "OK|VCON");
result = 0LL;
break;
case 3u:
case 7u:
voice_command("AT#VLS=1", "OK|VCON");
result = 0LL;
break;
case 4u:
voice_command("AT#VLS=3", "OK|VCON");
result = 0LL;
break;
case 5u:
internal_speaker_used = 1;
voice_command("AT#VLS=2", "OK|VCON");
result = 0LL;
break;
case 6u:
internal_speaker_used = 1;
voice_command("AT#VLS=4", "OK|VCON");
result = 0LL;
break;
default:
lprintf(3LL, "USR: Unknown output device (%d)", a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

reset_watchdog();
internal_speaker_used = 0;
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0H0", "OK|VCON");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=0", "OK|VCON");
result = 0LL;
break;
case 3u:
case 7u:
voice_command("AT#VLS=1", "OK|VCON");
result = 0LL;
break;
case 4u:
voice_command("AT#VLS=3", "OK|VCON");
result = 0LL;
break;
case 5u:
internal_speaker_used = 1;
voice_command("AT#VLS=2", "OK|VCON");
result = 0LL;
break;
case 6u:
internal_speaker_used = 1;
voice_command("AT#VLS=4", "OK|VCON");
result = 0LL;
break;
default:
lprintf(3LL, "USR: Unknown output device (%d)", a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static int USR_set_device(int device)
     {
     reset_watchdog();
     internal_speaker_used = (0==1);
     switch (device)
          {
          case (0x0001):
               voice_command("AT#VLS=0H0","OK|VCON");
               return((0));
          case (0x0002):
               voice_command("AT#VLS=0","OK|VCON");
               return((0));
   case (0x0007):
       voice_command("AT#VLS=1","OK|VCON");
       return((0));
          case (0x0003):
               voice_command("AT#VLS=1","OK|VCON");
               return((0));
          case (0x0006):
               internal_speaker_used = (0==0);
               voice_command("AT#VLS=4","OK|VCON");
               return((0));
          case (0x0005):
               internal_speaker_used = (0==0);
               voice_command("AT#VLS=2","OK|VCON");
               return((0));
          case (0x0004):
               voice_command("AT#VLS=3","OK|VCON");
               return((0));
          default:
               lprintf(3,"USR: Unknown output device (%d)",device);
               return((-1));
          };
     }

variable_types: device int


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

v0 = IS_101_stop_play_file();
if ( *(_QWORD *)&cvd[170]
&& ((unsigned int)voice_write_raw("ATE1\r", 5LL) || (voice_command(&unk_E49, "OK|VCON") & 0x1000) == 0)
|| (unsigned int)voice_command("AT", "OK") != 4096 )
{
return (unsigned int)-1;
}
voice_modem_state = 1;
voice_check_events();
if ( v0 )
v0 = 19712;
return v0;
}

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

v0 = IS_101_stop_play_file();
if ( *(_QWORD *)&cvd[170]
&& ((unsigned int)voice_write_raw("ATE1\r", 5LL) || (voice_command(&unk_E49, "OK|VCON") & 0x1000) == 0)
|| (unsigned int)voice_command("AT", "OK") != 4096 )
{
return (unsigned int)-1;
}
voice_modem_state = 1;
voice_check_events();
if ( v0 )
v0 = 19712;
return v0;
}

original_code:
static int USR_stop_play_file(void)
     {
     int stop_playing = IS_101_stop_play_file();
     if (cvd.enable_command_echo.d.i)
          {
          if (voice_write_raw("ATE1\r",5) != (0))
               return((-1));
          if ((voice_command("", "OK|VCON") & (0x1000)) != (0x1000))
               return((-1));
          }
     if (voice_command("AT", "OK") != (0x1000))
          return((-1));
     voice_modem_state = (0x0001);
     voice_check_events();
     if (stop_playing)
          return((0x4d00));
     return((0));
     }

canonical_original_code:
static int USR_stop_play_file()
     {
     int stop_playing = IS_101_stop_play_file();
     if (cvd.enable_command_echo.d.i)
          {
          if (voice_write_raw("ATE1\r",5) != (0))
               return((-1));
          if ((voice_command("", "OK|VCON") & (0x1000)) != (0x1000))
               return((-1));
          }
     if (voice_command("AT", "OK") != (0x1000))
          return((-1));
     voice_modem_state = (0x0001);
     voice_check_events();
     if (stop_playing)
          return((0x4d00));
     return((0));
     }


decompiled_code:
__int64 USR_init()
{
unsigned int v0; // eax
_BYTE v2[72]; // [rsp+0h] [rbp-48h] BYREF

reset_watchdog();
lprintf(4LL, "US Robotics voice modem");
lprintf(3LL, "This is a driver beta version. V0.4.b3");
voice_modem_state = 2;
if ( (unsigned int)voice_command("AT&H1&R2&I0", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") == 4096 )
lprintf(3LL, "VTD setup successful");
else
lprintf(3LL, "can't set DLE responses");
v0 = silence_threshold_compute(cvd[116]);
sprintf(buffer_0, "AT#VSD=1#VSS=%d#VSP=%d", v0, cvd[110]);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
sprintf(buffer_0, "AT#VRA=%d#VRN=%d", cvd[398], cvd[404]);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
_BYTE v2[72]; // [rsp+0h] [rbp-48h] BYREF

reset_watchdog();
lprintf(4LL, "US Robotics voice modem");
lprintf(3LL, "This is a driver beta version. V0.4.b3");
voice_modem_state = 2;
if ( (unsigned int)voice_command("AT&H1&R2&I0", "OK") == 4096 )
{
tio_get(voice_fd, v2);
tio_set_flow_control(voice_fd, v2, 1LL);
tio_set(voice_fd, v2);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") == 4096 )
lprintf(3LL, "VTD setup successful");
else
lprintf(3LL, "can't set DLE responses");
v0 = func0(cvd[116]);
sprintf(buffer_0, "AT#VSD=1#VSS=%d#VSP=%d", v0, cvd[110]);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
sprintf(buffer_0, "AT#VRA=%d#VRN=%d", cvd[398], cvd[404]);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int USR_init(void)
     {
     static char buffer[(256)];
     reset_watchdog();
     lprintf(4, "US Robotics voice modem");
     lprintf(3, "This is a driver beta version. V0.4.b3");
     voice_modem_state = (0x0002);
     if (voice_command("AT&H1&R2&I0", "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");
     if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
          lprintf(3, "can't set DLE responses");
     else
          lprintf(3, "VTD setup successful");
     sprintf(buffer, "AT#VSD=1#VSS=%d#VSP=%d",
             silence_threshold_compute(cvd.rec_silence_threshold.d.i),
             (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting recording preferences didn't work");
     sprintf(buffer, "AT#VRA=%d#VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int USR_init()
     {
     static char buffer[-1];
     reset_watchdog();
     lprintf(4, "US Robotics voice modem");
     lprintf(3, "This is a driver beta version. V0.4.b3");
     voice_modem_state = (0x0002);
     if (voice_command("AT&H1&R2&I0", "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");
     if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
          lprintf(3, "can't set DLE responses");
     else
          lprintf(3, "VTD setup successful");
     sprintf(buffer, "AT#VSD=1#VSS=%d#VSP=%d",
             silence_threshold_compute(cvd.rec_silence_threshold.d.i),
             (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting recording preferences didn't work");
     sprintf(buffer, "AT#VRA=%d#VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

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


decompiled_code:
__int64 __fastcall USR_handle_dle(char a1)
{
__int64 v1; // rdx

v1 = (unsigned int)a1;
if ( a1 != 100 && a1 != 105 )
return IS_101_handle_dle((unsigned int)v1);
if ( voice_modem_state != 5 )
{
if ( voice_modem_state == 6 )
{
lprintf(6LL, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is RECORDING.", v1);
return 0LL;
}
return IS_101_handle_dle((unsigned int)v1);
}
lprintf(6LL, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is PLAYING.", v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
__int64 v1; // rdx

v1 = (unsigned int)a1;
if ( a1 != 100 && a1 != 105 )
return IS_101_handle_dle((unsigned int)v1);
if ( voice_modem_state != 5 )
{
if ( voice_modem_state == 6 )
{
lprintf(6LL, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is RECORDING.", v1);
return 0LL;
}
return IS_101_handle_dle((unsigned int)v1);
}
lprintf(6LL, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is PLAYING.", v1);
return 0LL;
}

original_code:
static int USR_handle_dle(char data)
   {
   if (data == 'd' || data == 'i')
      {
      switch (voice_modem_state)
           {
           case (0x0005):
                lprintf(6, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is PLAYING.",data);
                return((0));
           case (0x0006):
                lprintf(6, "USR_handle_dle: Ignoring <DLE> <%c> because the modem is RECORDING.",data);
                return((0));
           }
      }
   return(IS_101_handle_dle(data));
   }

variable_types: data char


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

result = IS_101_beep();
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
if ( !internal_speaker_used )
result = (unsigned int)-((unsigned int)IS_101_answer_phone() != 8202);
return result;
}

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

result = IS_101_beep();
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
if ( !internal_speaker_used )
result = (unsigned int)-((unsigned int)IS_101_answer_phone() != 8202);
return result;
}

original_code:
static int USR_beep(int frequency, int length)
     {
     if (IS_101_beep(frequency, length) != (0))
          return((-1));
     if (internal_speaker_used) return((0));
     if (IS_101_answer_phone() != (0x200a))
          return((-1));
     return((0));
}

variable_types: frequency int

variable_types: length int


original_code:
void g3_init_lr_bittable (void)
{
signed int i,j;
    if ( bits_lr_init ) return;
    bits_left[0] = bits_right[0] = 8;
    for( i=0; i<=7; i++ )
    {
 for( j=(1<<(7-i))-1;j>=0; j--)
 {
     bits_left[ (1<<(7-i)) + j ] = i;
     bits_right[ ((j<<1)+1) << i ] = i;
 }
    }
    bits_lr_init = 1;
}

canonical_original_code:
void g3_init_lr_bittable()
{
int i; int j;
    if ( bits_lr_init ) return;
    bits_left[0] = bits_right[0] = 8;
    for( i=0; i<=7; i++ )
    {
 for( j=(1<<(7-i))-1;j>=0; j--)
 {
     bits_left[ (1<<(7-i)) + j ] = i;
     bits_right[ ((j<<1)+1) << i ] = i;
 }
    }
    bits_lr_init = 1;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall g3_open_read(char *file)
{
int v1; // eax
int v2; // eax
__int64 result; // rax

g3_init_lr_bittable();
v1 = open(file, 0);
g3_read_fd = v1;
if ( v1 < 0 )
{
lprintf(1LL, "g3_open_read: can't open '%s'", file);
result = 0xFFFFFFFFLL;
}
else
{
g3_rf_fine = -1;
g3_rf_idx = 0;
v2 = read(v1, &g3_rf_buf, 0x40uLL);
g3_rf_num = v2;
if ( v2 < 0 )
{
lprintf(1LL, "g3_open_read: can't read from '%s'", file);
close(g3_read_fd);
result = 0xFFFFFFFFLL;
}
else
{
if ( v2 > 63 && !(qword_8E1 ^ 0x6165736552204350LL | qword_8E9 ^ 0x636E49202C686372LL) && !byte_8F1 )
{
lprintf(4LL, "skipping over DigiFax header");
g3_rf_idx = 64;
g3_rf_fine = byte_8FD != 0;
}
result = (unsigned int)g3_read_fd;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *file)
{
int v1; // eax
int v2; // eax
__int64 result; // rax

func0();
v1 = open(file, 0);
g3_read_fd = v1;
if ( v1 < 0 )
{
lprintf(1LL, "g3_open_read: can't open '%s'", file);
result = 0xFFFFFFFFLL;
}
else
{
g3_rf_fine = -1;
g3_rf_idx = 0;
v2 = read(v1, &g3_rf_buf, 0x40uLL);
g3_rf_num = v2;
if ( v2 < 0 )
{
lprintf(1LL, "g3_open_read: can't read from '%s'", file);
close(g3_read_fd);
result = 0xFFFFFFFFLL;
}
else
{
if ( v2 > 63 && !(qword_8E1 ^ 0x6165736552204350LL | qword_8E9 ^ 0x636E49202C686372LL) && !byte_8F1 )
{
lprintf(4LL, "skipping over DigiFax header");
g3_rf_idx = 64;
g3_rf_fine = byte_8FD != 0;
}
result = (unsigned int)g3_read_fd;
}
}
return result;
}

original_code:
int g3_open_read (char * filename)
{
    g3_init_lr_bittable();
    g3_read_fd = open( filename, 00 );
    if ( g3_read_fd < 0 )
    {
 lprintf( 1, "g3_open_read: can't open '%s'", filename );
 return -1;
    }
    g3_rf_fine = -1;
    g3_rf_idx = 0;
    g3_rf_num = read( g3_read_fd, g3_rf_buf, sizeof(g3_rf_buf) );
    if ( g3_rf_num < 0 )
    {
 lprintf( 1, "g3_open_read: can't read from '%s'", filename );
 close( g3_read_fd );
 return -1;
    }
    if ( g3_rf_num >= 64 &&
  strcmp( g3_rf_buf+1, "PC Research, Inc" ) == 0 )
    {
 lprintf( 4, "skipping over DigiFax header" );
 g3_rf_idx = 64;
 g3_rf_fine = ( g3_rf_buf[29] != 0 );
    }
    return g3_read_fd;
}

canonical_original_code:
int g3_open_read(char *filename)
{
    g3_init_lr_bittable();
    g3_read_fd = open( filename, 00 );
    if ( g3_read_fd < 0 )
    {
 lprintf( 1, "g3_open_read: can't open '%s'", filename );
 return -1;
    }
    g3_rf_fine = -1;
    g3_rf_idx = 0;
    g3_rf_num = read( g3_read_fd, g3_rf_buf, sizeof(g3_rf_buf) );
    if ( g3_rf_num < 0 )
    {
 lprintf( 1, "g3_open_read: can't read from '%s'", filename );
 close( g3_read_fd );
 return -1;
    }
    if ( g3_rf_num >= 64 &&
  strcmp( g3_rf_buf+1, "PC Research, Inc" ) == 0 )
    {
 lprintf( 4, "skipping over DigiFax header" );
 g3_rf_idx = 64;
 g3_rf_fine = ( g3_rf_buf[29] != 0 );
    }
    return g3_read_fd;
}

variable_types:
filename
char *


decompiled_code:
int g3_close()
{
int result; // eax

if ( g3_read_fd >= 0 )
{
result = close(g3_read_fd);
g3_read_fd = -1;
g3_rf_idx = 0;
g3_rf_num = 0;
g3_rf_fine = -1;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

if ( g3_read_fd >= 0 )
{
result = close(g3_read_fd);
g3_read_fd = -1;
g3_rf_idx = 0;
g3_rf_num = 0;
g3_rf_fine = -1;
}
return result;
}

original_code:
void g3_close (void)
{
    if (g3_read_fd < 0 ) return;
    close(g3_read_fd);
    g3_read_fd = -1;
    g3_rf_idx = 0;
    g3_rf_num = 0;
    g3_rf_fine = -1;
}

canonical_original_code:
void g3_close()
{
    if (g3_read_fd < 0 ) return;
    close(g3_read_fd);
    g3_read_fd = -1;
    g3_rf_idx = 0;
    g3_rf_num = 0;
    g3_rf_fine = -1;
}


decompiled_code:
__int64 __fastcall g3_rf_chunk(char *a1, int a2)
{
char *v2; // r8
int v3; // ebx
int v4; // er13
int v5; // ebp
unsigned int v6; // er12
char *v7; // r8
int v8; // ebx
__int64 v9; // rdx

v2 = a1;
v3 = a2;
v4 = g3_rf_idx;
if ( g3_rf_idx >= g3_rf_num )
{
v6 = 0;
goto LABEL_7;
}
v5 = g3_rf_num - g3_rf_idx;
v6 = a2;
if ( g3_rf_num - g3_rf_idx <= a2 )
v6 = g3_rf_num - g3_rf_idx;
v7 = (char *)memcpy(a1, &g3_rf_buf, v5);
g3_rf_idx = v6 + v4;
if ( v5 < a2 )
{
v3 = a2 - v6;
v2 = &v7[v6];
LABEL_7:
v8 = read(g3_read_fd, v2, v3);
if ( v8 < 0 )
lprintf(1LL, "g3_read");
v9 = v6;
v6 += v8;
lprintf(6LL, "rp=%d, r=%d", v9, (unsigned int)v8);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2)
{
char *v2; // r8
int v3; // ebx
int v4; // er13
int v5; // ebp
unsigned int v6; // er12
char *v7; // r8
int v8; // ebx
__int64 v9; // rdx

v2 = a1;
v3 = a2;
v4 = g3_rf_idx;
if ( g3_rf_idx >= g3_rf_num )
{
v6 = 0;
goto LABEL_7;
}
v5 = g3_rf_num - g3_rf_idx;
v6 = a2;
if ( g3_rf_num - g3_rf_idx <= a2 )
v6 = g3_rf_num - g3_rf_idx;
v7 = (char *)memcpy(a1, &g3_rf_buf, v5);
g3_rf_idx = v6 + v4;
if ( v5 < a2 )
{
v3 = a2 - v6;
v2 = &v7[v6];
LABEL_7:
v8 = read(g3_read_fd, v2, v3);
if ( v8 < 0 )
lprintf(1LL, "g3_read");
v9 = v6;
v6 += v8;
lprintf(6LL, "rp=%d, r=%d", v9, (unsigned int)v8);
}
return v6;
}

original_code:
int g3_rf_chunk (char * buf,int max)
{
int r, rp;
    rp = 0;
    if ( g3_rf_idx < g3_rf_num )
    {
 r = g3_rf_num - g3_rf_idx;
 if ( r > max ) { r=max; }
 memcpy( buf, g3_rf_buf, g3_rf_num-g3_rf_idx );
 g3_rf_idx += r;
 if ( r == max ) return r;
 rp = r;
    }
    r = read( g3_read_fd, buf+rp, max-rp );
    if ( r < 0 )
 { lprintf( 1, "g3_read" ); }
    lprintf( 6, "rp=%d, r=%d", rp, r );
    return r+rp;
}

canonical_original_code:
int g3_rf_chunk(char *buf, int max)
{
int r; int rp;
    rp = 0;
    if ( g3_rf_idx < g3_rf_num )
    {
 r = g3_rf_num - g3_rf_idx;
 if ( r > max ) { r=max; }
 memcpy( buf, g3_rf_buf, g3_rf_num-g3_rf_idx );
 g3_rf_idx += r;
 if ( r == max ) return r;
 rp = r;
    }
    r = read( g3_read_fd, buf+rp, max-rp );
    if ( r < 0 )
 { lprintf( 1, "g3_read" ); }
    lprintf( 6, "rp=%d, r=%d", rp, r );
    return r+rp;
}

variable_types:
buf
char *

variable_types: max int

variable_types: r int

variable_types: rp int