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

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

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

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

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

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

variable_types:
name
char *

variable_types:
tty
char *

variable_types:
program
char *

variable_types: rc int


cndfind

repo: Distrotech/mgetty

decompiled_code:
int __fastcall cndfind(char *s)
{
char *v1; // rbp
__int64 v2; // rbx
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // r12
const unsigned __int16 *v5; // rax
char *i; // rax
const unsigned __int16 *v7; // rbx
__int64 v8; // rax
const char *v9; // r13
_BYTE *v10; // r14
char **v11; // r15
size_t v12; // r12
void **v13; // r13
void **v14; // r14
size_t v15; // rax
char *v16; // rax
char *v17; // rdx
__int64 j; // rax
char *v19; // rax
char *v20; // r8
__int64 v21; // rdx
size_t v22; // rbx
size_t v23; // r14
size_t v24; // rax
char *v25; // rax
char *sa; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
int __fastcall func0(char *s)
{
char *v1; // rbp
__int64 v2; // rbx
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // r12
const unsigned __int16 *v5; // rax
char *i; // rax
const unsigned __int16 *v7; // rbx
__int64 v8; // rax
const char *v9; // r13
_BYTE *v10; // r14
char **v11; // r15
size_t v12; // r12
void **v13; // r13
void **v14; // r14
size_t v15; // rax
char *v16; // rax
char *v17; // rdx
__int64 j; // rax
char *v19; // rax
char *v20; // r8
__int64 v21; // rdx
size_t v22; // rbx
size_t v23; // r14
size_t v24; // rax
char *v25; // rax
char *sa; // [rsp+8h] [rbp-40h]

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

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

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

variable_types:
str
char *

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

variable_types: len int

variable_types:
p
char *

return_type: void


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

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

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

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

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

variable_types: sig int


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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

variable_types: pid int

variable_types: status int


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

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

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


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

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

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

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

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

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

return_type: int


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

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

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

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

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

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


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

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

variable_types: device int


decompiled_code:
__int64 __fastcall Multitech_5634_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rcx
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_5634_set_compression(p_int *compression, p_int *speed,
 int *bits)
     {
     char buffer[(256)];
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 8000;
     if (*speed != 8000)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           (int)*speed);
          return((-1));
          }
     switch (*compression)
          {
          case 4:
               *bits = 4;
               sprintf(buffer, "AT+VSM=2,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          case 132:
               *bits = 4;
               sprintf(buffer, "AT+VSM=132,%d", (int)*speed);
               if (voice_command(buffer, "OK") != (0x1000))
                    return((-1));
               break;
          default:
               lprintf(3, "%s: Illegal voice compression method (%d)",
                voice_modem->name, (int)*compression);
               return((-1));
          }
     return((0));
     }

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


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

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


decompiled_code:
__int64 Multitech_5634_answer_phone()
{
int v0; // eax
unsigned int v1; // 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_5634_answer_phone(void)
     {
     int result;
     reset_watchdog();
     if (((result = voice_command("AT+VLS=1", "OK|CONNECT")) & (0x1000)) !=
      (0x1000))
          return((0x2003));
     if (result == (0x1001))
          return((0x2001));
     return((0x200a));
     }

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

variable_types: result int


decompiled_code:
void __fastcall Multitech_5634_fix_modem(int a1)
{
int v1; // 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_5634_fix_modem(int expect_error)
{
 char buffer[(256)];
 int result = (0x4000);
        if (!cvd.enable_command_echo.d.i) {
           return;
        }
 voice_write("AT");
 do {
  if (voice_read(buffer) != (0)) {
   voice_flush(1);
   break;
  }
  result = voice_analyze(buffer, "AT", (0==0));
  if (result == (0x4000)) {
   voice_flush(1);
   break;
  }
  if (result == (0x2003)) {
   lprintf(3, "%s: Modem returned ERROR",
           program_name);
   voice_flush(1);
   break;
  }
 } while (result != (0x1000));
 if (result == (0x1000) && expect_error)
         lprintf(3, "%s: Modem answered correctly", program_name);
        if (result != (0x1000) && !expect_error)
         lprintf(3, "%s: Modem answered incorrectly", program_name);
}

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


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

if ( !(unsigned int)voice_command(*(_QWORD *)(voice_modem + 192LL), &unk_995) )
{
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_995, *(_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_5634_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_995) )
{
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_995, *(_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_5634_voice_mode_on(void)
{
 char buffer[(256)];
 if (voice_command(voice_modem->ask_mode_cmnd, "") != (0))
  return (-1);
 do {
  if (voice_read(mode_save) != (0))
   return (-1);
 } while (strlen(mode_save) == 0);
 if (strncmp(mode_save, "+FCLASS=", 8) == 0)
         memmove(mode_save, mode_save + 8, strlen(mode_save) - 8 + 1);
 if ((voice_command("", voice_modem->ask_mode_answr) & (0x1000)) != (0x1000))
  return (-1);
 sprintf(buffer, "%s%s", voice_modem->switch_mode_cmnd,
  voice_modem->voice_mode_id);
 if ((voice_command(buffer, voice_modem->switch_mode_answr) & (0x1000)) !=
     (0x1000))
  return (-1);
 Multitech_5634_fix_modem(0);
 return (0);
}

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


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
mode
char *


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

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

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

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

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

variable_types: timeout int


decompiled_code:
__int64 check_system()
{
return 0xFFFFFFFFLL;
}

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

original_code:
void check_system (void)
     {
     volatile signed int a = -1024;
     volatile signed int b;
     volatile signed int c = 1024;
     volatile signed int d = 10;
     b = a / c;
     c = a >> d;
     ((void) sizeof ((b == c) ? 1 : 0), __extension__ ({ if (b == c) ; else __assert_fail ("b == c", "check_system.c", 28, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int16) == 2) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int16) == 2) ; else __assert_fail ("sizeof(vgetty_s_int16) == 2", "check_system.c", 34, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int16) == 2) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int16) == 2) ; else __assert_fail ("sizeof(vgetty_u_int16) == 2", "check_system.c", 35, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int32) == 4) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int32) == 4) ; else __assert_fail ("sizeof(vgetty_s_int32) == 4", "check_system.c", 36, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int32) == 4) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int32) == 4) ; else __assert_fail ("sizeof(vgetty_u_int32) == 4", "check_system.c", 37, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int64) == 8) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int64) == 8) ; else __assert_fail ("sizeof(vgetty_s_int64) == 8", "check_system.c", 38, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int64) == 8) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int64) == 8) ; else __assert_fail ("sizeof(vgetty_u_int64) == 8", "check_system.c", 39, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(int) >= 4) ? 1 : 0), __extension__ ({ if (sizeof(int) >= 4) ; else __assert_fail ("sizeof(int) >= 4", "check_system.c", 45, __extension__ __PRETTY_FUNCTION__); }));
     }

canonical_original_code:
void check_system()
     {
     int a = -1024;
     int b;
     int c = 1024;
     int d = 10;
     b = a / c;
     c = a >> d;
     ((void) sizeof ((b == c) ? 1 : 0), __extension__ ({ if (b == c) ; else __assert_fail ("b == c", "check_system.c", 28, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int16) == 2) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int16) == 2) ; else __assert_fail ("sizeof(vgetty_s_int16) == 2", "check_system.c", 34, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int16) == 2) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int16) == 2) ; else __assert_fail ("sizeof(vgetty_u_int16) == 2", "check_system.c", 35, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int32) == 4) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int32) == 4) ; else __assert_fail ("sizeof(vgetty_s_int32) == 4", "check_system.c", 36, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int32) == 4) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int32) == 4) ; else __assert_fail ("sizeof(vgetty_u_int32) == 4", "check_system.c", 37, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_s_int64) == 8) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_s_int64) == 8) ; else __assert_fail ("sizeof(vgetty_s_int64) == 8", "check_system.c", 38, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(vgetty_u_int64) == 8) ? 1 : 0), __extension__ ({ if (sizeof(vgetty_u_int64) == 8) ; else __assert_fail ("sizeof(vgetty_u_int64) == 8", "check_system.c", 39, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((sizeof(int) >= 4) ? 1 : 0), __extension__ ({ if (sizeof(int) >= 4) ; else __assert_fail ("sizeof(int) >= 4", "check_system.c", 45, __extension__ __PRETTY_FUNCTION__); }));
     }

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int


decompiled_code:
void __fastcall log_set_llevel(int a1)
{
log_level = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
log_level = a1;
}

original_code:
void log_set_llevel (int level)
{
    log_level = level;
}

canonical_original_code:
void log_set_llevel(int level)
{
    log_level = level;
}

variable_types: level int


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

if ( log_fp )
result = fclose(log_fp);
log_fp = 0LL;
return result;
}

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

