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

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

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

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

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

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


repo: Distrotech/mgetty

decompiled_code:
__int64 Sierra_voice_mode_on()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Sierra voice modem");
tio_get(voice_fd, &tio);
qword_5B0 = qword_5F0;
Sierra_tio_save = (__int128)_mm_load_si128((const __m128i *)&tio);
dword_5B8 = dword_5F8;
xmmword_590 = (__int128)_mm_load_si128((const __m128i *)&xmmword_5D0);
xmmword_5A0 = (__int128)_mm_load_si128((const __m128i *)&xmmword_5E0);
if ( (unsigned int)voice_command("AT#VS1", &unk_5FC) != 4096 )
lprintf(3LL, "Voice mode didn't work");
tio_set_speed(&tio, 115200LL);
tio_set(voice_fd, &tio);
sprintf((char *)v1, "ATM2L3#VL=0#VSM=2#VSC=0#VSS=3#VSI=%1u", cvd[110]);
if ( (unsigned int)voice_command(v1, &unk_5FC) != 4096 )
lprintf(3LL, "Couldn't set voice mode options");
v1[0] = 0x303D4656235441LL;
if ( (unsigned int)voice_command(v1, &unk_5FC) != 4096 )
lprintf(3LL, "Couldn't set buffer size to %d", 255LL);
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog();
voice_modem_state = 2;
lprintf(4LL, "initializing Sierra voice modem");
tio_get(voice_fd, &tio);
qword_5B0 = qword_5F0;
Sierra_tio_save = (__int128)_mm_load_si128((const __m128i *)&tio);
dword_5B8 = dword_5F8;
xmmword_590 = (__int128)_mm_load_si128((const __m128i *)&xmmword_5D0);
xmmword_5A0 = (__int128)_mm_load_si128((const __m128i *)&xmmword_5E0);
if ( (unsigned int)voice_command("AT#VS1", &unk_5FC) != 4096 )
lprintf(3LL, "Voice mode didn't work");
tio_set_speed(&tio, 115200LL);
tio_set(voice_fd, &tio);
sprintf((char *)v1, "ATM2L3#VL=0#VSM=2#VSC=0#VSS=3#VSI=%1u", cvd[110]);
if ( (unsigned int)voice_command(v1, &unk_5FC) != 4096 )
lprintf(3LL, "Couldn't set voice mode options");
v1[0] = 0x303D4656235441LL;
if ( (unsigned int)voice_command(v1, &unk_5FC) != 4096 )
lprintf(3LL, "Couldn't set buffer size to %d", 255LL);
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Sierra_voice_mode_on(void)
     {
     char buffer[255];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Sierra voice modem");
     tio_get(voice_fd, &tio);
     Sierra_tio_save = tio;
     if (voice_command("AT#VS1", "OK") != (0x1000))
          lprintf(3, "Voice mode didn't work");
     tio_set_speed(&tio, 115200);
     tio_set(voice_fd, &tio);
     sprintf(buffer, "ATM2L3#VL=0#VSM=2#VSC=0#VSS=3#VSI=%1u",
      (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "Couldn't set voice mode options");
     sprintf(buffer, "AT#VF=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "Couldn't set buffer size to %d", buffer_size);
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Sierra_voice_mode_on()
     {
     char buffer[255];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Sierra voice modem");
     tio_get(voice_fd, &tio);
     Sierra_tio_save = tio;
     if (voice_command("AT#VS1", "OK") != (0x1000))
          lprintf(3, "Voice mode didn't work");
     tio_set_speed(&tio, 115200);
     tio_set(voice_fd, &tio);
     sprintf(buffer, "ATM2L3#VL=0#VSM=2#VSC=0#VSS=3#VSI=%1u",
      (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "Couldn't set voice mode options");
     sprintf(buffer, "AT#VF=0");
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "Couldn't set buffer size to %d", buffer_size);
     voice_modem_state = (0x0001);
     return((0));
     }

variable_types:
buffer
char [255]

return_type: int


decompiled_code:
void getlog_timeout()
{
signal(14, getlog_timeout);
lprintf(3LL, "getlogname: timeout");
++timeouts;
}

canonical_decompiled_code:
void func0()
{
signal(14, getlog_timeout);
lprintf(3LL, "getlogname: timeout");
++timeouts;
}

original_code:
static RETSIGTYPE getlog_timeout()
{
    signal( 14, getlog_timeout );
    lprintf( 3, "getlogname: timeout" );
    timeouts++;
}

canonical_original_code:
static void getlog_timeout()
{
    signal( 14, getlog_timeout );
    lprintf( 3, "getlogname: timeout" );
    timeouts++;
}

return_type: void


strappnd

decompiled_code:
char *__fastcall strappnd(char *a1, const char *a2)
{
return (char *)(stpcpy(a1, a2) - a1);
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, const char *a2)
{
return (char *)(stpcpy(a1, a2) - a1);
}

original_code:
int strappnd (char * s1,char * s2)
{
    strcpy( s1, s2 );
    return strlen( s1 );
}

canonical_original_code:
int strappnd(char *s1, char *s2)
{
    strcpy( s1, s2 );
    return strlen( s1 );
}


decompiled_code:
char *__fastcall ln_escape_prompt(char *a1)
{
char *v1; // rbp
char v2; // al
signed int v3; // ebx
char *v4; // r13
__int64 v5; // r12
size_t v6; // rax
char *v7; // rdx
char *v8; // r13
char *result; // rax
char v10; // r14
const unsigned __int16 **v11; // rax
char *v12; // r15
const char *v13; // r14
unsigned int v14; // eax
char *v15; // r14
struct tm *v16; // rax
char *v17; // rdi
char *v18[15]; // [rsp+0h] [rbp-78h] BYREF

v1 = a1;
if ( !p_2 )
{
p_2 = (char *)malloc(0x12CuLL);
if ( !p_2 )
return a1;
}
if ( !un_cached_1 )
{
uname(&un_0);
un_cached_1 = 1;
}
v2 = *a1;
if ( *a1 )
{
v3 = 0;
while ( 1 )
{
v5 = v3;
if ( v2 == 64 )
{
v6 = strlen(un_0.nodename);
v7 = p_2;
if ( v6 + v3 + 1 > 0x12C )
goto LABEL_14;
v8 = v1++;
v3 += (unsigned int)strappnd(&p_2[v3], un_0.nodename);
v2 = v8[1];
v5 = v3;
if ( v3 > 295 )
goto LABEL_13;
}
else
{
v4 = v1 + 1;
if ( v2 == 92 )
{
v10 = v1[1];
switch ( v10 )
{
case 'C':
v18[0] = (char *)time(0LL);
v15 = ctime((const time_t *)v18);
if ( strlen(v15) + v3 + 1 <= 0x12C )
{
v3 = v3 + (unsigned int)strappnd(&p_2[v3], v15) - 1;
v5 = v3;
}
goto LABEL_20;
case 'D':
case 'T':
if ( v3 <= 270 )
{
v18[0] = (char *)time(0LL);
v16 = localtime((const time_t *)v18);
if ( v16 )
{
v17 = &p_2[v3];
if ( v1[1] == 68 )
sprintf(
v17,
"%d/%d/%d",
(unsigned int)(v16->tm_mon + 1),
(unsigned int)v16->tm_mday,
(unsigned int)(v16->tm_year + 1900));
else
sprintf(
v17,
"%02d:%02d:%02d",
(unsigned int)v16->tm_hour,
(unsigned int)v16->tm_min,
(unsigned int)v16->tm_sec);
v1 += 2;
v3 = strlen(p_2);
v5 = v3;
}
else
{
v1 += 2;
}
}
else
{
v1 += 2;
v3 += (unsigned int)strappnd(&p_2[v3], "(x)");
v5 = v3;
}
break;
case 'I':
v13 = (const char *)Connect;
goto LABEL_24;
case 'L':
case 'P':
v13 = Device;
goto LABEL_24;
case 'N':
case 'U':
v14 = get_current_users();
goto LABEL_27;
case 'R':
v1 += 2;
if ( strlen(un_0.release) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)strappnd(&p_2[v3], un_0.release);
v5 = v3;
}
break;
case 'S':
tio_get(0LL, v18);
v14 = tio_get_speed(v18);
LABEL_27:
v1 += 2;
sprintf(&p_2[v3], "%d", v14);
v3 = strlen(p_2);
v5 = v3;
break;
case 'V':
v1 += 2;
if ( strlen(un_0.version) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)strappnd(&p_2[v3], un_0.version);
v5 = v3;
}
break;
case 'Y':
v13 = (const char *)CallerId;
LABEL_24:
v1 += 2;
if ( strlen(v13) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)strappnd(&p_2[v3], v13);
v5 = v3;
}
break;
case 'b':
++v3;
v1 += 2;
p_2[v5] = 8;
v5 = v3;
break;
case 'f':
++v3;
v1 += 2;
p_2[v5] = 12;
v5 = v3;
break;
case 'g':
++v3;
v1 += 2;
p_2[v5] = 7;
v5 = v3;
break;
case 'm':
v1 += 2;
if ( strlen(un_0.machine) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)strappnd(&p_2[v3], un_0.machine);
v5 = v3;
}
break;
case 'n':
++v3;
v1 += 2;
p_2[v5] = 10;
v5 = v3;
break;
case 'r':
++v3;
v1 += 2;
p_2[v5] = 13;
v5 = v3;
break;
case 's':
v1 += 2;
if ( strlen(un_0.sysname) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)strappnd(&p_2[v3], un_0.sysname);
v5 = v3;
}
break;
case 't':
++v3;
v1 += 2;
p_2[v5] = 9;
v5 = v3;
break;
case 'v':
++v3;
v1 += 2;
p_2[v5] = 11;
v5 = v3;
break;
default:
v11 = _ctype_b_loc();
++v3;
v12 = &p_2[v5];
v5 = v3;
if ( ((*v11)[v10] & 0x800) != 0 )
{
*v12 = strtol(v1 + 1, v18, 0);
v1 = v18[0];
v4 = v18[0] - 1;
}
else
{
*v12 = v10;
LABEL_20:
v1 += 2;
}
break;
}
}
else
{
++v3;
p_2[v5] = v2;
v5 = v3;
v4 = v1++;
}
v2 = v4[1];
if ( v3 > 295 )
goto LABEL_13;
}
if ( !v2 )
goto LABEL_13;
}
}
v5 = 0LL;
LABEL_13:
v7 = p_2;
LABEL_14:
v7[v5] = 0;
result = v7;
if ( *v1 )
{
lprintf(3LL, "ln_escape_prompt: input line too long - data truncated");
result = p_2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
char *v1; // rbp
char v2; // al
signed int v3; // ebx
char *v4; // r13
__int64 v5; // r12
size_t v6; // rax
char *v7; // rdx
char *v8; // r13
char *result; // rax
char v10; // r14
const unsigned __int16 **v11; // rax
char *v12; // r15
const char *v13; // r14
unsigned int v14; // eax
char *v15; // r14
struct tm *v16; // rax
char *v17; // rdi
char *v18[15]; // [rsp+0h] [rbp-78h] BYREF

v1 = a1;
if ( !p_2 )
{
p_2 = (char *)malloc(0x12CuLL);
if ( !p_2 )
return a1;
}
if ( !un_cached_1 )
{
uname(&un_0);
un_cached_1 = 1;
}
v2 = *a1;
if ( *a1 )
{
v3 = 0;
while ( 1 )
{
v5 = v3;
if ( v2 == 64 )
{
v6 = strlen(un_0.nodename);
v7 = p_2;
if ( v6 + v3 + 1 > 0x12C )
goto LABEL_14;
v8 = v1++;
v3 += (unsigned int)func1(&p_2[v3], un_0.nodename);
v2 = v8[1];
v5 = v3;
if ( v3 > 295 )
goto LABEL_13;
}
else
{
v4 = v1 + 1;
if ( v2 == 92 )
{
v10 = v1[1];
switch ( v10 )
{
case 'C':
v18[0] = (char *)time(0LL);
v15 = ctime((const time_t *)v18);
if ( strlen(v15) + v3 + 1 <= 0x12C )
{
v3 = v3 + (unsigned int)func1(&p_2[v3], v15) - 1;
v5 = v3;
}
goto LABEL_20;
case 'D':
case 'T':
if ( v3 <= 270 )
{
v18[0] = (char *)time(0LL);
v16 = localtime((const time_t *)v18);
if ( v16 )
{
v17 = &p_2[v3];
if ( v1[1] == 68 )
sprintf(
v17,
"%d/%d/%d",
(unsigned int)(v16->tm_mon + 1),
(unsigned int)v16->tm_mday,
(unsigned int)(v16->tm_year + 1900));
else
sprintf(
v17,
"%02d:%02d:%02d",
(unsigned int)v16->tm_hour,
(unsigned int)v16->tm_min,
(unsigned int)v16->tm_sec);
v1 += 2;
v3 = strlen(p_2);
v5 = v3;
}
else
{
v1 += 2;
}
}
else
{
v1 += 2;
v3 += (unsigned int)func1(&p_2[v3], "(x)");
v5 = v3;
}
break;
case 'I':
v13 = (const char *)Connect;
goto LABEL_24;
case 'L':
case 'P':
v13 = Device;
goto LABEL_24;
case 'N':
case 'U':
v14 = get_current_users();
goto LABEL_27;
case 'R':
v1 += 2;
if ( strlen(un_0.release) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)func1(&p_2[v3], un_0.release);
v5 = v3;
}
break;
case 'S':
tio_get(0LL, v18);
v14 = tio_get_speed(v18);
LABEL_27:
v1 += 2;
sprintf(&p_2[v3], "%d", v14);
v3 = strlen(p_2);
v5 = v3;
break;
case 'V':
v1 += 2;
if ( strlen(un_0.version) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)func1(&p_2[v3], un_0.version);
v5 = v3;
}
break;
case 'Y':
v13 = (const char *)CallerId;
LABEL_24:
v1 += 2;
if ( strlen(v13) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)func1(&p_2[v3], v13);
v5 = v3;
}
break;
case 'b':
++v3;
v1 += 2;
p_2[v5] = 8;
v5 = v3;
break;
case 'f':
++v3;
v1 += 2;
p_2[v5] = 12;
v5 = v3;
break;
case 'g':
++v3;
v1 += 2;
p_2[v5] = 7;
v5 = v3;
break;
case 'm':
v1 += 2;
if ( strlen(un_0.machine) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)func1(&p_2[v3], un_0.machine);
v5 = v3;
}
break;
case 'n':
++v3;
v1 += 2;
p_2[v5] = 10;
v5 = v3;
break;
case 'r':
++v3;
v1 += 2;
p_2[v5] = 13;
v5 = v3;
break;
case 's':
v1 += 2;
if ( strlen(un_0.sysname) + v3 + 1 <= 0x12C )
{
v3 += (unsigned int)func1(&p_2[v3], un_0.sysname);
v5 = v3;
}
break;
case 't':
++v3;
v1 += 2;
p_2[v5] = 9;
v5 = v3;
break;
case 'v':
++v3;
v1 += 2;
p_2[v5] = 11;
v5 = v3;
break;
default:
v11 = _ctype_b_loc();
++v3;
v12 = &p_2[v5];
v5 = v3;
if ( ((*v11)[v10] & 0x800) != 0 )
{
*v12 = strtol(v1 + 1, v18, 0);
v1 = v18[0];
v4 = v18[0] - 1;
}
else
{
*v12 = v10;
LABEL_20:
v1 += 2;
}
break;
}
}
else
{
++v3;
p_2[v5] = v2;
v5 = v3;
v4 = v1++;
}
v2 = v4[1];
if ( v3 > 295 )
goto LABEL_13;
}
if ( !v2 )
goto LABEL_13;
}
}
v5 = 0LL;
LABEL_13:
v7 = p_2;
LABEL_14:
v7[v5] = 0;
result = v7;
if ( *v1 )
{
lprintf(3LL, "ln_escape_prompt: input line too long - data truncated");
result = p_2;
}
return result;
}

