makelock

decompiled_code:
__int64 __fastcall makelock(char *a1)
{
lprintf(5LL, "makelock(%s) called", a1);
if ( get_lock_name(lock, a1) )
return do_makelock();
lprintf(1LL, "cannot get lock name");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
lprintf(5LL, "makelock(%s) called", a1);
if ( func2(lock, a1) )
return func3();
lprintf(1LL, "cannot get lock name");
return 0xFFFFFFFFLL;
}

original_code:
int makelock (char *device)
{
    lprintf(5, "makelock(%s) called", device);
    if ( get_lock_name( lock, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return -1;
    }
    return do_makelock();
}

canonical_original_code:
int makelock(char *device)
{
    lprintf(5, "makelock(%s) called", device);
    if ( get_lock_name( lock, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return -1;
    }
    return do_makelock();
}


repo: Distrotech/mgetty

decompiled_code:
__int64 __fastcall steal_lock(char *a1, unsigned int a2)
{
unsigned int v2; // eax
int v3; // edi
__int64 result; // rax

lprintf(5LL, "steal_lock(%s) called", a1);
if ( get_lock_name(lock, a1) )
{
v2 = readlock(lock);
if ( v2 == a2 )
{
v3 = open(lock, 2);
if ( v3 < 0 )
{
lprintf(1LL, "can't open %s for read/write", lock);
result = 0xFFFFFFFFLL;
}
else
{
result = lock_write_pid(v3);
if ( !(_DWORD)result )
we_have_lock = 1;
}
}
else
{
lprintf(1LL, "PIDs do not match, lock process is %d, should be %d", v2, a2);
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(1LL, "cannot get lock name");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, unsigned int a2)
{
unsigned int v2; // eax
int v3; // edi
__int64 result; // rax

lprintf(5LL, "steal_lock(%s) called", a1);
if ( func2(lock, a1) )
{
v2 = func1(lock);
if ( v2 == a2 )
{
v3 = open(lock, 2);
if ( v3 < 0 )
{
lprintf(1LL, "can't open %s for read/write", lock);
result = 0xFFFFFFFFLL;
}
else
{
result = func0(v3);
if ( !(_DWORD)result )
we_have_lock = 1;
}
}
else
{
lprintf(1LL, "PIDs do not match, lock process is %d, should be %d", v2, a2);
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(1LL, "cannot get lock name");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int steal_lock (char * device,int pid)
{
    int retcode, is_pid, fd;
    lprintf(5, "steal_lock(%s) called", device);
    if ( get_lock_name( lock, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return -1;
    }
    is_pid = readlock(lock);
    if ( is_pid != pid )
    {
 lprintf( 1, "PIDs do not match, lock process is %d, should be %d", is_pid, pid );
 return -1;
    }
    fd = open( lock, 02 );
    if ( fd < 0 )
    {
 lprintf( 1, "can't open %s for read/write", lock );
 return -1;
    }
    retcode = lock_write_pid( fd );
    if ( retcode == 0 ) we_have_lock = (1==1);
    return retcode;
}

canonical_original_code:
int steal_lock(char *device, int pid)
{
    int retcode; int is_pid; int fd;
    lprintf(5, "steal_lock(%s) called", device);
    if ( get_lock_name( lock, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return -1;
    }
    is_pid = readlock(lock);
    if ( is_pid != pid )
    {
 lprintf( 1, "PIDs do not match, lock process is %d, should be %d", is_pid, pid );
 return -1;
    }
    fd = open( lock, 02 );
    if ( fd < 0 )
    {
 lprintf( 1, "can't open %s for read/write", lock );
 return -1;
    }
    retcode = lock_write_pid( fd );
    if ( retcode == 0 ) we_have_lock = (1==1);
    return retcode;
}

variable_types:
device
char *

variable_types: pid int

variable_types: retcode int

variable_types: fd int

return_type: int


decompiled_code:
__int64 __fastcall makelock_file(char *src)
{
lprintf(5LL, "makelock_file(%s) called", src);
strcpy(lock, src);
return do_makelock();
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
lprintf(5LL, "makelock_file(%s) called", src);
strcpy(lock, src);
return func3();
}

original_code:
int makelock_file (char * file)
{
    lprintf(5, "makelock_file(%s) called", file);
    strcpy( lock, file );
    return do_makelock();
}

canonical_original_code:
int makelock_file(char *file)
{
    lprintf(5, "makelock_file(%s) called", file);
    strcpy( lock, file );
    return do_makelock();
}

variable_types:
file
char *


checklock

decompiled_code:
__int64 __fastcall checklock(char *a1)
{
unsigned int v1; // ebx
char v3[1040]; // [rsp+0h] [rbp-4A8h] BYREF
struct stat v4; // [rsp+410h] [rbp-98h] BYREF

if ( get_lock_name(v3, a1) )
{
if ( stat(v3, &v4) == -1 && *_errno_location() == 2 )
{
lprintf(5LL, "checklock: stat failed, no file");
v1 = 0;
}
else
{
v1 = readlock(v3);
if ( v1 == -1 )
{
lprintf(4LL, "checklock: couldn't read lockfile");
v1 = 0;
}
else if ( getpid() == v1 )
{
lprintf(3LL, "huh? It's *our* lock file!");
v1 = 0;
}
else if ( kill(v1, 0) == -1 && *_errno_location() == 3 )
{
lprintf(5LL, "checklock: no active process has lock, will remove");
unlink(v3);
v1 = 0;
}
else
{
lprintf(5LL, "lockfile found, pid=%d", v1);
}
}
}
else
{
lprintf(1LL, "cannot get lock name");
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
unsigned int v1; // ebx
char v3[1040]; // [rsp+0h] [rbp-4A8h] BYREF
struct stat v4; // [rsp+410h] [rbp-98h] BYREF

if ( func2(v3, a1) )
{
if ( stat(v3, &v4) == -1 && *_errno_location() == 2 )
{
lprintf(5LL, "checklock: stat failed, no file");
v1 = 0;
}
else
{
v1 = func1(v3);
if ( v1 == -1 )
{
lprintf(4LL, "checklock: couldn't read lockfile");
v1 = 0;
}
else if ( getpid() == v1 )
{
lprintf(3LL, "huh? It's *our* lock file!");
v1 = 0;
}
else if ( kill(v1, 0) == -1 && *_errno_location() == 3 )
{
lprintf(5LL, "checklock: no active process has lock, will remove");
unlink(v3);
v1 = 0;
}
else
{
lprintf(5LL, "lockfile found, pid=%d", v1);
}
}
}
else
{
lprintf(1LL, "cannot get lock name");
v1 = 0;
}
return v1;
}

original_code:
int checklock (char * device)
{
    int pid;
    struct stat st;
    char name[1024 +1];
    if ( get_lock_name( name, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return 0;
    }
    if ((stat(name, &st) == -1) && (*__errno_location ()) == 2)
    {
 lprintf(5, "checklock: stat failed, no file");
 return 0;
    }
    if ((pid = readlock(name)) == -1)
    {
 lprintf(4, "checklock: couldn't read lockfile");
 return 0;
    }
    if (pid == getpid())
    {
 lprintf(3, "huh? It's *our* lock file!" );
 return 0;
    }
    if ((kill(pid, 0) == -1) && (*__errno_location ()) == 3)
    {
 lprintf(5, "checklock: no active process has lock, will remove");
 (void) unlink(name);
 return 0;
    }
    lprintf(5, "lockfile found, pid=%d", pid );
    return pid;
}

canonical_original_code:
int checklock(char *device)
{
    int pid;
    struct stat st;
    char name[-1];
    if ( get_lock_name( name, device ) == ((void *)0) )
    {
 lprintf( 1, "cannot get lock name" );
 return 0;
    }
    if ((stat(name, &st) == -1) && (*__errno_location ()) == 2)
    {
 lprintf(5, "checklock: stat failed, no file");
 return 0;
    }
    if ((pid = readlock(name)) == -1)
    {
 lprintf(4, "checklock: couldn't read lockfile");
 return 0;
    }
    if (pid == getpid())
    {
 lprintf(3, "huh? It's *our* lock file!" );
 return 0;
    }
    if ((kill(pid, 0) == -1) && (*__errno_location ()) == 3)
    {
 lprintf(5, "checklock: no active process has lock, will remove");
 (void) unlink(name);
 return 0;
    }
    lprintf(5, "lockfile found, pid=%d", pid );
    return pid;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
name
char [-1]

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


rmlocks

decompiled_code:
void rmlocks()
{
if ( we_have_lock )
{
lprintf(5LL, "removing lock file");
if ( unlink(lock) == -1 )
lprintf(1LL, "error removing lock file (huh?!)");
we_have_lock = 0;
}
else
{
we_have_lock = 0;
}
}

canonical_decompiled_code:
void func8()
{
if ( we_have_lock )
{
lprintf(5LL, "removing lock file");
if ( unlink(lock) == -1 )
lprintf(1LL, "error removing lock file (huh?!)");
we_have_lock = 0;
}
else
{
we_have_lock = 0;
}
}

original_code:
void rmlocks (void)
{
    if ( we_have_lock )
    {
 lprintf( 5, "removing lock file" );
 if ( unlink(lock) == -1 )
     lprintf( 1, "error removing lock file (huh?!)" );
    }
    we_have_lock = (1==0);
}

canonical_original_code:
void rmlocks()
{
    if ( we_have_lock )
    {
 lprintf( 5, "removing lock file" );
 if ( unlink(lock) == -1 )
     lprintf( 1, "error removing lock file (huh?!)" );
    }
    we_have_lock = (1==0);
}

return_type: void


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

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

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

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

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

variable_types: device int


decompiled_code:
__int64 __fastcall Multitech_2834_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx
__int64 result; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 4LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 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
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 4LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Multitech_2834_set_compression(p_int *compression, p_int *speed,
 int *bits)
     {
     char buffer[(256)];
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "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 Multitech_2834_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, *compression);
               return((-1));
          }
     return((0));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Multitech 2834 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8C0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Multitech 2834 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8C0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Multitech_2834_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Multitech 2834 voice modem");
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Multitech_2834_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Multitech 2834 voice modem");
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 Multitech_2834_answer_phone()
{
int v0; // eax
unsigned int v1; // edx

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
unsigned int v1; // edx

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

original_code:
static int Multitech_2834_answer_phone(void)
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

canonical_original_code:
static int Multitech_2834_answer_phone()
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

variable_types: result int


decompiled_code:
void __fastcall Multitech_2834_fix_modem(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly - mail rmk@arm.uk.linux.org", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly - mail rmk@arm.uk.linux.org", program_name);
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly - mail rmk@arm.uk.linux.org", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly - mail rmk@arm.uk.linux.org", program_name);
}
}

original_code:
void Multitech_2834_fix_modem(int expect_error)
{
 char buffer[(256)];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly - mail rmk@arm.uk.linux.org",
          program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly - mail rmk@arm.uk.linux.org",
   program_name);
}

canonical_original_code:
void Multitech_2834_fix_modem(int expect_error)
{
 char buffer[-1];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly - mail rmk@arm.uk.linux.org",
          program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly - mail rmk@arm.uk.linux.org",
   program_name);
}


decompiled_code:
__int64 Multitech_2834_voice_mode_on()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_998) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_998, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
Multitech_2834_fix_modem(0);
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_998) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_998, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
func4(0);
return v0;
}

original_code:
static int Multitech_2834_voice_mode_on(void)
{
 char buffer[(256)];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(0);
 return (0);
}

canonical_original_code:
static int Multitech_2834_voice_mode_on()
{
 char buffer[-1];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(0);
 return (0);
}


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

sprintf(v1, "%s%s", *(const char **)(voice_modem + 176LL), &mode_save);
if ( (voice_command(v1, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_2834_fix_modem(1);
return 0LL;
}

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

sprintf(v1, "%s%s", *(const char **)(voice_modem + 176LL), &mode_save);
if ( (voice_command(v1, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
func4(1);
return 0LL;
}

original_code:
static int Multitech_2834_voice_mode_off(void)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(1);
 return (0);
}

canonical_original_code:
static int Multitech_2834_voice_mode_off()
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(1);
 return (0);
}


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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_2834_fix_modem(1);
return 0LL;
}

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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
func4(1);
return 0LL;
}

original_code:
static int Multitech_2834_switch_to_data_fax(char *mode)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(1);
 return (0);
}

canonical_original_code:
static int Multitech_2834_switch_to_data_fax(char *mode)
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_2834_fix_modem(1);
 return (0);
}

variable_types:
mode
char *


decompiled_code:
__int64 Multitech_5634ZPX_answer_phone()
{
int v0; // eax
unsigned int v1; // edx

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

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

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

original_code:
int Multitech_5634ZPX_answer_phone(void)
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

canonical_original_code:
int Multitech_5634ZPX_answer_phone()
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }


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

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


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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing %s voice modem", (const char *)*voice_modem);
if ( (unsigned int)voice_command("AT+VIT=10", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing %s voice modem", (const char *)*voice_modem);
if ( (unsigned int)voice_command("AT+VIT=10", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
int Multitech_5634ZPX_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing %s voice modem", voice_modem->name);
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
int Multitech_5634ZPX_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing %s voice modem", voice_modem->name);
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 __fastcall Multitech_5634ZPX_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx
__int64 result; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 132LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx
__int64 result; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 132LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Multitech_5634ZPX_set_compression(p_int *compression, p_int *speed,
 int *bits)
     {
     char buffer[(256)];
     reset_watchdog();
     if (*compression == 0)
          *compression = 132;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, (int)*compression);
               return((-1));
          }
     return((0));
     }

canonical_original_code:
int Multitech_5634ZPX_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     reset_watchdog();
     if (*compression == 0)
          *compression = 132;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, (int)*compression);
               return((-1));
          }
     return((0));
     }


decompiled_code:
void __fastcall Multitech_5634ZPX_fix_modem(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly", program_name);
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly", program_name);
}
}

original_code:
void Multitech_5634ZPX_fix_modem(int expect_error)
{
 char buffer[(256)];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly", program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly", program_name);
}

