decompiled_code:
void __fastcall hylafax_nsf_decode(void *s2, unsigned int a2)
{
void **v3; // r14
void *v4; // rdi
const void **v5; // r12
const void *v6; // rdi
const char *v7; // r14
const char *v8; // r13
unsigned int v9; // edx
unsigned int v10; // eax
unsigned int v11; // er15
char *v12; // rbp
size_t n; // [rsp+8h] [rbp-40h]

v3 = &KnownNSF;
v4 = &unk_120;
while ( 1 )
{
v9 = *((_DWORD *)v3 + 2);
if ( v9 <= a2 && !memcmp(v4, s2, v9) )
break;
v3 += 6;
v4 = *v3;
if ( !*v3 )
return;
}
v8 = (const char *)v3[2];
v5 = (const void **)v3[5];
if ( v5 && (v6 = *v5) != 0LL )
{
v10 = *((_DWORD *)v3 + 7);
v11 = v10 + *((_DWORD *)v3 + 8);
n = *((unsigned int *)v3 + 8);
v12 = (char *)s2 + v10;
v7 = 0LL;
do
{
if ( a2 >= v11 && !memcmp(v6, v12, n) )
v7 = (const char *)v5[1];
v5 += 2;
v6 = *v5;
}
while ( *v5 );
if ( (unsigned __int64)v7 | (unsigned __int64)v8 )
{
if ( v7 )
{
if ( !v8 )
v8 = "<unknown>";
}
else
{
v7 = "<unknown>";
}
goto LABEL_10;
}
}
else if ( v8 )
{
v7 = "<unknown>";
LABEL_10:
lprintf(4LL, "NSF: vendor=%s, model=%s", v8, v7);
return;
}
}

canonical_decompiled_code:
void __fastcall func0(void *s2, unsigned int a2)
{
void **v3; // r14
void *v4; // rdi
const void **v5; // r12
const void *v6; // rdi
const char *v7; // r14
const char *v8; // r13
unsigned int v9; // edx
unsigned int v10; // eax
unsigned int v11; // er15
char *v12; // rbp
size_t n; // [rsp+8h] [rbp-40h]

v3 = &KnownNSF;
v4 = &unk_120;
while ( 1 )
{
v9 = *((_DWORD *)v3 + 2);
if ( v9 <= a2 && !memcmp(v4, s2, v9) )
break;
v3 += 6;
v4 = *v3;
if ( !*v3 )
return;
}
v8 = (const char *)v3[2];
v5 = (const void **)v3[5];
if ( v5 && (v6 = *v5) != 0LL )
{
v10 = *((_DWORD *)v3 + 7);
v11 = v10 + *((_DWORD *)v3 + 8);
n = *((unsigned int *)v3 + 8);
v12 = (char *)s2 + v10;
v7 = 0LL;
do
{
if ( a2 >= v11 && !memcmp(v6, v12, n) )
v7 = (const char *)v5[1];
v5 += 2;
v6 = *v5;
}
while ( *v5 );
if ( (unsigned __int64)v7 | (unsigned __int64)v8 )
{
if ( v7 )
{
if ( !v8 )
v8 = "<unknown>";
}
else
{
v7 = "<unknown>";
}
goto LABEL_10;
}
}
else if ( v8 )
{
v7 = "<unknown>";
LABEL_10:
lprintf(4LL, "NSF: vendor=%s, model=%s", v8, v7);
return;
}
}

original_code:
void hylafax_nsf_decode (unsigned char * nsf,int nsfSize)
{
const char * vendor = ((void *)0);
const char * model = ((void *)0);
const NSFData * p;
const ModelData * pp;
    for( p = KnownNSF; p->vendorId; p++ ){
        if( nsfSize >= p->vendorIdSize &&
            memcmp( p->vendorId, &nsf[0], p->vendorIdSize )==0 ){
     if( p->vendorName )
                vendor = p->vendorName;
            if( p->knownModels ){
                for( pp = p->knownModels; pp->modelId; pp++ )
                    if( nsfSize >= p->modelIdPos + p->modelIdSize &&
                        memcmp( pp->modelId, &nsf[p->modelIdPos], p->modelIdSize )==0 )
                        model = pp->modelName;
            }
     break;
        }
    }
    if ( vendor != ((void *)0) || model != ((void *)0) )
 lprintf( 4, "NSF: vendor=%s, model=%s",
   vendor != ((void *)0)? vendor: "<unknown>",
   model != ((void *)0)? model : "<unknown>" );
}

canonical_original_code:
void hylafax_nsf_decode(unsigned char *nsf, int nsfSize)
{
char *vendor = ((void *)0);
char *model = ((void *)0);
struct NSFData *p;
struct ModelData *pp;
    for( p = KnownNSF; p->vendorId; p++ ){
        if( nsfSize >= p->vendorIdSize &&
            memcmp( p->vendorId, &nsf[0], p->vendorIdSize )==0 ){
     if( p->vendorName )
                vendor = p->vendorName;
            if( p->knownModels ){
                for( pp = p->knownModels; pp->modelId; pp++ )
                    if( nsfSize >= p->modelIdPos + p->modelIdSize &&
                        memcmp( pp->modelId, &nsf[p->modelIdPos], p->modelIdSize )==0 )
                        model = pp->modelName;
            }
     break;
        }
    }
    if ( vendor != ((void *)0) || model != ((void *)0) )
 lprintf( 4, "NSF: vendor=%s, model=%s",
   vendor != ((void *)0)? vendor: "<unknown>",
   model != ((void *)0)? model : "<unknown>" );
}

variable_types:
nsf
unsigned char *

variable_types: nsfSize int

variable_types:
vendor
char *

variable_types:
model
char *

variable_types: struct NSFData { char *vendorId; unsigned int vendorIdSize; char *vendorName; char inverseStationIdOrder; unsigned int modelIdPos; unsigned int modelIdSize; struct ModelData { char *modelId; char *modelName; } *knownModels; } *

user_defined_types: struct NSFData { char *vendorId; unsigned int vendorIdSize; char *vendorName; char inverseStationIdOrder; unsigned int modelIdPos; unsigned int modelIdSize; struct ModelData *knownModels; }


repo: Distrotech/mgetty

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

v1 = 1;
if ( strcmp(a1, "ZyXEL 1496") )
v1 = strcmp(a1, "ZyXEL 2864") == 0;
return v1;
}

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

v1 = 1;
if ( strcmp(a1, "ZyXEL 1496") )
v1 = strcmp(a1, "ZyXEL 2864") == 0;
return v1;
}

original_code:
int ZyXEL_1496_check_rmd_adequation(char *rmd_name) {
   return !strncmp(rmd_name,
                   "ZyXEL 1496",
                   sizeof("ZyXEL 1496"))
          || !strncmp(rmd_name,
                      "ZyXEL 2864",
                      sizeof("ZyXEL 2864"));
}

return_type: int


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

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

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

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

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

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

variable_types: device int


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

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

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

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

