decompiled_code:
__int64 __fastcall callback_find_device(void *src, char *dest, _DWORD *a3, unsigned int a4, int a5)
{
const char *v8; // rbx
size_t v9; // rax
char *v10; // rax
int v11; // eax
__int64 result; // rax
size_t v13; // [rsp+8h] [rbp-450h]
char v14; // [rsp+17h] [rbp-441h]
char srca[1080]; // [rsp+20h] [rbp-438h] BYREF

lprintf(5LL, "cbfd: search ttys '%s'", (const char *)src);
while ( *(_BYTE *)src )
{
v8 = (const char *)src;
v14 = 0;
do
{
v9 = strlen(v8);
v10 = (char *)memccpy(srca, v8, 58, v9 + 1);
if ( v10 )
{
*(v10 - 1) = 0;
++v8;
}
v13 = strlen(srca);
if ( !memcmp(srca, "/dev/", 5uLL) )
{
strcpy(dest, srca);
}
else
{
if ( srca[0] == 47 )
{
lprintf(3LL, "%s: absolute paths must start with /dev, skipping", srca);
goto LABEL_7;
}
sprintf(dest, "/dev/%s", srca);
}
Device = dest + 5;
lprintf(5LL, "cbfd: device: '%s'", dest);
if ( (unsigned int)makelock(Device) )
{
lprintf(4LL, "%s: locked", Device);
v14 = 1;
}
else
{
v11 = find_mgetty(Device);
*a3 = v11;
if ( v11 == -1 )
{
lprintf(4LL, "no mgetty on %s, can't use this line", Device);
rmlocks();
}
else
{
result = callback_init_device(dest);
if ( (_DWORD)result != -1 )
return result;
lprintf(4LL, "can't init %s, skipping", Device);
rmlocks();
}
}
LABEL_7:
v8 += v13;
}
while ( *v8 );
if ( !v14 )
return 0xFFFFFFFFLL;
lprintf(5LL, "delaying %d seconds before next try", a4);
sleep(a4);
if ( time(0LL) >= a5 )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *src, char *dest, _DWORD *a3, unsigned int a4, int a5)
{
const char *v8; // rbx
size_t v9; // rax
char *v10; // rax
int v11; // eax
__int64 result; // rax
size_t v13; // [rsp+8h] [rbp-450h]
char v14; // [rsp+17h] [rbp-441h]
char srca[1080]; // [rsp+20h] [rbp-438h] BYREF

lprintf(5LL, "cbfd: search ttys '%s'", (const char *)src);
while ( *(_BYTE *)src )
{
v8 = (const char *)src;
v14 = 0;
do
{
v9 = strlen(v8);
v10 = (char *)memccpy(srca, v8, 58, v9 + 1);
if ( v10 )
{
*(v10 - 1) = 0;
++v8;
}
v13 = strlen(srca);
if ( !memcmp(srca, "/dev/", 5uLL) )
{
strcpy(dest, srca);
}
else
{
if ( srca[0] == 47 )
{
lprintf(3LL, "%s: absolute paths must start with /dev, skipping", srca);
goto LABEL_7;
}
sprintf(dest, "/dev/%s", srca);
}
Device = dest + 5;
lprintf(5LL, "cbfd: device: '%s'", dest);
if ( (unsigned int)makelock(Device) )
{
lprintf(4LL, "%s: locked", Device);
v14 = 1;
}
else
{
v11 = func3(Device);
*a3 = v11;
if ( v11 == -1 )
{
lprintf(4LL, "no mgetty on %s, can't use this line", Device);
rmlocks();
}
else
{
result = func6(dest);
if ( (_DWORD)result != -1 )
return result;
lprintf(4LL, "can't init %s, skipping", Device);
rmlocks();
}
}
LABEL_7:
v8 += v13;
}
while ( *v8 );
if ( !v14 )
return 0xFFFFFFFFLL;
lprintf(5LL, "delaying %d seconds before next try", a4);
sleep(a4);
if ( time(0LL) >= a5 )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

original_code:
int callback_find_device (char * ttys,char * device,int * mgetty_pid,int rtime,int end_time)
{
char * p, *p_help;
int fd;
char tty[1024];
boolean found_locked;
    lprintf( 5, "cbfd: search ttys '%s'", ttys );
    do
    {
 found_locked = (1==0);
 p = ttys;
 while( *p != 0 )
 {
     p_help = memccpy( tty, p, ':', strlen(p)+1 );
     if ( p_help != ((void *)0) ) { p_help--; *p_help = 0; p++; }
     p+=strlen(tty);
     if ( strncmp( tty, "/dev/", 5 ) == 0 )
     {
  strcpy( device, tty );
     }
     else
     {
  if ( tty[0] == '/' )
  {
      lprintf( 3, "%s: absolute paths must start with /dev, skipping", tty );
      continue;
  }
  sprintf( device, "/dev/%s", tty );
     }
     Device = device+5;
     lprintf( 5, "cbfd: device: '%s'", device );
     if ( makelock( Device ) != 0 )
     {
  lprintf( 4, "%s: locked", Device );
  found_locked = (1==1);
  continue;
     }
     if ( (*mgetty_pid = find_mgetty( Device )) == -1 )
     {
  lprintf( 4, "no mgetty on %s, can't use this line", Device );
  rmlocks();
  continue;
     }
     if ( ( fd = callback_init_device( device )) == -1 )
     {
  lprintf( 4, "can't init %s, skipping", Device );
  rmlocks();
  continue;
     }
     return fd;
 }
 if ( found_locked )
 {
     lprintf( 5, "delaying %d seconds before next try", rtime );
     sleep(rtime);
 }
    }
    while( found_locked && time(((void *)0)) < end_time );
    return -1;
}

canonical_original_code:
int callback_find_device(char *ttys, char *device, int *mgetty_pid, int rtime, int end_time)
{
char *p; char *p_help;
int fd;
char tty[1024];
char found_locked;
    lprintf( 5, "cbfd: search ttys '%s'", ttys );
    do
    {
 found_locked = (1==0);
 p = ttys;
 while( *p != 0 )
 {
     p_help = memccpy( tty, p, ':', strlen(p)+1 );
     if ( p_help != ((void *)0) ) { p_help--; *p_help = 0; p++; }
     p+=strlen(tty);
     if ( strncmp( tty, "/dev/", 5 ) == 0 )
     {
  strcpy( device, tty );
     }
     else
     {
  if ( tty[0] == '/' )
  {
      lprintf( 3, "%s: absolute paths must start with /dev, skipping", tty );
      continue;
  }
  sprintf( device, "/dev/%s", tty );
     }
     Device = device+5;
     lprintf( 5, "cbfd: device: '%s'", device );
     if ( makelock( Device ) != 0 )
     {
  lprintf( 4, "%s: locked", Device );
  found_locked = (1==1);
  continue;
     }
     if ( (*mgetty_pid = find_mgetty( Device )) == -1 )
     {
  lprintf( 4, "no mgetty on %s, can't use this line", Device );
  rmlocks();
  continue;
     }
     if ( ( fd = callback_init_device( device )) == -1 )
     {
  lprintf( 4, "can't init %s, skipping", Device );
  rmlocks();
  continue;
     }
     return fd;
 }
 if ( found_locked )
 {
     lprintf( 5, "delaying %d seconds before next try", rtime );
     sleep(rtime);
 }
    }
    while( found_locked && time(((void *)0)) < end_time );
    return -1;
}

variable_types:
ttys
char *

variable_types:
device
char *

variable_types: rtime int

variable_types:
p
char *

variable_types:
tty
char [1024]


dialup

repo: Distrotech/mgetty

decompiled_code:
__int64 __fastcall dialup(unsigned int a1, __int64 a2, int a3, int a4)
{
int v7; // er13
const char **v9; // rbx
const char *v10; // rax
const char *v11; // rbx
bool v12; // zf
_BOOL4 v13; // ebp
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

signal(14, (__sighandler_t)sig_timer);
v7 = 0;
do
{
alarm(0xB4u);
v9 = (const char **)(a2 + 8LL * v7);
lprintf(4LL, "dialing %s...", *v9);
sprintf(s, "%s%s", *(const char **)&c[50], *v9);
mdm_send(s, a1);
while ( 1 )
{
v10 = (const char *)((__int64 (__fastcall *)(_QWORD))mdm_get_line)(a1);
v11 = v10;
if ( !v10 )
break;
lprintf(4LL, "dialup: got '%s'", v10);
v12 = memcmp(v11, "CONNECT", 7uLL) == 0;
v13 = !v12;
if ( v12 )
{
alarm(0);
lprintf(4LL, "got CONNECT, success!");
return v13;
}
if ( !memcmp(v11, "ERROR", 5uLL)
|| !memcmp(v11, "OK", 2uLL)
|| !memcmp(v11, "BUSY", 4uLL)
|| !memcmp(v11, "NO DIALTONE", 0xBuLL)
|| !memcmp(v11, "NO CARRIER", 0xAuLL)
|| !strcmp(v11, "NO ANSWER") )
{
lprintf(4LL, "dialup attempt failed, try next number");
break;
}
}
alarm(0);
if ( ++v7 >= a3 )
v7 = 0;
sleep(c[26]);
}
while ( time(0LL) < a4 && !timeout );
lprintf(4LL, "time ran out, giving up");
return -1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, int a3, int a4)
{
int v7; // er13
const char **v9; // rbx
const char *v10; // rax
const char *v11; // rbx
bool v12; // zf
_BOOL4 v13; // ebp
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

signal(14, (__sighandler_t)sig_timer);
v7 = 0;
do
{
alarm(0xB4u);
v9 = (const char **)(a2 + 8LL * v7);
lprintf(4LL, "dialing %s...", *v9);
sprintf(s, "%s%s", *(const char **)&c[50], *v9);
mdm_send(s, a1);
while ( 1 )
{
v10 = (const char *)((__int64 (__fastcall *)(_QWORD))mdm_get_line)(a1);
v11 = v10;
if ( !v10 )
break;
lprintf(4LL, "dialup: got '%s'", v10);
v12 = memcmp(v11, "CONNECT", 7uLL) == 0;
v13 = !v12;
if ( v12 )
{
alarm(0);
lprintf(4LL, "got CONNECT, success!");
return v13;
}
if ( !memcmp(v11, "ERROR", 5uLL)
|| !memcmp(v11, "OK", 2uLL)
|| !memcmp(v11, "BUSY", 4uLL)
|| !memcmp(v11, "NO DIALTONE", 0xBuLL)
|| !memcmp(v11, "NO CARRIER", 0xAuLL)
|| !strcmp(v11, "NO ANSWER") )
{
lprintf(4LL, "dialup attempt failed, try next number");
break;
}
}
alarm(0);
if ( ++v7 >= a3 )
v7 = 0;
sleep(c[26]);
}
while ( time(0LL) < a4 && !timeout );
lprintf(4LL, "time ran out, giving up");
return -1;
}

original_code:
int dialup (int fd,char ** phone,int count,int end_time)
{
int n;
char dialbuf[1024];
char * r;
    signal( 14, sig_timer );
    n=0;
    do
    {
 alarm(180);
        lprintf( 4, "dialing %s...", phone[n] );
 sprintf( dialbuf, "%s%s", ((char *) c.dial_prefix.d.p), phone[n] );
 mdm_send( dialbuf, fd );
 while( 1 )
 {
     r = mdm_get_line( fd );
     if ( r == ((void *)0) ) break;
     lprintf( 4, "dialup: got '%s'", r );
     if ( strncmp( r, "CONNECT", 7 ) == 0 )
     {
         alarm(0); lprintf( 4, "got CONNECT, success!" );
  return 0;
     }
     if ( strncmp( r, "ERROR", 5 ) == 0 ||
   strncmp( r, "OK", 2 ) == 0 ||
   strncmp( r, "BUSY", 4 ) == 0 ||
   strncmp( r, "NO DIALTONE", 11 ) == 0 ||
   strncmp( r, "NO CARRIER", 10 ) == 0 ||
   strncmp( r, "NO ANSWER", 10 ) == 0 )
     {
  lprintf( 4, "dialup attempt failed, try next number");
  break;
     }
 }
 alarm(0);
 if ( ++n >= count ) n=0;
 sleep( ((int) c.retry_time.d.i) );
    }
    while( time(((void *)0)) < end_time && ! timeout );
    lprintf( 4, "time ran out, giving up" );
    return -1;
}

canonical_original_code:
int dialup(int fd, char **phone, int count, int end_time)
{
int n;
char dialbuf[1024];
char *r;
    signal( 14, sig_timer );
    n=0;
    do
    {
 alarm(180);
        lprintf( 4, "dialing %s...", phone[n] );
 sprintf( dialbuf, "%s%s", ((char *) c.dial_prefix.d.p), phone[n] );
 mdm_send( dialbuf, fd );
 while( 1 )
 {
     r = mdm_get_line( fd );
     if ( r == ((void *)0) ) break;
     lprintf( 4, "dialup: got '%s'", r );
     if ( strncmp( r, "CONNECT", 7 ) == 0 )
     {
         alarm(0); lprintf( 4, "got CONNECT, success!" );
  return 0;
     }
     if ( strncmp( r, "ERROR", 5 ) == 0 ||
   strncmp( r, "OK", 2 ) == 0 ||
   strncmp( r, "BUSY", 4 ) == 0 ||
   strncmp( r, "NO DIALTONE", 11 ) == 0 ||
   strncmp( r, "NO CARRIER", 10 ) == 0 ||
   strncmp( r, "NO ANSWER", 10 ) == 0 )
     {
  lprintf( 4, "dialup attempt failed, try next number");
  break;
     }
 }
 alarm(0);
 if ( ++n >= count ) n=0;
 sleep( ((int) c.retry_time.d.i) );
    }
    while( time(((void *)0)) < end_time && ! timeout );
    lprintf( 4, "time ran out, giving up" );
    return -1;
}

variable_types: fd int

variable_types:
phone
char **

variable_types: count int

variable_types: n int

variable_types:
dialbuf
char [1024]

variable_types:
r
char *

return_type: int


cndfind

decompiled_code:
void cndfind()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code: void cndfind (char * p) { }

canonical_original_code: void cndfind(char *p) { }

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char **v5; // rbp
__int64 v6; // rbx
time_t v7; // r13
unsigned int v8; // eax
__int64 v9; // rbx
int v10; // edx
signed int v11; // ebx
int v12; // edi
char *v13; // rbx
size_t v14; // rax
__uid_t v16; // eax
int v17; // ebp
const unsigned __int16 *v18; // rsi
char *v19; // rax
int v20; // [rsp+Ch] [rbp-8CCh] BYREF
char v21[64]; // [rsp+10h] [rbp-8C8h] BYREF
char s[1040]; // [rsp+50h] [rbp-888h] BYREF
char v23[48]; // [rsp+460h] [rbp-478h] BYREF
char *v24; // [rsp+490h] [rbp-448h] BYREF
__pid_t pid; // [rsp+49Ch] [rbp-43Ch] BYREF
char dest[1080]; // [rsp+4A0h] [rbp-438h] BYREF

pid = -1;
signal(1, (__sighandler_t)((char *)sig_timer + 1));
signal(2, (__sighandler_t)sig_goodbye);
signal(3, (__sighandler_t)sig_goodbye);
signal(15, (__sighandler_t)sig_goodbye);
siginterrupt(2, 1);
siginterrupt(14, 1);
siginterrupt(1, 1);
siginterrupt(10, 1);
siginterrupt(12, 1);
Device = "unknown";
if ( geteuid() )
{
fwrite("\nSorry, callback must be run as userid \"root\", otherwise it won't work.\n\n", 1uLL, 0x49uLL, stderr);
v16 = getuid();
lprintf(2LL, "fail: non-root user id %d", v16);
exit(2);
}
callback_parse_args((unsigned int)argc, argv);
if ( optind >= argc )
{
lprintf(4LL, "reading telephone number from stdin");
printf("Telephone number for callback: ");
fgets(v23, 30, stdin);
v24 = v23;
v17 = strlen(v23);
if ( v17 <= 0 )
{
v4 = 1;
v5 = &v24;
}
else
{
v18 = *_ctype_b_loc();
v19 = &v23[v17];
while ( (v18[*(v19 - 1)] & 0x4000) == 0 )
{
*--v19 = 0;
if ( v19 == &s[v17 + 1039 - (v17 - 1)] )
{
v4 = 1;
v5 = &v24;
goto LABEL_4;
}
}
v4 = 1;
v5 = &v24;
}
}
else
{
v4 = argc - optind;
v5 = (char **)&argv[optind];
}
LABEL_4:
sprintf(s, "/var/log/mgetty.%s", "callback");
log_init_paths(*argv, s, 0LL);
lprintf(5LL, "callback: %s", mgetty_version);
lprintf(6LL, "%d telephone numbers given:", v4);
v6 = 1LL;
do
{
lprintf(6LL, "#%d: %s", (unsigned int)v6, v5[v6 - 1]);
++v6;
}
while ( v6 != v4 + 1 );
callback_get_config(0LL);
v7 = time(0LL) + (int)c[32];
if ( !LOBYTE(c[68]) )
detach_tty();
v8 = time(0LL);
srand(v8);
v9 = *(_QWORD *)&c[14];
if ( (int)c[20] <= 0 )
v10 = rand() % 5;
else
v10 = rand() % (int)c[20];
v11 = v10 + v9;
if ( v11 < 4 )
v11 = 4;
lprintf(5LL, "delaying %d seconds", (unsigned int)v11);
sleep(v11);
v12 = callback_find_device(*(void **)&c[2], dest, &pid, c[26], v7);
if ( v12 == -1 )
{
lprintf(1LL, "can't get dialout device, exiting");
exit(2);
}
if ( (unsigned int)fd_make_stddev(v12) == -1 )
{
lprintf(1LL, "can't make stdin/stdout/sterr, exiting");
exit(2);
}
setbuf(stdin, 0LL);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
v13 = Device;
v14 = strlen(Device);
log_init_paths(0LL, 0LL, &v13[v14 - 3]);
callback_get_config(Device);
lprintf(4LL, "initializing modem...");
if ( (unsigned int)do_chat(0LL, *(_QWORD *)&c[38], &dial_chat_actions, &v20, 10LL, 1LL) )
{
if ( !v20 )
{
lprintf(1LL, "Error: modem does not answer, giving up!");
return -1;
}
lprintf(3LL, "modem init failed: expect problems.");
}
if ( (unsigned int)dialup(0, (__int64)v5, v4, v7) == -1 )
{
lprintf(1LL, "can't dial any of the given numbers, exiting");
exit(10);
}
tio_get(0LL, v21);
tio_carrier(v21, 1LL);
tio_set(0LL, v21);
delay(c[62]);
puts("Connection established, please wait...\r");
tio_drain_output(0LL);
delay(300LL);
signal(10, (__sighandler_t)sig_mgetty_ack);
if ( kill(pid, 10) < 0 )
{
lprintf(1LL, "can't signal mgetty process %d, giving up", (unsigned int)pid);
puts("Fatal error: can't pass control, hanging up.\r");
sleep(5u);
exit(5);
}
signal(14, (__sighandler_t)sig_timer);
alarm(0x1Eu);
pause();
alarm(0);
if ( timeout || !mgetty_ACK )
{
lprintf(0LL, "wait_ack: something went wrong, didn't get ACK in time");
puts("Fatal error: can't pass control, hanging up.\r");
sleep(5u);
exit(5);
}
lprintf(2LL, "callback: success, device=%s, mgetty=%d", dest, (unsigned int)pid);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char **v5; // rbp
__int64 v6; // rbx
time_t v7; // r13
unsigned int v8; // eax
__int64 v9; // rbx
int v10; // edx
signed int v11; // ebx
int v12; // edi
char *v13; // rbx
size_t v14; // rax
__uid_t v16; // eax
int v17; // ebp
const unsigned __int16 *v18; // rsi
char *v19; // rax
int v20; // [rsp+Ch] [rbp-8CCh] BYREF
char v21[64]; // [rsp+10h] [rbp-8C8h] BYREF
char s[1040]; // [rsp+50h] [rbp-888h] BYREF
char v23[48]; // [rsp+460h] [rbp-478h] BYREF
char *v24; // [rsp+490h] [rbp-448h] BYREF
__pid_t pid; // [rsp+49Ch] [rbp-43Ch] BYREF
char dest[1080]; // [rsp+4A0h] [rbp-438h] BYREF

pid = -1;
signal(1, (__sighandler_t)((char *)sig_timer + 1));
signal(2, (__sighandler_t)sig_goodbye);
signal(3, (__sighandler_t)sig_goodbye);
signal(15, (__sighandler_t)sig_goodbye);
siginterrupt(2, 1);
siginterrupt(14, 1);
siginterrupt(1, 1);
siginterrupt(10, 1);
siginterrupt(12, 1);
Device = "unknown";
if ( geteuid() )
{
fwrite("\nSorry, callback must be run as userid \"root\", otherwise it won't work.\n\n", 1uLL, 0x49uLL, stderr);
v16 = getuid();
lprintf(2LL, "fail: non-root user id %d", v16);
exit(2);
}
callback_parse_args((unsigned int)argc, argv);
if ( optind >= argc )
{
lprintf(4LL, "reading telephone number from stdin");
printf("Telephone number for callback: ");
fgets(v23, 30, stdin);
v24 = v23;
v17 = strlen(v23);
if ( v17 <= 0 )
{
v4 = 1;
v5 = &v24;
}
else
{
v18 = *_ctype_b_loc();
v19 = &v23[v17];
while ( (v18[*(v19 - 1)] & 0x4000) == 0 )
{
*--v19 = 0;
if ( v19 == &s[v17 + 1039 - (v17 - 1)] )
{
v4 = 1;
v5 = &v24;
goto LABEL_4;
}
}
v4 = 1;
v5 = &v24;
}
}
else
{
v4 = argc - optind;
v5 = (char **)&argv[optind];
}
LABEL_4:
sprintf(s, "/var/log/mgetty.%s", "callback");
log_init_paths(*argv, s, 0LL);
lprintf(5LL, "callback: %s", mgetty_version);
lprintf(6LL, "%d telephone numbers given:", v4);
v6 = 1LL;
do
{
lprintf(6LL, "#%d: %s", (unsigned int)v6, v5[v6 - 1]);
++v6;
}
while ( v6 != v4 + 1 );
callback_get_config(0LL);
v7 = time(0LL) + (int)c[32];
if ( !LOBYTE(c[68]) )
func4();
v8 = time(0LL);
srand(v8);
v9 = *(_QWORD *)&c[14];
if ( (int)c[20] <= 0 )
v10 = rand() % 5;
else
v10 = rand() % (int)c[20];
v11 = v10 + v9;
if ( v11 < 4 )
v11 = 4;
lprintf(5LL, "delaying %d seconds", (unsigned int)v11);
sleep(v11);
v12 = func7(*(void **)&c[2], dest, &pid, c[26], v7);
if ( v12 == -1 )
{
lprintf(1LL, "can't get dialout device, exiting");
exit(2);
}
if ( (unsigned int)func5(v12) == -1 )
{
lprintf(1LL, "can't make stdin/stdout/sterr, exiting");
exit(2);
}
setbuf(stdin, 0LL);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
v13 = Device;
v14 = strlen(Device);
log_init_paths(0LL, 0LL, &v13[v14 - 3]);
callback_get_config(Device);
lprintf(4LL, "initializing modem...");
if ( (unsigned int)do_chat(0LL, *(_QWORD *)&c[38], &dial_chat_actions, &v20, 10LL, 1LL) )
{
if ( !v20 )
{
lprintf(1LL, "Error: modem does not answer, giving up!");
return -1;
}
lprintf(3LL, "modem init failed: expect problems.");
}
if ( (unsigned int)func8(0, (__int64)v5, v4, v7) == -1 )
{
lprintf(1LL, "can't dial any of the given numbers, exiting");
exit(10);
}
tio_get(0LL, v21);
tio_carrier(v21, 1LL);
tio_set(0LL, v21);
delay(c[62]);
puts("Connection established, please wait...\r");
tio_drain_output(0LL);
delay(300LL);
signal(10, (__sighandler_t)sig_mgetty_ack);
if ( kill(pid, 10) < 0 )
{
lprintf(1LL, "can't signal mgetty process %d, giving up", (unsigned int)pid);
puts("Fatal error: can't pass control, hanging up.\r");
sleep(5u);
exit(5);
}
signal(14, (__sighandler_t)sig_timer);
alarm(0x1Eu);
pause();
alarm(0);
if ( timeout || !mgetty_ACK )
{
lprintf(0LL, "wait_ack: something went wrong, didn't get ACK in time");
puts("Fatal error: can't pass control, hanging up.\r");
sleep(5u);
exit(5);
}
lprintf(2LL, "callback: success, device=%s, mgetty=%d", dest, (unsigned int)pid);
return 0;
}

original_code:
int main (int argc,char ** argv)
{
    char devname[1024 +1];
    int mgetty_pid = -1;
    char ** t_numbers;
    int t_count;
    char * t_help;
    char phonebuf[40];
    char buf[1024 +1];
    TIO tio;
    int fd;
    int i;
    time_t end_time;
    action_t action;
    (void) signal(1, ((__sighandler_t) 1));
    (void) signal(2, sig_goodbye);
    (void) signal(3, sig_goodbye);
    (void) signal(15, sig_goodbye);
    siginterrupt( 2, (1==1) );
    siginterrupt( 14, (1==1) );
    siginterrupt( 1, (1==1) );
    siginterrupt( 10, (1==1) );
    siginterrupt( 12, (1==1) );
    Device = "unknown";
    if ( geteuid() != 0 )
    {
 fprintf( stderr, "\nSorry, callback must be run as userid \"root\", otherwise it won't work.\n\n" );
 lprintf( 2, "fail: non-root user id %d", getuid() );
 exit(2);
    }
    callback_parse_args( argc, argv );
    if (optind < argc)
    {
        t_count = argc - optind;
        t_numbers = &argv[optind];
    }
    else
    {
 lprintf( 4, "reading telephone number from stdin" );
 printf( "Telephone number for callback: " );
 fgets( phonebuf, 30, stdin );
 t_count = 1;
 t_numbers = &t_help;
 t_numbers[0] = phonebuf;
        i = strlen(phonebuf);
 while (i>0 && !((*__ctype_b_loc ())[(int) ((phonebuf[i-1]))] & (unsigned short int) _ISprint))
     phonebuf[--i] = 0;
    }
    sprintf( buf, "/var/log/mgetty.%s", "callback" );
    log_init_paths( argv[0], buf, ((void *)0) );
    lprintf( 5, "callback: %s", mgetty_version );
    lprintf( 6, "%d telephone numbers given:", t_count );
    for( i=0; i<t_count; i++ ) lprintf( 6, "#%d: %s", i+1, t_numbers[i] );
    callback_get_config( ((void *)0) );
    end_time = time(((void *)0)) + ((int) c.max_retry_time.d.i);
    if ( !((boolean) c.nodetach.d.i) )
 detach_tty();
    srand((unsigned)time(((void *)0)));
    i = ((int) c.delay.d.i) + ( (((int) c.delay_rand.d.i)>0) ? rand()%((int) c.delay_rand.d.i)
            : rand()%5 );
    if (i<4) i=4;
    lprintf( 5, "delaying %d seconds", i );
    sleep(i);
    fd = callback_find_device( ((char *) c.ttys.d.p), devname, &mgetty_pid,
    ((int) c.retry_time.d.i), end_time );
    if ( fd == -1 )
    {
 lprintf( 1, "can't get dialout device, exiting" );
 exit(2);
    }
    if ( fd_make_stddev( fd ) == -1 )
    {
 lprintf( 1, "can't make stdin/stdout/sterr, exiting" );
 exit(2);
    }
    fd=0;
    setbuf( stdin, (char *) ((void *)0) );
    setbuf( stdout, (char *) ((void *)0) );
    setbuf( stderr, (char *) ((void *)0) );
    log_init_paths( ((void *)0), ((void *)0), &Device[strlen(Device)-3] );
    callback_get_config( Device );
    lprintf( 4, "initializing modem..." );
    if ( do_chat( fd, ((char **) c.modem_init.d.p),
                  dial_chat_actions, &action, 10, (1==1) ) != 0 )
    {
        if ( action == A_TIMOUT )
        {
     lprintf( 1, "Error: modem does not answer, giving up!" );
     return -1;
 }
 lprintf( 3, "modem init failed: expect problems." );
    }
    if ( dialup( fd, t_numbers, t_count, end_time ) == -1 )
    {
 lprintf( 1, "can't dial any of the given numbers, exiting" );
 exit(10);
    }
    tio_get( 0, &tio );
    tio_carrier( &tio, (1==1) );
    tio_set( 0, &tio );
    delay( ((int) c.prompt_waittime.d.i) );
    printf( "Connection established, please wait...\r\n" );
    tio_drain_output( 0 );
    delay( 300 );
    signal( 10, sig_mgetty_ack );
    if ( kill( mgetty_pid, 10 ) < 0 )
    {
        lprintf( 1, "can't signal mgetty process %d, giving up",
   mgetty_pid);
        printf( "Fatal error: can't pass control, hanging up.\r\n" );
        sleep(5);
        exit(5);
    }
    signal( 14, sig_timer );
    alarm(30);
    pause();
    alarm(0);
    if ( timeout || !mgetty_ACK )
    {
        lprintf( 0, "wait_ack: something went wrong, didn't get ACK in time" );
        printf( "Fatal error: can't pass control, hanging up.\r\n" );
 sleep(5);
        exit(5);
    }
    lprintf( 2, "callback: success, device=%s, mgetty=%d", devname, mgetty_pid );
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char devname[-1];
    int mgetty_pid = -1;
    char **t_numbers;
    int t_count;
    char *t_help;
    char phonebuf[40];
    char buf[-1];
    struct termios tio;
    int fd;
    int i;
    long end_time;
    enum action_t action;
    (void) signal(1, ((void (*)(int)) 1));
    (void) signal(2, sig_goodbye);
    (void) signal(3, sig_goodbye);
    (void) signal(15, sig_goodbye);
    siginterrupt( 2, (1==1) );
    siginterrupt( 14, (1==1) );
    siginterrupt( 1, (1==1) );
    siginterrupt( 10, (1==1) );
    siginterrupt( 12, (1==1) );
    Device = "unknown";
    if ( geteuid() != 0 )
    {
 fprintf( stderr, "\nSorry, callback must be run as userid \"root\", otherwise it won't work.\n\n" );
 lprintf( 2, "fail: non-root user id %d", getuid() );
 exit(2);
    }
    callback_parse_args( argc, argv );
    if (optind < argc)
    {
        t_count = argc - optind;
        t_numbers = &argv[optind];
    }
    else
    {
 lprintf( 4, "reading telephone number from stdin" );
 printf( "Telephone number for callback: " );
 fgets( phonebuf, 30, stdin );
 t_count = 1;
 t_numbers = &t_help;
 t_numbers[0] = phonebuf;
        i = strlen(phonebuf);
 while (i>0 && !((*__ctype_b_loc ())[(int) ((phonebuf[i-1]))] & (unsigned short) _ISprint))
     phonebuf[--i] = 0;
    }
    sprintf( buf, "/var/log/mgetty.%s", "callback" );
    log_init_paths( argv[0], buf, ((void *)0) );
    lprintf( 5, "callback: %s", mgetty_version );
    lprintf( 6, "%d telephone numbers given:", t_count );
    for( i=0; i<t_count; i++ ) lprintf( 6, "#%d: %s", i+1, t_numbers[i] );
    callback_get_config( ((void *)0) );
    end_time = time(((void *)0)) + ((int) c.max_retry_time.d.i);
    if ( !((char) c.nodetach.d.i) )
 detach_tty();
    srand((unsigned int)time(((void *)0)));
    i = ((int) c.delay.d.i) + ( (((int) c.delay_rand.d.i)>0) ? rand()%((int) c.delay_rand.d.i)
            : rand()%5 );
    if (i<4) i=4;
    lprintf( 5, "delaying %d seconds", i );
    sleep(i);
    fd = callback_find_device( ((char *) c.ttys.d.p), devname, &mgetty_pid,
    ((int) c.retry_time.d.i), end_time );
    if ( fd == -1 )
    {
 lprintf( 1, "can't get dialout device, exiting" );
 exit(2);
    }
    if ( fd_make_stddev( fd ) == -1 )
    {
 lprintf( 1, "can't make stdin/stdout/sterr, exiting" );
 exit(2);
    }
    fd=0;
    setbuf( stdin, (char *) ((void *)0) );
    setbuf( stdout, (char *) ((void *)0) );
    setbuf( stderr, (char *) ((void *)0) );
    log_init_paths( ((void *)0), ((void *)0), &Device[strlen(Device)-3] );
    callback_get_config( Device );
    lprintf( 4, "initializing modem..." );
    if ( do_chat( fd, ((char **) c.modem_init.d.p),
                  dial_chat_actions, &action, 10, (1==1) ) != 0 )
    {
        if ( action == A_TIMOUT )
        {
     lprintf( 1, "Error: modem does not answer, giving up!" );
     return -1;
 }
 lprintf( 3, "modem init failed: expect problems." );
    }
    if ( dialup( fd, t_numbers, t_count, end_time ) == -1 )
    {
 lprintf( 1, "can't dial any of the given numbers, exiting" );
 exit(10);
    }
    tio_get( 0, &tio );
    tio_carrier( &tio, (1==1) );
    tio_set( 0, &tio );
    delay( ((int) c.prompt_waittime.d.i) );
    printf( "Connection established, please wait...\r\n" );
    tio_drain_output( 0 );
    delay( 300 );
    signal( 10, sig_mgetty_ack );
    if ( kill( mgetty_pid, 10 ) < 0 )
    {
        lprintf( 1, "can't signal mgetty process %d, giving up",
   mgetty_pid);
        printf( "Fatal error: can't pass control, hanging up.\r\n" );
        sleep(5);
        exit(5);
    }
    signal( 14, sig_timer );
    alarm(30);
    pause();
    alarm(0);
    if ( timeout || !mgetty_ACK )
    {
        lprintf( 0, "wait_ack: something went wrong, didn't get ACK in time" );
        printf( "Fatal error: can't pass control, hanging up.\r\n" );
 sleep(5);
        exit(5);
    }
    lprintf( 2, "callback: success, device=%s, mgetty=%d", devname, mgetty_pid );
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
devname
char [-1]

variable_types:
phonebuf
char [40]

variable_types:
buf
char [-1]

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

variable_types: i int

variable_types: enum action_t { A_TIMOUT=0, A_FAIL=1, A_FAX=2, A_VCON=3, A_CONN=4, A_RING1=5, A_RING2=6, A_RING3=7, A_RING4=8, A_RING5=9 }


decompiled_code:
__int64 __fastcall voice_write_char(char a1)
{
time_t v1; // rbx
int v2; // eax
int v3; // eax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
v1 = cvd[25] + time(0LL);
while ( 1 )
{
if ( time(0LL) > v1 )
{
lprintf(3LL, "%s: timeout while writing character to voice modem", program_name);
return 0xFFFFFFFFLL;
}
v2 = write(voice_fd, buf, 1uLL);
if ( v2 == 1 )
break;
if ( v2 < 0 )
{
v3 = *_errno_location();
if ( (v3 & 0xFFFFFFFB) != 0 && v3 != 11 )
{
lprintf(3LL, "%s: could not write character to voice modem", program_name);
return 0xFFFFFFFFLL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
time_t v1; // rbx
int v2; // eax
int v3; // eax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
v1 = cvd[25] + time(0LL);
while ( 1 )
{
if ( time(0LL) > v1 )
{
lprintf(3LL, "%s: timeout while writing character to voice modem", program_name);
return 0xFFFFFFFFLL;
}
v2 = write(voice_fd, buf, 1uLL);
if ( v2 == 1 )
break;
if ( v2 < 0 )
{
v3 = *_errno_location();
if ( (v3 & 0xFFFFFFFB) != 0 && v3 != 11 )
{
lprintf(3LL, "%s: could not write character to voice modem", program_name);
return 0xFFFFFFFFLL;
}
}
}
return 0LL;
}

original_code:
int voice_write_char(char charout)
     {
     time_t timeout;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while (timeout >= time(((void *)0)))
          {
          int result;
          result = write(voice_fd, &charout, 1);
          if (result == 1)
               return((0));
          if ((result < 0) && ((*__errno_location ()) != 0) && ((*__errno_location ()) != 4) && ((*__errno_location ()) !=
           11))
               {
               lprintf(3, "%s: could not write character to voice modem",
                program_name);
               return((-1));
               };
          };
     lprintf(3, "%s: timeout while writing character to voice modem",
      program_name);
     return((-1));
     }

canonical_original_code:
int voice_write_char(char charout)
     {
     long timeout;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while (timeout >= time(((void *)0)))
          {
          int result;
          result = write(voice_fd, &charout, 1);
          if (result == 1)
               return((0));
          if ((result < 0) && ((*__errno_location ()) != 0) && ((*__errno_location ()) != 4) && ((*__errno_location ()) !=
           11))
               {
               lprintf(3, "%s: could not write character to voice modem",
                program_name);
               return((-1));
               };
          };
     lprintf(3, "%s: timeout while writing character to voice modem",
      program_name);
     return((-1));
     }

variable_types: charout char

variable_types: timeout long

variable_types: result int


decompiled_code:
__int64 __fastcall voice_write_raw(void *buf, int a2)
{
time_t v4; // r12
int v5; // eax
time_t v6; // rax
int v7; // eax

v4 = cvd[25] + time(0LL);
while ( 1 )
{
v6 = time(0LL);
if ( a2 <= 0 || v6 > v4 )
break;
v7 = write(voice_fd, buf, a2);
if ( v7 < 0 )
{
v5 = *_errno_location();
if ( (v5 & 0xFFFFFFFB) != 0 && v5 != 11 )
{
lprintf(3LL, "%s: could not write buffer to voice modem", program_name);
return (unsigned int)-1;
}
if ( *_errno_location() == 11 )
{
LABEL_5:
delay(LODWORD(cvd[88]));
goto LABEL_6;
}
}
else
{
if ( v7 <= 0 )
goto LABEL_5;
buf = (char *)buf + v7;
a2 -= v7;
}
LABEL_6:
voice_check_events();
}
if ( a2 )
{
lprintf(3LL, "%s: timeout while writing buffer to voice modem", program_name);
a2 = -1;
}
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf, int a2)
{
time_t v4; // r12
int v5; // eax
time_t v6; // rax
int v7; // eax

v4 = cvd[25] + time(0LL);
while ( 1 )
{
v6 = time(0LL);
if ( a2 <= 0 || v6 > v4 )
break;
v7 = write(voice_fd, buf, a2);
if ( v7 < 0 )
{
v5 = *_errno_location();
if ( (v5 & 0xFFFFFFFB) != 0 && v5 != 11 )
{
lprintf(3LL, "%s: could not write buffer to voice modem", program_name);
return (unsigned int)-1;
}
if ( *_errno_location() == 11 )
{
LABEL_5:
delay(LODWORD(cvd[88]));
goto LABEL_6;
}
}
else
{
if ( v7 <= 0 )
goto LABEL_5;
buf = (char *)buf + v7;
a2 -= v7;
}
LABEL_6:
voice_check_events();
}
if ( a2 )
{
lprintf(3LL, "%s: timeout while writing buffer to voice modem", program_name);
a2 = -1;
}
return (unsigned int)a2;
}

original_code:
int voice_write_raw(char *buffer, int count)
     {
     time_t timeout;
     int result;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while ((timeout >= time(((void *)0))) && (count > 0))
          {
          result = write(voice_fd, buffer, count);
          if ((result < 0) && ((*__errno_location ()) != 0) && ((*__errno_location ()) != 4) && ((*__errno_location ()) !=
           11))
               {
               lprintf(3, "%s: could not write buffer to voice modem",
                program_name);
               return((-1));
               };
          if (result > 0)
               {
               buffer += result;
               count -= result;
               };
          if (result == 0 || (result < 0 && (*__errno_location ()) == 11))
               delay(cvd.poll_interval.d.i);
          voice_check_events();
          };
     if (count == 0)
          return((0));
     lprintf(3, "%s: timeout while writing buffer to voice modem",
      program_name);
     return((-1));
     }

canonical_original_code:
int voice_write_raw(char *buffer, int count)
     {
     long timeout;
     int result;
     timeout = time(((void *)0)) + cvd.port_timeout.d.i;
     while ((timeout >= time(((void *)0))) && (count > 0))
          {
          result = write(voice_fd, buffer, count);
          if ((result < 0) && ((*__errno_location ()) != 0) && ((*__errno_location ()) != 4) && ((*__errno_location ()) !=
           11))
               {
               lprintf(3, "%s: could not write buffer to voice modem",
                program_name);
               return((-1));
               };
          if (result > 0)
               {
               buffer += result;
               count -= result;
               };
          if (result == 0 || (result < 0 && (*__errno_location ()) == 11))
               delay(cvd.poll_interval.d.i);
          voice_check_events();
          };
     if (count == 0)
          return((0));
     lprintf(3, "%s: timeout while writing buffer to voice modem",
      program_name);
     return((-1));
     }

variable_types:
buffer
char *


decompiled_code:
__int64 voice_write(char *format, ...)
{
int v1; // eax
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-1D8h] BYREF
gcc_va_list arg; // [rsp+108h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(v3, format, arg);
lprintf(6LL, "%s: %s", program_name, v3);
v1 = strlen(v3);
result = voice_write_raw(v3, v1);
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)voice_write_char(13) == -1);
return result;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
int v1; // eax
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-1D8h] BYREF
gcc_va_list arg; // [rsp+108h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(v3, format, arg);
lprintf(6LL, "%s: %s", program_name, v3);
v1 = strlen(v3);
result = func1(v3, v1);
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)func0(13) == -1);
return result;
}