canonical_original_code:
void Multitech_5634ZPX_fix_modem(int expect_error)
{
 char buffer[-1];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly", program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly", program_name);
}


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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_5634ZPX_fix_modem(1);
return 0LL;
}

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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
func4(1);
return 0LL;
}

original_code:
int Multitech_5634ZPX_switch_to_data_fax(char *mode)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(1);
 return (0);
}

canonical_original_code:
int Multitech_5634ZPX_switch_to_data_fax(char *mode)
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(1);
 return (0);
}


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

sprintf(v1, "%s%s", *(const char **)(voice_modem + 176LL), &mode_save);
if ( (voice_command(v1, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_5634ZPX_fix_modem(1);
return 0LL;
}

original_code:
int Multitech_5634ZPX_voice_mode_off(void)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(1);
 return (0);
}

canonical_original_code:
int Multitech_5634ZPX_voice_mode_off()
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(1);
 return (0);
}


decompiled_code:
__int64 Multitech_5634ZPX_voice_mode_on()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9D6) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_9D6, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
Multitech_5634ZPX_fix_modem(0);
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9D6) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_9D6, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
func4(0);
return v0;
}

original_code:
int Multitech_5634ZPX_voice_mode_on(void)
{
 char buffer[(256)];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(0);
 return (0);
}