if ( log_fp )
result = fclose(log_fp);
log_fp = 0LL;
return result;
}

original_code:
void log_close (void)
{
    if ( log_fp != ((void *)0) ) fclose( log_fp );
    log_fp = ((void *)0);
}

canonical_original_code:
void log_close()
{
    if ( log_fp != ((void *)0) ) fclose( log_fp );
    log_fp = ((void *)0);
}


decompiled_code:
void __fastcall log_init_paths(const char *a1, const char *a2, const char *a3)
{
char *v4; // rbx
char *v5; // rax

if ( a1 )
{
v4 = (char *)a1;
v5 = strrchr(a1, 47);
if ( v5 )
v4 = v5 + 1;
log_program = v4;
}
if ( !a2 )
goto LABEL_10;
if ( log_fp )
{
if ( strcmp(a2, &log_path) )
{
lprintf(4u, "logging continues in file %s", a2);
log_close();
}
}
strncpy(&log_path, a2, 0x3FFuLL);
byte_C7F = 0;
if ( strlen(a2) <= 0x3FF )
{
LABEL_10:
if ( !a3 )
return;
goto LABEL_11;
}
lprintf(0, "internal error: log file path too long!");
if ( a3 )
LABEL_11:
sprintf(log_infix, "%.*s ", 8, a3);
}

canonical_decompiled_code:
void __fastcall func5(const char *a1, const char *a2, const char *a3)
{
char *v4; // rbx
char *v5; // rax

if ( a1 )
{
v4 = (char *)a1;
v5 = strrchr(a1, 47);
if ( v5 )
v4 = v5 + 1;
log_program = v4;
}
if ( !a2 )
goto LABEL_10;
if ( log_fp )
{
if ( strcmp(a2, &log_path) )
{
func4(4u, "logging continues in file %s", a2);
func1();
}
}
strncpy(&log_path, a2, 0x3FFuLL);
byte_C7F = 0;
if ( strlen(a2) <= 0x3FF )
{
LABEL_10:
if ( !a3 )
return;
goto LABEL_11;
}
func4(0, "internal error: log file path too long!");
if ( a3 )
LABEL_11:
sprintf(log_infix, "%.*s ", 8, a3);
}

original_code:
void log_init_paths (char * l_program,char * l_path,char * l_infix)
{
    if ( l_program != ((void *)0) )
    {
 char * p = strrchr( l_program, '/' );
 log_program = ( p == ((void *)0) ) ? l_program : p+1;
    }
    if ( l_path != ((void *)0) )
    {
 if ( log_fp != ((void *)0) &&
      strcmp( l_path, log_path ) != 0 )
 {
     lprintf( 4, "logging continues in file %s", l_path );
     log_close();
 }
 strncpy( log_path, l_path, sizeof(log_path)-1 );
 log_path[sizeof(log_path)-1] = 0;
 if ( strlen(l_path) >= sizeof(log_path) )
 {
     lprintf( 0, "internal error: log file path too long!" );
 }
    }
    if ( l_infix != ((void *)0) )
    {
 sprintf( log_infix, "%.*s ", (int) sizeof(log_infix)-2, l_infix );
    }
}

canonical_original_code:
void log_init_paths(char *l_program, char *l_path, char *l_infix)
{
    if ( l_program != ((void *)0) )
    {
 char *p = strrchr( l_program, '/' );
 log_program = ( p == ((void *)0) ) ? l_program : p+1;
    }
    if ( l_path != ((void *)0) )
    {
 if ( log_fp != ((void *)0) &&
      strcmp( l_path, log_path ) != 0 )
 {
     lprintf( 4, "logging continues in file %s", l_path );
     log_close();
 }
 strncpy( log_path, l_path, sizeof(log_path)-1 );
 log_path[sizeof(log_path)-1] = 0;
 if ( strlen(l_path) >= sizeof(log_path) )
 {
     lprintf( 0, "internal error: log file path too long!" );
 }
    }
    if ( l_infix != ((void *)0) )
    {
 sprintf( log_infix, "%.*s ", (int) sizeof(log_infix)-2, l_infix );
    }
}

variable_types:
p
char *


lputc

decompiled_code:
__int64 __fastcall lputc(int a1, unsigned __int8 a2)
{
FILE *v2; // rbp

v2 = log_fp;
if ( log_fp && log_level >= a1 )
{
if ( ((*_ctype_b_loc())[(char)a2] & 0x4000) != 0 )
fputc((char)a2, v2);
else
fprintf(v2, "[%02x]", a2);
fflush(log_fp);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned __int8 a2)
{
FILE *v2; // rbp

v2 = log_fp;
if ( log_fp && log_level >= a1 )
{
if ( ((*_ctype_b_loc())[(char)a2] & 0x4000) != 0 )
fputc((char)a2, v2);
else
fprintf(v2, "[%02x]", a2);
fflush(log_fp);
}
return 0LL;
}

original_code:
int lputc (int level,char ch)
{
    if ( log_fp != ((void *)0) && level <= log_level )
    {
 if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) ) fputc( ch, log_fp );
        else fprintf( log_fp, "[%02x]", (unsigned char) ch );
 fflush( log_fp );
    }
    return 0;
}

canonical_original_code:
int lputc(int level, char ch)
{
    if ( log_fp != ((void *)0) && level <= log_level )
    {
 if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) ) fputc( ch, log_fp );
        else fprintf( log_fp, "[%02x]", (unsigned char) ch );
 fflush( log_fp );
    }
    return 0;
}

variable_types: ch char


lputs

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

v3 = a2;
v4 = 0;
if ( log_fp && log_level >= a1 )
{
if ( !a2 )
v3 = "(NULL)";
v4 = fputs(v3, log_fp);
fflush(log_fp);
}
return v4;
}

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

v3 = a2;
v4 = 0;
if ( log_fp && log_level >= a1 )
{
if ( !a2 )
v3 = "(NULL)";
v4 = fputs(v3, log_fp);
fflush(log_fp);
}
return v4;
}

original_code:
int lputs (int level,char * s)
{
int retcode = 0;
    if ( log_fp != ((void *)0) && level <= log_level )
    {
 retcode = fputs( s!=((void *)0)? s : "(NULL)", log_fp );
 fflush( log_fp );
    }
    return retcode;
}

canonical_original_code:
int lputs(int level, char *s)
{
int retcode = 0;
    if ( log_fp != ((void *)0) && level <= log_level )
    {
 retcode = fputs( s!=((void *)0)? s : "(NULL)", log_fp );
 fflush( log_fp );
    }
    return retcode;
}

variable_types:
s
char *

variable_types: retcode int


decompiled_code:
void chat_timeout()
{
chat_has_timeout = 1;
}

canonical_decompiled_code:
void func0()
{
chat_has_timeout = 1;
}

original_code:
static RETSIGTYPE chat_timeout()
{
    chat_has_timeout = (1==1);
}

canonical_original_code:
static void chat_timeout()
{
    chat_has_timeout = (1==1);
}


safedup

decompiled_code:
char *__fastcall safedup(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
result = "<null>";
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
result = "<null>";
return result;
}

original_code:
static char * safedup( char * in )
{
    char * p = strdup( in );
    return ( p == ((void *)0) ) ? "<null>" : p;
}

canonical_original_code:
static char *safedup(char *in)
{
    char *p = strdup( in );
    return ( p == ((void *)0) ) ? "<null>" : p;
}

variable_types:
in
char *

return_type: char *


decompiled_code:
__int64 __fastcall ring_handle_ZoomMX(__int64 a1)
{
const unsigned __int16 *v1; // rcx
_BYTE *i; // rax

lprintf(4LL, "Zoom MX/S: '%s'", (const char *)a1);
v1 = *_ctype_b_loc();
for ( i = (_BYTE *)(a1 + 8); (v1[(char)*i] & 0x800) != 0; ++i )
;
*i = 0;
CallerId = safedup((const char *)(a1 + 8));
return (unsigned int)(*(char *)(a1 + 6) - 48);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
const unsigned __int16 *v1; // rcx
_BYTE *i; // rax

lprintf(4LL, "Zoom MX/S: '%s'", (const char *)a1);
v1 = *_ctype_b_loc();
for ( i = (_BYTE *)(a1 + 8); (v1[(char)*i] & 0x800) != 0; ++i )
;
*i = 0;
CallerId = func1((const char *)(a1 + 8));
return (unsigned int)(*(char *)(a1 + 6) - 48);
}

