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


repo: Distrotech/mgetty

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

return_type: void


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 )
{
if ( log_fp && strcmp(a2, &log_path) )
{
lprintf(4u, "logging continues in file %s", a2);
log_close();
}
strncpy(&log_path, a2, 0x3FFuLL);
byte_C3F = 0;
if ( strlen(a2) > 0x3FF )
lprintf(0, "internal error: log file path too long!");
}
if ( a3 )
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 )
{
if ( log_fp && strcmp(a2, &log_path) )
{
func4(4u, "logging continues in file %s", a2);
func1();
}
strncpy(&log_path, a2, 0x3FFuLL);
byte_C3F = 0;
if ( strlen(a2) > 0x3FF )
func4(0, "internal error: log file path too long!");
}
if ( a3 )
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

return_type: int


lputs

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

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; // ebx

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; // er13
char *v3; // rax
const char *v4; // rdx
__int64 v5; // rbx
const char *v6; // rbp
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;
do
{
lprintf(6LL, "match: '%s'", v4);
v6 = a2[v5];
v7 = strlen(v6);
if ( v2 >= v7 && !strncmp(v6, &s[v2 - v7], v7) )
return (unsigned int)(v5 + 1);
v4 = a2[++v5];
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, const char **a2)
{
int v2; // er13
char *v3; // rax
const char *v4; // rdx
__int64 v5; // rbx
const char *v6; // rbp
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;
do
{
lprintf(6LL, "match: '%s'", v4);
v6 = a2[v5];
v7 = strlen(v6);
if ( v2 >= v7 && !strncmp(v6, &s[v2 - v7], v7) )
return (unsigned int)(v5 + 1);
v4 = a2[++v5];
}
while ( v4 );
return 0LL;
}

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(char *s, const char **a2)
{
char *v2; // rbx
char v3; // r12
const unsigned __int16 *v4; // rdx
char v5; // al
const unsigned __int16 **v6; // r14
char *i; // rbp
__int64 result; // rax
char *v9; // rdi
char v10; // al

v2 = s;
lprintf(4LL, "ELSA: '%s'", s);
v3 = *s;
if ( *s )
{
v4 = *_ctype_b_loc();
v5 = v3;
do
{
if ( (v4[v5] & 0x800) != 0 )
break;
v5 = *++v2;
}
while ( *v2 );
}
v6 = _ctype_b_loc();
for ( i = v2; ((*v6)[*i] & 0x800) != 0; ++i )
;
if ( *i )
{
*i = 0;
CallerId = safedup(v2);
v9 = i + 1;
v10 = i[1];
if ( v10 )
{
do
{
if ( ((*v6)[v10] & 0x800) != 0 )
break;
v10 = *++v9;
}
while ( *v9 );
}
result = find_msn(v9, a2);
}
else if ( v3 == 47 )
{
result = find_msn(v2, a2);
}
else
{
CallerId = safedup(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, const char **a2)
{
char *v2; // rbx
char v3; // r12
const unsigned __int16 *v4; // rdx
char v5; // al
const unsigned __int16 **v6; // r14
char *i; // rbp
__int64 result; // rax
char *v9; // rdi
char v10; // al

v2 = s;
lprintf(4LL, "ELSA: '%s'", s);
v3 = *s;
if ( *s )
{
v4 = *_ctype_b_loc();
v5 = v3;
do
{
if ( (v4[v5] & 0x800) != 0 )
break;
v5 = *++v2;
}
while ( *v2 );
}
v6 = _ctype_b_loc();
for ( i = v2; ((*v6)[*i] & 0x800) != 0; ++i )
;
if ( *i )
{
*i = 0;
CallerId = func1(v2);
v9 = i + 1;
v10 = i[1];
if ( v10 )
{
do
{
if ( ((*v6)[v10] & 0x800) != 0 )
break;
v10 = *++v9;
}
while ( *v9 );
}
result = func3(v9, a2);
}
else if ( v3 == 47 )
{
result = func3(v2, a2);
}
else
{
CallerId = func1(v2);
result = 0LL;
}
return result;
}

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
int v3; // eax
int v4; // ebx
const char *v5; // rsi
__int64 result; // rax

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

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

v2 = *_ctype_b_loc();
while ( (v2[*nptr] & 0x2000) != 0 || *nptr == 61 )
++nptr;
v3 = atoi(nptr);
if ( !drox_count || (v4 = 0, v5 = "<short>", v3 > 9) )
{
v4 = 1;
v5 = "<long>";
}
lputs(5LL, v5);
result = v4 | (unsigned int)(2 * drox_bitstring);
drox_bitstring = v4 | (2 * drox_bitstring);
++drox_count;
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, unsigned int *a6)
{
char v7; // r13
char v8; // r15
int v9; // ebx
unsigned int v10; // ebp
char v12; // bp
bool v13; // zf
const unsigned __int16 *v14; // rax
char *i; // r14
const char **v16; // r14
const char *v17; // rbp
int v18; // eax
char v19; // r15
unsigned __int16 v24; // [rsp+1Eh] [rbp-25Ah]
char v26; // [rsp+3Fh] [rbp-239h] BYREF
char s1[4]; // [rsp+40h] [rbp-238h] BYREF
char s[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;
v7 = virtual_ring;
if ( virtual_ring )
{
LABEL_8:
lputs(5LL, "``found''");
v10 = 0;
goto LABEL_15;
}
v8 = virtual_ring;
v9 = 0;
while ( 1 )
{
if ( (int)mdm_read_byte(a1, &v26) <= 0 )
{
if ( chat_has_timeout )
lprintf(3LL, "wfr: timeout waiting for RING");
else
lprintf(1LL, "wfr: error in read()");
v10 = -1;
if ( a5 )
*a5 = 0;
goto LABEL_15;
}
lputc(5LL, (unsigned int)v26);
if ( v8 )
{
switch ( v26 )
{
case 'H':
case 'P':
case 'h':
case 'p':
case 'r':
*a6 = -v26;
v10 = 0;
break;
case 'R':
*a6 = 0;
v10 = 0;
break;
default:
goto LABEL_20;
}
goto LABEL_15;
}
v12 = v26;
if ( v26 == 16 )
{
v8 = 1;
}
else
{
LABEL_20:
v12 = v26;
if ( v26 == 13 || (v8 = v7, v26 == 10) )
{
if ( v9 )
{
s1[v9] = 0;
cndfind(s1);
if ( !memcmp(s1, "FM:", 3uLL) || !memcmp(s1, "TO:", 3uLL) )
{
*a6 = ring_handle_ZyXEL(s1, a2);
v10 = 0;
goto LABEL_15;
}
v10 = drox_count | (memcmp(s1, "NMBR", 4uLL) != 0);
if ( !v10 )
goto LABEL_15;
if ( !memcmp(s1, "DRON", 4uLL) || !memcmp(s1, "DROF", 4uLL) )
{
ring_handle_DROx(s);
v8 = v7;
v9 = 0;
}
else
{
v13 = memcmp(s1, "RING", 4uLL) == 0;
v10 = !v13;
if ( v13 )
{
v14 = *_ctype_b_loc();
for ( i = s; ; ++i )
{
v19 = *i;
v24 = v14[*i];
if ( (v24 & 0x2000) == 0 )
break;
}
switch ( v19 )
{
case 0:
goto LABEL_15;
case 59:
LABEL_54:
*a6 = ring_handle_ELSA(i, a2);
goto LABEL_15;
case 58:
*a6 = ring_handle_ZoomMX((__int64)i);
goto LABEL_15;
}
if ( strlen(i) > 1 )
goto LABEL_54;
if ( (v24 & 0x800) != 0 )
{
*a6 = v19 - 48;
goto LABEL_15;
}
if ( (v24 & 0x400) != 0 )
{
*a6 = (*_ctype_tolower_loc())[v19] - 96;
goto LABEL_15;
}
v8 = v7;
}
else
{
lprintf(5LL, "got: ");
v8 = v7;
v9 = 0;
}
}
}
else
{
v8 = v7;
}
goto LABEL_4;
}
}
if ( v9 )
break;
if ( ((*_ctype_b_loc())[v12] & 0x2000) == 0 )
goto LABEL_33;
LABEL_4:
if ( virtual_ring )
goto LABEL_8;
}
if ( v9 <= 8189 )
LABEL_33:
s1[v9++] = v12;
v16 = a4;
if ( !a4 )
goto LABEL_4;
v17 = *a4;
if ( !*a4 )
goto LABEL_4;
while ( 1 )
{
v18 = strlen(v17);
if ( v9 == v18 && !memcmp(s1, v17, v18) )
break;
v16 += 2;
v17 = *v16;
if ( !*v16 )
goto LABEL_4;
}
lprintf(4LL, "wfr: found action string: ``%s''", v17);
*a5 = *((_DWORD *)v16 + 2);
v10 = -1;
LABEL_15:
alarm(0);
if ( drox_count > 0 )
{
lprintf(5LL, "wfr: DRON/DROF cadence: %x", (unsigned int)drox_bitstring);
*a6 = drox_bitstring;
drox_count = 0;
drox_bitstring = 0;
}
lprintf(5LL, "wfr: rc=%d, drn=%d", v10, *a6);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const char **a2, unsigned int a3, const char **a4, _DWORD *a5, unsigned int *a6)
{
char v7; // r13
char v8; // r15
int v9; // ebx
unsigned int v10; // ebp
char v12; // bp
bool v13; // zf
const unsigned __int16 *v14; // rax
char *i; // r14
const char **v16; // r14
const char *v17; // rbp
int v18; // eax
char v19; // r15
unsigned __int16 v24; // [rsp+1Eh] [rbp-25Ah]
char v26; // [rsp+3Fh] [rbp-239h] BYREF
char s1[4]; // [rsp+40h] [rbp-238h] BYREF
char s[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;
v7 = virtual_ring;
if ( virtual_ring )
{
LABEL_8:
lputs(5LL, "``found''");
v10 = 0;
goto LABEL_15;
}
v8 = virtual_ring;
v9 = 0;
while ( 1 )
{
if ( (int)mdm_read_byte(a1, &v26) <= 0 )
{
if ( chat_has_timeout )
lprintf(3LL, "wfr: timeout waiting for RING");
else
lprintf(1LL, "wfr: error in read()");
v10 = -1;
if ( a5 )
*a5 = 0;
goto LABEL_15;
}
lputc(5LL, (unsigned int)v26);
if ( v8 )
{
switch ( v26 )
{
case 'H':
case 'P':
case 'h':
case 'p':
case 'r':
*a6 = -v26;
v10 = 0;
break;
case 'R':
*a6 = 0;
v10 = 0;
break;
default:
goto LABEL_20;
}
goto LABEL_15;
}
v12 = v26;
if ( v26 == 16 )
{
v8 = 1;
}
else
{
LABEL_20:
v12 = v26;
if ( v26 == 13 || (v8 = v7, v26 == 10) )
{
if ( v9 )
{
s1[v9] = 0;
cndfind(s1);
if ( !memcmp(s1, "FM:", 3uLL) || !memcmp(s1, "TO:", 3uLL) )
{
*a6 = func4(s1, a2);
v10 = 0;
goto LABEL_15;
}
v10 = drox_count | (memcmp(s1, "NMBR", 4uLL) != 0);
if ( !v10 )
goto LABEL_15;
if ( !memcmp(s1, "DRON", 4uLL) || !memcmp(s1, "DROF", 4uLL) )
{
func6(s);
v8 = v7;
v9 = 0;
}
else
{
v13 = memcmp(s1, "RING", 4uLL) == 0;
v10 = !v13;
if ( v13 )
{
v14 = *_ctype_b_loc();
for ( i = s; ; ++i )
{
v19 = *i;
v24 = v14[*i];
if ( (v24 & 0x2000) == 0 )
break;
}
switch ( v19 )
{
case 0:
goto LABEL_15;
case 59:
LABEL_54:
*a6 = func5(i, a2);
goto LABEL_15;
case 58:
*a6 = func2((__int64)i);
goto LABEL_15;
}
if ( strlen(i) > 1 )
goto LABEL_54;
if ( (v24 & 0x800) != 0 )
{
*a6 = v19 - 48;
goto LABEL_15;
}
if ( (v24 & 0x400) != 0 )
{
*a6 = (*_ctype_tolower_loc())[v19] - 96;
goto LABEL_15;
}
v8 = v7;
}
else
{
lprintf(5LL, "got: ");
v8 = v7;
v9 = 0;
}
}
}
else
{
v8 = v7;
}
goto LABEL_4;
}
}
if ( v9 )
break;
if ( ((*_ctype_b_loc())[v12] & 0x2000) == 0 )
goto LABEL_33;
LABEL_4:
if ( virtual_ring )
goto LABEL_8;
}
if ( v9 <= 8189 )
LABEL_33:
s1[v9++] = v12;
v16 = a4;
if ( !a4 )
goto LABEL_4;
v17 = *a4;
if ( !*a4 )
goto LABEL_4;
while ( 1 )
{
v18 = strlen(v17);
if ( v9 == v18 && !memcmp(s1, v17, v18) )
break;
v16 += 2;
v17 = *v16;
if ( !*v16 )
goto LABEL_4;
}
lprintf(4LL, "wfr: found action string: ``%s''", v17);
*a5 = *((_DWORD *)v16 + 2);
v10 = -1;
LABEL_15:
alarm(0);
if ( drox_count > 0 )
{
lprintf(5LL, "wfr: DRON/DROF cadence: %x", (unsigned int)drox_bitstring);
*a6 = drox_bitstring;
drox_count = 0;
drox_bitstring = 0;
}
lprintf(5LL, "wfr: rc=%d, drn=%d", v10, *a6);
return v10;
}

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: timeout 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(_QWORD *a1, unsigned int a2, int a3)
{
_QWORD *v3; // rbx
time_t v5; // r14
unsigned int v6; // er15
unsigned int v7; // ebp
int v8; // er12
time_t v9; // rax
__int64 v11; // rcx
unsigned int v12; // [rsp+Ch] [rbp-7Ch] BYREF
char v13[120]; // [rsp+10h] [rbp-78h] BYREF

v3 = 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 )
{
v6 = 0;
v7 = 0;
goto LABEL_11;
}
if ( !*a1 )
{
v6 = 0;
v7 = 0;
goto LABEL_11;
}
v6 = 0;
v7 = 0;
v8 = 0;
while ( 2 )
{
++v7;
v11 = 2 * (unsigned int)(v3[1] == 0LL);
fax_page_tx_status = -1;
if ( (unsigned int)fax_send_page(*v3, &v12, v13, v11, 0LL) == -1 )
goto LABEL_11;
switch ( fax_page_tx_status )
{
case 0xFFFFFFFF:
lprintf(3LL, "fpts:-1");
goto LABEL_15;
case 1:
goto LABEL_15;
case 2:
if ( a3 <= 0 )
{
lprintf(3LL, "WARNING: RTN ignored");
LABEL_15:
if ( fax_hangup && fax_hangup_code )
goto LABEL_11;
++v3;
v8 = 0;
LABEL_17:
if ( !*v3 )
goto LABEL_11;
continue;
}
if ( a3 > ++v8 )
{
++v6;
goto LABEL_17;
}
lprintf(3LL, "ERROR: too many retries - aborting send");
fax_hangup_code = -1;
fax_hangup = 1;
LABEL_11:
v9 = time(0LL);
lprintf(2LL, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d", fax_hangup_code, v9 - v5, v7, v6, v12);
voice_fax_hangup_code = fax_hangup_code;
voice_fax_remote_id = &fax_remote_id;
voice_fax_files = 0LL;
return 0LL;
case 3:
lprintf(3LL, "WARNING: RTP: page good, but retrain requested");
goto LABEL_15;
case 4:
case 5:
lprintf(3LL, "WARNING: procedure interrupt requested - don't know how to handle it");
goto LABEL_15;
default:
lprintf(3LL, "WARNING: invalid code: +FPTS:%d", fax_page_tx_status);
goto LABEL_15;
}
}
}

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

v3 = 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 )
{
v6 = 0;
v7 = 0;
goto LABEL_11;
}
if ( !*a1 )
{
v6 = 0;
v7 = 0;
goto LABEL_11;
}
v6 = 0;
v7 = 0;
v8 = 0;
while ( 2 )
{
++v7;
v11 = 2 * (unsigned int)(v3[1] == 0LL);
fax_page_tx_status = -1;
if ( (unsigned int)fax_send_page(*v3, &v12, v13, v11, 0LL) == -1 )
goto LABEL_11;
switch ( fax_page_tx_status )
{
case 0xFFFFFFFF:
lprintf(3LL, "fpts:-1");
goto LABEL_15;
case 1:
goto LABEL_15;
case 2:
if ( a3 <= 0 )
{
lprintf(3LL, "WARNING: RTN ignored");
LABEL_15:
if ( fax_hangup && fax_hangup_code )
goto LABEL_11;
++v3;
v8 = 0;
LABEL_17:
if ( !*v3 )
goto LABEL_11;
continue;
}
if ( a3 > ++v8 )
{
++v6;
goto LABEL_17;
}
lprintf(3LL, "ERROR: too many retries - aborting send");
fax_hangup_code = -1;
fax_hangup = 1;
LABEL_11:
v9 = time(0LL);
lprintf(2LL, "+FHS:%02d, time=%ds, pages=%d(+%d), bytes=%d", fax_hangup_code, v9 - v5, v7, v6, v12);
voice_fax_hangup_code = fax_hangup_code;
voice_fax_remote_id = &fax_remote_id;
voice_fax_files = 0LL;
return 0LL;
case 3:
lprintf(3LL, "WARNING: RTP: page good, but retrain requested");
goto LABEL_15;
case 4:
case 5:
lprintf(3LL, "WARNING: procedure interrupt requested - don't know how to handle it");
goto LABEL_15;
default:
lprintf(3LL, "WARNING: invalid code: +FPTS:%d", fax_page_tx_status);
goto LABEL_15;
}
}
}

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
_BYTE v5[60]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v6[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v6[0] = 0;
faxlib_init();
lprintf(5LL, "fax receiver: entry");
tio_get(0LL, v5);
if ( a2 )
{
tio_set_speed(v5, a2);
tio_mode_raw(v5);
tio_set(0LL, v5);
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_9:
fax_hangup = 1;
goto LABEL_3;
}
tio_mode_raw(v5);
tio_set(0LL, v5);
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_9;
}
LABEL_3:
tio_set_flow_control(0LL, v5, 3LL);
tio_set(0LL, v5);
fax_set_flowcontrol(0LL, 1LL);
fax_get_pages(0LL, v6, 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,
v6[0],
v3 - v2);
voice_fax_hangup_code = fax_hangup_code;
voice_fax_remote_id = &fax_remote_id;
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
_BYTE v5[60]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v6[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v6[0] = 0;
faxlib_init();
lprintf(5LL, "fax receiver: entry");
tio_get(0LL, v5);
if ( a2 )
{
tio_set_speed(v5, a2);
tio_mode_raw(v5);
tio_set(0LL, v5);
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_9:
fax_hangup = 1;
goto LABEL_3;
}
tio_mode_raw(v5);
tio_set(0LL, v5);
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_9;
}
LABEL_3:
tio_set_flow_control(0LL, v5, 3LL);
tio_set(0LL, v5);
fax_set_flowcontrol(0LL, 1LL);
fax_get_pages(0LL, v6, 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,
v6[0],
v3 - v2);
voice_fax_hangup_code = fax_hangup_code;
voice_fax_remote_id = &fax_remote_id;
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; }


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

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

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

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

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

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