canonical_original_code:
int Multitech_5634ZPX_voice_mode_on()
{
 char buffer[-1];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634ZPX_fix_modem(0);
 return (0);
}


decompiled_code:
void *process_rockwell_mesg()
{
void *result; // rax
unsigned int v1; // ebx
char *v2; // rax
const char *v3; // rdx
int v4; // ebx
_BYTE *v5; // rdi
__int64 v6; // rsi
__int64 v7; // rax
char *v8; // rsi
unsigned int v9; // [rsp+Ch] [rbp-Ch] BYREF

v9 = 0;
result = CallMsg1;
if ( *(_BYTE *)CallMsg1 == 48 && *((_BYTE *)CallMsg1 + 1) == 51 )
{
*((_BYTE *)CallMsg1 + 4) = 0;
_isoc99_sscanf((char *)CallMsg1 + 2, "%x", &v9);
lprintf(6LL, "CND: number length: %d", v9);
v1 = v9;
v2 = (char *)malloc((int)(v9 + 1));
v3 = v2;
CallerId = v2;
v4 = 2 * v1;
if ( v4 <= 1 )
{
v8 = v2;
}
else
{
v5 = CallMsg1;
v6 = ((unsigned int)(v4 - 2) >> 1) + 1;
v7 = 0LL;
do
{
v3[v7] = v5[2 * v7 + 5];
++v7;
}
while ( v7 != v6 );
v8 = (char *)&v3[v6];
}
*v8 = 0;
result = (void *)lprintf(6LL, "CND: caller ID: %s", v3);
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax
unsigned int v1; // ebx
char *v2; // rax
const char *v3; // rdx
int v4; // ebx
_BYTE *v5; // rdi
__int64 v6; // rsi
__int64 v7; // rax
char *v8; // rsi
unsigned int v9; // [rsp+Ch] [rbp-Ch] BYREF

v9 = 0;
result = CallMsg1;
if ( *(_BYTE *)CallMsg1 == 48 && *((_BYTE *)CallMsg1 + 1) == 51 )
{
*((_BYTE *)CallMsg1 + 4) = 0;
_isoc99_sscanf((char *)CallMsg1 + 2, "%x", &v9);
lprintf(6LL, "CND: number length: %d", v9);
v1 = v9;
v2 = (char *)malloc((int)(v9 + 1));
v3 = v2;
CallerId = v2;
v4 = 2 * v1;
if ( v4 <= 1 )
{
v8 = v2;
}
else
{
v5 = CallMsg1;
v6 = ((unsigned int)(v4 - 2) >> 1) + 1;
v7 = 0LL;
do
{
v3[v7] = v5[2 * v7 + 5];
++v7;
}
while ( v7 != v6 );
v8 = (char *)&v3[v6];
}
*v8 = 0;
result = (void *)lprintf(6LL, "CND: caller ID: %s", v3);
}
return result;
}

original_code:
void process_rockwell_mesg (void)
{
    int length = 0;
    int loop;
    char *p;
    if ( CallMsg1[0] == 0) return;
    if ( (CallMsg1[0] != '0') || (CallMsg1[1] != '3')) return;
    CallMsg1[4] = '\0';
    sscanf( &CallMsg1[2], "%x", &length);
    lprintf(6, "CND: number length: %d",length);
    p = CallerId = malloc(length + 1);
    for (loop = 5; loop <= (3 + length*2); loop += 2)
    {
 *p = CallMsg1[loop];
 p++;
    }
    *p = 0;
    lprintf(6, "CND: caller ID: %s", CallerId);
}

canonical_original_code:
void process_rockwell_mesg()
{
    int length = 0;
    int loop;
    char *p;
    if ( CallMsg1[0] == 0) return;
    if ( (CallMsg1[0] != '0') || (CallMsg1[1] != '3')) return;
    CallMsg1[4] = '\0';
    sscanf( &CallMsg1[2], "%x", &length);
    lprintf(6, "CND: number length: %d",length);
    p = CallerId = malloc(length + 1);
    for (loop = 5; loop <= (3 + length*2); loop += 2)
    {
 *p = CallMsg1[loop];
 p++;
    }
    *p = 0;
    lprintf(6, "CND: caller ID: %s", CallerId);
}

variable_types: length int

variable_types: loop int

variable_types:
p
char *


cndlookup

decompiled_code:
__int64 cndlookup()
{
return 1LL;
}

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

original_code:
int cndlookup (void)
{
    int match = 1;
    return(match);
}

canonical_original_code:
int cndlookup()
{
    int match = 1;
    return(match);
}

variable_types: match int


decompiled_code:
__int64 __fastcall cnd_call(const char *a1, const char *a2, unsigned int a3)
{
size_t v3; // r12
const char *v4; // r13
const char *v5; // r15
const char *v6; // r14
size_t v7; // rax
char *v8; // rax
char *v9; // r12
int v10; // eax
int v11; // ebx
__int64 result; // rax
size_t v13; // [rsp+0h] [rbp-58h]
size_t v14; // [rsp+8h] [rbp-50h]
size_t v15; // [rsp+10h] [rbp-48h]

v3 = strlen(a1);
v13 = strlen(a2);
v4 = CallerId;
v14 = strlen(CallerId);
v5 = CalledNr;
v15 = strlen(CalledNr);
v6 = CallName;
v7 = strlen(CallName);
v8 = (char *)malloc(v15 + v14 + v3 + v13 + 63 + v7);
if ( v8 )
{
v9 = v8;
sprintf(v8, "%s %s '%s' '%s' %d '%s' >%s 2>&1 </dev/null", a1, a2, v4, v6, a3, v5, "/dev/console");
lprintf(5LL, "CND: program \"%s\"", v9);
v10 = system(v9);
v11 = v10;
if ( v10 < 0 )
{
lprintf(1LL, "cnd_call: system failed");
free(v9);
result = 0LL;
}
else
{
lprintf(5LL, "CND: rc=0x%x", (unsigned int)v10);
free(v9);
result = (unsigned int)(v11 >> 8);
}
}
else
{
lprintf(1LL, "cnd_call: can't malloc");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2, unsigned int a3)
{
size_t v3; // r12
const char *v4; // r13
const char *v5; // r15
const char *v6; // r14
size_t v7; // rax
char *v8; // rax
char *v9; // r12
int v10; // eax
int v11; // ebx
__int64 result; // rax
size_t v13; // [rsp+0h] [rbp-58h]
size_t v14; // [rsp+8h] [rbp-50h]
size_t v15; // [rsp+10h] [rbp-48h]

v3 = strlen(a1);
v13 = strlen(a2);
v4 = CallerId;
v14 = strlen(CallerId);
v5 = CalledNr;
v15 = strlen(CalledNr);
v6 = CallName;
v7 = strlen(CallName);
v8 = (char *)malloc(v15 + v14 + v3 + v13 + 63 + v7);
if ( v8 )
{
v9 = v8;
sprintf(v8, "%s %s '%s' '%s' %d '%s' >%s 2>&1 </dev/null", a1, a2, v4, v6, a3, v5, "/dev/console");
lprintf(5LL, "CND: program \"%s\"", v9);
v10 = system(v9);
v11 = v10;
if ( v10 < 0 )
{
lprintf(1LL, "cnd_call: system failed");
free(v9);
result = 0LL;
}
else
{
lprintf(5LL, "CND: rc=0x%x", (unsigned int)v10);
free(v9);
result = (unsigned int)(v11 >> 8);
}
}
else
{
lprintf(1LL, "cnd_call: can't malloc");
result = 0LL;
}
return result;
}

original_code:
int cnd_call (char * name,char * tty,int dist_ring)
{
    char * program;
    int rc;
    program = malloc( strlen(name) + strlen(tty) +
        strlen( CallerId ) + strlen( CalledNr ) +
        strlen( CallName ) +
        sizeof( "/dev/console" ) + 50 );
    if ( program == ((void *)0) )
     { lprintf( 1, "cnd_call: can't malloc" ); return 0; }
    sprintf( program, "%s %s '%s' '%s' %d '%s' >%s 2>&1 </dev/null", name,
        tty, CallerId, CallName, dist_ring, CalledNr, "/dev/console" );
    lprintf( 5, "CND: program \"%s\"", program );
    rc = system(program);
    if ( rc < 0 )
    { lprintf( 1, "cnd_call: system failed" ); free(program); return 0; }
    lprintf( 5, "CND: rc=0x%x", rc );
    free(program);
    return rc>>8;
}

canonical_original_code:
int cnd_call(char *name, char *tty, int dist_ring)
{
    char *program;
    int rc;
    program = malloc( strlen(name) + strlen(tty) +
        strlen( CallerId ) + strlen( CalledNr ) +
        strlen( CallName ) +
        sizeof( "/dev/console" ) + 50 );
    if ( program == ((void *)0) )
     { lprintf( 1, "cnd_call: can't malloc" ); return 0; }
    sprintf( program, "%s %s '%s' '%s' %d '%s' >%s 2>&1 </dev/null", name,
        tty, CallerId, CallName, dist_ring, CalledNr, "/dev/console" );
    lprintf( 5, "CND: program \"%s\"", program );
    rc = system(program);
    if ( rc < 0 )
    { lprintf( 1, "cnd_call: system failed" ); free(program); return 0; }
    lprintf( 5, "CND: rc=0x%x", rc );
    free(program);
    return rc>>8;
}

variable_types:
name
char *

variable_types:
tty
char *

variable_types:
program
char *

variable_types: rc int


cndfind

decompiled_code:
int __fastcall cndfind(char *s2)
{
char *v1; // rbx
char v2; // bp
const unsigned __int16 *v3; // rax
char *v4; // rbp
const unsigned __int16 **v5; // rcx
const unsigned __int16 **v6; // r13
const unsigned __int16 *v7; // rax
const char *v8; // r15
_BYTE *v9; // rbp
char **v10; // r12
char *v11; // rsi
char *v12; // rax
size_t v13; // r13
size_t v14; // rbp
size_t v15; // rax
char *v16; // rbp
char i; // al
size_t v18; // r14
void **v19; // r15
const char *v20; // rbp
size_t v21; // rax

v1 = s2;
v2 = *s2;
if ( *s2 )
{
v3 = *_ctype_b_loc();
do
{
if ( (v3[v2] & 0x2000) == 0 )
break;
v2 = *++v1;
}
while ( *v1 );
}
v4 = &v1[strlen(v1) - 1];
if ( v4 >= v1 )
{
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 >= v1 );
}
lprintf(6LL, "CND: %s", v1);
v6 = _ctype_b_loc();
v7 = *v6;
if ( ((*v6)[*v1] & 0x800) != 0 )
{
v11 = strdup(v1);
CallerId = v11;
if ( ((*v6)[*v11] & 0x800) != 0 )
{
v12 = v11;
do
++v12;
while ( ((*v6)[*v12] & 0x800) != 0 );
}
else
{
v12 = v11;
}
*v12 = 0;
LODWORD(v7) = lprintf(5LL, "CND: ELink caller ID: '%s'", v11);
}
else
{
v8 = cndtable;
v9 = CallMsg1;
v10 = &cndtable;
if ( cndtable )
{
while ( 1 )
{
v18 = (int)strlen(v8);
LODWORD(v7) = strncmp(v8, v1, v18);
if ( !(_DWORD)v7 )
{
v19 = (void **)v10[1];
if ( !v19 )
return (int)v7;
if ( v19 != &CallMsg1 || !*v9 )
break;
}
v10 += 2;
v8 = *v10;
if ( !*v10 )
return (int)v7;
}
v20 = cnd_carrier;
if ( (*cnd_carrier || *cnd_protocol) && !memcmp(v1, "CONNECT ", 8uLL) )
{
v13 = strlen(v1);
v14 = strlen(v20);
v15 = strlen(cnd_protocol);
*v19 = malloc(v15 + v14 + v13 - v18 + 5);
sprintf(*(char **)v10[1], "%s/%s %s", &v1[v18], cnd_carrier, cnd_protocol);
}
else
{
v21 = strlen(v1);
v16 = (char *)malloc(v21 - v18 + 1);
*v19 = v16;
strcpy(*(char **)v10[1], &v1[v18]);
for ( i = *v16; *v16; i = *v16 )
{
if ( i == 39 || i == 34 || ((*v6)[i] & 0x4000) == 0 )
*v16 = 32;
++v16;
}
}
LODWORD(v7) = lprintf(6LL, "CND: found: %s", *(const char **)v10[1]);
}
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func0(char *s2)
{
char *v1; // rbx
char v2; // bp
const unsigned __int16 *v3; // rax
char *v4; // rbp
const unsigned __int16 **v5; // rcx
const unsigned __int16 **v6; // r13
const unsigned __int16 *v7; // rax
const char *v8; // r15
_BYTE *v9; // rbp
char **v10; // r12
char *v11; // rsi
char *v12; // rax
size_t v13; // r13
size_t v14; // rbp
size_t v15; // rax
char *v16; // rbp
char i; // al
size_t v18; // r14
void **v19; // r15
const char *v20; // rbp
size_t v21; // rax

v1 = s2;
v2 = *s2;
if ( *s2 )
{
v3 = *_ctype_b_loc();
do
{
if ( (v3[v2] & 0x2000) == 0 )
break;
v2 = *++v1;
}
while ( *v1 );
}
v4 = &v1[strlen(v1) - 1];
if ( v4 >= v1 )
{
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 >= v1 );
}
lprintf(6LL, "CND: %s", v1);
v6 = _ctype_b_loc();
v7 = *v6;
if ( ((*v6)[*v1] & 0x800) != 0 )
{
v11 = strdup(v1);
CallerId = v11;
if ( ((*v6)[*v11] & 0x800) != 0 )
{
v12 = v11;
do
++v12;
while ( ((*v6)[*v12] & 0x800) != 0 );
}
else
{
v12 = v11;
}
*v12 = 0;
LODWORD(v7) = lprintf(5LL, "CND: ELink caller ID: '%s'", v11);
}
else
{
v8 = cndtable;
v9 = CallMsg1;
v10 = &cndtable;
if ( cndtable )
{
while ( 1 )
{
v18 = (int)strlen(v8);
LODWORD(v7) = strncmp(v8, v1, v18);
if ( !(_DWORD)v7 )
{
v19 = (void **)v10[1];
if ( !v19 )
return (int)v7;
if ( v19 != &CallMsg1 || !*v9 )
break;
}
v10 += 2;
v8 = *v10;
if ( !*v10 )
return (int)v7;
}
v20 = cnd_carrier;
if ( (*cnd_carrier || *cnd_protocol) && !memcmp(v1, "CONNECT ", 8uLL) )
{
v13 = strlen(v1);
v14 = strlen(v20);
v15 = strlen(cnd_protocol);
*v19 = malloc(v15 + v14 + v13 - v18 + 5);
sprintf(*(char **)v10[1], "%s/%s %s", &v1[v18], cnd_carrier, cnd_protocol);
}
else
{
v21 = strlen(v1);
v16 = (char *)malloc(v21 - v18 + 1);
*v19 = v16;
strcpy(*(char **)v10[1], &v1[v18]);
for ( i = *v16; *v16; i = *v16 )
{
if ( i == 39 || i == 34 || ((*v6)[i] & 0x4000) == 0 )
*v16 = 32;
++v16;
}
}
LODWORD(v7) = lprintf(6LL, "CND: found: %s", *(const char **)v10[1]);
}
}
return (int)v7;
}

original_code:
void
cndfind (char *str)
{
    struct cndtable *cp;
    register int len;
    register char *p;
    while (*str && ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
    p = str + strlen(str) - 1;
    while(p >= str && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace))
 *p-- = '\0';
    lprintf(6, "CND: %s", str);
    if ( ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit) )
    {
 CallerId = p = strdup(str);
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) ) p++;
 *p = 0;
 lprintf( 5, "CND: ELink caller ID: '%s'", CallerId );
 return;
    }
    for (cp = cndtable; cp->string; cp++)
    {
 len = strlen(cp->string);
 if (strncmp(cp->string, str, len) == 0)
 {
     if (!cp->variable)
  return;
     if (cp->variable == &CallMsg1 && CallMsg1[0] != 0)
  continue;
     if ( ( cnd_carrier[0] != 0 || cnd_protocol[0] != 0 ) &&
   strncmp( str, "CONNECT ", 8 ) == 0 )
     {
  *(cp->variable) = malloc( strlen(str) - len +
                    strlen( cnd_carrier ) +
      strlen( cnd_protocol ) + 5 );
  sprintf( *(cp->variable), "%s/%s %s",
    str+len, cnd_carrier, cnd_protocol );
     }
     else
     {
  *(cp->variable) = p = malloc(strlen(str) - len + 1);
  (void) strcpy(*(cp->variable), str+len);
  while( *p != '\0' )
  {
      if ( *p == '\'' || *p == '\"' || !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISprint) ) *p = ' ';
      p++;
  }
     }
     lprintf(6, "CND: found: %s", *(cp->variable));
     return;
 }
    }
}