original_code:
static int ring_handle_ZoomMX (char * string)
{
char * p;
    lprintf( 4, "Zoom MX/S: '%s'", string );
    p=&string[8];
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) ) p++;
    *p = '\0';
    CallerId = safedup( &string[8] );
    return ( string[6]-'0');
}

canonical_original_code:
static int ring_handle_ZoomMX(char *string)
{
char *p;
    lprintf( 4, "Zoom MX/S: '%s'", string );
    p=&string[8];
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) ) p++;
    *p = '\0';
    CallerId = safedup( &string[8] );
    return ( string[6]-'0');
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall find_msn(char *s, const char **a2)
{
int v2; // er12
char *v3; // rax
const char *v4; // rdx
__int64 v5; // rbx
const char *v6; // r15
int v7; // eax

lprintf(5LL, "MSN: '%s'", s);
CalledNr = safedup(s);
if ( !a2 )
return 0LL;
v2 = strlen(s);
v3 = strchr(s, 47);
if ( v3 )
v2 = (_DWORD)v3 - (_DWORD)s;
v4 = *a2;
if ( !*a2 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
lprintf(6LL, "match: '%s'", v4);
v6 = a2[v5];
v7 = strlen(v6);
if ( v2 >= v7 && !strncmp(v6, &s[v2 - v7], v7) )
break;
v4 = a2[++v5];
if ( !v4 )
return 0LL;
}
return (unsigned int)(v5 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, const char **a2)
{
int v2; // er12
char *v3; // rax
const char *v4; // rdx
__int64 v5; // rbx
const char *v6; // r15
int v7; // eax

lprintf(5LL, "MSN: '%s'", s);
CalledNr = func1(s);
if ( !a2 )
return 0LL;
v2 = strlen(s);
v3 = strchr(s, 47);
if ( v3 )
v2 = (_DWORD)v3 - (_DWORD)s;
v4 = *a2;
if ( !*a2 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
lprintf(6LL, "match: '%s'", v4);
v6 = a2[v5];
v7 = strlen(v6);
if ( v2 >= v7 && !strncmp(v6, &s[v2 - v7], v7) )
break;
v4 = a2[++v5];
if ( !v4 )
return 0LL;
}
return (unsigned int)(v5 + 1);
}

original_code:
static int find_msn (char * string,char ** msn_list)
{
int i, len, len2;
char * p;
    lprintf( 5, "MSN: '%s'", string );
    CalledNr = safedup(string);
    if ( msn_list == ((void *)0) ) return 0;
    len=strlen(string);
    p = strchr( string, '/' );
    if ( p != ((void *)0) ) { len = (p - string); }
    for( i=0; msn_list[i] != ((void *)0); i++ )
    {
 lprintf( 6, "match: '%s'", msn_list[i] );
 len2=strlen( msn_list[i] );
 if ( len2 <= len &&
      strncmp( msn_list[i], &string[len-len2], len2 ) == 0 )
  { return i+1; }
    }
    return 0;
}

canonical_original_code:
static int find_msn(char *string, char **msn_list)
{
int i; int len; int len2;
char *p;
    lprintf( 5, "MSN: '%s'", string );
    CalledNr = safedup(string);
    if ( msn_list == ((void *)0) ) return 0;
    len=strlen(string);
    p = strchr( string, '/' );
    if ( p != ((void *)0) ) { len = (p - string); }
    for( i=0; msn_list[i] != ((void *)0); i++ )
    {
 lprintf( 6, "match: '%s'", msn_list[i] );
 len2=strlen( msn_list[i] );
 if ( len2 <= len &&
      strncmp( msn_list[i], &string[len-len2], len2 ) == 0 )
  { return i+1; }
    }
    return 0;
}

variable_types: i int

variable_types: len int


original_code:
static int ring_handle_ZyXEL (char * string,char ** msn_list)
{
char * p, ch;
    lprintf( 4, "ZyXEL: '%s'", string );
    if ( strncmp( string, "FM:", 3 ) == 0 )
    {
 string+=3;
 while( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISspace) ) { string++; }
 p=string;
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) ) p++;
 ch = *p; *p = '\0';
 CallerId = safedup(string);
 *p = ch;
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace) ) p++;
 if ( *p == '/' )
 {
     p++;
     while ( *p != '\0' && *p != '/' ) { p++; }
     if ( *p != '\0' ) p++;
 }
 string = p;
    }
    if ( strncmp( string, "TO:", 3 ) == 0 )
    {
 string += 3;
 while( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISspace) ) { string++; }
 return find_msn( string, msn_list );
    }
    return 0;
}

canonical_original_code:
static int ring_handle_ZyXEL(char *string, char **msn_list)
{
char *p; char ch;
    lprintf( 4, "ZyXEL: '%s'", string );
    if ( strncmp( string, "FM:", 3 ) == 0 )
    {
 string+=3;
 while( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISspace) ) { string++; }
 p=string;
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) ) p++;
 ch = *p; *p = '\0';
 CallerId = safedup(string);
 *p = ch;
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace) ) p++;
 if ( *p == '/' )
 {
     p++;
     while ( *p != '\0' && *p != '/' ) { p++; }
     if ( *p != '\0' ) p++;
 }
 string = p;
    }
    if ( strncmp( string, "TO:", 3 ) == 0 )
    {
 string += 3;
 while( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISspace) ) { string++; }
 return find_msn( string, msn_list );
    }
    return 0;
}


decompiled_code:
__int64 __fastcall ring_handle_ELSA(const char *a1, const char **a2)
{
const char *v2; // rbp
char v3; // r14
const unsigned __int16 **v4; // rax
_QWORD *v5; // r13
__int64 v6; // rdx
const char *v7; // rbx
char *v8; // rdi
__int64 i; // rax

v2 = a1;
lprintf(4LL, "ELSA: '%s'", a1);
v3 = *a1;
v4 = _ctype_b_loc();
v5 = v4;
if ( v3 )
{
v6 = (__int64)*v4;
v4 = (const unsigned __int16 **)v3;
while ( (*(_BYTE *)(v6 + 2LL * (_QWORD)v4 + 1) & 8) == 0 )
{
v4 = (const unsigned __int16 **)*++v2;
if ( !(_BYTE)v4 )
goto LABEL_6;
}
LOBYTE(v4) = *v2;
}
else
{
v6 = (__int64)*v4;
LOBYTE(v4) = 0;
}
LABEL_6:
v7 = v2;
while ( (*(_BYTE *)(v6 + 2LL * (char)v4 + 1) & 8) != 0 )
LOBYTE(v4) = *++v7;
if ( (_BYTE)v4 )
{
*v7 = 0;
v8 = (char *)(v7 + 1);
CallerId = safedup(v2);
for ( i = v7[1]; (_BYTE)i; i = *++v8 )
{
if ( (*(_BYTE *)(*v5 + 2 * i + 1) & 8) != 0 )
break;
}
}
else
{
v8 = (char *)v2;
if ( v3 != 47 )
{
CallerId = safedup(v2);
return 0LL;
}
}
return find_msn(v8, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char **a2)
{
const char *v2; // rbp
char v3; // r14
const unsigned __int16 **v4; // rax
_QWORD *v5; // r13
__int64 v6; // rdx
const char *v7; // rbx
char *v8; // rdi
__int64 i; // rax

v2 = a1;
lprintf(4LL, "ELSA: '%s'", a1);
v3 = *a1;
v4 = _ctype_b_loc();
v5 = v4;
if ( v3 )
{
v6 = (__int64)*v4;
v4 = (const unsigned __int16 **)v3;
while ( (*(_BYTE *)(v6 + 2LL * (_QWORD)v4 + 1) & 8) == 0 )
{
v4 = (const unsigned __int16 **)*++v2;
if ( !(_BYTE)v4 )
goto LABEL_6;
}
LOBYTE(v4) = *v2;
}
else
{
v6 = (__int64)*v4;
LOBYTE(v4) = 0;
}
LABEL_6:
v7 = v2;
while ( (*(_BYTE *)(v6 + 2LL * (char)v4 + 1) & 8) != 0 )
LOBYTE(v4) = *++v7;
if ( (_BYTE)v4 )
{
*v7 = 0;
v8 = (char *)(v7 + 1);
CallerId = func1(v2);
for ( i = v7[1]; (_BYTE)i; i = *++v8 )
{
if ( (*(_BYTE *)(*v5 + 2 * i + 1) & 8) != 0 )
break;
}
}
else
{
v8 = (char *)v2;
if ( v3 != 47 )
{
CallerId = func1(v2);
return 0LL;
}
}
return func3(v8, a2);
}

original_code:
static int ring_handle_ELSA (char * string,char ** msn_list)
{
char * p;
char ch;
    lprintf( 4, "ELSA: '%s'", string );
    ch = *string;
    while( *string != '\0' && !((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISdigit) ) string++;
    p=string;
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) ) p++;
    if ( *p == '\0' )
    {
 if ( ch == '/' )
     return find_msn( string, msn_list );
 CallerId = safedup( string );
 return 0;
    }
    else
    {
 *p = '\0';
 CallerId = safedup( string );
 p++;
 while( *p != '\0' && !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) ) p++;
 return find_msn( p, msn_list );
    }
}