original_code:
static int ZyXEL_1496_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          };
     switch (*compression)
          {
          case 1:
               *bits = 1;
               if (voice_command("AT+VSM=1", "OK") != (0x1000))
                    return((-1));
               break;
          case 2:
               *bits = 2;
               if (voice_command("AT+VSM=2", "OK") != (0x1000))
                    return((-1));
               break;
          case 3:
               *bits = 3;
               if (voice_command("AT+VSM=3", "OK") != (0x1000))
                    return((-1));
               break;
          case 30:
               *bits = 3;
               if (voice_command("AT+VSM=30", "OK") != (0x1000))
                    return((-1));
               break;
          case 4:
               *bits = 4;
               if (voice_command("AT+VSM=4", "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 ZyXEL_1496_set_compression(long *compression, long *speed, int *bits)
     {
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 9600;
     if (*speed != 9600)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          };
     switch (*compression)
          {
          case 1:
               *bits = 1;
               if (voice_command("AT+VSM=1", "OK") != (0x1000))
                    return((-1));
               break;
          case 2:
               *bits = 2;
               if (voice_command("AT+VSM=2", "OK") != (0x1000))
                    return((-1));
               break;
          case 3:
               *bits = 3;
               if (voice_command("AT+VSM=3", "OK") != (0x1000))
                    return((-1));
               break;
          case 30:
               *bits = 3;
               if (voice_command("AT+VSM=30", "OK") != (0x1000))
                    return((-1));
               break;
          case 4:
               *bits = 4;
               if (voice_command("AT+VSM=4", "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 *


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

reset_watchdog();
voice_modem_state = 2;
voice_command("ATI1", &unk_82B);
voice_read(v1);
voice_read(v1);
voice_command(&unk_82B, "OK");
rom_release = 100 * (v1[10] - 48) + 2 * (5 * v1[12] - 240) + v1[13] - 48;
lprintf(4LL, "ROM release %4.2f detected", (double)rom_release / 100.0);
lprintf(4LL, "initializing ZyXEL 1496 voice modem");
if ( (unsigned int)voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") != 4096 )
lprintf(3LL, "couldn't initialize distinctive RING");
if ( (unsigned int)voice_command("ATS39.6=1 S39.7=0 +VIT=60", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(
v1,
"AT+VDH=%d +VDD=%d",
(unsigned int)((int)(31 * *((_QWORD *)&cvd + 37)) / 100),
(unsigned int)((int)*((_QWORD *)&cvd + 34) / 5));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting DTMF preferences didn't work");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 75LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(255 * *((_QWORD *)&cvd + 82)) / 100));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 75LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(255 * *((_QWORD *)&cvd + 79)) / 100));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VNH=1", "OK") != 4096 )
lprintf(3LL, "can't disable autohangup");
sprintf(v1, "AT+VRA=%d+VRN=%d", *((unsigned int *)&cvd + 398), *((unsigned int *)&cvd + 404));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
voice_modem_state = 1;
return 0LL;
}

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

reset_watchdog();
voice_modem_state = 2;
voice_command("ATI1", &unk_82B);
voice_read(v1);
voice_read(v1);
voice_command(&unk_82B, "OK");
rom_release = 100 * (v1[10] - 48) + 2 * (5 * v1[12] - 240) + v1[13] - 48;
lprintf(4LL, "ROM release %4.2f detected", (double)rom_release / 100.0);
lprintf(4LL, "initializing ZyXEL 1496 voice modem");
if ( (unsigned int)voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") != 4096 )
lprintf(3LL, "couldn't initialize distinctive RING");
if ( (unsigned int)voice_command("ATS39.6=1 S39.7=0 +VIT=60", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(
v1,
"AT+VDH=%d +VDD=%d",
(unsigned int)((int)(31 * *((_QWORD *)&cvd + 37)) / 100),
(unsigned int)((int)*((_QWORD *)&cvd + 34) / 5));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting DTMF preferences didn't work");
sprintf(v1, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 75LL;
sprintf(v1, "AT+VGT=%d", (unsigned int)((int)(255 * *((_QWORD *)&cvd + 82)) / 100));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 75LL;
sprintf(v1, "AT+VGR=%d", (unsigned int)((int)(255 * *((_QWORD *)&cvd + 79)) / 100));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VNH=1", "OK") != 4096 )
lprintf(3LL, "can't disable autohangup");
sprintf(v1, "AT+VRA=%d+VRN=%d", *((unsigned int *)&cvd + 398), *((unsigned int *)&cvd + 404));
if ( (unsigned int)voice_command(v1, "OK") != 4096 )
lprintf(3LL, "setting ringback delay didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int ZyXEL_1496_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     voice_command("ATI1", "");
     voice_read(buffer);
     voice_read(buffer);
     voice_command("", "OK");
     rom_release = 100 * (buffer[10] - '0') + 10 *
      (buffer[12] - '0') + (buffer[13] - '0');
     lprintf(4, "ROM release %4.2f detected", rom_release / 100.0);
     lprintf(4, "initializing ZyXEL 1496 voice modem");
     if (voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     if (voice_command("ATS39.6=1 S39.7=0 +VIT=60", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDH=%d +VDD=%d", (int)cvd.dtmf_threshold.d.i *
      31 / 100, (int)cvd.dtmf_len.d.i / 5);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting DTMF preferences didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 75;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 255 / 100);
     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 = 75;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 255 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VNH=1", "OK") != (0x1000))
          lprintf(3, "can't disable autohangup");
     sprintf(buffer, "AT+VRA=%d+VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int ZyXEL_1496_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     voice_command("ATI1", "");
     voice_read(buffer);
     voice_read(buffer);
     voice_command("", "OK");
     rom_release = 100 * (buffer[10] - '0') + 10 *
      (buffer[12] - '0') + (buffer[13] - '0');
     lprintf(4, "ROM release %4.2f detected", rom_release / 100.0);
     lprintf(4, "initializing ZyXEL 1496 voice modem");
     if (voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     if (voice_command("ATS39.6=1 S39.7=0 +VIT=60", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDH=%d +VDD=%d", (int)cvd.dtmf_threshold.d.i *
      31 / 100, (int)cvd.dtmf_len.d.i / 5);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting DTMF preferences didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 75;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 255 / 100);
     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 = 75;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 255 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VNH=1", "OK") != (0x1000))
          lprintf(3, "can't disable autohangup");
     sprintf(buffer, "AT+VRA=%d+VRN=%d",
      (int)cvd.ringback_goes_away.d.i, (int)cvd.ringback_never_came.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3,"setting ringback delay didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

variable_types:
buffer
char [-1]


original_code:
void Gsm_Coder (struct gsm_state * S, word * s, word * LARc, word * Nc, word * bc, word * Mc, word * xmaxc, word * xMc)
{
     int k;
     word * dp = S->dp0 + 120;
     word * dpp = dp;
     static word e [50] = {0};
     word so[160];
     Gsm_Preprocess (S, s, so);
     Gsm_LPC_Analysis (S, so, LARc);
     Gsm_Short_Term_Analysis_Filter (S, LARc, so);
     for (k = 0; k <= 3; k++, xMc += 13) {
          Gsm_Long_Term_Predictor ( S,
                          so+k*40,
                          dp,
                         e + 5,
                         dpp,
                          Nc++,
                          bc++);
          Gsm_RPE_Encoding ( S,
                         e + 5,
                           xmaxc++, Mc++, xMc );
          { register int i;
            register longword ltmp;
            for (i = 0; i <= 39; i++)
               dp[ i ] = ((ulongword)((ltmp = (longword)(e[5 + i]) + (longword)(dpp[i])) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp);
          }
          dp += 40;
          dpp += 40;
     }
     (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
          120 * sizeof(*S->dp0) );
}

canonical_original_code:
void Gsm_Coder(struct gsm_state *S, short *s, short *LARc, short *Nc, short *bc, short *Mc, short *xmaxc, short *xMc)
{
     int k;
     short *dp = S->dp0 + 120;
     short *dpp = dp;
     static short e[50] = {0};
     short so[160];
     Gsm_Preprocess (S, s, so);
     Gsm_LPC_Analysis (S, so, LARc);
     Gsm_Short_Term_Analysis_Filter (S, LARc, so);
     for (k = 0; k <= 3; k++, xMc += 13) {
          Gsm_Long_Term_Predictor ( S,
                          so+k*40,
                          dp,
                         e + 5,
                         dpp,
                          Nc++,
                          bc++);
          Gsm_RPE_Encoding ( S,
                         e + 5,
                           xmaxc++, Mc++, xMc );
          { register int i;
            register long ltmp;
            for (i = 0; i <= 39; i++)
               dp[ i ] = ((ulongword)((ltmp = (longword)(e[5 + i]) + (longword)(dpp[i])) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp);
          }
          dp += 40;
          dpp += 40;
     }
     (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
          120 * sizeof(*S->dp0) );
}

variable_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; } *

variable_types:
s
short *

variable_types:
LARc
short *

variable_types:
Nc
short *

variable_types:
bc
short *

variable_types:
Mc
short *

variable_types:
xmaxc
short *

variable_types:
xMc
short *

variable_types: k int

variable_types:
dp
short *

variable_types:
dpp
short *

variable_types:
e
short [50]

variable_types:
so
short [160]

variable_types: i int

variable_types: ltmp long

return_type: void


decompiled_code:
__int64 __fastcall gsm_add(__int16 a1, __int16 a2)
{
__int64 result; // rax

result = a1 + (__int64)a2;
if ( result > 0x7FFF )
result = 0x7FFFLL;
if ( result < -32768 )
result = -32768LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, __int16 a2)
{
__int64 result; // rax

result = a1 + (__int64)a2;
if ( result > 0x7FFF )
result = 0x7FFFLL;
if ( result < -32768 )
result = -32768LL;
return result;
}

variable_types: a short

variable_types: b short

variable_types: sum long

return_type: short


decompiled_code:
__int64 __fastcall gsm_sub(__int16 a1, __int16 a2)
{
__int64 result; // rax

result = a1 - (__int64)a2;
if ( result > 0x7FFF )
result = 0x7FFFLL;
if ( result < -32768 )
result = -32768LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, __int16 a2)
{
__int64 result; // rax

result = a1 - (__int64)a2;
if ( result > 0x7FFF )
result = 0x7FFFLL;
if ( result < -32768 )
result = -32768LL;
return result;
}

original_code:
word gsm_sub (word a, word b)
{
     longword diff = (longword)a - (longword)b;
     return ((diff) < ((-32767)-1) ? ((-32767)-1) : (diff) > ( 32767) ? ( 32767): (diff));
}

canonical_original_code:
short gsm_sub(short a, short b)
{
     long diff = (longword)a - (longword)b;
     return ((diff) < ((-32767)-1) ? ((-32767)-1) : (diff) > ( 32767) ? ( 32767): (diff));
}

variable_types: diff long


decompiled_code:
__int64 __fastcall gsm_mult(__int16 a1, __int16 a2)
{
__int64 result; // rax

if ( a1 != (__int16)0x8000 || (result = 0x7FFFLL, a2 != (__int16)0x8000) )
result = (a2 * (__int64)a1) >> 15;
return result;
}


original_code:
word gsm_mult_r (word a, word b)
{
     if (b == ((-32767)-1) && a == ((-32767)-1)) return ( 32767);
     else {
          longword prod = (longword)a * (longword)b + 16384;
          prod >>= 15;
          return prod & 0xFFFF;
     }
}

canonical_original_code:
short gsm_mult_r(short a, short b)
{
     if (b == ((-32767)-1) && a == ((-32767)-1)) return ( 32767);
     else {
          long prod = (longword)a * (longword)b + 16384;
          prod >>= 15;
          return prod & 0xFFFF;
     }
}

variable_types: prod long


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

result = a1;
if ( (a1 & 0x8000u) != 0 )
{
result = -a1;
if ( (_WORD)a1 == 0x8000 )
result = 0x7FFFLL;
}
return result;
}

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

result = a1;
if ( (a1 & 0x8000u) != 0 )
{
result = -a1;
if ( (_WORD)a1 == 0x8000 )
result = 0x7FFFLL;
}
return result;
}


decompiled_code:
unsigned __int64 __fastcall gsm_L_add(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
{
if ( a2 < 0 )
{
result = a1 + a2;
if ( (unsigned __int64)(-2 - (a1 + a2)) > 0x7FFFFFFE )
result = 0xFFFFFFFF80000000LL;
}
else
{
result = a1 + a2;
}
}
else if ( a2 <= 0 )
{
result = a1 + a2;
}
else
{
result = a1 + a2;
if ( (unsigned __int64)(a1 + a2) > 0x7FFFFFFF )
result = 0x7FFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
{
if ( a2 < 0 )
{
result = a1 + a2;
if ( (unsigned __int64)(-2 - (a1 + a2)) > 0x7FFFFFFE )
result = 0xFFFFFFFF80000000LL;
}
else
{
result = a1 + a2;
}
}
else if ( a2 <= 0 )
{
result = a1 + a2;
}
else
{
result = a1 + a2;
if ( (unsigned __int64)(a1 + a2) > 0x7FFFFFFF )
result = 0x7FFFFFFFLL;
}
return result;
}

original_code:
longword gsm_L_add (longword a, longword b)
{
     if (a < 0) {
          if (b >= 0) return a + b;
          else {
               ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
               return A >= ( 2147483647) ? ((-2147483647)-1) :-(longword)A-2;
          }
     }
     else if (b <= 0) return a + b;
     else {
          ulongword A = (ulongword)a + (ulongword)b;
          return A > ( 2147483647) ? ( 2147483647) : A;
     }
}

canonical_original_code:
long gsm_L_add(long a, long b)
{
     if (a < 0) {
          if (b >= 0) return a + b;
          else {
               unsigned long A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
               return A >= ( 2147483647) ? ((-2147483647)-1) :-(long)A-2;
          }
     }
     else if (b <= 0) return a + b;
     else {
          unsigned long A = (ulongword)a + (ulongword)b;
          return A > ( 2147483647) ? ( 2147483647) : A;
     }
}

variable_types: a long

variable_types: b long

variable_types:
A
unsigned long

return_type: long


decompiled_code:
unsigned __int64 __fastcall gsm_L_sub(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdi
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdi
bool v6; // cf

if ( a1 < 0 )
{
if ( a2 <= 0 )
{
result = a1 - a2;
}
else
{
v4 = a2 - 1 - a1;
v5 = a1 - a2;
v6 = v4 < 0x7FFFFFFF;
result = 0xFFFFFFFF80000000LL;
if ( v6 )
result = v5;
}
}
else if ( a2 < 0 )
{
v3 = a1 - a2 - 1;
if ( v3 > 0x7FFFFFFE )
v3 = 2147483646LL;
result = v3 + 1;
}
else
{
result = a1 - a2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdi
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdi
bool v6; // cf

if ( a1 < 0 )
{
if ( a2 <= 0 )
{
result = a1 - a2;
}
else
{
v4 = a2 - 1 - a1;
v5 = a1 - a2;
v6 = v4 < 0x7FFFFFFF;
result = 0xFFFFFFFF80000000LL;
if ( v6 )
result = v5;
}
}
else if ( a2 < 0 )
{
v3 = a1 - a2 - 1;
if ( v3 > 0x7FFFFFFE )
v3 = 2147483646LL;
result = v3 + 1;
}
else
{
result = a1 - a2;
}
return result;
}

original_code:
longword gsm_L_sub (longword a, longword b)
{
     if (a >= 0) {
          if (b >= 0) return a - b;
          else {
               ulongword A = (ulongword)a + -(b + 1);
               return A >= ( 2147483647) ? ( 2147483647) : (A + 1);
          }
     }
     else if (b <= 0) return a - b;
     else {
          ulongword A = (ulongword)-(a + 1) + b;
          return A >= ( 2147483647) ? ((-2147483647)-1) : -(longword)A - 1;
     }
}

canonical_original_code:
long gsm_L_sub(long a, long b)
{
     if (a >= 0) {
          if (b >= 0) return a - b;
          else {
               unsigned long A = (ulongword)a + -(b + 1);
               return A >= ( 2147483647) ? ( 2147483647) : (A + 1);
          }
     }
     else if (b <= 0) return a - b;
     else {
          unsigned long A = (ulongword)-(a + 1) + b;
          return A >= ( 2147483647) ? ((-2147483647)-1) : -(long)A - 1;
     }
}


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

if ( !a1 )
_assert_fail("a != 0", "add.c", 0x89u, "gsm_norm");
if ( a1 < 0 )
{
result = 0LL;
if ( a1 < -1073741823 )
return result;
LODWORD(a1) = ~(_DWORD)a1;
}
if ( (a1 & 0xFFFF0000) != 0 )
{
if ( (a1 & 0xFF000000) != 0 )
result = (unsigned int)(unsigned __int8)bitoff[BYTE3(a1)] - 1;
else
result = (unsigned int)(unsigned __int8)bitoff[BYTE2(a1)] + 7;
}
else if ( (a1 & 0xFF00) != 0 )
{
result = (unsigned int)(unsigned __int8)bitoff[BYTE1(a1)] + 15;
}
else
{
result = (unsigned int)(unsigned __int8)bitoff[(unsigned __int8)a1] + 23;
}
return result;
}

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

if ( !a1 )
_assert_fail("a != 0", "add.c", 0x89u, "gsm_norm");
if ( a1 < 0 )
{
result = 0LL;
if ( a1 < -1073741823 )
return result;
LODWORD(a1) = ~(_DWORD)a1;
}
if ( (a1 & 0xFFFF0000) != 0 )
{
if ( (a1 & 0xFF000000) != 0 )
result = (unsigned int)(unsigned __int8)bitoff[BYTE3(a1)] - 1;
else
result = (unsigned int)(unsigned __int8)bitoff[BYTE2(a1)] + 7;
}
else if ( (a1 & 0xFF00) != 0 )
{
result = (unsigned int)(unsigned __int8)bitoff[BYTE1(a1)] + 15;
}
else
{
result = (unsigned int)(unsigned __int8)bitoff[(unsigned __int8)a1] + 23;
}
return result;
}


decompiled_code:
__int64 __fastcall gsm_L_asr(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdi

if ( a2 > 31 )
return a1 >> 63;
result = 0LL;
if ( a2 >= -31 )
{
result = a1 << -(char)a2;
v3 = a1 >> a2;
if ( a2 >= 0 )
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdi

if ( a2 > 31 )
return a1 >> 63;
result = 0LL;
if ( a2 >= -31 )
{
result = a1 << -(char)a2;
v3 = a1 >> a2;
if ( a2 >= 0 )
result = v3;
}
return result;
}

original_code:
longword gsm_L_asr (longword a, int n)
{
     if (n >= 32) return -(a < 0);
     if (n <= -32) return 0;
     if (n < 0) return a << -n;
          return a >> n;
}

canonical_original_code:
long gsm_L_asr(long a, int n)
{
     if (n >= 32) return -(a < 0);
     if (n <= -32) return 0;
     if (n < 0) return a << -n;
          return a >> n;
}

variable_types: n int


decompiled_code:
__int64 __fastcall gsm_L_asl(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 31 )
{
if ( a2 < -31 )
{
result = a1 >> 63;
}
else
{
result = a1 << a2;
if ( a2 < 0 )
result = gsm_L_asr(a1, -a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 31 )
{
if ( a2 < -31 )
{
result = a1 >> 63;
}
else
{
result = a1 << a2;
if ( a2 < 0 )
result = func9(a1, -a2);
}
}
return result;
}

original_code:
longword gsm_L_asl (longword a, int n)
{
     if (n >= 32) return 0;
     if (n <= -32) return -(a < 0);
     if (n < 0) return gsm_L_asr(a, -n);
     return a << n;
}

canonical_original_code:
long gsm_L_asl(long a, int n)
{
     if (n >= 32) return 0;
     if (n <= -32) return -(a < 0);
     if (n < 0) return gsm_L_asr(a, -n);
     return a << n;
}


original_code:
word gsm_asr (word a, int n)
{
     if (n >= 16) return -(a < 0);
     if (n <= -16) return 0;
     if (n < 0) return a << -n;
          return a >> n;
}

canonical_original_code:
short gsm_asr(short a, int n)
{
     if (n >= 16) return -(a < 0);
     if (n <= -16) return 0;
     if (n < 0) return a << -n;
          return a >> n;
}


decompiled_code:
__int16 __fastcall gsm_asl(__int16 a1, int a2)
{
int v2; // eax

LOWORD(v2) = 0;
if ( a2 <= 15 )
{
if ( a2 < -15 )
{
LOWORD(v2) = a1 >> 15;
}
else
{
v2 = a1 << a2;
if ( a2 < 0 )
LOWORD(v2) = gsm_asr(a1, -a2);
}
}
return v2;
}

original_code:
word gsm_asl (word a, int n)
{
     if (n >= 16) return 0;
     if (n <= -16) return -(a < 0);
     if (n < 0) return gsm_asr(a, -n);
     return a << n;
}

canonical_original_code:
short gsm_asl(short a, int n)
{
     if (n >= 16) return 0;
     if (n <= -16) return -(a < 0);
     if (n < 0) return gsm_asr(a, -n);
     return a << n;
}


decompiled_code:
__int64 __fastcall gsm_div(unsigned int a1, __int16 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

if ( (a1 & 0x8000u) != 0 || (__int16)a1 > a2 )
_assert_fail("num >= 0 && denum >= num", "add.c", 0xDCu, "gsm_div");
result = a1;
if ( (_WORD)a1 )
{
v3 = (__int16)a1;
v4 = 15;
LOWORD(result) = 0;
do
{
result = (unsigned int)(2 * (__int16)result);
v3 *= 2LL;
if ( a2 <= v3 )
{
v3 -= a2;
result = (unsigned int)(result + 1);
}
--v4;
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, __int16 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

if ( (a1 & 0x8000u) != 0 || (__int16)a1 > a2 )
_assert_fail("num >= 0 && denum >= num", "add.c", 0xDCu, "gsm_div");
result = a1;
if ( (_WORD)a1 )
{
v3 = (__int16)a1;
v4 = 15;
LOWORD(result) = 0;
do
{
result = (unsigned int)(2 * (__int16)result);
v3 *= 2LL;
if ( a2 <= v3 )
{
v3 -= a2;
result = (unsigned int)(result + 1);
}
--v4;
}
while ( v4 );
}
return result;
}

original_code:
word gsm_div (word num, word denum)
{
     longword L_num = num;
     longword L_denum = denum;
     word div = 0;
     int k = 15;
     ((void) sizeof ((num >= 0 && denum >= num) ? 1 : 0), __extension__ ({ if (num >= 0 && denum >= num) ; else __assert_fail ("num >= 0 && denum >= num", "add.c", 220, __extension__ __PRETTY_FUNCTION__); }));
     if (num == 0)
         return 0;
     while (k--) {
          div <<= 1;
          L_num <<= 1;
          if (L_num >= L_denum) {
               L_num -= L_denum;
               div++;
          }
     }
     return div;
}

canonical_original_code:
short gsm_div(short num, short denum)
{
     long L_num = num;
     long L_denum = denum;
     short div = 0;
     int k = 15;
     ((void) sizeof ((num >= 0 && denum >= num) ? 1 : 0), __extension__ ({ if (num >= 0 && denum >= num) ; else __assert_fail ("num >= 0 && denum >= num", "add.c", 220, __extension__ __PRETTY_FUNCTION__); }));
     if (num == 0)
         return 0;
     while (k--) {
          div <<= 1;
          L_num <<= 1;
          if (L_num >= L_denum) {
               L_num -= L_denum;
               div++;
          }
     }
     return div;
}

variable_types: num short

variable_types: denum short

variable_types: div short


decompiled_code:
__int64 no_modem_play_dtmf()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 146LL, "] ", "no_modem_play_dtmf", ":");
lprintf(3LL, "%s: play_dtmf called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 146LL, "] ", "no_modem_play_dtmf", ":");
lprintf(3LL, "%s: play_dtmf called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_play_dtmf(char* number)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 146, "] ", __FUNCTION__, ":"); lprintf(3, "%s: play_dtmf called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_play_dtmf(char *number)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 146, "] ", __FUNCTION__, ":"); lprintf(3, "%s: play_dtmf called", POS);
     return((-1));
     }

variable_types:
number
char *


decompiled_code:
__int64 no_modem_wait()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 140LL, "] ", "no_modem_wait", ":");
lprintf(3LL, "%s: wait called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 140LL, "] ", "no_modem_wait", ":");
lprintf(3LL, "%s: wait called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_wait(int wait_timeout)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 140, "] ", __FUNCTION__, ":"); lprintf(3, "%s: wait called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_voice_mode_on()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 134LL, "] ", "no_modem_voice_mode_on", ":");
lprintf(3LL, "%s: voice_mode_on called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 134LL, "] ", "no_modem_voice_mode_on", ":");
lprintf(3LL, "%s: voice_mode_on called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_voice_mode_on(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 134, "] ", __FUNCTION__, ":"); lprintf(3, "%s: voice_mode_on called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_voice_mode_on()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 134, "] ", __FUNCTION__, ":"); lprintf(3, "%s: voice_mode_on called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_voice_mode_off()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 128LL, "] ", "no_modem_voice_mode_off", ":");
lprintf(3LL, "%s: voice_mode_off called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 128LL, "] ", "no_modem_voice_mode_off", ":");
lprintf(3LL, "%s: voice_mode_off called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_voice_mode_off(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 128, "] ", __FUNCTION__, ":"); lprintf(3, "%s: voice_mode_off called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_voice_mode_off()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 128, "] ", __FUNCTION__, ":"); lprintf(3, "%s: voice_mode_off called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_switch_to_data_fax()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 122LL, "] ", "no_modem_switch_to_data_fax", ":");
lprintf(3LL, "%s: switch_to_data_fax called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 122LL, "] ", "no_modem_switch_to_data_fax", ":");
lprintf(3LL, "%s: switch_to_data_fax called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_switch_to_data_fax(char *mode)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 122, "] ", __FUNCTION__, ":"); lprintf(3, "%s: switch_to_data_fax called", POS);
     return((-1));
     }

variable_types:
mode
char *


decompiled_code:
__int64 no_modem_stop_waiting()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 116LL, "] ", "no_modem_stop_waiting", ":");
lprintf(3LL, "%s: stop_waiting called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func5()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 116LL, "] ", "no_modem_stop_waiting", ":");
lprintf(3LL, "%s: stop_waiting called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_stop_waiting(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 116, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_waiting called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_stop_waiting()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 116, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_waiting called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_stop_recording()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 110LL, "] ", "no_modem_stop_recording", ":");
lprintf(3LL, "%s: stop_recording called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 110LL, "] ", "no_modem_stop_recording", ":");
lprintf(3LL, "%s: stop_recording called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_stop_recording(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 110, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_recording called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_stop_recording()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 110, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_recording called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_stop_playing()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 104LL, "] ", "no_modem_stop_playing", ":");
lprintf(3LL, "%s: stop_playing called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 104LL, "] ", "no_modem_stop_playing", ":");
lprintf(3LL, "%s: stop_playing called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_stop_playing(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 104, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_playing called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_stop_playing()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 104, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_playing called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_stop_dialing()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 98LL, "] ", "no_modem_stop_dialing", ":");
lprintf(3LL, "%s: stop_dialing called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func8()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 98LL, "] ", "no_modem_stop_dialing", ":");
lprintf(3LL, "%s: stop_dialing called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_stop_dialing(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 98, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_dialing called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_stop_dialing()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 98, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_dialing called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_set_device()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 92LL, "] ", "no_modem_set_device", ":");
lprintf(3LL, "%s: set_device called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func9()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 92LL, "] ", "no_modem_set_device", ":");
lprintf(3LL, "%s: set_device called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_set_device(int device)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 92, "] ", __FUNCTION__, ":"); lprintf(3, "%s: set_device called", POS);
     return((-1));
     }

variable_types: device int


decompiled_code:
__int64 no_modem_set_compression()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 86LL, "] ", "no_modem_set_compression", ":");
lprintf(3LL, "%s: set_compression called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func10()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 86LL, "] ", "no_modem_set_compression", ":");
lprintf(3LL, "%s: set_compression called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_set_compression(p_int *compression, p_int *speed, int *bits)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 86, "] ", __FUNCTION__, ":"); lprintf(3, "%s: set_compression called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_set_compression(long *compression, long *speed, int *bits)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 86, "] ", __FUNCTION__, ":"); lprintf(3, "%s: set_compression called", POS);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


decompiled_code:
__int64 no_modem_stop_play_file()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 68LL, "] ", "no_modem_stop_play_file", ":");
lprintf(3LL, "%s: stop_play_file called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func13()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 68LL, "] ", "no_modem_stop_play_file", ":");
lprintf(3LL, "%s: stop_play_file called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_stop_play_file(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 68, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_play_file called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_stop_play_file()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 68, "] ", __FUNCTION__, ":"); lprintf(3, "%s: stop_play_file called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_reset_play_file()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 62LL, "] ", "no_modem_reset_play_file", ":");
lprintf(3LL, "%s: next_play_file called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func14()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 62LL, "] ", "no_modem_reset_play_file", ":");
lprintf(3LL, "%s: next_play_file called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_reset_play_file(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 62, "] ", __FUNCTION__, ":"); lprintf(3, "%s: next_play_file called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_reset_play_file()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 62, "] ", __FUNCTION__, ":"); lprintf(3, "%s: next_play_file called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_start_play_file()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 56LL, "] ", "no_modem_start_play_file", ":");
lprintf(3LL, "%s: start_play_file called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func15()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 56LL, "] ", "no_modem_start_play_file", ":");
lprintf(3LL, "%s: start_play_file called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_start_play_file(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 56, "] ", __FUNCTION__, ":"); lprintf(3, "%s: start_play_file called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_start_play_file()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 56, "] ", __FUNCTION__, ":"); lprintf(3, "%s: start_play_file called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_message_light_on()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 50LL, "] ", "no_modem_message_light_on", ":");
lprintf(3LL, "%s: message_light_on called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func16()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 50LL, "] ", "no_modem_message_light_on", ":");
lprintf(3LL, "%s: message_light_on called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_message_light_on(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 50, "] ", __FUNCTION__, ":"); lprintf(3, "%s: message_light_on called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_message_light_on()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 50, "] ", __FUNCTION__, ":"); lprintf(3, "%s: message_light_on called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_message_light_off()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 44LL, "] ", "no_modem_message_light_off", ":");
lprintf(3LL, "%s: message_light_off called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func17()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 44LL, "] ", "no_modem_message_light_off", ":");
lprintf(3LL, "%s: message_light_off called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_message_light_off(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 44, "] ", __FUNCTION__, ":"); lprintf(3, "%s: message_light_off called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_message_light_off()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 44, "] ", __FUNCTION__, ":"); lprintf(3, "%s: message_light_off called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_init()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 38LL, "] ", "no_modem_init", ":");
lprintf(3LL, "%s: init called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func18()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 38LL, "] ", "no_modem_init", ":");
lprintf(3LL, "%s: init called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_init(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 38, "] ", __FUNCTION__, ":"); lprintf(3, "%s: init called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_init()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 38, "] ", __FUNCTION__, ":"); lprintf(3, "%s: init called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_handle_dle()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 32LL, "] ", "no_modem_handle_dle", ":");
lprintf(3LL, "%s: handle_dle called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func19()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 32LL, "] ", "no_modem_handle_dle", ":");
lprintf(3LL, "%s: handle_dle called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_handle_dle(char data)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 32, "] ", __FUNCTION__, ":"); lprintf(3, "%s: handle_dle called", POS);
     return((-1));
     }

