decompiled_code:
__int64 ZyXEL_2864_answer_phone()
{
int v0; // eax
unsigned int v1; // er8

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

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

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

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

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

variable_types: result int


repo: Distrotech/mgetty

decompiled_code:
__int64 __fastcall ZyXEL_2864_set_device(unsigned int a1)
{
__int64 result; // rax
bool v2; // zf

reset_watchdog();
switch ( a1 )
{
case 1u:
voice_command("AT+VLS=0", "OK");
result = 0LL;
break;
case 2u:
v2 = (unsigned int)voice_command("AT+VLS=2", "OK|CONNECT*") == 4097;
result = 0LL;
if ( v2 )
result = 8193LL;
break;
case 3u:
voice_command("AT+VLS=8", "OK");
result = 0LL;
break;
case 6u:
voice_command("AT+VLS=16", "OK");
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=1", "OK");
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

reset_watchdog();
switch ( a1 )
{
case 1u:
voice_command("AT+VLS=0", "OK");
result = 0LL;
break;
case 2u:
v2 = (unsigned int)voice_command("AT+VLS=2", "OK|CONNECT*") == 4097;
result = 0LL;
if ( v2 )
result = 8193LL;
break;
case 3u:
voice_command("AT+VLS=8", "OK");
result = 0LL;
break;
case 6u:
voice_command("AT+VLS=16", "OK");
result = 0LL;
break;
case 7u:
voice_command("AT+VLS=1", "OK");
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static int ZyXEL_2864_set_device (int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0007):
               voice_command("AT+VLS=1", "OK");
               return((0));
          case (0x0002):
               if (voice_command("AT+VLS=2", "OK|CONNECT*") == (0x1001))
                    return((0x2001));
               return((0));
          case (0x0003):
               voice_command("AT+VLS=8", "OK");
               return((0));
          case (0x0006):
               voice_command("AT+VLS=16", "OK");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

canonical_original_code:
static int ZyXEL_2864_set_device(int device)
     {
     reset_watchdog();
     switch (device)
          {
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0007):
               voice_command("AT+VLS=1", "OK");
               return((0));
          case (0x0002):
               if (voice_command("AT+VLS=2", "OK|CONNECT*") == (0x1001))
                    return((0x2001));
               return((0));
          case (0x0003):
               voice_command("AT+VLS=8", "OK");
               return((0));
          case (0x0006):
               voice_command("AT+VLS=16", "OK");
               return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

variable_types: device int

return_type: int


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

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 && v4 != 8000 && v4 != 7200 && v4 != 11025 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, (unsigned int)v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
v4 = 9600LL;
}
v5 = *a1;
if ( *a1 <= 40 )
{
if ( v5 > 1 )
{
switch ( v5 )
{
case 2LL:
*a3 = 2;
sprintf(v7, "AT+VSM=2,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 3LL:
*a3 = 3;
sprintf(v7, "AT+VSM=3,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 4LL:
*a3 = 4;
sprintf(v7, "AT+VSM=4,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 30LL:
*a3 = 3;
sprintf(v7, "AT+VSM=30,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 40LL:
*a3 = 4;
sprintf(v7, "AT+VSM=40,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
default:
goto LABEL_15;
}
}
goto LABEL_15;
}
if ( v5 == 80 )
{
*a3 = 8;
sprintf(v7, "AT+VSM=80,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
if ( v5 == 81 )
{
*a3 = 8;
sprintf(v7, "AT+VSM=81,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
LABEL_15:
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
return 0xFFFFFFFFLL;
}

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

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 9600 && v4 != 8000 && v4 != 7200 && v4 != 11025 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, (unsigned int)v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 9600LL;
v4 = 9600LL;
}
v5 = *a1;
if ( *a1 <= 40 )
{
if ( v5 > 1 )
{
switch ( v5 )
{
case 2LL:
*a3 = 2;
sprintf(v7, "AT+VSM=2,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 3LL:
*a3 = 3;
sprintf(v7, "AT+VSM=3,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 4LL:
*a3 = 4;
sprintf(v7, "AT+VSM=4,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 30LL:
*a3 = 3;
sprintf(v7, "AT+VSM=30,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
case 40LL:
*a3 = 4;
sprintf(v7, "AT+VSM=40,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
default:
goto LABEL_15;
}
}
goto LABEL_15;
}
if ( v5 == 80 )
{
*a3 = 8;
sprintf(v7, "AT+VSM=80,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
if ( v5 == 81 )
{
*a3 = 8;
sprintf(v7, "AT+VSM=81,%d", v4);
return (unsigned int)-((unsigned int)voice_command(v7, "OK") != 4096);
}
LABEL_15:
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, v5);
return 0xFFFFFFFFLL;
}

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

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


decompiled_code:
__int64 ZyXEL_2864_init()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rdx
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing ZyXEL 2864 voice modem");
if ( (unsigned int)voice_command("ATS48.5=1", "OK") != 4096 )
lprintf(3LL, "couldn't set IS 101 compatible mode");
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("AT+VIT=100", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(
v5,
"AT+VDD=%d,%d",
(unsigned int)((int)(15 * *((_QWORD *)&cvd + 37)) / 100),
(unsigned int)((int)*((_QWORD *)&cvd + 34) / 5));
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting DTMF preferences didn't work");
sprintf(v5, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 == -1 )
{
*((_QWORD *)&cvd + 82) = 50LL;
v1 = 128LL;
}
else
{
v1 = (unsigned int)(144 * (int)v0 / 100 + 56);
}
sprintf(v5, "AT+VGT=%d", v1);
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
v2 = *((_QWORD *)&cvd + 79);
if ( v2 == -1 )
{
*((_QWORD *)&cvd + 79) = 50LL;
v3 = 128LL;
}
else
{
v3 = (unsigned int)(144 * (int)v2 / 100 + 56);
}
sprintf(v5, "AT+VGR=%d", v3);
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rdx
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing ZyXEL 2864 voice modem");
if ( (unsigned int)voice_command("ATS48.5=1", "OK") != 4096 )
lprintf(3LL, "couldn't set IS 101 compatible mode");
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("AT+VIT=100", "OK") != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(
v5,
"AT+VDD=%d,%d",
(unsigned int)((int)(15 * *((_QWORD *)&cvd + 37)) / 100),
(unsigned int)((int)*((_QWORD *)&cvd + 34) / 5));
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting DTMF preferences didn't work");
sprintf(v5, "AT+VSD=%d,%d", (unsigned int)((int)(31 * *((_QWORD *)&cvd + 58)) / 100), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 == -1 )
{
*((_QWORD *)&cvd + 82) = 50LL;
v1 = 128LL;
}
else
{
v1 = (unsigned int)(144 * (int)v0 / 100 + 56);
}
sprintf(v5, "AT+VGT=%d", v1);
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
v2 = *((_QWORD *)&cvd + 79);
if ( v2 == -1 )
{
*((_QWORD *)&cvd + 79) = 50LL;
v3 = 128LL;
}
else
{
v3 = (unsigned int)(144 * (int)v2 / 100 + 56);
}
sprintf(v5, "AT+VGR=%d", v3);
if ( (unsigned int)voice_command(v5, "OK") != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int ZyXEL_2864_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL 2864 voice modem");
     if (voice_command("ATS48.5=1", "OK") != (0x1000))
          lprintf(3, "couldn't set IS 101 compatible mode");
     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("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDD=%d,%d", (int)cvd.dtmf_threshold.d.i *
      15 / 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 = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int ZyXEL_2864_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL 2864 voice modem");
     if (voice_command("ATS48.5=1", "OK") != (0x1000))
          lprintf(3, "couldn't set IS 101 compatible mode");
     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("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDD=%d,%d", (int)cvd.dtmf_threshold.d.i *
      15 / 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 = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 voice_init()
{
__int64 v0; // rdi
__int64 result; // rax

tio_get((unsigned int)voice_fd, &tio_save);
tio_get((unsigned int)voice_fd, voice_tio);
tio_mode_sane(voice_tio, 1LL);
if ( (int)tio_check_speed(cvd[44]) < 0 )
{
lprintf(3LL, "invalid port speed: %d", *(_QWORD *)&cvd[44]);
goto LABEL_9;
}
tio_set_speed(voice_tio, cvd[44]);
tio_set_speed(&tio_save, cvd[44]);
tio_default_cc(voice_tio);
tio_mode_raw(voice_tio);
tio_set_flow_control((unsigned int)voice_fd, voice_tio, 1LL);
v0 = (unsigned int)voice_fd;
voice_tio[11] = 0;
if ( (unsigned int)tio_set(v0, voice_tio) == -1 )
{
lprintf(3LL, "error in tio_set");
LABEL_9:
close(voice_fd);
rmlocks();
exit(-1);
}
if ( (unsigned int)voice_detect_modemtype()
|| (voice_flush(1LL), (unsigned int)voice_mode_on())
|| (*(unsigned int (**)(void))(voice_modem + 304LL))()
|| (result = voice_mode_off(), (_DWORD)result) )
{
close(voice_fd);
rmlocks();
result = 0xFFFFFFFFLL;
}
return result;
}

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

tio_get((unsigned int)voice_fd, &tio_save);
tio_get((unsigned int)voice_fd, voice_tio);
tio_mode_sane(voice_tio, 1LL);
if ( (int)tio_check_speed(cvd[44]) < 0 )
{
lprintf(3LL, "invalid port speed: %d", *(_QWORD *)&cvd[44]);
goto LABEL_9;
}
tio_set_speed(voice_tio, cvd[44]);
tio_set_speed(&tio_save, cvd[44]);
tio_default_cc(voice_tio);
tio_mode_raw(voice_tio);
tio_set_flow_control((unsigned int)voice_fd, voice_tio, 1LL);
v0 = (unsigned int)voice_fd;
voice_tio[11] = 0;
if ( (unsigned int)tio_set(v0, voice_tio) == -1 )
{
lprintf(3LL, "error in tio_set");
LABEL_9:
close(voice_fd);
rmlocks();
exit(-1);
}
if ( (unsigned int)voice_detect_modemtype()
|| (voice_flush(1LL), (unsigned int)voice_mode_on())
|| (*(unsigned int (**)(void))(voice_modem + 304LL))()
|| (result = voice_mode_off(), (_DWORD)result) )
{
close(voice_fd);
rmlocks();
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int voice_init(void)
     {
     tio_get(voice_fd, &tio_save);
     tio_get(voice_fd, &voice_tio);
     tio_mode_sane(&voice_tio, (0==0));
     if (tio_check_speed(cvd.port_speed.d.i) >= 0)
          {
          tio_set_speed(&voice_tio, cvd.port_speed.d.i);
          tio_set_speed(&tio_save, cvd.port_speed.d.i);
          }
     else
          {
          lprintf(3, "invalid port speed: %d", cvd.port_speed.d.i);
          close(voice_fd);
          rmlocks();
          exit((-1));
          }
     tio_default_cc(&voice_tio);
     tio_mode_raw(&voice_tio);
     tio_set_flow_control(voice_fd, &voice_tio, 0x01);
     voice_tio.c_cc[6] = 0;
     voice_tio.c_cc[5] = 0;
     if (tio_set(voice_fd, &voice_tio) == (-1))
          {
          lprintf(3, "error in tio_set");
          close(voice_fd);
          rmlocks();
          exit((-1));
          };
     if (voice_detect_modemtype() == (0))
          {
          voice_flush(1);
          if (voice_mode_on() != (0))
               {
               close(voice_fd);
               rmlocks();
               return((-1));
               }
          if (voice_modem->init() != (0))
               {
               close(voice_fd);
               rmlocks();
               return((-1));
               }
          if (voice_mode_off() == (0))
               return((0));
          }
     close(voice_fd);
     rmlocks();
     return((-1));
     }

canonical_original_code:
int voice_init()
     {
     tio_get(voice_fd, &tio_save);
     tio_get(voice_fd, &voice_tio);
     tio_mode_sane(&voice_tio, (0==0));
     if (tio_check_speed(cvd.port_speed.d.i) >= 0)
          {
          tio_set_speed(&voice_tio, cvd.port_speed.d.i);
          tio_set_speed(&tio_save, cvd.port_speed.d.i);
          }
     else
          {
          lprintf(3, "invalid port speed: %d", cvd.port_speed.d.i);
          close(voice_fd);
          rmlocks();
          exit((-1));
          }
     tio_default_cc(&voice_tio);
     tio_mode_raw(&voice_tio);
     tio_set_flow_control(voice_fd, &voice_tio, 0x01);
     voice_tio.c_cc[6] = 0;
     voice_tio.c_cc[5] = 0;
     if (tio_set(voice_fd, &voice_tio) == (-1))
          {
          lprintf(3, "error in tio_set");
          close(voice_fd);
          rmlocks();
          exit((-1));
          };
     if (voice_detect_modemtype() == (0))
          {
          voice_flush(1);
          if (voice_mode_on() != (0))
               {
               close(voice_fd);
               rmlocks();
               return((-1));
               }
          if (voice_modem->init() != (0))
               {
               close(voice_fd);
               rmlocks();
               return((-1));
               }
          if (voice_mode_off() == (0))
               return((0));
          }
     close(voice_fd);
     rmlocks();
     return((-1));
     }


decompiled_code:
__int64 __fastcall encode_c(__int16 a1, int a2)
{
int v2; // edx
__int64 result; // rax

LOWORD(v2) = a2;
result = 0LL;
if ( (a2 & 0x8000u) != 0 )
{
v2 = -a2;
result = 8LL;
}
if ( (__int16)v2 >= a1 )
{
result = (unsigned int)(result + 4);
LOWORD(v2) = v2 - a1;
}
if ( a1 >> 1 <= (__int16)v2 )
{
result = (unsigned int)(result + 2);
LOWORD(v2) = v2 - (a1 >> 1);
}
if ( a1 >> 2 <= (__int16)v2 )
result = (unsigned int)(result + 1);
return result;
}

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

LOWORD(v2) = a2;
result = 0LL;
if ( (a2 & 0x8000u) != 0 )
{
v2 = -a2;
result = 8LL;
}
if ( (__int16)v2 >= a1 )
{
result = (unsigned int)(result + 4);
LOWORD(v2) = v2 - a1;
}
if ( a1 >> 1 <= (__int16)v2 )
{
result = (unsigned int)(result + 2);
LOWORD(v2) = v2 - (a1 >> 1);
}
if ( a1 >> 2 <= (__int16)v2 )
result = (unsigned int)(result + 1);
return result;
}

original_code:
static char encode_c (short Delta_N, short Dn)
{ char c;
  c = 0;
  if ( Dn < 0 ) { c = 8; Dn = -Dn; }
  if ( Dn >= Delta_N ) { c += 4; Dn -= Delta_N; }
  if ( Dn >= (Delta_N>>1) ) { c += 2; Dn -= Delta_N>>1; }
  if ( Dn >= (Delta_N>>2) ) c += 1;
  return ( c );
}

canonical_original_code:
static char encode_c(short Delta_N, short Dn)
{ char c;
  c = 0;
  if ( Dn < 0 ) { c = 8; Dn = -Dn; }
  if ( Dn >= Delta_N ) { c += 4; Dn -= Delta_N; }
  if ( Dn >= (Delta_N>>1) ) { c += 2; Dn -= Delta_N>>1; }
  if ( Dn >= (Delta_N>>2) ) c += 1;
  return ( c );
}

variable_types: Dn short

variable_types: c char

return_type: char


decompiled_code:
__int64 __fastcall decode_c(int a1, char a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // edx
unsigned int v6; // edx
unsigned int v7; // edi

HIWORD(v2) = HIWORD(a1);
v3 = 0;
if ( (a2 & 4) != 0 )
v3 = a1;
LOWORD(v2) = (__int16)a1 >> 3;
result = (unsigned int)(v3 + v2);
HIWORD(v5) = HIWORD(a1);
LOWORD(v5) = (__int16)a1 >> 1;
v6 = result + v5;
if ( (a2 & 2) != 0 )
result = v6;
LOWORD(a1) = (__int16)a1 >> 2;
v7 = result + a1;
if ( (a2 & 1) != 0 )
result = v7;
if ( (a2 & 8) != 0 )
result = (unsigned int)-(int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // edx
unsigned int v6; // edx
unsigned int v7; // edi

HIWORD(v2) = HIWORD(a1);
v3 = 0;
if ( (a2 & 4) != 0 )
v3 = a1;
LOWORD(v2) = (__int16)a1 >> 3;
result = (unsigned int)(v3 + v2);
HIWORD(v5) = HIWORD(a1);
LOWORD(v5) = (__int16)a1 >> 1;
v6 = result + v5;
if ( (a2 & 2) != 0 )
result = v6;
LOWORD(a1) = (__int16)a1 >> 2;
v7 = result + a1;
if ( (a2 & 1) != 0 )
result = v7;
if ( (a2 & 8) != 0 )
result = (unsigned int)-(int)result;
return result;
}

original_code:
static short decode_c (short Delta_N, char c)
{ short b;
   b = Delta_N >> 3;
   b += (c&4) ? Delta_N : 0;
   b += (c&2) ? Delta_N >> 1 : 0;
   b += (c&1) ? Delta_N >> 2 : 0;
   return( (c&8) ? -b : b );
}

canonical_original_code:
static short decode_c(short Delta_N, char c)
{ short b;
   b = Delta_N >> 3;
   b += (c&4) ? Delta_N : 0;
   b += (c&2) ? Delta_N >> 1 : 0;
   b += (c&1) ? Delta_N >> 2 : 0;
   return( (c&8) ? -b : b );
}

variable_types: b short

return_type: short


match

decompiled_code:
bool __fastcall match(char *s1, char *s2)
{
int v2; // ebx
int v3; // er13
bool result; // al
char v5; // dl
int v6; // ebx
int v7; // er13
__int64 v8; // r14
int v9; // ebx
int v10; // ebx

v2 = strlen(s2);
v3 = strlen(s1);
lprintf(5LL, "match: user='%s', key='%s'", s1, s2);
result = 0;
if ( v2 )
{
v5 = s2[v2 - 1];
if ( *s2 == 42 )
{
if ( v5 == 42 )
{
result = 1;
if ( v2 > 1 )
{
v6 = v2 - 2;
v7 = v3 - v6;
if ( v7 < 0 )
{
LABEL_18:
result = 0;
}
else
{
v8 = 0LL;
while ( strncmp(&s1[v8], s2 + 1, v6) )
{
if ( v7 < (int)++v8 )
goto LABEL_18;
}
result = 1;
}
}
}
else
{
v9 = v2 - 1;
if ( v9 <= v3 )
result = strcmp(&s1[v3 - v9], s2 + 1) == 0;
}
}
else if ( v5 == 42 )
{
v10 = v2 - 1;
if ( v10 <= v3 )
result = strncmp(s1, s2, v10) == 0;
}
else if ( v2 == v3 )
{
result = strcmp(s1, s2) == 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(char *s1, char *s2)
{
int v2; // ebx
int v3; // er13
bool result; // al
char v5; // dl
int v6; // ebx
int v7; // er13
__int64 v8; // r14
int v9; // ebx
int v10; // ebx

v2 = strlen(s2);
v3 = strlen(s1);
lprintf(5LL, "match: user='%s', key='%s'", s1, s2);
result = 0;
if ( v2 )
{
v5 = s2[v2 - 1];
if ( *s2 == 42 )
{
if ( v5 == 42 )
{
result = 1;
if ( v2 > 1 )
{
v6 = v2 - 2;
v7 = v3 - v6;
if ( v7 < 0 )
{
LABEL_18:
result = 0;
}
else
{
v8 = 0LL;
while ( strncmp(&s1[v8], s2 + 1, v6) )
{
if ( v7 < (int)++v8 )
goto LABEL_18;
}
result = 1;
}
}
}
else
{
v9 = v2 - 1;
if ( v9 <= v3 )
result = strcmp(&s1[v3 - v9], s2 + 1) == 0;
}
}
else if ( v5 == 42 )
{
v10 = v2 - 1;
if ( v10 <= v3 )
result = strncmp(s1, s2, v10) == 0;
}
else if ( v2 == v3 )
{
result = strcmp(s1, s2) == 0;
}
}
return result;
}

original_code:
boolean match (char * user,char * key)
{
    int lk = strlen( key );
    int lu = strlen( user );
    int i;
    lprintf( 5, "match: user='%s', key='%s'", user, key );
    if ( lk == 0 ) return (1==0);
    if ( key[0] == '*' )
    {
 if ( key[lk-1] == '*' )
 {
     if ( lk < 2 ) return (1==1);
     for ( i=0; i <= lu - (lk-2); i++ )
     {
  if ( strncmp( &user[i], &key[1], lk-2 ) == 0 ) return (1==1);
     }
     return (1==0);
 }
 else
 {
     return ( ( lu >= lk-1 ) &&
       ( strcmp( &user[ lu-(lk-1) ], &key[1] ) == 0 ) );
 }
    }
    else
    {
 if ( key[lk-1] == '*' )
 {
     return ( ( lu >= lk-1 ) &&
       ( strncmp( user, key, lk-1 ) == 0 ) );
 }
 else
 {
     return ( ( lu == lk ) &&
       ( strcmp( user, key ) == 0 ) );
 }
    }
    return (1==0);
}

canonical_original_code:
char match(char *user, char *key)
{
    int lk = strlen( key );
    int lu = strlen( user );
    int i;
    lprintf( 5, "match: user='%s', key='%s'", user, key );
    if ( lk == 0 ) return (1==0);
    if ( key[0] == '*' )
    {
 if ( key[lk-1] == '*' )
 {
     if ( lk < 2 ) return (1==1);
     for ( i=0; i <= lu - (lk-2); i++ )
     {
  if ( strncmp( &user[i], &key[1], lk-2 ) == 0 ) return (1==1);
     }
     return (1==0);
 }
 else
 {
     return ( ( lu >= lk-1 ) &&
       ( strcmp( &user[ lu-(lk-1) ], &key[1] ) == 0 ) );
 }
    }
    else
    {
 if ( key[lk-1] == '*' )
 {
     return ( ( lu >= lk-1 ) &&
       ( strncmp( user, key, lk-1 ) == 0 ) );
 }
 else
 {
     return ( ( lu == lk ) &&
       ( strcmp( user, key ) == 0 ) );
 }
    }
    return (1==0);
}

variable_types:
user
char *

variable_types:
key
char *

variable_types: lk int

variable_types: lu int

variable_types: i int


decompiled_code:
__int64 setup_environment()
{
if ( !*CallerId )
{
if ( !*CallName )
goto LABEL_3;
LABEL_6:
set_env_var("CALLER_NAME");
if ( !*CalledNr )
goto LABEL_4;
LABEL_7:
set_env_var("CALLED_ID");
goto LABEL_4;
}
set_env_var("CALLER_ID");
if ( *CallName )
goto LABEL_6;
LABEL_3:
if ( *CalledNr )
goto LABEL_7;
LABEL_4:
set_env_var("CONNECT");
return set_env_var("DEVICE");
}

canonical_decompiled_code:
__int64 func1()
{
if ( !*CallerId )
{
if ( !*CallName )
goto LABEL_3;
LABEL_6:
set_env_var("CALLER_NAME");
if ( !*CalledNr )
goto LABEL_4;
LABEL_7:
set_env_var("CALLED_ID");
goto LABEL_4;
}
set_env_var("CALLER_ID");
if ( *CallName )
goto LABEL_6;
LABEL_3:
if ( *CalledNr )
goto LABEL_7;
LABEL_4:
set_env_var("CONNECT");
return set_env_var("DEVICE");
}

original_code:
void setup_environment (void)
{
    if ( *CallerId )
 set_env_var( "CALLER_ID", CallerId );
    if ( *CallName )
 set_env_var( "CALLER_NAME", CallName );
    if ( *CalledNr )
 set_env_var( "CALLED_ID", CalledNr );
    set_env_var( "CONNECT", Connect );
    set_env_var( "DEVICE", Device );
}

canonical_original_code:
void setup_environment()
{
    if ( *CallerId )
 set_env_var( "CALLER_ID", CallerId );
    if ( *CallName )
 set_env_var( "CALLER_NAME", CallName );
    if ( *CalledNr )
 set_env_var( "CALLED_ID", CalledNr );
    set_env_var( "CONNECT", Connect );
    set_env_var( "DEVICE", Device );
}

return_type: void


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:
so
short *

variable_types: mp short

variable_types: msp short

variable_types: lsp short

variable_types: SO short

variable_types: ltmp long

variable_types:
utmp
unsigned long

variable_types: k int


original_code:
void tree_add_node (struct g3_tree *p,struct g3code * g3c,int bit_code,int bit_length)
{
int i;
    if ( bit_length <= 8 )
    {
 g3c->nr_bits = bit_length;
 if ( bit_length == 8 )
 {
     p->nextb[ bit_code ] = (struct g3_tree *) g3c;
 }
 else
   for ( i=0; i< ( 1 << (8 -bit_length)); i++ )
   {
     p->nextb[ bit_code + ( i << bit_length ) ] = (struct g3_tree *) g3c;
   }
    }
    else
    {
    struct g3_tree *p2;
 p2 = p->nextb[ bit_code & 0xff ];
 if ( p2 == 0 )
 {
     p2 = p->nextb[ bit_code & 0xff ] =
  ( struct g3_tree * ) calloc( 1, sizeof( struct g3_tree ));
     if ( p2 == ((void *)0) ) { perror( "malloc 3" ); exit(11); }
     p2->nr_bits = 0;
 }
 if ( p2->nr_bits != 0 )
 {
     fprintf( stderr, "internal table setup error\n" ); exit(6);
 }
 tree_add_node( p2, g3c, bit_code >> 8, bit_length - 8 );
    }
}

canonical_original_code:
void tree_add_node(struct g3_tree *p, struct g3code *g3c, int bit_code, int bit_length)
{
int i;
    if ( bit_length <= 8 )
    {
 g3c->nr_bits = bit_length;
 if ( bit_length == 8 )
 {
     p->nextb[ bit_code ] = (struct g3_tree *) g3c;
 }
 else
   for ( i=0; i< ( 1 << (8 -bit_length)); i++ )
   {
     p->nextb[ bit_code + ( i << bit_length ) ] = (struct g3_tree *) g3c;
   }
    }
    else
    {
    struct g3_tree *p2;
 p2 = p->nextb[ bit_code & 0xff ];
 if ( p2 == 0 )
 {
     p2 = p->nextb[ bit_code & 0xff ] =
  ( struct g3_tree * ) calloc( 1, sizeof( struct g3_tree ));
     if ( p2 == ((void *)0) ) { perror( "malloc 3" ); exit(11); }
     p2->nr_bits = 0;
 }
 if ( p2->nr_bits != 0 )
 {
     fprintf( stderr, "internal table setup error\n" ); exit(6);
 }
 tree_add_node( p2, g3c, bit_code >> 8, bit_length - 8 );
    }
}

variable_types: struct g3_tree { int nr_bits; struct g3_tree *nextb[-1]; } *


decompiled_code:
void __fastcall build_tree(_DWORD **a1, int *a2)
{
int v3; // edx
int *v4; // rsi
int v5; // ecx
_DWORD *v6; // rax

if ( !*a1 )
{
v6 = calloc(1uLL, 0x808uLL);
*a1 = v6;
if ( !v6 )
{
perror("malloc(1)");
exit(10);
}
*v6 = 0;
}
while ( 1 )
{
v5 = a2[3];
if ( !v5 )
break;
v3 = a2[2];
v4 = a2;
a2 += 4;
tree_add_node(*a1, v4, v3, v5);
}
}

original_code:
void build_tree (struct g3_tree ** p,struct g3code * c)
{
    if ( *p == ((void *)0) )
    {
 (*p) = (struct g3_tree *) calloc( 1, sizeof(struct g3_tree) );
 if ( *p == ((void *)0) ) { perror( "malloc(1)" ); exit(10); }
 (*p)->nr_bits=0;
    }
    while ( c->bit_length != 0 )
    {
 tree_add_node( *p, c, c->bit_code, c->bit_length );
 c++;
    }
}

canonical_original_code:
void build_tree(struct g3_tree **p, struct g3code *c)
{
    if ( *p == ((void *)0) )
    {
 (*p) = (struct g3_tree *) calloc( 1, sizeof(struct g3_tree) );
 if ( *p == ((void *)0) ) { perror( "malloc(1)" ); exit(10); }
 (*p)->nr_bits=0;
    }
    while ( c->bit_length != 0 )
    {
 tree_add_node( *p, c, c->bit_code, c->bit_length );
 c++;
    }
}

variable_types: struct g3_tree { int nr_bits; struct g3_tree *nextb[-1]; } **

variable_types:
c
struct g3code { int nr_bits; } *


decompiled_code:
__int64 __fastcall init_byte_tab(int a1, __int64 a2)
{
__int64 result; // rax
__int64 i; // rdx

if ( a1 )
{
for ( result = 0LL; result != 256; ++result )
*(_DWORD *)(a2 + 4 * result) = result;
}
else
{
for ( i = 0LL; i != 256; ++i )
{
result = ((int)i >> 5) & 2 | ((int)i >> 3) & 4 | ((int)i >> 1) & 8 | (2 * (_BYTE)i) & 0x10 | (8 * (_BYTE)i) & 0x20 | ((int)i >> 7) | (32 * (_BYTE)i) & 0x40 | (unsigned int)(unsigned __int8)((_BYTE)i << 7);
*(_DWORD *)(a2 + 4 * i) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, __int64 a2)
{
__int64 result; // rax
__int64 i; // rdx

if ( a1 )
{
for ( result = 0LL; result != 256; ++result )
*(_DWORD *)(a2 + 4 * result) = result;
}
else
{
for ( i = 0LL; i != 256; ++i )
{
result = ((int)i >> 5) & 2 | ((int)i >> 3) & 4 | ((int)i >> 1) & 8 | (2 * (_BYTE)i) & 0x10 | (8 * (_BYTE)i) & 0x20 | ((int)i >> 7) | (32 * (_BYTE)i) & 0x40 | (unsigned int)(unsigned __int8)((_BYTE)i << 7);
*(_DWORD *)(a2 + 4 * i) = result;
}
}
return result;
}

variable_types: reverse int


decompiled_code:
void sig_timer()
{
signal(14, sig_timer);
lprintf(5LL, "got alarm signal -> huh?");
timeout = 1;
}

canonical_decompiled_code:
void func0()
{
signal(14, sig_timer);
lprintf(5LL, "got alarm signal -> huh?");
timeout = 1;
}

original_code:
static RETSIGTYPE sig_timer()
{
    signal( 14, sig_timer );
    lprintf( 5, "got alarm signal -> huh?" );
    timeout = (1==1);
}

canonical_original_code:
static void sig_timer()
{
    signal( 14, sig_timer );
    lprintf( 5, "got alarm signal -> huh?" );
    timeout = (1==1);
}


decompiled_code:
void sig_mgetty_ack()
{
signal(10, sig_mgetty_ack);
lprintf(5LL, "got ACK signal from mgetty");
mgetty_ACK = 1;
}

canonical_decompiled_code:
void func1()
{
signal(10, sig_mgetty_ack);
lprintf(5LL, "got ACK signal from mgetty");
mgetty_ACK = 1;
}

original_code:
static RETSIGTYPE sig_mgetty_ack()
{
    signal( 10, sig_mgetty_ack );
    lprintf( 5, "got ACK signal from mgetty" );
    mgetty_ACK = (1==1);
}

canonical_original_code:
static void sig_mgetty_ack()
{
    signal( 10, sig_mgetty_ack );
    lprintf( 5, "got ACK signal from mgetty" );
    mgetty_ACK = (1==1);
}


decompiled_code:
void __fastcall __noreturn sig_goodbye(unsigned int a1)
{
unsigned int v1; // eax

v1 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, got signal %d, exiting", Device, v1, a1);
rmlocks();
exit(10);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(unsigned int a1)
{
unsigned int v1; // eax

v1 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, got signal %d, exiting", Device, v1, a1);
rmlocks();
exit(10);
}

original_code:
static RETSIGTYPE sig_goodbye (int signo)
{
    lprintf( 2, "failed dev=%s, pid=%d, got signal %d, exiting",
               Device, getpid(), signo );
    rmlocks();
    exit(10);
}

canonical_original_code:
static void sig_goodbye(int signo)
{
    lprintf( 2, "failed dev=%s, pid=%d, got signal %d, exiting",
               Device, getpid(), signo );
    rmlocks();
    exit(10);
}

variable_types: signo int


decompiled_code:
int detach_tty()
{
__pid_t v0; // eax
int v1; // eax
int v2; // ebp

lprintf(4LL, "detaching from ctty...");
printf("\nDialing continues in the background, all further messages will\nbe written to the logfile '");
printf("/var/log/mgetty.%s", "callback");
puts("'.\nPlease look there for errors / diagnostics.\n");
fflush(stdout);
tio_drain_output(1LL);
sleep(1u);
v0 = fork();
if ( v0 == -1 )
{
perror("fork failed, can't detach myself");
fwrite("giving up.\n", 1uLL, 0xBuLL, stderr);
exit(4);
}
if ( v0 )
exit(0);
close(0);
close(1);
close(2);
v1 = open("/dev/tty", 2);
v2 = v1;
if ( v1 >= 0 )
{
ioctl(v1, 0x5422uLL, 0LL);
close(v2);
}
return setpgrp();
}

canonical_decompiled_code:
int func4()
{
__pid_t v0; // eax
int v1; // eax
int v2; // ebp

lprintf(4LL, "detaching from ctty...");
printf("\nDialing continues in the background, all further messages will\nbe written to the logfile '");
printf("/var/log/mgetty.%s", "callback");
puts("'.\nPlease look there for errors / diagnostics.\n");
fflush(stdout);
tio_drain_output(1LL);
sleep(1u);
v0 = fork();
if ( v0 == -1 )
{
perror("fork failed, can't detach myself");
fwrite("giving up.\n", 1uLL, 0xBuLL, stderr);
exit(4);
}
if ( v0 )
exit(0);
close(0);
close(1);
close(2);
v1 = open("/dev/tty", 2);
v2 = v1;
if ( v1 >= 0 )
{
ioctl(v1, 0x5422uLL, 0LL);
close(v2);
}
return setpgrp();
}

original_code:
void detach_tty (void)
{
int r;
    lprintf( 4, "detaching from ctty..." );
    printf( "\nDialing continues in the background, all further messages will\nbe written to the logfile '" );
    printf( "/var/log/mgetty.%s", "callback" );
    printf( "'.\nPlease look there for errors / diagnostics.\n\n" );
    fflush(stdout);
    tio_drain_output(1);
    sleep(1);
    switch( fork() )
    {
      case 0:
 close(0); close(1); close(2);
 if ( ( r = open( "/dev/tty", 02 ) ) >= 0 )
 {
     ioctl( r, 0x5422, ((void *)0) );
     close( r );
 }
 setpgrp();
 break;
      case -1:
        perror( "fork failed, can't detach myself" );
        fprintf( stderr, "giving up.\n" );
        exit(4);
      default:
        exit(0);
    }
}

canonical_original_code:
void detach_tty()
{
int r;
    lprintf( 4, "detaching from ctty..." );
    printf( "\nDialing continues in the background, all further messages will\nbe written to the logfile '" );
    printf( "/var/log/mgetty.%s", "callback" );
    printf( "'.\nPlease look there for errors / diagnostics.\n\n" );
    fflush(stdout);
    tio_drain_output(1);
    sleep(1);
    switch( fork() )
    {
      case 0:
 close(0); close(1); close(2);
 if ( ( r = open( "/dev/tty", 02 ) ) >= 0 )
 {
     ioctl( r, 0x5422, ((void *)0) );
     close( r );
 }
 setpgrp();
 break;
      case -1:
        perror( "fork failed, can't detach myself" );
        fprintf( stderr, "giving up.\n" );
        exit(4);
      default:
        exit(0);
    }
}

variable_types: r int


decompiled_code:
__int64 __fastcall fd_make_stddev(int fd)
{
__int64 result; // rax

if ( fd > 0 )
{
close(0);
if ( dup(fd) )
{
lprintf(1LL, "can't dup(fd=%d) to stdin", (unsigned int)fd);
return 0xFFFFFFFFLL;
}
close(fd);
}
close(1);
close(2);
if ( dup(0) == 1 )
{
if ( dup(0) == 2 )
{
result = 0LL;
}
else
{
lprintf(1LL, "can't dup(0) to stderr");
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(1LL, "can't dup(0) to stdout");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
__int64 result; // rax

if ( fd > 0 )
{
close(0);
if ( dup(fd) )
{
lprintf(1LL, "can't dup(fd=%d) to stdin", (unsigned int)fd);
return 0xFFFFFFFFLL;
}
close(fd);
}
close(1);
close(2);
if ( dup(0) == 1 )
{
if ( dup(0) == 2 )
{
result = 0LL;
}
else
{
lprintf(1LL, "can't dup(0) to stderr");
result = 0xFFFFFFFFLL;
}
}
else
{
lprintf(1LL, "can't dup(0) to stdout");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int fd_make_stddev (int fd)
{
    if ( fd > 0 )
    {
 (void) close(0);
 if ( dup(fd) != 0 )
 {
     lprintf( 1, "can't dup(fd=%d) to stdin", fd );
     return -1;
 }
 close(fd);
    }
    (void) close(1); (void) close(2);
    if ( dup(0) != 1 )
    {
 lprintf( 1, "can't dup(0) to stdout" ); return -1;
    }
    if ( dup(0) != 2 )
    {
 lprintf( 1, "can't dup(0) to stderr" ); return -1;
    }
    return 0;
}

canonical_original_code:
int fd_make_stddev(int fd)
{
    if ( fd > 0 )
    {
 (void) close(0);
 if ( dup(fd) != 0 )
 {
     lprintf( 1, "can't dup(fd=%d) to stdin", fd );
     return -1;
 }
 close(fd);
    }
    (void) close(1); (void) close(2);
    if ( dup(0) != 1 )
    {
 lprintf( 1, "can't dup(0) to stdout" ); return -1;
    }
    if ( dup(0) != 2 )
    {
 lprintf( 1, "can't dup(0) to stderr" ); return -1;
    }
    return 0;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall callback_init_device(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi
_BYTE v5[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
lprintf(1LL, "can't open %s", a1);
}
else
{
fcntl(v1, 4, 2LL);
if ( (unsigned int)tio_get(v2, v5) == -1
|| (tio_mode_sane(v5, 1LL),
((void (__fastcall *)(_BYTE *, _QWORD))tio_set_speed)(v5, c[44]),
tio_default_cc(v5),
tio_mode_raw(v5),
tio_set_flow_control(v2, v5, 1LL),
(unsigned int)tio_set(v2, v5) == -1) )
{
v4 = v2;
v2 = -1;
close(v4);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi
_BYTE v5[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
lprintf(1LL, "can't open %s", a1);
}
else
{
fcntl(v1, 4, 2LL);
if ( (unsigned int)tio_get(v2, v5) == -1
|| (tio_mode_sane(v5, 1LL),
((void (__fastcall *)(_BYTE *, _QWORD))tio_set_speed)(v5, c[44]),
tio_default_cc(v5),
tio_mode_raw(v5),
tio_set_flow_control(v2, v5, 1LL),
(unsigned int)tio_set(v2, v5) == -1) )
{
v4 = v2;
v2 = -1;
close(v4);
}
}
return v2;
}

original_code:
int callback_init_device (char * dev)
{
int fd;
TIO tio;
    fd = open( dev, 02 | 04000 | 0400 );
    if ( fd == -1 )
    {
 lprintf( 1, "can't open %s", dev );
 return -1;
    }
    fcntl( fd, 4, 02 );
    if ( tio_get( fd, &tio ) == -1 ) { close(fd); return -1; }
    tio_mode_sane( &tio, (1==1) );
    tio_set_speed( &tio, ((int) c.speed.d.i) );
    tio_default_cc( &tio );
    tio_mode_raw( &tio );
    tio_set_flow_control( fd, &tio, 0x01 );
    if ( tio_set( fd, &tio ) == -1 ) { close(fd); return -1; }
    return fd;
}

canonical_original_code:
int callback_init_device(char *dev)
{
int fd;
struct termios tio;
    fd = open( dev, 02 | 04000 | 0400 );
    if ( fd == -1 )
    {
 lprintf( 1, "can't open %s", dev );
 return -1;
    }
    fcntl( fd, 4, 02 );
    if ( tio_get( fd, &tio ) == -1 ) { close(fd); return -1; }
    tio_mode_sane( &tio, (1==1) );
    tio_set_speed( &tio, ((int) c.speed.d.i) );
    tio_default_cc( &tio );
    tio_mode_raw( &tio );
    tio_set_flow_control( fd, &tio, 0x01 );
    if ( tio_set( fd, &tio ) == -1 ) { close(fd); return -1; }
    return fd;
}

variable_types:
dev
char *

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


decompiled_code:
__int64 __fastcall callback_find_device(void *src, char *s, _DWORD *a3, unsigned int a4, int a5)
{
const char *v7; // rbx
size_t v8; // rax
char *v9; // rax
size_t v10; // rax
size_t v11; // r13
int v12; // eax
__int64 result; // rax
unsigned int v14; // eax
unsigned int v15; // ebx
char v17; // [rsp+17h] [rbp-441h]
unsigned int seconds; // [rsp+18h] [rbp-440h]
int v19; // [rsp+1Ch] [rbp-43Ch]
char dest[1080]; // [rsp+20h] [rbp-438h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(void *src, char *s, _DWORD *a3, unsigned int a4, int a5)
{
const char *v7; // rbx
size_t v8; // rax
char *v9; // rax
size_t v10; // rax
size_t v11; // r13
int v12; // eax
__int64 result; // rax
unsigned int v14; // eax
unsigned int v15; // ebx
char v17; // [rsp+17h] [rbp-441h]
unsigned int seconds; // [rsp+18h] [rbp-440h]
int v19; // [rsp+1Ch] [rbp-43Ch]
char dest[1080]; // [rsp+20h] [rbp-438h] BYREF

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

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

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

variable_types:
ttys
char *

variable_types:
device
char *

variable_types: rtime int

variable_types:
p
char *

variable_types:
tty
char [1024]


dialup

decompiled_code:
__int64 __fastcall dialup(unsigned int a1, __int64 a2, int a3, int a4)
{
time_t v6; // r13
int v7; // er12
const char **v9; // rbp
const char *v10; // rax
const char *v11; // rbp
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, int a3, int a4)
{
time_t v6; // r13
int v7; // er12
const char **v9; // rbp
const char *v10; // rax
const char *v11; // rbp
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

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

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

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

variable_types:
phone
char **

variable_types: count int

variable_types: n int

variable_types:
dialbuf
char [1024]

variable_types:
r
char *


cndfind

decompiled_code:
void cndfind()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code: void cndfind (char * p) { }

canonical_original_code: void cndfind(char *p) { }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char **v5; // rbp
__int64 v6; // rbx
const char *v7; // rcx
__int64 v8; // rdx
time_t v9; // rbx
unsigned int v10; // eax
__int64 v11; // r13
int v12; // edx
signed int v13; // er13
int v14; // edi
char *v15; // r13
size_t v16; // rax
size_t v18; // rax
int v19; // ebp
const unsigned __int16 *v20; // rsi
__int64 *v21; // rax
__uid_t v22; // eax
__pid_t pid; // [rsp+0h] [rbp-8C8h] BYREF
int v24; // [rsp+4h] [rbp-8C4h] BYREF
char *v25; // [rsp+8h] [rbp-8C0h] BYREF
char v26[48]; // [rsp+10h] [rbp-8B8h] BYREF
char v27[64]; // [rsp+40h] [rbp-888h] BYREF
char v28[1040]; // [rsp+80h] [rbp-848h] BYREF
char s[1080]; // [rsp+490h] [rbp-438h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char **v5; // rbp
__int64 v6; // rbx
const char *v7; // rcx
__int64 v8; // rdx
time_t v9; // rbx
unsigned int v10; // eax
__int64 v11; // r13
int v12; // edx
signed int v13; // er13
int v14; // edi
char *v15; // r13
size_t v16; // rax
size_t v18; // rax
int v19; // ebp
const unsigned __int16 *v20; // rsi
__int64 *v21; // rax
__uid_t v22; // eax
__pid_t pid; // [rsp+0h] [rbp-8C8h] BYREF
int v24; // [rsp+4h] [rbp-8C4h] BYREF
char *v25; // [rsp+8h] [rbp-8C0h] BYREF
char v26[48]; // [rsp+10h] [rbp-8B8h] BYREF
char v27[64]; // [rsp+40h] [rbp-888h] BYREF
char v28[1040]; // [rsp+80h] [rbp-848h] BYREF
char s[1080]; // [rsp+490h] [rbp-438h] BYREF

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types:
devname
char [-1]

variable_types:
phonebuf
char [40]

variable_types:
buf
char [-1]

variable_types: i int

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

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


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

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

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

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

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

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

variable_types: charout char

variable_types: timeout long

variable_types: result int


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

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

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

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

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

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

variable_types:
buffer
char *


decompiled_code:
__int64 voice_write(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

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

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

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

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

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

variable_types:
format
char *

variable_types:
command
char [-1]


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

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

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

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 __fastcall ISDN4Linux_handle_dle(char a1)
{
__int64 v1; // rdx
const char *v2; // rsi
int v3; // eax
__int64 v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
__int64 v1; // rdx
const char *v2; // rsi
int v3; // eax
__int64 v4; // rax

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

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

variable_types: data char


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

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

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

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

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

variable_types:
number
char *


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

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

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

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

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

variable_types: device int


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

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

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

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

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

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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