canonical_original_code:
static int ring_handle_ELSA(char *string, char **msn_list)
{
char *p;
char ch;
    lprintf( 4, "ELSA: '%s'", string );
    ch = *string;
    while( *string != '\0' && !((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISdigit) ) string++;
    p=string;
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) ) p++;
    if ( *p == '\0' )
    {
 if ( ch == '/' )
     return find_msn( string, msn_list );
 CallerId = safedup( string );
 return 0;
    }
    else
    {
 *p = '\0';
 CallerId = safedup( string );
 p++;
 while( *p != '\0' && !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) ) p++;
 return find_msn( p, msn_list );
    }
}


decompiled_code:
__int64 __fastcall ring_handle_DROx(char *nptr)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rdx
int v4; // eax
int v5; // ebp
const char *v6; // rsi
__int64 result; // rax

v2 = *_ctype_b_loc();
while ( 1 )
{
v3 = *nptr;
if ( (v2[v3] & 0x2000) == 0 && (_BYTE)v3 != 61 )
break;
++nptr;
}
v4 = atoi(nptr);
if ( !drox_count || (v5 = 0, v6 = "<short>", v4 > 9) )
{
v5 = 1;
v6 = "<long>";
}
lputs(5LL, v6);
++drox_count;
result = v5 | (unsigned int)(2 * drox_bitstring);
drox_bitstring = v5 | (2 * drox_bitstring);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *nptr)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rdx
int v4; // eax
int v5; // ebp
const char *v6; // rsi
__int64 result; // rax

v2 = *_ctype_b_loc();
while ( 1 )
{
v3 = *nptr;
if ( (v2[v3] & 0x2000) == 0 && (_BYTE)v3 != 61 )
break;
++nptr;
}
v4 = atoi(nptr);
if ( !drox_count || (v5 = 0, v6 = "<short>", v4 > 9) )
{
v5 = 1;
v6 = "<long>";
}
lputs(5LL, v6);
++drox_count;
result = v5 | (unsigned int)(2 * drox_bitstring);
drox_bitstring = v5 | (2 * drox_bitstring);
return result;
}

original_code:
static void ring_handle_DROx( char * p )
{
    int len, bit;
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace) || *p == '=' ) { p++; }
    len = atoi( p );
    bit = ( drox_count == 0 || len > 9 ) ? 1 : 0;
    lputs( 5, bit? "<long>": "<short>" );
    drox_bitstring = (drox_bitstring << 1 ) | bit;
    drox_count++;
}

canonical_original_code:
static void ring_handle_DROx(char *p)
{
    int len; int bit;
    while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace) || *p == '=' ) { p++; }
    len = atoi( p );
    bit = ( drox_count == 0 || len > 9 ) ? 1 : 0;
    lputs( 5, bit? "<long>": "<short>" );
    drox_bitstring = (drox_bitstring << 1 ) | bit;
    drox_count++;
}

variable_types: bit int


