bucleAccept

repo: Dinuuu/SDSockets

decompiled_code:
void __fastcall __noreturn bucleAccept(void *a1)
{
void *v1; // rbp
size_t v2; // rbx
int v3; // eax
int v4; // ebx
__int64 v5; // rax
int v6; // edx
int v7; // er12
_BYTE v8[64]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-48h] BYREF
socklen_t addr_len[11]; // [rsp+5Ch] [rbp-2Ch] BYREF

v1 = 0LL;
while ( 1 )
{
addr_len[0] = 16;
v7 = accept((int)a1, &addr, addr_len);
if ( v7 < 0 )
break;
while ( 1 )
{
v3 = read(v7, v8, 0x40uLL);
v4 = v3;
if ( v3 <= 0 )
break;
v2 = v3;
v1 = realloc(v1, v3);
memcpy(v1, v8, v2);
}
v5 = unMarshallMsg(v1);
v6 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 == 5 )
{
notifi_alta(*(_QWORD *)(v5 + 8));
}
else if ( v6 == 6 )
{
notifi_baja(*(_QWORD *)(v5 + 8));
}
else if ( v6 == 3 )
{
notifi(*(_QWORD *)(v5 + 8), *(_QWORD *)(v5 + 16));
}
if ( v4 < 0 )
{
perror("error en read");
close((int)a1);
close(v7);
pthread_exit(0LL);
}
close(v7);
}
perror("error en accept");
close((int)a1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
void *v1; // rbp
size_t v2; // rbx
int v3; // eax
int v4; // ebx
__int64 v5; // rax
int v6; // edx
int v7; // er12
_BYTE v8[64]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-48h] BYREF
socklen_t addr_len[11]; // [rsp+5Ch] [rbp-2Ch] BYREF

v1 = 0LL;
while ( 1 )
{
addr_len[0] = 16;
v7 = accept((int)a1, &addr, addr_len);
if ( v7 < 0 )
break;
while ( 1 )
{
v3 = read(v7, v8, 0x40uLL);
v4 = v3;
if ( v3 <= 0 )
break;
v2 = v3;
v1 = realloc(v1, v3);
memcpy(v1, v8, v2);
}
v5 = unMarshallMsg(v1);
v6 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 == 5 )
{
notifi_alta(*(_QWORD *)(v5 + 8));
}
else if ( v6 == 6 )
{
notifi_baja(*(_QWORD *)(v5 + 8));
}
else if ( v6 == 3 )
{
notifi(*(_QWORD *)(v5 + 8), *(_QWORD *)(v5 + 16));
}
if ( v4 < 0 )
{
perror("error en read");
close((int)a1);
close(v7);
pthread_exit(0LL);
}
close(v7);
}
perror("error en accept");
close((int)a1);
pthread_exit(0LL);
}

original_code:
void* bucleAccept(void* socket) {
 int socketNum = (int) socket;
 int s_conec, leido;
 unsigned int tam_dir;
 struct sockaddr_in dir_cliente;
 char buf[64];
 char * mensaje = ((void *)0);
 int mensajeLong = 0;
 while (1) {
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(socketNum, (struct sockaddr *) &dir_cliente,
    &tam_dir)) < 0) {
   perror("error en accept");
   close(socketNum);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, mensajeLong + leido * sizeof(char));
   memcpy((void*) mensaje, (void*) buf, leido);
  }
  notif notificacion = unMarshallMsg(mensaje);
  switch (notificacion->opt) {
  case 3:
   (*notifi)(notificacion->tema, notificacion->mensaje);
   break;
  case 5:
   (*notifi_alta)(notificacion->tema);
   break;
  case 6:
   (*notifi_baja)(notificacion->tema);
   break;
  }
  if (leido < 0) {
   perror("error en read");
   close(socketNum);
   close(s_conec);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  close(s_conec);
 }
 close(socketNum);
 pthread_exit(((void *)0) );
 return ((void *)0) ;
}

canonical_original_code:
void *bucleAccept(void *socket) {
 int socketNum = (int) socket;
 int s_conec; int leido;
 unsigned int tam_dir;
 struct sockaddr_in dir_cliente;
 char buf[64];
 char *mensaje = ((void *)0);
 int mensajeLong = 0;
 while (1) {
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(socketNum, (struct sockaddr *) &dir_cliente,
    &tam_dir)) < 0) {
   perror("error en accept");
   close(socketNum);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, mensajeLong + leido * sizeof(char));
   memcpy((void *) mensaje, (void *) buf, leido);
  }
  struct notificacion *notificacion = unMarshallMsg(mensaje);
  switch (notificacion->opt) {
  case 3:
   (*notifi)(notificacion->tema, notificacion->mensaje);
   break;
  case 5:
   (*notifi_alta)(notificacion->tema);
   break;
  case 6:
   (*notifi_baja)(notificacion->tema);
   break;
  }
  if (leido < 0) {
   perror("error en read");
   close(socketNum);
   close(s_conec);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  close(s_conec);
 }
 close(socketNum);
 pthread_exit(((void *)0) );
 return ((void *)0) ;
}

variable_types:
socket
void *

variable_types: socketNum int

variable_types: leido int

variable_types:
buf
char [64]

variable_types:
mensaje
char *

variable_types: mensajeLong int

variable_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } *

return_type: void *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in *cliente; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 fin_subscriptor()
{
if ( !puerto )
return 0xFFFFFFFFLL;
enviarMensaje(4LL);
close(socketAbierto);
socketAbierto = 0;
puerto = 0;
threadId = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( !puerto )
return 0xFFFFFFFFLL;
enviarMensaje(4LL);
close(socketAbierto);
socketAbierto = 0;
puerto = 0;
threadId = 0LL;
return 0LL;
}

original_code:
int fin_subscriptor() {
 if (puerto == 0)
  return -1;
 enviarMensaje(4, puerto);
 close(socketAbierto);
 socketAbierto = 0;
 puerto = 0;
 threadId = 0;
 return 0;
}

return_type: int


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

if ( puerto )
result = enviarMensaje(1LL);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( puerto )
result = enviarMensaje(1LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int alta_subscripcion_tema(const char *tema) {
 if (puerto == 0)
  return -1;
 return enviarMensaje(1, tema, puerto);
}

canonical_original_code:
int alta_subscripcion_tema(char *tema) {
 if (puerto == 0)
  return -1;
 return enviarMensaje(1, tema, puerto);
}

variable_types:
tema
char *


decompiled_code:
__int64 baja_subscripcion_tema()
{
return enviarMensaje(2LL);
}

canonical_decompiled_code:
__int64 func4()
{
return enviarMensaje(2LL);
}

original_code:
int baja_subscripcion_tema(const char *tema) {
 return enviarMensaje(2, tema, puerto);
}

canonical_original_code:
int baja_subscripcion_tema(char *tema) {
 return enviarMensaje(2, tema, puerto);
}


decompiled_code:
__int64 __fastcall inicio_subscriptor(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 (__fastcall *a3)(_QWORD))
{
unsigned int v3; // ebx
int v5; // eax
int v6; // ebp
socklen_t len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-48h] BYREF
int optval; // [rsp+2Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

v3 = puerto;
if ( puerto )
return (unsigned int)-1;
notifi = a1;
notifi_alta = a2;
notifi_baja = a3;
optval = 1;
v5 = socket(2, 1, 6);
v6 = v5;
if ( v5 < 0 )
{
perror("error creando socket");
v3 = 1;
}
else if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
perror("error en setsockopt");
v3 = 1;
}
else
{
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = 0;
addr.sa_family = 2;
if ( bind(v6, &addr, 0x10u) < 0 )
{
perror("error en bind");
close(v6);
v3 = 1;
}
else if ( listen(v6, 64) < 0 )
{
perror("error en listen");
close(v6);
v3 = 1;
}
else
{
len = 16;
getsockname(v6, &v8, &len);
puerto = (unsigned __int16)_bswap_16(*(__int16 *)v8.sa_data);
socketAbierto = v6;
if ( (int)enviarMensaje(7LL) < 0 )
v3 = -1;
else
pthread_create(&threadId, 0LL, (void *(*)(void *))bucleAccept, (void *)v6);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 (__fastcall *a3)(_QWORD))
{
unsigned int v3; // ebx
int v5; // eax
int v6; // ebp
socklen_t len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-48h] BYREF
int optval; // [rsp+2Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

v3 = puerto;
if ( puerto )
return (unsigned int)-1;
notifi = a1;
notifi_alta = a2;
notifi_baja = a3;
optval = 1;
v5 = socket(2, 1, 6);
v6 = v5;
if ( v5 < 0 )
{
perror("error creando socket");
v3 = 1;
}
else if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
perror("error en setsockopt");
v3 = 1;
}
else
{
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = 0;
addr.sa_family = 2;
if ( bind(v6, &addr, 0x10u) < 0 )
{
perror("error en bind");
close(v6);
v3 = 1;
}
else if ( listen(v6, 64) < 0 )
{
perror("error en listen");
close(v6);
v3 = 1;
}
else
{
len = 16;
getsockname(v6, &v8, &len);
puerto = (unsigned __int16)func0(*(__int16 *)v8.sa_data);
socketAbierto = v6;
if ( (int)enviarMensaje(7LL) < 0 )
v3 = -1;
else
pthread_create(&threadId, 0LL, (void *(*)(void *))bucleAccept, (void *)v6);
}
}
return v3;
}

original_code:
int inicio_subscriptor(void (*notif_evento)(const char *, const char *),
  void (*alta_tema)(const char *), void (*baja_tema)(const char *)) {
 if (puerto != 0)
  return -1;
 notifi = notif_evento;
 notifi_alta = alta_tema;
 notifi_baja = baja_tema;
 int s;
 struct sockaddr_in dir;
 int opcion = 1;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 dir.sin_port = 0;
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 struct sockaddr_in aux;
 int tam = sizeof(aux);
 getsockname(s, (void*) &aux, (socklen_t *) &tam);
 puerto = ntohs(aux.sin_port);
 socketAbierto = s;
 if (enviarMensaje(7, puerto) < 0)
  return -1;
 pthread_create(&threadId, ((void *)0), bucleAccept, (void*) s);
 return 0;
}