original_code:
int voice_write(const char *format, ...)
     {
     va_list arguments;
     char command[(256)];
     __builtin_va_start(arguments,format);
     vsprintf(command, format, arguments);
     __builtin_va_end(arguments);
     lprintf(6, "%s: %s", program_name, command);
     if (voice_write_raw(command, strlen(command)) == (-1))
          return((-1));
     if (voice_write_char((0x0d)) == (-1))
          return((-1));
     return((0));
     }

canonical_original_code:
int voice_write(char *format, ...)
     {
     __builtin_va_list arguments;
     char command[-1];
     __builtin_va_start(arguments,format);
     vsprintf(command, format, arguments);
     __builtin_va_end(arguments);
     lprintf(6, "%s: %s", program_name, command);
     if (voice_write_raw(command, strlen(command)) == (-1))
          return((-1));
     if (voice_write_char((0x0d)) == (-1))
          return((-1));
     return((0));
     }

variable_types:
format
char *

variable_types:
command
char [-1]


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

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

original_code:
static int ISDN4Linux_beep(int frequency, int length)
     {
     return((0));
     }

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 __fastcall ISDN4Linux_handle_dle(char a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // eax
int v6; // edx

if ( a1 == 3 )
{
lprintf(3LL, "%s: <DLE> <ETX> received", program_name);
voice_stop_current_action();
v5 = voice_command(&unk_914, "OK|VCON|NO CARRIER");
v6 = v5;
if ( v5 <= 4097 )
{
result = (unsigned int)-(v5 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v6 == 4098 )
goto LABEL_5;
}
}
else if ( a1 == 20 )
{
lprintf(3LL, "%s: <DLE> <DC4> received", program_name);
voice_stop_current_action();
v1 = voice_command(&unk_914, "OK|VCON|NO CARRIER");
v2 = v1;
if ( v1 <= 4097 )
{
result = (unsigned int)-(v1 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v2 == 4098 )
{
LABEL_5:
v4 = create_event(8204LL);
queue_event(v4);
return 0LL;
}
}
}
else
{
result = IS_101_handle_dle((unsigned int)a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // eax
int v6; // edx

if ( a1 == 3 )
{
lprintf(3LL, "%s: <DLE> <ETX> received", program_name);
voice_stop_current_action();
v5 = voice_command(&unk_914, "OK|VCON|NO CARRIER");
v6 = v5;
if ( v5 <= 4097 )
{
result = (unsigned int)-(v5 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v6 == 4098 )
goto LABEL_5;
}
}
else if ( a1 == 20 )
{
lprintf(3LL, "%s: <DLE> <DC4> received", program_name);
voice_stop_current_action();
v1 = voice_command(&unk_914, "OK|VCON|NO CARRIER");
v2 = v1;
if ( v1 <= 4097 )
{
result = (unsigned int)-(v1 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v2 == 4098 )
{
LABEL_5:
v4 = create_event(8204LL);
queue_event(v4);
return 0LL;
}
}
}
else
{
result = IS_101_handle_dle((unsigned int)a1);
}
return result;
}

original_code:
int ISDN4Linux_handle_dle(char data)
     {
     switch (data)
        {
        case (0x14):
             lprintf(3, "%s: <DLE> <DC4> received", program_name);
             voice_stop_current_action();
             switch (voice_command("", "OK|VCON|NO CARRIER"))
                  {
                  case (0x1002):
                       queue_event(create_event((0x200c)));
                       break;
                  case (0x1000):
                  case (0x1001):
                       break;
                  default:
                       return (-1);
                  }
             got_DLE_DC4 = (0==0);
             return ((0));
        case (0x03):
             lprintf(3, "%s: <DLE> <ETX> received", program_name);
             voice_stop_current_action();
             switch (voice_command("", "OK|VCON|NO CARRIER"))
                  {
                  case (0x1002):
                       queue_event(create_event((0x200c)));
                       break;
                  case (0x1000):
                  case (0x1001):
                       break;
                  default:
                       return (-1);
                  }
             return ((0));
        default:
             return(IS_101_handle_dle(data));
        }
     }

variable_types: data char


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

is_voicecall = 0;
if ( (unsigned int)voice_command("ATS18=1", "OK") != 4096 )
return 0xFFFFFFFFLL;
result = IS_101_dial(a1);
if ( !(_DWORD)result )
is_voicecall = 1;
return result;
}

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

is_voicecall = 0;
if ( (unsigned int)voice_command("ATS18=1", "OK") != 4096 )
return 0xFFFFFFFFLL;
result = IS_101_dial(a1);
if ( !(_DWORD)result )
is_voicecall = 1;
return result;
}