variable_types: data char


decompiled_code:
__int64 no_modem_dial()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 26LL, "] ", "no_modem_dial", ":");
lprintf(3LL, "%s: dial called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func20()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 26LL, "] ", "no_modem_dial", ":");
lprintf(3LL, "%s: dial called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_dial(char *number)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 26, "] ", __FUNCTION__, ":"); lprintf(3, "%s: dial called", POS);
     return((-1));
     }


decompiled_code:
__int64 no_modem_beep()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 20LL, "] ", "no_modem_beep", ":");
lprintf(3LL, "%s: beep called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func21()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 20LL, "] ", "no_modem_beep", ":");
lprintf(3LL, "%s: beep called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_beep(int frequency, int length)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 20, "] ", __FUNCTION__, ":"); lprintf(3, "%s: beep called", POS);
     return((-1));
     }

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 no_modem_answer_phone()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 14LL, "] ", "no_modem_answer_phone", ":");
lprintf(3LL, "%s: answer_phone called", &POS);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func22()
{
sprintf(&POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 14LL, "] ", "no_modem_answer_phone", ":");
lprintf(3LL, "%s: answer_phone called", &POS);
return 0xFFFFFFFFLL;
}

original_code:
static int no_modem_answer_phone(void)
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 14, "] ", __FUNCTION__, ":"); lprintf(3, "%s: answer_phone called", POS);
     return((-1));
     }