canonical_original_code:
int inicio_subscriptor(void (*notif_evento)(char *, char *), void (*alta_tema)(char *), void (*baja_tema)(char *)) {
 if (puerto != 0)
  return -1;
 notifi = notif_evento;
 notifi_alta = alta_tema;
 notifi_baja = baja_tema;
 int s;
 struct sockaddr_in dir;
 int opcion = 1;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((unsigned int) 0x00000000);
 dir.sin_port = 0;
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 struct sockaddr_in aux;
 int tam = sizeof(aux);
 getsockname(s, (void *) &aux, (unsigned int *) &tam);
 puerto = ntohs(aux.sin_port);
 socketAbierto = s;
 if (enviarMensaje(7, puerto) < 0)
  return -1;
 pthread_create(&threadId, ((void *)0), bucleAccept, (void *) s);
 return 0;
}

variable_types: s int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: opcion int

variable_types: tam int


decompiled_code:
int __fastcall baja_tema(const char *a1)
{
return printf("\n-> Recibida baja tema %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("\n-> Recibida baja tema %s\n", a1);
}

original_code:
static void baja_tema(const char *t) {
 printf("\n-> Recibida baja tema %s\n", t);
}

canonical_original_code:
static void baja_tema(char *t) {
 printf("\n-> Recibida baja tema %s\n", t);
}

variable_types:
t
char *

return_type: void


decompiled_code:
int __fastcall alta_tema(const char *a1)
{
return printf("\n-> Recibida alta tema %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("\n-> Recibida alta tema %s\n", a1);
}

original_code:
static void alta_tema(const char *t) {
 printf("\n-> Recibida alta tema %s\n", t);
}

canonical_original_code:
static void alta_tema(char *t) {
 printf("\n-> Recibida alta tema %s\n", t);
}


decompiled_code:
int __fastcall notificacion_evento(const char *a1, const char *a2)
{
return printf("\n-> Recibido evento %s con valor %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2)
{
return printf("\n-> Recibido evento %s con valor %s\n", a1, a2);
}

original_code:
static void notificacion_evento(const char *t, const char *e) {
 printf("\n-> Recibido evento %s con valor %s\n", t, e);
}

canonical_original_code:
static void notificacion_evento(char *t, char *e) {
 printf("\n-> Recibido evento %s con valor %s\n", t, e);
}

variable_types:
e
char *


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

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v3, 256, stdin) )
break;
if ( (unsigned int)_isoc99_sscanf(v3, "%u%64s", a1, a2) == 2 && *a1 <= 1u )
return 1LL;
puts("\nError formato de entrada");
}
return 0LL;
}

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

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v3, 256, stdin) )
break;
if ( (unsigned int)_isoc99_sscanf(v3, "%u%64s", a1, a2) == 2 && *a1 <= 1u )
return 1LL;
puts("\nError formato de entrada");
}
return 0LL;
}

original_code:
static _Bool leer_orden(unsigned int *op, char *tema) {
 char linea[256];
 _Bool leido = 0;
 do {
  printf(
    "\nIntroduzca una línea con la operación (0 = alta; 1 = baja) y el tema\n");
  if (fgets(linea, 256, stdin) == ((void *)0) )
   return 0;
  if ((sscanf(linea, "%u%64s", op, tema) == 2) && (*op < 2))
   leido = 1;
  else
   printf("\nError formato de entrada\n");
 } while (!leido);
 return 1;
}

variable_types:
op
unsigned int *

variable_types:
linea
char [256]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[76]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v5[3]; // [rsp+4Ch] [rbp-Ch] BYREF

inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
while ( (unsigned __int8)leer_orden(v5, (__int64)v4) )
{
if ( (int)(*(&ops + v5[0]))(v4) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v5[0]], v4);
}
fin_subscriptor();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[76]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v5[3]; // [rsp+4Ch] [rbp-Ch] BYREF

inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
while ( (unsigned __int8)func3(v5, (__int64)v4) )
{
if ( (int)(*(&ops + v5[0]))(v4) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v5[0]], v4);
}
fin_subscriptor();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 unsigned int op;
 char tema[64];
 inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
 while (leer_orden(&op, tema))
  if (ops[op](tema) < 0)
   fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[op], tema);
 fin_subscriptor();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
op
unsigned int

variable_types:
tema
char [64]


decompiled_code:
__int64 leer_evento()
{
char v1[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v1, 256, _bss_start) )
break;
if ( (unsigned int)__isoc99_sscanf() == 2 )
return 1LL;
puts("\nError formato de entrada");
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
char v1[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v1, 256, _bss_start) )
break;
if ( (unsigned int)__isoc99_sscanf() == 2 )
return 1LL;
puts("\nError formato de entrada");
}
return 0LL;
}

original_code:
static _Bool leer_evento(char *tema, char *valor) {
 char linea[256];
 _Bool leido = 0;
 do {
  printf("\nIntroduzca una línea con el tema y el valor del evento\n");
  if (fgets(linea, 256, stdin) == ((void *)0) )
   return 0;
  if (sscanf(linea, "%64s%64s", tema, valor) == 2)
   leido = 1;
  else
   printf("\nError formato de entrada\n");
 } while (!leido);
 return 1;
}

variable_types:
valor
char *