canonical_original_code:
void cndfind(char *str)
{
    struct cndtable *cp;
    register int len;
    register char *p;
    while (*str && ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
    p = str + strlen(str) - 1;
    while(p >= str && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace))
 *p-- = '\0';
    lprintf(6, "CND: %s", str);
    if ( ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit) )
    {
 CallerId = p = strdup(str);
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) ) p++;
 *p = 0;
 lprintf( 5, "CND: ELink caller ID: '%s'", CallerId );
 return;
    }
    for (cp = cndtable; cp->string; cp++)
    {
 len = strlen(cp->string);
 if (strncmp(cp->string, str, len) == 0)
 {
     if (!cp->variable)
  return;
     if (cp->variable == &CallMsg1 && CallMsg1[0] != 0)
  continue;
     if ( ( cnd_carrier[0] != 0 || cnd_protocol[0] != 0 ) &&
   strncmp( str, "CONNECT ", 8 ) == 0 )
     {
  *(cp->variable) = malloc( strlen(str) - len +
                    strlen( cnd_carrier ) +
      strlen( cnd_protocol ) + 5 );
  sprintf( *(cp->variable), "%s/%s %s",
    str+len, cnd_carrier, cnd_protocol );
     }
     else
     {
  *(cp->variable) = p = malloc(strlen(str) - len + 1);
  (void) strcpy(*(cp->variable), str+len);
  while( *p != '\0' )
  {
      if ( *p == '\'' || *p == '\"' || !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISprint) ) *p = ' ';
      p++;
  }
     }
     lprintf(6, "CND: found: %s", *(cp->variable));
     return;
 }
    }
}