original_code:
char * ln_escape_prompt (char * ep)
{
    static char * p = ((void *)0);
    int i;
    static struct utsname un;
    static boolean un_cached = (1==0);
    if ( p == ((void *)0) ) p = malloc( 300 );
    if ( p == ((void *)0) ) return ep;
    if ( ! un_cached )
    {
 uname( &un );
 un_cached = (1==1);
    }
    i = 0;
    while ( *ep != 0 && i < 300 -4 )
    {
 if ( *ep == '@' )
 {
     if ( strlen( un.nodename ) +1 +i > 300 ) break;
     i += strappnd( &p[i], un.nodename );
 }
 else if ( *ep != '\\' ) p[i++] = *ep;
 else
 {
     ep++;
     switch ( *ep )
     {
       case 'n': p[i++] = '\n'; break;
       case 'r': p[i++] = '\r'; break;
       case 'g': p[i++] = '\007'; break;
       case 'b': p[i++] = '\010'; break;
       case 'v': p[i++] = '\013'; break;
       case 'f': p[i++] = '\f'; break;
       case 't': p[i++] = '\t'; break;
       case 's':
      if ( i + strlen(un.sysname) +1 > 300 ) break;
      i += strappnd( &p[i], un.sysname );
      break;
       case 'm':
      if ( i + strlen(un.machine) +1 > 300 ) break;
      i += strappnd( &p[i], un.machine );
      break;
       case 'R':
      if ( i + strlen(un.release) +1 > 300 ) break;
      i += strappnd( &p[i], un.release );
      break;
       case 'V':
      if ( i + strlen(un.version) +1 > 300 ) break;
      i += strappnd( &p[i], un.version );
      break;
       case 'Y':
  {
  extern char * CallerId;
      if ( i + strlen(CallerId) +1 > 300 ) break;
      i += strappnd( &p[i], CallerId );
      break;
  }
       case 'P':
       case 'L':
  {
      if ( i + strlen(Device) +1 > 300 ) break;
      i += strappnd( &p[i], Device );
      break;
  }
       case 'C':
  {
      time_t ti = time(((void *)0));
      char * h = ctime( &ti );
      if ( strlen(h) +1 +i > 300 ) break;
      i += strappnd( &p[i], h ) -1;
      break;
  }
       case 'I':
  {
      if ( strlen(Connect) +1 +i > 300 ) break;
      i += strappnd( &p[i], Connect);
      break;
  }
       case 'N':
       case 'U':
  {
      sprintf( &p[i], "%d", get_current_users() );
      i = strlen(p);
      break;
  }
       case 'S':
  {
      TIO temp_t;
      tio_get( 0, &temp_t );
      sprintf( &p[i], "%d", tio_get_speed( &temp_t ) );
      i = strlen(p);
  }
  break;
       case 'D':
       case 'T':
  if ( i + 30 > 300 )
  {
      i += strappnd( &p[i], "(x)" ); break;
  }
  else
  {
      time_t ti = time( ((void *)0) );
      struct tm * tm = localtime( &ti );
      if ( tm == ((void *)0) ) break;
      if ( *ep == 'D' )
          sprintf( &p[i], "%d/%d/%d", tm->tm_mon+1,
     tm->tm_mday, tm->tm_year + 1900 );
      else
          sprintf( &p[i], "%02d:%02d:%02d", tm->tm_hour,
     tm->tm_min, tm->tm_sec );
      i = strlen(p);
  }
  break;
       default:
  if ( ((*__ctype_b_loc ())[(int) ((*ep))] & (unsigned short int) _ISdigit) )
  {
      char * help;
      p[i++] = strtol( ep, &help, 0 );
      ep = help-1;
  }
  else p[i++] = *ep;
     }
 }
 ep++;
    }
    p[i] = 0;
    if ( *ep != 0 )
    {
 lprintf( 3, "ln_escape_prompt: input line too long - data truncated" );
    }
    return p;
}