decompiled_code:
__int64 __fastcall wait_for_ring(unsigned int a1, const char **a2, unsigned int a3, const char **a4, _DWORD *a5, _DWORD *a6)
{
bool v9; // bp
int v10; // ebx
char v11; // r12
const char **v12; // r12
const char *v13; // r15
int v14; // eax
unsigned int v15; // er12
int v16; // edx
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
__int64 v22; // rax
__int64 v23; // rcx
const unsigned __int16 **v25; // rax
char *v26; // rdi
const unsigned __int16 *v27; // rax
__int64 v28; // r8
unsigned __int16 v29; // r15
size_t v30; // rax
const __int32_t **v31; // rax
int v32; // eax
int v33; // eax
int v34; // eax
int v36; // [rsp+0h] [rbp-278h]
int n; // [rsp+18h] [rbp-260h]
__int64 v40; // [rsp+20h] [rbp-258h]
char v41; // [rsp+2Bh] [rbp-24Dh]
char v42; // [rsp+3Fh] [rbp-239h] BYREF
int s1; // [rsp+40h] [rbp-238h] BYREF
char nptr[564]; // [rsp+44h] [rbp-234h] BYREF

lprintf(4LL, "wfr: waiting for ``RING''");
lprintf(5LL, "got: ");
signal(14, (__sighandler_t)chat_timeout);
alarm(a3);
chat_has_timeout = 0;
if ( virtual_ring )
{
LABEL_30:
v15 = 0;
lputs(5LL, "``found''");
v16 = drox_count;
goto LABEL_34;
}
v9 = 0;
v10 = 0;
while ( 1 )
{
while ( 1 )
{
if ( (int)mdm_read_byte(a1, &v42) <= 0 )
{
if ( chat_has_timeout )
lprintf(3LL, "wfr: timeout waiting for RING");
else
lprintf(1LL, "wfr: error in read()");
v16 = drox_count;
v15 = -1;
if ( a5 )
*a5 = 0;
goto LABEL_34;
}
lputc(5LL, (unsigned int)v42);
if ( v9 )
{
v11 = v42;
switch ( v42 )
{
case 'H':
case 'P':
case 'h':
case 'p':
case 'r':
v16 = drox_count;
*a6 = -v42;
v15 = 0;
goto LABEL_34;
case 'R':
*a6 = 0;
v16 = drox_count;
v15 = 0;
goto LABEL_34;
default:
v9 = 0;
if ( v42 != 13 )
goto LABEL_7;
goto LABEL_18;
}
}
v11 = v42;
v9 = v42 == 16;
if ( v42 != 13 )
break;
LABEL_18:
if ( !v10 )
goto LABEL_29;
*((_BYTE *)&s1 + v10) = 0;
cndfind(&s1);
if ( (_WORD)s1 == 19782 && BYTE2(s1) == 58
|| (v17 = (unsigned __int16)s1 < 0x4F54u, v18 = (_WORD)s1 == 20308)
&& (v17 = BYTE2(s1) < 0x3Au, v18 = BYTE2(s1) == 58) )
{
v15 = 0;
v32 = ring_handle_ZyXEL((__int64)&s1, a2);
v16 = drox_count;
*a6 = v32;
goto LABEL_34;
}
v19 = "NMBR";
v20 = 4LL;
v21 = (const char *)&s1;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v15 = drox_count | (char)((!v17 && !v18) - v17);
if ( !v15 )
{
alarm(0);
goto LABEL_35;
}
if ( s1 != 1313821252 && s1 != 1179603524 )
{
if ( s1 == 1196312914 )
{
n = drox_count;
v15 = 0;
v25 = _ctype_b_loc();
v16 = n;
v26 = nptr;
v27 = *v25;
while ( 1 )
{
v28 = *v26;
v29 = v27[v28];
if ( (v29 & 0x2000) == 0 )
break;
++v26;
}
switch ( (_BYTE)v28 )
{
case 0:
goto LABEL_34;
case 0x3B:
LABEL_61:
v33 = ring_handle_ELSA(v26, a2);
v16 = drox_count;
*a6 = v33;
goto LABEL_34;
case 0x3A:
v34 = ring_handle_ZoomMX((__int64)v26);
v16 = drox_count;
*a6 = v34;
goto LABEL_34;
}
v40 = *v26;
v41 = *v26;
v30 = strlen(v26);
v16 = n;
if ( v30 > 1 )
goto LABEL_61;
if ( (v29 & 0x800) != 0 )
{
*a6 = v41 - 48;
goto LABEL_34;
}
if ( (v29 & 0x400) != 0 )
{
v31 = _ctype_tolower_loc();
v16 = n;
*a6 = (*v31)[v40] - 96;
goto LABEL_34;
}
}
else
{
v10 = 0;
lprintf(5LL, "got: ", (unsigned int)drox_count, v20, &s1);
}
goto LABEL_29;
}
v10 = 0;
ring_handle_DROx(nptr);
if ( virtual_ring )
goto LABEL_30;
}
LABEL_7:
if ( v11 == 10 )
goto LABEL_18;
if ( v10 )
break;
if ( ((*_ctype_b_loc())[v11] & 0x2000) == 0 )
goto LABEL_32;
LABEL_29:
if ( virtual_ring )
goto LABEL_30;
}
if ( v10 > 8189 )
goto LABEL_10;
LABEL_32:
v22 = v10++;
*((_BYTE *)&s1 + v22) = v11;
LABEL_10:
v12 = a4;
if ( !a4 )
goto LABEL_29;
v13 = *a4;
if ( !*a4 )
goto LABEL_29;
while ( v10 != (unsigned int)strlen(v13) || memcmp(&s1, v13, v10) )
{
v13 = v12[2];
v12 += 2;
if ( !v13 )
goto LABEL_29;
}
lprintf(4LL, "wfr: found action string: ``%s''", v13);
v14 = *((_DWORD *)v12 + 2);
v15 = -1;
v16 = drox_count;
*a5 = v14;
LABEL_34:
v36 = v16;
alarm(0);
if ( v36 > 0 )
{
lprintf(5LL, "wfr: DRON/DROF cadence: %x", (unsigned int)drox_bitstring);
v23 = (unsigned int)drox_bitstring;
drox_count = 0;
drox_bitstring = 0;
*a6 = v23;
}
else
{
LABEL_35:
v23 = (unsigned int)*a6;
}
lprintf(5LL, "wfr: rc=%d, drn=%d", v15, v23);
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const char **a2, unsigned int a3, const char **a4, _DWORD *a5, _DWORD *a6)
{
bool v9; // bp
int v10; // ebx
char v11; // r12
const char **v12; // r12
const char *v13; // r15
int v14; // eax
unsigned int v15; // er12
int v16; // edx
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
__int64 v22; // rax
__int64 v23; // rcx
const unsigned __int16 **v25; // rax
char *v26; // rdi
const unsigned __int16 *v27; // rax
__int64 v28; // r8
unsigned __int16 v29; // r15
size_t v30; // rax
const __int32_t **v31; // rax
int v32; // eax
int v33; // eax
int v34; // eax
int v36; // [rsp+0h] [rbp-278h]
int n; // [rsp+18h] [rbp-260h]
__int64 v40; // [rsp+20h] [rbp-258h]
char v41; // [rsp+2Bh] [rbp-24Dh]
char v42; // [rsp+3Fh] [rbp-239h] BYREF
int s1; // [rsp+40h] [rbp-238h] BYREF
char nptr[564]; // [rsp+44h] [rbp-234h] BYREF

lprintf(4LL, "wfr: waiting for ``RING''");
lprintf(5LL, "got: ");
signal(14, (__sighandler_t)chat_timeout);
alarm(a3);
chat_has_timeout = 0;
if ( virtual_ring )
{
LABEL_30:
v15 = 0;
lputs(5LL, "``found''");
v16 = drox_count;
goto LABEL_34;
}
v9 = 0;
v10 = 0;
while ( 1 )
{
while ( 1 )
{
if ( (int)mdm_read_byte(a1, &v42) <= 0 )
{
if ( chat_has_timeout )
lprintf(3LL, "wfr: timeout waiting for RING");
else
lprintf(1LL, "wfr: error in read()");
v16 = drox_count;
v15 = -1;
if ( a5 )
*a5 = 0;
goto LABEL_34;
}
lputc(5LL, (unsigned int)v42);
if ( v9 )
{
v11 = v42;
switch ( v42 )
{
case 'H':
case 'P':
case 'h':
case 'p':
case 'r':
v16 = drox_count;
*a6 = -v42;
v15 = 0;
goto LABEL_34;
case 'R':
*a6 = 0;
v16 = drox_count;
v15 = 0;
goto LABEL_34;
default:
v9 = 0;
if ( v42 != 13 )
goto LABEL_7;
goto LABEL_18;
}
}
v11 = v42;
v9 = v42 == 16;
if ( v42 != 13 )
break;
LABEL_18:
if ( !v10 )
goto LABEL_29;
*((_BYTE *)&s1 + v10) = 0;
cndfind(&s1);
if ( (_WORD)s1 == 19782 && BYTE2(s1) == 58
|| (v17 = (unsigned __int16)s1 < 0x4F54u, v18 = (_WORD)s1 == 20308)
&& (v17 = BYTE2(s1) < 0x3Au, v18 = BYTE2(s1) == 58) )
{
v15 = 0;
v32 = func4((__int64)&s1, a2);
v16 = drox_count;
*a6 = v32;
goto LABEL_34;
}
v19 = "NMBR";
v20 = 4LL;
v21 = (const char *)&s1;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v15 = drox_count | (char)((!v17 && !v18) - v17);
if ( !v15 )
{
alarm(0);
goto LABEL_35;
}
if ( s1 != 1313821252 && s1 != 1179603524 )
{
if ( s1 == 1196312914 )
{
n = drox_count;
v15 = 0;
v25 = _ctype_b_loc();
v16 = n;
v26 = nptr;
v27 = *v25;
while ( 1 )
{
v28 = *v26;
v29 = v27[v28];
if ( (v29 & 0x2000) == 0 )
break;
++v26;
}
switch ( (_BYTE)v28 )
{
case 0:
goto LABEL_34;
case 0x3B:
LABEL_61:
v33 = func5(v26, a2);
v16 = drox_count;
*a6 = v33;
goto LABEL_34;
case 0x3A:
v34 = func2((__int64)v26);
v16 = drox_count;
*a6 = v34;
goto LABEL_34;
}
v40 = *v26;
v41 = *v26;
v30 = strlen(v26);
v16 = n;
if ( v30 > 1 )
goto LABEL_61;
if ( (v29 & 0x800) != 0 )
{
*a6 = v41 - 48;
goto LABEL_34;
}
if ( (v29 & 0x400) != 0 )
{
v31 = _ctype_tolower_loc();
v16 = n;
*a6 = (*v31)[v40] - 96;
goto LABEL_34;
}
}
else
{
v10 = 0;
lprintf(5LL, "got: ", (unsigned int)drox_count, v20, &s1);
}
goto LABEL_29;
}
v10 = 0;
func6(nptr);
if ( virtual_ring )
goto LABEL_30;
}
LABEL_7:
if ( v11 == 10 )
goto LABEL_18;
if ( v10 )
break;
if ( ((*_ctype_b_loc())[v11] & 0x2000) == 0 )
goto LABEL_32;
LABEL_29:
if ( virtual_ring )
goto LABEL_30;
}
if ( v10 > 8189 )
goto LABEL_10;
LABEL_32:
v22 = v10++;
*((_BYTE *)&s1 + v22) = v11;
LABEL_10:
v12 = a4;
if ( !a4 )
goto LABEL_29;
v13 = *a4;
if ( !*a4 )
goto LABEL_29;
while ( v10 != (unsigned int)strlen(v13) || memcmp(&s1, v13, v10) )
{
v13 = v12[2];
v12 += 2;
if ( !v13 )
goto LABEL_29;
}
lprintf(4LL, "wfr: found action string: ``%s''", v13);
v14 = *((_DWORD *)v12 + 2);
v15 = -1;
v16 = drox_count;
*a5 = v14;
LABEL_34:
v36 = v16;
alarm(0);
if ( v36 > 0 )
{
lprintf(5LL, "wfr: DRON/DROF cadence: %x", (unsigned int)drox_bitstring);
v23 = (unsigned int)drox_bitstring;
drox_count = 0;
drox_bitstring = 0;
*a6 = v23;
}
else
{
LABEL_35:
v23 = (unsigned int)*a6;
}
lprintf(5LL, "wfr: rc=%d, drn=%d", v15, v23);
return v15;
}

