decompiled_code:
__int64 __fastcall g3_send_file(__int64 (__fastcall *a1)(char *, __int64), unsigned int a2, int a3, int a4, unsigned int a5, int a6)
{
const char *v8; // rdx
const char *v9; // r8
int v10; // ebx
int v11; // ebp
unsigned int v12; // er15
signed int v13; // er13
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rsi
char v17; // al
int v18; // er12
unsigned int v20; // er9
char *v21; // rdx
bool v23; // [rsp+1Fh] [rbp-869h]
unsigned int v25; // [rsp+2Ch] [rbp-85Ch]
char v26; // [rsp+3Fh] [rbp-849h] BYREF
char v27[1024]; // [rsp+40h] [rbp-848h] BYREF
char buf[1096]; // [rsp+440h] [rbp-448h] BYREF

if ( g3_rf_fine != -1 && g3_rf_fine != a6 )
{
v8 = "fine";
v9 = "normal";
if ( g3_rf_fine )
v9 = "fine";
if ( !a6 )
v8 = "normal";
fprintf(stderr, "WARNING: sending in %s mode, fax data is %s mode\n", v8, v9);
lprintf(3LL, "resolution mismatch");
}
if ( a5 > 0x201 )
{
*_errno_location() = 22;
lprintf(1LL, "g3_send_file: too much padding requested, pad_bytes=%d, CHUNK=%d", a5, 1024LL);
fwrite("g3_send_file: internal error (pad_bytes)\n", 1uLL, 0x29uLL, stderr);
return 0xFFFFFFFFLL;
}
v23 = a4 != 0;
v10 = a1(v27, 1024LL);
v11 = 0;
v12 = 0;
v25 = -1;
v13 = a5;
v14 = 0LL;
v15 = 0LL;
while ( 1 )
{
LODWORD(v16) = (unsigned __int8)v27[v14];
v18 = v14 + 1;
++v13;
v26 = v16;
if ( (_BYTE)v16 )
{
v16 = (int)v16;
if ( *((unsigned __int8 *)&bits_left + (int)v16) + v11 > 10 )
{
if ( (int)a5 > v13 )
{
v20 = a5 - v13;
if ( (int)(a5 - v13) > 0 )
{
v21 = &buf[v15];
if ( v20 < 8 )
{
if ( (v20 & 4) != 0 )
{
*(_DWORD *)v21 = 0;
*(_DWORD *)&v21[v20 - 4] = 0;
}
else if ( v20 )
{
*v21 = 0;
if ( (v20 & 2) != 0 )
*(_WORD *)&v21[v20 - 2] = 0;
}
}
else
{
*(_QWORD *)v21 = 0LL;
*(_QWORD *)&v21[v20 - 8] = 0LL;
memset(
(void *)((unsigned __int64)(v21 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * ((v20 + (_DWORD)v21 - (((_DWORD)v21 + 8) & 0xFFFFFFF8)) >> 3));
}
v12 += v20;
v15 = (int)v12;
}
}
++v25;
v13 = 0;
}
v11 = (unsigned __int8)bits_right[(int)v16];
}
else
{
v11 += 8;
v16 = (int)v16;
}
v17 = *((_BYTE *)&fax_send_swaptable + v16);
buf[v15] = v17;
if ( v17 == 16 && v23 )
buf[++v12] = 16;
++v12;
if ( v10 <= v18 )
{
v10 = a1(v27, 1024LL);
if ( v10 < 0 )
goto LABEL_32;
v18 = 0;
}
v15 = (int)v12;
if ( (int)v12 < (unsigned __int64)(1024LL - (int)a5) && v10 )
goto LABEL_23;
if ( v12 != write(a2, buf, (int)v12) )
break;
lprintf(6LL, "write %d", v12);
if ( a3 && (unsigned __int8)check_for_input(a2) )
{
lprintf(5LL, "input: got ");
while ( read(a2, &v26, 1uLL) == 1 )
{
lputc(5LL, (unsigned int)v26);
if ( !(unsigned __int8)check_for_input(a2) )
goto LABEL_21;
}
lprintf(1LL, "read failed");
if ( !v10 )
goto LABEL_32;
}
else
{
LABEL_21:
if ( !v10 )
goto LABEL_32;
}
v12 = 0;
v15 = 0LL;
LABEL_23:
v14 = v18;
}
lprintf(1LL, "fax1_send_page: can't write %d bytes", v12);
LABEL_32:
g3_close();
lprintf(5LL, "end of page, %d lines sent", v25);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 (__fastcall *a1)(char *, __int64), unsigned int a2, int a3, int a4, unsigned int a5, int a6)
{
const char *v8; // rdx
const char *v9; // r8
int v10; // ebx
int v11; // ebp
unsigned int v12; // er15
signed int v13; // er13
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rsi
char v17; // al
int v18; // er12
unsigned int v20; // er9
char *v21; // rdx
bool v23; // [rsp+1Fh] [rbp-869h]
unsigned int v25; // [rsp+2Ch] [rbp-85Ch]
char v26; // [rsp+3Fh] [rbp-849h] BYREF
char v27[1024]; // [rsp+40h] [rbp-848h] BYREF
char buf[1096]; // [rsp+440h] [rbp-448h] BYREF

if ( g3_rf_fine != -1 && g3_rf_fine != a6 )
{
v8 = "fine";
v9 = "normal";
if ( g3_rf_fine )
v9 = "fine";
if ( !a6 )
v8 = "normal";
fprintf(stderr, "WARNING: sending in %s mode, fax data is %s mode\n", v8, v9);
lprintf(3LL, "resolution mismatch");
}
if ( a5 > 0x201 )
{
*_errno_location() = 22;
lprintf(1LL, "g3_send_file: too much padding requested, pad_bytes=%d, CHUNK=%d", a5, 1024LL);
fwrite("g3_send_file: internal error (pad_bytes)\n", 1uLL, 0x29uLL, stderr);
return 0xFFFFFFFFLL;
}
v23 = a4 != 0;
v10 = a1(v27, 1024LL);
v11 = 0;
v12 = 0;
v25 = -1;
v13 = a5;
v14 = 0LL;
v15 = 0LL;
while ( 1 )
{
LODWORD(v16) = (unsigned __int8)v27[v14];
v18 = v14 + 1;
++v13;
v26 = v16;
if ( (_BYTE)v16 )
{
v16 = (int)v16;
if ( *((unsigned __int8 *)&bits_left + (int)v16) + v11 > 10 )
{
if ( (int)a5 > v13 )
{
v20 = a5 - v13;
if ( (int)(a5 - v13) > 0 )
{
v21 = &buf[v15];
if ( v20 < 8 )
{
if ( (v20 & 4) != 0 )
{
*(_DWORD *)v21 = 0;
*(_DWORD *)&v21[v20 - 4] = 0;
}
else if ( v20 )
{
*v21 = 0;
if ( (v20 & 2) != 0 )
*(_WORD *)&v21[v20 - 2] = 0;
}
}
else
{
*(_QWORD *)v21 = 0LL;
*(_QWORD *)&v21[v20 - 8] = 0LL;
memset(
(void *)((unsigned __int64)(v21 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * ((v20 + (_DWORD)v21 - (((_DWORD)v21 + 8) & 0xFFFFFFF8)) >> 3));
}
v12 += v20;
v15 = (int)v12;
}
}
++v25;
v13 = 0;
}
v11 = (unsigned __int8)bits_right[(int)v16];
}
else
{
v11 += 8;
v16 = (int)v16;
}
v17 = *((_BYTE *)&fax_send_swaptable + v16);
buf[v15] = v17;
if ( v17 == 16 && v23 )
buf[++v12] = 16;
++v12;
if ( v10 <= v18 )
{
v10 = a1(v27, 1024LL);
if ( v10 < 0 )
goto LABEL_32;
v18 = 0;
}
v15 = (int)v12;
if ( (int)v12 < (unsigned __int64)(1024LL - (int)a5) && v10 )
goto LABEL_23;
if ( v12 != write(a2, buf, (int)v12) )
break;
lprintf(6LL, "write %d", v12);
if ( a3 && (unsigned __int8)check_for_input(a2) )
{
lprintf(5LL, "input: got ");
while ( read(a2, &v26, 1uLL) == 1 )
{
lputc(5LL, (unsigned int)v26);
if ( !(unsigned __int8)check_for_input(a2) )
goto LABEL_21;
}
lprintf(1LL, "read failed");
if ( !v10 )
goto LABEL_32;
}
else
{
LABEL_21:
if ( !v10 )
goto LABEL_32;
}
v12 = 0;
v15 = 0LL;
LABEL_23:
v14 = v18;
}
lprintf(1LL, "fax1_send_page: can't write %d bytes", v12);
LABEL_32:
func2();
lprintf(5LL, "end of page, %d lines sent", v25);
return 0LL;
}

original_code:
int g3_send_file (in_func_t * in_func,int out_fd,int is_device,int escape_dle,int pad_bytes,int fax_res)
{
uch rbuf[1024], wbuf[1024 +2];
int r, w, r_num;
uch r_ch;
int bytes_cur;
int have_0bits;
int lines_seen=-1;
    if ( g3_rf_fine != -1 && fax_res != g3_rf_fine )
    {
 fprintf( stderr, "WARNING: sending in %s mode, fax data is %s mode\n",
   fax_res? "fine" : "normal",
   g3_rf_fine? "fine" : "normal" );
 lprintf( 3, "resolution mismatch" );
    }
    if ( pad_bytes > sizeof(wbuf)/2 )
    {
 (*__errno_location ())=22;
 lprintf( 1, "g3_send_file: too much padding requested, pad_bytes=%d, CHUNK=%d", pad_bytes, 1024 );
 fprintf( stderr, "g3_send_file: internal error (pad_bytes)\n" );
 return -1;
    }
    if ( pad_bytes < 0 ) pad_bytes = 0;
    r_num = in_func( rbuf, sizeof(rbuf) );
    r=0;
    w=0;
    bytes_cur=pad_bytes;
    have_0bits=0;
    do
    {
 r_ch = (uch)rbuf[r++];
 bytes_cur++;
 if ( r_ch == 0 )
     { have_0bits += 8; }
 else
 {
     if ( have_0bits + bits_left[r_ch] >= 11 )
     {
  int need = (bytes_cur<pad_bytes)? pad_bytes-bytes_cur: 0;
  while( need>0 )
      { wbuf[w++] = 0; need--; }
  bytes_cur=0;
  lines_seen++;
     }
     have_0bits = bits_right[r_ch];
 }
 wbuf[w] = fax_send_swaptable[ r_ch ];
 if ( escape_dle && wbuf[w] == 020 ) wbuf[++w] = 020;
 w++;
        if ( r >= r_num )
 {
     r_num = in_func( rbuf, sizeof(rbuf) );
     if ( r_num < 0 )
  { break; }
     r = 0;
 }
 if ( ( w >= (sizeof(wbuf)-2 - pad_bytes ) ) ||
      (r_num == 0) )
 {
     if ( w != write( out_fd, wbuf, w ) )
     {
         lprintf( 1, "fax1_send_page: can't write %d bytes", w );
  break;
     }
     lprintf( 6, "write %d", w );
     w=0;
     if ( is_device && check_for_input( out_fd ) )
     {
  lprintf( 5, "input: got " );
  do
  {
      if ( read( out_fd, &r_ch, 1 ) != 1 )
      {
   lprintf( 1, "read failed" );
   break;
      }
      else
   lputc( 5, r_ch );
  }
  while ( check_for_input( out_fd ) );
     }
 }
    }
    while(r_num>0);
    g3_close();
    lprintf( 5, "end of page, %d lines sent", lines_seen );
    return 0;
}

canonical_original_code:
int g3_send_file(int (*in_func)(char *, int), int out_fd, int is_device, int escape_dle, int pad_bytes, int fax_res)
{
unsigned char rbuf[1024]; unsigned char wbuf[-1];
int r; int w; int r_num;
unsigned char r_ch;
int bytes_cur;
int have_0bits;
int lines_seen = -1;
    if ( g3_rf_fine != -1 && fax_res != g3_rf_fine )
    {
 fprintf( stderr, "WARNING: sending in %s mode, fax data is %s mode\n",
   fax_res? "fine" : "normal",
   g3_rf_fine? "fine" : "normal" );
 lprintf( 3, "resolution mismatch" );
    }
    if ( pad_bytes > sizeof(wbuf)/2 )
    {
 (*__errno_location ())=22;
 lprintf( 1, "g3_send_file: too much padding requested, pad_bytes=%d, CHUNK=%d", pad_bytes, 1024 );
 fprintf( stderr, "g3_send_file: internal error (pad_bytes)\n" );
 return -1;
    }
    if ( pad_bytes < 0 ) pad_bytes = 0;
    r_num = in_func( rbuf, sizeof(rbuf) );
    r=0;
    w=0;
    bytes_cur=pad_bytes;
    have_0bits=0;
    do
    {
 r_ch = (unsigned char)rbuf[r++];
 bytes_cur++;
 if ( r_ch == 0 )
     { have_0bits += 8; }
 else
 {
     if ( have_0bits + bits_left[r_ch] >= 11 )
     {
  int need = (bytes_cur<pad_bytes)? pad_bytes-bytes_cur: 0;
  while( need>0 )
      { wbuf[w++] = 0; need--; }
  bytes_cur=0;
  lines_seen++;
     }
     have_0bits = bits_right[r_ch];
 }
 wbuf[w] = fax_send_swaptable[ r_ch ];
 if ( escape_dle && wbuf[w] == 020 ) wbuf[++w] = 020;
 w++;
        if ( r >= r_num )
 {
     r_num = in_func( rbuf, sizeof(rbuf) );
     if ( r_num < 0 )
  { break; }
     r = 0;
 }
 if ( ( w >= (sizeof(wbuf)-2 - pad_bytes ) ) ||
      (r_num == 0) )
 {
     if ( w != write( out_fd, wbuf, w ) )
     {
         lprintf( 1, "fax1_send_page: can't write %d bytes", w );
  break;
     }
     lprintf( 6, "write %d", w );
     w=0;
     if ( is_device && check_for_input( out_fd ) )
     {
  lprintf( 5, "input: got " );
  do
  {
      if ( read( out_fd, &r_ch, 1 ) != 1 )
      {
   lprintf( 1, "read failed" );
   break;
      }
      else
   lputc( 5, r_ch );
  }
  while ( check_for_input( out_fd ) );
     }
 }
    }
    while(r_num>0);
    g3_close();
    lprintf( 5, "end of page, %d lines sent", lines_seen );
    return 0;
}

variable_types:
rbuf
unsigned char [1024]

variable_types:
wbuf
unsigned char [-1]

variable_types: w int

variable_types: need int


repo: Distrotech/mgetty

decompiled_code:
const char *__fastcall get_basename(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( !a1 )
return 0LL;
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( !a1 )
return 0LL;
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
char * get_basename (char * s)
{
char * p;
    if ( s == ((void *)0) ) return ((void *)0);
    p = strrchr( s, '/' );
    return ( p == ((void *)0) ) ? s: p+1;
}

canonical_original_code:
char *get_basename(char *s)
{
char *p;
    if ( s == ((void *)0) ) return ((void *)0);
    p = strrchr( s, '/' );
    return ( p == ((void *)0) ) ? s: p+1;
}

variable_types:
s
char *

variable_types:
p
char *

return_type: char *


decompiled_code:
void __fastcall get_ugid(__int64 a1, __int64 a2, __uid_t *a3, __gid_t *a4)
{
const unsigned __int16 **v7; // rax
const char *v8; // rdi
struct passwd *v9; // rax
const unsigned __int16 **v10; // rax
const char *v11; // rdi
struct group *v12; // rax
int v13; // eax
int v14; // eax

*a4 = 0;
*a3 = 0;
if ( *(_DWORD *)(a1 + 20) )
{
v7 = _ctype_b_loc();
v8 = *(const char **)(a1 + 8);
if ( ((*v7)[*v8] & 0x800) != 0 )
{
v14 = atoi(v8);
v9 = getpwuid(v14);
}
else
{
v9 = getpwnam(v8);
}
if ( v9 )
{
*a3 = v9->pw_uid;
*a4 = v9->pw_gid;
}
else
{
lprintf(1LL, "can't get user id for '%s'", *(const char **)(a1 + 8));
}
endpwent();
}
if ( *(_DWORD *)(a2 + 20) )
{
v10 = _ctype_b_loc();
v11 = *(const char **)(a2 + 8);
if ( ((*v10)[*v11] & 0x800) != 0 )
{
v13 = atoi(v11);
v12 = getgrgid(v13);
}
else
{
v12 = getgrnam(v11);
}
if ( v12 )
*a4 = v12->gr_gid;
else
lprintf(1LL, "can't get group '%s'", *(const char **)(a2 + 8));
endgrent();
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __uid_t *a3, __gid_t *a4)
{
const unsigned __int16 **v7; // rax
const char *v8; // rdi
struct passwd *v9; // rax
const unsigned __int16 **v10; // rax
const char *v11; // rdi
struct group *v12; // rax
int v13; // eax
int v14; // eax

*a4 = 0;
*a3 = 0;
if ( *(_DWORD *)(a1 + 20) )
{
v7 = _ctype_b_loc();
v8 = *(const char **)(a1 + 8);
if ( ((*v7)[*v8] & 0x800) != 0 )
{
v14 = atoi(v8);
v9 = getpwuid(v14);
}
else
{
v9 = getpwnam(v8);
}
if ( v9 )
{
*a3 = v9->pw_uid;
*a4 = v9->pw_gid;
}
else
{
lprintf(1LL, "can't get user id for '%s'", *(const char **)(a1 + 8));
}
endpwent();
}
if ( *(_DWORD *)(a2 + 20) )
{
v10 = _ctype_b_loc();
v11 = *(const char **)(a2 + 8);
if ( ((*v10)[*v11] & 0x800) != 0 )
{
v13 = atoi(v11);
v12 = getgrgid(v13);
}
else
{
v12 = getgrnam(v11);
}
if ( v12 )
*a4 = v12->gr_gid;
else
lprintf(1LL, "can't get group '%s'", *(const char **)(a2 + 8));
endgrent();
}
}

original_code:
void get_ugid (conf_data * user,conf_data * group,uid_t * uid,gid_t * gid)
{
    *uid = *gid = 0;
    if ( user->flags != C_EMPTY )
    {
 struct passwd *pwd;
 if ( ((*__ctype_b_loc ())[(int) ((*(char*)(user->d.p)))] & (unsigned short int) _ISdigit))
     pwd = getpwuid( atoi( (char*) (user->d.p) ));
 else
     pwd = getpwnam( (char*)(user->d.p) );
 if ( pwd == ((void *)0) )
     lprintf( 1, "can't get user id for '%s'", user->d.p );
 else
 {
     *uid = pwd->pw_uid;
     *gid = pwd->pw_gid;
 }
 endpwent();
    }
    if ( group->flags != C_EMPTY )
    {
 struct group * grp;
 if ( ((*__ctype_b_loc ())[(int) ((*(char*)(group->d.p)))] & (unsigned short int) _ISdigit))
     grp = getgrgid( atoi( (char*)(group->d.p)) );
 else
     grp = getgrnam( (char*) (group->d.p) );
 if ( grp == ((void *)0) )
     lprintf( 1, "can't get group '%s'", group->d.p );
 else
     *gid = grp->gr_gid;
 endgrent();
    }
}

canonical_original_code:
void get_ugid(struct conf_data *user, struct conf_data *group, unsigned int *uid, unsigned int *gid)
{
    *uid = *gid = 0;
    if ( user->flags != C_EMPTY )
    {
 struct passwd *pwd;
 if ( ((*__ctype_b_loc ())[(int) ((*(char *)(user->d.p)))] & (unsigned short) _ISdigit))
     pwd = getpwuid( atoi( (char *) (user->d.p) ));
 else
     pwd = getpwnam( (char *)(user->d.p) );
 if ( pwd == ((void *)0) )
     lprintf( 1, "can't get user id for '%s'", user->d.p );
 else
 {
     *uid = pwd->pw_uid;
     *gid = pwd->pw_gid;
 }
 endpwent();
    }
    if ( group->flags != C_EMPTY )
    {
 struct group *grp;
 if ( ((*__ctype_b_loc ())[(int) ((*(char *)(group->d.p)))] & (unsigned short) _ISdigit))
     grp = getgrgid( atoi( (char *)(group->d.p)) );
 else
     grp = getgrnam( (char *) (group->d.p) );
 if ( grp == ((void *)0) )
     lprintf( 1, "can't get group '%s'", group->d.p );
 else
     *gid = grp->gr_gid;
 endgrent();
    }
}

variable_types: struct conf_data { char *key; union { long i; void *p; } d; enum { CT_INT=0, CT_STRING=1, CT_CHAT=2, CT_BOOL=3, CT_FLOWL=4, CT_ACTION=5, CT_KEYWORD=6 } type; enum { C_EMPTY=0, C_PRESET=1, C_OVERRIDE=2, C_CONF=3, C_IGNORE=4 } flags; } *

variable_types:
group
struct conf_data *

variable_types:
uid
unsigned int *

variable_types:
gid
unsigned int *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

return_type: void


decompiled_code:
char *__fastcall get_ps_args(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
__int64 i; // rax
const unsigned __int16 **v5; // rsi
__int64 v6; // rax
char *result; // rax
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v8, "/proc/%d/cmdline", a1);
v1 = open(v8, 0);
if ( v1 < 0 )
{
lprintf(1LL, "cannot open %s", v8);
result = 0LL;
}
else
{
v2 = v1;
v3 = read(v1, psinfo_0, 0x3BuLL);
if ( v3 < 0 )
{
lprintf(1LL, "reading %s failed", v8);
close(v2);
result = 0LL;
}
else
{
close(v2);
psinfo_0[v3] = 0;
if ( v3 )
{
for ( i = 0LL; ; ++i )
{
if ( !psinfo_0[i] )
psinfo_0[i] = 32;
if ( v3 - 1 == i )
break;
}
v5 = _ctype_b_loc();
v6 = v3;
do
{
if ( ((*v5)[*(char *)(v6 + 607)] & 0x2000) == 0 )
break;
*(_BYTE *)(v6 + 607) = 0;
--v6;
}
while ( (_DWORD)v6 );
}
result = psinfo_0;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
__int64 i; // rax
const unsigned __int16 **v5; // rsi
__int64 v6; // rax
char *result; // rax
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v8, "/proc/%d/cmdline", a1);
v1 = open(v8, 0);
if ( v1 < 0 )
{
lprintf(1LL, "cannot open %s", v8);
result = 0LL;
}
else
{
v2 = v1;
v3 = read(v1, psinfo_0, 0x3BuLL);
if ( v3 < 0 )
{
lprintf(1LL, "reading %s failed", v8);
close(v2);
result = 0LL;
}
else
{
close(v2);
psinfo_0[v3] = 0;
if ( v3 )
{
for ( i = 0LL; ; ++i )
{
if ( !psinfo_0[i] )
psinfo_0[i] = 32;
if ( v3 - 1 == i )
break;
}
v5 = _ctype_b_loc();
v6 = v3;
do
{
if ( ((*v5)[*(char *)(v6 + 607)] & 0x2000) == 0 )
break;
*(_BYTE *)(v6 + 607) = 0;
--v6;
}
while ( (_DWORD)v6 );
}
result = psinfo_0;
}
}
return result;
}

original_code:
char * get_ps_args (int pid)
{
    char procfn[30];
    int procfd;
    int i,l;
    static char psinfo[60];
    sprintf( procfn, "/proc/%d/cmdline", pid );
    procfd = open( procfn, 00 );
    if ( procfd < 0 )
    {
 lprintf( 1, "cannot open %s", procfn );
 return ((void *)0);
    }
    l = read( procfd, psinfo, sizeof( psinfo ) -1 );
    if ( l < 0 )
    {
 lprintf( 1, "reading %s failed", procfn );
 close( procfd );
 return ((void *)0);
    }
    close( procfd );
    psinfo[l] = 0;
    for ( i=0; i<l; i++ )
 if ( psinfo[i] == 0 ) psinfo[i] = ' ';
    while( l>0 && ((*__ctype_b_loc ())[(int) ((psinfo[l-1]))] & (unsigned short int) _ISspace) ) psinfo[--l]='\0';
    return psinfo;
}

canonical_original_code:
char *get_ps_args(int pid)
{
    char procfn[30];
    int procfd;
    int i; int l;
    static char psinfo[60];
    sprintf( procfn, "/proc/%d/cmdline", pid );
    procfd = open( procfn, 00 );
    if ( procfd < 0 )
    {
 lprintf( 1, "cannot open %s", procfn );
 return ((void *)0);
    }
    l = read( procfd, psinfo, sizeof( psinfo ) -1 );
    if ( l < 0 )
    {
 lprintf( 1, "reading %s failed", procfn );
 close( procfd );
 return ((void *)0);
    }
    close( procfd );
    psinfo[l] = 0;
    for ( i=0; i<l; i++ )
 if ( psinfo[i] == 0 ) psinfo[i] = ' ';
    while( l>0 && ((*__ctype_b_loc ())[(int) ((psinfo[l-1]))] & (unsigned short) _ISspace) ) psinfo[--l]='\0';
    return psinfo;
}

variable_types: pid int

variable_types:
procfn
char [30]

variable_types: procfd int

variable_types: i int

variable_types: l int

variable_types:
psinfo
char [60]


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);
}


decompiled_code:
__int64 __fastcall do_chat_send(int fd, void *buf)
{
char v2; // r13
char *v3; // rbx
char v4; // al
char v5; // al
__int64 v6; // rsi
char *v7; // rbp
__int64 result; // rax

v2 = 0;
v3 = (char *)buf;
delay(50LL);
lprintf(4LL, "send: ");
v4 = *(_BYTE *)buf;
if ( *(_BYTE *)buf )
{
do
{
while ( v4 == 92 )
{
v5 = v3[1];
if ( v5 == 99 )
{
v2 = 1;
}
else if ( v5 == 100 )
{
lputs(4LL, "\\d");
delay(500LL);
}
else
{
write(fd, v3 + 1, 1uLL);
lputc(4LL, (unsigned int)v3[1]);
}
v4 = v3[2];
v3 += 2;
if ( !v4 )
goto LABEL_10;
}
if ( write(fd, v3, 1uLL) != 1 )
{
lprintf(1LL, "do_chat: can't write to modem!");
return 0xFFFFFFFFLL;
}
v6 = (unsigned int)*v3;
v7 = v3++;
lputc(4LL, v6);
v4 = v7[1];
}
while ( v4 );
LABEL_10:
if ( !v2 )
goto LABEL_14;
result = 0LL;
}
else
{
LABEL_14:
write(fd, "\r", 1uLL);
lputc(4LL, 13LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf)
{
char v2; // r13
char *v3; // rbx
char v4; // al
char v5; // al
__int64 v6; // rsi
char *v7; // rbp
__int64 result; // rax

v2 = 0;
v3 = (char *)buf;
delay(50LL);
lprintf(4LL, "send: ");
v4 = *(_BYTE *)buf;
if ( *(_BYTE *)buf )
{
do
{
while ( v4 == 92 )
{
v5 = v3[1];
if ( v5 == 99 )
{
v2 = 1;
}
else if ( v5 == 100 )
{
lputs(4LL, "\\d");
delay(500LL);
}
else
{
write(fd, v3 + 1, 1uLL);
lputc(4LL, (unsigned int)v3[1]);
}
v4 = v3[2];
v3 += 2;
if ( !v4 )
goto LABEL_10;
}
if ( write(fd, v3, 1uLL) != 1 )
{
lprintf(1LL, "do_chat: can't write to modem!");
return 0xFFFFFFFFLL;
}
v6 = (unsigned int)*v3;
v7 = v3++;
lputc(4LL, v6);
v4 = v7[1];
}
while ( v4 );
LABEL_10:
if ( !v2 )
goto LABEL_14;
result = 0LL;
}
else
{
LABEL_14:
write(fd, "\r", 1uLL);
lputc(4LL, 13LL);
result = 0LL;
}
return result;
}

original_code:
int do_chat_send (int fd,char * p)
{
    boolean nocr = (1==0);
    delay(50);
    lprintf( 4, "send: " );
    while ( *p != 0 )
    {
 if ( *p == '\\' )
 {
     switch ( *(++p) )
     {
       case 'd': lputs( 4, "\\d"); delay(500); break;
       case 'c': nocr = (1==1); break;
       default:
  write( fd, p, 1 );
  lputc( 4, *p );
     }
 }
 else
 {
     if ( write( fd, p, 1 ) != 1 )
     {
  lprintf( 1, "do_chat: can't write to modem!" );
  return -1;
     }
     lputc( 4, *p );
 }
 p++;
    }
    if ( ! nocr )
    {
 write( fd, "\r", sizeof("\r")-1 );
 p = "\r";
 while ( *p ) lputc( 4, *(p++) );
    }
    return 0;
}

canonical_original_code:
int do_chat_send(int fd, char *p)
{
    char nocr = (1==0);
    delay(50);
    lprintf( 4, "send: " );
    while ( *p != 0 )
    {
 if ( *p == '\\' )
 {
     switch ( *(++p) )
     {
       case 'd': lputs( 4, "\\d"); delay(500); break;
       case 'c': nocr = (1==1); break;
       default:
  write( fd, p, 1 );
  lputc( 4, *p );
     }
 }
 else
 {
     if ( write( fd, p, 1 ) != 1 )
     {
  lprintf( 1, "do_chat: can't write to modem!" );
  return -1;
     }
     lputc( 4, *p );
 }
 p++;
    }
    if ( ! nocr )
    {
 write( fd, "\r", sizeof("\r")-1 );
 p = "\r";
 while ( *p ) lputc( 4, *(p++) );
    }
    return 0;
}

variable_types: fd int

variable_types: nocr char

return_type: int


decompiled_code:
__int64 __fastcall do_chat(__int64 fd, const char **a2, const char **a3, _DWORD *a4, unsigned int a5, char a6)
{
unsigned int v6; // er14
const char **v8; // r12
_DWORD *v9; // rbx
__m128i v10; // xmm0
__m128i v11; // xmm1
__m128i v12; // xmm2
const char *v13; // rdx
char *v14; // rsi
int v15; // ebp
__int64 v16; // r15
int v17; // eax
__int64 v18; // rsi
char *v19; // rdx
char v20; // al
const char *v21; // r15
int v22; // eax
const char *v23; // r15
const char **v24; // rbx
int v25; // eax
unsigned int v26; // er12
const char *v28; // rdx
int v29; // edx
int v30; // [rsp+Ch] [rbp-2CCh]
__m128i v34; // [rsp+20h] [rbp-2B8h] BYREF
__m128i v35; // [rsp+30h] [rbp-2A8h] BYREF
__m128i v36; // [rsp+40h] [rbp-298h] BYREF
__int64 v37; // [rsp+50h] [rbp-288h]
int v38; // [rsp+58h] [rbp-280h]
__int128 v39[3]; // [rsp+60h] [rbp-278h] BYREF
__int64 v40; // [rsp+90h] [rbp-248h]
int v41; // [rsp+98h] [rbp-240h]
char dest[250]; // [rsp+A0h] [rbp-238h] BYREF
char src[318]; // [rsp+19Ah] [rbp-13Eh] BYREF

v6 = fd;
v8 = a2;
v9 = a4;
tio_get(fd, &v34);
v10 = _mm_loadu_si128(&v34);
v11 = _mm_loadu_si128(&v35);
v12 = _mm_loadu_si128(&v36);
v40 = v37;
v39[0] = (__int128)v10;
v41 = v38;
v39[1] = (__int128)v11;
v39[2] = (__int128)v12;
tio_mode_raw(&v34);
tio_set((unsigned int)fd, &v34);
signal(14, (__sighandler_t)chat_timeout);
if ( a3 && v9 )
*v9 = 0;
v13 = *a2;
v30 = 0;
if ( *a2 )
{
do
{
if ( *v13 )
{
lprintf(4LL, "waiting for ``%s''", v13);
lprintf(5LL, "got: ");
chat_has_timeout = 0;
if ( v30 || a6 )
alarm(a5);
else
alarm(0);
v15 = 0;
while ( !virtual_ring || memcmp(*v8, "RING", 4uLL) )
{
v16 = v15;
v17 = read(v6, &dest[v15], 1uLL);
if ( v17 < 0 )
{
if ( *_errno_location() != 4 )
{
v26 = -1;
lprintf(1LL, "do_chat: error in read()");
alarm(0);
goto LABEL_34;
}
if ( chat_has_timeout )
{
LABEL_37:
v28 = *v8;
v26 = -1;
lprintf(3LL, "timeout in chat script, waiting for `%s'", v28);
alarm(0);
goto LABEL_34;
}
}
else
{
if ( chat_has_timeout )
goto LABEL_37;
if ( v17 )
{
v18 = (unsigned int)dest[v15];
v15 += v17;
lputc(5LL, v18);
v19 = lptr_1;
v20 = dest[v16];
if ( v20 == 13 || v20 == 10 || lptr_1 >= byte_761 )
{
*lptr_1 = 0;
if ( lbuf_0 )
cndfind(&lbuf_0, v18, v19);
lptr_1 = &lbuf_0;
}
else
{
*lptr_1 = v20;
lptr_1 = v19 + 1;
}
}
}
if ( v15 > 495 )
{
v29 = v15 - 249;
v15 -= 250;
memcpy(dest, src, v29);
}
v21 = *v8;
v22 = strlen(*v8);
if ( v15 >= v22 && !memcmp(&dest[v15 - v22], v21, v22) )
{
lputs(4LL, " ** found **");
alarm(0);
goto LABEL_6;
}
if ( a3 )
{
v23 = *a3;
if ( *a3 )
{
v24 = a3;
while ( 1 )
{
v25 = strlen(v23);
if ( v15 >= v25 && !memcmp(&dest[v15 - v25], v23, v25) )
break;
v23 = v24[2];
v24 += 2;
if ( !v23 )
goto LABEL_13;
}
v26 = -1;
lprintf(4LL, "found action string: ``%s''", v23);
*a4 = *((_DWORD *)v24 + 2);
alarm(0);
goto LABEL_34;
}
}
LABEL_13:
if ( v15 > 499 )
goto LABEL_44;
}
lputs(4LL, " ``found''");
LABEL_44:
alarm(0);
}
LABEL_6:
v14 = (char *)v8[1];
if ( !v14 )
break;
v8 += 2;
v30 += 2;
do_chat_send(v6, v14);
v13 = *v8;
}
while ( *v8 );
}
v26 = 0;
LABEL_34:
tio_set(v6, v39);
return v26;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 fd, const char **a2, const char **a3, _DWORD *a4, unsigned int a5, char a6)
{
unsigned int v6; // er14
const char **v8; // r12
_DWORD *v9; // rbx
__m128i v10; // xmm0
__m128i v11; // xmm1
__m128i v12; // xmm2
const char *v13; // rdx
char *v14; // rsi
int v15; // ebp
__int64 v16; // r15
int v17; // eax
__int64 v18; // rsi
char *v19; // rdx
char v20; // al
const char *v21; // r15
int v22; // eax
const char *v23; // r15
const char **v24; // rbx
int v25; // eax
unsigned int v26; // er12
const char *v28; // rdx
int v29; // edx
int v30; // [rsp+Ch] [rbp-2CCh]
__m128i v34; // [rsp+20h] [rbp-2B8h] BYREF
__m128i v35; // [rsp+30h] [rbp-2A8h] BYREF
__m128i v36; // [rsp+40h] [rbp-298h] BYREF
__int64 v37; // [rsp+50h] [rbp-288h]
int v38; // [rsp+58h] [rbp-280h]
__int128 v39[3]; // [rsp+60h] [rbp-278h] BYREF
__int64 v40; // [rsp+90h] [rbp-248h]
int v41; // [rsp+98h] [rbp-240h]
char dest[250]; // [rsp+A0h] [rbp-238h] BYREF
char src[318]; // [rsp+19Ah] [rbp-13Eh] BYREF

v6 = fd;
v8 = a2;
v9 = a4;
tio_get(fd, &v34);
v10 = _mm_loadu_si128(&v34);
v11 = _mm_loadu_si128(&v35);
v12 = _mm_loadu_si128(&v36);
v40 = v37;
v39[0] = (__int128)v10;
v41 = v38;
v39[1] = (__int128)v11;
v39[2] = (__int128)v12;
tio_mode_raw(&v34);
tio_set((unsigned int)fd, &v34);
signal(14, (__sighandler_t)chat_timeout);
if ( a3 && v9 )
*v9 = 0;
v13 = *a2;
v30 = 0;
if ( *a2 )
{
do
{
if ( *v13 )
{
lprintf(4LL, "waiting for ``%s''", v13);
lprintf(5LL, "got: ");
chat_has_timeout = 0;
if ( v30 || a6 )
alarm(a5);
else
alarm(0);
v15 = 0;
while ( !virtual_ring || memcmp(*v8, "RING", 4uLL) )
{
v16 = v15;
v17 = read(v6, &dest[v15], 1uLL);
if ( v17 < 0 )
{
if ( *_errno_location() != 4 )
{
v26 = -1;
lprintf(1LL, "do_chat: error in read()");
alarm(0);
goto LABEL_34;
}
if ( chat_has_timeout )
{
LABEL_37:
v28 = *v8;
v26 = -1;
lprintf(3LL, "timeout in chat script, waiting for `%s'", v28);
alarm(0);
goto LABEL_34;
}
}
else
{
if ( chat_has_timeout )
goto LABEL_37;
if ( v17 )
{
v18 = (unsigned int)dest[v15];
v15 += v17;
lputc(5LL, v18);
v19 = lptr_1;
v20 = dest[v16];
if ( v20 == 13 || v20 == 10 || lptr_1 >= byte_761 )
{
*lptr_1 = 0;
if ( lbuf_0 )
cndfind(&lbuf_0, v18, v19);
lptr_1 = &lbuf_0;
}
else
{
*lptr_1 = v20;
lptr_1 = v19 + 1;
}
}
}
if ( v15 > 495 )
{
v29 = v15 - 249;
v15 -= 250;
memcpy(dest, src, v29);
}
v21 = *v8;
v22 = strlen(*v8);
if ( v15 >= v22 && !memcmp(&dest[v15 - v22], v21, v22) )
{
lputs(4LL, " ** found **");
alarm(0);
goto LABEL_6;
}
if ( a3 )
{
v23 = *a3;
if ( *a3 )
{
v24 = a3;
while ( 1 )
{
v25 = strlen(v23);
if ( v15 >= v25 && !memcmp(&dest[v15 - v25], v23, v25) )
break;
v23 = v24[2];
v24 += 2;
if ( !v23 )
goto LABEL_13;
}
v26 = -1;
lprintf(4LL, "found action string: ``%s''", v23);
*a4 = *((_DWORD *)v24 + 2);
alarm(0);
goto LABEL_34;
}
}
LABEL_13:
if ( v15 > 499 )
goto LABEL_44;
}
lputs(4LL, " ``found''");
LABEL_44:
alarm(0);
}
LABEL_6:
v14 = (char *)v8[1];
if ( !v14 )
break;
v8 += 2;
v30 += 2;
func1(v6, v14);
v13 = *v8;
}
while ( *v8 );
}
v26 = 0;
LABEL_34:
tio_set(v6, v39);
return v26;
}

original_code:
int do_chat (int fd,char * expect_send[],chat_action_t actions[],action_t * action,int chat_timeout_time,boolean timeout_first)
{
char buffer[500];
int i,cnt;
int retcode = 0;
int str;
int h;
TIO tio, save_tio;
static char lbuf[100];
static char *lptr = lbuf;
    tio_get( fd, &tio );
    save_tio = tio;
    tio_mode_raw( &tio );
    tio_set( fd, &tio );
    signal( 14, chat_timeout );
    if ( actions != ((void *)0) && action != ((void *)0) ) *action = A_TIMOUT;
    str=0;
    while ( expect_send[str] != ((void *)0) )
    {
 i = 0;
 if ( strlen( expect_send[str] ) != 0 )
 {
     lprintf( 4, "waiting for ``%s''", expect_send[str] );
     lprintf( 5, "got: " );
     chat_has_timeout = (1==0);
     if ( str != 0 || timeout_first )
  alarm( chat_timeout_time );
     else
  alarm( 0 );
     do
     {
  if ( virtual_ring &&
       strncmp( expect_send[str], "RING", 4 ) == 0 )
  {
      lputs( 4, " ``found''" );
      break;
  }
  cnt = read( fd, &buffer[i], 1 );
  if ( cnt < 0 )
  {
      if ( (*__errno_location ()) == 4 ) cnt = 0;
      else
      {
          lprintf( 1, "do_chat: error in read()");
   retcode = -1;
   break;
      }
  }
  if ( chat_has_timeout )
  {
      lprintf( 3, "timeout in chat script, waiting for `%s'", expect_send[str] );
      retcode = -1;
      break;
  }
  if ( cnt > 0 )
  {
      lputc( 5, buffer[i] );
      if ( buffer[i] == '\r' || buffer[i] == '\n' ||
    (lptr >= lbuf+100 -3) )
      {
   *lptr = '\0';
   if (lbuf[0])
       cndfind(lbuf);
   lptr = lbuf;
      }
      else
   *lptr++ = buffer[i];
  }
  i += cnt;
  if ( i>500 -5 )
  {
      memcpy( &buffer[0], &buffer[500/2], i-500/2+1 );
      i-=500/2;
  }
  cnt = strlen( expect_send[str] );
  if ( i >= cnt &&
       memcmp( &buffer[i-cnt], expect_send[str], cnt ) == 0 )
  {
      lputs( 4, " ** found **" );
      break;
  }
                if ( actions != ((void *)0) )
    for ( h=0; actions[h].expect != ((void *)0); h ++ )
  {
      cnt = strlen( actions[h].expect );
      if ( i>=cnt &&
    memcmp( &buffer[i-cnt], actions[h].expect, cnt ) == 0 )
      {
   lprintf( 4,"found action string: ``%s''",
                   actions[h].expect );
   *action = actions[h].action;
   retcode = -1;
   break;
      }
  }
     }
     while ( i<500 && retcode != -1 );
     alarm(0);
     if ( retcode == -1 ) break;
 }
 str++;
 if ( expect_send[str] == ((void *)0) ) break;
 do_chat_send(fd, expect_send[str++] );
    }
    tio_set( fd, &save_tio );
    return retcode;
}

canonical_original_code:
int do_chat(int fd, char *expect_send[], struct chat_actions actions[], enum action_t *action, int chat_timeout_time, char timeout_first)
{
char buffer[500];
int i; int cnt;
int retcode = 0;
int str;
int h;
struct termios tio; struct termios save_tio;
static char lbuf[100];
static char *lptr = lbuf;
    tio_get( fd, &tio );
    save_tio = tio;
    tio_mode_raw( &tio );
    tio_set( fd, &tio );
    signal( 14, chat_timeout );
    if ( actions != ((void *)0) && action != ((void *)0) ) *action = A_TIMOUT;
    str=0;
    while ( expect_send[str] != ((void *)0) )
    {
 i = 0;
 if ( strlen( expect_send[str] ) != 0 )
 {
     lprintf( 4, "waiting for ``%s''", expect_send[str] );
     lprintf( 5, "got: " );
     chat_has_timeout = (1==0);
     if ( str != 0 || timeout_first )
  alarm( chat_timeout_time );
     else
  alarm( 0 );
     do
     {
  if ( virtual_ring &&
       strncmp( expect_send[str], "RING", 4 ) == 0 )
  {
      lputs( 4, " ``found''" );
      break;
  }
  cnt = read( fd, &buffer[i], 1 );
  if ( cnt < 0 )
  {
      if ( (*__errno_location ()) == 4 ) cnt = 0;
      else
      {
          lprintf( 1, "do_chat: error in read()");
   retcode = -1;
   break;
      }
  }
  if ( chat_has_timeout )
  {
      lprintf( 3, "timeout in chat script, waiting for `%s'", expect_send[str] );
      retcode = -1;
      break;
  }
  if ( cnt > 0 )
  {
      lputc( 5, buffer[i] );
      if ( buffer[i] == '\r' || buffer[i] == '\n' ||
    (lptr >= lbuf+100 -3) )
      {
   *lptr = '\0';
   if (lbuf[0])
       cndfind(lbuf);
   lptr = lbuf;
      }
      else
   *lptr++ = buffer[i];
  }
  i += cnt;
  if ( i>500 -5 )
  {
      memcpy( &buffer[0], &buffer[500/2], i-500/2+1 );
      i-=500/2;
  }
  cnt = strlen( expect_send[str] );
  if ( i >= cnt &&
       memcmp( &buffer[i-cnt], expect_send[str], cnt ) == 0 )
  {
      lputs( 4, " ** found **" );
      break;
  }
                if ( actions != ((void *)0) )
    for ( h=0; actions[h].expect != ((void *)0); h ++ )
  {
      cnt = strlen( actions[h].expect );
      if ( i>=cnt &&
    memcmp( &buffer[i-cnt], actions[h].expect, cnt ) == 0 )
      {
   lprintf( 4,"found action string: ``%s''",
                   actions[h].expect );
   *action = actions[h].action;
   retcode = -1;
   break;
      }
  }
     }
     while ( i<500 && retcode != -1 );
     alarm(0);
     if ( retcode == -1 ) break;
 }
 str++;
 if ( expect_send[str] == ((void *)0) ) break;
 do_chat_send(fd, expect_send[str++] );
    }
    tio_set( fd, &save_tio );
    return retcode;
}

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:
buffer
char [500]

variable_types: cnt int

variable_types: retcode int

variable_types: str int

variable_types: h 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:
lbuf
char [100]

variable_types:
lptr
char *

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


decompiled_code:
__int64 __fastcall clean_line(int fd, unsigned int a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm0
int v4; // ebx
__m128i v5; // xmm2
char buf[2]; // [rsp+Eh] [rbp-9Ah] BYREF
__m128i v8; // [rsp+10h] [rbp-98h] BYREF
__m128i v9; // [rsp+20h] [rbp-88h] BYREF
__m128i v10; // [rsp+30h] [rbp-78h] BYREF
__int64 v11; // [rsp+40h] [rbp-68h]
int v12; // [rsp+48h] [rbp-60h]
__int128 v13[3]; // [rsp+50h] [rbp-58h] BYREF
__int64 v14; // [rsp+80h] [rbp-28h]
int v15; // [rsp+88h] [rbp-20h]

lprintf(5LL, "waiting for line to clear (VTIME=%d), read: ", a2);
tio_get((unsigned int)fd, &v8);
v2 = _mm_loadu_si128(&v9);
v3 = _mm_loadu_si128(&v8);
v9.m128i_i16[3] = (unsigned __int8)a2;
v4 = 0;
v14 = v11;
v5 = _mm_loadu_si128(&v10);
v8.m128i_i32[3] &= 0xFFFFFFFD;
v15 = v12;
v13[0] = (__int128)v3;
v13[1] = (__int128)v2;
v13[2] = (__int128)v5;
tio_set((unsigned int)fd, &v8);
while ( read(fd, buf, 1uLL) > 0 )
{
if ( v4 == 10000 )
{
tio_set((unsigned int)fd, v13);
lprintf(3LL, "clean_line: only 500 of %d bytes logged", 10000LL);
goto LABEL_9;
}
if ( ++v4 <= 499 )
lputc(5LL, (unsigned int)buf[0]);
}
tio_set((unsigned int)fd, v13);
if ( v4 <= 500 )
return 0LL;
lprintf(3LL, "clean_line: only 500 of %d bytes logged", (unsigned int)v4);
if ( v4 != 10000 )
return 0LL;
LABEL_9:
lprintf(0LL, "clean_line: got too much junk (dev=%s).", Device);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, unsigned int a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm0
int v4; // ebx
__m128i v5; // xmm2
char buf[2]; // [rsp+Eh] [rbp-9Ah] BYREF
__m128i v8; // [rsp+10h] [rbp-98h] BYREF
__m128i v9; // [rsp+20h] [rbp-88h] BYREF
__m128i v10; // [rsp+30h] [rbp-78h] BYREF
__int64 v11; // [rsp+40h] [rbp-68h]
int v12; // [rsp+48h] [rbp-60h]
__int128 v13[3]; // [rsp+50h] [rbp-58h] BYREF
__int64 v14; // [rsp+80h] [rbp-28h]
int v15; // [rsp+88h] [rbp-20h]

lprintf(5LL, "waiting for line to clear (VTIME=%d), read: ", a2);
tio_get((unsigned int)fd, &v8);
v2 = _mm_loadu_si128(&v9);
v3 = _mm_loadu_si128(&v8);
v9.m128i_i16[3] = (unsigned __int8)a2;
v4 = 0;
v14 = v11;
v5 = _mm_loadu_si128(&v10);
v8.m128i_i32[3] &= 0xFFFFFFFD;
v15 = v12;
v13[0] = (__int128)v3;
v13[1] = (__int128)v2;
v13[2] = (__int128)v5;
tio_set((unsigned int)fd, &v8);
while ( read(fd, buf, 1uLL) > 0 )
{
if ( v4 == 10000 )
{
tio_set((unsigned int)fd, v13);
lprintf(3LL, "clean_line: only 500 of %d bytes logged", 10000LL);
goto LABEL_9;
}
if ( ++v4 <= 499 )
lputc(5LL, (unsigned int)buf[0]);
}
tio_set((unsigned int)fd, v13);
if ( v4 <= 500 )
return 0LL;
lprintf(3LL, "clean_line: only 500 of %d bytes logged", (unsigned int)v4);
if ( v4 != 10000 )
return 0LL;
LABEL_9:
lprintf(0LL, "clean_line: got too much junk (dev=%s).", Device);
return 0LL;
}

original_code:
int clean_line (int fd,int waittime)
{
    char buffer[2];
    int bytes = 0;
TIO tio, save_tio;
    lprintf( 5, "waiting for line to clear (VTIME=%d), read: ", waittime);
    tio_get( fd, &tio );
    save_tio = tio;
    tio.c_lflag &= ~0000002;
    tio.c_cc[6] = 0;
    tio.c_cc[5] = waittime;
    tio_set( fd, &tio );
    while ( read( fd, buffer, 1 ) > 0 &&
     bytes < 10000 )
    {
        if ( ++bytes < 500 ) lputc( 5, buffer[0] );
    }
    tio_set( fd, &save_tio );
    if ( bytes > 500 )
        lprintf( 3, "clean_line: only 500 of %d bytes logged", bytes );
    if ( bytes >= 10000 )
    {
 extern char * Device;
        lprintf( 0, "clean_line: got too much junk (dev=%s).", Device );
    }
    return 0;
}

canonical_original_code:
int clean_line(int fd, int waittime)
{
    char buffer[2];
    int bytes = 0;
struct termios tio; struct termios save_tio;
    lprintf( 5, "waiting for line to clear (VTIME=%d), read: ", waittime);
    tio_get( fd, &tio );
    save_tio = tio;
    tio.c_lflag &= ~0000002;
    tio.c_cc[6] = 0;
    tio.c_cc[5] = waittime;
    tio_set( fd, &tio );
    while ( read( fd, buffer, 1 ) > 0 &&
     bytes < 10000 )
    {
        if ( ++bytes < 500 ) lputc( 5, buffer[0] );
    }
    tio_set( fd, &save_tio );
    if ( bytes > 500 )
        lprintf( 3, "clean_line: only 500 of %d bytes logged", bytes );
    if ( bytes >= 10000 )
    {
 extern char *Device;
        lprintf( 0, "clean_line: got too much junk (dev=%s).", Device );
    }
    return 0;
}

variable_types: waittime int

variable_types:
buffer
char [2]

variable_types: bytes int

variable_types:
Device
char *

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:
int __fastcall pbm_getint(int fd)
{
const unsigned __int16 **v1; // rbp
__int64 v2; // rbx
ssize_t v3; // rax
__int64 v5; // rbx
__int64 v6; // r13
bool v7; // zf
const unsigned __int16 *v8; // rax
char buf[104]; // [rsp+0h] [rbp-68h] BYREF

do
{
if ( read(fd, buf, 1uLL) != 1 )
return -1;
v2 = buf[0];
if ( buf[0] == 35 )
{
do
{
v3 = read(fd, buf, 1uLL);
v2 = buf[0];
}
while ( v3 == 1 && buf[0] != 10 );
}
v1 = _ctype_b_loc();
}
while ( ((*v1)[v2] & 0x2000) != 0 );
v5 = 1LL;
while ( 1 )
{
v6 = (int)v5;
v7 = read(fd, &buf[v5], 1uLL) == 1;
v8 = *v1;
if ( !v7 )
break;
if ( (v8[buf[v5]] & 0x2000) != 0 )
goto LABEL_14;
if ( ++v5 == 49 )
{
v6 = 49LL;
break;
}
}
if ( (v8[buf[v6]] & 0x2000) == 0 )
return -1;
LABEL_14:
buf[v6] = 0;
return atoi(buf);
}

canonical_decompiled_code:
int __fastcall func0(int fd)
{
const unsigned __int16 **v1; // rbp
__int64 v2; // rbx
ssize_t v3; // rax
__int64 v5; // rbx
__int64 v6; // r13
bool v7; // zf
const unsigned __int16 *v8; // rax
char buf[104]; // [rsp+0h] [rbp-68h] BYREF

do
{
if ( read(fd, buf, 1uLL) != 1 )
return -1;
v2 = buf[0];
if ( buf[0] == 35 )
{
do
{
v3 = read(fd, buf, 1uLL);
v2 = buf[0];
}
while ( v3 == 1 && buf[0] != 10 );
}
v1 = _ctype_b_loc();
}
while ( ((*v1)[v2] & 0x2000) != 0 );
v5 = 1LL;
while ( 1 )
{
v6 = (int)v5;
v7 = read(fd, &buf[v5], 1uLL) == 1;
v8 = *v1;
if ( !v7 )
break;
if ( (v8[buf[v5]] & 0x2000) != 0 )
goto LABEL_14;
if ( ++v5 == 49 )
{
v6 = 49LL;
break;
}
}
if ( (v8[buf[v6]] & 0x2000) == 0 )
return -1;
LABEL_14:
buf[v6] = 0;
return atoi(buf);
}

original_code:
int pbm_getint (int fd)
{
    char buf[50];
    int i;
    do
    {
 if ( read( fd, buf, 1 ) != 1 ) return -1;
 if ( buf[0] == '#' )
 {
     while( buf[0] != '\n' && read( fd, buf, 1 ) == 1 ) {}
 }
    }
    while ( ((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short int) _ISspace) );
    i = 1;
    while ( i < sizeof( buf ) -1 &&
     read( fd, &buf[i], 1 ) == 1 &&
     ! ((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short int) _ISspace) )
    {
 i++;
    }
    if ( ! ((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short int) _ISspace) ) return -1;
    buf[i] = 0;
    return ( atoi( buf ) );
}

canonical_original_code:
int pbm_getint(int fd)
{
    char buf[50];
    int i;
    do
    {
 if ( read( fd, buf, 1 ) != 1 ) return -1;
 if ( buf[0] == '#' )
 {
     while( buf[0] != '\n' && read( fd, buf, 1 ) == 1 ) {}
 }
    }
    while ( ((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short) _ISspace) );
    i = 1;
    while ( i < sizeof( buf ) -1 &&
     read( fd, &buf[i], 1 ) == 1 &&
     ! ((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short) _ISspace) )
    {
 i++;
    }
    if ( ! ((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short) _ISspace) ) return -1;
    buf[i] = 0;
    return ( atoi( buf ) );
}

variable_types:
buf
char [50]

variable_types: i int


decompiled_code:
int __fastcall pbm_getheader(int fd)
{
ssize_t v1; // rax
char buf; // [rsp+6h] [rbp-12h] BYREF
char v4; // [rsp+7h] [rbp-11h]

v1 = read(fd, &buf, 2uLL);
if ( v1 == 2 && buf == 80 )
{
LODWORD(v1) = (unsigned __int8)(v4 - 49);
switch ( v4 )
{
case '1':
pbm_type = 1;
break;
case '2':
pbm_type = 2;
break;
case '3':
pbm_type = 3;
break;
case '4':
pbm_type = 4;
break;
case '5':
pbm_type = 5;
break;
case '6':
pbm_type = 6;
break;
default:
goto LABEL_3;
}
pbm_xsize = pbm_getint(fd);
LODWORD(v1) = pbm_getint(fd);
pbm_ysize = v1;
}
else
{
LABEL_3:
pbm_type = 0;
}
return v1;
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
ssize_t v1; // rax
char buf; // [rsp+6h] [rbp-12h] BYREF
char v4; // [rsp+7h] [rbp-11h]

v1 = read(fd, &buf, 2uLL);
if ( v1 == 2 && buf == 80 )
{
LODWORD(v1) = (unsigned __int8)(v4 - 49);
switch ( v4 )
{
case '1':
pbm_type = 1;
break;
case '2':
pbm_type = 2;
break;
case '3':
pbm_type = 3;
break;
case '4':
pbm_type = 4;
break;
case '5':
pbm_type = 5;
break;
case '6':
pbm_type = 6;
break;
default:
goto LABEL_3;
}
pbm_xsize = func0(fd);
LODWORD(v1) = func0(fd);
pbm_ysize = v1;
}
else
{
LABEL_3:
pbm_type = 0;
}
return v1;
}

original_code:
void pbm_getheader (int fd)
{
    char buf[10];
    if ( read( fd, buf, 2 ) != 2 || buf[0] != 'P' )
    {
 pbm_type = unknown; return;
    }
    switch( buf[1] )
    {
      case '1': pbm_type = pbm; break;
      case '2': pbm_type = pgm; break;
      case '3': pbm_type = ppm; break;
      case '4': pbm_type = pbm_raw; break;
      case '5': pbm_type = pgm_raw; break;
      case '6': pbm_type = ppm_raw; break;
      default: pbm_type = unknown; return;
    }
    pbm_xsize = pbm_getint( fd );
    pbm_ysize = pbm_getint( fd );
}

canonical_original_code:
void pbm_getheader(int fd)
{
    char buf[10];
    if ( read( fd, buf, 2 ) != 2 || buf[0] != 'P' )
    {
 pbm_type = unknown; return;
    }
    switch( buf[1] )
    {
      case '1': pbm_type = pbm; break;
      case '2': pbm_type = pgm; break;
      case '3': pbm_type = ppm; break;
      case '4': pbm_type = pbm_raw; break;
      case '5': pbm_type = pgm_raw; break;
      case '6': pbm_type = ppm_raw; break;
      default: pbm_type = unknown; return;
    }
    pbm_xsize = pbm_getint( fd );
    pbm_ysize = pbm_getint( fd );
}

variable_types: fd int

variable_types:
buf
char [10]


decompiled_code:
int __fastcall convert_pbm_raw(int fd, int a2)
{
int v2; // er12
signed int v3; // er13
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rbx
int result; // eax
unsigned int i; // er14
int v8; // eax
unsigned __int8 *v9; // r10
int v10; // edx
int v11; // er15
unsigned int v12; // er14
int v13; // er13
int v14; // eax
__int64 v15; // rdx
__int64 v16; // rsi
__int64 v17; // rax
int v18; // eax
int v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+Ch] [rbp-4Ch]
unsigned __int8 *v21; // [rsp+10h] [rbp-48h]
unsigned __int8 *v22; // [rsp+10h] [rbp-48h]
unsigned __int8 *v23; // [rsp+10h] [rbp-48h]
int v24; // [rsp+18h] [rbp-40h]
int v25; // [rsp+18h] [rbp-40h]
unsigned int v26; // [rsp+1Ch] [rbp-3Ch]

make_run_tables();
v2 = (pbm_xsize + 7) >> 3;
v3 = (pbm_xsize + 7) & 0xFFFFFFF8;
pbm_xsize = v3;
v4 = (unsigned __int8 *)malloc(v2);
if ( !v4 )
{
fprintf(stderr, "cannot malloc %d bytes: ", (unsigned int)v2);
perror(&s);
exit(5);
}
v5 = v4;
result = v3;
if ( v3 > a2 )
result = a2;
v20 = 0;
v19 = result;
v26 = a2 - result;
if ( pbm_ysize <= 0 )
return result;
do
{
for ( i = 0; v2 > (int)i; i += v8 )
{
v8 = read(fd, &v5[i], (int)(v2 - i));
if ( !v8 )
return fprintf(stderr, "line %d: want %d, got %d bytes, EOF", (unsigned int)v20, (unsigned int)v2, i);
}
if ( v19 <= 0 )
{
v12 = 0;
goto LABEL_26;
}
v9 = v5;
v10 = 7;
v11 = 0;
v12 = 0;
v13 = 0;
do
{
while ( 1 )
{
v16 = *v9;
v17 = (__int64)v10 << 8;
if ( v11 )
break;
v14 = *((char *)&w_rtab + v16 + v17);
v12 += v14;
v15 = (unsigned int)(v10 - v14);
if ( (int)v15 < 0 )
goto LABEL_18;
v24 = v15;
v21 = v9;
putwhitespan(v12);
v9 = v21;
v10 = v24;
LABEL_14:
v13 += v12;
v11 ^= 1u;
v12 = 0;
if ( v19 <= v13 )
goto LABEL_21;
}
v18 = *((char *)&b_rtab + v16 + v17);
v12 += v18;
v15 = (unsigned int)(v10 - v18);
if ( (int)v15 >= 0 )
{
v25 = v15;
v22 = v9;
putblackspan(v12);
v10 = v25;
v9 = v22;
goto LABEL_14;
}
LABEL_18:
if ( (_DWORD)v15 != -1 )
{
v23 = v9;
fprintf(stderr, "bit panic: %d\n", v15);
v9 = v23;
}
++v9;
v10 = 7;
}
while ( v19 > (int)(v13 + v12) );
LABEL_21:
if ( v11 )
{
putblackspan(v12);
putwhitespan(v26);
goto LABEL_23;
}
LABEL_26:
putwhitespan(v26 + v12);
LABEL_23:
puteol();
result = ++v20;
}
while ( pbm_ysize > v20 );
return result;
}

canonical_decompiled_code:
int __fastcall func3(int fd, int a2)
{
int v2; // er12
signed int v3; // er13
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rbx
int result; // eax
unsigned int i; // er14
int v8; // eax
unsigned __int8 *v9; // r10
int v10; // edx
int v11; // er15
unsigned int v12; // er14
int v13; // er13
int v14; // eax
__int64 v15; // rdx
__int64 v16; // rsi
__int64 v17; // rax
int v18; // eax
int v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+Ch] [rbp-4Ch]
unsigned __int8 *v21; // [rsp+10h] [rbp-48h]
unsigned __int8 *v22; // [rsp+10h] [rbp-48h]
unsigned __int8 *v23; // [rsp+10h] [rbp-48h]
int v24; // [rsp+18h] [rbp-40h]
int v25; // [rsp+18h] [rbp-40h]
unsigned int v26; // [rsp+1Ch] [rbp-3Ch]

make_run_tables();
v2 = (pbm_xsize + 7) >> 3;
v3 = (pbm_xsize + 7) & 0xFFFFFFF8;
pbm_xsize = v3;
v4 = (unsigned __int8 *)malloc(v2);
if ( !v4 )
{
fprintf(stderr, "cannot malloc %d bytes: ", (unsigned int)v2);
perror(&s);
exit(5);
}
v5 = v4;
result = v3;
if ( v3 > a2 )
result = a2;
v20 = 0;
v19 = result;
v26 = a2 - result;
if ( pbm_ysize <= 0 )
return result;
do
{
for ( i = 0; v2 > (int)i; i += v8 )
{
v8 = read(fd, &v5[i], (int)(v2 - i));
if ( !v8 )
return fprintf(stderr, "line %d: want %d, got %d bytes, EOF", (unsigned int)v20, (unsigned int)v2, i);
}
if ( v19 <= 0 )
{
v12 = 0;
goto LABEL_26;
}
v9 = v5;
v10 = 7;
v11 = 0;
v12 = 0;
v13 = 0;
do
{
while ( 1 )
{
v16 = *v9;
v17 = (__int64)v10 << 8;
if ( v11 )
break;
v14 = *((char *)&w_rtab + v16 + v17);
v12 += v14;
v15 = (unsigned int)(v10 - v14);
if ( (int)v15 < 0 )
goto LABEL_18;
v24 = v15;
v21 = v9;
putwhitespan(v12);
v9 = v21;
v10 = v24;
LABEL_14:
v13 += v12;
v11 ^= 1u;
v12 = 0;
if ( v19 <= v13 )
goto LABEL_21;
}
v18 = *((char *)&b_rtab + v16 + v17);
v12 += v18;
v15 = (unsigned int)(v10 - v18);
if ( (int)v15 >= 0 )
{
v25 = v15;
v22 = v9;
putblackspan(v12);
v10 = v25;
v9 = v22;
goto LABEL_14;
}
LABEL_18:
if ( (_DWORD)v15 != -1 )
{
v23 = v9;
fprintf(stderr, "bit panic: %d\n", v15);
v9 = v23;
}
++v9;
v10 = 7;
}
while ( v19 > (int)(v13 + v12) );
LABEL_21:
if ( v11 )
{
putblackspan(v12);
putwhitespan(v26);
goto LABEL_23;
}
LABEL_26:
putwhitespan(v26 + v12);
LABEL_23:
puteol();
result = ++v20;
}
while ( pbm_ysize > v20 );
return result;
}

original_code:
void convert_pbm_raw (int fd,int g3_page_width)
{
    extern void make_run_tables (void);
    extern char w_rtab[8][256],
                b_rtab[8][256];
    int x, y, maxx;
    int run, c;
    int bit;
    int ll;
    unsigned char * linebuf, * r;
    make_run_tables();
    pbm_xsize = ( pbm_xsize + 7 ) & ~7;
    ll = pbm_xsize / 8;
    linebuf = (unsigned char *) malloc( ll );
    if ( linebuf == ((void *)0) )
    {
 fprintf( stderr, "cannot malloc %d bytes: ", ll );
 perror( "" );
 exit(5);
    }
    if ( g3_page_width > pbm_xsize ) maxx = pbm_xsize;
                                else maxx = g3_page_width;
    for ( y=0; y<pbm_ysize; y++ )
    {
 int h;
 c = 0;
 run = 0;
 x = 0;
 bit = 7;
 h = 0;
 while ( h < ll )
 {
     int h2;
     h2 = read( fd, linebuf+h, ll-h );
     if ( h2 == 0 )
     {
  fprintf( stderr, "line %d: want %d, got %d bytes, EOF", y, ll, h );
  return;
     }
     h += h2;
 }
 r = linebuf;
 while ( x+run < maxx )
 {
     if ( c == 0 )
     {
  run += w_rtab[ bit ][ *r ];
  bit -= w_rtab[ bit ][ *r ];
     }
     else
     {
  run += b_rtab[ bit ][ *r ];
  bit -= b_rtab[ bit ][ *r ];
     }
     if ( bit < 0 )
     {
  if ( bit != -1 ) fprintf( stderr, "bit panic: %d\n", bit );
  bit = 7;
  r++;
     }
     else
     {
  if ( c == 0 )
      putwhitespan( run );
  else
      putblackspan( run );
                x += run;
  run = 0;
  c = !c;
     }
 }
 if ( c == 0 ) putwhitespan( run + (g3_page_width - maxx) );
 else
 {
     putblackspan( run );
     putwhitespan( g3_page_width - maxx );
 }
        puteol();
    }
}

canonical_original_code:
void convert_pbm_raw(int fd, int g3_page_width)
{
    extern void make_run_tables();
    extern char w_rtab[8][256]; extern char b_rtab[8][256];
    int x; int y; int maxx;
    int run; int c;
    int bit;
    int ll;
    unsigned char *linebuf; unsigned char *r;
    make_run_tables();
    pbm_xsize = ( pbm_xsize + 7 ) & ~7;
    ll = pbm_xsize / 8;
    linebuf = (unsigned char *) malloc( ll );
    if ( linebuf == ((void *)0) )
    {
 fprintf( stderr, "cannot malloc %d bytes: ", ll );
 perror( "" );
 exit(5);
    }
    if ( g3_page_width > pbm_xsize ) maxx = pbm_xsize;
                                else maxx = g3_page_width;
    for ( y=0; y<pbm_ysize; y++ )
    {
 int h;
 c = 0;
 run = 0;
 x = 0;
 bit = 7;
 h = 0;
 while ( h < ll )
 {
     int h2;
     h2 = read( fd, linebuf+h, ll-h );
     if ( h2 == 0 )
     {
  fprintf( stderr, "line %d: want %d, got %d bytes, EOF", y, ll, h );
  return;
     }
     h += h2;
 }
 r = linebuf;
 while ( x+run < maxx )
 {
     if ( c == 0 )
     {
  run += w_rtab[ bit ][ *r ];
  bit -= w_rtab[ bit ][ *r ];
     }
     else
     {
  run += b_rtab[ bit ][ *r ];
  bit -= b_rtab[ bit ][ *r ];
     }
     if ( bit < 0 )
     {
  if ( bit != -1 ) fprintf( stderr, "bit panic: %d\n", bit );
  bit = 7;
  r++;
     }
     else
     {
  if ( c == 0 )
      putwhitespan( run );
  else
      putblackspan( run );
                x += run;
  run = 0;
  c = !c;
     }
 }
 if ( c == 0 ) putwhitespan( run + (g3_page_width - maxx) );
 else
 {
     putblackspan( run );
     putwhitespan( g3_page_width - maxx );
 }
        puteol();
    }
}

variable_types: x int

variable_types: y int

variable_types: maxx int

variable_types: run int

variable_types: c int

variable_types: bit int

variable_types: ll int

variable_types:
linebuf
unsigned char *

variable_types:
r
unsigned char *


decompiled_code:
void __fastcall __noreturn exit_usage(const char *a1)
{
fprintf(stderr, "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n", a1);
exit(1);
}

original_code:
void exit_usage (char * name)
{
    fprintf( stderr,
      "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n",
       name );
    exit(1);
}

canonical_original_code:
void exit_usage(char *name)
{
    fprintf( stderr,
      "usage: %s [-w width] [-h blank_lines] [-d] [-a] [-r] [pbm file]\n",
       name );
    exit(1);
}

variable_types:
name
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
__int64 v6; // rdx
int v7; // er15
int v8; // er14
int i; // ebx
char *file; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 1728;
init_byte_tab(0LL, &out_byte_tab, envp);
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "h:w:dar");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'a':
byte_align = 1;
continue;
case 'd':
continue;
case 'h':
v3 = atoi(optarg);
continue;
case 'r':
init_byte_tab(1LL, &out_byte_tab, v6);
continue;
case 'w':
v4 = atoi(optarg);
continue;
default:
goto LABEL_7;
}
}
break;
}
v7 = optind;
if ( optind == argc )
{
v8 = 0;
}
else
{
file = (char *)argv[optind];
v8 = strcmp(file, "-");
if ( v8 )
{
if ( v7 != argc - 1 )
LABEL_7:
exit_usage(*argv);
v8 = open(file, 0);
if ( v8 == -1 )
{
fprintf(stderr, "%s: cannot open %s: ", *argv, argv[optind]);
perror(&s);
exit(2);
}
}
}
pbm_getheader(v8);
if ( pbm_type )
{
if ( pbm_xsize != -1 && pbm_ysize != -1 )
{
if ( pbm_type == 2 || pbm_type == 5 )
{
fprintf(stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", *argv);
}
else
{
if ( pbm_type != 3 && pbm_type != 6 )
{
if ( !v4 )
v4 = pbm_xsize;
if ( pbm_type == 4 && (int)((pbm_xsize + 7) & 0xFFFFFFF8) > v4 )
v4 = (v4 + 7) & 0xFFFFFFF8;
puteol();
for ( i = 0; i < v3; ++i )
{
putwhitespan((unsigned int)v4);
puteol();
}
if ( pbm_type == 1 )
convert_pbm(v8, v4);
else
convert_pbm_raw(v8, v4);
close(v8);
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
write(1, &buf, buflen);
exit(0);
}
fprintf(stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", *argv);
}
exit(3);
}
fprintf(stderr, "%s: error reading PBM header\n", *argv);
exit(4);
}
fprintf(stderr, "%s: input file type unknown\n", *argv);
exit(3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
__int64 v6; // rdx
int v7; // er15
int v8; // er14
int i; // ebx
char *file; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 1728;
init_byte_tab(0LL, &out_byte_tab, envp);
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "h:w:dar");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'a':
byte_align = 1;
continue;
case 'd':
continue;
case 'h':
v3 = atoi(optarg);
continue;
case 'r':
init_byte_tab(1LL, &out_byte_tab, v6);
continue;
case 'w':
v4 = atoi(optarg);
continue;
default:
goto LABEL_7;
}
}
break;
}
v7 = optind;
if ( optind == argc )
{
v8 = 0;
}
else
{
file = (char *)argv[optind];
v8 = strcmp(file, "-");
if ( v8 )
{
if ( v7 != argc - 1 )
LABEL_7:
func2(*argv);
v8 = open(file, 0);
if ( v8 == -1 )
{
fprintf(stderr, "%s: cannot open %s: ", *argv, argv[optind]);
perror(&s);
exit(2);
}
}
}
func1(v8);
if ( pbm_type )
{
if ( pbm_xsize != -1 && pbm_ysize != -1 )
{
if ( pbm_type == 2 || pbm_type == 5 )
{
fprintf(stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", *argv);
}
else
{
if ( pbm_type != 3 && pbm_type != 6 )
{
if ( !v4 )
v4 = pbm_xsize;
if ( pbm_type == 4 && (int)((pbm_xsize + 7) & 0xFFFFFFF8) > v4 )
v4 = (v4 + 7) & 0xFFFFFFF8;
puteol();
for ( i = 0; i < v3; ++i )
{
putwhitespan((unsigned int)v4);
puteol();
}
if ( pbm_type == 1 )
func4(v8, v4);
else
func3(v8, v4);
close(v8);
puteol();
puteol();
puteol();
puteol();
puteol();
puteol();
write(1, &buf, buflen);
exit(0);
}
fprintf(stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", *argv);
}
exit(3);
}
fprintf(stderr, "%s: error reading PBM header\n", *argv);
exit(4);
}
fprintf(stderr, "%s: input file type unknown\n", *argv);
exit(3);
}

original_code:
int main (int argc,char ** argv)
{
    int c, fd, i;
    int empty_lines = 0;
    int g3_page_width = 1728;
    int digifax_header = 0;
    init_byte_tab( 0, out_byte_tab );
    while ( (c = getopt(argc, argv, "h:w:dar") ) != (-1))
    {
 switch (c)
 {
   case 'h': empty_lines = atoi( optarg ); break;
   case 'w': g3_page_width = atoi( optarg ); break;
   case 'd': digifax_header = 1; break;
   case 'a': byte_align = 1; break;
   case 'r': init_byte_tab( 1, out_byte_tab ); break;
   default: exit_usage( argv[0] );
 }
    }
    if ( optind == argc ||
  strcmp( argv[optind], "-" ) == 0 )
    {
 fd = 0;
    }
    else
    {
 if ( optind != argc -1 ) exit_usage( argv[0] );
 fd = open( argv[optind], 00 );
 if ( fd == -1 )
 {
     fprintf( stderr, "%s: cannot open %s: ", argv[0], argv[optind] );
     perror( "" );
     exit(2);
 }
    }
    pbm_getheader( fd );
    if ( pbm_type == unknown )
    {
 fprintf( stderr, "%s: input file type unknown\n", argv[0] );
 exit(3);
    }
    if ( pbm_xsize == -1 || pbm_ysize == -1 )
    {
 fprintf( stderr, "%s: error reading PBM header\n", argv[0] );
 exit(4);
    }
    if ( pbm_type == pgm || pbm_type == pgm_raw )
    {
 fprintf( stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( pbm_type == ppm || pbm_type == ppm_raw )
    {
 fprintf( stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( g3_page_width == 0 ) g3_page_width = pbm_xsize;
    if ( pbm_type == pbm_raw && g3_page_width < ( ( pbm_xsize+7 ) & ~7) )
    {
 g3_page_width = ( g3_page_width + 7 ) & ~7;
    }
    puteol();
    for ( i=0; i<empty_lines; i++ )
    {
 putwhitespan( g3_page_width ); puteol();
    }
    if ( pbm_type == pbm )
    {
 convert_pbm( fd, g3_page_width );
    }
    else
    {
 convert_pbm_raw( fd, g3_page_width );
    }
    close( fd );
    for ( i=0; i<6; i++ ) puteol();
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int c; int fd; int i;
    int empty_lines = 0;
    int g3_page_width = 1728;
    int digifax_header = 0;
    init_byte_tab( 0, out_byte_tab );
    while ( (c = getopt(argc, argv, "h:w:dar") ) != (-1))
    {
 switch (c)
 {
   case 'h': empty_lines = atoi( optarg ); break;
   case 'w': g3_page_width = atoi( optarg ); break;
   case 'd': digifax_header = 1; break;
   case 'a': byte_align = 1; break;
   case 'r': init_byte_tab( 1, out_byte_tab ); break;
   default: exit_usage( argv[0] );
 }
    }
    if ( optind == argc ||
  strcmp( argv[optind], "-" ) == 0 )
    {
 fd = 0;
    }
    else
    {
 if ( optind != argc -1 ) exit_usage( argv[0] );
 fd = open( argv[optind], 00 );
 if ( fd == -1 )
 {
     fprintf( stderr, "%s: cannot open %s: ", argv[0], argv[optind] );
     perror( "" );
     exit(2);
 }
    }
    pbm_getheader( fd );
    if ( pbm_type == unknown )
    {
 fprintf( stderr, "%s: input file type unknown\n", argv[0] );
 exit(3);
    }
    if ( pbm_xsize == -1 || pbm_ysize == -1 )
    {
 fprintf( stderr, "%s: error reading PBM header\n", argv[0] );
 exit(4);
    }
    if ( pbm_type == pgm || pbm_type == pgm_raw )
    {
 fprintf( stderr, "%s: portable greymaps (pgm) not supported, use ``pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( pbm_type == ppm || pbm_type == ppm_raw )
    {
 fprintf( stderr, "%s: portable pixmap (ppm) not supported, use ``ppmtopgm | pgmtopbm'' first.\n", argv[0] );
 exit(3);
    }
    if ( g3_page_width == 0 ) g3_page_width = pbm_xsize;
    if ( pbm_type == pbm_raw && g3_page_width < ( ( pbm_xsize+7 ) & ~7) )
    {
 g3_page_width = ( g3_page_width + 7 ) & ~7;
    }
    puteol();
    for ( i=0; i<empty_lines; i++ )
    {
 putwhitespan( g3_page_width ); puteol();
    }
    if ( pbm_type == pbm )
    {
 convert_pbm( fd, g3_page_width );
    }
    else
    {
 convert_pbm_raw( fd, g3_page_width );
    }
    close( fd );
    for ( i=0; i<6; i++ ) puteol();
    if ( out_hibit != 0 )
        buf[buflen++] = out_byte_tab[out_data & 0xff];
    write( 1, buf, buflen );
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall conf_get_flow(const char *a1, __int64 a2)
{
int v2; // er8
bool v5; // zf
__int64 result; // rax

v2 = *(unsigned __int8 *)a1;
if ( v2 == 114 && a1[1] == 116 && a1[2] == 115 || !memcmp(a1, "hard", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 1LL;
result = 0LL;
}
else if ( v2 == 120 && a1[1] == 111 && a1[2] == 110 || !memcmp(a1, "soft", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 6LL;
result = 0LL;
}
else
{
v5 = strcmp(a1, "both") == 0;
result = !v5;
if ( v5 )
{
*(_QWORD *)(a2 + 8) = 7LL;
}
else
{
v5 = strcmp(a1, "none") == 0;
result = !v5;
if ( v5 )
{
*(_QWORD *)(a2 + 8) = 0LL;
}
else
{
lprintf(3LL, "conf_get_flow: unknown keyword '%s'", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
int v2; // er8
bool v5; // zf
__int64 result; // rax

v2 = *(unsigned __int8 *)a1;
if ( v2 == 114 && a1[1] == 116 && a1[2] == 115 || !memcmp(a1, "hard", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 1LL;
result = 0LL;
}
else if ( v2 == 120 && a1[1] == 111 && a1[2] == 110 || !memcmp(a1, "soft", 4uLL) )
{
*(_QWORD *)(a2 + 8) = 6LL;
result = 0LL;
}
else
{
v5 = strcmp(a1, "both") == 0;
result = !v5;
if ( v5 )
{
*(_QWORD *)(a2 + 8) = 7LL;
}
else
{
v5 = strcmp(a1, "none") == 0;
result = !v5;
if ( v5 )
{
*(_QWORD *)(a2 + 8) = 0LL;
}
else
{
lprintf(3LL, "conf_get_flow: unknown keyword '%s'", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int conf_get_flow (char * line,conf_data * cp)
{
    if ( strncmp( line, "rts", 3 ) == 0 ||
  strncmp( line, "hard", 4 ) == 0 )
    {
 cp->d.i = 0x01; return 0;
    }
    if ( strncmp( line, "xon", 3 ) == 0 ||
         strncmp( line, "soft", 4 ) == 0 )
    {
 cp->d.i = (0x02 | 0x04); return 0;
    }
    if ( strcmp( line, "both" ) == 0 )
    {
 cp->d.i = (0x01 | (0x02 | 0x04) ); return 0;
    }
    if ( strcmp( line, "none" ) == 0 )
    {
 cp->d.i = 0x00; return 0;
    }
    lprintf( 3, "conf_get_flow: unknown keyword '%s'", line);
    return -1;
}

canonical_original_code:
int conf_get_flow(char *line, struct conf_data *cp)
{
    if ( strncmp( line, "rts", 3 ) == 0 ||
  strncmp( line, "hard", 4 ) == 0 )
    {
 cp->d.i = 0x01; return 0;
    }
    if ( strncmp( line, "xon", 3 ) == 0 ||
         strncmp( line, "soft", 4 ) == 0 )
    {
 cp->d.i = (0x02 | 0x04); return 0;
    }
    if ( strcmp( line, "both" ) == 0 )
    {
 cp->d.i = (0x01 | (0x02 | 0x04) ); return 0;
    }
    if ( strcmp( line, "none" ) == 0 )
    {
 cp->d.i = 0x00; return 0;
    }
    lprintf( 3, "conf_get_flow: unknown keyword '%s'", line);
    return -1;
}

variable_types:
line
char *

variable_types: struct conf_data { char *key; union { long i; void *p; } d; enum { CT_INT=0, CT_STRING=1, CT_CHAT=2, CT_BOOL=3, CT_FLOWL=4, CT_ACTION=5, CT_KEYWORD=6 } type; enum { C_EMPTY=0, C_PRESET=1, C_OVERRIDE=2, C_CONF=3, C_IGNORE=4 } flags; } *


decompiled_code:
void __fastcall display_cd(const char **a1)
{
const char *v1; // rdx
const char **v2; // rbx
int v3; // eax
const char *v4; // rsi
const char *v5; // rbp
__int64 i; // rsi
char v7[136]; // [rsp-88h] [rbp-88h] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
lprintf(5LL, "key: '%s', type=%d, flags=%d, data=", v1, *((unsigned int *)v2 + 4), *((unsigned int *)v2 + 5));
v3 = *((_DWORD *)v2 + 5);
if ( v3 )
{
if ( v3 == 4 )
{
lputs(5LL, "(ignored)");
}
else
{
switch ( *((_DWORD *)v2 + 4) )
{
case 0:
case 4:
sprintf(v7, "%ld", v2[1]);
lputs(5LL, v7);
break;
case 1:
lputs(5LL, v2[1]);
break;
case 2:
v5 = v2[1];
for ( i = *(_QWORD *)v5; *(_QWORD *)v5; i = *(_QWORD *)v5 )
{
v5 += 8;
lputs(5LL, i);
lputc(5LL, 32LL);
}
break;
case 3:
v4 = "FALSE";
if ( v2[1] )
v4 = "TRUE";
lputs(5LL, v4);
break;
default:
lputs(5LL, "**unprintable**");
break;
}
}
}
else
{
lputs(5LL, "(empty)");
}
v1 = v2[3];
v2 += 3;
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(const char **a1)
{
const char *v1; // rdx
const char **v2; // rbx
int v3; // eax
const char *v4; // rsi
const char *v5; // rbp
__int64 i; // rsi
char v7[136]; // [rsp-88h] [rbp-88h] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
lprintf(5LL, "key: '%s', type=%d, flags=%d, data=", v1, *((unsigned int *)v2 + 4), *((unsigned int *)v2 + 5));
v3 = *((_DWORD *)v2 + 5);
if ( v3 )
{
if ( v3 == 4 )
{
lputs(5LL, "(ignored)");
}
else
{
switch ( *((_DWORD *)v2 + 4) )
{
case 0:
case 4:
sprintf(v7, "%ld", v2[1]);
lputs(5LL, v7);
break;
case 1:
lputs(5LL, v2[1]);
break;
case 2:
v5 = v2[1];
for ( i = *(_QWORD *)v5; *(_QWORD *)v5; i = *(_QWORD *)v5 )
{
v5 += 8;
lputs(5LL, i);
lputc(5LL, 32LL);
}
break;
case 3:
v4 = "FALSE";
if ( v2[1] )
v4 = "TRUE";
lputs(5LL, v4);
break;
default:
lputs(5LL, "**unprintable**");
break;
}
}
}
else
{
lputs(5LL, "(empty)");
}
v1 = v2[3];
v2 += 3;
}
while ( v1 );
}
}

original_code:
void display_cd (conf_data * cd)
{
conf_data * cp;
char ** p;
    cp = cd;
    while ( cp->key != ((void *)0) )
    {
    char buf[100];
 lprintf( 5, "key: '%s', type=%d, flags=%d, data=",
  cp->key, cp->type, cp->flags );
 if ( cp->flags == C_EMPTY )
  lputs( 5, "(empty)" );
 else
 if ( cp->flags == C_IGNORE )
  lputs( 5, "(ignored)" );
 else
   switch ( cp->type )
 {
     case CT_FLOWL:
     case CT_INT: sprintf( buf, "%ld", cp->d.i );
    lputs( 5, buf );
    break;
     case CT_STRING:
    lputs( 5, (char *) cp->d.p );
    break;
     case CT_BOOL:
    lputs( 5, cp->d.i ? "TRUE" : "FALSE" );
    break;
     case CT_CHAT:
    p = (char **) cp->d.p;
    while ( *p != ((void *)0) )
    {
        lputs( 5, *p ); lputc( 5, ' ');
        p++;
    }
    break;
     default:
    lputs( 5, "**unprintable**" );
    break;
 }
 cp++;
    }
}

canonical_original_code:
void display_cd(struct conf_data *cd)
{
struct conf_data *cp;
char **p;
    cp = cd;
    while ( cp->key != ((void *)0) )
    {
    char buf[100];
 lprintf( 5, "key: '%s', type=%d, flags=%d, data=",
  cp->key, cp->type, cp->flags );
 if ( cp->flags == C_EMPTY )
  lputs( 5, "(empty)" );
 else
 if ( cp->flags == C_IGNORE )
  lputs( 5, "(ignored)" );
 else
   switch ( cp->type )
 {
     case CT_FLOWL:
     case CT_INT: sprintf( buf, "%ld", cp->d.i );
    lputs( 5, buf );
    break;
     case CT_STRING:
    lputs( 5, (char *) cp->d.p );
    break;
     case CT_BOOL:
    lputs( 5, cp->d.i ? "TRUE" : "FALSE" );
    break;
     case CT_CHAT:
    p = (char **) cp->d.p;
    while ( *p != ((void *)0) )
    {
        lputs( 5, *p ); lputc( 5, ' ');
        p++;
    }
    break;
     default:
    lputs( 5, "**unprintable**" );
    break;
 }
 cp++;
    }
}

variable_types:
p
char **

variable_types:
buf
char [100]

user_defined_types: struct conf_data { char *key; union { long i; void *p; } d; enum { CT_INT=0, CT_STRING=1, CT_CHAT=2, CT_BOOL=3, CT_FLOWL=4, CT_ACTION=5, CT_KEYWORD=6 } type; enum { C_EMPTY=0, C_PRESET=1, C_OVERRIDE=2, C_CONF=3, C_IGNORE=4 } flags; }


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

reset_watchdog();
sprintf(v2, "AT#CLS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

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

reset_watchdog();
sprintf(v2, "AT#CLS=%s", a1);
return (unsigned int)-((unsigned int)voice_command(v2, "OK") != 4096);
}

original_code:
int UMC_switch_to_data_fax(char *mode)
     {
     char buffer[(256)];
     reset_watchdog();
     sprintf(buffer, "AT#CLS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int UMC_switch_to_data_fax(char *mode)
     {
     char buffer[-1];
     reset_watchdog();
     sprintf(buffer, "AT#CLS=%s", mode);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types:
mode
char *

variable_types:
buffer
char [-1]


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

reset_watchdog();
if ( current_device != a1 && current_device >= 0 )
voice_command("ATH0", "VCON|OK");
current_device = a1;
voice_command("AT#CLS=8", "OK");
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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

reset_watchdog();
if ( current_device != a1 && current_device >= 0 )
voice_command("ATH0", "VCON|OK");
current_device = a1;
voice_command("AT#CLS=8", "OK");
switch ( a1 )
{
case 1u:
voice_command("AT#VLS=0", "OK");
result = 0LL;
break;
case 2u:
voice_command("AT#VLS=4", "OK");
result = 0LL;
break;
case 3u:
voice_command("AT#VLS=3", "VCON");
result = 0LL;
break;
case 6u:
voice_command("AT#VLS=2", "VCON");
result = 0LL;
break;
case 7u:
voice_command("AT#VLS=1", "VCON");
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 UMC_set_device(int device)
     {
     reset_watchdog();
     if ((current_device != device) && (current_device >= 0))
          voice_command("ATH0","VCON|OK");
     current_device=device;
     voice_command("AT#CLS=8", "OK");
     switch (device)
          {
          case (0x0001):
               voice_command("AT#VLS=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT#VLS=4", "OK");
               return((0));
          case (0x0003):
               voice_command("AT#VLS=3", "VCON");
               return((0));
          case (0x0006):
               voice_command("AT#VLS=2", "VCON");
               return((0));
          case (0x0007):
               voice_command("AT#VLS=1","VCON");
               return((0));
          }
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

variable_types: device int


decompiled_code:
__int64 __fastcall UMC_set_compression(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdx
const char *v5; // rdi

reset_watchdog();
v4 = *a1;
if ( !*a1 )
{
*a1 = 4LL;
if ( *a2 )
goto LABEL_11;
goto LABEL_3;
}
if ( !*a2 )
{
LABEL_3:
*a2 = 7200LL;
v4 = *a1;
}
switch ( v4 )
{
case 3LL:
*a3 = 3;
v5 = "AT#VBS=3";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
case 4LL:
LABEL_11:
*a3 = 4;
v5 = "AT#VBS=4";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
case 2LL:
*a3 = 2;
v5 = "AT#VBS=2";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
}
lprintf(3LL, "UMC handle event: Illegal voice compression method (%d)", v4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdx
const char *v5; // rdi

reset_watchdog();
v4 = *a1;
if ( !*a1 )
{
*a1 = 4LL;
if ( *a2 )
goto LABEL_11;
goto LABEL_3;
}
if ( !*a2 )
{
LABEL_3:
*a2 = 7200LL;
v4 = *a1;
}
switch ( v4 )
{
case 3LL:
*a3 = 3;
v5 = "AT#VBS=3";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
case 4LL:
LABEL_11:
*a3 = 4;
v5 = "AT#VBS=4";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
case 2LL:
*a3 = 2;
v5 = "AT#VBS=2";
return (unsigned int)-((unsigned int)voice_command(v5, "OK") != 4096);
}
lprintf(3LL, "UMC handle event: Illegal voice compression method (%d)", v4);
return 0xFFFFFFFFLL;
}

original_code:
static int UMC_set_compression(p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 7200;
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 3:
               *bits=3;
               if (voice_command("AT#VBS=3", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "UMC handle event: Illegal voice compression method (%d)",
      (int)*compression);
     return((-1));
     }

canonical_original_code:
static int UMC_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 4;
     if (*speed == 0)
          *speed = 7200;
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 3:
               *bits=3;
               if (voice_command("AT#VBS=3", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "UMC handle event: Illegal voice compression method (%d)",
      (int)*compression);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


decompiled_code:
__int64 __fastcall UMC_beep(unsigned int a1, int a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( a2 > 4000 )
lprintf(
3LL,
"%s->%s: Warning beeps longer than 4000 ms might not be supported.",
program_name,
(const char *)*voice_modem);
lprintf(
6LL,
"%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
program_name,
(const char *)*voice_modem);
sprintf(v3, "AT#VTS=[%d,0,%d]", a1, (unsigned int)(a2 / 100));
return (unsigned int)-((unsigned int)voice_command(v3, "OK") != 4096);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

reset_watchdog();
if ( a2 > 4000 )
lprintf(
3LL,
"%s->%s: Warning beeps longer than 4000 ms might not be supported.",
program_name,
(const char *)*voice_modem);
lprintf(
6LL,
"%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
program_name,
(const char *)*voice_modem);
sprintf(v3, "AT#VTS=[%d,0,%d]", a1, (unsigned int)(a2 / 100));
return (unsigned int)-((unsigned int)voice_command(v3, "OK") != 4096);
}

original_code:
static int UMC_beep(int frequency, int length)
     {
     char buffer[(256)];
     reset_watchdog();
     if (length > 4000 )
          lprintf(3, "%s->%s: Warning beeps longer than 4000 ms might not be supported.",
    program_name, voice_modem->name);
     lprintf(6, "%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
      program_name, voice_modem->name);
     sprintf(buffer, "AT#VTS=[%d,0,%d]", frequency, length / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
static int UMC_beep(int frequency, int length)
     {
     char buffer[-1];
     reset_watchdog();
     if (length > 4000 )
          lprintf(3, "%s->%s: Warning beeps longer than 4000 ms might not be supported.",
    program_name, voice_modem->name);
     lprintf(6, "%s->%s: Some UMC modems beep with fixed frequency. This is a not a software bug.",
      program_name, voice_modem->name);
     sprintf(buffer, "AT#VTS=[%d,0,%d]", frequency, length / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          return((-1));
     return((0));
     }

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 UMC_init()
{
__int64 v0; // rdx
unsigned __int64 v1; // rax
__int64 result; // rax
_BYTE v3[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing UMC voice modem");
v0 = *((unsigned int *)&cvd + 110);
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", v0);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v1 = *((_QWORD *)&cvd + 58);
if ( v1 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * v1) / 0x64uLL);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v3);
tio_set_flow_control(voice_fd, v3, 1LL);
tio_set(voice_fd, v3);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rdx
unsigned __int64 v1; // rax
__int64 result; // rax
_BYTE v3[64]; // [rsp+0h] [rbp-148h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

reset_watchdog();
lprintf(4LL, "initializing UMC voice modem");
v0 = *((unsigned int *)&cvd + 110);
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", v0);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
if ( (unsigned int)voice_command("AT#VSD=0", "OK") != 4096 )
lprintf(3LL, "can't disable silence deletion");
if ( (unsigned int)voice_command("AT#VTD=3F,3F,3F", "OK") != 4096 )
lprintf(3LL, "can't set DLE responses");
v1 = *((_QWORD *)&cvd + 58);
if ( v1 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * v1) / 0x64uLL);
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT\\Q3", "OK") == 4096 )
{
tio_get(voice_fd, v3);
tio_set_flow_control(voice_fd, v3, 1LL);
tio_set(voice_fd, v3);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

original_code:
static int UMC_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     lprintf(4, "initializing UMC voice modem");
     voice_modem_state = (0x0002);
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period");
     if (voice_command("AT#VSD=0", "OK") != (0x1000))
         lprintf(3, "can't disable silence deletion");
    if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
         lprintf(3, "can't set DLE responses");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          TIO tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int UMC_init()
     {
     char buffer[-1];
     reset_watchdog();
     lprintf(4, "initializing UMC voice modem");
     voice_modem_state = (0x0002);
     sprintf(buffer, "AT#VSP=%1u", (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence period");
     if (voice_command("AT#VSD=0", "OK") != (0x1000))
         lprintf(3, "can't disable silence deletion");
    if (voice_command("AT#VTD=3F,3F,3F", "OK") != (0x1000))
         lprintf(3, "can't set DLE responses");
     if ((cvd.rec_silence_threshold.d.i > 100) ||
      (cvd.rec_silence_threshold.d.i < 0))
          {
          lprintf(3, "Invalid threshold value.");
          return(-1);
          }
     sprintf(buffer, "AT#VSS=%1u", (int)cvd.rec_silence_threshold.d.i * 3 / 100);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "can't set silence threshold");
     if (voice_command("AT\\Q3", "OK") == (0x1000))
          {
          struct termios tio;
          tio_get(voice_fd, &tio);
          tio_set_flow_control(voice_fd, &tio, 0x01);
          tio_set(voice_fd, &tio);
          }
     else
          lprintf(3, "can't turn on hardware flow control");
     voice_modem_state = (0x0001);
     return((0));
     }

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


decompiled_code:
void fax_send_timeout()
{
signal(14, fax_send_timeout);
lprintf(3LL, "fax_send: timeout");
fax_sendpg_timeout = 1;
}

canonical_decompiled_code:
void func0()
{
signal(14, fax_send_timeout);
lprintf(3LL, "fax_send: timeout");
fax_sendpg_timeout = 1;
}

original_code:
static RETSIGTYPE fax_send_timeout()
{
    signal( 14, fax_send_timeout );
    lprintf( 3, "fax_send: timeout" );
    fax_sendpg_timeout = (1==1);
}

canonical_original_code:
static void fax_send_timeout()
{
    signal( 14, fax_send_timeout );
    lprintf( 3, "fax_send: timeout" );
    fax_sendpg_timeout = (1==1);
}


decompiled_code:
void __fastcall __noreturn fax_send_panic_exit(int fd)
{
lprintf(0LL, "PANIC: timeout sending fax page data, trying force modem reset\n");
alarm(5u);
tio_flush_queue((unsigned int)fd, 2LL);
alarm(5u);
tio_flow((unsigned int)fd, 1LL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, "AT+FK\r\n", 7uLL);
alarm(5u);
write(fd, "ATH0\r\n", 6uLL);
alarm(0xAu);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
alarm(5u);
write(fd, "ATH0Z\r\n", 7uLL);
delay(500LL);
alarm(0);
rmlocks();
exit(15);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int fd)
{
lprintf(0LL, "PANIC: timeout sending fax page data, trying force modem reset\n");
alarm(5u);
tio_flush_queue((unsigned int)fd, 2LL);
alarm(5u);
tio_flow((unsigned int)fd, 1LL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, &fax_end_of_page, 2uLL);
alarm(5u);
write(fd, "AT+FK\r\n", 7uLL);
alarm(5u);
write(fd, "ATH0\r\n", 6uLL);
alarm(0xAu);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
tio_toggle_dtr((unsigned int)fd, 500LL);
delay(500LL);
alarm(5u);
write(fd, "ATH0Z\r\n", 7uLL);
delay(500LL);
alarm(0);
rmlocks();
exit(15);
}

original_code:
static void fax_send_panic_exit (int fd)
{
    lprintf( 0, "PANIC: timeout sending fax page data, trying force modem reset\n" );
    alarm( 5 ); tio_flush_queue( fd, 0x02 );
    alarm( 5 ); tio_flow( fd, (1==1) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, "AT+FK\r\n", 7 );
    alarm( 5 ); write( fd, "ATH0\r\n", 6 );
    alarm( 10 );
    tio_toggle_dtr( fd, 500 );
    delay(500);
    tio_toggle_dtr( fd, 500 );
    delay(500);
    alarm( 5 ); write( fd, "ATH0Z\r\n", 7 );
    delay(500);
    alarm( 0 );
    rmlocks();
    exit(15);
}

canonical_original_code:
static void fax_send_panic_exit(int fd)
{
    lprintf( 0, "PANIC: timeout sending fax page data, trying force modem reset\n" );
    alarm( 5 ); tio_flush_queue( fd, 0x02 );
    alarm( 5 ); tio_flow( fd, (1==1) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, fax_end_of_page, sizeof( fax_end_of_page ) );
    alarm( 5 ); write( fd, "AT+FK\r\n", 7 );
    alarm( 5 ); write( fd, "ATH0\r\n", 6 );
    alarm( 10 );
    tio_toggle_dtr( fd, 500 );
    delay(500);
    tio_toggle_dtr( fd, 500 );
    delay(500);
    alarm( 5 ); write( fd, "ATH0Z\r\n", 7 );
    delay(500);
    alarm( 0 );
    rmlocks();
    exit(15);
}

variable_types: fd int


decompiled_code:
__int64 __fastcall fax_send_ppm(int fd, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v6; // er13
char v7; // bp
const char *v8; // rax
const char *v9; // rbp
const char *v10; // rax
int v11; // eax
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

alarm(0x78u);
if ( modem_type == 5 )
{
if ( a3 == 1 )
{
v6 = 59;
v7 = 59;
}
else if ( a3 == 2 )
{
v6 = 46;
tio_carrier(a2, 0LL);
v7 = 46;
tio_set((unsigned int)fd, a2);
}
else
{
if ( a3 )
{
LABEL_5:
lprintf(3LL, "ppm type %d not implemented", a3);
return 0xFFFFFFFFLL;
}
v6 = 44;
v7 = 44;
}
lprintf(4LL, "sending DLE '");
lputc(4LL, v6);
lputc(4LL, 39LL);
buf[0] = 16;
buf[1] = v7;
if ( write(fd, buf, 2uLL) != 2 )
{
lprintf(1LL, "cannot write PPM");
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v8 = (const char *)mdm_get_line((unsigned int)fd);
v9 = v8;
if ( !v8 )
break;
if ( !memcmp(v8, "+FHS:", 5uLL) )
{
fax_hangup = 1;
signal(1, (__sighandler_t)((char *)fax_send_timeout + 1));
_isoc99_sscanf(v9 + 5, "%d", &fax_hangup_code);
lprintf(4LL, "connection hangup: '%s'", v9);
v10 = (const char *)fax_strerror(fax_hangup_code);
lprintf(5LL, "(%s)", v10);
}
if ( *v9 == 79 && v9[1] == 75 && !v9[2] || !strcmp(v9, "ERROR") )
{
lprintf(4LL, "got response: '%s'", v9);
if ( *v9 != 79 || v9[1] != 75 || (v11 = 1, v9[2]) )
v11 = 2;
fax_page_tx_status = v11;
return 0LL;
}
}
return 0xFFFFFFFFLL;
}
lprintf(4LL, "sending DLE ETX...");
write(fd, &fax_end_of_page, 2uLL);
result = fax_wait_for("OK", (unsigned int)fd);
if ( (_DWORD)result != -1 )
{
switch ( a3 )
{
case 1u:
return fax_command("AT+FET=1", "OK", (unsigned int)fd);
case 2u:
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
return fax_command("AT+FET=2", "OK", (unsigned int)fd);
case 0u:
return fax_command("AT+FET=0", "OK", (unsigned int)fd);
}
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v6; // er13
char v7; // bp
const char *v8; // rax
const char *v9; // rbp
const char *v10; // rax
int v11; // eax
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

alarm(0x78u);
if ( modem_type == 5 )
{
if ( a3 == 1 )
{
v6 = 59;
v7 = 59;
}
else if ( a3 == 2 )
{
v6 = 46;
tio_carrier(a2, 0LL);
v7 = 46;
tio_set((unsigned int)fd, a2);
}
else
{
if ( a3 )
{
LABEL_5:
lprintf(3LL, "ppm type %d not implemented", a3);
return 0xFFFFFFFFLL;
}
v6 = 44;
v7 = 44;
}
lprintf(4LL, "sending DLE '");
lputc(4LL, v6);
lputc(4LL, 39LL);
buf[0] = 16;
buf[1] = v7;
if ( write(fd, buf, 2uLL) != 2 )
{
lprintf(1LL, "cannot write PPM");
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v8 = (const char *)mdm_get_line((unsigned int)fd);
v9 = v8;
if ( !v8 )
break;
if ( !memcmp(v8, "+FHS:", 5uLL) )
{
fax_hangup = 1;
signal(1, (__sighandler_t)((char *)fax_send_timeout + 1));
_isoc99_sscanf(v9 + 5, "%d", &fax_hangup_code);
lprintf(4LL, "connection hangup: '%s'", v9);
v10 = (const char *)fax_strerror(fax_hangup_code);
lprintf(5LL, "(%s)", v10);
}
if ( *v9 == 79 && v9[1] == 75 && !v9[2] || !strcmp(v9, "ERROR") )
{
lprintf(4LL, "got response: '%s'", v9);
if ( *v9 != 79 || v9[1] != 75 || (v11 = 1, v9[2]) )
v11 = 2;
fax_page_tx_status = v11;
return 0LL;
}
}
return 0xFFFFFFFFLL;
}
lprintf(4LL, "sending DLE ETX...");
write(fd, &fax_end_of_page, 2uLL);
result = fax_wait_for("OK", (unsigned int)fd);
if ( (_DWORD)result != -1 )
{
switch ( a3 )
{
case 1u:
return fax_command("AT+FET=1", "OK", (unsigned int)fd);
case 2u:
tio_carrier(a2, 0LL);
tio_set((unsigned int)fd, a2);
return fax_command("AT+FET=2", "OK", (unsigned int)fd);
case 0u:
return fax_command("AT+FET=0", "OK", (unsigned int)fd);
}
goto LABEL_5;
}
return result;
}

original_code:
int fax_send_ppm (int fd,TIO * tio,Post_page_messages ppm)
{
    int rc;
    alarm( 120 );
    if ( modem_type == Mt_class2_0 )
    {
 char ppm_char, ppm_buf[2], *ppm_r;
 switch( ppm )
 {
   case pp_mps:
     ppm_char = 0x2c; break;
   case pp_eom:
     ppm_char = 0x3b; break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     ppm_char = 0x2e; break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     return -1;
 }
 lprintf( 4, "sending DLE '" );
 lputc( 4, ppm_char ); lputc( 4, '\'' );
 ppm_buf[0] = 020; ppm_buf[1] = ppm_char;
 if ( write( fd, ppm_buf, 2 ) != 2 )
 {
     lprintf( 1, "cannot write PPM" );
     return -1;
 }
 do
 {
     ppm_r = mdm_get_line( fd );
     if ( ppm_r == ((void *)0) ) return -1;
     if ( strncmp( ppm_r, "+FHS:", 5 ) == 0 )
     {
  fax_hangup = 1;
  signal( 1, ((__sighandler_t) 1) );
  sscanf( &ppm_r[5], "%d", &fax_hangup_code );
  lprintf( 4, "connection hangup: '%s'", ppm_r );
  lprintf( 5,"(%s)", fax_strerror( fax_hangup_code ));
     }
 }
 while ( strcmp( ppm_r, "OK" ) != 0 &&
         strcmp( ppm_r, "ERROR" ) != 0 );
 lprintf( 4, "got response: '%s'", ppm_r );
 fax_page_tx_status = ( strcmp( ppm_r, "OK" ) == 0 ) ? 1: 2;
 return 0;
    }
    else
    {
 lprintf( 4, "sending DLE ETX..." );
 write( fd, fax_end_of_page, sizeof( fax_end_of_page ));
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 switch ( ppm )
 {
   case pp_mps:
     rc = fax_command( "AT+FET=0", "OK", fd );
     break;
   case pp_eom:
     rc = fax_command( "AT+FET=1", "OK", fd );
     break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     rc = fax_command( "AT+FET=2", "OK", fd );
     break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     rc = -1;
 }
 return rc;
    }
}

canonical_original_code:
int fax_send_ppm(int fd, struct termios *tio, enum Post_page_messages ppm)
{
    int rc;
    alarm( 120 );
    if ( modem_type == Mt_class2_0 )
    {
 char ppm_char; char ppm_buf[2]; char *ppm_r;
 switch( ppm )
 {
   case pp_mps:
     ppm_char = 0x2c; break;
   case pp_eom:
     ppm_char = 0x3b; break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     ppm_char = 0x2e; break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     return -1;
 }
 lprintf( 4, "sending DLE '" );
 lputc( 4, ppm_char ); lputc( 4, '\'' );
 ppm_buf[0] = 020; ppm_buf[1] = ppm_char;
 if ( write( fd, ppm_buf, 2 ) != 2 )
 {
     lprintf( 1, "cannot write PPM" );
     return -1;
 }
 do
 {
     ppm_r = mdm_get_line( fd );
     if ( ppm_r == ((void *)0) ) return -1;
     if ( strncmp( ppm_r, "+FHS:", 5 ) == 0 )
     {
  fax_hangup = 1;
  signal( 1, ((void (*)(int)) 1) );
  sscanf( &ppm_r[5], "%d", &fax_hangup_code );
  lprintf( 4, "connection hangup: '%s'", ppm_r );
  lprintf( 5,"(%s)", fax_strerror( fax_hangup_code ));
     }
 }
 while ( strcmp( ppm_r, "OK" ) != 0 &&
         strcmp( ppm_r, "ERROR" ) != 0 );
 lprintf( 4, "got response: '%s'", ppm_r );
 fax_page_tx_status = ( strcmp( ppm_r, "OK" ) == 0 ) ? 1: 2;
 return 0;
    }
    else
    {
 lprintf( 4, "sending DLE ETX..." );
 write( fd, fax_end_of_page, sizeof( fax_end_of_page ));
 if ( fax_wait_for( "OK", fd ) == -1 ) return -1;
 switch ( ppm )
 {
   case pp_mps:
     rc = fax_command( "AT+FET=0", "OK", fd );
     break;
   case pp_eom:
     rc = fax_command( "AT+FET=1", "OK", fd );
     break;
   case pp_eop:
     tio_carrier( tio, (1==0) );
     tio_set( fd, tio );
     rc = fax_command( "AT+FET=2", "OK", fd );
     break;
   default:
     lprintf( 3, "ppm type %d not implemented", ppm );
     rc = -1;
 }
 return rc;
    }
}

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 }

variable_types: rc int