variable_types:
str
char *

variable_types: struct cndtable { char *string; char **variable; } *

variable_types: len int


decompiled_code:
void signal_sigusr2()
{
__int64 v0; // rax

signal(12, signal_sigusr2);
lprintf(6LL, "%s: Got user 2 signal", program_name);
v0 = create_event(16392LL);
queue_event(v0);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rax

signal(12, signal_sigusr2);
lprintf(6LL, "%s: Got user 2 signal", program_name);
v0 = create_event(16392LL);
queue_event(v0);
}

original_code:
static void signal_sigusr2(int sig)
     {
     signal(12, signal_sigusr2);
     lprintf(6, "%s: Got user 2 signal", program_name);
     queue_event(create_event((0x4008)));
     }

variable_types: sig int


decompiled_code:
void signal_sigusr1()
{
__int64 v0; // rax

signal(10, signal_sigusr1);
lprintf(6LL, "%s: Got user 1 signal", program_name);
v0 = create_event(16391LL);
queue_event(v0);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rax

signal(10, signal_sigusr1);
lprintf(6LL, "%s: Got user 1 signal", program_name);
v0 = create_event(16391LL);
queue_event(v0);
}

original_code:
static void signal_sigusr1(int sig)
     {
     signal(10, signal_sigusr1);
     lprintf(6, "%s: Got user 1 signal", program_name);
     queue_event(create_event((0x4007)));
     }