canonical_original_code:
static int no_modem_answer_phone()
     {
     sprintf(POS, "%s%s%03d%s%s%s", "no_modem.c", " [", 14, "] ", __FUNCTION__, ":"); lprintf(3, "%s: answer_phone called", POS);
     return((-1));
     }


decompiled_code:
char *__fastcall event_name(unsigned int a1)
{
_DWORD *v1; // rdx
char v2; // si
int v3; // eax
int v4; // ecx

i_1 = 0;
v1 = &unk_F98;
v2 = 0;
v3 = 0x2000;
v4 = 0;
while ( a1 != v3 )
{
++v4;
v1 += 4;
v3 = *(v1 - 4);
v2 = 1;
if ( !v3 )
{
i_1 = v4;
sprintf(tmp_string_0, "0x%04x", a1);
return tmp_string_0;
}
}
if ( v2 )
i_1 = v4;
return (&event_names)[2 * v4];
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
_DWORD *v1; // rdx
char v2; // si
int v3; // eax
int v4; // ecx

i_1 = 0;
v1 = &unk_F98;
v2 = 0;
v3 = 0x2000;
v4 = 0;
while ( a1 != v3 )
{
++v4;
v1 += 4;
v3 = *(v1 - 4);
v2 = 1;
if ( !v3 )
{
i_1 = v4;
sprintf(tmp_string_0, "0x%04x", a1);
return tmp_string_0;
}
}
if ( v2 )
i_1 = v4;
return (&event_names)[2 * v4];
}

original_code:
char *event_name(int event)
     {
     static int i = 0;
     static char tmp_string[10];
     for (i = 0; (event_names[i].number != 0); i++)
          if (event_names[i].number == event)
               return(event_names[i].name);
     sprintf(tmp_string, "0x%04x", event);
     return(tmp_string);
     }

variable_types: event int

variable_types: i int

return_type: char *


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