decompiled_code:
__int64 __fastcall generar_evento(int a1, int a2, __int64 a3, int a4, int a5, int a6)
{
return enviarMensaje(3, a1, a2, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, __int64 a3, int a4, int a5, int a6)
{
return func13(3, a1, a2, a4, a5, a6);
}

original_code:
int generar_evento(const char *tema, const char *valor) {
 return enviarMensaje(3, tema, valor);
}

canonical_original_code:
int generar_evento(char *tema, char *valor) {
 return enviarMensaje(3, tema, valor);
}


decompiled_code:
__int64 __fastcall eliminar_tema(int a1, __int64 a2, int a3, int a4, int a5, int a6)
{
return enviarMensaje(6, a1, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, int a3, int a4, int a5, int a6)
{
return func13(6, a1, a3, a4, a5, a6);
}

original_code:
int eliminar_tema(const char *tema) {
 return enviarMensaje(6, tema);
}

canonical_original_code:
int eliminar_tema(char *tema) {
 return enviarMensaje(6, tema);
}


conectarIntermediario

decompiled_code:
__int64 conectarIntermediario()
{
char *v0; // rbp
char *v1; // rbx
struct hostent *v2; // rax
__int16 v3; // ax
int v4; // eax
unsigned int v5; // ebx
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v0 = getenv("SERVIDOR");
v1 = getenv("PUERTO");
v2 = gethostbyname(v0);
memcpy(&v7[0].sa_data[2], *(const void **)v2->h_addr_list, v2->h_length);
v3 = atoi(v1);
*(_WORD *)v7[0].sa_data = _bswap_16(v3);
v7[0].sa_family = 2;
v4 = socket(2, 1, 6);
if ( v4 < 0 )
{
perror("error creando socket");
v5 = -1;
}
else
{
v5 = v4;
if ( connect(v4, v7, 0x10u) < 0 )
{
perror("error en connect");
close(v5);
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 func12()
{
char *v0; // rbp
char *v1; // rbx
struct hostent *v2; // rax
__int16 v3; // ax
int v4; // eax
unsigned int v5; // ebx
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v0 = getenv("SERVIDOR");
v1 = getenv("PUERTO");
v2 = gethostbyname(v0);
memcpy(&v7[0].sa_data[2], *(const void **)v2->h_addr_list, v2->h_length);
v3 = atoi(v1);
*(_WORD *)v7[0].sa_data = func11(v3);
v7[0].sa_family = 2;
v4 = socket(2, 1, 6);
if ( v4 < 0 )
{
perror("error creando socket");
v5 = -1;
}
else
{
v5 = v4;
if ( connect(v4, v7, 0x10u) < 0 )
{
perror("error en connect");
close(v5);
v5 = -1;
}
}
return v5;
}

original_code:
int conectarIntermediario() {
 struct hostent *host_info;
 char* servidor = getenv("SERVIDOR");
 char* puerto = getenv("PUERTO");
 struct sockaddr_in dir;
 int s;
 host_info = gethostbyname(servidor);
 memcpy(&dir.sin_addr.s_addr, host_info->h_addr_list[0], host_info->h_length);
 dir.sin_port = htons(atoi(puerto));
 dir.sin_family = 2;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return -1;
 }
 if (connect(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en connect");
  close(s);
  return -1;
 }
 return s;
}

canonical_original_code:
int conectarIntermediario() {
 struct hostent *host_info;
 char *servidor = getenv("SERVIDOR");
 char *puerto = getenv("PUERTO");
 struct sockaddr_in dir;
 int s;
 host_info = gethostbyname(servidor);
 memcpy(&dir.sin_addr.s_addr, host_info->h_addr_list[0], host_info->h_length);
 dir.sin_port = htons(atoi(puerto));
 dir.sin_family = 2;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return -1;
 }
 if (connect(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en connect");
  close(s);
  return -1;
 }
 return s;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
servidor
char *

variable_types:
puerto
char *


enviarMensaje

decompiled_code:
__int64 enviarMensaje(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // ebx
int v10; // er12
size_t v11; // r14
_QWORD *v12; // rbp
__int64 v13; // rax
__int64 v14; // rax
int *v15; // rdx
int v16; // er15
_BYTE *v17; // rax
void *v18; // rbp
int v19; // er12
_QWORD *v21; // rcx
gcc_va_list va; // [rsp+8h] [rbp-90h] BYREF
int buf; // [rsp+27h] [rbp-71h] BYREF
int v24; // [rsp+2Ch] [rbp-6Ch] BYREF

v24 = 0;
v9 = conectarIntermediario();
if ( v9 >= 0 )
{
va_start(va, a9);
switch ( a1 )
{
case 1u:
case 2u:
case 5u:
case 6u:
v10 = 1;
goto LABEL_4;
case 3u:
v10 = 2;
LABEL_4:
v11 = v10;
v12 = malloc(v11 * 8);
v13 = 0LL;
do
{
if ( va[0].gp_offset > 0x2F )
{
v21 = va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v21 = (char *)va[0].reg_save_area + va[0].gp_offset;
va[0].gp_offset += 8;
}
v12[v13++] = *v21;
}
while ( v10 > (int)v13 );
break;
case 4u:
case 7u:
v12 = malloc(0LL);
v10 = 0;
v11 = 0LL;
break;
default:
v10 = 0;
v11 = 0LL;
v12 = malloc(0LL);
break;
}
if ( a1 <= 7 )
{
v14 = 150LL;
if ( _bittest64(&v14, a1) )
{
if ( va[0].gp_offset > 0x2F )
v15 = (int *)va[0].overflow_arg_area;
else
v15 = (int *)((char *)va[0].reg_save_area + va[0].gp_offset);
v16 = *v15;
v17 = malloc(5uLL);
*(_DWORD *)v17 = v16;
v17[4] = 0;
v12[v11] = v17;
}
}
v18 = (void *)marshallMsg(a1, v12, (unsigned int)v10, &v24);
if ( write(v9, v18, v24) < 0 )
{
perror("error en write");
close(v9);
free(v18);
v9 = -1;
}
else
{
shutdown(v9, 1);
if ( (int)read(v9, &buf, 5uLL) < 0 )
perror("Error en read de respuesta");
v19 = buf;
close(v9);
free(v18);
v9 = v19;
}
}
return (unsigned int)v9;
}

canonical_decompiled_code:
__int64 func13(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // ebx
int v10; // er12
size_t v11; // r14
_QWORD *v12; // rbp
__int64 v13; // rax
__int64 v14; // rax
int *v15; // rdx
int v16; // er15
_BYTE *v17; // rax
void *v18; // rbp
int v19; // er12
_QWORD *v21; // rcx
gcc_va_list va; // [rsp+8h] [rbp-90h] BYREF
int buf; // [rsp+27h] [rbp-71h] BYREF
int v24; // [rsp+2Ch] [rbp-6Ch] BYREF

v24 = 0;
v9 = func12();
if ( v9 >= 0 )
{
va_start(va, a9);
switch ( a1 )
{
case 1u:
case 2u:
case 5u:
case 6u:
v10 = 1;
goto LABEL_4;
case 3u:
v10 = 2;
LABEL_4:
v11 = v10;
v12 = malloc(v11 * 8);
v13 = 0LL;
do
{
if ( va[0].gp_offset > 0x2F )
{
v21 = va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v21 = (char *)va[0].reg_save_area + va[0].gp_offset;
va[0].gp_offset += 8;
}
v12[v13++] = *v21;
}
while ( v10 > (int)v13 );
break;
case 4u:
case 7u:
v12 = malloc(0LL);
v10 = 0;
v11 = 0LL;
break;
default:
v10 = 0;
v11 = 0LL;
v12 = malloc(0LL);
break;
}
if ( a1 <= 7 )
{
v14 = 150LL;
if ( _bittest64(&v14, a1) )
{
if ( va[0].gp_offset > 0x2F )
v15 = (int *)va[0].overflow_arg_area;
else
v15 = (int *)((char *)va[0].reg_save_area + va[0].gp_offset);
v16 = *v15;
v17 = malloc(5uLL);
*(_DWORD *)v17 = v16;
v17[4] = 0;
v12[v11] = v17;
}
}
v18 = (void *)func14(a1, v12, (unsigned int)v10, &v24);
if ( write(v9, v18, v24) < 0 )
{
perror("error en write");
close(v9);
free(v18);
v9 = -1;
}
else
{
shutdown(v9, 1);
if ( (int)read(v9, &buf, 5uLL) < 0 )
perror("Error en read de respuesta");
v19 = buf;
close(v9);
free(v18);
v9 = v19;
}
}
return (unsigned int)v9;
}

original_code:
void enviarMensaje(int opt, char** argumentos, int cantArgumentos,
  struct sockaddr_in * cliente) {
 int s, longitud;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return;
 }
 if (connect(s, (struct sockaddr *) cliente, sizeof(struct sockaddr_in))
   < 0) {
  perror("error en connect");
  close(s);
  return;
 }
 char* mensajeAEnviar = marshallMsg(opt, argumentos, cantArgumentos,
   &longitud);
 if (write(s, mensajeAEnviar, longitud) < 0) {
  perror("error en write");
  close(s);
  return;
 }
 close(s);
 return;
}

canonical_original_code:
void enviarMensaje(int opt, char **argumentos, int cantArgumentos, struct sockaddr_in *cliente) {
 int s; int longitud;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return;
 }
 if (connect(s, (struct sockaddr *) cliente, sizeof(struct sockaddr_in))
   < 0) {
  perror("error en connect");
  close(s);
  return;
 }
 char *mensajeAEnviar = marshallMsg(opt, argumentos, cantArgumentos,
   &longitud);
 if (write(s, mensajeAEnviar, longitud) < 0) {
  perror("error en write");
  close(s);
  return;
 }
 close(s);
 return;
}

variable_types: opt int

variable_types:
argumentos
char **

variable_types: cantArgumentos int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: longitud int

variable_types:
mensajeAEnviar
char *


conectarIntermediario

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: s int

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-98h] BYREF
char v5[76]; // [rsp+40h] [rbp-58h] BYREF
int v6[3]; // [rsp+8Ch] [rbp-Ch] BYREF

while ( leer_orden(v6) )
{
if ( ((int (__fastcall *)(char *, __int64 *))ops[v6[0]])(v5, &v4) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v6[0]], v5);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-98h] BYREF
char v5[76]; // [rsp+40h] [rbp-58h] BYREF
int v6[3]; // [rsp+8Ch] [rbp-Ch] BYREF

while ( func7(v6) )
{
if ( ((int (__fastcall *)(char *, __int64 *))ops[v6[0]])(v5, &v4) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v6[0]], v5);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 if (argc != 3) {
  perror("La cantidad de argumentos es invalida");
  return 1;
 }
 char * port = argv[1];
 int portInt = atoi(port);
 char* archivo = argv[2];
 lista_temas* listaTemas = inicializar_temas(archivo);
 int s, s_conec, leido;
 unsigned int tam_dir;
 struct sockaddr_in dir, dir_cliente;
 char buf[64];
 char mensajeRsp[5];
 int opcion = 1, resp = -1;
 char* mensaje = ((void *)0);
 int mensajeLong = 0;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 dir.sin_port = htons(portInt);
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 while (1) {
  mensajeLong = 0;
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(s, (struct sockaddr *) &dir_cliente, &tam_dir))
    < 0) {
   perror("error en accept");
   close(s);
   return 1;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, (mensajeLong + leido) * sizeof(char));
   memcpy((void*) (mensaje + mensajeLong), (void*) buf, leido);
   mensajeLong += leido;
  }
  notif notificacion = unMarshallMsg(mensaje);
  struct sockaddr_in peer;
  int tamanio = sizeof(peer);
  if (notificacion->opt == 1 || notificacion->opt == 2
    || notificacion->opt == 7 || notificacion->opt == 4) {
   getpeername(s_conec, (void *) &peer, (socklen_t *) &tamanio);
   notificacion->cliente = &peer;
  }
  resp = procesarNotificacion(notificacion, listaTemas);
  memcpy((void *) mensajeRsp, (void*) &resp, sizeof(int));
  mensajeRsp[4] = 0;
  if (write(s_conec, mensajeRsp, sizeof(int)+sizeof(char)) < 0) {
   free(mensaje);
   perror("error en write");
   close(s);
   close(s_conec);
   return 1;
  }
  close(s_conec);
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc != 3) {
  perror("La cantidad de argumentos es invalida");
  return 1;
 }
 char *port = argv[1];
 int portInt = atoi(port);
 char *archivo = argv[2];
 struct lista_temas *listaTemas = inicializar_temas(archivo);
 int s; int s_conec; int leido;
 unsigned int tam_dir;
 struct sockaddr_in dir; struct sockaddr_in dir_cliente;
 char buf[64];
 char mensajeRsp[5];
 int opcion = 1; int resp = -1;
 char *mensaje = ((void *)0);
 int mensajeLong = 0;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((unsigned int) 0x00000000);
 dir.sin_port = htons(portInt);
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 while (1) {
  mensajeLong = 0;
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(s, (struct sockaddr *) &dir_cliente, &tam_dir))
    < 0) {
   perror("error en accept");
   close(s);
   return 1;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, (mensajeLong + leido) * sizeof(char));
   memcpy((void *) (mensaje + mensajeLong), (void *) buf, leido);
   mensajeLong += leido;
  }
  struct notificacion *notificacion = unMarshallMsg(mensaje);
  struct sockaddr_in peer;
  int tamanio = sizeof(peer);
  if (notificacion->opt == 1 || notificacion->opt == 2
    || notificacion->opt == 7 || notificacion->opt == 4) {
   getpeername(s_conec, (void *) &peer, (unsigned int *) &tamanio);
   notificacion->cliente = &peer;
  }
  resp = procesarNotificacion(notificacion, listaTemas);
  memcpy((void *) mensajeRsp, (void *) &resp, sizeof(int));
  mensajeRsp[4] = 0;
  if (write(s_conec, mensajeRsp, sizeof(int)+sizeof(char)) < 0) {
   free(mensaje);
   perror("error en write");
   close(s);
   close(s_conec);
   return 1;
  }
  close(s_conec);
 }
 close(s);
 return 0;
}

variable_types:
port
char *

variable_types: portInt int

variable_types:
archivo
char *

variable_types: struct lista_temas { struct tema { char *tema; int cantSuscript; struct suscriptor { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } **suscriptores; } **temas; int cant_temas; } *

variable_types: leido int

variable_types:
buf
char [64]

variable_types:
mensajeRsp
char [5]

variable_types: opcion int

variable_types: resp int

variable_types:
mensaje
char *

variable_types: mensajeLong int

variable_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } *

variable_types: tamanio int

user_defined_types: struct lista_temas { struct tema **temas; int cant_temas; }

user_defined_types: struct tema { char *tema; int cantSuscript; struct suscriptor **suscriptores; }

user_defined_types: struct suscriptor { struct sockaddr_in *cliente; }