decompiled_code:
void signal_sigterm()
{
__int64 v0; // rax

signal(15, signal_sigterm);
lprintf(6LL, "%s: Got terminate signal", program_name);
v0 = create_event(16390LL);
queue_event(v0);
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // rax

signal(15, signal_sigterm);
lprintf(6LL, "%s: Got terminate signal", program_name);
v0 = create_event(16390LL);
queue_event(v0);
}

original_code:
static void signal_sigterm(int sig)
     {
     signal(15, signal_sigterm);
     lprintf(6, "%s: Got terminate signal", program_name);
     queue_event(create_event((0x4006)));
     }


decompiled_code:
void signal_sigquit()
{
__int64 v0; // rax

signal(3, signal_sigquit);
lprintf(6LL, "%s: Got quit signal", program_name);
v0 = create_event(16389LL);
queue_event(v0);
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rax

signal(3, signal_sigquit);
lprintf(6LL, "%s: Got quit signal", program_name);
v0 = create_event(16389LL);
queue_event(v0);
}

original_code:
static void signal_sigquit(int sig)
     {
     signal(3, signal_sigquit);
     lprintf(6, "%s: Got quit signal", program_name);
     queue_event(create_event((0x4005)));
     }


decompiled_code:
void signal_sigpipe()
{
__int64 v0; // rax

signal(13, signal_sigpipe);
lprintf(6LL, "%s: Got pipe signal", program_name);
v0 = create_event(16388LL);
queue_event(v0);
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rax

signal(13, signal_sigpipe);
lprintf(6LL, "%s: Got pipe signal", program_name);
v0 = create_event(16388LL);
queue_event(v0);
}

original_code:
static void signal_sigpipe(int sig)
     {
     signal(13, signal_sigpipe);
     lprintf(6, "%s: Got pipe signal", program_name);
     queue_event(create_event((0x4004)));
     }


decompiled_code:
void signal_sigint()
{
__int64 v0; // rax

signal(2, signal_sigint);
lprintf(6LL, "%s: Got interrupt signal", program_name);
v0 = create_event(16387LL);
queue_event(v0);
}

canonical_decompiled_code:
void func5()
{
__int64 v0; // rax

signal(2, signal_sigint);
lprintf(6LL, "%s: Got interrupt signal", program_name);
v0 = create_event(16387LL);
queue_event(v0);
}

original_code:
static void signal_sigint(int sig)
     {
     signal(2, signal_sigint);
     lprintf(6, "%s: Got interrupt signal", program_name);
     queue_event(create_event((0x4003)));
     }


decompiled_code:
void signal_sighup()
{
__int64 v0; // rax

signal(1, signal_sighup);
lprintf(6LL, "%s: Got hangup signal", program_name);
v0 = create_event(16386LL);
queue_event(v0);
}

canonical_decompiled_code:
void func6()
{
__int64 v0; // rax

signal(1, signal_sighup);
lprintf(6LL, "%s: Got hangup signal", program_name);
v0 = create_event(16386LL);
queue_event(v0);
}

original_code:
static void signal_sighup(int sig)
     {
     signal(1, signal_sighup);
     lprintf(6, "%s: Got hangup signal", program_name);
     queue_event(create_event((0x4002)));
     }


decompiled_code:
void signal_sigchld()
{
unsigned int v0; // ebx
__int64 v1; // rax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = wait((__WAIT_STATUS)&stat_loc);
signal(17, signal_sigchld);
if ( LODWORD(stat_loc.__uptr) )
lprintf(3LL, "%s: Got child %d exit status %d signal", program_name, v0, LODWORD(stat_loc.__uptr));
else
lprintf(6LL, "%s: Got child %d exit signal", program_name, v0);
v1 = create_event(16385LL);
queue_event(v1);
}

canonical_decompiled_code:
void func7()
{
unsigned int v0; // ebx
__int64 v1; // rax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = wait((__WAIT_STATUS)&stat_loc);
signal(17, signal_sigchld);
if ( LODWORD(stat_loc.__uptr) )
lprintf(3LL, "%s: Got child %d exit status %d signal", program_name, v0, LODWORD(stat_loc.__uptr));
else
lprintf(6LL, "%s: Got child %d exit signal", program_name, v0);
v1 = create_event(16385LL);
queue_event(v1);
}

original_code:
static void signal_sigchld(int sig)
     {
     pid_t pid;
     int status;
     pid = wait(&status);
     signal(17, signal_sigchld);
     if (status) {
        lprintf(3, "%s: Got child %d exit status %d signal",
                program_name,
                pid,
                status);
     }
     else {
        lprintf(6, "%s: Got child %d exit signal",
                program_name,
                pid);
     }
     queue_event(create_event((0x4001)));
     }

canonical_original_code:
static void signal_sigchld(int sig)
     {
     int pid;
     int status;
     pid = wait(&status);
     signal(17, signal_sigchld);
     if (status) {
        lprintf(3, "%s: Got child %d exit status %d signal",
                program_name,
                pid,
                status);
     }
     else {
        lprintf(6, "%s: Got child %d exit signal",
                program_name,
                pid);
     }
     queue_event(create_event((0x4001)));
     }

variable_types: pid int

variable_types: status int