canonical_original_code:
char *ln_escape_prompt(char *ep)
{
    static char *p = ((void *)0);
    int i;
    static struct utsname un;
    static char un_cached = (1==0);
    if ( p == ((void *)0) ) p = malloc( 300 );
    if ( p == ((void *)0) ) return ep;
    if ( ! un_cached )
    {
 uname( &un );
 un_cached = (1==1);
    }
    i = 0;
    while ( *ep != 0 && i < 300 -4 )
    {
 if ( *ep == '@' )
 {
     if ( strlen( un.nodename ) +1 +i > 300 ) break;
     i += strappnd( &p[i], un.nodename );
 }
 else if ( *ep != '\\' ) p[i++] = *ep;
 else
 {
     ep++;
     switch ( *ep )
     {
       case 'n': p[i++] = '\n'; break;
       case 'r': p[i++] = '\r'; break;
       case 'g': p[i++] = '\007'; break;
       case 'b': p[i++] = '\010'; break;
       case 'v': p[i++] = '\013'; break;
       case 'f': p[i++] = '\f'; break;
       case 't': p[i++] = '\t'; break;
       case 's':
      if ( i + strlen(un.sysname) +1 > 300 ) break;
      i += strappnd( &p[i], un.sysname );
      break;
       case 'm':
      if ( i + strlen(un.machine) +1 > 300 ) break;
      i += strappnd( &p[i], un.machine );
      break;
       case 'R':
      if ( i + strlen(un.release) +1 > 300 ) break;
      i += strappnd( &p[i], un.release );
      break;
       case 'V':
      if ( i + strlen(un.version) +1 > 300 ) break;
      i += strappnd( &p[i], un.version );
      break;
       case 'Y':
  {
  extern char *CallerId;
      if ( i + strlen(CallerId) +1 > 300 ) break;
      i += strappnd( &p[i], CallerId );
      break;
  }
       case 'P':
       case 'L':
  {
      if ( i + strlen(Device) +1 > 300 ) break;
      i += strappnd( &p[i], Device );
      break;
  }
       case 'C':
  {
      long ti = time(((void *)0));
      char *h = ctime( &ti );
      if ( strlen(h) +1 +i > 300 ) break;
      i += strappnd( &p[i], h ) -1;
      break;
  }
       case 'I':
  {
      if ( strlen(Connect) +1 +i > 300 ) break;
      i += strappnd( &p[i], Connect);
      break;
  }
       case 'N':
       case 'U':
  {
      sprintf( &p[i], "%d", get_current_users() );
      i = strlen(p);
      break;
  }
       case 'S':
  {
      struct termios temp_t;
      tio_get( 0, &temp_t );
      sprintf( &p[i], "%d", tio_get_speed( &temp_t ) );
      i = strlen(p);
  }
  break;
       case 'D':
       case 'T':
  if ( i + 30 > 300 )
  {
      i += strappnd( &p[i], "(x)" ); break;
  }
  else
  {
      long ti = time( ((void *)0) );
      struct tm *tm = localtime( &ti );
      if ( tm == ((void *)0) ) break;
      if ( *ep == 'D' )
          sprintf( &p[i], "%d/%d/%d", tm->tm_mon+1,
     tm->tm_mday, tm->tm_year + 1900 );
      else
          sprintf( &p[i], "%02d:%02d:%02d", tm->tm_hour,
     tm->tm_min, tm->tm_sec );
      i = strlen(p);
  }
  break;
       default:
  if ( ((*__ctype_b_loc ())[(int) ((*ep))] & (unsigned short) _ISdigit) )
  {
      char *help;
      p[i++] = strtol( ep, &help, 0 );
      ep = help-1;
  }
  else p[i++] = *ep;
     }
 }
 ep++;
    }
    p[i] = 0;
    if ( *ep != 0 )
    {
 lprintf( 3, "ln_escape_prompt: input line too long - data truncated" );
    }
    return p;
}