original_code:
int wait_for_ring (int fd,char ** msn_list,int timeout,chat_action_t actions[],action_t * action,int * dist_ring_number)
{
char buf[500], ch, *p;
int i, w, r;
int rc = 0;
boolean got_dle;
    lprintf( 4, "wfr: waiting for ``RING''" );
    lprintf( 5, "got: ");
    w=0;
    got_dle = (1==0);
    signal( 14, chat_timeout );
    alarm( timeout );
    chat_has_timeout = (1==0);
    while((1==1))
    {
 if ( virtual_ring )
 {
     lputs( 5, "``found''" );
     break;
 }
 r = mdm_read_byte( fd, &ch );
 if ( r <= 0 )
 {
     if ( chat_has_timeout )
  lprintf( 3, "wfr: timeout waiting for RING" );
     else
  lprintf( 1, "wfr: error in read()" );
     if ( action != ((void *)0) ) *action = A_TIMOUT;
     rc = -1; break;
 }
 lputc( 5, ch );
 if ( got_dle )
 {
     switch( ch )
     {
  case 'h':
  case 'p':
  case 'H':
  case 'P':
  case 'r':
      *dist_ring_number = - (int)ch;
      goto have_ring; break;
  case 'R':
      *dist_ring_number = 0;
      goto have_ring; break;
  default:
      got_dle = (1==0);
     }
 }
 else
     if ( ch == 020 ) got_dle = (1==1);
 if ( ch != '\r' && ch != '\n' )
 {
     if ( w == 0 && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISspace) ) continue;
     if( w < 8192 -2 )
  buf[w++] = ch;
     if ( actions != ((void *)0) )
       for( i=0; actions[i].expect != ((void *)0); i++ )
     {
  int len = strlen( actions[i].expect );
  if ( w == len &&
       memcmp( buf, actions[i].expect, len ) == 0 )
  {
      lprintf( 4, "wfr: found action string: ``%s''",
         actions[i].expect );
      *action = actions[i].action;
      rc = -1; break;
  }
     }
     if ( rc == -1 ) break;
     continue;
 }
 if ( w == 0 ) { continue; }
 buf[w] = '\0';
 cndfind( buf );
 if ( strncmp( buf, "FM:", 3 ) == 0 ||
      strncmp( buf, "TO:", 3 ) == 0 )
     { *dist_ring_number = ring_handle_ZyXEL( buf, msn_list ); break; }
 if ( strncmp( buf, "NMBR", 4 ) == 0 && drox_count == 0 ) { break; }
 if ( strncmp( buf, "DRON", 4 ) == 0 ||
      strncmp( buf, "DROF", 4 ) == 0 )
  { ring_handle_DROx( buf+4 ); w=0; continue; }
 if ( strncmp( buf, "RING", 4 ) != 0 )
     { w = 0; lprintf( 5, "got: " ); continue; }
 p=&buf[4];
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace) ) p++;
 if ( *p == '\0' )
     { break; }
 if ( *p == ';' )
     { *dist_ring_number = ring_handle_ELSA( p, msn_list ); break; }
 if ( *p== ':' )
     { *dist_ring_number = ring_handle_ZoomMX( p ); break; }
 if ( strlen(p) > 1 )
     { *dist_ring_number = ring_handle_ELSA( p, msn_list ); break; }
 if ( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) )
     { *dist_ring_number = *p-'0'; break; }
 if ( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) )
     { *dist_ring_number = tolower(*p)-'a' +1; break; }
    }
have_ring:
    alarm(0);
    if ( drox_count > 0 )
    {
 lprintf( 5, "wfr: DRON/DROF cadence: %x", drox_bitstring );
 *dist_ring_number = drox_bitstring;
 drox_count=0; drox_bitstring=0;
    }
    lprintf( 5, "wfr: rc=%d, drn=%d", rc, *dist_ring_number );
    return rc;
}

canonical_original_code:
int wait_for_ring(int fd, char **msn_list, int timeout, struct chat_actions actions[], enum action_t *action, int *dist_ring_number)
{
char buf[500]; char ch; char *p;
int i; int w; int r;
int rc = 0;
char got_dle;
    lprintf( 4, "wfr: waiting for ``RING''" );
    lprintf( 5, "got: ");
    w=0;
    got_dle = (1==0);
    signal( 14, chat_timeout );
    alarm( timeout );
    chat_has_timeout = (1==0);
    while((1==1))
    {
 if ( virtual_ring )
 {
     lputs( 5, "``found''" );
     break;
 }
 r = mdm_read_byte( fd, &ch );
 if ( r <= 0 )
 {
     if ( chat_has_timeout )
  lprintf( 3, "wfr: timeout waiting for RING" );
     else
  lprintf( 1, "wfr: error in read()" );
     if ( action != ((void *)0) ) *action = A_TIMOUT;
     rc = -1; break;
 }
 lputc( 5, ch );
 if ( got_dle )
 {
     switch( ch )
     {
  case 'h':
  case 'p':
  case 'H':
  case 'P':
  case 'r':
      *dist_ring_number = - (int)ch;
      goto have_ring; break;
  case 'R':
      *dist_ring_number = 0;
      goto have_ring; break;
  default:
      got_dle = (1==0);
     }
 }
 else
     if ( ch == 020 ) got_dle = (1==1);
 if ( ch != '\r' && ch != '\n' )
 {
     if ( w == 0 && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISspace) ) continue;
     if( w < 8192 -2 )
  buf[w++] = ch;
     if ( actions != ((void *)0) )
       for( i=0; actions[i].expect != ((void *)0); i++ )
     {
  int len = strlen( actions[i].expect );
  if ( w == len &&
       memcmp( buf, actions[i].expect, len ) == 0 )
  {
      lprintf( 4, "wfr: found action string: ``%s''",
         actions[i].expect );
      *action = actions[i].action;
      rc = -1; break;
  }
     }
     if ( rc == -1 ) break;
     continue;
 }
 if ( w == 0 ) { continue; }
 buf[w] = '\0';
 cndfind( buf );
 if ( strncmp( buf, "FM:", 3 ) == 0 ||
      strncmp( buf, "TO:", 3 ) == 0 )
     { *dist_ring_number = ring_handle_ZyXEL( buf, msn_list ); break; }
 if ( strncmp( buf, "NMBR", 4 ) == 0 && drox_count == 0 ) { break; }
 if ( strncmp( buf, "DRON", 4 ) == 0 ||
      strncmp( buf, "DROF", 4 ) == 0 )
  { ring_handle_DROx( buf+4 ); w=0; continue; }
 if ( strncmp( buf, "RING", 4 ) != 0 )
     { w = 0; lprintf( 5, "got: " ); continue; }
 p=&buf[4];
 while( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace) ) p++;
 if ( *p == '\0' )
     { break; }
 if ( *p == ';' )
     { *dist_ring_number = ring_handle_ELSA( p, msn_list ); break; }
 if ( *p== ':' )
     { *dist_ring_number = ring_handle_ZoomMX( p ); break; }
 if ( strlen(p) > 1 )
     { *dist_ring_number = ring_handle_ELSA( p, msn_list ); break; }
 if ( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) )
     { *dist_ring_number = *p-'0'; break; }
 if ( ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) )
     { *dist_ring_number = tolower(*p)-'a' +1; break; }
    }
have_ring:
    alarm(0);
    if ( drox_count > 0 )
    {
 lprintf( 5, "wfr: DRON/DROF cadence: %x", drox_bitstring );
 *dist_ring_number = drox_bitstring;
 drox_count=0; drox_bitstring=0;
    }
    lprintf( 5, "wfr: rc=%d, drn=%d", rc, *dist_ring_number );
    return rc;
}

variable_types: fd int

variable_types: struct chat_actions { char *expect; enum action_t { A_TIMOUT=0, A_FAIL=1, A_FAX=2, A_VCON=3, A_CONN=4, A_RING1=5, A_RING2=6, A_RING3=7, A_RING4=8, A_RING5=9 } action; } []

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

variable_types:
buf
char [500]

variable_types: w int

variable_types: r int

variable_types: rc int

user_defined_types: struct chat_actions { char *expect; enum action_t action; }