decompiled_code:
void __noreturn signal_sigalrm()
{
lprintf(3LL, "%s: Watchdog timer expired, exiting...", program_name);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func8()
{
lprintf(3LL, "%s: Watchdog timer expired, exiting...", program_name);
exit(-1);
}

original_code:
static void signal_sigalrm(int sig)
     {
     lprintf(3, "%s: Watchdog timer expired, exiting...",
      program_name);
     exit((-1));
     }


decompiled_code:
__int64 voice_install_signal_handler()
{
lprintf(5LL, "%s: Installing signal handlers", program_name);
if ( signals_initialized )
{
lprintf(5LL, "%s: Signal handlers are already installed", program_name);
}
else
{
old_sigalrm = signal(14, (__sighandler_t)signal_sigalrm);
old_sigchld = signal(17, (__sighandler_t)signal_sigchld);
old_sighup = signal(1, (__sighandler_t)signal_sighup);
old_sigint = signal(2, (__sighandler_t)signal_sigint);
old_sigpipe = signal(13, (__sighandler_t)signal_sigpipe);
old_sigquit = signal(3, (__sighandler_t)signal_sigquit);
old_sigterm = signal(15, (__sighandler_t)signal_sigterm);
old_sigusr1 = signal(10, (__sighandler_t)signal_sigusr1);
old_sigusr2 = signal(12, (__sighandler_t)signal_sigusr2);
siginterrupt(14, 1);
siginterrupt(17, 1);
siginterrupt(1, 1);
siginterrupt(2, 1);
siginterrupt(13, 1);
siginterrupt(3, 1);
siginterrupt(15, 1);
siginterrupt(10, 1);
siginterrupt(12, 1);
alarm(cvd[152]);
signals_initialized = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
lprintf(5LL, "%s: Installing signal handlers", program_name);
if ( signals_initialized )
{
lprintf(5LL, "%s: Signal handlers are already installed", program_name);
}
else
{
old_sigalrm = signal(14, (__sighandler_t)signal_sigalrm);
old_sigchld = signal(17, (__sighandler_t)signal_sigchld);
old_sighup = signal(1, (__sighandler_t)signal_sighup);
old_sigint = signal(2, (__sighandler_t)signal_sigint);
old_sigpipe = signal(13, (__sighandler_t)signal_sigpipe);
old_sigquit = signal(3, (__sighandler_t)signal_sigquit);
old_sigterm = signal(15, (__sighandler_t)signal_sigterm);
old_sigusr1 = signal(10, (__sighandler_t)signal_sigusr1);
old_sigusr2 = signal(12, (__sighandler_t)signal_sigusr2);
siginterrupt(14, 1);
siginterrupt(17, 1);
siginterrupt(1, 1);
siginterrupt(2, 1);
siginterrupt(13, 1);
siginterrupt(3, 1);
siginterrupt(15, 1);
siginterrupt(10, 1);
siginterrupt(12, 1);
alarm(cvd[152]);
signals_initialized = 1;
}
return 0LL;
}

original_code:
int voice_install_signal_handler(void)
     {
     lprintf(5, "%s: Installing signal handlers", program_name);
     if (signals_initialized)
          {
          lprintf(5, "%s: Signal handlers are already installed",
           program_name);
          return((0));
          };
     old_sigalrm = signal(14, signal_sigalrm);
     old_sigchld = signal(17, signal_sigchld);
     old_sighup = signal(1, signal_sighup);
     old_sigint = signal(2, signal_sigint);
     old_sigpipe = signal(13, signal_sigpipe);
     old_sigquit = signal(3, signal_sigquit);
     old_sigterm = signal(15, signal_sigterm);
     old_sigusr1 = signal(10, signal_sigusr1);
     old_sigusr2 = signal(12, signal_sigusr2);
     siginterrupt(14, (0==0));
     siginterrupt(17, (0==0));
     siginterrupt(1, (0==0));
     siginterrupt(2, (0==0));
     siginterrupt(13, (0==0));
     siginterrupt(3, (0==0));
     siginterrupt(15, (0==0));
     siginterrupt(10, (0==0));
     siginterrupt(12, (0==0));
     alarm(cvd.watchdog_timeout.d.i);
     signals_initialized = (0==0);
     return((0));
     }

canonical_original_code:
int voice_install_signal_handler()
     {
     lprintf(5, "%s: Installing signal handlers", program_name);
     if (signals_initialized)
          {
          lprintf(5, "%s: Signal handlers are already installed",
           program_name);
          return((0));
          };
     old_sigalrm = signal(14, signal_sigalrm);
     old_sigchld = signal(17, signal_sigchld);
     old_sighup = signal(1, signal_sighup);
     old_sigint = signal(2, signal_sigint);
     old_sigpipe = signal(13, signal_sigpipe);
     old_sigquit = signal(3, signal_sigquit);
     old_sigterm = signal(15, signal_sigterm);
     old_sigusr1 = signal(10, signal_sigusr1);
     old_sigusr2 = signal(12, signal_sigusr2);
     siginterrupt(14, (0==0));
     siginterrupt(17, (0==0));
     siginterrupt(1, (0==0));
     siginterrupt(2, (0==0));
     siginterrupt(13, (0==0));
     siginterrupt(3, (0==0));
     siginterrupt(15, (0==0));
     siginterrupt(10, (0==0));
     siginterrupt(12, (0==0));
     alarm(cvd.watchdog_timeout.d.i);
     signals_initialized = (0==0);
     return((0));
     }


decompiled_code:
__int64 voice_restore_signal_handler()
{
lprintf(5LL, "%s: Restoring signal handlers", program_name);
if ( signals_initialized )
{
alarm(0);
signal(14, old_sigalrm);
signal(17, old_sigchld);
signal(1, old_sighup);
signal(2, old_sigint);
signal(13, old_sigpipe);
signal(3, old_sigquit);
signal(15, old_sigterm);
signal(10, old_sigusr1);
signal(12, old_sigusr2);
signals_initialized = 0;
}
else
{
lprintf(5LL, "%s: No signal handlers were installed", program_name);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
lprintf(5LL, "%s: Restoring signal handlers", program_name);
if ( signals_initialized )
{
alarm(0);
signal(14, old_sigalrm);
signal(17, old_sigchld);
signal(1, old_sighup);
signal(2, old_sigint);
signal(13, old_sigpipe);
signal(3, old_sigquit);
signal(15, old_sigterm);
signal(10, old_sigusr1);
signal(12, old_sigusr2);
signals_initialized = 0;
}
else
{
lprintf(5LL, "%s: No signal handlers were installed", program_name);
}
return 0LL;
}

original_code:
int voice_restore_signal_handler(void)
     {
     lprintf(5, "%s: Restoring signal handlers", program_name);
     if (!signals_initialized)
          {
          lprintf(5, "%s: No signal handlers were installed",
           program_name);
          return((0));
          };
     alarm(0);
     signal(14, old_sigalrm);
     signal(17, old_sigchld);
     signal(1, old_sighup);
     signal(2, old_sigint);
     signal(13, old_sigpipe);
     signal(3, old_sigquit);
     signal(15, old_sigterm);
     signal(10, old_sigusr1);
     signal(12, old_sigusr2);
     signals_initialized = (0==1);
     return((0));
     }

canonical_original_code:
int voice_restore_signal_handler()
     {
     lprintf(5, "%s: Restoring signal handlers", program_name);
     if (!signals_initialized)
          {
          lprintf(5, "%s: No signal handlers were installed",
           program_name);
          return((0));
          };
     alarm(0);
     signal(14, old_sigalrm);
     signal(17, old_sigchld);
     signal(1, old_sighup);
     signal(2, old_sigint);
     signal(13, old_sigpipe);
     signal(3, old_sigquit);
     signal(15, old_sigterm);
     signal(10, old_sigusr1);
     signal(12, old_sigusr2);
     signals_initialized = (0==1);
     return((0));
     }


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

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

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

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

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

variable_types: device int


decompiled_code:
__int64 __fastcall Multitech_5634_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx
__int64 result; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 4LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 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
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( !*a1 )
*a1 = 4LL;
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 == 4 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=2,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else if ( v5 == 132 )
{
*a3 = 4;
sprintf(v7, "AT+VSM=132,%d", *a2);
result = (unsigned int)-((unsigned int)voice_command(v7, &unk_8C0) != 4096);
}
else
{
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Multitech_5634_set_compression(p_int *compression, p_int *speed,
 int *bits)
     {
     char buffer[(256)];
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, (int)*compression);
               return((-1));
          }
     return((0));
     }

canonical_original_code:
static int Multitech_5634_set_compression(long *compression, long *speed, int *bits)
     {
     char buffer[-1];
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, (int)*compression);
               return((-1));
          }
     return((0));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Multitech 5634 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8C0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Multitech 5634 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8C0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v1, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 82)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(144 * *((_QWORD *)&cvd + 79)) / 100 + 56));