usage

repo: Distrotech/cyrus-imapd

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

original_code:
static void
usage (void)
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}

canonical_original_code:
static void usage()
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}


decompiled_code:
__int64 __fastcall free_link_data(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

original_code:
static void
free_link_data (gpointer key,
                                 gpointer value,
                                 gpointer data)
{
  GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

canonical_original_code:
static void free_link_data(void *key, void *value, void *data)
{
  struct _GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

variable_types:
key
void *

variable_types:
value
void *

variable_types:
data
void *

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


original_code:
static void
free_rule_array (gpointer key,
                                 gpointer value,
                                 gpointer data)
{
  char *name = key;
  GArray *rule_array = value;
  RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((RuleData*) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

canonical_original_code:
static void free_rule_array(void *key, void *value, void *data)
{
  char *name = key;
  struct _GArray *rule_array = value;
  struct _RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((struct _RuleData *) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

variable_types:
name
char *

variable_types: struct _GArray { char *data; unsigned int len; } *

variable_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; } *

variable_types: i int

user_defined_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; }


original_code:
static void
free_zone_data (GArray *zone_data)
{
  ZoneData *zone;
  ZoneLineData *zone_line;
  int i, j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((ZoneData*) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((ZoneLineData*) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

canonical_original_code:
static void free_zone_data(struct _GArray *zone_data)
{
  struct _ZoneData *zone;
  struct _ZoneLineData *zone_line;
  int i; int j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((struct _ZoneData *) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((struct _ZoneLineData *) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

variable_types: struct _ZoneData { char *zone_name; struct _GArray { char *data; unsigned int len; } *zone_line_data; } *

variable_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } until_time_code; } *

variable_types: j int

user_defined_types: struct _ZoneData { char *zone_name; struct _GArray *zone_line_data; }

user_defined_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode until_time_code; }


decompiled_code:
int __fastcall dump_compare_strings(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
dump_compare_strings (const void *arg1,
                                 const void *arg2)
{
  char **a, **b;
  a = (char**) arg1;
  b = (char**) arg2;
  return strcmp (*a, *b);
}

canonical_original_code:
static int dump_compare_strings(void *arg1, void *arg2)
{
  char **a; char **b;
  a = (char **) arg1;
  b = (char **) arg2;
  return strcmp (*a, *b);
}

variable_types:
a
char **

variable_types:
b
char **


decompiled_code:
__int64 __fastcall dump_add_rule(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

original_code:
static void
dump_add_rule (char *name,
                                 GArray *rule_array,
                                 GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

canonical_original_code:
static void dump_add_rule(char *name, struct _GArray *rule_array, struct _GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

variable_types: struct _GPtrArray { void **pdata; unsigned int len; } *

user_defined_types: struct _GArray { char *data; unsigned int len; }


decompiled_code:
const char *__fastcall dump_time(int a1, int a2, int a3)
{
const char *v5; // r9
const char *v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
unsigned int v9; // eax

v5 = (const char *)&unk_D48;
if ( a2 != 1 )
{
v5 = (const char *)&unk_D4C;
if ( a2 == 2 )
v5 = (const char *)&unk_D4A;
}
v6 = (const char *)&unk_D4C;
if ( a1 < 0 )
{
a1 = -a1;
v6 = "-";
}
sign_4 = (__int64)v6;
v7 = (unsigned int)(a1 / 3600);
v8 = (unsigned int)(a1 % 3600 / 60);
v9 = a1 % 60;
if ( a3 && !((unsigned int)v8 | v9 | (unsigned int)v7) )
return "0";
if ( v9 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v6, v7, v8, v9, v5);
else
sprintf(buffer_3, "%s%i:%02i%s", v6, v7, v8, v5);
return buffer_3;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1, int a2, int a3)
{
const char *v5; // r9
const char *v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
unsigned int v9; // eax

v5 = (const char *)&unk_D48;
if ( a2 != 1 )
{
v5 = (const char *)&unk_D4C;
if ( a2 == 2 )
v5 = (const char *)&unk_D4A;
}
v6 = (const char *)&unk_D4C;
if ( a1 < 0 )
{
a1 = -a1;
v6 = "-";
}
sign_4 = (__int64)v6;
v7 = (unsigned int)(a1 / 3600);
v8 = (unsigned int)(a1 % 3600 / 60);
v9 = a1 % 60;
if ( a3 && !((unsigned int)v8 | v9 | (unsigned int)v7) )
return "0";
if ( v9 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v6, v7, v8, v9, v5);
else
sprintf(buffer_3, "%s%i:%02i%s", v6, v7, v8, v5);
return buffer_3;
}

original_code:
char*
dump_time (int seconds,
                                 TimeCode time_code,
                                 gboolean use_zero)
{
  static char buffer[256], *sign;
  int hours, minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

canonical_original_code:
char *dump_time(int seconds, enum TimeCode time_code, int use_zero)
{
  static char buffer[256]; static char *sign;
  int hours; int minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

variable_types: seconds int

variable_types: enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 }

variable_types:
buffer
char [256]

variable_types:
sign
char *

variable_types: hours int

variable_types: minutes int

variable_types:
code
char *

return_type: char *


decompiled_code:
char *__fastcall dump_day_coded(unsigned int a1, unsigned int a2, int a3)
{
if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
}
else if ( a1 )
{
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
}
else
{
sprintf(buffer_2, "%i", a2);
}
return buffer_2;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1, unsigned int a2, int a3)
{
if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
}
else if ( a1 )
{
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
}
else
{
sprintf(buffer_2, "%i", a2);
}
return buffer_2;
}

original_code:
char*
dump_day_coded (DayCode day_code,
                                 int day_number,
                                 int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
                              "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

canonical_original_code:
char *dump_day_coded(enum DayCode day_code, int day_number, int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
                              "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

variable_types: enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 }

variable_types:
weekdays
char *[]


decompiled_code:
const char *__fastcall dump_year(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

original_code:
char*
dump_year (int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

canonical_original_code:
char *dump_year(int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

variable_types: year int


repo: Distrotech/dmake

decompiled_code:
void malloc_init()
{
char *v0; // rax
int v1; // eax
char *v2; // rax
int v3; // eax
char *v4; // rax
int v5; // eax
char *v6; // rax

if ( !malloc_data_start )
{
malloc_data_start = sbrk(0LL);
malloc_data_end = malloc_data_start;
malloc_start[6] = 0;
malloc_end = malloc_start;
v0 = getenv("MALLOC_WARN");
if ( v0 )
{
v1 = atoi(v0);
mallopt(1, v1);
}
v2 = getenv("MALLOC_FATAL");
if ( v2 )
{
v3 = atoi(v2);
mallopt(2, v3);
}
v4 = getenv("MALLOC_CKCHAIN");
if ( v4 )
{
v5 = atoi(v4);
mallopt(4, v5);
}
v6 = getenv("MALLOC_ERRFILE");
if ( v6 )
mallopt(3, (int)v6);
}
}

canonical_decompiled_code:
void func0()
{
char *v0; // rax
int v1; // eax
char *v2; // rax
int v3; // eax
char *v4; // rax
int v5; // eax
char *v6; // rax

if ( !malloc_data_start )
{
malloc_data_start = sbrk(0LL);
malloc_data_end = malloc_data_start;
malloc_start[6] = 0;
malloc_end = malloc_start;
v0 = getenv("MALLOC_WARN");
if ( v0 )
{
v1 = atoi(v0);
mallopt(1, v1);
}
v2 = getenv("MALLOC_FATAL");
if ( v2 )
{
v3 = atoi(v2);
mallopt(2, v3);
}
v4 = getenv("MALLOC_CKCHAIN");
if ( v4 )
{
v5 = atoi(v4);
mallopt(4, v5);
}
v6 = getenv("MALLOC_ERRFILE");
if ( v6 )
mallopt(3, (int)v6);
}
}

original_code:
void
malloc_init()
{
 char * cptr;
 char * getenv();
 union malloptarg m;
 extern char * malloc_data_end;
 extern char * malloc_data_start;
 extern struct mlist * malloc_end;
 extern struct mlist malloc_start;
 char * sbrk();
 if( malloc_data_start != (char *) 0)
 {
  return;
 }
 malloc_data_start = sbrk(0);
 malloc_data_end = malloc_data_start;
 malloc_start.s.size = 0;
 malloc_end = &malloc_start;
 if( (cptr=getenv("MALLOC_WARN")) != ((void *)0) )
 {
  m.i = atoi(cptr);
  (void) mallopt(1,m);
 }
 if( (cptr=getenv("MALLOC_FATAL")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(2,m);
 }
 if( (cptr=getenv("MALLOC_CKCHAIN")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(4,m);
 }
 if( (cptr=getenv("MALLOC_ERRFILE")) != ((void *)0))
 {
  m.str = cptr;
  (void) mallopt(3,m);
 }
}

canonical_original_code:
void malloc_init()
{
 char *cptr;
 char *getenv();
 union malloptarg m;
 extern char *malloc_data_end;
 extern char *malloc_data_start;
 extern struct mlist *malloc_end;
 extern struct mlist malloc_start;
 char *sbrk();
 if( malloc_data_start != (char *) 0)
 {
  return;
 }
 malloc_data_start = sbrk(0);
 malloc_data_end = malloc_data_start;
 malloc_start.s.size = 0;
 malloc_end = &malloc_start;
 if( (cptr=getenv("MALLOC_WARN")) != ((void *)0) )
 {
  m.i = atoi(cptr);
  (void) mallopt(1,m);
 }
 if( (cptr=getenv("MALLOC_FATAL")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(2,m);
 }
 if( (cptr=getenv("MALLOC_CKCHAIN")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(4,m);
 }
 if( (cptr=getenv("MALLOC_ERRFILE")) != ((void *)0))
 {
  m.str = cptr;
  (void) mallopt(3,m);
 }
}

variable_types:
cptr
char *

variable_types:
getenv
char *()

variable_types:
m
union malloptarg { int i; char *str; }

variable_types: struct mlist { struct mlist *next; struct mlist *prev; int flag; unsigned int r_size; union { unsigned int size; double unused_just_for_alignment; } s; char data[4]; } *

variable_types:
sbrk
char *()


setlink

repo: Distrotech/libdwarf

decompiled_code:
void __fastcall setlink(__int64 a1, int a2, __int64 a3)
{
if ( a2 < 0 )
*(_QWORD *)(a1 + 8) = a3;
else
*(_QWORD *)(a1 + 16) = a3;
}

original_code:
static void
setlink(struct ts_entry*t,int a,struct ts_entry *x)
{
    if(a < 0) {
        t->llink = x;
    } else {
        t->rlink = x;
    }
}

canonical_original_code:
static void setlink(struct ts_entry *t, int a, struct ts_entry *x)
{
    if(a < 0) {
        t->llink = x;
    } else {
        t->rlink = x;
    }
}

variable_types: struct ts_entry { void *keyptr; int balance; struct ts_entry *llink; struct ts_entry *rlink; } *

variable_types: a int

variable_types:
x
struct ts_entry *


getlink

decompiled_code:
__int64 __fastcall getlink(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 < 0 )
result = *(_QWORD *)(a1 + 8);
else
result = *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 < 0 )
result = *(_QWORD *)(a1 + 8);
else
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
static struct ts_entry*
getlink(struct ts_entry*t,int a)
{
    if(a < 0) {
        return(t->llink);
    }
    return(t->rlink);
}

canonical_original_code:
static struct ts_entry *getlink(struct ts_entry *t, int a)
{
    if(a < 0) {
        return(t->llink);
    }
    return(t->rlink);
}

variable_types:
t
struct ts_entry *

return_type: struct ts_entry { void *keyptr; unsigned char color; struct ts_entry *llink; struct ts_entry *rlink; } *


printlevel

decompiled_code:
int __fastcall printlevel(unsigned int a1)
{
int v1; // ebx
int result; // eax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

v1 = snprintf(s, 0xAuLL, "<%d>", a1);
for ( result = printf("%s", s); (int)(a1 + 4) > v1; ++v1 )
result = putchar(32);
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
int v1; // ebx
int result; // eax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

v1 = snprintf(s, 0xAuLL, "<%d>", a1);
for ( result = printf("%s", s); (int)(a1 + 4) > v1; ++v1 )
result = putchar(32);
return result;
}

original_code:
static void printlevel(int level)
{
    int len = 0;
    int targetlen = 4 + level;
    int shownlen = 0;
    char number[10];
    len = snprintf(number,sizeof(number),"<%d>",level);
    printf("%s",number);
    shownlen = len;
    while(shownlen < targetlen) {
        putchar(' ');
        ++shownlen;
    }
}

variable_types: level int

variable_types: len int

variable_types: targetlen int

variable_types: shownlen int

variable_types:
number
char [10]


repo: Distrotech/mgetty

decompiled_code:
void fwf_sig_alarm()
{
signal(14, fwf_sig_alarm);
lprintf(3LL, "Warning: got alarm signal!");
}

canonical_decompiled_code:
void func0()
{
signal(14, fwf_sig_alarm);
lprintf(3LL, "Warning: got alarm signal!");
}

original_code:
static RETSIGTYPE fwf_sig_alarm()
{
    signal( 14, fwf_sig_alarm );
    lprintf( 3, "Warning: got alarm signal!" );
    fwf_timeout = (1==1);
}

canonical_original_code:
static void fwf_sig_alarm()
{
    signal( 14, fwf_sig_alarm );
    lprintf( 3, "Warning: got alarm signal!" );
    fwf_timeout = (1==1);
}


decompiled_code:
__int64 __fastcall mdm_send(void *buf, int fd)
{
size_t v2; // rax
ssize_t v3; // r12

delay(50LL);
lprintf(4LL, "mdm_send: '%s'", (const char *)buf);
v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
if ( v3 == strlen((const char *)buf) && write(fd, "\r", 1uLL) == 1 )
return 0LL;
lprintf(1LL, "mdm_send: cannot write");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf, int fd)
{
size_t v2; // rax
ssize_t v3; // r12

delay(50LL);
lprintf(4LL, "mdm_send: '%s'", (const char *)buf);
v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
if ( v3 == strlen((const char *)buf) && write(fd, "\r", 1uLL) == 1 )
return 0LL;
lprintf(1LL, "mdm_send: cannot write");
return 0xFFFFFFFFLL;
}

original_code:
int mdm_send (char * send,int fd)
{
    delay(50);
    lprintf( 4, "mdm_send: '%s'", send );
    if ( write( fd, send, strlen( send ) ) != strlen( send ) ||
  write( fd, "\r", sizeof("\r")-1 ) !=
         ( sizeof("\r")-1 ) )
    {
 lprintf( 1, "mdm_send: cannot write" );
 return -1;
    }
    return 0;
}

canonical_original_code:
int mdm_send(char *send, int fd)
{
    delay(50);
    lprintf( 4, "mdm_send: '%s'", send );
    if ( write( fd, send, strlen( send ) ) != strlen( send ) ||
  write( fd, "\r", sizeof("\r")-1 ) !=
         ( sizeof("\r")-1 ) )
    {
 lprintf( 1, "mdm_send: cannot write" );
 return -1;
    }
    return 0;
}

variable_types:
send
char *

variable_types: fd int


decompiled_code:
char *__fastcall mdm_get_line(int a1)
{
unsigned int v1; // ebx
const unsigned __int16 **v3; // rdx
char v4; // al
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

lprintf(6LL, "got:");
v1 = 0;
do
{
do
{
if ( (unsigned int)mdm_read_byte(a1, v5) != 1 )
{
lprintf(1LL, "mdm_get_line: cannot read byte, return");
return 0LL;
}
lputc(6LL, (unsigned int)v5[0]);
v3 = _ctype_b_loc();
v4 = v5[0];
if ( ((*v3)[v5[0]] & 0x4000) != 0 && v1 <= 0xC7 )
{
buffer_4[v1++] = v5[0];
break;
}
}
while ( !v1 );
}
while ( v4 != 10 && v4 != 13 );
buffer_4[v1] = 0;
return buffer_4;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
unsigned int v1; // ebx
const unsigned __int16 **v3; // rdx
char v4; // al
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

lprintf(6LL, "got:");
v1 = 0;
do
{
do
{
if ( (unsigned int)func2(a1, v5) != 1 )
{
lprintf(1LL, "mdm_get_line: cannot read byte, return");
return 0LL;
}
lputc(6LL, (unsigned int)v5[0]);
v3 = _ctype_b_loc();
v4 = v5[0];
if ( ((*v3)[v5[0]] & 0x4000) != 0 && v1 <= 0xC7 )
{
buffer_4[v1++] = v5[0];
break;
}
}
while ( !v1 );
}
while ( v4 != 10 && v4 != 13 );
buffer_4[v1] = 0;
return buffer_4;
}

original_code:
char * mdm_get_line (int fd)
{
    static char buffer[200];
    int bufferp;
    char c;
    bufferp = 0;
    lprintf( 6, "got:" );
    do
    {
 if( mdm_read_byte( fd, &c ) != 1 )
 {
     lprintf( 1, "mdm_get_line: cannot read byte, return" );
     return ((void *)0);
 }
 lputc( 6, c );
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) &&
      bufferp < sizeof(buffer) )
 {
     buffer[ bufferp++ ] = c;
 }
    }
    while ( bufferp == 0 || ( c != 0x0a && c != 0x0d ) );
    buffer[bufferp] = 0;
    return buffer;
}

canonical_original_code:
char *mdm_get_line(int fd)
{
    static char buffer[200];
    int bufferp;
    char c;
    bufferp = 0;
    lprintf( 6, "got:" );
    do
    {
 if( mdm_read_byte( fd, &c ) != 1 )
 {
     lprintf( 1, "mdm_get_line: cannot read byte, return" );
     return ((void *)0);
 }
 lputc( 6, c );
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) &&
      bufferp < sizeof(buffer) )
 {
     buffer[ bufferp++ ] = c;
 }
    }
    while ( bufferp == 0 || ( c != 0x0a && c != 0x0d ) );
    buffer[bufferp] = 0;
    return buffer;
}

variable_types:
buffer
char [200]

variable_types: bufferp int

variable_types: c char


decompiled_code:
__int64 __fastcall mdm_command(void *a1, int a2)
{
__int64 result; // rax
char *v3; // rax
const char *v4; // rbx

result = mdm_send(a1, a2);
if ( (_DWORD)result != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
do
{
v3 = mdm_get_line(a2);
v4 = v3;
if ( !v3 )
{
alarm(0);
signal(14, 0LL);
goto LABEL_10;
}
lprintf(5LL, "mdm_command: string '%s'", v3);
}
while ( strcmp(v4, "OK") && strcmp(v4, "ERROR") );
alarm(0);
signal(14, 0LL);
if ( strcmp(v4, "ERROR") )
{
lputs(4LL, " -> OK");
return 0LL;
}
LABEL_10:
lputs(4LL, " -> ERROR");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1, int a2)
{
__int64 result; // rax
char *v3; // rax
const char *v4; // rbx

result = func1(a1, a2);
if ( (_DWORD)result != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
do
{
v3 = func3(a2);
v4 = v3;
if ( !v3 )
{
alarm(0);
signal(14, 0LL);
goto LABEL_10;
}
lprintf(5LL, "mdm_command: string '%s'", v3);
}
while ( strcmp(v4, "OK") && strcmp(v4, "ERROR") );
alarm(0);
signal(14, 0LL);
if ( strcmp(v4, "ERROR") )
{
lputs(4LL, " -> OK");
return 0LL;
}
LABEL_10:
lputs(4LL, " -> ERROR");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mdm_command (char * send,int fd)
{
    char * l;
    if ( mdm_send( send, fd ) == -1 ) return -1;
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    do
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 lprintf( 5, "mdm_command: string '%s'", l );
    }
    while ( strcmp( l, "OK" ) != 0 && strcmp( l, "ERROR" ) != 0 );
    alarm(0); signal( 14, ((__sighandler_t) 0) );
    if ( l == ((void *)0) || strcmp( l, "ERROR" ) == 0 )
    {
 lputs( 4, " -> ERROR" );
 return -1;
    }
    lputs( 4, " -> OK" );
    return 0;
}

canonical_original_code:
int mdm_command(char *send, int fd)
{
    char *l;
    if ( mdm_send( send, fd ) == -1 ) return -1;
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    do
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 lprintf( 5, "mdm_command: string '%s'", l );
    }
    while ( strcmp( l, "OK" ) != 0 && strcmp( l, "ERROR" ) != 0 );
    alarm(0); signal( 14, ((void (*)(int)) 0) );
    if ( l == ((void *)0) || strcmp( l, "ERROR" ) == 0 )
    {
 lputs( 4, " -> ERROR" );
 return -1;
    }
    lputs( 4, " -> OK" );
    return 0;
}

variable_types:
l
char *


decompiled_code:
char *__fastcall mdm_get_idstring(char *s2, int a2, int a3)
{
int v4; // edx
char *result; // rax
int v6; // ebp
char *v7; // rax
const char *v8; // rbx

v4 = mdm_send(s2, a3);
result = "<ERROR>";
if ( v4 != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
rbuf_0 = 0;
v6 = 0;
while ( 1 )
{
do
{
v7 = mdm_get_line(a3);
v8 = v7;
if ( !v7 )
{
alarm(0);
signal(14, 0LL);
return "<ERROR>";
}
}
while ( !strcmp(v7, s2) );
if ( !strcmp(v8, "OK") || !strcmp(v8, "ERROR") )
break;
lprintf(5LL, "mdm_gis: string %d: '%s'", (unsigned int)++v6, v8);
if ( v6 == -1 || v6 == a2 )
{
strncpy(&rbuf_0, v8, 0x77uLL);
byte_4B7 = 0;
}
}
alarm(0);
signal(14, 0LL);
result = &rbuf_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *s2, int a2, int a3)
{
int v4; // edx
char *result; // rax
int v6; // ebp
char *v7; // rax
const char *v8; // rbx

v4 = func1(s2, a3);
result = "<ERROR>";
if ( v4 != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
rbuf_0 = 0;
v6 = 0;
while ( 1 )
{
do
{
v7 = func3(a3);
v8 = v7;
if ( !v7 )
{
alarm(0);
signal(14, 0LL);
return "<ERROR>";
}
}
while ( !strcmp(v7, s2) );
if ( !strcmp(v8, "OK") || !strcmp(v8, "ERROR") )
break;
lprintf(5LL, "mdm_gis: string %d: '%s'", (unsigned int)++v6, v8);
if ( v6 == -1 || v6 == a2 )
{
strncpy(&rbuf_0, v8, 0x77uLL);
byte_4B7 = 0;
}
}
alarm(0);
signal(14, 0LL);
result = &rbuf_0;
}
return result;
}

original_code:
char * mdm_get_idstring (char * send,int n,int fd)
{
    char * l; int i;
    static char rbuf[120];
    if ( mdm_send( send, fd ) == -1 ) return "<ERROR>";
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    i=0;
    rbuf[0] = '\0';
    while(1)
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 if ( strcmp( l, send ) == 0 ) continue;
        if ( strcmp( l, "OK" ) == 0 ||
      strcmp( l, "ERROR" ) == 0 ) break;
        i++;
 lprintf( 5, "mdm_gis: string %d: '%s'", i, l );
 if ( i==-1 || i==n )
     { strncpy( rbuf, l, sizeof(rbuf)-1); rbuf[sizeof(rbuf)-1]='\0'; }
    }
    alarm(0); signal( 14, ((__sighandler_t) 0) );
    if ( l == ((void *)0) ) return "<ERROR>";
    return rbuf;
}

canonical_original_code:
char *mdm_get_idstring(char *send, int n, int fd)
{
    char *l; int i;
    static char rbuf[120];
    if ( mdm_send( send, fd ) == -1 ) return "<ERROR>";
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    i=0;
    rbuf[0] = '\0';
    while(1)
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 if ( strcmp( l, send ) == 0 ) continue;
        if ( strcmp( l, "OK" ) == 0 ||
      strcmp( l, "ERROR" ) == 0 ) break;
        i++;
 lprintf( 5, "mdm_gis: string %d: '%s'", i, l );
 if ( i==-1 || i==n )
     { strncpy( rbuf, l, sizeof(rbuf)-1); rbuf[sizeof(rbuf)-1]='\0'; }
    }
    alarm(0); signal( 14, ((void (*)(int)) 0) );
    if ( l == ((void *)0) ) return "<ERROR>";
    return rbuf;
}

variable_types: n int

variable_types: i int

variable_types:
rbuf
char [120]


decompiled_code:
__int64 __fastcall mdm_read_byte(int a1, _BYTE *a2)
{
int v2; // eax
int v4; // eax
unsigned int v5; // ebp

if ( frb_rp_3 < frb_len_2 )
goto LABEL_2;
v4 = read(a1, frb_buf_1, 0x200uLL);
v5 = v4;
frb_len_2 = v4;
if ( v4 > 0 )
{
frb_rp_3 = 0;
LABEL_2:
v2 = frb_rp_3++;
*a2 = frb_buf_1[v2];
return 1LL;
}
if ( !v4 )
*_errno_location() = 0;
lprintf(1LL, "mdm_read_byte: read returned %d", v5);
return (unsigned int)frb_len_2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _BYTE *a2)
{
int v2; // eax
int v4; // eax
unsigned int v5; // ebp

if ( frb_rp_3 < frb_len_2 )
goto LABEL_2;
v4 = read(a1, frb_buf_1, 0x200uLL);
v5 = v4;
frb_len_2 = v4;
if ( v4 > 0 )
{
frb_rp_3 = 0;
LABEL_2:
v2 = frb_rp_3++;
*a2 = frb_buf_1[v2];
return 1LL;
}
if ( !v4 )
*_errno_location() = 0;
lprintf(1LL, "mdm_read_byte: read returned %d", v5);
return (unsigned int)frb_len_2;
}

original_code:
int mdm_read_byte (int fd,char * c)
{
static char frb_buf[512];
static int frb_rp = 0;
static int frb_len = 0;
    if ( frb_rp >= frb_len )
    {
 frb_len = read( fd, frb_buf, sizeof( frb_buf ) );
 if ( frb_len <= 0 )
 {
     if ( frb_len == 0 ) (*__errno_location ()) = 0;
     lprintf( 1, "mdm_read_byte: read returned %d", frb_len );
     return frb_len;
 }
 frb_rp = 0;
    }
    *c = frb_buf[ frb_rp++ ];
    return 1;
}

canonical_original_code:
int mdm_read_byte(int fd, char *c)
{
static char frb_buf[512];
static int frb_rp = 0;
static int frb_len = 0;
    if ( frb_rp >= frb_len )
    {
 frb_len = read( fd, frb_buf, sizeof( frb_buf ) );
 if ( frb_len <= 0 )
 {
     if ( frb_len == 0 ) (*__errno_location ()) = 0;
     lprintf( 1, "mdm_read_byte: read returned %d", frb_len );
     return frb_len;
 }
 frb_rp = 0;
    }
    *c = frb_buf[ frb_rp++ ];
    return 1;
}

variable_types:
c
char *


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

reset_watchdog();
if ( current_device_0 >= 0 && current_device_0 != a1 )
{
voice_command("ATH0", "VCON|OK");
voice_command("AT#CLS=8", "OK");
}
current_device_0 = a1;
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 func0(unsigned int a1)
{
__int64 result; // rax

reset_watchdog();
if ( current_device_0 >= 0 && current_device_0 != a1 )
{
voice_command("ATH0", "VCON|OK");
voice_command("AT#CLS=8", "OK");
}
current_device_0 = a1;
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 Rockwell_set_device (int device)
     {
     static int current_device = -1;
     reset_watchdog();
     if ((current_device != device) && (current_device >= 0)) {
          voice_command("ATH0","VCON|OK");
   voice_command("AT#CLS=8", "OK");
     }
     current_device=device;
     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));
     }

canonical_original_code:
static int Rockwell_set_device(int device)
     {
     static int current_device = -1;
     reset_watchdog();
     if ((current_device != device) && (current_device >= 0)) {
          voice_command("ATH0","VCON|OK");
   voice_command("AT#CLS=8", "OK");
     }
     current_device=device;
     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 Rockwell_set_compression(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 7200 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 7200LL;
}
v5 = *a1;
if ( *a1 == 8 )
{
*a3 = 8;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=8", "OK") != 4096);
}
else
{
if ( *a1 > 8 )
{
if ( v5 == 16 )
{
*a3 = 16;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=16", "OK") != 4096);
}
}
else
{
if ( v5 == 2 )
{
*a3 = 2;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=2", "OK") != 4096);
}
if ( v5 == 4 )
{
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=4", "OK") != 4096);
}
}
lprintf(3LL, "ROCKWELL handle event: Illegal voice compression method (%d)", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax

reset_watchdog();
if ( !*a1 )
*a1 = 2LL;
v4 = *a2;
if ( *a2 )
{
if ( v4 != 7200 )
{
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v4);
return 0xFFFFFFFFLL;
}
}
else
{
*a2 = 7200LL;
}
v5 = *a1;
if ( *a1 == 8 )
{
*a3 = 8;
result = (unsigned int)-((unsigned int)voice_command("AT#VBS=8", "OK") != 4096);
}
else
{
if ( *a1 > 8 )
{
if ( v5 == 16 )
{
*a3 = 16;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=16", "OK") != 4096);
}
}
else
{
if ( v5 == 2 )
{
*a3 = 2;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=2", "OK") != 4096);
}
if ( v5 == 4 )
{
*a3 = 4;
return (unsigned int)-((unsigned int)voice_command("AT#VBS=4", "OK") != 4096);
}
}
lprintf(3LL, "ROCKWELL handle event: Illegal voice compression method (%d)", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int Rockwell_set_compression (p_int *compression, p_int *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 7200;
     if (*speed != 7200)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          };
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 8:
               *bits=8;
               if (voice_command("AT#VBS=8", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 16:
               *bits=16;
               if (voice_command("AT#VBS=16", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "ROCKWELL handle event: Illegal voice compression method (%d)",
      *compression);
     return((-1));
     }

canonical_original_code:
static int Rockwell_set_compression(long *compression, long *speed, int *bits)
     {
     reset_watchdog();
     if (*compression == 0)
          *compression = 2;
     if (*speed == 0)
          *speed = 7200;
     if (*speed != 7200)
          {
          lprintf(3, "%s: Illegal sample rate (%d)", voice_modem->name,
           *speed);
          return((-1));
          };
     switch (*compression)
          {
          case 2:
               *bits=2;
               if (voice_command("AT#VBS=2", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 4:
               *bits=4;
               if (voice_command("AT#VBS=4", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 8:
               *bits=8;
               if (voice_command("AT#VBS=8", "OK") != (0x1000))
                    return((-1));
               return ((0));
          case 16:
               *bits=16;
               if (voice_command("AT#VBS=16", "OK") != (0x1000))
                    return((-1));
               return ((0));
          }
     lprintf(3,
      "ROCKWELL handle event: Illegal voice compression method (%d)",
      *compression);
     return((-1));
     }

variable_types:
compression
long *

variable_types:
speed
long *

variable_types:
bits
int *


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

reset_watchdog();
lprintf(4LL, "initializing ROCKWELL voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 )
{
if ( v0 == -1 )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#TL=%X", (unsigned int)(0x10000 / (100 / *((_DWORD *)&cvd + 164))));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set transmit gain");
}
v1 = *((_QWORD *)&cvd + 79);
if ( v1 )
{
if ( v1 == -1 )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(s, "AT#RG=%X", (unsigned int)(0x10000 / (100 / *((_DWORD *)&cvd + 158))));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record gain");
}
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");
v2 = *((_QWORD *)&cvd + 58);
if ( v2 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v2 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT&K3", "OK") == 4096 )
{
tio_get(voice_fd, v4);
tio_set_flow_control(voice_fd, v4, 1LL);
tio_set(voice_fd, v4);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

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

reset_watchdog();
lprintf(4LL, "initializing ROCKWELL voice modem");
voice_modem_state = 2;
sprintf(s, "AT#VSP=%1u", *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence period");
v0 = *((_QWORD *)&cvd + 82);
if ( v0 )
{
if ( v0 == -1 )
*((_QWORD *)&cvd + 82) = 50LL;
sprintf(s, "AT#TL=%X", (unsigned int)(0x10000 / (100 / *((_DWORD *)&cvd + 164))));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set transmit gain");
}
v1 = *((_QWORD *)&cvd + 79);
if ( v1 )
{
if ( v1 == -1 )
*((_QWORD *)&cvd + 79) = 50LL;
sprintf(s, "AT#RG=%X", (unsigned int)(0x10000 / (100 / *((_DWORD *)&cvd + 158))));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set record gain");
}
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");
v2 = *((_QWORD *)&cvd + 58);
if ( v2 > 0x64 )
{
lprintf(3LL, "Invalid threshold value.");
result = 0xFFFFFFFFLL;
}
else
{
sprintf(s, "AT#VSS=%1u", (unsigned int)(3 * (int)v2 / 100));
if ( (unsigned int)voice_command(s, "OK") != 4096 )
lprintf(3LL, "can't set silence threshold");
if ( (unsigned int)voice_command("AT&K3", "OK") == 4096 )
{
tio_get(voice_fd, v4);
tio_set_flow_control(voice_fd, v4, 1LL);
tio_set(voice_fd, v4);
}
else
{
lprintf(3LL, "can't turn on hardware flow control");
}
voice_modem_state = 1;
result = 0LL;
}
return result;
}

original_code:
static int Rockwell_init(void)
     {
     char buffer[(256)];
     reset_watchdog();
     lprintf(4, "initializing ROCKWELL 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 (cvd.transmit_gain.d.i) {
 if (cvd.transmit_gain.d.i == -1) {
    cvd.transmit_gain.d.i = 50;
 }
        sprintf(buffer, "AT#TL=%X", (65536 / (100 / (int)cvd.transmit_gain.d.i)));
 if (voice_command(buffer, "OK") != (0x1000)) {
          lprintf(3, "can't set transmit gain");
        }
     }
     if (cvd.receive_gain.d.i) {
 if (cvd.receive_gain.d.i == -1) {
    cvd.receive_gain.d.i = 50;
 }
        sprintf(buffer, "AT#RG=%X", (65536 / (100 / (int)cvd.receive_gain.d.i)));
 if (voice_command(buffer, "OK") != (0x1000)) {
      lprintf(3, "can't set record gain");
        }
     }
     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&K3", "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 Rockwell_init()
     {
     char buffer[-1];
     reset_watchdog();
     lprintf(4, "initializing ROCKWELL 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 (cvd.transmit_gain.d.i) {
 if (cvd.transmit_gain.d.i == -1) {
    cvd.transmit_gain.d.i = 50;
 }
        sprintf(buffer, "AT#TL=%X", (65536 / (100 / (int)cvd.transmit_gain.d.i)));
 if (voice_command(buffer, "OK") != (0x1000)) {
          lprintf(3, "can't set transmit gain");
        }
     }
     if (cvd.receive_gain.d.i) {
 if (cvd.receive_gain.d.i == -1) {
    cvd.receive_gain.d.i = 50;
 }
        sprintf(buffer, "AT#RG=%X", (65536 / (100 / (int)cvd.receive_gain.d.i)));
 if (voice_command(buffer, "OK") != (0x1000)) {
      lprintf(3, "can't set record gain");
        }
     }
     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&K3", "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:
buffer
char [-1]

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


decompiled_code:
__int64 __fastcall Rockwell_handle_dle(char a1)
{
__int64 v2; // rax

if ( a1 != 116 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8200LL);
return queue_event(v2);
}

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

if ( a1 != 116 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8200LL);
return queue_event(v2);
}

original_code:
static int Rockwell_handle_dle(char data)
     {
     switch (data)
          {
          case 't':
               return(queue_event(create_event((0x2008))));
          }
     return(IS_101_handle_dle(data));
     }

variable_types: data char


decompiled_code:
__int64 __fastcall Lucent_beep(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
unsigned int v3; // er12
int v4; // edi
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = (unsigned int)((int)a2 >> 31);
LODWORD(v2) = (int)a2 % *(_DWORD *)(voice_modem + 48LL);
v3 = (int)a2 / *(_DWORD *)(voice_modem + 48LL);
reset_watchdog(a1, a2, v2);
sprintf(v6, *(const char **)(voice_modem + 32LL), (unsigned int)a1, (unsigned int)a1, v3);
if ( (unsigned int)voice_command(v6, &unk_8A9) )
return 0xFFFFFFFFLL;
v4 = 1000;
if ( (int)a2 >= 1000 )
v4 = a2;
delay((unsigned int)(v4 - 1000));
return (unsigned int)-((voice_command(&unk_8A9, *(_QWORD *)(voice_modem + 40LL)) & 0x1000) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
unsigned int v3; // er12
int v4; // edi
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = (unsigned int)((int)a2 >> 31);
LODWORD(v2) = (int)a2 % *(_DWORD *)(voice_modem + 48LL);
v3 = (int)a2 / *(_DWORD *)(voice_modem + 48LL);
reset_watchdog(a1, a2, v2);
sprintf(v6, *(const char **)(voice_modem + 32LL), (unsigned int)a1, (unsigned int)a1, v3);
if ( (unsigned int)voice_command(v6, &unk_8A9) )
return 0xFFFFFFFFLL;
v4 = 1000;
if ( (int)a2 >= 1000 )
v4 = a2;
delay((unsigned int)(v4 - 1000));
return (unsigned int)-((voice_command(&unk_8A9, *(_QWORD *)(voice_modem + 40LL)) & 0x1000) == 0);
}

original_code:
int Lucent_beep(int frequency, int length)
     {
     char buffer[(256)];
     int true_length = length / voice_modem->beep_timeunit;
     reset_watchdog();
     sprintf(buffer, voice_modem->beep_cmnd, frequency, frequency, true_length);
     if (voice_command(buffer, "") != (0))
          return((-1));
     delay(((length - 1000) > 0) ? (length - 1000) : 0);
     if ((voice_command("", voice_modem->beep_answr) & (0x1000)) != (0x1000))
          return((-1));
     return((0));
     }

canonical_original_code:
int Lucent_beep(int frequency, int length)
     {
     char buffer[-1];
     int true_length = length / voice_modem->beep_timeunit;
     reset_watchdog();
     sprintf(buffer, voice_modem->beep_cmnd, frequency, frequency, true_length);
     if (voice_command(buffer, "") != (0))
          return((-1));
     delay(((length - 1000) > 0) ? (length - 1000) : 0);
     if ((voice_command("", voice_modem->beep_answr) & (0x1000)) != (0x1000))
          return((-1));
     return((0));
     }

variable_types: frequency int

variable_types: length int


decompiled_code:
__int64 __fastcall Lucent_set_device(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

reset_watchdog(a1, a2, a3);
switch ( (int)a1 )
{
case 1:
case 10:
voice_command("AT+VLS=0", &unk_8AA);
result = 0LL;
break;
case 2:
voice_command("AT+VLS=1", &unk_8AA);
result = 0LL;
break;
case 4:
voice_command("AT+VLS=6", &unk_8AA);
result = 0LL;
break;
case 6:
voice_command("AT+VLS=4", &unk_8AA);
result = 0LL;
break;
case 7:
voice_command("AT+VLS=2", &unk_8AA);
result = 0LL;
break;
case 9:
voice_command("AT+VLS=5", &unk_8AA);
result = 0LL;
break;
case 12:
voice_command("AT+VLS=7", &unk_8AA);
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

reset_watchdog(a1, a2, a3);
switch ( (int)a1 )
{
case 1:
case 10:
voice_command("AT+VLS=0", &unk_8AA);
result = 0LL;
break;
case 2:
voice_command("AT+VLS=1", &unk_8AA);
result = 0LL;
break;
case 4:
voice_command("AT+VLS=6", &unk_8AA);
result = 0LL;
break;
case 6:
voice_command("AT+VLS=4", &unk_8AA);
result = 0LL;
break;
case 7:
voice_command("AT+VLS=2", &unk_8AA);
result = 0LL;
break;
case 9:
voice_command("AT+VLS=5", &unk_8AA);
result = 0LL;
break;
case 12:
voice_command("AT+VLS=7", &unk_8AA);
result = 0LL;
break;
default:
lprintf(3LL, "%s: Unknown output device (%d)", (const char *)*voice_modem, (unsigned int)a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static int Lucent_set_device (int device)
     {
     reset_watchdog();
     switch (device)
          {
   case (0x000A):
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=1", "OK");
               return((0));
   case (0x0007):
     voice_command("AT+VLS=2", "OK");
     return((0));
          case (0x0006):
               voice_command("AT+VLS=4", "OK");
               return((0));
          case (0x0004):
               voice_command("AT+VLS=6", "OK");
               return((0));
   case (0x0009):
     voice_command("AT+VLS=5", "OK");
     return((0));
   case (0x000C):
     voice_command("AT+VLS=7", "OK");
     return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }

canonical_original_code:
static int Lucent_set_device(int device)
     {
     reset_watchdog();
     switch (device)
          {
   case (0x000A):
          case (0x0001):
               voice_command("AT+VLS=0", "OK");
               return((0));
          case (0x0002):
               voice_command("AT+VLS=1", "OK");
               return((0));
   case (0x0007):
     voice_command("AT+VLS=2", "OK");
     return((0));
          case (0x0006):
               voice_command("AT+VLS=4", "OK");
               return((0));
          case (0x0004):
               voice_command("AT+VLS=6", "OK");
               return((0));
   case (0x0009):
     voice_command("AT+VLS=5", "OK");
     return((0));
   case (0x000C):
     voice_command("AT+VLS=7", "OK");
     return((0));
          };
     lprintf(3, "%s: Unknown output device (%d)", voice_modem->name,
      device);
     return((-1));
     }


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

reset_watchdog(a1, a2, a3);
if ( !*a1 )
{
*a1 = 4LL;
if ( *a2 )
{
LABEL_18:
*a3 = 8;
v7 = *a2;
if ( *a2 == 8000 )
{
sprintf(v9, "AT+VSM=131,%d", 8000LL);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
}
else
{
LABEL_17:
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v7);
result = 0xFFFFFFFFLL;
}
return result;
}
goto LABEL_3;
}
if ( !*a2 )
LABEL_3:
*a2 = 8000LL;
switch ( *a1 )
{
case 1LL:
*a3 = 8;
v4 = *a2;
if ( *a2 != 8000 && *a2 != 7200 && v4 != 11025 )
goto LABEL_24;
sprintf(v9, "AT+VSM=128,%d", v4);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
break;
case 2LL:
*a3 = 16;
v6 = *a2;
if ( *a2 != 8000 && *a2 != 7200 && v6 != 11025 )
goto LABEL_24;
sprintf(v9, "AT+VSM=129,%d", v6);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
break;
case 3LL:
*a3 = 8;
v7 = *a2;
if ( *a2 != 8000 )
goto LABEL_17;
sprintf(v9, "AT+VSM=130,%d", 8000LL);
return (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
case 4LL:
goto LABEL_18;
case 5LL:
*a3 = 4;
v8 = *a2;
if ( *a2 != 7200 && *a2 != 8000 && v8 != 11025 )
{
LABEL_24:
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, *a2);
result = 0xFFFFFFFFLL;
}
else
{
sprintf(v9, "AT+VSM=132,%d", v8);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
}
break;
default:
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, *a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

reset_watchdog(a1, a2, a3);
if ( !*a1 )
{
*a1 = 4LL;
if ( *a2 )
{
LABEL_18:
*a3 = 8;
v7 = *a2;
if ( *a2 == 8000 )
{
sprintf(v9, "AT+VSM=131,%d", 8000LL);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
}
else
{
LABEL_17:
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, v7);
result = 0xFFFFFFFFLL;
}
return result;
}
goto LABEL_3;
}
if ( !*a2 )
LABEL_3:
*a2 = 8000LL;
switch ( *a1 )
{
case 1LL:
*a3 = 8;
v4 = *a2;
if ( *a2 != 8000 && *a2 != 7200 && v4 != 11025 )
goto LABEL_24;
sprintf(v9, "AT+VSM=128,%d", v4);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
break;
case 2LL:
*a3 = 16;
v6 = *a2;
if ( *a2 != 8000 && *a2 != 7200 && v6 != 11025 )
goto LABEL_24;
sprintf(v9, "AT+VSM=129,%d", v6);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
break;
case 3LL:
*a3 = 8;
v7 = *a2;
if ( *a2 != 8000 )
goto LABEL_17;
sprintf(v9, "AT+VSM=130,%d", 8000LL);
return (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
case 4LL:
goto LABEL_18;
case 5LL:
*a3 = 4;
v8 = *a2;
if ( *a2 != 7200 && *a2 != 8000 && v8 != 11025 )
{
LABEL_24:
lprintf(3LL, "%s: Illegal sample rate (%d)", (const char *)*voice_modem, *a2);
result = 0xFFFFFFFFLL;
}
else
{
sprintf(v9, "AT+VSM=132,%d", v8);
result = (unsigned int)-((unsigned int)voice_command(v9, &unk_8AA) != 4096);
}
break;
default:
lprintf(3LL, "%s: Illegal voice compression method (%d)", (const char *)*voice_modem, *a1);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

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


decompiled_code:
__int64 __fastcall Lucent_init(__int64 a1, __int64 a2, __int64 a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog(a1, a2, a3);
voice_modem_state = 2;
lprintf(4LL, "initializing Lucent voice modem");
sprintf(v4, "AT+VSD=%d,%d", (unsigned int)((int)*((_QWORD *)&cvd + 58) / 10 + 123), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 128LL;
sprintf(v4, "AT+VGT=%d", *((unsigned int *)&cvd + 164));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 128LL;
sprintf(v4, "AT+VGR=%d", *((unsigned int *)&cvd + 158));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VIT=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't deactivate inactivity timer");
if ( (unsigned int)voice_command("AT+VPR=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't select autobauding");
if ( (unsigned int)voice_command("AT+VLS=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't deselect all input/output devices");
voice_modem_state = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

reset_watchdog(a1, a2, a3);
voice_modem_state = 2;
lprintf(4LL, "initializing Lucent voice modem");
sprintf(v4, "AT+VSD=%d,%d", (unsigned int)((int)*((_QWORD *)&cvd + 58) / 10 + 123), *((unsigned int *)&cvd + 110));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting recording preferences didn't work");
if ( *((_QWORD *)&cvd + 82) == -1LL )
*((_QWORD *)&cvd + 82) = 128LL;
sprintf(v4, "AT+VGT=%d", *((unsigned int *)&cvd + 164));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting transmit gain didn't work");
if ( *((_QWORD *)&cvd + 79) == -1LL )
*((_QWORD *)&cvd + 79) = 128LL;
sprintf(v4, "AT+VGR=%d", *((unsigned int *)&cvd + 158));
if ( (unsigned int)voice_command(v4, &unk_8AA) != 4096 )
lprintf(3LL, "setting receive gain didn't work");
if ( (unsigned int)voice_command("AT+VIT=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't deactivate inactivity timer");
if ( (unsigned int)voice_command("AT+VPR=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't select autobauding");
if ( (unsigned int)voice_command("AT+VLS=0", &unk_8AA) != 4096 )
lprintf(3LL, "can't deselect all input/output devices");
voice_modem_state = 1;
return 0LL;
}

original_code:
static int Lucent_init (void)
     {
     char buffer[(256)];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Lucent voice modem");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      10 / 100 + 123, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 128;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 128;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VIT=0", "OK") != (0x1000))
          lprintf(3, "can't deactivate inactivity timer");
     if (voice_command("AT+VPR=0", "OK") != (0x1000))
          lprintf(3, "can't select autobauding");
     if (voice_command("AT+VLS=0", "OK") != (0x1000))
          lprintf(3, "can't deselect all input/output devices");
     voice_modem_state = (0x0001);
     return((0));
     }

canonical_original_code:
static int Lucent_init()
     {
     char buffer[-1];
     reset_watchdog();
     voice_modem_state = (0x0002);
     lprintf(4, "initializing Lucent voice modem");
     sprintf(buffer, "AT+VSD=%d,%d", (int)cvd.rec_silence_threshold.d.i *
      10 / 100 + 123, (int)cvd.rec_silence_len.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting recording preferences didn't work");
     if (cvd.transmit_gain.d.i == -1)
          cvd.transmit_gain.d.i = 128;
     sprintf(buffer, "AT+VGT=%d", (int)cvd.transmit_gain.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting transmit gain didn't work");
     if (cvd.receive_gain.d.i == -1)
          cvd.receive_gain.d.i = 128;
     sprintf(buffer, "AT+VGR=%d", (int)cvd.receive_gain.d.i);
     if (voice_command(buffer, "OK") != (0x1000))
          lprintf(3, "setting receive gain didn't work");
     if (voice_command("AT+VIT=0", "OK") != (0x1000))
          lprintf(3, "can't deactivate inactivity timer");
     if (voice_command("AT+VPR=0", "OK") != (0x1000))
          lprintf(3, "can't select autobauding");
     if (voice_command("AT+VLS=0", "OK") != (0x1000))
          lprintf(3, "can't deselect all input/output devices");
     voice_modem_state = (0x0001);
     return((0));
     }


decompiled_code:
__int64 __fastcall Lucent_handle_dle(char a1)
{
__int64 v2; // rax

if ( a1 != 115 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8210LL);
return queue_event(v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
__int64 v2; // rax

if ( a1 != 115 )
return IS_101_handle_dle((unsigned int)a1);
v2 = create_event(8210LL);
return queue_event(v2);
}

original_code:
static int Lucent_handle_dle(char data)
     {
     switch (data)
          {
          case 's':
               return(queue_event(create_event((0x2012))));
          }
     return(IS_101_handle_dle(data));
     }