switch ( voice_modem_state )
{
case 0:
result = (*(__int64 (**)(void))(voice_modem + 384LL))();
break;
case 1:
case 2:
case 3:
case 4:
result = 0LL;
break;
case 5:
result = (*(__int64 (**)(void))(voice_modem + 392LL))();
break;
case 6:
result = (*(__int64 (**)(void))(voice_modem + 400LL))();
break;
case 7:
result = (*(__int64 (**)(void))(voice_modem + 408LL))();
break;
case 8:
result = (*(__int64 (**)(void))(voice_modem + 472LL))();
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( voice_modem_state )
{
case 0:
result = (*(__int64 (**)(void))(voice_modem + 384LL))();
break;
case 1:
case 2:
case 3:
case 4:
result = 0LL;
break;
case 5:
result = (*(__int64 (**)(void))(voice_modem + 392LL))();
break;
case 6:
result = (*(__int64 (**)(void))(voice_modem + 400LL))();
break;
case 7:
result = (*(__int64 (**)(void))(voice_modem + 408LL))();
break;
case 8:
result = (*(__int64 (**)(void))(voice_modem + 472LL))();
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int voice_stop_current_action(void)
     {
     switch (voice_modem_state)
          {
          case (0x0000):
               return(voice_modem->stop_dialing());
          case (0x0005):
               return(voice_modem->stop_playing());
          case (0x0006):
               return(voice_modem->stop_recording());
          case (0x0007):
               return(voice_modem->stop_waiting());
   case (0x0008):
     return(voice_modem->stop_duplex_voice());
          };
     return((0));
     }

canonical_original_code:
int voice_stop_current_action()
     {
     switch (voice_modem_state)
          {
          case (0x0000):
               return(voice_modem->stop_dialing());
          case (0x0005):
               return(voice_modem->stop_playing());
          case (0x0006):
               return(voice_modem->stop_recording());
          case (0x0007):
               return(voice_modem->stop_waiting());
   case (0x0008):
     return(voice_modem->stop_duplex_voice());
          };
     return((0));
     }


decompiled_code:
__int64 __fastcall voice_register_event_handler(__int64 a1)
{
program_handle_event = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
program_handle_event = a1;
return 0LL;
}

original_code:
int voice_register_event_handler(int (*new_program_handle_event) (int event,
 event_data data))
     {
     program_handle_event = new_program_handle_event;
     return((0));
     }

canonical_original_code:
int voice_register_event_handler(int (*new_program_handle_event)(int event, union event_data data))
     {
     program_handle_event = new_program_handle_event;
     return((0));
     }

variable_types: int (*)(int event, union event_data { char c; int i; void *p; struct { int frequency; int length; } beep; } data)


decompiled_code:
__int64 voice_unregister_event_handler()
{
program_handle_event = 0LL;
return 0LL;
}

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

original_code:
int voice_unregister_event_handler(void)
     {
     program_handle_event = ((void *)0);
     return((0));
     }

canonical_original_code:
int voice_unregister_event_handler()
     {
     program_handle_event = ((void *)0);
     return((0));
     }


decompiled_code:
__int64 __fastcall voice_handle_event(signed int a1, __int64 a2)
{
const char *v2; // r13
char *v3; // rax
unsigned int v4; // er12
unsigned int v5; // eax
char *v6; // rax
char v8[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v8[0] = a2;
v8[1] = 0;
v2 = v8;
if ( !(_BYTE)a2 )
v2 = "NUL";
v3 = event_name(a1);
lprintf(6LL, "%s: voice_handle_event got event %s with data <%s>", program_name, v3, v2);
if ( a1 == 8198 && *((_QWORD *)&cvd + 43) )
return 0;
v4 = voice_shell_handle_event((unsigned int)a1, a2);
if ( v4 == -2 )
{
if ( program_handle_event && (v5 = program_handle_event((unsigned int)a1, a2), v5 != -2) )
{
v4 = v5;
}
else
{
if ( a1 > 16387 )
{
if ( (unsigned int)(a1 - 16389) > 1 )
{
switch ( voice_modem_state )
{
case 0:
goto LABEL_14;
case 5:
goto LABEL_17;
case 6:
goto LABEL_20;
case 7:
goto LABEL_24;
case 8:
goto LABEL_22;
default:
goto LABEL_28;
}
}
LABEL_13:
lprintf(4LL, "%s: Received signal to terminate", program_name);
voice_stop_current_action();
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(1LL);
voice_mode_off();
voice_close_device();
voice_unregister_event_handler();
exit(99);
}
if ( a1 > 16385 )
goto LABEL_13;
switch ( voice_modem_state )
{
case 0:
LABEL_14:
if ( (unsigned int)(a1 - 8193) > 5 || ((1LL << ((unsigned __int8)a1 - 1)) & 0x29) == 0 )
goto LABEL_26;
v4 = (*(__int64 (**)(void))(voice_modem + 384LL))();
break;
case 5:
LABEL_17:
if ( (unsigned int)(a1 - 8193) > 8 || ((1LL << ((unsigned __int8)a1 - 1)) & 0x1ED) == 0 )
goto LABEL_26;
v4 = (*(__int64 (**)(void))(voice_modem + 392LL))();
break;
case 6:
LABEL_20:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8199:
case 8200:
case 8201:
case 8206:
case 8210:
v4 = (*(__int64 (**)(void))(voice_modem + 400LL))();
break;
default:
goto LABEL_26;
}
break;
case 7:
LABEL_24:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8201:
case 8207:
v4 = (*(__int64 (**)(void))(voice_modem + 408LL))();
break;
default:
goto LABEL_26;
}
break;
case 8:
LABEL_22:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8201:
case 8206:
case 8210:
v4 = (*(__int64 (**)(void))(voice_modem + 472LL))();
break;
default:
goto LABEL_26;
}
break;
default:
LABEL_26:
if ( a1 == 0x4000 )
{
alarm(*((_DWORD *)&cvd + 152));
v4 = 0;
}
else
{
LABEL_28:
v8[0] = a2;
v6 = event_name(a1);
lprintf(6LL, "%s: voice_handle_event got unknown event %s with data <%s>", program_name, v6, v2);
}
break;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(signed int a1, __int64 a2)
{
const char *v2; // r13
char *v3; // rax
unsigned int v4; // er12
unsigned int v5; // eax
char *v6; // rax
char v8[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v8[0] = a2;
v8[1] = 0;
v2 = v8;
if ( !(_BYTE)a2 )
v2 = "NUL";
v3 = func0(a1);
lprintf(6LL, "%s: voice_handle_event got event %s with data <%s>", program_name, v3, v2);
if ( a1 == 8198 && *((_QWORD *)&cvd + 43) )
return 0;
v4 = voice_shell_handle_event((unsigned int)a1, a2);
if ( v4 == -2 )
{
if ( program_handle_event && (v5 = program_handle_event((unsigned int)a1, a2), v5 != -2) )
{
v4 = v5;
}
else
{
if ( a1 > 16387 )
{
if ( (unsigned int)(a1 - 16389) > 1 )
{
switch ( voice_modem_state )
{
case 0:
goto LABEL_14;
case 5:
goto LABEL_17;
case 6:
goto LABEL_20;
case 7:
goto LABEL_24;
case 8:
goto LABEL_22;
default:
goto LABEL_28;
}
}
LABEL_13:
lprintf(4LL, "%s: Received signal to terminate", program_name);
func1();
(*(void (__fastcall **)(__int64))(voice_modem + 376LL))(1LL);
voice_mode_off();
voice_close_device();
func3();
exit(99);
}
if ( a1 > 16385 )
goto LABEL_13;
switch ( voice_modem_state )
{
case 0:
LABEL_14:
if ( (unsigned int)(a1 - 8193) > 5 || ((1LL << ((unsigned __int8)a1 - 1)) & 0x29) == 0 )
goto LABEL_26;
v4 = (*(__int64 (**)(void))(voice_modem + 384LL))();
break;
case 5:
LABEL_17:
if ( (unsigned int)(a1 - 8193) > 8 || ((1LL << ((unsigned __int8)a1 - 1)) & 0x1ED) == 0 )
goto LABEL_26;
v4 = (*(__int64 (**)(void))(voice_modem + 392LL))();
break;
case 6:
LABEL_20:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8199:
case 8200:
case 8201:
case 8206:
case 8210:
v4 = (*(__int64 (**)(void))(voice_modem + 400LL))();
break;
default:
goto LABEL_26;
}
break;
case 7:
LABEL_24:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8201:
case 8207:
v4 = (*(__int64 (**)(void))(voice_modem + 408LL))();
break;
default:
goto LABEL_26;
}
break;
case 8:
LABEL_22:
switch ( a1 )
{
case 8193:
case 8195:
case 8196:
case 8198:
case 8201:
case 8206:
case 8210:
v4 = (*(__int64 (**)(void))(voice_modem + 472LL))();
break;
default:
goto LABEL_26;
}
break;
default:
LABEL_26:
if ( a1 == 0x4000 )
{
alarm(*((_DWORD *)&cvd + 152));
v4 = 0;
}
else
{
LABEL_28:
v8[0] = a2;
v6 = func0(a1);
lprintf(6LL, "%s: voice_handle_event got unknown event %s with data <%s>", program_name, v6, v2);
}
break;
}
}
}
return v4;
}

original_code:
int voice_handle_event(int event, event_data data)
     {
     int result;
     char buffer[2];
     buffer[0] = data.c;
     buffer[1] = '\0';
     lprintf(6,
             "%s: voice_handle_event got event %s with data <%s>",
             program_name,
             event_name(event),
             data.c ? buffer
                    : "NUL");
     if ((event == (0x2006)) && (cvd.ignore_fax_dle.d.i))
          return((0));
     if ((result = voice_shell_handle_event(event, data)) != (-2))
          return(result);
     if (program_handle_event != ((void *)0))
          if ((result = program_handle_event(event, data)) != (-2))
               return(result);
     switch (event)
          {
          case (0x4002):
          case (0x4003):
          case (0x4005):
          case (0x4006):
               lprintf(4, "%s: Received signal to terminate",
                program_name);
               voice_stop_current_action();
               voice_modem->set_device((0x0001));
               voice_mode_off();
               voice_close_device();
               voice_unregister_event_handler();
               exit(99);
          };
     switch (voice_modem_state)
          {
          case (0x0000):
               switch (event)
                    {
                    case (0x2001):
                    case (0x2004):
                    case (0x2006):
                         return(voice_modem->stop_dialing());
                    };
               break;
          case (0x0005):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x2008):
                    case (0x2007):
                         return(voice_modem->stop_playing());
                    };
               break;
          case (0x0006):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200e):
                    case (0x2012):
                    case (0x2008):
                    case (0x2007):
                         return(voice_modem->stop_recording());
                    };
               break;
   case (0x0008):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200e):
                    case (0x2012):
                         return(voice_modem->stop_duplex_voice());
                    };
        break;
          case (0x0007):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200f):
                         return(voice_modem->stop_waiting());
                    };
               break;
          };
     if (event == (0x4000))
          {
          alarm(cvd.watchdog_timeout.d.i);
          return((0));
          }
     buffer[0] = data.c;
     lprintf(6,
             "%s: voice_handle_event got unknown event %s with data <%s>",
             program_name, event_name(event), data.c ? buffer : "NUL");
     return((-2));
     }