if ( (unsigned int)voice_command(v1, &unk_8C0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Multitech_5634_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Multitech 5634 voice modem");
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Multitech_5634_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Multitech 5634 voice modem");
     if (voice_command("AT+VIT=10", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VSD=%d,%d", 128, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 Multitech_5634_answer_phone()
{
int v0; // eax
unsigned int v1; // edx

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
unsigned int v1; // edx

reset_watchdog();
v0 = voice_command("AT+VLS=1", "OK|CONNECT");
v1 = 8195;
if ( (v0 & 0x1000) != 0 )
v1 = 9 * (v0 != 4097) + 8193;
return v1;
}

original_code:
static int Multitech_5634_answer_phone(void)
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

canonical_original_code:
static int Multitech_5634_answer_phone()
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

variable_types: result int


decompiled_code:
void __fastcall Multitech_5634_fix_modem(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly", program_name);
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // ebx
int v2; // eax
_BYTE v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( cvd[85] )
{
voice_write("AT");
v1 = 0x4000;
while ( !(unsigned int)voice_read(v3) )
{
v2 = voice_analyze(v3, "AT", 1LL);
v1 = v2;
switch ( v2 )
{
case 0x4000:
voice_flush(1LL);
goto LABEL_14;
case 0x2003:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
goto LABEL_14;
case 0x1000:
if ( !a1 )
return;
goto LABEL_11;
}
}
voice_flush(1LL);
if ( v1 == 4096 && a1 )
{
LABEL_11:
lprintf(3LL, "%s: Modem answered correctly", program_name);
return;
}
LABEL_14:
if ( v1 != 4096 && !a1 )
lprintf(3LL, "%s: Modem answered incorrectly", program_name);
}
}

original_code:
void Multitech_5634_fix_modem(int expect_error)
{
 char buffer[(256)];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly", program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly", program_name);
}

canonical_original_code:
void Multitech_5634_fix_modem(int expect_error)
{
 char buffer[-1];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly", program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly", program_name);
}


decompiled_code:
__int64 Multitech_5634_voice_mode_on()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9B5) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_9B5, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
Multitech_5634_fix_modem(0);
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
size_t v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9B5) )
return (unsigned int)-1;
do
{
v0 = voice_read(&mode_save);
if ( v0 )
return (unsigned int)-1;
}
while ( !mode_save );
if ( !memcmp(&mode_save, "+FCLASS=", 8uLL) )
{
v1 = strlen(&mode_save);
memmove(&mode_save, &unk_8B8, v1 - 7);
}
if ( (voice_command(&unk_9B5, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) == 0 )
return (unsigned int)-1;
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return (unsigned int)-1;
func4(0);
return v0;
}

original_code:
static int Multitech_5634_voice_mode_on(void)
{
 char buffer[(256)];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(0);
 return (0);
}

canonical_original_code:
static int Multitech_5634_voice_mode_on()
{
 char buffer[-1];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(0);
 return (0);
}


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

sprintf(v1, "%s%s", *(const char **)(voice_modem + 176LL), &mode_save);
if ( (voice_command(v1, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_5634_fix_modem(1);
return 0LL;
}

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

sprintf(v1, "%s%s", *(const char **)(voice_modem + 176LL), &mode_save);
if ( (voice_command(v1, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
func4(1);
return 0LL;
}

original_code:
static int Multitech_5634_voice_mode_off(void)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(1);
 return (0);
}

canonical_original_code:
static int Multitech_5634_voice_mode_off()
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode_save);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(1);
 return (0);
}


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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
Multitech_5634_fix_modem(1);
return 0LL;
}

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

sprintf(v2, "%s%s", *(const char **)(voice_modem + 176LL), a1);
if ( (voice_command(v2, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) == 0 )
return 0xFFFFFFFFLL;
func4(1);
return 0LL;
}

original_code:
static int Multitech_5634_switch_to_data_fax(char *mode)
{
 char buffer[(256)];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(1);
 return (0);
}

canonical_original_code:
static int Multitech_5634_switch_to_data_fax(char *mode)
{
 char buffer[-1];
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd, mode);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(1);
 return (0);
}

variable_types:
mode
char *


decompiled_code:
__int64 __fastcall voice_flush(int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // eax

v1 = 1;
do
{
while ( 1 )
{
v3 = voice_read_byte();
if ( v3 < 0 )
break;
if ( v3 == 10 || v3 == 13 )
{
v1 = 1;
}
else if ( v1 )
{
lprintf(6LL, "%s: %c", (const char *)*voice_modem, (unsigned int)v3);
v1 = 0;
}
else
{
lputc(6LL, (unsigned int)(char)v3);
}
}
if ( a1 > 0 )
delay((unsigned int)(100 * a1));
result = voice_check_for_input();
}
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // eax

v1 = 1;
do
{
while ( 1 )
{
v3 = voice_read_byte();
if ( v3 < 0 )
break;
if ( v3 == 10 || v3 == 13 )
{
v1 = 1;
}
else if ( v1 )
{
lprintf(6LL, "%s: %c", (const char *)*voice_modem, (unsigned int)v3);
v1 = 0;
}
else
{
lputc(6LL, (unsigned int)(char)v3);
}
}
if ( a1 > 0 )
delay((unsigned int)(100 * a1));
result = voice_check_for_input();
}
while ( (_DWORD)result );
return result;
}

original_code:
void voice_flush(int timeout)
     {
     int modem_byte;
     int first_char = (0==0);
     do
          {
          while ((modem_byte = voice_read_byte()) >= 0)
               {
               if ((modem_byte == 0x0a) || (modem_byte == 0x0d))
                    first_char = (0==0);
               else
                    if (first_char)
                         {
                         first_char = (0==1);
                         lprintf(6, "%s: %c", voice_modem->name, modem_byte);
                         }
                    else
                         lputc(6, modem_byte);
               }
          if (timeout > 0)
               delay(100 * timeout);
          }
     while (voice_check_for_input());
     }

variable_types: timeout int