decompiled_code:
__int64 __fastcall voice_faxsnd(__int64 *a1, unsigned int a2, int a3)
{
__int64 *v4; // rbx
time_t v5; // r14
__int64 v6; // rdi
unsigned int v7; // er15
unsigned int v8; // ebp
int v9; // er12
time_t v10; // rax
unsigned int v12; // [rsp+Ch] [rbp-7Ch] BYREF
char v13[120]; // [rsp+10h] [rbp-78h] BYREF

v4 = a1;
v12 = 0;
faxlib_init();
tio_get(0LL, v13);
if ( a2 )
tio_set_speed(v13, a2);
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_set_bor(0LL, 0LL);
if ( (unsigned int)fax_set_flowcontrol(0LL, 1LL) == -1 )
lprintf(3LL, "cannot set modem flow control");
v5 = time(0LL);
if ( (unsigned int)fax_command("ATD", "OK", 0LL) == -1 )
{
v7 = 0;
v8 = 0;
goto LABEL_14;
}
v6 = *a1;
v7 = 0;
v8 = 0;
if ( *v4 )
{
v9 = 0;
while ( 1 )
{
++v8;
fax_page_tx_status = -1;
if ( (unsigned int)fax_send_page(v6, &v12, v13, 2 * (unsigned int)(v4[1] == 0), 0LL) == -1 )
break;
switch ( fax_page_tx_status )
{
case 0xFFFFFFFF:
lprintf(3LL, "fpts:-1");
if ( !fax_hangup )
goto LABEL_12;
goto LABEL_16;
case 1:
goto LABEL_11;
case 2:
if ( a3 <= 0 )
{
lprintf(3LL, "WARNING: RTN ignored");
LABEL_11:
if ( fax_hangup )
{
LABEL_16:
if ( fax_hangup_code )
goto LABEL_14;
}
LABEL_12:
++v4;
v9 = 0;
}
else
{
if ( a3 <= ++v9 )
{
lprintf(3LL, "ERROR: too many retries - aborting send");
fax_hangup = 1;
fax_hangup_code = -1;
goto LABEL_14;
}
++v7;
}
v6 = *v4;
if ( !*v4 )
goto LABEL_14;
break;
case 3:
lprintf(3LL, "WARNING: RTP: page good, but retrain requested");
goto LABEL_11;
case 4:
case 5:
lprintf(3LL, "WARNING: procedure interrupt requested - don't know how to handle it");
goto LABEL_11;
default:
lprintf(3LL, "WARNING: invalid code: +FPTS:%d", fax_page_tx_status);
goto LABEL_11;
}
}
}
LABEL_14:
v10 = time(0LL);
lprintf(2LL, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d", fax_hangup_code, v10 - v5, v8, v7, v12);
voice_fax_remote_id = &fax_remote_id;
voice_fax_files = 0LL;
voice_fax_hangup_code = fax_hangup_code;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, unsigned int a2, int a3)
{
__int64 *v4; // rbx
time_t v5; // r14
__int64 v6; // rdi
unsigned int v7; // er15
unsigned int v8; // ebp
int v9; // er12
time_t v10; // rax
unsigned int v12; // [rsp+Ch] [rbp-7Ch] BYREF
char v13[120]; // [rsp+10h] [rbp-78h] BYREF

v4 = a1;
v12 = 0;
faxlib_init();
tio_get(0LL, v13);
if ( a2 )
tio_set_speed(v13, a2);
tio_mode_raw(v13);
tio_set(0LL, v13);
fax_set_bor(0LL, 0LL);
if ( (unsigned int)fax_set_flowcontrol(0LL, 1LL) == -1 )
lprintf(3LL, "cannot set modem flow control");
v5 = time(0LL);
if ( (unsigned int)fax_command("ATD", "OK", 0LL) == -1 )
{
v7 = 0;
v8 = 0;
goto LABEL_14;
}
v6 = *a1;
v7 = 0;
v8 = 0;
if ( *v4 )
{
v9 = 0;
while ( 1 )
{
++v8;
fax_page_tx_status = -1;
if ( (unsigned int)fax_send_page(v6, &v12, v13, 2 * (unsigned int)(v4[1] == 0), 0LL) == -1 )
break;
switch ( fax_page_tx_status )
{
case 0xFFFFFFFF:
lprintf(3LL, "fpts:-1");
if ( !fax_hangup )
goto LABEL_12;
goto LABEL_16;
case 1:
goto LABEL_11;
case 2:
if ( a3 <= 0 )
{
lprintf(3LL, "WARNING: RTN ignored");
LABEL_11:
if ( fax_hangup )
{
LABEL_16:
if ( fax_hangup_code )
goto LABEL_14;
}
LABEL_12:
++v4;
v9 = 0;
}
else
{
if ( a3 <= ++v9 )
{
lprintf(3LL, "ERROR: too many retries - aborting send");
fax_hangup = 1;
fax_hangup_code = -1;
goto LABEL_14;
}
++v7;
}
v6 = *v4;
if ( !*v4 )
goto LABEL_14;
break;
case 3:
lprintf(3LL, "WARNING: RTP: page good, but retrain requested");
goto LABEL_11;
case 4:
case 5:
lprintf(3LL, "WARNING: procedure interrupt requested - don't know how to handle it");
goto LABEL_11;
default:
lprintf(3LL, "WARNING: invalid code: +FPTS:%d", fax_page_tx_status);
goto LABEL_11;
}
}
}
LABEL_14:
v10 = time(0LL);
lprintf(2LL, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d", fax_hangup_code, v10 - v5, v8, v7, v12);
voice_fax_remote_id = &fax_remote_id;
voice_fax_files = 0LL;
voice_fax_hangup_code = fax_hangup_code;
return 0LL;
}

original_code:
int voice_faxsnd (char **name,int switchbd,int max_tries)
{
    int tries;
    TIO tio;
    time_t call_start;
    int total_bytes = 0;
    int total_pages = 0;
    int total_resent= 0;
    faxlib_init();
    tio_get( 0, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    fax_set_bor( 0, 0 );
    if ( fax_set_flowcontrol( 0, (0x01 | (0x02 | 0x04)) & 0x01 ) == -1 )
    {
     lprintf( 3, "cannot set modem flow control" );
    }
    call_start = time( ((void *)0) );
    tries = 0;
    if (fax_command( "ATD", "OK", 0 ) == -1) ;
      else
    while ( *name )
    {
     Post_page_messages ppm;
     total_pages++;
     if ( ! *(name+1) )
             ppm = pp_eop;
     else
             ppm = pp_mps;
     fax_page_tx_status = -1;
     if ( fax_send_page( *name, &total_bytes, &tio, ppm, 0 ) == -1 )
     {
         break;
     }
     switch ( fax_page_tx_status )
     {
       case 1: break;
       case 2:
         if ( max_tries <= 0 )
         {
          lprintf( 3, "WARNING: RTN ignored" );
         }
         else
         {
          tries ++;
          if ( tries >= max_tries )
          {
               lprintf( 3, "ERROR: too many retries - aborting send" );
               fax_hangup_code = -1;
               fax_hangup = 1;
          }
          else
          {
              total_resent++;
              continue;
          }
         }
         break;
       case 3: lprintf( 3, "WARNING: RTP: page good, but retrain requested" );
              break;
       case 4:
       case 5: lprintf( 3, "WARNING: procedure interrupt requested - don't know how to handle it" );
              break;
       case -1:
            lprintf( 3, "fpts:-1" );
            break;
       default:lprintf( 3, "WARNING: invalid code: +FPTS:%d",
                       fax_page_tx_status );
            break;
     }
     if ( fax_hangup && fax_hangup_code != 0 ) break;
     tries=0;
     name++;
    }
    call_start = time(((void *)0))-call_start;
    lprintf( 2, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d",
                   fax_hangup_code, call_start,
                   total_pages, total_resent, total_bytes );
    voice_fax_hangup_code = fax_hangup_code;
    voice_fax_remote_id = fax_remote_id;
    voice_fax_files = ((void *)0);
    return 0;
}

canonical_original_code:
int voice_faxsnd(char **name, int switchbd, int max_tries)
{
    int tries;
    struct termios tio;
    long call_start;
    int total_bytes = 0;
    int total_pages = 0;
    int total_resent = 0;
    faxlib_init();
    tio_get( 0, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    fax_set_bor( 0, 0 );
    if ( fax_set_flowcontrol( 0, (0x01 | (0x02 | 0x04)) & 0x01 ) == -1 )
    {
     lprintf( 3, "cannot set modem flow control" );
    }
    call_start = time( ((void *)0) );
    tries = 0;
    if (fax_command( "ATD", "OK", 0 ) == -1) ;
      else
    while ( *name )
    {
     enum Post_page_messages ppm;
     total_pages++;
     if ( ! *(name+1) )
             ppm = pp_eop;
     else
             ppm = pp_mps;
     fax_page_tx_status = -1;
     if ( fax_send_page( *name, &total_bytes, &tio, ppm, 0 ) == -1 )
     {
         break;
     }
     switch ( fax_page_tx_status )
     {
       case 1: break;
       case 2:
         if ( max_tries <= 0 )
         {
          lprintf( 3, "WARNING: RTN ignored" );
         }
         else
         {
          tries ++;
          if ( tries >= max_tries )
          {
               lprintf( 3, "ERROR: too many retries - aborting send" );
               fax_hangup_code = -1;
               fax_hangup = 1;
          }
          else
          {
              total_resent++;
              continue;
          }
         }
         break;
       case 3: lprintf( 3, "WARNING: RTP: page good, but retrain requested" );
              break;
       case 4:
       case 5: lprintf( 3, "WARNING: procedure interrupt requested - don't know how to handle it" );
              break;
       case -1:
            lprintf( 3, "fpts:-1" );
            break;
       default:lprintf( 3, "WARNING: invalid code: +FPTS:%d",
                       fax_page_tx_status );
            break;
     }
     if ( fax_hangup && fax_hangup_code != 0 ) break;
     tries=0;
     name++;
    }
    call_start = time(((void *)0))-call_start;
    lprintf( 2, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d",
                   fax_hangup_code, call_start,
                   total_pages, total_resent, total_bytes );
    voice_fax_hangup_code = fax_hangup_code;
    voice_fax_remote_id = fax_remote_id;
    voice_fax_files = ((void *)0);
    return 0;
}

variable_types:
name
char **

variable_types: switchbd int

variable_types: tries int

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: enum Post_page_messages { pp_mps=0, pp_eom=1, pp_eop=2, pp_pri_mps=3, pp_pri_eom=4, pp_pri_eop=5 }


decompiled_code:
__int64 __fastcall voice_faxrec(__int64 a1, unsigned int a2)
{
time_t v2; // rbp
time_t v3; // rax
__int64 result; // rax
unsigned int v5; // [rsp+Ch] [rbp-5Ch] BYREF
char v6[88]; // [rsp+10h] [rbp-58h] BYREF

v5 = 0;
faxlib_init();
lprintf(5LL, "fax receiver: entry");
tio_get(0LL, v6);
if ( a2 )
{
tio_set_speed(v6, a2);
tio_mode_raw(v6);
tio_set(0LL, v6);
v2 = time(0LL);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", a2);
if ( a2 == 19200 )
lprintf(3LL, ">> try using 'switchbd 0'");
else
lprintf(3LL, ">> try using 'switchbd 19200' or 'switchbd 0'");
LABEL_7:
fax_hangup = 1;
goto LABEL_3;
}
tio_mode_raw(v6);
tio_set(0LL, v6);
v2 = time(0LL);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code == -6 )
{
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", 0LL);
lprintf(3LL, ">> try using 'switchbd 19200'");
goto LABEL_7;
}
LABEL_3:
tio_set_flow_control(0LL, v6, 3LL);
tio_set(0LL, v6);
fax_set_flowcontrol(0LL, 1LL);
fax_get_pages(0LL, &v5, a1, 0LL, 0LL, 432LL);
lprintf(5LL, "fax receiver: hangup & end");
v3 = time(0LL);
lprintf(
2LL,
"fax caller=%s, name='%s', id='%s', +FHNG=%03d, pages=%d, time=%ds",
CallerId,
CallName,
(const char *)&fax_remote_id,
fax_hangup_code,
v5,
v3 - v2);
voice_fax_remote_id = &fax_remote_id;
voice_fax_hangup_code = fax_hangup_code;
result = fax_file_names;
voice_fax_files = fax_file_names;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
time_t v2; // rbp
time_t v3; // rax
__int64 result; // rax
unsigned int v5; // [rsp+Ch] [rbp-5Ch] BYREF
char v6[88]; // [rsp+10h] [rbp-58h] BYREF

v5 = 0;
faxlib_init();
lprintf(5LL, "fax receiver: entry");
tio_get(0LL, v6);
if ( a2 )
{
tio_set_speed(v6, a2);
tio_mode_raw(v6);
tio_set(0LL, v6);
v2 = time(0LL);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code != -6 )
goto LABEL_3;
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", a2);
if ( a2 == 19200 )
lprintf(3LL, ">> try using 'switchbd 0'");
else
lprintf(3LL, ">> try using 'switchbd 19200' or 'switchbd 0'");
LABEL_7:
fax_hangup = 1;
goto LABEL_3;
}
tio_mode_raw(v6);
tio_set(0LL, v6);
v2 = time(0LL);
fax_wait_for("OK", 0LL);
if ( fax_hangup_code == -6 )
{
lprintf(3LL, ">> The problem seen above might be caused by a wrong value of the");
lprintf(3LL, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", 0LL);
lprintf(3LL, ">> try using 'switchbd 19200'");
goto LABEL_7;
}
LABEL_3:
tio_set_flow_control(0LL, v6, 3LL);
tio_set(0LL, v6);
fax_set_flowcontrol(0LL, 1LL);
fax_get_pages(0LL, &v5, a1, 0LL, 0LL, 432LL);
lprintf(5LL, "fax receiver: hangup & end");
v3 = time(0LL);
lprintf(
2LL,
"fax caller=%s, name='%s', id='%s', +FHNG=%03d, pages=%d, time=%ds",
CallerId,
CallName,
(const char *)&fax_remote_id,
fax_hangup_code,
v5,
v3 - v2);
voice_fax_remote_id = &fax_remote_id;
voice_fax_hangup_code = fax_hangup_code;
result = fax_file_names;
voice_fax_files = fax_file_names;
return result;
}

original_code:
void voice_faxrec (char * spool_in,unsigned int switchbd)
{
    int pagenum = 0;
    TIO tio;
    time_t call_start;
    faxlib_init();
    lprintf( 5, "fax receiver: entry" );
    tio_get( 0, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    call_start = time( ((void *)0) );
    fax_wait_for( "OK", 0 );
    if ( fax_hangup_code == -6 )
    {
     lprintf( 3, ">> The problem seen above might be caused by a wrong value of the" );
     lprintf( 3, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", switchbd );
     if ( switchbd > 0 && switchbd != 19200 )
          lprintf( 3, ">> try using 'switchbd 19200' or 'switchbd 0'");
     else if ( switchbd > 0 )
          lprintf( 3, ">> try using 'switchbd 0'" );
     else lprintf( 3, ">> try using 'switchbd 19200'" );
     fax_hangup = 1;
    }
    tio_set_flow_control( 0, &tio,
                (0x01 | (0x02 | 0x04)) & (0x01|0x02) );
    tio_set( 0, &tio );
    fax_set_flowcontrol( 0, (0x01 | (0x02 | 0x04)) & 0x01 );
    fax_get_pages( 0, &pagenum, spool_in, 0, 0, 0660 );
    lprintf( 5, "fax receiver: hangup & end" );
    lprintf( 2, "fax caller=%s, name='%s', id='%s', +FHNG=%03d, pages=%d, time=%ds",
     CallerId, CallName, fax_remote_id, fax_hangup_code, pagenum,
                   ( time(((void *)0))-call_start ));
    voice_fax_hangup_code = fax_hangup_code;
    voice_fax_remote_id = fax_remote_id;
    voice_fax_files = fax_file_names;
    return;
}

canonical_original_code:
void voice_faxrec(char *spool_in, unsigned int switchbd)
{
    int pagenum = 0;
    struct termios tio;
    long call_start;
    faxlib_init();
    lprintf( 5, "fax receiver: entry" );
    tio_get( 0, &tio );
    if ( switchbd != 0 ) tio_set_speed( &tio, switchbd );
    tio_mode_raw( &tio );
    tio_set( 0, &tio );
    call_start = time( ((void *)0) );
    fax_wait_for( "OK", 0 );
    if ( fax_hangup_code == -6 )
    {
     lprintf( 3, ">> The problem seen above might be caused by a wrong value of the" );
     lprintf( 3, ">> 'switchbd' option in 'mgetty.config' (currently set to '%d')", switchbd );
     if ( switchbd > 0 && switchbd != 19200 )
          lprintf( 3, ">> try using 'switchbd 19200' or 'switchbd 0'");
     else if ( switchbd > 0 )
          lprintf( 3, ">> try using 'switchbd 0'" );
     else lprintf( 3, ">> try using 'switchbd 19200'" );
     fax_hangup = 1;
    }
    tio_set_flow_control( 0, &tio,
                (0x01 | (0x02 | 0x04)) & (0x01|0x02) );
    tio_set( 0, &tio );
    fax_set_flowcontrol( 0, (0x01 | (0x02 | 0x04)) & 0x01 );
    fax_get_pages( 0, &pagenum, spool_in, 0, 0, 0660 );
    lprintf( 5, "fax receiver: hangup & end" );
    lprintf( 2, "fax caller=%s, name='%s', id='%s', +FHNG=%03d, pages=%d, time=%ds",
     CallerId, CallName, fax_remote_id, fax_hangup_code, pagenum,
                   ( time(((void *)0))-call_start ));
    voice_fax_hangup_code = fax_hangup_code;
    voice_fax_remote_id = fax_remote_id;
    voice_fax_files = fax_file_names;
    return;
}

variable_types:
switchbd
unsigned int

variable_types: pagenum int

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