canonical_original_code:
int voice_handle_event(int event, union event_data data)
     {
     int result;
     char buffer[2];
     buffer[0] = data.c;
     buffer[1] = '\0';
     lprintf(6,
             "%s: voice_handle_event got event %s with data <%s>",
             program_name,
             event_name(event),
             data.c ? buffer
                    : "NUL");
     if ((event == (0x2006)) && (cvd.ignore_fax_dle.d.i))
          return((0));
     if ((result = voice_shell_handle_event(event, data)) != (-2))
          return(result);
     if (program_handle_event != ((void *)0))
          if ((result = program_handle_event(event, data)) != (-2))
               return(result);
     switch (event)
          {
          case (0x4002):
          case (0x4003):
          case (0x4005):
          case (0x4006):
               lprintf(4, "%s: Received signal to terminate",
                program_name);
               voice_stop_current_action();
               voice_modem->set_device((0x0001));
               voice_mode_off();
               voice_close_device();
               voice_unregister_event_handler();
               exit(99);
          };
     switch (voice_modem_state)
          {
          case (0x0000):
               switch (event)
                    {
                    case (0x2001):
                    case (0x2004):
                    case (0x2006):
                         return(voice_modem->stop_dialing());
                    };
               break;
          case (0x0005):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x2008):
                    case (0x2007):
                         return(voice_modem->stop_playing());
                    };
               break;
          case (0x0006):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200e):
                    case (0x2012):
                    case (0x2008):
                    case (0x2007):
                         return(voice_modem->stop_recording());
                    };
               break;
   case (0x0008):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200e):
                    case (0x2012):
                         return(voice_modem->stop_duplex_voice());
                    };
        break;
          case (0x0007):
               switch (event)
                    {
                    case (0x2009):
                    case (0x2001):
                    case (0x2003):
                    case (0x2004):
                    case (0x2006):
                    case (0x200f):
                         return(voice_modem->stop_waiting());
                    };
               break;
          };
     if (event == (0x4000))
          {
          alarm(cvd.watchdog_timeout.d.i);
          return((0));
          }
     buffer[0] = data.c;
     lprintf(6,
             "%s: voice_handle_event got unknown event %s with data <%s>",
             program_name, event_name(event), data.c ? buffer : "NUL");
     return((-2));
     }

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

variable_types: result int

variable_types:
buffer
char [2]