variable_types:
ep
char *

variable_types:
p
char *

variable_types: i int

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types:
CallerId
char *

variable_types: ti long

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
help
char *

return_type: char *


decompiled_code:
int __fastcall set_env_var(const char *a1, const char *a2)
{
size_t v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
int result; // eax

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 2);
if ( !v4 )
return lprintf(1LL, "set_env_var: cannot malloc");
v5 = v4;
sprintf(v4, "%s=%s", a1, a2);
lprintf(5LL, "setenv: '%s'", v5);
result = putenv(v5);
if ( result )
result = lprintf(1LL, "putenv failed");
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, const char *a2)
{
size_t v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
int result; // eax

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 2);
if ( !v4 )
return lprintf(1LL, "set_env_var: cannot malloc");
v5 = v4;
sprintf(v4, "%s=%s", a1, a2);
lprintf(5LL, "setenv: '%s'", v5);
result = putenv(v5);
if ( result )
result = lprintf(1LL, "putenv failed");
return result;
}

original_code:
void set_env_var (char * var,char * string)
{
    char * v;
    v = malloc( strlen(var) + strlen(string) + 2 );
    if ( v == ((void *)0) )
        lprintf( 1, "set_env_var: cannot malloc" );
    else
    {
 sprintf( v, "%s=%s", var, string );
 lprintf( 5, "setenv: '%s'", v );
 if ( putenv( v ) != 0 )
     lprintf( 1, "putenv failed" );
    }
}

canonical_original_code:
void set_env_var(char *var, char *string)
{
    char *v;
    v = malloc( strlen(var) + strlen(string) + 2 );
    if ( v == ((void *)0) )
        lprintf( 1, "set_env_var: cannot malloc" );
    else
    {
 sprintf( v, "%s=%s", var, string );
 lprintf( 5, "setenv: '%s'", v );
 if ( putenv( v ) != 0 )
     lprintf( 1, "putenv failed" );
    }
}

variable_types:
var
char *

variable_types:
string
char *

variable_types:
v
char *


getlogname