original_code:
int ISDN4Linux_dial(char *number)
     {
     int result;
     is_voicecall = (0==1);
     if (voice_command("ATS18=1", "OK") != (0x1000))
          return((-1));
     result = IS_101_dial(number);
     if (result == (0))
          is_voicecall = (0==0);
     return(result);
     }

variable_types:
number
char *


decompiled_code:
__int64 __fastcall ISDN4Linux_set_device(unsigned int a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rax
int v4; // eax
int v5; // edx

reset_watchdog();
if ( a1 == 1 )
{
voice_write("AT+VLS=0");
v2 = voice_command(&unk_914, "OK|NO CARRIER|AT+VLS=0");
if ( v2 == 4098 )
v2 = voice_command(&unk_914, "OK|NO CARRIER");
result = 0LL;
if ( v2 != 4096 )
{
result = 0xFFFFFFFFLL;
if ( v2 == 4097 )
goto LABEL_8;
}
}
else
{
if ( a1 != 2 )
{
lprintf(3LL, "ISDN4Linux handle event: Unknown output device (%d)", a1);
return 0xFFFFFFFFLL;
}
v4 = voice_command("AT+VLS=2", "VCON|OK|NO CARRIER");
v5 = v4;
if ( v4 <= 4097 )
{
result = (unsigned int)-(v4 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v5 == 4098 )
{
LABEL_8:
v3 = create_event(8204LL);
queue_event(v3);
return 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rax
int v4; // eax
int v5; // edx

reset_watchdog();
if ( a1 == 1 )
{
voice_write("AT+VLS=0");
v2 = voice_command(&unk_914, "OK|NO CARRIER|AT+VLS=0");
if ( v2 == 4098 )
v2 = voice_command(&unk_914, "OK|NO CARRIER");
result = 0LL;
if ( v2 != 4096 )
{
result = 0xFFFFFFFFLL;
if ( v2 == 4097 )
goto LABEL_8;
}
}
else
{
if ( a1 != 2 )
{
lprintf(3LL, "ISDN4Linux handle event: Unknown output device (%d)", a1);
return 0xFFFFFFFFLL;
}
v4 = voice_command("AT+VLS=2", "VCON|OK|NO CARRIER");
v5 = v4;
if ( v4 <= 4097 )
{
result = (unsigned int)-(v4 <= 4095);
}
else
{
result = 0xFFFFFFFFLL;
if ( v5 == 4098 )
{
LABEL_8:
v3 = create_event(8204LL);
queue_event(v3);
return 0LL;
}
}
}
return result;
}

original_code:
static int ISDN4Linux_set_device(int device)
     {
     int result;
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               voice_write("AT+VLS=0");
               result = voice_command("", "OK|NO CARRIER|AT+VLS=0");
               if (result == (0x1002))
                    result = voice_command("", "OK|NO CARRIER");
               switch(result)
                    {
                    case (0x1001):
                         queue_event(create_event((0x200c)));
                    case (0x1000):
                         return ((0));
                    }
               return((-1));
          case (0x0002):
               switch (voice_command("AT+VLS=2", "VCON|OK|NO CARRIER"))
                    {
                    case (0x1002):
                         queue_event(create_event((0x200c)));
                    case (0x1000):
                    case (0x1001):
                         return((0));
                    }
               return((-1));
          }
     lprintf(3, "ISDN4Linux handle event: Unknown output device (%d)",
      device);
     return((-1));
     }

variable_types: device int


decompiled_code:
__int64 __fastcall ISDN4Linux_set_compression(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdx
__int64 result; // rax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
*a2 = 8000LL;
v4 = *a1;
if ( *a1 == 4 )
{
*a3 = 4;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=4", "OK") != 4096);
}
else
{
if ( *a1 > 4 )
{
if ( (unsigned __int64)(v4 - 5) <= 1 )
{
*a3 = 8;
sprintf(v6, "AT+VSM=%d", *a1);
return (unsigned int)-((unsigned int)voice_command(v6, "OK") != 4096);
}
}
else
{
if ( v4 == 2 )
{
*a3 = 2;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=2", "OK") != 4096);
}
if ( v4 == 3 )
{
*a3 = 3;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=3", "OK") != 4096);
}
}
lprintf(3LL, "ISDN4Linux handle event: Illegal voice compression method (%d)", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdx
__int64 result; // rax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
*a2 = 8000LL;
v4 = *a1;
if ( *a1 == 4 )
{
*a3 = 4;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=4", "OK") != 4096);
}
else
{
if ( *a1 > 4 )
{
if ( (unsigned __int64)(v4 - 5) <= 1 )
{
*a3 = 8;
sprintf(v6, "AT+VSM=%d", *a1);
return (unsigned int)-((unsigned int)voice_command(v6, "OK") != 4096);
}
}
else
{
if ( v4 == 2 )
{
*a3 = 2;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=2", "OK") != 4096);
}
if ( v4 == 3 )
{
*a3 = 3;
return (unsigned int)-((unsigned int)voice_command("AT+VSM=3", "OK") != 4096);
}
}
lprintf(3LL, "ISDN4Linux handle event: Illegal voice compression method (%d)", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int ISDN4Linux_set_compression(p_int *compression, p_int *speed, int *bits)
     {
     char buffer[(256)];
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     *speed = 8000;
     switch (*compression)
          {
          case 2:
               *bits = 2;
               if (voice_command("AT+VSM=2", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 3:
               *bits = 3;
               if (voice_command("AT+VSM=3", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 4:
               *bits = 4;
               if (voice_command("AT+VSM=4", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 5:
          case 6:
               *bits = 8;
               sprintf(buffer,"AT+VSM=%d",(int)*compression);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               return((0));
          }
     lprintf(3,
      "ISDN4Linux handle event: Illegal voice compression method (%d)",
      *compression);
     return((-1));
     }

canonical_original_code:
static int ISDN4Linux_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     *speed = 8000;
     switch (*compression)
          {
          case 2:
               *bits = 2;
               if (voice_command("AT+VSM=2", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 3:
               *bits = 3;
               if (voice_command("AT+VSM=3", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 4:
               *bits = 4;
               if (voice_command("AT+VSM=4", "OK") != (0x1000))
                    return((-1));
               return((0));
          case 5:
          case 6:
               *bits = 8;
               sprintf(buffer,"AT+VSM=%d",(int)*compression);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               return((0));
          }
     lprintf(3,
      "ISDN4Linux handle event: Illegal voice compression method (%d)",
      *compression);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


decompiled_code:
__int64 ISDN4Linux_init()
{
int v0; // eax
unsigned int v1; // ebx
int v2; // eax

voice_modem_state = 2;
lprintf(4LL, "initializing ISDN4Linux voice mode");
reset_watchdog();
if ( (unsigned int)voice_command("ATS18?", &unk_914) )
return (unsigned int)-1;
if ( (unsigned int)voice_read(buffer_0) )
return (unsigned int)-1;
if ( (unsigned int)voice_command(&unk_914, "OK") != 4096 )
return (unsigned int)-1;
v0 = atoi(buffer_0);
sprintf(buffer_0, "ATS18=%u", v0 | 1u);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
return (unsigned int)-1;
if ( (unsigned int)voice_command("ATS13?", &unk_914) )
return (unsigned int)-1;
v1 = voice_read(buffer_0);
if ( v1 )
return (unsigned int)-1;
if ( (unsigned int)voice_command(&unk_914, "OK") != 4096 )
return (unsigned int)-1;
v2 = atoi(buffer_0);
sprintf(buffer_0, "ATS13=%u", v2 | 0x10u);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
return (unsigned int)-1;
voice_modem_state = 1;
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
unsigned int v1; // ebx
int v2; // eax

voice_modem_state = 2;
lprintf(4LL, "initializing ISDN4Linux voice mode");
reset_watchdog();
if ( (unsigned int)voice_command("ATS18?", &unk_914) )
return (unsigned int)-1;
if ( (unsigned int)voice_read(buffer_0) )
return (unsigned int)-1;
if ( (unsigned int)voice_command(&unk_914, "OK") != 4096 )
return (unsigned int)-1;
v0 = atoi(buffer_0);
sprintf(buffer_0, "ATS18=%u", v0 | 1u);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
return (unsigned int)-1;
if ( (unsigned int)voice_command("ATS13?", &unk_914) )
return (unsigned int)-1;
v1 = voice_read(buffer_0);
if ( v1 )
return (unsigned int)-1;
if ( (unsigned int)voice_command(&unk_914, "OK") != 4096 )
return (unsigned int)-1;
v2 = atoi(buffer_0);
sprintf(buffer_0, "ATS13=%u", v2 | 0x10u);
if ( (unsigned int)voice_command(buffer_0, "OK") != 4096 )
return (unsigned int)-1;
voice_modem_state = 1;
return v1;
}

original_code:
static int ISDN4Linux_init(void)
     {
     static char buffer[(256)] = "";
     unsigned reg_content;
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ISDN4Linux voice mode");
     reset_watchdog();
     if (voice_command("ATS18?", "") != (0))
          return((-1));
     if (voice_read(buffer) != (0))
          return((-1));
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     reg_content=atoi(buffer);
     sprintf(buffer, "ATS18=%u", reg_content | 1);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     if (voice_command("ATS13?", "") != (0))
          return((-1));
     if (voice_read(buffer) != (0))
          return((-1));
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     reg_content=atoi(buffer);
     sprintf(buffer, "ATS13=%u", reg_content | (1 << 4));
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int ISDN4Linux_init()
     {
     static char buffer[-1] = "";
     unsigned int reg_content;
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ISDN4Linux voice mode");
     reset_watchdog();
     if (voice_command("ATS18?", "") != (0))
          return((-1));
     if (voice_read(buffer) != (0))
          return((-1));
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     reg_content=atoi(buffer);
     sprintf(buffer, "ATS18=%u", reg_content | 1);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     if (voice_command("ATS13?", "") != (0))
          return((-1));
     if (voice_read(buffer) != (0))
          return((-1));
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     reg_content=atoi(buffer);
     sprintf(buffer, "ATS13=%u", reg_content | (1 << 4));
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 ISDN4Linux_answer_phone()
{
int v0; // edx
__int64 result; // rax

reset_watchdog();
v0 = voice_command("ATS20?", "0|1|2|3|4");
result = 8193LL;
is_voicecall = v0 == 4097;
if ( v0 == 4097 )
result = IS_101_answer_phone();
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx
__int64 result; // rax

reset_watchdog();
v0 = voice_command("ATS20?", "0|1|2|3|4");
result = 8193LL;
is_voicecall = v0 == 4097;
if ( v0 == 4097 )
result = IS_101_answer_phone();
return result;
}

original_code:
static int ISDN4Linux_answer_phone(void)
     {
     int result;
     reset_watchdog();
     result = voice_command("ATS20?", "0|1|2|3|4");
     is_voicecall = (result==(0x1001));
     if (is_voicecall)
          return(IS_101_answer_phone());
     return((0x2001));
     }

canonical_original_code:
static int ISDN4Linux_answer_phone()
     {
     int result;
     reset_watchdog();
     result = voice_command("ATS20?", "0|1|2|3|4");
     is_voicecall = (result==(0x1001));
     if (is_voicecall)
          return(IS_101_answer_phone());
     return((0x2001));
     }


decompiled_code:
__int64 ISDN4Linux_start_play_file()
{
__int64 v1; // rax

voice_modem_state = 5;
if ( is_voicecall )
return IS_101_start_play_file();
v1 = create_event(8196LL);
return queue_event(v1);
}

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

voice_modem_state = 5;
if ( is_voicecall )
return IS_101_start_play_file();
v1 = create_event(8196LL);
return queue_event(v1);
}

original_code:
int ISDN4Linux_start_play_file(void)
     {
     voice_modem_state = (0x0005);
     if (!is_voicecall)
          return(queue_event(create_event((0x2004))));
     return(IS_101_start_play_file());
     }

canonical_original_code:
int ISDN4Linux_start_play_file()
     {
     voice_modem_state = (0x0005);
     if (!is_voicecall)
          return(queue_event(create_event((0x2004))));
     return(IS_101_start_play_file());
     }


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

reset_watchdog();
if ( a1 == 4 )
{
voice_command("AT+VLS=14", &unk_5E9);
result = 0LL;
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
{
voice_command("AT+VLS=4", &unk_5E9);
return 0LL;
}
}
else
{
if ( a1 == 1 )
{
voice_command("AT+VLS=0", &unk_5E9);
return 0LL;
}
if ( a1 == 2 )
{
voice_command("AT+VLS=2", &unk_5E9);
return 0LL;
}
}
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

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

reset_watchdog();
if ( a1 == 4 )
{
voice_command("AT+VLS=14", &unk_5E9);
result = 0LL;
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
{
voice_command("AT+VLS=4", &unk_5E9);
return 0LL;
}
}
else
{
if ( a1 == 1 )
{
voice_command("AT+VLS=0", &unk_5E9);
return 0LL;
}
if ( a1 == 2 )
{
voice_command("AT+VLS=2", &unk_5E9);
return 0LL;
}
}
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

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

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


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

reset_watchdog();
if ( !*a1 )
*a1 = 129LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 8000 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 8000LL;
}
v5 = *a1;
if ( *a1 == 129 )
{
*a3 = 2;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=129", &unk_5E9) != 4096);
}
else if ( v5 == 130 )
{
*a3 = 3;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=130", &unk_5E9) != 4096);
}
else if ( v5 == 128 )
{
*a3 = 8;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=128", &unk_5E9) != 4096);
}
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 = 129LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 8000 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 8000LL;
}
v5 = *a1;
if ( *a1 == 129 )
{
*a3 = 2;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=129", &unk_5E9) != 4096);
}
else if ( v5 == 130 )
{
*a3 = 3;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=130", &unk_5E9) != 4096);
}
else if ( v5 == 128 )
{
*a3 = 8;
result = (unsigned int)-((unsigned int)voice_command("AT+VSM=128", &unk_5E9) != 4096);
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Dr_Neuhaus_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 129;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          };
     switch (*compression)
          {
          case 128:
               *bits = 8;
               if (voice_command("AT+VSM=128", "OK") != (0x1000))
                    return((-1));
               break;
          case 129:
               *bits = 2;
               if (voice_command("AT+VSM=129", "OK") != (0x1000))
                    return((-1));
               break;
          case 130:
               *bits = 3;
               if (voice_command("AT+VSM=130", "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, *compression);
               return((-1));
          };
     return((0));
     }

canonical_original_code:
static int Dr_Neuhaus_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 129;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          };
     switch (*compression)
          {
          case 128:
               *bits = 8;
               if (voice_command("AT+VSM=128", "OK") != (0x1000))
                    return((-1));
               break;
          case 129:
               *bits = 2;
               if (voice_command("AT+VSM=129", "OK") != (0x1000))
                    return((-1));
               break;
          case 130:
               *bits = 3;
               if (voice_command("AT+VSM=130", "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, *compression);
               return((-1));
          };
     return((0));
     }


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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Dr. Neuhaus voice modem");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)*((_QWORD *)&cvd + 58) / 10 + 123), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 100LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)*((_QWORD *)&cvd + 82) / 10 + 123));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 40LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)*((_QWORD *)&cvd + 79) / 10 + 123));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VIT=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't deactivate inactivity timer");
if ( (unsigned int)voice_command("AT+VPR=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't select autobauding");
if ( (unsigned int)voice_command("AT+VLS=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't deselect all input/output devices");
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 Dr. Neuhaus voice modem");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)*((_QWORD *)&cvd + 58) / 10 + 123), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 100LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)*((_QWORD *)&cvd + 82) / 10 + 123));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 40LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)*((_QWORD *)&cvd + 79) / 10 + 123));
if ( (unsigned int)voice_command(v1, &unk_5E9) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VIT=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't deactivate inactivity timer");
if ( (unsigned int)voice_command("AT+VPR=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't select autobauding");
if ( (unsigned int)voice_command("AT+VLS=0", &unk_5E9) != 4096 )
lprintf(3LL, "can't deselect all input/output devices");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Dr_Neuhaus_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Dr. Neuhaus voice modem");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      10 / 100 + 123, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 100;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 10 / 100 + 123);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 40;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 10 / 100 + 123);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VIT=0", "OK") != (0x1000))
          lprintf(3, "can't deactivate inactivity timer");
     if (voice_command("AT+VPR=0", "OK") != (0x1000))
          lprintf(3, "can't select autobauding");
     if (voice_command("AT+VLS=0", "OK") != (0x1000))
          lprintf(3, "can't deselect all input/output devices");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Dr_Neuhaus_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Dr. Neuhaus voice modem");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      10 / 100 + 123, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 100;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 10 / 100 + 123);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 40;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 10 / 100 + 123);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VIT=0", "OK") != (0x1000))
          lprintf(3, "can't deactivate inactivity timer");
     if (voice_command("AT+VPR=0", "OK") != (0x1000))
          lprintf(3, "can't select autobauding");
     if (voice_command("AT+VLS=0", "OK") != (0x1000))
          lprintf(3, "can't deselect all input/output devices");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 Cirrus_Logic_answer_phone()
{
int v0; // edx
__int64 result; // rax
bool v2; // zf

reset_watchdog();
lprintf(4LL, "Answering Call");
v0 = voice_command("AT#VLN=1", "OK");
result = 8195LL;
if ( v0 == 4096 )
{
v2 = (unsigned int)voice_command("AT#VIP=1", "OK") == 4096;
result = 8202LL;
if ( !v2 )
result = 8195LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 result; // rax
bool v2; // zf

reset_watchdog();
lprintf(4LL, "Answering Call");
v0 = voice_command("AT#VLN=1", "OK");
result = 8195LL;
if ( v0 == 4096 )
{
v2 = (unsigned int)voice_command("AT#VIP=1", "OK") == 4096;
result = 8202LL;
if ( !v2 )
result = 8195LL;
}
return result;
}

original_code:
int Cirrus_Logic_answer_phone (void)
     {
     reset_watchdog();
     lprintf(4, "Answering Call");
     if (voice_command("AT#VLN=1", "OK") != (0x1000))
          return((0x2003));
     if (voice_command("AT#VIP=1", "OK") != (0x1000))
          return((0x2003));
     return((0x200a));
     }

canonical_original_code:
int Cirrus_Logic_answer_phone()
     {
     reset_watchdog();
     lprintf(4, "Answering Call");
     if (voice_command("AT#VLN=1", "OK") != (0x1000))
          return((0x2003));
     if (voice_command("AT#VIP=1", "OK") != (0x1000))
          return((0x2003));
     return((0x200a));
     }


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

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

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

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

original_code:
int Cirrus_Logic_set_device (int device)
     {
     reset_watchdog();
     lprintf(4, "Setting device");
     switch (device)
          {
          case (0x0001):
               voice_command("AT#VLN=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT#VLN=1", "OK");
               return((0));
          case (0x0003):
               voice_command("AT#VLN=32", "OK");
               return((0));
          case (0x0006):
               voice_command("AT#VLN=16", "OK");
               return((0));
          case (0x0007):
               voice_command("AT#VLN=2","OK");
               return((0));
          }
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

canonical_original_code:
int Cirrus_Logic_set_device(int device)
     {
     reset_watchdog();
     lprintf(4, "Setting device");
     switch (device)
          {
          case (0x0001):
               voice_command("AT#VLN=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT#VLN=1", "OK");
               return((0));
          case (0x0003):
               voice_command("AT#VLN=32", "OK");
               return((0));
          case (0x0006):
               voice_command("AT#VLN=16", "OK");
               return((0));
          case (0x0007):
               voice_command("AT#VLN=2","OK");
               return((0));
          }
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }


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

lprintf(4LL, "Setting compression");
reset_watchdog();
if ( !*a1 )
*a1 = 1LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 )
{
lprintf(3LL, "%s: Illegal sample speed (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
}
voice_command("AT#VSR=9600", "OK");
if ( *a1 == 3LL )
{
voice_command("AT#VSM=AD3", "OK");
*a3 = 3;
result = 0LL;
}
else
{
if ( *a1 == 4LL )
{
voice_command("AT#VSM=AD4", "OK");
*a3 = 4;
}
else
{
voice_command("AT#VSM=CL1", "OK");
*a3 = 5;
}
result = 0LL;
}
return result;
}

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

lprintf(4LL, "Setting compression");
reset_watchdog();
if ( !*a1 )
*a1 = 1LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 )
{
lprintf(3LL, "%s: Illegal sample speed (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
}
voice_command("AT#VSR=9600", "OK");
if ( *a1 == 3LL )
{
voice_command("AT#VSM=AD3", "OK");
*a3 = 3;
result = 0LL;
}
else
{
if ( *a1 == 4LL )
{
voice_command("AT#VSM=AD4", "OK");
*a3 = 4;
}
else
{
voice_command("AT#VSM=CL1", "OK");
*a3 = 5;
}
result = 0LL;
}
return result;
}

original_code:
static int Cirrus_Logic_set_compression (p_int *compression, p_int *speed,
 int *bits)
     {
     lprintf(4, "Setting compression");
     reset_watchdog();
     if (*compression == 0)
          *compression = 1;
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, *speed);
          return((-1));
          }
     voice_command("AT#VSR=9600", "OK");
     switch (*compression)
          {
          case 3:
               voice_command("AT#VSM=AD3", "OK");
               *bits = 3;
               return((0));
          case 4:
               voice_command("AT#VSM=AD4", "OK");
               *bits = 4;
               return((0));
          default:
               voice_command("AT#VSM=CL1", "OK");
               *bits = 5;
               return((0));
          }
     return((0));
     }

canonical_original_code:
static int Cirrus_Logic_set_compression(long *compression, long *speed, int *bits)
     {
     lprintf(4, "Setting compression");
     reset_watchdog();
     if (*compression == 0)
          *compression = 1;
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, *speed);
          return((-1));
          }
     voice_command("AT#VSR=9600", "OK");
     switch (*compression)
          {
          case 3:
               voice_command("AT#VSM=AD3", "OK");
               *bits = 3;
               return((0));
          case 4:
               voice_command("AT#VSM=AD4", "OK");
               *bits = 4;
               return((0));
          default:
               voice_command("AT#VSM=CL1", "OK");
               *bits = 5;
               return((0));
          }
     return((0));
     }


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

lprintf(4LL, "Switching to data/fax");
reset_watchdog();
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

lprintf(4LL, "Switching to data/fax");
reset_watchdog();
sprintf(v2, "AT+FCLASS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

original_code:
int Cirrus_Logic_switch_to_data_fax (char *mode)
     {
     char buffer[(256)];
     lprintf(4, "Switching to data/fax");
     reset_watchdog();
     sprintf(buffer, "AT+FCLASS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int Cirrus_Logic_switch_to_data_fax(char *mode)
     {
     char buffer[-1];
     lprintf(4, "Switching to data/fax");
     reset_watchdog();
     sprintf(buffer, "AT+FCLASS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types:
mode
char *


decompiled_code:
__int64 Cirrus_Logic_beep()
{
__int64 v0; // rbx
__int64 v1; // rdx
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
strcpy(v3, "AT#VBP");
lprintf(4LL, "Checking Beep");
if ( (unsigned int)voice_command(v3, &unk_B89) )
return 0xFFFFFFFFLL;
LODWORD(v0) = 0;
while ( !(unsigned __int8)check_for_input(voice_fd) )
{
if ( (int)v0 <= 0 )
{
reset_watchdog();
v1 = 1000LL * *((_QWORD *)&cvd + 76) % *((_QWORD *)&cvd + 88);
v0 = 1000LL * *((_QWORD *)&cvd + 76) / *((_QWORD *)&cvd + 88) / 2;
}
else
{
LODWORD(v0) = v0 - 1;
}
delay(*((unsigned int *)&cvd + 176), &unk_B89, v1);
}
return (unsigned int)-((unsigned int)voice_command(&unk_B89, "OK") != 4096);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
__int64 v1; // rdx
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
strcpy(v3, "AT#VBP");
lprintf(4LL, "Checking Beep");
if ( (unsigned int)voice_command(v3, &unk_B89) )
return 0xFFFFFFFFLL;
LODWORD(v0) = 0;
while ( !(unsigned __int8)check_for_input(voice_fd) )
{
if ( (int)v0 <= 0 )
{
reset_watchdog();
v1 = 1000LL * *((_QWORD *)&cvd + 76) % *((_QWORD *)&cvd + 88);
v0 = 1000LL * *((_QWORD *)&cvd + 76) / *((_QWORD *)&cvd + 88) / 2;
}
else
{
LODWORD(v0) = v0 - 1;
}
delay(*((unsigned int *)&cvd + 176), &unk_B89, v1);
}
return (unsigned int)-((unsigned int)voice_command(&unk_B89, "OK") != 4096);
}

original_code:
int Cirrus_Logic_beep (int frequency, int length)
     {
     char buffer[(256)];
     int watchdog_count = 0;
     reset_watchdog();
     sprintf(buffer, "AT#VBP");
     lprintf(4, "Checking Beep");
     if (voice_command(buffer, "") != (0))
          return((-1));
     while (!check_for_input(voice_fd))
          {
          if ((watchdog_count--) <= 0)
               {
               reset_watchdog();
               watchdog_count = cvd.watchdog_timeout.d.i * 1000 /
                cvd.poll_interval.d.i / 2;
               }
          delay(cvd.poll_interval.d.i);
          }
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int Cirrus_Logic_beep(int frequency, int length)
     {
     char buffer[-1];
     int watchdog_count = 0;
     reset_watchdog();
     sprintf(buffer, "AT#VBP");
     lprintf(4, "Checking Beep");
     if (voice_command(buffer, "") != (0))
          return((-1));
     while (!check_for_input(voice_fd))
          {
          if ((watchdog_count--) <= 0)
               {
               reset_watchdog();
               watchdog_count = cvd.watchdog_timeout.d.i * 1000 /
                cvd.poll_interval.d.i / 2;
               }
          delay(cvd.poll_interval.d.i);
          }
     if (voice_command("", "OK") != (0x1000))
          return((-1));
     return((0));
     }


decompiled_code:
__int64 Cirrus_Logic_init()
{
__int64 result; // rax
_BYTE v1[72]; // [rsp+0h] [rbp-168h] BYREF
int v2; // [rsp+48h] [rbp-120h] BYREF
int v3; // [rsp+4Ch] [rbp-11Ch]
int v4; // [rsp+50h] [rbp-118h] BYREF
int v5; // [rsp+54h] [rbp-114h]
int v6; // [rsp+58h] [rbp-110h] BYREF
int v7; // [rsp+5Ch] [rbp-10Ch]
char s[264]; // [rsp+60h] [rbp-108h] BYREF

v6 = 0;
v7 = 0;
v4 = 0;
v5 = 0;
v2 = 0;
v3 = 0;
reset_watchdog();
lprintf(4LL, "Initializing Cirrus Logic voice modem");
voice_modem_state = 2;
voice_command("AT#VRL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
get_range((__int64)&cirrus_logic_ans, (__int64)&v4);
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = (v5 + v4) / 2;
sprintf(s, "AT#VRL=%.0f", (double)(int)(*((_QWORD *)&cvd + 79) * (v5 - v4)) / 100.0 + (double)v4);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set recording volume");
voice_command("AT#VPL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
get_range((__int64)&cirrus_logic_ans, (__int64)&v6);
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = (v7 + v6) / 2;
sprintf(s, "AT#VPL=%.0f", (double)(int)(*((_QWORD *)&cvd + 82) * (v7 - v6)) / 100.0 + (double)v6);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set play volume");
if ( *((_QWORD *)&cvd + 58) > 0x64uLL )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
voice_command("AT#VSL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
get_range((__int64)&cirrus_logic_ans, (__int64)&v2);
sprintf(s, "AT#VSL=%.0f", (double)(int)(*((_QWORD *)&cvd + 58) * (v3 - v2)) / 100.0 + (double)v2);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
sprintf(s, "AT#VSQT=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period record mode");
sprintf(s, "AT#VSST=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period record and command mode");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
_BYTE v1[72]; // [rsp+0h] [rbp-168h] BYREF
int v2; // [rsp+48h] [rbp-120h] BYREF
int v3; // [rsp+4Ch] [rbp-11Ch]
int v4; // [rsp+50h] [rbp-118h] BYREF
int v5; // [rsp+54h] [rbp-114h]
int v6; // [rsp+58h] [rbp-110h] BYREF
int v7; // [rsp+5Ch] [rbp-10Ch]
char s[264]; // [rsp+60h] [rbp-108h] BYREF

v6 = 0;
v7 = 0;
v4 = 0;
v5 = 0;
v2 = 0;
v3 = 0;
reset_watchdog();
lprintf(4LL, "Initializing Cirrus Logic voice modem");
voice_modem_state = 2;
voice_command("AT#VRL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
func5((__int64)&cirrus_logic_ans, (__int64)&v4);
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = (v5 + v4) / 2;
sprintf(s, "AT#VRL=%.0f", (double)(int)(*((_QWORD *)&cvd + 79) * (v5 - v4)) / 100.0 + (double)v4);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set recording volume");
voice_command("AT#VPL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
func5((__int64)&cirrus_logic_ans, (__int64)&v6);
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = (v7 + v6) / 2;
sprintf(s, "AT#VPL=%.0f", (double)(int)(*((_QWORD *)&cvd + 82) * (v7 - v6)) / 100.0 + (double)v6);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set play volume");
if ( *((_QWORD *)&cvd + 58) > 0x64uLL )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
voice_command("AT#VSL=?", &unk_B89);
voice_read(&cirrus_logic_ans);
voice_flush(1LL);
func5((__int64)&cirrus_logic_ans, (__int64)&v2);
sprintf(s, "AT#VSL=%.0f", (double)(int)(*((_QWORD *)&cvd + 58) * (v3 - v2)) / 100.0 + (double)v2);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
sprintf(s, "AT#VSQT=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period record mode");
sprintf(s, "AT#VSST=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period record and command mode");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v1);
tio_set_flow_control(voice_fd, v1, 1LL);
tio_set(voice_fd, v1);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

original_code:
int Cirrus_Logic_init (void)
     {
     char buffer[(256)];
     range play_range = {0, 0};
     range rec_range = {0, 0};
     range rec_silence_threshold = {0, 0};
     reset_watchdog();
     lprintf(4, "Initializing Cirrus Logic voice modem");
     voice_modem_state = (0x0002);
     voice_command("AT#VRL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &rec_range);
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = (rec_range.max + rec_range.min) / 2;
     sprintf(buffer, "AT#VRL=%.0f", rec_range.min + ((rec_range.max -
      rec_range.min) * cvd.receive_gain.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set recording volume");
     voice_command("AT#VPL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &play_range);
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = (play_range.max + play_range.min) / 2;
     sprintf(buffer, "AT#VPL=%.0f", play_range.min + ((play_range.max -
      play_range.min) * cvd.transmit_gain.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set play volume");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
        (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     voice_command("AT#VSL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &rec_silence_threshold);
     sprintf(buffer, "AT#VSL=%.0f", rec_silence_threshold.min +
      ((rec_silence_threshold.max - rec_silence_threshold.min) *
      cvd.rec_silence_threshold.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     sprintf(buffer, "AT#VSQT=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period record mode");
     sprintf(buffer, "AT#VSST=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period record and command mode");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          TIO tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
int Cirrus_Logic_init()
     {
     char buffer[-1];
     struct range play_range = {0, 0};
     struct range rec_range = {0, 0};
     struct range rec_silence_threshold = {0, 0};
     reset_watchdog();
     lprintf(4, "Initializing Cirrus Logic voice modem");
     voice_modem_state = (0x0002);
     voice_command("AT#VRL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &rec_range);
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = (rec_range.max + rec_range.min) / 2;
     sprintf(buffer, "AT#VRL=%.0f", rec_range.min + ((rec_range.max -
      rec_range.min) * cvd.receive_gain.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set recording volume");
     voice_command("AT#VPL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &play_range);
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = (play_range.max + play_range.min) / 2;
     sprintf(buffer, "AT#VPL=%.0f", play_range.min + ((play_range.max -
      play_range.min) * cvd.transmit_gain.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set play volume");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
        (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     voice_command("AT#VSL=?", "");
     voice_read(cirrus_logic_ans);
     voice_flush(1);
     get_range(cirrus_logic_ans, &rec_silence_threshold);
     sprintf(buffer, "AT#VSL=%.0f", rec_silence_threshold.min +
      ((rec_silence_threshold.max - rec_silence_threshold.min) *
      cvd.rec_silence_threshold.d.i / 100.0));
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     sprintf(buffer, "AT#VSQT=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period record mode");
     sprintf(buffer, "AT#VSST=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period record and command mode");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          struct termios tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

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


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

if ( (unsigned int)IS_101_switch_to_data_fax() )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-((unsigned int)voice_command("AT+FCLASS=2", &unk_868) != 4096);
return result;
}

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

if ( (unsigned int)IS_101_switch_to_data_fax() )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-((unsigned int)voice_command("AT+FCLASS=2", &unk_868) != 4096);
return result;
}

original_code:
static int Supra_switch_to_data_fax(char *mode)
     {
     if (IS_101_switch_to_data_fax(mode) != (0))
        return((-1));
     if (voice_command("AT+FCLASS=2", "OK") != (0x1000))
        return((-1));
     return((0));
     }


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

reset_watchdog();
if ( a1 == 4 )
{
lprintf(6LL, "%s: _INT_MIC: (%d)", (const char *)*voice_modem, 4LL);
voice_command("AT#VLS=9", "VCON");
result = 0LL;
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
{
lprintf(6LL, "%s: _INT_SEAK: (%d)", (const char *)*voice_modem, 6LL);
voice_command("AT#VLS=3", "VCON");
return 0LL;
}
}
else
{
if ( a1 == 1 )
{
lprintf(6LL, "%s: _NO_DEV: (%d)", (const char *)*voice_modem, 1LL);
voice_command("AT#VLS=0", &unk_868);
return 0LL;
}
if ( a1 == 2 )
{
lprintf(6LL, "%s: _DIALUP: (%d)", (const char *)*voice_modem, 2LL);
voice_command("AT#VLS=4", &unk_868);
return 0LL;
}
}
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

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

reset_watchdog();
if ( a1 == 4 )
{
lprintf(6LL, "%s: _INT_MIC: (%d)", (const char *)*voice_modem, 4LL);
voice_command("AT#VLS=9", "VCON");
result = 0LL;
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
{
lprintf(6LL, "%s: _INT_SEAK: (%d)", (const char *)*voice_modem, 6LL);
voice_command("AT#VLS=3", "VCON");
return 0LL;
}
}
else
{
if ( a1 == 1 )
{
lprintf(6LL, "%s: _NO_DEV: (%d)", (const char *)*voice_modem, 1LL);
voice_command("AT#VLS=0", &unk_868);
return 0LL;
}
if ( a1 == 2 )
{
lprintf(6LL, "%s: _DIALUP: (%d)", (const char *)*voice_modem, 2LL);
voice_command("AT#VLS=4", &unk_868);
return 0LL;
}
}
lprintf(3LL, "%s: Unknown device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Supra_set_device (int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               lprintf(6, "%s: _NO_DEV: (%d)", voice_modem->name, device);
               voice_command("AT#VLS=0", "OK");
               return((0));
          case (0x0002):
               lprintf(6, "%s: _DIALUP: (%d)", voice_modem->name, device);
               voice_command("AT#VLS=4", "OK");
        return((0));
          case (0x0004):
        lprintf(6, "%s: _INT_MIC: (%d)", voice_modem->name, device);
        voice_command("AT#VLS=9", "VCON");
        return((0));
          case (0x0006):
               lprintf(6, "%s: _INT_SEAK: (%d)", voice_modem->name, device);
        voice_command("AT#VLS=3", "VCON");
               return((0));
          }
     lprintf(3, "%s: Unknown device (%d)", voice_modem->name, device);
     return((-1));
     }

canonical_original_code:
static int Supra_set_device(int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               lprintf(6, "%s: _NO_DEV: (%d)", voice_modem->name, device);
               voice_command("AT#VLS=0", "OK");
               return((0));
          case (0x0002):
               lprintf(6, "%s: _DIALUP: (%d)", voice_modem->name, device);
               voice_command("AT#VLS=4", "OK");
        return((0));
          case (0x0004):
        lprintf(6, "%s: _INT_MIC: (%d)", voice_modem->name, device);
        voice_command("AT#VLS=9", "VCON");
        return((0));
          case (0x0006):
               lprintf(6, "%s: _INT_SEAK: (%d)", voice_modem->name, device);
        voice_command("AT#VLS=3", "VCON");
               return((0));
          }
     lprintf(3, "%s: Unknown device (%d)", voice_modem->name, device);
     return((-1));
     }


decompiled_code:
__int64 __fastcall Supra_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 && v4 != 11025 )
{
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", &unk_868);
*a3 = 2;
result = 0LL;
}
else if ( v5 == 3 )
{
voice_command("AT#VBS=3", &unk_868);
*a3 = 3;
result = 0LL;
}
else if ( v5 == 4 )
{
voice_command("AT#VBS=4", &unk_868);
*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 func2(__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 && v4 != 11025 )
{
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", &unk_868);
*a3 = 2;
result = 0LL;
}
else if ( v5 == 3 )
{
voice_command("AT#VBS=3", &unk_868);
*a3 = 3;
result = 0LL;
}
else if ( v5 == 4 )
{
voice_command("AT#VBS=4", &unk_868);
*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 Supra_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 && *speed != 11025)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, (int)*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, (int)*compression);
     return((-1));
     }

canonical_original_code:
static int Supra_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 7200;
     if (*speed != 7200 && *speed != 11025)
          {
          lprintf(3, "%s: Illegal sample speed (%d)",
           voice_modem->name, (int)*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, (int)*compression);
     return((-1));
     }