decompiled_code:
void __fastcall clear_event(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func5(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void clear_event(event_type* event)
     {
     if (event != ((void *)0))
          free(event);
     event = ((void *)0);
     }

canonical_original_code:
void clear_event(struct event_type *event)
     {
     if (event != ((void *)0))
          free(event);
     event = ((void *)0);
     }

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

user_defined_types: struct event_type { int event; union event_data data; }


decompiled_code:
__int64 __fastcall queue_event(unsigned int *a1)
{
int v1; // ebx
__int64 v2; // rax
unsigned __int64 v3; // rax
char *v4; // rax
__int64 result; // rax

v1 = last_event;
++event_queue[4 * last_event];
if ( ++event_count > 63 )
{
lprintf(3LL, "%s: event queue full, ignoring event", program_name);
--event_queue[4 * v1];
--event_count;
result = 0xFFFFFFFFLL;
}
else
{
if ( event_queue[4 * v1] > 1 )
{
do
{
--event_queue[4 * v1];
v1 = (v1 + 1) % 64;
v2 = 4LL * v1;
++event_queue[v2];
}
while ( event_queue[v2] > 1 );
}
last_event = (last_event + 1) % 64;
v3 = 4LL * v1;
qword_728[v3 / 2] = (__int64)a1;
--event_queue[v3];
v4 = event_name(*a1);
lprintf(6LL, "%s: queued event %s at position %04d", program_name, v4, (unsigned int)v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
int v1; // ebx
__int64 v2; // rax
unsigned __int64 v3; // rax
char *v4; // rax
__int64 result; // rax

v1 = last_event;
++event_queue[4 * last_event];
if ( ++event_count > 63 )
{
lprintf(3LL, "%s: event queue full, ignoring event", program_name);
--event_queue[4 * v1];
--event_count;
result = 0xFFFFFFFFLL;
}
else
{
if ( event_queue[4 * v1] > 1 )
{
do
{
--event_queue[4 * v1];
v1 = (v1 + 1) % 64;
v2 = 4LL * v1;
++event_queue[v2];
}
while ( event_queue[v2] > 1 );
}
last_event = (last_event + 1) % 64;
v3 = 4LL * v1;
qword_728[v3 / 2] = (__int64)a1;
--event_queue[v3];
v4 = func0(*a1);
lprintf(6LL, "%s: queued event %s at position %04d", program_name, v4, (unsigned int)v1);
result = 0LL;
}
return result;
}

original_code:
int queue_event(event_type* event)
     {
     int event_number = last_event;
     event_queue[event_number].write_lock++;
     event_count++;
     if (event_count >= 64)
          {
          lprintf(3, "%s: event queue full, ignoring event", program_name);
          event_queue[event_number].write_lock--;
          event_count--;
          return((-1));
          };
     while(event_queue[event_number].write_lock > 1)
          {
          event_queue[event_number].write_lock--;
          event_number = (event_number + 1) % 64;
          event_queue[event_number].write_lock++;
          };
     last_event = (last_event + 1) % 64;
     event_queue[event_number].event = event;
     event_queue[event_number].write_lock--;
     lprintf(6, "%s: queued event %s at position %04d", program_name, event_name(event->event),
      event_number);
     return((0));
     }

canonical_original_code:
int queue_event(struct event_type *event)
     {
     int event_number = last_event;
     event_queue[event_number].write_lock++;
     event_count++;
     if (event_count >= 64)
          {
          lprintf(3, "%s: event queue full, ignoring event", program_name);
          event_queue[event_number].write_lock--;
          event_count--;
          return((-1));
          };
     while(event_queue[event_number].write_lock > 1)
          {
          event_queue[event_number].write_lock--;
          event_number = (event_number + 1) % 64;
          event_queue[event_number].write_lock++;
          };
     last_event = (last_event + 1) % 64;
     event_queue[event_number].event = event;
     event_queue[event_number].write_lock--;
     lprintf(6, "%s: queued event %s at position %04d", program_name, event_name(event->event),
      event_number);
     return((0));
     }

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


decompiled_code:
__int64 reset_watchdog()
{
unsigned int *v0; // rax

v0 = create_event(0x4000);
return queue_event(v0);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int *v0; // rax

v0 = create_event(0x4000);
return func6(v0);
}

original_code:
void reset_watchdog(void)
     {
     queue_event(create_event((0x4000)));
     }

canonical_original_code:
void reset_watchdog()
     {
     queue_event(create_event((0x4000)));
     }


decompiled_code:
__int64 unqueue_event()
{
int v0; // ebx
__int64 v1; // rax
unsigned __int64 v2; // rbp
char *v3; // rax
__int64 result; // rax

v0 = first_event;
++dword_724[4 * first_event];
if ( --event_count < 0 )
{
--dword_724[4 * v0];
++event_count;
result = 0LL;
}
else
{
if ( event_queue[4 * v0 + 1] > 1 )
{
do
{
--dword_724[4 * v0];
v0 = (v0 + 1) % 64;
v1 = 4LL * v0;
++dword_724[v1];
}
while ( event_queue[v1 + 1] > 1 );
}
if ( event_queue[4 * v0] > 0 )
{
--dword_724[4 * v0];
++event_count;
result = 0LL;
}
else
{
first_event = (first_event + 1) % 64;
v2 = 16LL * v0;
--dword_724[v2 / 4];
v3 = event_name(*(_DWORD *)qword_728[v2 / 8]);
lprintf(6LL, "%s: unqueued event %s at position %04d", program_name, v3, (unsigned int)v0);
result = qword_728[v2 / 8];
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
__int64 v1; // rax
unsigned __int64 v2; // rbp
char *v3; // rax
__int64 result; // rax

v0 = first_event;
++dword_724[4 * first_event];
if ( --event_count < 0 )
{
--dword_724[4 * v0];
++event_count;
result = 0LL;
}
else
{
if ( event_queue[4 * v0 + 1] > 1 )
{
do
{
--dword_724[4 * v0];
v0 = (v0 + 1) % 64;
v1 = 4LL * v0;
++dword_724[v1];
}
while ( event_queue[v1 + 1] > 1 );
}
if ( event_queue[4 * v0] > 0 )
{
--dword_724[4 * v0];
++event_count;
result = 0LL;
}
else
{
first_event = (first_event + 1) % 64;
v2 = 16LL * v0;
--dword_724[v2 / 4];
v3 = func0(*(_DWORD *)qword_728[v2 / 8]);
lprintf(6LL, "%s: unqueued event %s at position %04d", program_name, v3, (unsigned int)v0);
result = qword_728[v2 / 8];
}
}
return result;
}

original_code:
event_type* unqueue_event(void)
     {
     int event_number = first_event;
     event_queue[event_number].read_lock++;
     event_count--;
     if (event_count < 0)
          {
          event_queue[event_number].read_lock--;
          event_count++;
          return(((void *)0));
          };
     while(event_queue[event_number].read_lock > 1)
          {
          event_queue[event_number].read_lock--;
          event_number = (event_number + 1) % 64;
          event_queue[event_number].read_lock++;
          };
     if (event_queue[event_number].write_lock > 0)
          {
          event_queue[event_number].read_lock--;
          event_count++;
          return(((void *)0));
          };
     first_event = (first_event + 1) % 64;
     event_queue[event_number].read_lock--;
     lprintf(6, "%s: unqueued event %s at position %04d", program_name,
      event_name(event_queue[event_number].event->event), event_number);
     return(event_queue[event_number].event);
     }

canonical_original_code:
struct event_type *unqueue_event()
     {
     int event_number = first_event;
     event_queue[event_number].read_lock++;
     event_count--;
     if (event_count < 0)
          {
          event_queue[event_number].read_lock--;
          event_count++;
          return(((void *)0));
          };
     while(event_queue[event_number].read_lock > 1)
          {
          event_queue[event_number].read_lock--;
          event_number = (event_number + 1) % 64;
          event_queue[event_number].read_lock++;
          };
     if (event_queue[event_number].write_lock > 0)
          {
          event_queue[event_number].read_lock--;
          event_count++;
          return(((void *)0));
          };
     first_event = (first_event + 1) % 64;
     event_queue[event_number].read_lock--;
     lprintf(6, "%s: unqueued event %s at position %04d", program_name,
      event_name(event_queue[event_number].event->event), event_number);
     return(event_queue[event_number].event);
     }

return_type: struct event_type { int event; union event_data { char c; int i; void *p; struct { int frequency; int length; } beep; } data; } *


decompiled_code:
__int64 voice_check_events()
{
__int64 result; // rax
void *v1; // rbx

while ( 1 )
{
result = unqueue_event();
v1 = (void *)result;
if ( !result )
break;
if ( (unsigned int)voice_handle_event(*(_DWORD *)result, *(_QWORD *)(result + 8)) == -1 )
{
lprintf(3LL, "%s: Could not handle event, something failed", program_name);
exit(99);
}
clear_event(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
void *v1; // rbx

while ( 1 )
{
result = func8();
v1 = (void *)result;
if ( !result )
break;
if ( (unsigned int)func4(*(_DWORD *)result, *(_QWORD *)(result + 8)) == -1 )
{
lprintf(3LL, "%s: Could not handle event, something failed", program_name);
exit(99);
}
func5(v1);
}
return result;
}

original_code:
void voice_check_events(void)
     {
     event_type* event;
     while ((event = unqueue_event()) != ((void *)0))
          {
          if (voice_handle_event(event->event, event->data) == (-1))
               {
               lprintf(3, "%s: Could not handle event, something failed", program_name);
               exit(99);
               };
          clear_event(event);
          };
     }

canonical_original_code:
void voice_check_events()
     {
     struct event_type *event;
     while ((event = unqueue_event()) != ((void *)0))
          {
          if (voice_handle_event(event->event, event->data) == (-1))
               {
               lprintf(3, "%s: Could not handle event, something failed", program_name);
               exit(99);
               };
          clear_event(event);
          };
     }


Postprocessing

original_code:
static void Postprocessing (struct gsm_state * S, register word * s)
{
     register int k;
     register word msr = S->msr;
     register longword ltmp;
     register word tmp;
     for (k = 160; k--; s++) {
          tmp = (((((longword)(msr) * (longword)(28180) + 16384)) >> (15)));
          msr = ((ulongword)((ltmp = (longword)(*s) + (longword)(tmp)) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp);
          *s = ((ulongword)((ltmp = (longword)(msr) + (longword)(msr)) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp) & 0xFFF8;
     }
     S->msr = msr;
}

canonical_original_code:
static void Postprocessing(struct gsm_state *S, short *s)
{
     register int k;
     register short msr = S->msr;
     register long ltmp;
     register short tmp;
     for (k = 160; k--; s++) {
          tmp = (((((longword)(msr) * (longword)(28180) + 16384)) >> (15)));
          msr = ((ulongword)((ltmp = (longword)(*s) + (longword)(tmp)) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp);
          *s = ((ulongword)((ltmp = (longword)(msr) + (longword)(msr)) - ((-32767)-1)) > ( 32767) - ((-32767)-1) ? (ltmp > 0 ? ( 32767) : ((-32767)-1)) : ltmp) & 0xFFF8;
     }
     S->msr = msr;
}

variable_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; } *

variable_types:
s
short *

variable_types: k int

variable_types: msr short

variable_types: ltmp long

variable_types: tmp short


decompiled_code:
__int64 __fastcall Gsm_Decoder(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int16 *a8)
{
char *v11; // rbp
__int64 i; // r12
__int64 j; // rax
char v17[320]; // [rsp+20h] [rbp-1C8h] BYREF
char v18[136]; // [rsp+160h] [rbp-88h] BYREF

v11 = v17;
for ( i = 0LL; i != 8; i += 2LL )
{
Gsm_RPE_Decoding(a1, (unsigned int)*(__int16 *)(a6 + i), (unsigned int)*(__int16 *)(a5 + i), a7, v18);
Gsm_Long_Term_Synthesis_Filtering(
a1,
(unsigned int)*(__int16 *)(a3 + i),
(unsigned int)*(__int16 *)(a4 + i),
v18,
a1 + 240);
for ( j = 0LL; j != 80; j += 2LL )
*(_WORD *)&v11[j] = *(_WORD *)(a1 + j + 240);
a7 += 26LL;
v11 += 80;
}
Gsm_Short_Term_Synthesis_Filter(a1, a2, v17, a8);
return Postprocessing(a1, a8);
}

original_code:
void Gsm_Decoder (struct gsm_state * S, word * LARcr, word * Ncr, word * bcr, word * Mcr, word * xmaxcr, word * xMcr, word * s)
{
     int j, k;
     word erp[40], wt[160];
     word * drp = S->dp0 + 120;
     for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {
          Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
          Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
          for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ];
     }
     Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
     Postprocessing(S, s);
}

canonical_original_code:
void Gsm_Decoder(struct gsm_state *S, short *LARcr, short *Ncr, short *bcr, short *Mcr, short *xmaxcr, short *xMcr, short *s)
{
     int j; int k;
     short erp[40]; short wt[160];
     short *drp = S->dp0 + 120;
     for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {
          Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
          Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
          for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ];
     }
     Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
     Postprocessing(S, s);
}

variable_types:
LARcr
short *

variable_types:
Ncr
short *

variable_types:
bcr
short *

variable_types:
Mcr
short *

variable_types:
xmaxcr
short *

variable_types:
xMcr
short *

variable_types: j int

variable_types:
erp
short [40]

variable_types:
wt
short [160]

variable_types:
drp
short *

user_defined_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; }


decompiled_code:
__int64 __fastcall mg_init_data(__int64 a1, __int64 a2, char a3, __int64 a4)
{
__int64 result; // rax
int v7; // eax
int v8; // ebx
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

result = do_chat(a1, a2, &init_chat_actions, v9, 20LL, 1LL);
if ( (_DWORD)result )
{
if ( a3 )
{
v7 = tio_get_rs232_lines((unsigned int)a1);
if ( v7 != -1 && (v7 & 0x120) == 0 )
{
lprintf(3LL, "No DSR/CTS signals, assuming modem is switched off, waiting...");
while ( (tio_get_rs232_lines((unsigned int)a1) & 0x120) == 0 )
sleep(0x3Cu);
}
}
if ( !v9[0] && a4 )
{
lprintf(3LL, "init chat timed out, trying force-init-chat");
if ( (unsigned int)do_chat((unsigned int)a1, a4, &init_chat_actions, v9, 20LL, 1LL) && !v9[0] )
{
v8 = 4;
goto LABEL_16;
}
lprintf(5LL, "force-init succeeded, retrying init-chat");
clean_line((unsigned int)a1, 3LL);
result = do_chat((unsigned int)a1, a2, &init_chat_actions, v9, 20LL, 1LL);
if ( !(_DWORD)result )
return result;
}
v8 = v9[0] == 0 ? 4 : 22;
LABEL_16:
*_errno_location() = v8;
lprintf(1LL, "init chat failed, exiting...");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, char a3, __int64 a4)
{
__int64 result; // rax
int v7; // eax
int v8; // ebx
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

result = do_chat(a1, a2, &init_chat_actions, v9, 20LL, 1LL);
if ( (_DWORD)result )
{
if ( a3 )
{
v7 = tio_get_rs232_lines((unsigned int)a1);
if ( v7 != -1 && (v7 & 0x120) == 0 )
{
lprintf(3LL, "No DSR/CTS signals, assuming modem is switched off, waiting...");
while ( (tio_get_rs232_lines((unsigned int)a1) & 0x120) == 0 )
sleep(0x3Cu);
}
}
if ( !v9[0] && a4 )
{
lprintf(3LL, "init chat timed out, trying force-init-chat");
if ( (unsigned int)do_chat((unsigned int)a1, a4, &init_chat_actions, v9, 20LL, 1LL) && !v9[0] )
{
v8 = 4;
goto LABEL_16;
}
lprintf(5LL, "force-init succeeded, retrying init-chat");
clean_line((unsigned int)a1, 3LL);
result = do_chat((unsigned int)a1, a2, &init_chat_actions, v9, 20LL, 1LL);
if ( !(_DWORD)result )
return result;
}
v8 = v9[0] == 0 ? 4 : 22;
LABEL_16:
*_errno_location() = v8;
lprintf(1LL, "init chat failed, exiting...");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mg_init_data (int fd,char * chat_seq[],boolean need_dsr,char * force_chat_seq[])
{
    action_t what_action;
    if ( do_chat( fd, chat_seq, init_chat_actions,
   &what_action, init_chat_timeout, (1==1) ) == 0 )
    {
 return 0;
    }
    if ( need_dsr )
    {
        int rs_lines = tio_get_rs232_lines(fd);
 if ( rs_lines != -1 &&
       (rs_lines & (0x100|0x020) ) == 0 )
 {
     lprintf( 3, "No DSR/CTS signals, assuming modem is switched off, waiting..." );
     while( (tio_get_rs232_lines(fd) & (0x100|0x020) ) == 0)
     {
  sleep(60);
     }
 }
    }
    if ( what_action == A_TIMOUT && force_chat_seq != ((void *)0) )
    {
 lprintf( 3, "init chat timed out, trying force-init-chat" );
 if ( do_chat( fd, force_chat_seq, init_chat_actions,
       &what_action, init_chat_timeout, (1==1) ) == 0 ||
      what_action != A_TIMOUT )
        {
     lprintf( 5, "force-init succeeded, retrying init-chat");
     clean_line(fd, 3);
     if ( do_chat( fd, chat_seq, init_chat_actions,
    &what_action, init_chat_timeout, (1==1) ) == 0 )
     {
  return 0;
     }
        }
    }
    (*__errno_location ()) = ( what_action == A_TIMOUT )? 4: 22;
    lprintf( 1, "init chat failed, exiting..." );
    return -1;
}

canonical_original_code:
int mg_init_data(int fd, char *chat_seq[], char need_dsr, char *force_chat_seq[])
{
    enum action_t what_action;
    if ( do_chat( fd, chat_seq, init_chat_actions,
   &what_action, init_chat_timeout, (1==1) ) == 0 )
    {
 return 0;
    }
    if ( need_dsr )
    {
        int rs_lines = tio_get_rs232_lines(fd);
 if ( rs_lines != -1 &&
       (rs_lines & (0x100|0x020) ) == 0 )
 {
     lprintf( 3, "No DSR/CTS signals, assuming modem is switched off, waiting..." );
     while( (tio_get_rs232_lines(fd) & (0x100|0x020) ) == 0)
     {
  sleep(60);
     }
 }
    }
    if ( what_action == A_TIMOUT && force_chat_seq != ((void *)0) )
    {
 lprintf( 3, "init chat timed out, trying force-init-chat" );
 if ( do_chat( fd, force_chat_seq, init_chat_actions,
       &what_action, init_chat_timeout, (1==1) ) == 0 ||
      what_action != A_TIMOUT )
        {
     lprintf( 5, "force-init succeeded, retrying init-chat");
     clean_line(fd, 3);
     if ( do_chat( fd, chat_seq, init_chat_actions,
    &what_action, init_chat_timeout, (1==1) ) == 0 )
     {
  return 0;
     }
        }
    }
    (*__errno_location ()) = ( what_action == A_TIMOUT )? 4: 22;
    lprintf( 1, "init chat failed, exiting..." );
    return -1;
}

variable_types: fd int

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


decompiled_code:
__int64 __fastcall mg_init_fax(unsigned int a1, __int64 a2, __int64 a3, char a4, unsigned int a5)
{
int v9; // eax
int v10; // edx
__int64 result; // rax
const char *v12; // rdx
const char *v13; // rdi
const char *v14; // rdi
const char *v15; // rdi
char v16[72]; // [rsp+0h] [rbp-48h] BYREF

v9 = fax_get_modem_type();
modem_type = v9;
if ( v9 == 1 )
{
lprintf(5LL, "no class 2/2.0 faxmodem, no faxing available");
result = 0xFFFFFFFFLL;
}
else
{
if ( (unsigned int)(v9 - 2) <= 1 )
{
v12 = "E";
if ( v9 != 2 )
v12 = "A";
sprintf(v16, "AT+FA%s=%d", v12, a4 == 0);
if ( (unsigned int)mdm_command(v16, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
fax_set_bor(a1, 1LL);
}
if ( modem_type == 5 )
{
v13 = "AT+FAA=0;+FCR=1";
if ( !a4 )
v13 = "AT+FAA=1;+FCR=1";
if ( (unsigned int)mdm_command(v13, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
if ( (unsigned int)fax_set_bor(a1, 1LL) == -1 )
{
lprintf(4LL, "cannot set bit order, trying +BOR=0");
fax_set_bor(a1, 0LL);
}
v14 = "AT+FNR=1,1,1,1";
if ( (modem_quirks & 0x40) == 0 )
v14 = "AT+FNR=1,1,1,0";
mdm_command(v14, a1);
}
if ( modem_type == 4 )
{
v15 = "AT+FAA=0;+FCR=1";
if ( !a4 )
{
if ( (modem_quirks & 1) == 0 && (unsigned int)mdm_command("AT+FCLASS=0", a1) == -1 )
lprintf(4LL, "weird: cannot set class 0");
v15 = "AT+FAA=1;+FCR=1";
}
if ( (unsigned int)mdm_command(v15, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
if ( (unsigned int)fax_set_bor(a1, 0LL) == -1 )
lprintf(4LL, "cannot set bit order. Huh?");
}
fax_set_l_id(a1, a3);
v10 = fax_set_fdcc(a1, 1LL, a5, 0LL);
result = 0LL;
if ( v10 == -1 )
{
lprintf(4LL, "huh? Cannot set +FDCC parameters");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, __int64 a3, char a4, unsigned int a5)
{
int v9; // eax
int v10; // edx
__int64 result; // rax
const char *v12; // rdx
const char *v13; // rdi
const char *v14; // rdi
const char *v15; // rdi
char v16[72]; // [rsp+0h] [rbp-48h] BYREF

v9 = fax_get_modem_type();
modem_type = v9;
if ( v9 == 1 )
{
lprintf(5LL, "no class 2/2.0 faxmodem, no faxing available");
result = 0xFFFFFFFFLL;
}
else
{
if ( (unsigned int)(v9 - 2) <= 1 )
{
v12 = "E";
if ( v9 != 2 )
v12 = "A";
sprintf(v16, "AT+FA%s=%d", v12, a4 == 0);
if ( (unsigned int)mdm_command(v16, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
fax_set_bor(a1, 1LL);
}
if ( modem_type == 5 )
{
v13 = "AT+FAA=0;+FCR=1";
if ( !a4 )
v13 = "AT+FAA=1;+FCR=1";
if ( (unsigned int)mdm_command(v13, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
if ( (unsigned int)fax_set_bor(a1, 1LL) == -1 )
{
lprintf(4LL, "cannot set bit order, trying +BOR=0");
fax_set_bor(a1, 0LL);
}
v14 = "AT+FNR=1,1,1,1";
if ( (modem_quirks & 0x40) == 0 )
v14 = "AT+FNR=1,1,1,0";
mdm_command(v14, a1);
}
if ( modem_type == 4 )
{
v15 = "AT+FAA=0;+FCR=1";
if ( !a4 )
{
if ( (modem_quirks & 1) == 0 && (unsigned int)mdm_command("AT+FCLASS=0", a1) == -1 )
lprintf(4LL, "weird: cannot set class 0");
v15 = "AT+FAA=1;+FCR=1";
}
if ( (unsigned int)mdm_command(v15, a1) == -1 )
lprintf(4LL, "cannot set answer/reception flags");
if ( (unsigned int)fax_set_bor(a1, 0LL) == -1 )
lprintf(4LL, "cannot set bit order. Huh?");
}
fax_set_l_id(a1, a3);
v10 = fax_set_fdcc(a1, 1LL, a5, 0LL);
result = 0LL;
if ( v10 == -1 )
{
lprintf(4LL, "huh? Cannot set +FDCC parameters");
result = 0LL;
}
}
return result;
}

original_code:
int mg_init_fax (int fd,char * mclass,char * fax_id,boolean fax_only,int fax_max_speed)
{
    modem_type = fax_get_modem_type( fd, mclass );
    if ( modem_type == Mt_data )
    {
 lprintf( 5, "no class 2/2.0 faxmodem, no faxing available" );
 return -1;
    }
    if ( modem_type == Mt_class1 || modem_type == Mt_class1_0 )
    {
        char aabuf[20];
 sprintf( aabuf, "AT+FA%s=%d",
   modem_type == Mt_class1? "E": "A",
   fax_only? 0:1 );
 if ( mdm_command( aabuf, fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 fax_set_bor( fd, 1 );
    }
    if ( modem_type == Mt_class2_0 )
    {
 if ( mdm_command( fax_only? "AT+FAA=0;+FCR=1":
               "AT+FAA=1;+FCR=1", fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 if ( fax_set_bor( fd, 1 ) == -1 )
 {
     lprintf( 4, "cannot set bit order, trying +BOR=0" );
     fax_set_bor( fd, 0 );
 }
 mdm_command( (modem_quirks & 0x40)? "AT+FNR=1,1,1,1"
       : "AT+FNR=1,1,1,0", fd );
    }
    if ( modem_type == Mt_class2 )
    {
 if ( !fax_only && ! ( modem_quirks & 0x01 ) )
 {
     if ( mdm_command( "AT+FCLASS=0", fd ) == -1 )
     {
  lprintf( 4, "weird: cannot set class 0" );
     }
 }
 if ( mdm_command( fax_only? "AT+FAA=0;+FCR=1":
               "AT+FAA=1;+FCR=1", fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 if ( fax_set_bor( fd, 0 ) == -1 )
 {
     lprintf( 4, "cannot set bit order. Huh?" );
 }
    }
    fax_set_l_id( fd, fax_id );
    if ( fax_set_fdcc( fd, 1, fax_max_speed, 0 ) == -1 )
    {
 lprintf( 4, "huh? Cannot set +FDCC parameters" );
    }
    return 0;
}

canonical_original_code:
int mg_init_fax(int fd, char *mclass, char *fax_id, char fax_only, int fax_max_speed)
{
    modem_type = fax_get_modem_type( fd, mclass );
    if ( modem_type == Mt_data )
    {
 lprintf( 5, "no class 2/2.0 faxmodem, no faxing available" );
 return -1;
    }
    if ( modem_type == Mt_class1 || modem_type == Mt_class1_0 )
    {
        char aabuf[20];
 sprintf( aabuf, "AT+FA%s=%d",
   modem_type == Mt_class1? "E": "A",
   fax_only? 0:1 );
 if ( mdm_command( aabuf, fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 fax_set_bor( fd, 1 );
    }
    if ( modem_type == Mt_class2_0 )
    {
 if ( mdm_command( fax_only? "AT+FAA=0;+FCR=1":
               "AT+FAA=1;+FCR=1", fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 if ( fax_set_bor( fd, 1 ) == -1 )
 {
     lprintf( 4, "cannot set bit order, trying +BOR=0" );
     fax_set_bor( fd, 0 );
 }
 mdm_command( (modem_quirks & 0x40)? "AT+FNR=1,1,1,1"
       : "AT+FNR=1,1,1,0", fd );
    }
    if ( modem_type == Mt_class2 )
    {
 if ( !fax_only && ! ( modem_quirks & 0x01 ) )
 {
     if ( mdm_command( "AT+FCLASS=0", fd ) == -1 )
     {
  lprintf( 4, "weird: cannot set class 0" );
     }
 }
 if ( mdm_command( fax_only? "AT+FAA=0;+FCR=1":
               "AT+FAA=1;+FCR=1", fd ) == -1 )
 {
     lprintf( 4, "cannot set answer/reception flags" );
 }
 if ( fax_set_bor( fd, 0 ) == -1 )
 {
     lprintf( 4, "cannot set bit order. Huh?" );
 }
    }
    fax_set_l_id( fd, fax_id );
    if ( fax_set_fdcc( fd, 1, fax_max_speed, 0 ) == -1 )
    {
 lprintf( 4, "huh? Cannot set +FDCC parameters" );
    }
    return 0;
}

variable_types:
mclass
char *

variable_types:
aabuf
char [20]


decompiled_code:
__int64 __fastcall faxpoll_server_init(unsigned int a1, const char *a2)
{
const char *v3; // rdi

faxpoll_server_file = 0LL;
if ( access(a2, 4) )
return lprintf(1LL, "cannot access/read '%s'", a2);
v3 = "AT+FLP=1";
if ( modem_type != 5 )
v3 = "AT+FLPL=1";
if ( (unsigned int)mdm_command(v3, a1) == -1 )
return lprintf(3LL, "faxpoll_server_init: no polling available");
faxpoll_server_file = a2;
return lprintf(5LL, "faxpoll_server_init: OK, waiting for poll");
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, const char *a2)
{
const char *v3; // rdi

faxpoll_server_file = 0LL;
if ( access(a2, 4) )
return lprintf(1LL, "cannot access/read '%s'", a2);
v3 = "AT+FLP=1";
if ( modem_type != 5 )
v3 = "AT+FLPL=1";
if ( (unsigned int)mdm_command(v3, a1) == -1 )
return lprintf(3LL, "faxpoll_server_init: no polling available");
faxpoll_server_file = a2;
return lprintf(5LL, "faxpoll_server_init: OK, waiting for poll");
}

original_code:
void faxpoll_server_init (int fd,char * f)
{
    faxpoll_server_file = ((void *)0);
    if ( access( f, 4 ) != 0 )
    {
 lprintf( 1, "cannot access/read '%s'", f );
    }
    else if ( mdm_command( modem_type == Mt_class2_0? "AT+FLP=1":"AT+FLPL=1",
      fd ) == -1)
    {
 lprintf( 3, "faxpoll_server_init: no polling available" );
    }
    else
    {
 faxpoll_server_file = f;
 lprintf( 5, "faxpoll_server_init: OK, waiting for poll" );
    }
}

canonical_original_code:
void faxpoll_server_init(int fd, char *f)
{
    faxpoll_server_file = ((void *)0);
    if ( access( f, 4 ) != 0 )
    {
 lprintf( 1, "cannot access/read '%s'", f );
    }
    else if ( mdm_command( modem_type == Mt_class2_0? "AT+FLP=1":"AT+FLPL=1",
      fd ) == -1)
    {
 lprintf( 3, "faxpoll_server_init: no polling available" );
    }
    else
    {
 faxpoll_server_file = f;
 lprintf( 5, "faxpoll_server_init: OK, waiting for poll" );
    }
}

variable_types:
f
char *