variable_types: result int


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

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

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

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

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

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

variable_types: device int


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

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

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

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

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

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

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *

variable_types:
buffer
char [-1]


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

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

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

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

original_code:
static int ZyXEL_2864_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL 2864 voice modem");
     if (voice_command("ATS48.5=1", "OK") != (0x1000))
          lprintf(3, "couldn't set IS 101 compatible mode");
     if (voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     if (voice_command("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDD=%d,%d", (int)cvd.dtmf_threshold.d.i *
      15 / 100, (int)cvd.dtmf_len.d.i / 5);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting DTMF preferences didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int ZyXEL_2864_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing ZyXEL 2864 voice modem");
     if (voice_command("ATS48.5=1", "OK") != (0x1000))
          lprintf(3, "couldn't set IS 101 compatible mode");
     if (voice_command("ATS40.3=1 S40.4=1 S40.5=1 S40.6=1", "OK") !=
      (0x1000))
          lprintf(3, "couldn't initialize distinctive RING");
     if (voice_command("AT+VIT=100", "OK") != (0x1000))
          lprintf(3, "voice init failed, continuing");
     sprintf(buffer, "AT+VDD=%d,%d", (int)cvd.dtmf_threshold.d.i *
      15 / 100, (int)cvd.dtmf_len.d.i / 5);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting DTMF preferences didn't work");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      31 / 100, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 50;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 50;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i * 144 / 100 + 56);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     voice_modem_state = (0x0001);
     return((0));
     }


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

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

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

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

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

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


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

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

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

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

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

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

variable_types: Dn short

variable_types: c char

return_type: char


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

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

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

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

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

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

variable_types: b short

return_type: short


match

decompiled_code:
_BOOL8 __fastcall match(char *s1, char *s2)
{
int v2; // ebp
int v3; // er13
_BOOL8 result; // rax
int v5; // ebp
int v6; // er13
__int64 v7; // r14
int v8; // ebp
int v9; // ebp

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

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s1, char *s2)
{
int v2; // ebp
int v3; // er13
_BOOL8 result; // rax
int v5; // ebp
int v6; // er13
__int64 v7; // r14
int v8; // ebp
int v9; // ebp

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

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

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

variable_types:
user
char *

variable_types:
key
char *

variable_types: lk int

variable_types: lu int

variable_types: i int


decompiled_code:
__int64 setup_environment()
{
if ( *CallerId )
set_env_var("CALLER_ID");
if ( *CallName )
set_env_var("CALLER_NAME");
if ( *CalledNr )
set_env_var("CALLED_ID");
set_env_var("CONNECT");
return set_env_var("DEVICE");
}

canonical_decompiled_code:
__int64 func1()
{
if ( *CallerId )
set_env_var("CALLER_ID");
if ( *CallName )
set_env_var("CALLER_NAME");
if ( *CalledNr )
set_env_var("CALLED_ID");
set_env_var("CONNECT");
return set_env_var("DEVICE");
}

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

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


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

variable_types:
s
short *

variable_types:
so
short *

variable_types: mp short

variable_types: msp short

variable_types: lsp short

variable_types: SO short

variable_types: ltmp long

variable_types:
utmp
unsigned long

variable_types: k int


decompiled_code:
void __fastcall tree_add_node(__int64 a1, int *a2, int a3, int a4)
{
int v8; // esi
int v9; // edx
int v10; // er14
_DWORD *v11; // rdi
_DWORD *v12; // rax

if ( a4 > 8 )
{
v10 = (unsigned __int8)a3;
v11 = *(_DWORD **)(a1 + 8LL * (unsigned __int8)a3 + 8);
if ( v11 )
{
if ( *v11 )
{
fwrite("internal table setup error\n", 1uLL, 0x1BuLL, stderr);
exit(6);
}
}
else
{
v12 = calloc(1uLL, 0x808uLL);
v11 = v12;
*(_QWORD *)(a1 + 8LL * v10 + 8) = v12;
if ( !v12 )
{
perror("malloc 3");
exit(11);
}
*v12 = 0;
}
tree_add_node(v11, a2, (unsigned int)(a3 >> 8), (unsigned int)(a4 - 8));
}
else
{
*a2 = a4;
if ( a4 == 8 )
{
*(_QWORD *)(a1 + 8LL * a3 + 8) = a2;
}
else
{
v8 = 1 << (8 - a4);
v9 = 0;
if ( v8 > 0 )
{
do
*(_QWORD *)(a1 + 8LL * (a3 + (v9++ << a4)) + 8) = a2;
while ( v9 != v8 );
}
}
}
}

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

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

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


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

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

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

variable_types:
c
struct g3code { int nr_bits; } *


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

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

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

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

variable_types: reverse int


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

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types: signo int


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

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

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

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

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

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

variable_types: r int


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

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

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

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

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

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

variable_types: fd int


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

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

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

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

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

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

variable_types:
dev
char *

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