decompiled_code:
__int64 __fastcall getlogname(char *a1, __m128i *a2, const char *a3, int a4, signed int a5, __int64 a6, char a7)
{
int v11; // eax
char *v12; // rax
const char *v13; // r13
int v14; // ebx
int v15; // eax
__int64 v16; // rsi
unsigned __int8 v17; // al
signed __int8 v18; // di
__int64 v19; // rdx
int v20; // ebx
__m128i v21; // xmm3
__m128i v22; // xmm4
int v23; // eax
__m128i v24; // xmm5
unsigned int v26; // eax
unsigned int v27; // eax
unsigned __int8 buf; // [rsp+Fh] [rbp-79h] BYREF
__m128i v29; // [rsp+10h] [rbp-78h] BYREF
__m128i v30; // [rsp+20h] [rbp-68h] BYREF
__m128i v31; // [rsp+30h] [rbp-58h] BYREF
__int64 v32; // [rsp+40h] [rbp-48h]
int v33; // [rsp+48h] [rbp-40h]

v32 = a2[3].m128i_i64[0];
v11 = a2[3].m128i_i32[2];
v29 = _mm_loadu_si128(a2);
v30 = _mm_loadu_si128(a2 + 1);
v31 = _mm_loadu_si128(a2 + 2);
v33 = v11;
tio_mode_raw(a2);
tio_set(0LL, a2);
v12 = ln_escape_prompt(a1);
v13 = v12;
if ( a7 )
{
printf("\r\n%s", v12);
tio_mode_sane(a2, 0LL);
tio_map_cr(a2, 1LL);
tio_set(0LL, a2);
*a3 = 0;
set_env_var("TTYPROMPT", v13);
return 0LL;
}
if ( a5 > 0 )
{
signal(14, (__sighandler_t)getlog_timeout);
alarm(a5);
}
LABEL_4:
printf("\r\n%s", v13);
if ( ferror(stdin) )
lprintf(1LL, "getlogname: error writing prompt");
v14 = 0;
lprintf(5LL, "getlogname (no opts), read:");
do
{
while ( 1 )
{
v15 = read(0, &buf, 1uLL);
if ( v15 == 1 )
{
v16 = (unsigned int)(char)buf;
}
else
{
if ( !v15 )
{
lprintf(4LL, "getlogname: got EOF, exiting");
exit(0);
}
if ( *_errno_location() != 4 )
goto LABEL_38;
if ( timeouts > 1 )
{
printf("\r\n\a\r\nYour login time (%d minutes) ran out. Goodbye.\r\n", (unsigned int)(a5 / 60 + 1));
sleep(3u);
v26 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, login time out", Device, v26);
LABEL_38:
exit(0);
}
puts("\r\n\a\r\nHey! Please login now. You have one minute left\r");
alarm(0x3Cu);
buf = 21;
v16 = 21LL;
}
lputc(5LL, v16);
v17 = buf;
if ( buf <= 1u )
break;
v18 = buf & 0x7F;
buf = v18;
switch ( v18 )
{
case 28:
goto LABEL_38;
case 4:
if ( !v14 )
goto LABEL_38;
break;
case 21:
case 3:
goto LABEL_4;
default:
if ( (v17 & 0x7D) == 17 )
{
v17 = v18;
goto LABEL_30;
}
if ( v18 == 127 || v18 == 8 )
{
v17 = v18;
if ( v14 > 0 )
{
--v14;
fwrite("\b \b", 1uLL, 3uLL, stdout);
v17 = buf;
}
goto LABEL_30;
}
if ( v18 != 27 )
{
putc(v18, stdout);
if ( v14 < a4 )
{
if ( buf == 32 )
{
if ( v14 )
{
LABEL_25:
v19 = v14++;
a3[v19] = buf;
goto LABEL_26;
}
}
else if ( v14 || buf != 45 )
{
goto LABEL_25;
}
}
fwrite("\b \b", 1uLL, 3uLL, stdout);
LABEL_26:
if ( v14 > 6 && !memcmp(&a3[v14 - 7], "**EMSI_", 7uLL) )
lprintf(4LL, "incoming fido call, but no FIDO support");
v17 = buf;
goto LABEL_30;
}
break;
}
}
LABEL_30:
;
}
while ( v17 != 10 && v17 != 13 );
v20 = v14 - 1;
alarm(0);
a3[v20] = 0;
v21 = _mm_loadu_si128(&v29);
v22 = _mm_loadu_si128(&v30);
a2[3].m128i_i64[0] = v32;
v23 = v33;
v24 = _mm_loadu_si128(&v31);
*a2 = v21;
a2[3].m128i_i32[2] = v23;
a2[1] = v22;
a2[2] = v24;
if ( !strcmp(a3, "NO CARRIER") || !strcmp(a3, "ERROR") )
{
v27 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, got modem error '%s'", Device, v27, a3);
exit(0);
}
if ( buf == 10 )
{
tio_map_cr(a2, 0LL);
fputc(13, stdout);
}
else
{
tio_map_cr(a2, 1LL);
fputc(10, stdout);
lprintf(5LL, "input finished with '\\r', setting ICRNL ONLCR");
}
tio_drain_output(0LL);
tio_set(0LL, a2);
return (unsigned int)-(v20 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, __m128i *a2, const char *a3, int a4, signed int a5, __int64 a6, char a7)
{
int v11; // eax
char *v12; // rax
const char *v13; // r13
int v14; // ebx
int v15; // eax
__int64 v16; // rsi
unsigned __int8 v17; // al
signed __int8 v18; // di
__int64 v19; // rdx
int v20; // ebx
__m128i v21; // xmm3
__m128i v22; // xmm4
int v23; // eax
__m128i v24; // xmm5
unsigned int v26; // eax
unsigned int v27; // eax
unsigned __int8 buf; // [rsp+Fh] [rbp-79h] BYREF
__m128i v29; // [rsp+10h] [rbp-78h] BYREF
__m128i v30; // [rsp+20h] [rbp-68h] BYREF
__m128i v31; // [rsp+30h] [rbp-58h] BYREF
__int64 v32; // [rsp+40h] [rbp-48h]
int v33; // [rsp+48h] [rbp-40h]

v32 = a2[3].m128i_i64[0];
v11 = a2[3].m128i_i32[2];
v29 = _mm_loadu_si128(a2);
v30 = _mm_loadu_si128(a2 + 1);
v31 = _mm_loadu_si128(a2 + 2);
v33 = v11;
tio_mode_raw(a2);
tio_set(0LL, a2);
v12 = func2(a1);
v13 = v12;
if ( a7 )
{
printf("\r\n%s", v12);
tio_mode_sane(a2, 0LL);
tio_map_cr(a2, 1LL);
tio_set(0LL, a2);
*a3 = 0;
func3("TTYPROMPT", v13);
return 0LL;
}
if ( a5 > 0 )
{
signal(14, (__sighandler_t)getlog_timeout);
alarm(a5);
}
LABEL_4:
printf("\r\n%s", v13);
if ( ferror(stdin) )
lprintf(1LL, "getlogname: error writing prompt");
v14 = 0;
lprintf(5LL, "getlogname (no opts), read:");
do
{
while ( 1 )
{
v15 = read(0, &buf, 1uLL);
if ( v15 == 1 )
{
v16 = (unsigned int)(char)buf;
}
else
{
if ( !v15 )
{
lprintf(4LL, "getlogname: got EOF, exiting");
exit(0);
}
if ( *_errno_location() != 4 )
goto LABEL_38;
if ( timeouts > 1 )
{
printf("\r\n\a\r\nYour login time (%d minutes) ran out. Goodbye.\r\n", (unsigned int)(a5 / 60 + 1));
sleep(3u);
v26 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, login time out", Device, v26);
LABEL_38:
exit(0);
}
puts("\r\n\a\r\nHey! Please login now. You have one minute left\r");
alarm(0x3Cu);
buf = 21;
v16 = 21LL;
}
lputc(5LL, v16);
v17 = buf;
if ( buf <= 1u )
break;
v18 = buf & 0x7F;
buf = v18;
switch ( v18 )
{
case 28:
goto LABEL_38;
case 4:
if ( !v14 )
goto LABEL_38;
break;
case 21:
case 3:
goto LABEL_4;
default:
if ( (v17 & 0x7D) == 17 )
{
v17 = v18;
goto LABEL_30;
}
if ( v18 == 127 || v18 == 8 )
{
v17 = v18;
if ( v14 > 0 )
{
--v14;
fwrite("\b \b", 1uLL, 3uLL, stdout);
v17 = buf;
}
goto LABEL_30;
}
if ( v18 != 27 )
{
putc(v18, stdout);
if ( v14 < a4 )
{
if ( buf == 32 )
{
if ( v14 )
{
LABEL_25:
v19 = v14++;
a3[v19] = buf;
goto LABEL_26;
}
}
else if ( v14 || buf != 45 )
{
goto LABEL_25;
}
}
fwrite("\b \b", 1uLL, 3uLL, stdout);
LABEL_26:
if ( v14 > 6 && !memcmp(&a3[v14 - 7], "**EMSI_", 7uLL) )
lprintf(4LL, "incoming fido call, but no FIDO support");
v17 = buf;
goto LABEL_30;
}
break;
}
}
LABEL_30:
;
}
while ( v17 != 10 && v17 != 13 );
v20 = v14 - 1;
alarm(0);
a3[v20] = 0;
v21 = _mm_loadu_si128(&v29);
v22 = _mm_loadu_si128(&v30);
a2[3].m128i_i64[0] = v32;
v23 = v33;
v24 = _mm_loadu_si128(&v31);
*a2 = v21;
a2[3].m128i_i32[2] = v23;
a2[1] = v22;
a2[2] = v24;
if ( !strcmp(a3, "NO CARRIER") || !strcmp(a3, "ERROR") )
{
v27 = getpid();
lprintf(2LL, "failed dev=%s, pid=%d, got modem error '%s'", Device, v27, a3);
exit(0);
}
if ( buf == 10 )
{
tio_map_cr(a2, 0LL);
fputc(13, stdout);
}
else
{
tio_map_cr(a2, 1LL);
fputc(10, stdout);
lprintf(5LL, "input finished with '\\r', setting ICRNL ONLCR");
}
tio_drain_output(0LL);
tio_set(0LL, a2);
return (unsigned int)-(v20 == 0);
}

original_code:
int getlogname (char * prompt,TIO * tio,char * buf,int maxsize,int max_login_time,boolean do_fido,boolean env_ttyprompt)
{
    int i, r;
    char ch;
    TIO tio_save;
    char * final_prompt;
    tio_save = *tio;
    tio_mode_raw( tio );
    tio_set( 0, tio );
    final_prompt = ln_escape_prompt( prompt );
    if ( env_ttyprompt )
    {
 printf( "\r\n%s", final_prompt );
 tio_mode_sane( tio, (1==0) );
 tio_map_cr( tio, (1==1) );
 tio_set( 0, tio );
 buf[0] = 0;
 set_env_var( "TTYPROMPT", final_prompt );
 return 0;
    }
    if ( max_login_time > 0 )
    {
 signal( 14, getlog_timeout );
 alarm( max_login_time );
    }
  newlogin:
    printf( "\r\n%s", final_prompt );
    if ( ferror( stdin ) )
    {
 lprintf( 1, "getlogname: error writing prompt" );
    }
    lprintf( 5, "getlogname (no opts), read:" );
    i = 0;
    do
    {
 if ( ( r = read( 0, &ch, 1 ) ) != 1 )
 {
     if ( r == 0 )
     {
  lprintf( 4, "getlogname: got EOF, exiting" );
  exit(0);
     }
     if ( (*__errno_location ()) != 4 ) exit(0);
     if ( timeouts <= 1 )
     {
  printf( "\r\n\07\r\nHey! Please login now. You have one minute left\r\n" );
  alarm(60);
     }
     else
     {
  printf( "\r\n\07\r\nYour login time (%d minutes) ran out. Goodbye.\r\n",
         (max_login_time / 60)+1 );
  sleep(3);
  lprintf( 2, "failed dev=%s, pid=%d, login time out",
    Device, getpid() );
  exit(0);
     }
     ch = ('u'&037);
 }
 lputc( 5, ch );
 if ( ch == 0 || ch == 1 ) continue;
 ch = ch & 0x7f;
 if ( ch == 034 ) exit(0);
 if ( ch == ('d'&037) )
 {
            if ( i == 0 ) exit(0); else continue;
 }
 if ( ch == ('u'&037) || ch == 03 ) goto newlogin;
 if ( ch == ('q'&037) || ch == ('s'&037) ) continue;
 if ( ch == 0x7f || ch == 0x08 || ch == 0177 )
 {
     if ( i > 0 )
     {
  fputs( "\b \b", stdout );
  i--;
     }
 }
 else
   if ( ch != 27 )
 {
     putc( ch, stdout );
     if ( i >= maxsize ||
   ( ch == ' ' && i == 0 ) ||
   ( ch == '-' && i == 0 ) )
  fputs( "\b \b", stdout );
     else
  buf[i++] = ch;
     if ( i >= 7 && strncmp( &buf[i-7], "**EMSI_", 7 ) == 0 )
     {
  lprintf( 4, "incoming fido call, but no FIDO support" );
     }
 }
    }
    while ( ch != '\n' && ch != '\r' );
    alarm(0);
    buf[--i] = 0;
    *tio = tio_save;
    if( strcmp(buf,"NO CARRIER") == 0 ||
        strcmp(buf,"ERROR") == 0 )
    {
 lprintf( 2, "failed dev=%s, pid=%d, got modem error '%s'",
                 Device, getpid(), buf );
 exit(0);
    }
    if ( ch == '\n' )
    {
 tio_map_cr( tio, (1==0) );
 fputc( '\r', stdout );
    }
    else
    {
 tio_map_cr( tio, (1==1) );
 fputc( '\n', stdout );
 lprintf( 5, "input finished with '\\r', setting ICRNL ONLCR" );
    }
    tio_drain_output( 0 );
    tio_set( 0, tio );
    if ( i == 0 ) return -1;
    else return 0;
}

canonical_original_code:
int getlogname(char *prompt, struct termios *tio, char *buf, int maxsize, int max_login_time, char do_fido, char env_ttyprompt)
{
    int i; int r;
    char ch;
    struct termios tio_save;
    char *final_prompt;
    tio_save = *tio;
    tio_mode_raw( tio );
    tio_set( 0, tio );
    final_prompt = ln_escape_prompt( prompt );
    if ( env_ttyprompt )
    {
 printf( "\r\n%s", final_prompt );
 tio_mode_sane( tio, (1==0) );
 tio_map_cr( tio, (1==1) );
 tio_set( 0, tio );
 buf[0] = 0;
 set_env_var( "TTYPROMPT", final_prompt );
 return 0;
    }
    if ( max_login_time > 0 )
    {
 signal( 14, getlog_timeout );
 alarm( max_login_time );
    }
  newlogin:
    printf( "\r\n%s", final_prompt );
    if ( ferror( stdin ) )
    {
 lprintf( 1, "getlogname: error writing prompt" );
    }
    lprintf( 5, "getlogname (no opts), read:" );
    i = 0;
    do
    {
 if ( ( r = read( 0, &ch, 1 ) ) != 1 )
 {
     if ( r == 0 )
     {
  lprintf( 4, "getlogname: got EOF, exiting" );
  exit(0);
     }
     if ( (*__errno_location ()) != 4 ) exit(0);
     if ( timeouts <= 1 )
     {
  printf( "\r\n\07\r\nHey! Please login now. You have one minute left\r\n" );
  alarm(60);
     }
     else
     {
  printf( "\r\n\07\r\nYour login time (%d minutes) ran out. Goodbye.\r\n",
         (max_login_time / 60)+1 );
  sleep(3);
  lprintf( 2, "failed dev=%s, pid=%d, login time out",
    Device, getpid() );
  exit(0);
     }
     ch = ('u'&037);
 }
 lputc( 5, ch );
 if ( ch == 0 || ch == 1 ) continue;
 ch = ch & 0x7f;
 if ( ch == 034 ) exit(0);
 if ( ch == ('d'&037) )
 {
            if ( i == 0 ) exit(0); else continue;
 }
 if ( ch == ('u'&037) || ch == 03 ) goto newlogin;
 if ( ch == ('q'&037) || ch == ('s'&037) ) continue;
 if ( ch == 0x7f || ch == 0x08 || ch == 0177 )
 {
     if ( i > 0 )
     {
  fputs( "\b \b", stdout );
  i--;
     }
 }
 else
   if ( ch != 27 )
 {
     putc( ch, stdout );
     if ( i >= maxsize ||
   ( ch == ' ' && i == 0 ) ||
   ( ch == '-' && i == 0 ) )
  fputs( "\b \b", stdout );
     else
  buf[i++] = ch;
     if ( i >= 7 && strncmp( &buf[i-7], "**EMSI_", 7 ) == 0 )
     {
  lprintf( 4, "incoming fido call, but no FIDO support" );
     }
 }
    }
    while ( ch != '\n' && ch != '\r' );
    alarm(0);
    buf[--i] = 0;
    *tio = tio_save;
    if( strcmp(buf,"NO CARRIER") == 0 ||
        strcmp(buf,"ERROR") == 0 )
    {
 lprintf( 2, "failed dev=%s, pid=%d, got modem error '%s'",
                 Device, getpid(), buf );
 exit(0);
    }
    if ( ch == '\n' )
    {
 tio_map_cr( tio, (1==0) );
 fputc( '\r', stdout );
    }
    else
    {
 tio_map_cr( tio, (1==1) );
 fputc( '\n', stdout );
 lprintf( 5, "input finished with '\\r', setting ICRNL ONLCR" );
    }
    tio_drain_output( 0 );
    tio_set( 0, tio );
    if ( i == 0 ) return -1;
    else return 0;
}

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

variable_types:
buf
char *

variable_types: maxsize int

variable_types: r int

variable_types: ch char


decompiled_code:
__int64 __fastcall lock_write_pid(int fd)
{
unsigned int v1; // eax
size_t v2; // rax
ssize_t v3; // rbx
__int64 result; // rax
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = getpid();
sprintf(v5, "%10d\n", v1);
v2 = strlen(v5);
v3 = write(fd, v5, v2);
if ( v3 == strlen(v5) )
{
close(fd);
result = 0LL;
}
else
{
lprintf(0LL, "cannot write PID to (temp) lock file");
close(fd);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
unsigned int v1; // eax
size_t v2; // rax
ssize_t v3; // rbx
__int64 result; // rax
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = getpid();
sprintf(v5, "%10d\n", v1);
v2 = strlen(v5);
v3 = write(fd, v5, v2);
if ( v3 == strlen(v5) )
{
close(fd);
result = 0LL;
}
else
{
lprintf(0LL, "cannot write PID to (temp) lock file");
close(fd);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int lock_write_pid (int fd)
{
    char apid[16];
    sprintf( apid, "%10d\n", (int) getpid() );
    if ( write(fd, apid, strlen(apid)) != strlen(apid) )
    {
 lprintf( 0, "cannot write PID to (temp) lock file" );
 close(fd);
 return(-1);
    }
    close(fd);
    return 0;
}

canonical_original_code:
static int lock_write_pid(int fd)
{
    char apid[16];
    sprintf( apid, "%10d\n", (int) getpid() );
    if ( write(fd, apid, strlen(apid)) != strlen(apid) )
    {
 lprintf( 0, "cannot write PID to (temp) lock file" );
 close(fd);
 return(-1);
    }
    close(fd);
    return 0;
}

variable_types: fd int

variable_types:
apid
char [16]


readlock

decompiled_code:
__int64 __fastcall readlock(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // ebx
unsigned int v5; // [rsp+Ch] [rbp-3Ch] BYREF
int buf[14]; // [rsp+10h] [rbp-38h] BYREF

v1 = open(a1, 0);
v2 = v1;
if ( v1 != -1 )
{
v5 = 0;
v3 = read(v1, buf, 0x13uLL);
*((_BYTE *)buf + (int)v3) = 0;
if ( v3 == 4 || (unsigned int)_isoc99_sscanf(buf, "%d", &v5) != 1 || !v5 )
{
v5 = buf[0];
lprintf(3LL, "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", v3, (unsigned int)buf[0]);
}
close(v2);
v2 = v5;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // ebx
unsigned int v5; // [rsp+Ch] [rbp-3Ch] BYREF
int buf[14]; // [rsp+10h] [rbp-38h] BYREF

v1 = open(a1, 0);
v2 = v1;
if ( v1 != -1 )
{
v5 = 0;
v3 = read(v1, buf, 0x13uLL);
*((_BYTE *)buf + (int)v3) = 0;
if ( v3 == 4 || (unsigned int)_isoc99_sscanf(buf, "%d", &v5) != 1 || !v5 )
{
v5 = buf[0];
lprintf(3LL, "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", v3, (unsigned int)buf[0]);
}
close(v2);
v2 = v5;
}
return v2;
}

original_code:
static int readlock (char * name)
{
 int fd, pid;
 char apid[20];
 int length;
 if ((fd = open(name, 00)) == -1)
  return(-1);
 length = read(fd, apid, sizeof(apid)-1);
 apid[length]=0;
 pid = 0;
 if ( length == sizeof( pid ) || sscanf(apid, "%d", &pid) != 1 ||
      pid == 0 )
 {
     pid = * ( (int *) apid );
     lprintf( 3, "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", length, pid );
 }
 (void) close(fd);
 return(pid);
}

canonical_original_code:
static int readlock(char *name)
{
 int fd; int pid;
 char apid[20];
 int length;
 if ((fd = open(name, 00)) == -1)
  return(-1);
 length = read(fd, apid, sizeof(apid)-1);
 apid[length]=0;
 pid = 0;
 if ( length == sizeof( pid ) || sscanf(apid, "%d", &pid) != 1 ||
      pid == 0 )
 {
     pid = * ( (int *) apid );
     lprintf( 3, "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", length, pid );
 }
 (void) close(fd);
 return(pid);
}

variable_types:
name
char *

variable_types: pid int

variable_types:
apid
char [20]

variable_types: length int


decompiled_code:
char *__fastcall get_lock_name(char *s, char *a2)
{
char *v2; // r12

v2 = a2;
if ( strchr(a2, 47) )
v2 = strrchr(a2, 47) + 1;
sprintf(s, "/var/lock/LCK..%s", v2);
return s;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, char *a2)
{
char *v2; // r12

v2 = a2;
if ( strchr(a2, 47) )
v2 = strrchr(a2, 47) + 1;
sprintf(s, "/var/lock/LCK..%s", v2);
return s;
}

original_code:
static char * get_lock_name (char * lock_name,char * device)
{
    if ( strchr( device, '/' ) != ((void *)0) )
        device = strrchr( device, '/' ) +1;
    sprintf( lock_name, "/var/lock/LCK..%s", device);
    return lock_name;
}

canonical_original_code:
static char *get_lock_name(char *lock_name, char *device)
{
    if ( strchr( device, '/' ) != ((void *)0) )
        device = strrchr( device, '/' ) +1;
    sprintf( lock_name, "/var/lock/LCK..%s", device);
    return lock_name;
}

variable_types:
device
char *


decompiled_code:
__int64 do_makelock()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er12
__int64 result; // rax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

we_have_lock = 0;
lprintf(5LL, "do_makelock: lock='%s'", lock);
sprintf(v4, "/var/lock/LCK..%s", "TM.XXXXXX");
v0 = mkstemp(v4);
if ( v0 == -1 )
{
lprintf(1LL, "cannot create tempfile (%s)", v4);
}
else
{
chmod(v4, 0x1A4u);
if ( (unsigned int)lock_write_pid(v0) != -1 )
{
while ( 1 )
{
while ( 1 )
{
if ( link(v4, lock) != -1 )
goto LABEL_18;
v1 = _errno_location();
if ( *v1 != 17 )
{
lprintf(1LL, "lock not made: link(temp,lock) failed");
if ( *v1 != 17 )
goto LABEL_15;
}
v2 = readlock(lock);
if ( v2 != -1 )
break;
if ( *v1 != 2 )
{
lprintf(5LL, "cannot read lockfile");
unlink(v4);
return v2;
}
}
if ( getpid() == v2 )
{
lprintf(3LL, "we *have* the line!");
LABEL_18:
lprintf(5LL, "lock made");
unlink(v4);
result = 0LL;
we_have_lock = 1;
return result;
}
if ( kill(v2, 0) != -1 || *v1 != 3 )
break;
lprintf(5LL, "stale lockfile, created by process %d, ignoring", v2);
if ( unlink(lock) < 0 && ((*v1 - 2) & 0xFFFFFFFD) != 0 )
{
lprintf(1LL, "unlink() failed, giving up");
goto LABEL_15;
}
}
lprintf(4LL, "lock not made: lock file exists (pid=%d)", v2);
}
LABEL_15:
v0 = -1;
unlink(v4);
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er12
__int64 result; // rax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

we_have_lock = 0;
lprintf(5LL, "do_makelock: lock='%s'", lock);
sprintf(v4, "/var/lock/LCK..%s", "TM.XXXXXX");
v0 = mkstemp(v4);
if ( v0 == -1 )
{
lprintf(1LL, "cannot create tempfile (%s)", v4);
}
else
{
chmod(v4, 0x1A4u);
if ( (unsigned int)func0(v0) != -1 )
{
while ( 1 )
{
while ( 1 )
{
if ( link(v4, lock) != -1 )
goto LABEL_18;
v1 = _errno_location();
if ( *v1 != 17 )
{
lprintf(1LL, "lock not made: link(temp,lock) failed");
if ( *v1 != 17 )
goto LABEL_15;
}
v2 = func1(lock);
if ( v2 != -1 )
break;
if ( *v1 != 2 )
{
lprintf(5LL, "cannot read lockfile");
unlink(v4);
return v2;
}
}
if ( getpid() == v2 )
{
lprintf(3LL, "we *have* the line!");
LABEL_18:
lprintf(5LL, "lock made");
unlink(v4);
result = 0LL;
we_have_lock = 1;
return result;
}
if ( kill(v2, 0) != -1 || *v1 != 3 )
break;
lprintf(5LL, "stale lockfile, created by process %d, ignoring", v2);
if ( unlink(lock) < 0 && ((*v1 - 2) & 0xFFFFFFFD) != 0 )
{
lprintf(1LL, "unlink() failed, giving up");
goto LABEL_15;
}
}
lprintf(4LL, "lock not made: lock file exists (pid=%d)", v2);
}
LABEL_15:
v0 = -1;
unlink(v4);
}
return v0;
}

original_code:
int do_makelock (void)
{
 int fd, pid;
 char *temp, buf[1024 +1];
 we_have_lock = (1==0);
 lprintf( 5, "do_makelock: lock='%s'", lock );
 temp=buf;
 sprintf(buf, "/var/lock/LCK..%s", "TM.XXXXXX");
 if ((fd = mkstemp(temp)) == -1 ) {
  lprintf(1, "cannot create tempfile (%s)", temp);
  return(-1);
 }
 chmod( temp, 0644 );
 if ( lock_write_pid( fd ) == -1)
                         { unlink(temp); return -1; }
 while (link(temp, lock) == -1)
 {
         if ((*__errno_location ()) != 17 )
  {
      lprintf(1, "lock not made: link(temp,lock) failed" );
  }
  if ((*__errno_location ()) == 17)
  {
      if ((pid = readlock(lock)) == -1)
      {
   if ( (*__errno_location ()) == 2 )
       continue;
   else
   {
       lprintf( 5, "cannot read lockfile" );
       unlink(temp);
       return -1;
   }
      }
      if (pid == getpid())
      {
   lprintf( 3, "we *have* the line!" );
   break;
      }
      if ((kill(pid, 0) == -1) && (*__errno_location ()) == 3)
      {
   lprintf( 5, "stale lockfile, created by process %d, ignoring", pid );
   if ( unlink(lock) < 0 &&
            (*__errno_location ()) != 4 && (*__errno_location ()) != 2 )
   {
       lprintf( 1, "unlink() failed, giving up" );
       unlink(temp);
       return -1;
   }
   continue;
      }
      lprintf(4, "lock not made: lock file exists (pid=%d)", pid);
  }
  (void) unlink(temp);
  return(-1);
 }
 lprintf(5, "lock made");
 (void) unlink(temp);
 we_have_lock = (1==1);
 return(0);
}

canonical_original_code:
int do_makelock()
{
 int fd; int pid;
 char *temp; char buf[-1];
 we_have_lock = (1==0);
 lprintf( 5, "do_makelock: lock='%s'", lock );
 temp=buf;
 sprintf(buf, "/var/lock/LCK..%s", "TM.XXXXXX");
 if ((fd = mkstemp(temp)) == -1 ) {
  lprintf(1, "cannot create tempfile (%s)", temp);
  return(-1);
 }
 chmod( temp, 0644 );
 if ( lock_write_pid( fd ) == -1)
                         { unlink(temp); return -1; }
 while (link(temp, lock) == -1)
 {
         if ((*__errno_location ()) != 17 )
  {
      lprintf(1, "lock not made: link(temp,lock) failed" );
  }
  if ((*__errno_location ()) == 17)
  {
      if ((pid = readlock(lock)) == -1)
      {
   if ( (*__errno_location ()) == 2 )
       continue;
   else
   {
       lprintf( 5, "cannot read lockfile" );
       unlink(temp);
       return -1;
   }
      }
      if (pid == getpid())
      {
   lprintf( 3, "we *have* the line!" );
   break;
      }
      if ((kill(pid, 0) == -1) && (*__errno_location ()) == 3)
      {
   lprintf( 5, "stale lockfile, created by process %d, ignoring", pid );
   if ( unlink(lock) < 0 &&
            (*__errno_location ()) != 4 && (*__errno_location ()) != 2 )
   {
       lprintf( 1, "unlink() failed, giving up" );
       unlink(temp);
       return -1;
   }
   continue;
      }
      lprintf(4, "lock not made: lock file exists (pid=%d)", pid);
  }
  (void) unlink(temp);
  return(-1);
 }
 lprintf(5, "lock made");
 (void) unlink(temp);
 we_have_lock = (1==1);
 return(0);
}

variable_types:
temp
char *

variable_types:
buf
char [-1]


makelock

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

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

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

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


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

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

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

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

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

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

variable_types: retcode int


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

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

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

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

variable_types:
file
char *


checklock

decompiled_code:
__int64 __fastcall checklock(char *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-4A8h] BYREF
char file[1048]; // [rsp+90h] [rbp-418h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-4A8h] BYREF
char file[1048]; // [rsp+90h] [rbp-418h] BYREF

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

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

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

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

variable_types:
name
char [-1]

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


rmlocks

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

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

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

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

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

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


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

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

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

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

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

variable_types: device int


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

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

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

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

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

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


decompiled_code:
__int64 Multitech_2834_init()
{
__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 Multitech 2834 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8A0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v5, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v5, &unk_8A0) != 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, &unk_8A0) != 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, &unk_8A0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__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 Multitech 2834 voice modem");
if ( (unsigned int)voice_command("AT+VIT=10", &unk_8A0) != 4096 )
lprintf(3LL, "voice init failed, continuing");
sprintf(v5, "AT+VSD=%d,%d", 128LL, *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v5, &unk_8A0) != 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, &unk_8A0) != 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, &unk_8A0) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
voice_modem_state = 1;
return 0LL;
}

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

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


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

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

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

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

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

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

variable_types: result int


decompiled_code:
void __fastcall Multitech_2834_fix_modem(int a1)
{
int v1; // eax
_BYTE v2[264]; // [rsp-108h] [rbp-108h] BYREF

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

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // eax
_BYTE v2[264]; // [rsp-108h] [rbp-108h] BYREF

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

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

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


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

if ( !(unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_978) )
{
while ( 1 )
{
v0 = voice_read(mode_save);
if ( v0 )
break;
if ( mode_save[0] )
{
if ( *(_QWORD *)mode_save == 0x3D5353414C43462BLL )
{
v2 = strlen(mode_save);
memmove(mode_save, &unk_898, v2 - 7);
}
if ( (voice_command(&unk_978, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) != 0 )
{
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) != 0 )
{
Multitech_2834_fix_modem(0);
return v0;
}
}
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

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

if ( !(unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_978) )
{
while ( 1 )
{
v0 = voice_read(mode_save);
if ( v0 )
break;
if ( mode_save[0] )
{
if ( *(_QWORD *)mode_save == 0x3D5353414C43462BLL )
{
v2 = strlen(mode_save);
memmove(mode_save, &unk_898, v2 - 7);
}
if ( (voice_command(&unk_978, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) != 0 )
{
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) != 0 )
{
func4(0);
return v0;
}
}
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

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

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


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
mode
char *


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall Multitech_5634ZPX_set_device(int a1)
{
reset_watchdog();
if ( a1 == 3 )
{
voice_command("AT+VLS=11", "OK");
return 0LL;
}
if ( a1 <= 3 )
{
if ( (unsigned int)(a1 - 1) <= 1 )
{
voice_command("AT+VLS=0", "OK");
return 0LL;
}
}
else
{
if ( a1 == 6 )
{
voice_command("AT+VLS=4", "OK");
return 0LL;
}
if ( a1 == 7 )
{
voice_command("AT+VLS=2", "OK");
return 0LL;
}
}
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
reset_watchdog();
if ( a1 == 3 )
{
voice_command("AT+VLS=11", "OK");
return 0LL;
}
if ( a1 <= 3 )
{
if ( (unsigned int)(a1 - 1) <= 1 )
{
voice_command("AT+VLS=0", "OK");
return 0LL;
}
}
else
{
if ( a1 == 6 )
{
voice_command("AT+VLS=4", "OK");
return 0LL;
}
if ( a1 == 7 )
{
voice_command("AT+VLS=2", "OK");
return 0LL;
}
}
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
return 0xFFFFFFFFLL;
}

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


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

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


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

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

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

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

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

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


decompiled_code:
void __fastcall Multitech_5634ZPX_fix_modem(int a1)
{
int v1; // eax
_BYTE v2[264]; // [rsp-108h] [rbp-108h] BYREF

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

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // eax
_BYTE v2[264]; // [rsp-108h] [rbp-108h] BYREF

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

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

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


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

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

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

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

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

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


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

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

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

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


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

if ( !(unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9B6) )
{
while ( 1 )
{
v0 = voice_read(mode_save);
if ( v0 )
break;
if ( mode_save[0] )
{
if ( *(_QWORD *)mode_save == 0x3D5353414C43462BLL )
{
v2 = strlen(mode_save);
memmove(mode_save, &unk_898, v2 - 7);
}
if ( (voice_command(&unk_9B6, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) != 0 )
{
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) != 0 )
{
Multitech_5634ZPX_fix_modem(0);
return v0;
}
}
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

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

if ( !(unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_9B6) )
{
while ( 1 )
{
v0 = voice_read(mode_save);
if ( v0 )
break;
if ( mode_save[0] )
{
if ( *(_QWORD *)mode_save == 0x3D5353414C43462BLL )
{
v2 = strlen(mode_save);
memmove(mode_save, &unk_898, v2 - 7);
}
if ( (voice_command(&unk_9B6, *(_QWORD *)(voice_modem + 200LL)) & 0x1000) != 0 )
{
sprintf(v3, "%s%s", *(const char **)(voice_modem + 176LL), *(const char **)(voice_modem + 208LL));
if ( (voice_command(v3, *(_QWORD *)(voice_modem + 184LL)) & 0x1000) != 0 )
{
func4(0);
return v0;
}
}
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

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

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


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

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

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

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

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

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

variable_types: loop int

variable_types:
p
char *


cndlookup

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

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

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

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

variable_types: match int