parseModule

decompiled_code:
__int64 __fastcall parseModule(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 result; // rax
unsigned int v8; // ebp
unsigned int v9; // er12
jmp_buf env; // [rsp+18h] [rbp-E8h] BYREF
char *v11; // [rsp+E0h] [rbp-20h]

*(_QWORD *)(a2 + 48) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
*(_OWORD *)(a2 + 32) = 0LL;
v11 = &a7;
if ( setjmp(env) )
{
freeNode(a2);
result = 0LL;
}
else
{
readWhitespace(a1);
v8 = *(_DWORD *)(a1 + 4);
parseTerminated(a1, a2, parseDeclaration, &asc_B84[3]);
v9 = isEof(a1);
if ( !(_BYTE)v9 )
{
panicStream(a1, "expected declaration");
JUMPOUT(0xB5BLL);
}
makeString(a1, v8, *(_DWORD *)(a1 + 4) - v8, a2 + 8);
*(_QWORD *)(a1 + 24) = &abort;
result = v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 result; // rax
unsigned int v8; // ebp
unsigned int v9; // er12
jmp_buf env; // [rsp+18h] [rbp-E8h] BYREF
char *v11; // [rsp+E0h] [rbp-20h]

*(_QWORD *)(a2 + 48) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
*(_OWORD *)(a2 + 32) = 0LL;
v11 = &a7;
if ( setjmp(env) )
{
freeNode(a2);
result = 0LL;
}
else
{
readWhitespace(a1);
v8 = *(_DWORD *)(a1 + 4);
parseTerminated(a1, a2, parseDeclaration, &asc_B84[3]);
v9 = isEof(a1);
if ( !(_BYTE)v9 )
{
panicStream(a1, "expected declaration");
JUMPOUT(0xB5BLL);
}
makeString(a1, v8, *(_DWORD *)(a1 + 4) - v8, a2 + 8);
*(_QWORD *)(a1 + 24) = &abort;
result = v9;
}
return result;
}

original_code:
_Bool parseModule(Stream* s, Node* m)
{
 *m=(Node){0};
 jmp_buf env;
 if(_setjmp (env))
 {
  freeNode(m);
  return 0;
 }
 __attribute__((noreturn)) void errorHandler()
 {
  longjmp(env,1);
 }
 readWhitespace(s);
 int start=s->offset;
 parseTerminated(s,m,parseDeclaration,";");
 if(!isEof(s))
  panicStream(s,"expected declaration");
 makeString(s, start, s->offset-start, &m->source);
 s->errorHandler=abort;
 return 1;
}

canonical_original_code:
_Bool parseModule(struct Stream *s, struct Node *m)
{
 *m=(struct Node){0};
 struct __jmp_buf_tag env[1];
 if(_setjmp (env))
 {
  freeNode(m);
  return 0;
 }
 __attribute__((noreturn)) void errorHandler()
 {
  longjmp(env,1);
 }
 readWhitespace(s);
 int start = s->offset;
 parseTerminated(s,m,parseDeclaration,";");
 if(!isEof(s))
  panicStream(s,"expected declaration");
 makeString(s, start, s->offset-start, &m->source);
 s->errorHandler=abort;
 return 1;
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


panic

decompiled_code:
void __noreturn panic(const char *a1, unsigned int a2, const char *a3, ...)
{
int v4; // edi
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s:%i: ", a1, a2);
vfprintf(stderr, a3, arg);
v4 = *_errno_location();
if ( v4 )
{
v5 = strerror(v4);
fprintf(stderr, ": %s", v5);
}
fputc(10, stderr);
abort();
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, unsigned int a2, const char *a3, ...)
{
int v4; // edi
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s:%i: ", a1, a2);
vfprintf(stderr, a3, arg);
v4 = *_errno_location();
if ( v4 )
{
v5 = strerror(v4);
fprintf(stderr, ": %s", v5);
}
fputc(10, stderr);
abort();
}

original_code:
__attribute__((__noreturn__)) void panic(char* file,int line,char *format,...)
{
 va_list args;
 __builtin_va_start(args,format);
 fprintf(stderr, "%s:%i: ", file,line);
 vfprintf(stderr,format,args);
 if((*__errno_location ())!=0)
  fprintf(stderr,": %s",strerror((*__errno_location ())));
 fprintf(stderr,"\n");
 __builtin_va_end(args);
    abort();
}

canonical_original_code:
void panic(char *file, int line, char *format, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,format);
 fprintf(stderr, "%s:%i: ", file,line);
 vfprintf(stderr,format,args);
 if((*__errno_location ())!=0)
  fprintf(stderr,": %s",strerror((*__errno_location ())));
 fprintf(stderr,"\n");
 __builtin_va_end(args);
    abort();
}

variable_types:
file
char *

variable_types: line int

variable_types:
format
char *

return_type: void


echoOff

repo: bard/spock

decompiled_code:
int __fastcall echoOff(int fd)
{
int result; // eax
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

result = isatty(fd);
if ( result )
{
tcgetattr(fd, &v2);
v2.c_lflag &= 0xFFFFFFF7;
result = tcsetattr(fd, 2, &v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int fd)
{
int result; // eax
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

result = isatty(fd);
if ( result )
{
tcgetattr(fd, &v2);
v2.c_lflag &= 0xFFFFFFF7;
result = tcsetattr(fd, 2, &v2);
}
return result;
}

original_code:
static void echoOff(int fd)
{
    if (isatty(fd)) {
 struct termios tio;
 tcgetattr(fd, &tio);
 tio.c_lflag &= ~0000010;
 tcsetattr(fd, 2, &tio);
    }
}

variable_types: fd int

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


echoOn

decompiled_code:
int __fastcall echoOn(int fd)
{
int result; // eax
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

result = isatty(fd);
if ( result )
{
tcgetattr(fd, &v2);
v2.c_lflag |= 8u;
result = tcsetattr(fd, 2, &v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
int result; // eax
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

result = isatty(fd);
if ( result )
{
tcgetattr(fd, &v2);
v2.c_lflag |= 8u;
result = tcsetattr(fd, 2, &v2);
}
return result;
}

original_code:
static void echoOn(int fd)
{
    if (isatty(fd)) {
 struct termios tio;
 tcgetattr(fd, &tio);
 tio.c_lflag |= 0000010;
 tcsetattr(fd, 2, &tio);
    }
}

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


decompiled_code:
__int64 __fastcall SEC_CheckPassword(const char *a1)
{
const char *v1; // rbx
int v2; // eax
const char *v3; // rdx
char v4; // al

v1 = a1;
v2 = strlen(a1);
if ( v2 > 7 )
{
v3 = &a1[v2];
while ( v1 < v3 )
{
v4 = *v1++;
if ( (unsigned __int8)((v4 & 0xDF) - 65) > 0x19u )
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
const char *v1; // rbx
int v2; // eax
const char *v3; // rdx
char v4; // al

v1 = a1;
v2 = strlen(a1);
if ( v2 > 7 )
{
v3 = &a1[v2];
while ( v1 < v3 )
{
v4 = *v1++;
if ( (unsigned __int8)((v4 & 0xDF) - 65) > 0x19u )
return 1LL;
}
}
return 0LL;
}

original_code:
PRBool SEC_CheckPassword(char *cp)
{
    int len;
    char *end;
    len = strlen(cp);
    if (len < 8) {
 return 0;
    }
    end = cp + len;
    while (cp < end) {
 unsigned char ch = *cp++;
 if (!((ch >= 'A') && (ch <= 'Z')) &&
     !((ch >= 'a') && (ch <= 'z'))) {
     return 1;
 }
    }
    return 0;
}

canonical_original_code:
int SEC_CheckPassword(char *cp)
{
    int len;
    char *end;
    len = strlen(cp);
    if (len < 8) {
 return 0;
    }
    end = cp + len;
    while (cp < end) {
 unsigned char ch = *cp++;
 if (!((ch >= 'A') && (ch <= 'Z')) &&
     !((ch >= 'a') && (ch <= 'z'))) {
     return 1;
 }
    }
    return 0;
}

variable_types:
cp
char *

variable_types: len int

variable_types:
end
char *

variable_types:
ch
unsigned char

return_type: int


decompiled_code:
_BOOL8 __fastcall SEC_BlindCheckPassword(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return a1 != 0;
}

original_code:
PRBool SEC_BlindCheckPassword(char *cp)
{
    if (cp != ((void *)0)) {
 return 1;
    }
    return 0;
}

canonical_original_code:
int SEC_BlindCheckPassword(char *cp)
{
    if (cp != ((void *)0)) {
 return 1;
    }
    return 0;
}


decompiled_code:
__int64 SECU_RegisterDynamicOids()
{
unsigned int v0; // er12
char *v1; // rbx

v0 = 0;
v1 = (char *)&oids;
do
{
if ( !(unsigned int)SECOID_AddEntry(v1) )
v0 = -1;
v1 += 56;
}
while ( v1 != (char *)&vcp4 );
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
char *v1; // rbx

v0 = 0;
v1 = (char *)&oids;
do
{
if ( !(unsigned int)SECOID_AddEntry(v1) )
v0 = -1;
v1 += 56;
}
while ( v1 != (char *)&vcp4 );
return v0;
}

original_code:
SECStatus
SECU_RegisterDynamicOids(void)
{
    unsigned int i;
    SECStatus rv = SECSuccess;
    for (i = 0; i < numOids; ++i) {
 SECOidTag tag = SECOID_AddEntry(&oids[i]);
 if (tag == SEC_OID_UNKNOWN) {
     rv = SECFailure;
 }
    }
    return rv;
}

canonical_original_code:
enum _SECStatus SECU_RegisterDynamicOids()
{
    unsigned int i;
    enum _SECStatus rv = SECSuccess;
    for (i = 0; i < numOids; ++i) {
 enum SECOidTag tag = SECOID_AddEntry(&oids[i]);
 if (tag == SEC_OID_UNKNOWN) {
     rv = SECFailure;
 }
    }
    return rv;
}

variable_types:
i
unsigned int

variable_types: enum _SECStatus { SECWouldBlock=-2, SECFailure=-1, SECSuccess=0 }

variable_types: enum SECOidTag { SEC_OID_UNKNOWN=0, SEC_OID_MD2=1, SEC_OID_MD4=2, SEC_OID_MD5=3, SEC_OID_SHA1=4, SEC_OID_RC2_CBC=5, SEC_OID_RC4=6, SEC_OID_DES_EDE3_CBC=7, SEC_OID_RC5_CBC_PAD=8, SEC_OID_DES_ECB=9, SEC_OID_DES_CBC=10, SEC_OID_DES_OFB=11, SEC_OID_DES_CFB=12, SEC_OID_DES_MAC=13, SEC_OID_DES_EDE=14, SEC_OID_ISO_SHA_WITH_RSA_SIGNATURE=15, SEC_OID_PKCS1_RSA_ENCRYPTION=16, SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION=17, SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION=18, SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION=19, SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION=20, SEC_OID_PKCS5_PBE_WITH_MD2_AND_DES_CBC=21, SEC_OID_PKCS5_PBE_WITH_MD5_AND_DES_CBC=22, SEC_OID_PKCS5_PBE_WITH_SHA1_AND_DES_CBC=23, SEC_OID_PKCS7=24, SEC_OID_PKCS7_DATA=25, SEC_OID_PKCS7_SIGNED_DATA=26, SEC_OID_PKCS7_ENVELOPED_DATA=27, SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA=28, SEC_OID_PKCS7_DIGESTED_DATA=29, SEC_OID_PKCS7_ENCRYPTED_DATA=30, SEC_OID_PKCS9_EMAIL_ADDRESS=31, SEC_OID_PKCS9_UNSTRUCTURED_NAME=32, SEC_OID_PKCS9_CONTENT_TYPE=33, SEC_OID_PKCS9_MESSAGE_DIGEST=34, SEC_OID_PKCS9_SIGNING_TIME=35, SEC_OID_PKCS9_COUNTER_SIGNATURE=36, SEC_OID_PKCS9_CHALLENGE_PASSWORD=37, SEC_OID_PKCS9_UNSTRUCTURED_ADDRESS=38, SEC_OID_PKCS9_EXTENDED_CERTIFICATE_ATTRIBUTES=39, SEC_OID_PKCS9_SMIME_CAPABILITIES=40, SEC_OID_AVA_COMMON_NAME=41, SEC_OID_AVA_COUNTRY_NAME=42, SEC_OID_AVA_LOCALITY=43, SEC_OID_AVA_STATE_OR_PROVINCE=44, SEC_OID_AVA_ORGANIZATION_NAME=45, SEC_OID_AVA_ORGANIZATIONAL_UNIT_NAME=46, SEC_OID_AVA_DN_QUALIFIER=47, SEC_OID_AVA_DC=48, SEC_OID_NS_TYPE_GIF=49, SEC_OID_NS_TYPE_JPEG=50, SEC_OID_NS_TYPE_URL=51, SEC_OID_NS_TYPE_HTML=52, SEC_OID_NS_TYPE_CERT_SEQUENCE=53, SEC_OID_MISSI_KEA_DSS_OLD=54, SEC_OID_MISSI_DSS_OLD=55, SEC_OID_MISSI_KEA_DSS=56, SEC_OID_MISSI_DSS=57, SEC_OID_MISSI_KEA=58, SEC_OID_MISSI_ALT_KEA=59, SEC_OID_NS_CERT_EXT_NETSCAPE_OK=60, SEC_OID_NS_CERT_EXT_ISSUER_LOGO=61, SEC_OID_NS_CERT_EXT_SUBJECT_LOGO=62, SEC_OID_NS_CERT_EXT_CERT_TYPE=63, SEC_OID_NS_CERT_EXT_BASE_URL=64, SEC_OID_NS_CERT_EXT_REVOCATION_URL=65, SEC_OID_NS_CERT_EXT_CA_REVOCATION_URL=66, SEC_OID_NS_CERT_EXT_CA_CRL_URL=67, SEC_OID_NS_CERT_EXT_CA_CERT_URL=68, SEC_OID_NS_CERT_EXT_CERT_RENEWAL_URL=69, SEC_OID_NS_CERT_EXT_CA_POLICY_URL=70, SEC_OID_NS_CERT_EXT_HOMEPAGE_URL=71, SEC_OID_NS_CERT_EXT_ENTITY_LOGO=72, SEC_OID_NS_CERT_EXT_USER_PICTURE=73, SEC_OID_NS_CERT_EXT_SSL_SERVER_NAME=74, SEC_OID_NS_CERT_EXT_COMMENT=75, SEC_OID_NS_CERT_EXT_LOST_PASSWORD_URL=76, SEC_OID_NS_CERT_EXT_CERT_RENEWAL_TIME=77, SEC_OID_NS_KEY_USAGE_GOVT_APPROVED=78, SEC_OID_X509_SUBJECT_DIRECTORY_ATTR=79, SEC_OID_X509_SUBJECT_KEY_ID=80, SEC_OID_X509_KEY_USAGE=81, SEC_OID_X509_PRIVATE_KEY_USAGE_PERIOD=82, SEC_OID_X509_SUBJECT_ALT_NAME=83, SEC_OID_X509_ISSUER_ALT_NAME=84, SEC_OID_X509_BASIC_CONSTRAINTS=85, SEC_OID_X509_NAME_CONSTRAINTS=86, SEC_OID_X509_CRL_DIST_POINTS=87, SEC_OID_X509_CERTIFICATE_POLICIES=88, SEC_OID_X509_POLICY_MAPPINGS=89, SEC_OID_X509_POLICY_CONSTRAINTS=90, SEC_OID_X509_AUTH_KEY_ID=91, SEC_OID_X509_EXT_KEY_USAGE=92, SEC_OID_X509_AUTH_INFO_ACCESS=93, SEC_OID_X509_CRL_NUMBER=94, SEC_OID_X509_REASON_CODE=95, SEC_OID_X509_INVALID_DATE=96, SEC_OID_X500_RSA_ENCRYPTION=97, SEC_OID_RFC1274_UID=98, SEC_OID_RFC1274_MAIL=99, SEC_OID_PKCS12=100, SEC_OID_PKCS12_MODE_IDS=101, SEC_OID_PKCS12_ESPVK_IDS=102, SEC_OID_PKCS12_BAG_IDS=103, SEC_OID_PKCS12_CERT_BAG_IDS=104, SEC_OID_PKCS12_OIDS=105, SEC_OID_PKCS12_PBE_IDS=106, SEC_OID_PKCS12_SIGNATURE_IDS=107, SEC_OID_PKCS12_ENVELOPING_IDS=108, SEC_OID_PKCS12_PKCS8_KEY_SHROUDING=109, SEC_OID_PKCS12_KEY_BAG_ID=110, SEC_OID_PKCS12_CERT_AND_CRL_BAG_ID=111, SEC_OID_PKCS12_SECRET_BAG_ID=112, SEC_OID_PKCS12_X509_CERT_CRL_BAG=113, SEC_OID_PKCS12_SDSI_CERT_BAG=114, SEC_OID_PKCS12_PBE_WITH_SHA1_AND_128_BIT_RC4=115, SEC_OID_PKCS12_PBE_WITH_SHA1_AND_40_BIT_RC4=116, SEC_OID_PKCS12_PBE_WITH_SHA1_AND_TRIPLE_DES_CBC=117, SEC_OID_PKCS12_PBE_WITH_SHA1_AND_128_BIT_RC2_CBC=118, SEC_OID_PKCS12_PBE_WITH_SHA1_AND_40_BIT_RC2_CBC=119, SEC_OID_PKCS12_RSA_ENCRYPTION_WITH_128_BIT_RC4=120, SEC_OID_PKCS12_RSA_ENCRYPTION_WITH_40_BIT_RC4=121, SEC_OID_PKCS12_RSA_ENCRYPTION_WITH_TRIPLE_DES=122, SEC_OID_PKCS12_RSA_SIGNATURE_WITH_SHA1_DIGEST=123, SEC_OID_ANSIX9_DSA_SIGNATURE=124, SEC_OID_ANSIX9_DSA_SIGNATURE_WITH_SHA1_DIGEST=125, SEC_OID_BOGUS_DSA_SIGNATURE_WITH_SHA1_DIGEST=126, SEC_OID_VERISIGN_USER_NOTICES=127, SEC_OID_PKIX_CPS_POINTER_QUALIFIER=128, SEC_OID_PKIX_USER_NOTICE_QUALIFIER=129, SEC_OID_PKIX_OCSP=130, SEC_OID_PKIX_OCSP_BASIC_RESPONSE=131, SEC_OID_PKIX_OCSP_NONCE=132, SEC_OID_PKIX_OCSP_CRL=133, SEC_OID_PKIX_OCSP_RESPONSE=134, SEC_OID_PKIX_OCSP_NO_CHECK=135, SEC_OID_PKIX_OCSP_ARCHIVE_CUTOFF=136, SEC_OID_PKIX_OCSP_SERVICE_LOCATOR=137, SEC_OID_PKIX_REGCTRL_REGTOKEN=138, SEC_OID_PKIX_REGCTRL_AUTHENTICATOR=139, SEC_OID_PKIX_REGCTRL_PKIPUBINFO=140, SEC_OID_PKIX_REGCTRL_PKI_ARCH_OPTIONS=141, SEC_OID_PKIX_REGCTRL_OLD_CERT_ID=142, SEC_OID_PKIX_REGCTRL_PROTOCOL_ENC_KEY=143, SEC_OID_PKIX_REGINFO_UTF8_PAIRS=144, SEC_OID_PKIX_REGINFO_CERT_REQUEST=145, SEC_OID_EXT_KEY_USAGE_SERVER_AUTH=146, SEC_OID_EXT_KEY_USAGE_CLIENT_AUTH=147, SEC_OID_EXT_KEY_USAGE_CODE_SIGN=148, SEC_OID_EXT_KEY_USAGE_EMAIL_PROTECT=149, SEC_OID_EXT_KEY_USAGE_TIME_STAMP=150, SEC_OID_OCSP_RESPONDER=151, SEC_OID_NETSCAPE_SMIME_KEA=152, SEC_OID_FORTEZZA_SKIPJACK=153, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_128_BIT_RC4=154, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_40_BIT_RC4=155, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC=156, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_2KEY_TRIPLE_DES_CBC=157, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_128_BIT_RC2_CBC=158, SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_40_BIT_RC2_CBC=159, SEC_OID_PKCS12_SAFE_CONTENTS_ID=160, SEC_OID_PKCS12_PKCS8_SHROUDED_KEY_BAG_ID=161, SEC_OID_PKCS12_V1_KEY_BAG_ID=162, SEC_OID_PKCS12_V1_PKCS8_SHROUDED_KEY_BAG_ID=163, SEC_OID_PKCS12_V1_CERT_BAG_ID=164, SEC_OID_PKCS12_V1_CRL_BAG_ID=165, SEC_OID_PKCS12_V1_SECRET_BAG_ID=166, SEC_OID_PKCS12_V1_SAFE_CONTENTS_BAG_ID=167, SEC_OID_PKCS9_X509_CERT=168, SEC_OID_PKCS9_SDSI_CERT=169, SEC_OID_PKCS9_X509_CRL=170, SEC_OID_PKCS9_FRIENDLY_NAME=171, SEC_OID_PKCS9_LOCAL_KEY_ID=172, SEC_OID_BOGUS_KEY_USAGE=173, SEC_OID_X942_DIFFIE_HELMAN_KEY=174, SEC_OID_NETSCAPE_NICKNAME=175, SEC_OID_NETSCAPE_RECOVERY_REQUEST=176, SEC_OID_CERT_RENEWAL_LOCATOR=177, SEC_OID_NS_CERT_EXT_SCOPE_OF_USE=178, SEC_OID_CMS_EPHEMERAL_STATIC_DIFFIE_HELLMAN=179, SEC_OID_CMS_3DES_KEY_WRAP=180, SEC_OID_CMS_RC2_KEY_WRAP=181, SEC_OID_SMIME_ENCRYPTION_KEY_PREFERENCE=182, SEC_OID_AES_128_ECB=183, SEC_OID_AES_128_CBC=184, SEC_OID_AES_192_ECB=185, SEC_OID_AES_192_CBC=186, SEC_OID_AES_256_ECB=187, SEC_OID_AES_256_CBC=188, SEC_OID_SDN702_DSA_SIGNATURE=189, SEC_OID_MS_SMIME_ENCRYPTION_KEY_PREFERENCE=190, SEC_OID_SHA256=191, SEC_OID_SHA384=192, SEC_OID_SHA512=193, SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION=194, SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION=195, SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION=196, SEC_OID_AES_128_KEY_WRAP=197, SEC_OID_AES_192_KEY_WRAP=198, SEC_OID_AES_256_KEY_WRAP=199, SEC_OID_ANSIX962_EC_PUBLIC_KEY=200, SEC_OID_ANSIX962_ECDSA_SHA1_SIGNATURE=201, SEC_OID_ANSIX962_EC_PRIME192V1=202, SEC_OID_ANSIX962_EC_PRIME192V2=203, SEC_OID_ANSIX962_EC_PRIME192V3=204, SEC_OID_ANSIX962_EC_PRIME239V1=205, SEC_OID_ANSIX962_EC_PRIME239V2=206, SEC_OID_ANSIX962_EC_PRIME239V3=207, SEC_OID_ANSIX962_EC_PRIME256V1=208, SEC_OID_SECG_EC_SECP112R1=209, SEC_OID_SECG_EC_SECP112R2=210, SEC_OID_SECG_EC_SECP128R1=211, SEC_OID_SECG_EC_SECP128R2=212, SEC_OID_SECG_EC_SECP160K1=213, SEC_OID_SECG_EC_SECP160R1=214, SEC_OID_SECG_EC_SECP160R2=215, SEC_OID_SECG_EC_SECP192K1=216, SEC_OID_SECG_EC_SECP224K1=217, SEC_OID_SECG_EC_SECP224R1=218, SEC_OID_SECG_EC_SECP256K1=219, SEC_OID_SECG_EC_SECP384R1=220, SEC_OID_SECG_EC_SECP521R1=221, SEC_OID_ANSIX962_EC_C2PNB163V1=222, SEC_OID_ANSIX962_EC_C2PNB163V2=223, SEC_OID_ANSIX962_EC_C2PNB163V3=224, SEC_OID_ANSIX962_EC_C2PNB176V1=225, SEC_OID_ANSIX962_EC_C2TNB191V1=226, SEC_OID_ANSIX962_EC_C2TNB191V2=227, SEC_OID_ANSIX962_EC_C2TNB191V3=228, SEC_OID_ANSIX962_EC_C2ONB191V4=229, SEC_OID_ANSIX962_EC_C2ONB191V5=230, SEC_OID_ANSIX962_EC_C2PNB208W1=231, SEC_OID_ANSIX962_EC_C2TNB239V1=232, SEC_OID_ANSIX962_EC_C2TNB239V2=233, SEC_OID_ANSIX962_EC_C2TNB239V3=234, SEC_OID_ANSIX962_EC_C2ONB239V4=235, SEC_OID_ANSIX962_EC_C2ONB239V5=236, SEC_OID_ANSIX962_EC_C2PNB272W1=237, SEC_OID_ANSIX962_EC_C2PNB304W1=238, SEC_OID_ANSIX962_EC_C2TNB359V1=239, SEC_OID_ANSIX962_EC_C2PNB368W1=240, SEC_OID_ANSIX962_EC_C2TNB431R1=241, SEC_OID_SECG_EC_SECT113R1=242, SEC_OID_SECG_EC_SECT113R2=243, SEC_OID_SECG_EC_SECT131R1=244, SEC_OID_SECG_EC_SECT131R2=245, SEC_OID_SECG_EC_SECT163K1=246, SEC_OID_SECG_EC_SECT163R1=247, SEC_OID_SECG_EC_SECT163R2=248, SEC_OID_SECG_EC_SECT193R1=249, SEC_OID_SECG_EC_SECT193R2=250, SEC_OID_SECG_EC_SECT233K1=251, SEC_OID_SECG_EC_SECT233R1=252, SEC_OID_SECG_EC_SECT239K1=253, SEC_OID_SECG_EC_SECT283K1=254, SEC_OID_SECG_EC_SECT283R1=255, SEC_OID_SECG_EC_SECT409K1=256, SEC_OID_SECG_EC_SECT409R1=257, SEC_OID_SECG_EC_SECT571K1=258, SEC_OID_SECG_EC_SECT571R1=259, SEC_OID_NETSCAPE_AOLSCREENNAME=260, SEC_OID_AVA_SURNAME=261, SEC_OID_AVA_SERIAL_NUMBER=262, SEC_OID_AVA_STREET_ADDRESS=263, SEC_OID_AVA_TITLE=264, SEC_OID_AVA_POSTAL_ADDRESS=265, SEC_OID_AVA_POSTAL_CODE=266, SEC_OID_AVA_POST_OFFICE_BOX=267, SEC_OID_AVA_GIVEN_NAME=268, SEC_OID_AVA_INITIALS=269, SEC_OID_AVA_GENERATION_QUALIFIER=270, SEC_OID_AVA_HOUSE_IDENTIFIER=271, SEC_OID_AVA_PSEUDONYM=272, SEC_OID_PKIX_CA_ISSUERS=273, SEC_OID_PKCS9_EXTENSION_REQUEST=274, SEC_OID_ANSIX962_ECDSA_SIGNATURE_RECOMMENDED_DIGEST=275, SEC_OID_ANSIX962_ECDSA_SIGNATURE_SPECIFIED_DIGEST=276, SEC_OID_ANSIX962_ECDSA_SHA224_SIGNATURE=277, SEC_OID_ANSIX962_ECDSA_SHA256_SIGNATURE=278, SEC_OID_ANSIX962_ECDSA_SHA384_SIGNATURE=279, SEC_OID_ANSIX962_ECDSA_SHA512_SIGNATURE=280, SEC_OID_X509_HOLD_INSTRUCTION_CODE=281, SEC_OID_X509_DELTA_CRL_INDICATOR=282, SEC_OID_X509_ISSUING_DISTRIBUTION_POINT=283, SEC_OID_X509_CERT_ISSUER=284, SEC_OID_X509_FRESHEST_CRL=285, SEC_OID_X509_INHIBIT_ANY_POLICY=286, SEC_OID_X509_SUBJECT_INFO_ACCESS=287, SEC_OID_CAMELLIA_128_CBC=288, SEC_OID_CAMELLIA_192_CBC=289, SEC_OID_CAMELLIA_256_CBC=290, SEC_OID_PKCS5_PBKDF2=291, SEC_OID_PKCS5_PBES2=292, SEC_OID_PKCS5_PBMAC1=293, SEC_OID_HMAC_SHA1=294, SEC_OID_HMAC_SHA224=295, SEC_OID_HMAC_SHA256=296, SEC_OID_HMAC_SHA384=297, SEC_OID_HMAC_SHA512=298, SEC_OID_PKIX_TIMESTAMPING=299, SEC_OID_PKIX_CA_REPOSITORY=300, SEC_OID_ISO_SHA1_WITH_RSA_SIGNATURE=301, SEC_OID_SEED_CBC=302, SEC_OID_X509_ANY_POLICY=303, SEC_OID_PKCS1_RSA_OAEP_ENCRYPTION=304, SEC_OID_PKCS1_MGF1=305, SEC_OID_PKCS1_PSPECIFIED=306, SEC_OID_PKCS1_RSA_PSS_SIGNATURE=307, SEC_OID_PKCS1_SHA224_WITH_RSA_ENCRYPTION=308, SEC_OID_SHA224=309, SEC_OID_EV_INCORPORATION_LOCALITY=310, SEC_OID_EV_INCORPORATION_STATE=311, SEC_OID_EV_INCORPORATION_COUNTRY=312, SEC_OID_BUSINESS_CATEGORY=313, SEC_OID_NIST_DSA_SIGNATURE_WITH_SHA224_DIGEST=314, SEC_OID_NIST_DSA_SIGNATURE_WITH_SHA256_DIGEST=315, SEC_OID_MS_EXT_KEY_USAGE_CTL_SIGNING=316, SEC_OID_AVA_NAME=317, SEC_OID_AES_128_GCM=318, SEC_OID_AES_192_GCM=319, SEC_OID_AES_256_GCM=320, SEC_OID_IDEA_CBC=321, SEC_OID_RC2_40_CBC=322, SEC_OID_DES_40_CBC=323, SEC_OID_RC4_40=324, SEC_OID_RC4_56=325, SEC_OID_NULL_CIPHER=326, SEC_OID_HMAC_MD5=327, SEC_OID_TLS_RSA=328, SEC_OID_TLS_DHE_RSA=329, SEC_OID_TLS_DHE_DSS=330, SEC_OID_TLS_DH_RSA=331, SEC_OID_TLS_DH_DSS=332, SEC_OID_TLS_DH_ANON=333, SEC_OID_TLS_ECDHE_ECDSA=334, SEC_OID_TLS_ECDHE_RSA=335, SEC_OID_TLS_ECDH_ECDSA=336, SEC_OID_TLS_ECDH_RSA=337, SEC_OID_TLS_ECDH_ANON=338, SEC_OID_TLS_RSA_EXPORT=339, SEC_OID_TLS_DHE_RSA_EXPORT=340, SEC_OID_TLS_DHE_DSS_EXPORT=341, SEC_OID_TLS_DH_RSA_EXPORT=342, SEC_OID_TLS_DH_DSS_EXPORT=343, SEC_OID_TLS_DH_ANON_EXPORT=344, SEC_OID_APPLY_SSL_POLICY=345, SEC_OID_CHACHA20_POLY1305=346, SEC_OID_TLS_ECDHE_PSK=347, SEC_OID_TLS_DHE_PSK=348, SEC_OID_TLS_FFDHE_2048=349, SEC_OID_TLS_FFDHE_3072=350, SEC_OID_TLS_FFDHE_4096=351, SEC_OID_TLS_FFDHE_6144=352, SEC_OID_TLS_FFDHE_8192=353, SEC_OID_TLS_DHE_CUSTOM=354, SEC_OID_CURVE25519=355, SEC_OID_TLS13_KEA_ANY=356, SEC_OID_X509_ANY_EXT_KEY_USAGE=357, SEC_OID_EXT_KEY_USAGE_IPSEC_IKE=358, SEC_OID_IPSEC_IKE_END=359, SEC_OID_IPSEC_IKE_INTERMEDIATE=360, SEC_OID_TOTAL=361 }


decompiled_code:
__int64 __fastcall SECU_Strerror(int a1)
{
unsigned int v1; // ebp
const char **v2; // rbx
__int64 i; // rcx
unsigned int v4; // er12
__int64 v5; // rcx
__int64 v6; // rsi
int v7; // edx
__int64 v8; // rsi
__int64 v9; // rcx
__int64 result; // rax

v1 = initDone_0;
if ( !initDone_0 )
{
v2 = (const char **)(unsigned int)((_DWORD)errStrings + 8);
for ( i = 4294955008LL; ; i = v4 )
{
++v1;
v2 += 2;
if ( v1 == 338 )
break;
v4 = *((_DWORD *)v2 - 2);
if ( (int)i >= (int)v4 )
fprintf(
stderr,
"sequence error in error strings at item %d\nerror %d (%s)\nshould come after \nerror %d (%s)\n",
v1,
i,
*(v2 - 2),
v4,
*v2);
}
initDone_0 = 1;
}
v5 = 337LL;
v6 = 0LL;
while ( (int)v5 > (int)v6 + 1 )
{
v7 = ((int)v5 + (int)v6) >> 1;
if ( a1 == LODWORD(errStrings[2 * v7]) )
return errStrings[2 * v7 + 1];
if ( a1 >= SLODWORD(errStrings[2 * v7]) )
v6 = v7;
else
v5 = v7;
}
v8 = 2 * v6;
if ( LODWORD(errStrings[v8]) == a1 )
return errStrings[v8 + 1];
v9 = 2 * v5;
result = 0LL;
if ( LODWORD(errStrings[v9]) == a1 )
result = errStrings[v9 + 1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ebp
const char **v2; // rbx
__int64 i; // rcx
unsigned int v4; // er12
__int64 v5; // rcx
__int64 v6; // rsi
int v7; // edx
__int64 v8; // rsi
__int64 v9; // rcx
__int64 result; // rax

v1 = initDone_0;
if ( !initDone_0 )
{
v2 = (const char **)(unsigned int)((_DWORD)errStrings + 8);
for ( i = 4294955008LL; ; i = v4 )
{
++v1;
v2 += 2;
if ( v1 == 338 )
break;
v4 = *((_DWORD *)v2 - 2);
if ( (int)i >= (int)v4 )
fprintf(
stderr,
"sequence error in error strings at item %d\nerror %d (%s)\nshould come after \nerror %d (%s)\n",
v1,
i,
*(v2 - 2),
v4,
*v2);
}
initDone_0 = 1;
}
v5 = 337LL;
v6 = 0LL;
while ( (int)v5 > (int)v6 + 1 )
{
v7 = ((int)v5 + (int)v6) >> 1;
if ( a1 == LODWORD(errStrings[2 * v7]) )
return errStrings[2 * v7 + 1];
if ( a1 >= SLODWORD(errStrings[2 * v7]) )
v6 = v7;
else
v5 = v7;
}
v8 = 2 * v6;
if ( LODWORD(errStrings[v8]) == a1 )
return errStrings[v8 + 1];
v9 = 2 * v5;
result = 0LL;
if ( LODWORD(errStrings[v9]) == a1 )
result = errStrings[v9 + 1];
return result;
}

original_code:
const char *
SECU_Strerror(PRErrorCode errNum) {
    PRInt32 low = 0;
    PRInt32 high = numStrings - 1;
    PRInt32 i;
    PRErrorCode num;
    static int initDone;
    if (!initDone) {
 PRErrorCode lastNum = ((PRInt32)0x80000000);
     for (i = low; i <= high; ++i) {
     num = errStrings[i].errNum;
     if (num <= lastNum) {
      fprintf(stderr,
"sequence error in error strings at item %d\n"
"error %d (%s)\n"
"should come after \n"
"error %d (%s)\n",
          i, lastNum, errStrings[i-1].errString,
   num, errStrings[i].errString);
     }
     lastNum = num;
 }
 initDone = 1;
    }
    while (low + 1 < high) {
     i = (low + high) / 2;
 num = errStrings[i].errNum;
 if (errNum == num)
     return errStrings[i].errString;
        if (errNum < num)
     high = i;
 else
     low = i;
    }
    if (errNum == errStrings[low].errNum)
     return errStrings[low].errString;
    if (errNum == errStrings[high].errNum)
     return errStrings[high].errString;
    return ((void *)0);
}

canonical_original_code:
char *SECU_Strerror(int errNum) {
    int low = 0;
    int high = numStrings - 1;
    int i;
    int num;
    static int initDone;
    if (!initDone) {
 int lastNum = ((PRInt32)0x80000000);
     for (i = low; i <= high; ++i) {
     num = errStrings[i].errNum;
     if (num <= lastNum) {
      fprintf(stderr,
"sequence error in error strings at item %d\n"
"error %d (%s)\n"
"should come after \n"
"error %d (%s)\n",
          i, lastNum, errStrings[i-1].errString,
   num, errStrings[i].errString);
     }
     lastNum = num;
 }
 initDone = 1;
    }
    while (low + 1 < high) {
     i = (low + high) / 2;
 num = errStrings[i].errNum;
 if (errNum == num)
     return errStrings[i].errString;
        if (errNum < num)
     high = i;
 else
     low = i;
    }
    if (errNum == errStrings[low].errNum)
     return errStrings[low].errString;
    if (errNum == errStrings[high].errNum)
     return errStrings[high].errString;
    return ((void *)0);
}

variable_types: errNum int

variable_types: low int

variable_types: high int

variable_types: i int

variable_types: num int

variable_types: initDone int

variable_types: lastNum int

return_type: char *


main

canonical_name: main

repo: bartoszp/killfd

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v4; // er13
char v5; // al
int v6; // ebx
int v7; // ebx
__int64 v8; // rcx
_DWORD *v9; // rsi
char *v10; // rdi
__int64 v11; // rax
int v12; // ebx
int v13; // ebx
int v14; // ebx
int v15; // ebx
char v16; // [rsp+0h] [rbp-208h]
char v17; // [rsp+0h] [rbp-208h]
char v18; // [rsp+0h] [rbp-208h]
char v19; // [rsp+0h] [rbp-208h]
char v20; // [rsp+0h] [rbp-208h]
char v21; // [rsp+0h] [rbp-208h]
char v22; // [rsp+0h] [rbp-208h]
char v23; // [rsp+0h] [rbp-208h]
char v24; // [rsp+0h] [rbp-208h]
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1FCh] BYREF
char v26[80]; // [rsp+F0h] [rbp-118h] BYREF
__int64 v27; // [rsp+140h] [rbp-C8h]
__int64 v28; // [rsp+160h] [rbp-A8h]
__int64 v29; // [rsp+170h] [rbp-98h]

v4 = -1;
verbose("user_regs_struct size: %d\n", v16);
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vp:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'p':
v4 = atoi(optarg);
break;
case 'v':
flag_verbose = 1;
break;
case '?':
if ( optopt == 112 )
error(1, (char)"-p requires an argument (pid of the process)\n");
break;
default:
main_cold();
}
}
if ( v4 != -1 && optind + 1 >= argc && optind != argc )
{
if ( optind < argc )
v3 = atol(argv[optind]);
v6 = ptrace(PTRACE_ATTACH, v4, 0LL, 0LL);
verbose("ptrace attach: %d\n", v17);
if ( v6 )
error(
1,
(char)"error in ptrace attach: %d to pid: %d; is the process running and are you allowed to attach to it?\n");
while ( 1 )
{
wait((__WAIT_STATUS)&stat_loc);
verbose("wait: %d, %x\n", v18);
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
if ( LOBYTE(stat_loc.__uptr) == 127 )
{
verbose("Child received signal: %d\n", v18);
v7 = ptrace(PTRACE_GETREGS, v4, 0LL, (char *)&stat_loc.__iptr + 4);
verbose("ptrace getregs: %d\n", v19);
if ( !v7 )
{
v8 = 54LL;
v9 = (_DWORD *)&stat_loc.__iptr + 1;
v10 = v26;
while ( v8 )
{
*(_DWORD *)v10 = *v9++;
v10 += 4;
--v8;
}
v11 = find_syscall(v4, v9);
if ( v11 )
{
v29 = v11;
v27 = 3LL;
v28 = v3;
v12 = ptrace(PTRACE_SETREGS, v4, 0LL, v26);
verbose("setregs: %d\n", v20);
if ( !v12 )
{
v13 = ptrace(PTRACE_SINGLESTEP, v4, 0LL, 0LL);
verbose("ptrace singlestep: %d\n", v21);
if ( !v13 )
{
wait((__WAIT_STATUS)&stat_loc);
verbose("wait: %d, %x\n", v22);
v14 = ptrace(PTRACE_SETREGS, v4, 0LL, (char *)&stat_loc.__iptr + 4);
verbose("setregs: %d\n", v23);
if ( !v14 )
{
v15 = ptrace(PTRACE_DETACH, v4, 0LL, 18LL);
verbose("detach(): %d\n", v24);
if ( v15 )
error(1, (char)"ptrace detach error: %d\n");
exit(0);
}
error(1, (char)"ptrace setregs error: %d\n");
}
error(1, (char)"ptrace singlestep error: %d\n");
}
error(1, (char)"ptrace setregs error: %d\n");
}
error(1, (char)"Couldn't find system call machine code\n");
}
error(1, (char)"ptrace getregs error: %d\n");
}
}
error(1, (char)"The process has terminated\n");
}
usage(argv);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v4; // er13
char v5; // al
int v6; // ebx
int v7; // ebx
__int64 v8; // rcx
_DWORD *v9; // rsi
char *v10; // rdi
__int64 v11; // rax
int v12; // ebx
int v13; // ebx
int v14; // ebx
int v15; // ebx
char v16; // [rsp+0h] [rbp-208h]
char v17; // [rsp+0h] [rbp-208h]
char v18; // [rsp+0h] [rbp-208h]
char v19; // [rsp+0h] [rbp-208h]
char v20; // [rsp+0h] [rbp-208h]
char v21; // [rsp+0h] [rbp-208h]
char v22; // [rsp+0h] [rbp-208h]
char v23; // [rsp+0h] [rbp-208h]
char v24; // [rsp+0h] [rbp-208h]
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1FCh] BYREF
char v26[80]; // [rsp+F0h] [rbp-118h] BYREF
__int64 v27; // [rsp+140h] [rbp-C8h]
__int64 v28; // [rsp+160h] [rbp-A8h]
__int64 v29; // [rsp+170h] [rbp-98h]

v4 = -1;
func8("user_regs_struct size: %d\n", v16);
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vp:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'p':
v4 = atoi(optarg);
break;
case 'v':
flag_verbose = 1;
break;
case '?':
if ( optopt == 112 )
func9(1, (char)"-p requires an argument (pid of the process)\n");
break;
default:
func1();
}
}
if ( v4 != -1 && optind + 1 >= argc && optind != argc )
{
if ( optind < argc )
v3 = atol(argv[optind]);
v6 = ptrace(PTRACE_ATTACH, v4, 0LL, 0LL);
func8("ptrace attach: %d\n", v17);
if ( v6 )
func9(
1,
(char)"error in ptrace attach: %d to pid: %d; is the process running and are you allowed to attach to it?\n");
while ( 1 )
{
wait((__WAIT_STATUS)&stat_loc);
func8("wait: %d, %x\n", v18);
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
if ( LOBYTE(stat_loc.__uptr) == 127 )
{
func8("Child received signal: %d\n", v18);
v7 = ptrace(PTRACE_GETREGS, v4, 0LL, (char *)&stat_loc.__iptr + 4);
func8("ptrace getregs: %d\n", v19);
if ( !v7 )
{
v8 = 54LL;
v9 = (_DWORD *)&stat_loc.__iptr + 1;
v10 = v26;
while ( v8 )
{
*(_DWORD *)v10 = *v9++;
v10 += 4;
--v8;
}
v11 = func10(v4, v9);
if ( v11 )
{
v29 = v11;
v27 = 3LL;
v28 = v3;
v12 = ptrace(PTRACE_SETREGS, v4, 0LL, v26);
func8("setregs: %d\n", v20);
if ( !v12 )
{
v13 = ptrace(PTRACE_SINGLESTEP, v4, 0LL, 0LL);
func8("ptrace singlestep: %d\n", v21);
if ( !v13 )
{
wait((__WAIT_STATUS)&stat_loc);
func8("wait: %d, %x\n", v22);
v14 = ptrace(PTRACE_SETREGS, v4, 0LL, (char *)&stat_loc.__iptr + 4);
func8("setregs: %d\n", v23);
if ( !v14 )
{
v15 = ptrace(PTRACE_DETACH, v4, 0LL, 18LL);
func8("detach(): %d\n", v24);
if ( v15 )
func9(1, (char)"ptrace detach error: %d\n");
exit(0);
}
func9(1, (char)"ptrace setregs error: %d\n");
}
func9(1, (char)"ptrace singlestep error: %d\n");
}
func9(1, (char)"ptrace setregs error: %d\n");
}
func9(1, (char)"Couldn't find system call machine code\n");
}
func9(1, (char)"ptrace getregs error: %d\n");
}
}
func9(1, (char)"The process has terminated\n");
}
func11(argv);
}

original_code:
int main (int argc, char **argv) {
        struct user_regs_struct orig_regs, new_regs;
        int pid = -1, status, last_status = 0;
        int data = 0, done = 0, i, *p, fd, ec;
        char c;
        unsigned char *t;
 long int file_desc_no;
        verbose("user_regs_struct size: %d\n", sizeof(struct user_regs_struct));
 while ((c = getopt (argc, argv, "vp:")) != -1)
  switch (c) {
   case 'p':
    pid = atoi(optarg);
    break;
   case 'v':
    flag_verbose = 1;
    break;
   case '?':
    if (optopt == 'p')
     error(1, "-p requires an argument (pid of the process)\n");
    break;
   default:
    abort ();
  }
 if (pid == -1 || (optind + 1 < argc) || (optind == argc)) {
  usage(argv);
 }
 if (optind < argc) {
  file_desc_no = atol(argv[optind]);
 }
        i = 0;
        if (1) {
  ec = ptrace(PTRACE_ATTACH, pid, 0, 0);
                verbose("ptrace attach: %d\n", ec);
  if (ec)
   error(1, "error in ptrace attach: %d to pid: %d; is the process running and are you allowed to attach to it?\n", ec, pid);
                while (1) {
                        data = 0;
                        wait(&status);
                        verbose("wait: %d, %x\n", status, status);
                        if (done) {
                                p = (int *) &orig_regs;
                                ec = ptrace(PTRACE_SETREGS, pid, 0, &orig_regs);
    verbose("setregs: %d\n", ec);
    if (ec)
     error(1, "ptrace setregs error: %d\n", ec);
    ec = ptrace(PTRACE_DETACH, pid, 0, 18);
                                verbose("detach(): %d\n", ec);
    if (ec)
     error(1, "ptrace detach error: %d\n", ec);
                                exit(0);
                        }
                        if ((((status) & 0x7f) == 0)) {
    error(1, "The process has terminated\n");
                        }
                        if ((((status) & 0xff) == 0x7f)) {
                                verbose("Child received signal: %d\n", (((status) & 0xff00) >> 8));
                                if ((((status) & 0xff00) >> 8) != 5)
                                        data = (((status) & 0xff00) >> 8);
                                p = (int *) &orig_regs;
    ec = ptrace(PTRACE_GETREGS, pid, 0, &orig_regs);
                                verbose("ptrace getregs: %d\n", ec);
    if (ec)
     error(1, "ptrace getregs error: %d\n", ec);
                                memcpy(&new_regs, &orig_regs, sizeof(orig_regs));
    t = find_syscall(pid);
    if (!t)
     error(1, "Couldn't find system call machine code\n");
                                new_regs.rax = 3;
                                new_regs.rdi = file_desc_no;
                                new_regs.rip = (long int) t;
    ec = ptrace(PTRACE_SETREGS, pid, 0, &new_regs);
                                verbose("setregs: %d\n", ec);
    if (ec)
     error(1, "ptrace setregs error: %d\n", ec);
    ec = ptrace(PTRACE_SINGLESTEP, pid, 0, 0);
                                verbose("ptrace singlestep: %d\n", ec);
    if (ec)
     error(1, "ptrace singlestep error: %d\n", ec);
                                done = 1;
                        }
                }
                verbose("This is the end\n");
        }
}

canonical_original_code:
int main(int argc, char **argv) {
        struct user_regs_struct orig_regs; struct user_regs_struct new_regs;
        int pid = -1; int status; int last_status = 0;
        int data = 0; int done = 0; int i; int *p; int fd; int ec;
        char c;
        unsigned char *t;
 long file_desc_no;
        verbose("user_regs_struct size: %d\n", sizeof(struct user_regs_struct));
 while ((c = getopt (argc, argv, "vp:")) != -1)
  switch (c) {
   case 'p':
    pid = atoi(optarg);
    break;
   case 'v':
    flag_verbose = 1;
    break;
   case '?':
    if (optopt == 'p')
     error(1, "-p requires an argument (pid of the process)\n");
    break;
   default:
    abort ();
  }
 if (pid == -1 || (optind + 1 < argc) || (optind == argc)) {
  usage(argv);
 }
 if (optind < argc) {
  file_desc_no = atol(argv[optind]);
 }
        i = 0;
        if (1) {
  ec = ptrace(PTRACE_ATTACH, pid, 0, 0);
                verbose("ptrace attach: %d\n", ec);
  if (ec)
   error(1, "error in ptrace attach: %d to pid: %d; is the process running and are you allowed to attach to it?\n", ec, pid);
                while (1) {
                        data = 0;
                        wait(&status);
                        verbose("wait: %d, %x\n", status, status);
                        if (done) {
                                p = (int *) &orig_regs;
                                ec = ptrace(PTRACE_SETREGS, pid, 0, &orig_regs);
    verbose("setregs: %d\n", ec);
    if (ec)
     error(1, "ptrace setregs error: %d\n", ec);
    ec = ptrace(PTRACE_DETACH, pid, 0, 18);
                                verbose("detach(): %d\n", ec);
    if (ec)
     error(1, "ptrace detach error: %d\n", ec);
                                exit(0);
                        }
                        if ((((status) & 0x7f) == 0)) {
    error(1, "The process has terminated\n");
                        }
                        if ((((status) & 0xff) == 0x7f)) {
                                verbose("Child received signal: %d\n", (((status) & 0xff00) >> 8));
                                if ((((status) & 0xff00) >> 8) != 5)
                                        data = (((status) & 0xff00) >> 8);
                                p = (int *) &orig_regs;
    ec = ptrace(PTRACE_GETREGS, pid, 0, &orig_regs);
                                verbose("ptrace getregs: %d\n", ec);
    if (ec)
     error(1, "ptrace getregs error: %d\n", ec);
                                memcpy(&new_regs, &orig_regs, sizeof(orig_regs));
    t = find_syscall(pid);
    if (!t)
     error(1, "Couldn't find system call machine code\n");
                                new_regs.rax = 3;
                                new_regs.rdi = file_desc_no;
                                new_regs.rip = (long) t;
    ec = ptrace(PTRACE_SETREGS, pid, 0, &new_regs);
                                verbose("setregs: %d\n", ec);
    if (ec)
     error(1, "ptrace setregs error: %d\n", ec);
    ec = ptrace(PTRACE_SINGLESTEP, pid, 0, 0);
                                verbose("ptrace singlestep: %d\n", ec);
    if (ec)
     error(1, "ptrace singlestep error: %d\n", ec);
                                done = 1;
                        }
                }
                verbose("This is the end\n");
        }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct user_regs_struct { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long rbp; unsigned long long rbx; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rax; unsigned long long rcx; unsigned long long rdx; unsigned long long rsi; unsigned long long rdi; unsigned long long orig_rax; unsigned long long rip; unsigned long long cs; unsigned long long eflags; unsigned long long rsp; unsigned long long ss; unsigned long long fs_base; unsigned long long gs_base; unsigned long long ds; unsigned long long es; unsigned long long fs; unsigned long long gs; }

variable_types: pid int

variable_types: status int

variable_types: data int

variable_types: done int

variable_types:
p
int *

variable_types: ec int

variable_types: c char

variable_types:
t
unsigned char *


verbose

decompiled_code:
int verbose(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
result = flag_verbose;
if ( flag_verbose )
result = vfprintf(stderr, format, arg);
return result;
}

canonical_decompiled_code:
int func8(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
result = flag_verbose;
if ( flag_verbose )
result = vfprintf(stderr, format, arg);
return result;
}

original_code:
void verbose(char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 if (flag_verbose)
  vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void verbose(char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 if (flag_verbose)
  vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


error

decompiled_code:
void __noreturn error(int status, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
vfprintf(stderr, a2, arg);
exit(status);
}

canonical_decompiled_code:
void __noreturn func9(int status, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
vfprintf(stderr, a2, arg);
exit(status);
}

original_code:
void error(int exit_code, char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(exit_code);
}

canonical_original_code:
void error(int exit_code, char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(exit_code);
}


decompiled_code:
unsigned __int64 __fastcall find_syscall(unsigned int a1)
{
int v2; // eax
int v3; // er12
int v4; // ebp
__int64 v5; // rbx
unsigned int v6; // ebx
char *v7; // rax
unsigned __int64 v8; // r14
__int64 v9; // rax
__int64 v10; // rdx
int v11; // eax
_BOOL8 v12; // rbp
__int64 v13; // rsi
unsigned __int64 v14; // rbx
char *v15; // rcx
__int64 v16; // rax
char v17; // di
char v19[4]; // [rsp+Bh] [rbp-26Dh] BYREF
char v20; // [rsp+Fh] [rbp-269h] BYREF
unsigned __int64 v21; // [rsp+10h] [rbp-268h]
__int64 v22; // [rsp+18h] [rbp-260h]
__int64 v23[2]; // [rsp+20h] [rbp-258h]
char s[32]; // [rsp+30h] [rbp-248h] BYREF
char v25[552]; // [rsp+50h] [rbp-228h] BYREF

v23[0] = 0LL;
v23[1] = 0LL;
snprintf(s, 0x20uLL, "/proc/%d/maps", a1);
verbose("Opening process's maps file: %s\n", s);
v2 = open(s, 0);
if ( v2 < 0 )
error(1, "Error when trying to open maps file: %s\n", s);
v3 = v2;
while ( 1 )
{
while ( 1 )
{
v4 = 0;
do
{
v5 = v4;
if ( read(v3, &v25[v4], 1uLL) != 1 )
return 0LL;
++v4;
}
while ( v25[v5] != 10 );
v25[v5] = 0;
verbose("Read line: %s\n", v25);
v6 = 0;
__isoc99_sscanf();
v20 = 0;
v7 = v19;
do
{
if ( *v7 == 120 )
{
v6 |= 2u;
}
else if ( *v7 == 114 )
{
v6 |= 1u;
}
++v7;
}
while ( v7 != &v20 );
verbose("start: %lx, stop: %lx, delta: %d; perm: %s, %d\n", v21, v22, v22 - v21, v19, v6);
if ( v6 == 3 )
{
verbose("Found readable and executable memory area\n");
v8 = v21;
v9 = ptrace(PTRACE_PEEKTEXT, a1, v21, 0LL);
v10 = v22;
v23[0] = v9;
if ( v8 < v22 - 1 )
break;
}
}
v11 = 0;
v12 = 0LL;
LABEL_14:
v13 = v11;
v14 = v8 + 1;
++v11;
v15 = &v25[8 * v12 + 512];
if ( v15[v13 - 560] == magic && v15[v11 - 560] == byte_404099 )
return v8;
while ( 1 )
{
v8 = v14;
if ( v14 >= v10 - 1 )
break;
if ( v11 != 7 )
goto LABEL_14;
++v14;
v16 = ptrace(PTRACE_PEEKTEXT, a1, v8 + 1, 0LL);
v17 = magic;
v23[!v12] = v16;
if ( HIBYTE(v23[v12]) == v17 && LOBYTE(v23[!v12]) == byte_404099 )
return v8;
v12 = !v12;
v10 = v22;
v11 = 0;
}
}
}

original_code:
unsigned char *find_syscall(int pid) {
 unsigned char *t;
 int a, fd, idx, i, seg, j;
 long long start, stop;
 char perm[5];
 int permissions;
 char line[512];
 long long peek_data;
 char filename[32];
 unsigned char data[2][8];
 memset(data[0], 0, 8);
 memset(data[1], 0, 8);
 snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
 verbose("Opening process's maps file: %s\n", filename);
 fd = open(filename, 00);
 if (fd < 0)
  error(1, "Error when trying to open maps file: %s\n", filename);
 idx = 0;
 while (1) {
  if (read(fd, &line[idx], 1) != 1) {
   line[idx] = '\0';
   break;
  }
  if (line[idx] == '\n') {
   line[idx] = '\0';
   verbose("Read line: %s\n", line);
   sscanf(line, "%lx-%lx %4c", &start, &stop, perm);
   perm[4] = '\0';
   permissions = 0;
   for (i = 0; i < 4; i++) {
    if (perm[i] == 'x')
     permissions |= 2;
    if (perm[i] == 'r')
     permissions |= 1;
   }
   verbose("start: %lx, stop: %lx, delta: %d; perm: %s, %d\n", start, stop, stop - start, perm, permissions);
   if (permissions == (2 | 1)) {
    verbose("Found readable and executable memory area\n");
    t = (unsigned char *) start;
    seg = 0;
    peek_data = ptrace(PTRACE_PEEKTEXT, pid, t, ((void *)0));
    memcpy(data[seg], &peek_data, 8);
    j = 0;
    while (t < (unsigned char *) (stop - 1)) {
     if (j == (8 - 1)) {
      peek_data = ptrace(PTRACE_PEEKTEXT, pid, t + 1, ((void *)0));
      memcpy(data[!seg], &peek_data, 8);
      if (data[seg][8 - 1] == magic[0] && data[!seg][0] == magic[1])
       return t;
      seg = !seg;
      j = 0;
     } else {
      if (data[seg][j] == magic[0] && data[seg][j + 1] == magic[1])
       return t;
      j++;
     }
     t++;
    }
   }
   idx = 0;
   continue;
  }
  idx++;
 }
 return ((void *)0);
}

canonical_original_code:
unsigned char *find_syscall(int pid) {
 unsigned char *t;
 int a; int fd; int idx; int i; int seg; int j;
 long long start; long long stop;
 char perm[5];
 int permissions;
 char line[512];
 long long peek_data;
 char filename[32];
 unsigned char data[2][8];
 memset(data[0], 0, 8);
 memset(data[1], 0, 8);
 snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
 verbose("Opening process's maps file: %s\n", filename);
 fd = open(filename, 00);
 if (fd < 0)
  error(1, "Error when trying to open maps file: %s\n", filename);
 idx = 0;
 while (1) {
  if (read(fd, &line[idx], 1) != 1) {
   line[idx] = '\0';
   break;
  }
  if (line[idx] == '\n') {
   line[idx] = '\0';
   verbose("Read line: %s\n", line);
   sscanf(line, "%lx-%lx %4c", &start, &stop, perm);
   perm[4] = '\0';
   permissions = 0;
   for (i = 0; i < 4; i++) {
    if (perm[i] == 'x')
     permissions |= 2;
    if (perm[i] == 'r')
     permissions |= 1;
   }
   verbose("start: %lx, stop: %lx, delta: %d; perm: %s, %d\n", start, stop, stop - start, perm, permissions);
   if (permissions == (2 | 1)) {
    verbose("Found readable and executable memory area\n");
    t = (unsigned char *) start;
    seg = 0;
    peek_data = ptrace(PTRACE_PEEKTEXT, pid, t, ((void *)0));
    memcpy(data[seg], &peek_data, 8);
    j = 0;
    while (t < (unsigned char *) (stop - 1)) {
     if (j == (8 - 1)) {
      peek_data = ptrace(PTRACE_PEEKTEXT, pid, t + 1, ((void *)0));
      memcpy(data[!seg], &peek_data, 8);
      if (data[seg][8 - 1] == magic[0] && data[!seg][0] == magic[1])
       return t;
      seg = !seg;
      j = 0;
     } else {
      if (data[seg][j] == magic[0] && data[seg][j + 1] == magic[1])
       return t;
      j++;
     }
     t++;
    }
   }
   idx = 0;
   continue;
  }
  idx++;
 }
 return ((void *)0);
}

variable_types: a int

variable_types: fd int

variable_types: idx int

variable_types: seg int

variable_types: j int

variable_types:
start
long long

variable_types:
stop
long long

variable_types:
perm
char [5]

variable_types: permissions int

variable_types:
line
char [512]

variable_types:
filename
char [32]

variable_types:
data
unsigned char [2][8]

return_type: unsigned char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char **a1)
{
fprintf(stderr, "Usage: %s -p process_id file_descriptor_number\n", *a1);
fwrite("\n\n", 1uLL, 2uLL, stderr);
fwrite("This program closes a file descriptor/socket in a process <process_id>\n", 1uLL, 0x47uLL, stderr);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char **a1)
{
fprintf(stderr, "Usage: %s -p process_id file_descriptor_number\n", *a1);
fwrite("\n\n", 1uLL, 2uLL, stderr);
fwrite("This program closes a file descriptor/socket in a process <process_id>\n", 1uLL, 0x47uLL, stderr);
exit(2);
}

original_code:
void usage(char **argv) {
 fprintf(stderr, "Usage: %s -p process_id file_descriptor_number\n", argv[0]);
 fprintf(stderr, "\n\n");
 fprintf(stderr, "This program closes a file descriptor/socket in a process <process_id>\n");
 exit(2);
}

variable_types:
argv
char **


repo: bas-t/ffdecsawrapper

decompiled_code:
int __fastcall dump_element_prefix(int a1)
{
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
const char *v4; // rdi
__int64 v5; // rbx

v1 = a1;
v2 = 2LL * a1;
if ( LODWORD(db[v2]) == 1000000 )
{
LODWORD(v3) = puts("PANIC!");
}
else
{
v3 = HIDWORD(db[v2]);
switch ( v3 )
{
case 0LL:
LODWORD(v3) = putchar(48);
return v3;
case 1LL:
LODWORD(v3) = putchar(49);
return v3;
case 2LL:
LODWORD(v3) = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
LODWORD(v3) = putchar(97);
break;
case 11:
LODWORD(v3) = printf("an");
break;
case 20:
LODWORD(v3) = putchar(98);
break;
case 21:
LODWORD(v3) = printf("bn");
break;
case 30:
LODWORD(v3) = putchar(99);
break;
case 31:
LODWORD(v3) = printf("cn");
break;
case 40:
LODWORD(v3) = putchar(100);
break;
case 41:
LODWORD(v3) = printf("dn");
break;
default:
return v3;
}
return v3;
case 3LL:
v4 = "FFAND(";
goto LABEL_4;
case 4LL:
v4 = "FFOR(";
goto LABEL_4;
case 5LL:
v4 = "FFXOR(";
LABEL_4:
printf(v4);
v5 = 16 * v1 + 4210848;
dump_element_prefix(*(unsigned int *)(v5 + 8));
putchar(44);
dump_element_prefix(*(unsigned int *)(v5 + 12));
LODWORD(v3) = putchar(41);
break;
default:
return v3;
}
}
return v3;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
const char *v4; // rdi
__int64 v5; // rbx

v1 = a1;
v2 = 2LL * a1;
if ( LODWORD(db[v2]) == 1000000 )
{
LODWORD(v3) = puts("PANIC!");
}
else
{
v3 = HIDWORD(db[v2]);
switch ( v3 )
{
case 0LL:
LODWORD(v3) = putchar(48);
return v3;
case 1LL:
LODWORD(v3) = putchar(49);
return v3;
case 2LL:
LODWORD(v3) = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
LODWORD(v3) = putchar(97);
break;
case 11:
LODWORD(v3) = printf("an");
break;
case 20:
LODWORD(v3) = putchar(98);
break;
case 21:
LODWORD(v3) = printf("bn");
break;
case 30:
LODWORD(v3) = putchar(99);
break;
case 31:
LODWORD(v3) = printf("cn");
break;
case 40:
LODWORD(v3) = putchar(100);
break;
case 41:
LODWORD(v3) = printf("dn");
break;
default:
return v3;
}
return v3;
case 3LL:
v4 = "FFAND(";
goto LABEL_4;
case 4LL:
v4 = "FFOR(";
goto LABEL_4;
case 5LL:
v4 = "FFXOR(";
LABEL_4:
printf(v4);
v5 = 16 * v1 + 4210848;
func7(*(unsigned int *)(v5 + 8));
putchar(44);
func7(*(unsigned int *)(v5 + 12));
LODWORD(v3) = putchar(41);
break;
default:
return v3;
}
}
return v3;
}

original_code:
void dump_element_prefix(int e){
  if(db[e].level==1000000){
    printf("PANIC!\n");
    return;
  };
  switch(db[e].op_type){
  case 0:
    printf("0");
    break;
  case 1:
    printf("1");
    break;
  case 2:
    switch(db[e].op1){
    case 10:
      printf("a");
      break;
    case 20:
      printf("b");
      break;
    case 30:
      printf("c");
      break;
    case 40:
      printf("d");
      break;
    case 11:
      printf("an");
      break;
    case 21:
      printf("bn");
      break;
    case 31:
      printf("cn");
      break;
    case 41:
      printf("dn");
      break;
    }
    break;
  case 3:
    printf("FFAND(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  case 4:
    printf("FFOR(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  case 5:
    printf("FFXOR(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  }
}

variable_types: e int


decompiled_code:
int __fastcall dump_element_infix(int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rbx
int v4; // edi

v1 = 2LL * a1;
if ( LODWORD(db[v1]) == 1000000 )
{
LODWORD(v2) = puts("PANIC!");
}
else
{
v2 = HIDWORD(db[v1]);
switch ( v2 )
{
case 0LL:
LODWORD(v2) = putchar(48);
return v2;
case 1LL:
LODWORD(v2) = putchar(49);
return v2;
case 2LL:
LODWORD(v2) = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
LODWORD(v2) = putchar(97);
break;
case 11:
LODWORD(v2) = printf("an");
break;
case 20:
LODWORD(v2) = putchar(98);
break;
case 21:
LODWORD(v2) = printf("bn");
break;
case 30:
LODWORD(v2) = putchar(99);
break;
case 31:
LODWORD(v2) = printf("cn");
break;
case 40:
LODWORD(v2) = putchar(100);
break;
case 41:
LODWORD(v2) = printf("dn");
break;
default:
return v2;
}
return v2;
case 3LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
dump_element_infix((unsigned int)dword_4040A8[4 * a1]);
v4 = 38;
goto LABEL_4;
case 4LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
dump_element_infix((unsigned int)dword_4040A8[4 * a1]);
v4 = 124;
goto LABEL_4;
case 5LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
dump_element_infix((unsigned int)dword_4040A8[4 * a1]);
v4 = 94;
LABEL_4:
putchar(v4);
dump_element_infix(*(unsigned int *)(v3 + 12));
LODWORD(v2) = printf(" )");
break;
default:
return v2;
}
}
return v2;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rbx
int v4; // edi

v1 = 2LL * a1;
if ( LODWORD(db[v1]) == 1000000 )
{
LODWORD(v2) = puts("PANIC!");
}
else
{
v2 = HIDWORD(db[v1]);
switch ( v2 )
{
case 0LL:
LODWORD(v2) = putchar(48);
return v2;
case 1LL:
LODWORD(v2) = putchar(49);
return v2;
case 2LL:
LODWORD(v2) = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
LODWORD(v2) = putchar(97);
break;
case 11:
LODWORD(v2) = printf("an");
break;
case 20:
LODWORD(v2) = putchar(98);
break;
case 21:
LODWORD(v2) = printf("bn");
break;
case 30:
LODWORD(v2) = putchar(99);
break;
case 31:
LODWORD(v2) = printf("cn");
break;
case 40:
LODWORD(v2) = putchar(100);
break;
case 41:
LODWORD(v2) = printf("dn");
break;
default:
return v2;
}
return v2;
case 3LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
func8((unsigned int)dword_4040A8[4 * a1]);
v4 = 38;
goto LABEL_4;
case 4LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
func8((unsigned int)dword_4040A8[4 * a1]);
v4 = 124;
goto LABEL_4;
case 5LL:
printf("( ");
v3 = 16LL * a1 + 4210848;
func8((unsigned int)dword_4040A8[4 * a1]);
v4 = 94;
LABEL_4:
putchar(v4);
func8(*(unsigned int *)(v3 + 12));
LODWORD(v2) = printf(" )");
break;
default:
return v2;
}
}
return v2;
}

original_code:
void dump_element_infix(int e){
  if(db[e].level==1000000){
    printf("PANIC!\n");
    return;
  };
  switch(db[e].op_type){
  case 0:
    printf("0");
    break;
  case 1:
    printf("1");
    break;
  case 2:
    switch(db[e].op1){
    case 10:
      printf("a");
      break;
    case 20:
      printf("b");
      break;
    case 30:
      printf("c");
      break;
    case 40:
      printf("d");
      break;
    case 11:
      printf("an");
      break;
    case 21:
      printf("bn");
      break;
    case 31:
      printf("cn");
      break;
    case 41:
      printf("dn");
      break;
    }
    break;
  case 3:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("&");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  case 4:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("|");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  case 5:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("^");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  }
}


main

variable_types: i int

variable_types: l int

variable_types: candidate int


original_code:
int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->lat, pack->ns, pack->lon, pack->ew,
        pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units,
        pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid);
}

canonical_original_code:
int nmea_gen_GPGGA(char *buff, int buff_sz, struct _nmeaGPGGA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->lat, pack->ns, pack->lon, pack->ew,
        pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units,
        pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid);
}

variable_types:
buff
char *

variable_types: struct _nmeaGPGGA { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; } *

user_defined_types: struct _nmeaGPGGA { struct _nmeaTIME utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; }


original_code:
int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f",
        pack->fix_mode, pack->fix_type,
        pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5],
        pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11],
        pack->PDOP, pack->HDOP, pack->VDOP);
}

canonical_original_code:
int nmea_gen_GPGSA(char *buff, int buff_sz, struct _nmeaGPGSA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f",
        pack->fix_mode, pack->fix_type,
        pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5],
        pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11],
        pack->PDOP, pack->HDOP, pack->VDOP);
}

variable_types: struct _nmeaGPGSA { char fix_mode; int fix_type; int sat_prn[-1]; double PDOP; double HDOP; double VDOP; } *


original_code:
int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSV,%1d,%1d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d",
        pack->pack_count, pack->pack_index + 1, pack->sat_count,
        pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig,
        pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig,
        pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig,
        pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig);
}

canonical_original_code:
int nmea_gen_GPGSV(char *buff, int buff_sz, struct _nmeaGPGSV *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSV,%1d,%1d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d",
        pack->pack_count, pack->pack_index + 1, pack->sat_count,
        pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig,
        pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig,
        pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig,
        pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig);
}

variable_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat_data[-1]; } *

user_defined_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE sat_data[-1]; }


original_code:
int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->status, pack->lat, pack->ns, pack->lon, pack->ew,
        pack->speed, pack->direction,
        pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100,
        pack->declination, pack->declin_ew, pack->mode);
}

canonical_original_code:
int nmea_gen_GPRMC(char *buff, int buff_sz, struct _nmeaGPRMC *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->status, pack->lat, pack->ns, pack->lon, pack->ew,
        pack->speed, pack->direction,
        pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100,
        pack->declination, pack->declin_ew, pack->mode);
}

variable_types: struct _nmeaGPRMC { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; } *

user_defined_types: struct _nmeaGPRMC { struct _nmeaTIME utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; }


original_code:
int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C",
        pack->dir, pack->dir_t,
        pack->dec, pack->dec_m,
        pack->spn, pack->spn_n,
        pack->spk, pack->spk_k);
}

canonical_original_code:
int nmea_gen_GPVTG(char *buff, int buff_sz, struct _nmeaGPVTG *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C",
        pack->dir, pack->dir_t,
        pack->dec, pack->dec_m,
        pack->spn, pack->spn_n,
        pack->spk, pack->spk_k);
}

variable_types: struct _nmeaGPVTG { double dir; char dir_t; double dec; char dec_m; double spn; char spn_n; double spk; char spk_k; } *


original_code:
void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack)
{
    nmea_zero_GPGGA(pack);
    pack->utc = info->utc;
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->sig = info->sig;
    pack->satinuse = info->satinfo.inuse;
    pack->HDOP = info->HDOP;
    pack->elv = info->elv;
}

canonical_original_code:
void nmea_info2GPGGA(struct _nmeaINFO *info, struct _nmeaGPGGA *pack)
{
    nmea_zero_GPGGA(pack);
    pack->utc = info->utc;
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->sig = info->sig;
    pack->satinuse = info->satinfo.inuse;
    pack->HDOP = info->HDOP;
    pack->elv = info->elv;
}

variable_types: struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *

variable_types: struct _nmeaGPGGA { struct _nmeaTIME utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; } *

user_defined_types: struct _nmeaINFO { int smask; struct _nmeaTIME utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO satinfo; }

user_defined_types: struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE sat[-1]; }


original_code:
void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack)
{
    int it;
    nmea_zero_GPGSA(pack);
    pack->fix_type = info->fix;
    pack->PDOP = info->PDOP;
    pack->HDOP = info->HDOP;
    pack->VDOP = info->VDOP;
    for(it = 0; it < (12); ++it)
    {
        pack->sat_prn[it] =
            ((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0);
    }
}

canonical_original_code:
void nmea_info2GPGSA(struct _nmeaINFO *info, struct _nmeaGPGSA *pack)
{
    int it;
    nmea_zero_GPGSA(pack);
    pack->fix_type = info->fix;
    pack->PDOP = info->PDOP;
    pack->HDOP = info->HDOP;
    pack->VDOP = info->VDOP;
    for(it = 0; it < (12); ++it)
    {
        pack->sat_prn[it] =
            ((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0);
    }
}

variable_types: it int

user_defined_types: struct _nmeaGPGSA { char fix_mode; int fix_type; int sat_prn[-1]; double PDOP; double HDOP; double VDOP; }

user_defined_types: struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; }

user_defined_types: struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; }


decompiled_code:
__int64 __fastcall nmea_gsv_npack(int a1)
{
double v1; // xmm0_8
__m128d v2; // xmm3
__m128d v3; // xmm1
__int64 result; // rax

v1 = (double)a1 * 0.25;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v2.m128d_f64[0] = (double)a1 * 0.25;
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64(v3.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9)) | ~LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v1;
if ( !(_DWORD)result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
double v1; // xmm0_8
__m128d v2; // xmm3
__m128d v3; // xmm1
__int64 result; // rax

v1 = (double)a1 * 0.25;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v2.m128d_f64[0] = (double)a1 * 0.25;
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64(v3.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9)) | ~LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v1;
if ( !(_DWORD)result )
result = 1LL;
return result;
}

original_code:
int nmea_gsv_npack(int sat_count)
{
    int pack_count = (int)ceil(((double)sat_count) / (4));
    if(0 == pack_count)
        pack_count = 1;
    return pack_count;
}


original_code:
void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx)
{
    int sit, pit;
    nmea_zero_GPGSV(pack);
    pack->sat_count = (info->satinfo.inview <= (12))?info->satinfo.inview:(12);
    pack->pack_count = nmea_gsv_npack(pack->sat_count);
    if(pack->pack_count == 0)
        pack->pack_count = 1;
    if(pack_idx >= pack->pack_count)
        pack->pack_index = pack_idx % pack->pack_count;
    else
        pack->pack_index = pack_idx;
    for(pit = 0, sit = pack->pack_index * (4); pit < (4); ++pit, ++sit)
        pack->sat_data[pit] = info->satinfo.sat[sit];
}

canonical_original_code:
void nmea_info2GPGSV(struct _nmeaINFO *info, struct _nmeaGPGSV *pack, int pack_idx)
{
    int sit; int pit;
    nmea_zero_GPGSV(pack);
    pack->sat_count = (info->satinfo.inview <= (12))?info->satinfo.inview:(12);
    pack->pack_count = nmea_gsv_npack(pack->sat_count);
    if(pack->pack_count == 0)
        pack->pack_count = 1;
    if(pack_idx >= pack->pack_count)
        pack->pack_index = pack_idx % pack->pack_count;
    else
        pack->pack_index = pack_idx;
    for(pit = 0, sit = pack->pack_index * (4); pit < (4); ++pit, ++sit)
        pack->sat_data[pit] = info->satinfo.sat[sit];
}

variable_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE sat_data[-1]; } *

variable_types: sit int

variable_types: pit int


original_code:
void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack)
{
    nmea_zero_GPRMC(pack);
    pack->utc = info->utc;
    pack->status = ((info->sig > 0)?'A':'V');
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->speed = info->speed / (1.852);
    pack->direction = info->direction;
    pack->declination = info->declination;
    pack->declin_ew = 'E';
    pack->mode = ((info->sig > 0)?'A':'N');
}

canonical_original_code:
void nmea_info2GPRMC(struct _nmeaINFO *info, struct _nmeaGPRMC *pack)
{
    nmea_zero_GPRMC(pack);
    pack->utc = info->utc;
    pack->status = ((info->sig > 0)?'A':'V');
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->speed = info->speed / (1.852);
    pack->direction = info->direction;
    pack->declination = info->declination;
    pack->declin_ew = 'E';
    pack->mode = ((info->sig > 0)?'A':'N');
}

variable_types: struct _nmeaGPRMC { struct _nmeaTIME utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; } *


decompiled_code:
__int64 __fastcall nmea_info2GPVTG(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8

result = nmea_zero_GPVTG(a2);
*(_QWORD *)a2 = *(_QWORD *)(a1 + 96);
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 104);
v3 = *(double *)(a1 + 88);
*(double *)(a2 + 48) = v3;
*(double *)(a2 + 32) = v3 / 1.852;
return result;
}

original_code:
void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack)
{
    nmea_zero_GPVTG(pack);
    pack->dir = info->direction;
    pack->dec = info->declination;
    pack->spn = info->speed / (1.852);
    pack->spk = info->speed;
}

canonical_original_code:
void nmea_info2GPVTG(struct _nmeaINFO *info, struct _nmeaGPVTG *pack)
{
    nmea_zero_GPVTG(pack);
    pack->dir = info->direction;
    pack->dec = info->declination;
    pack->spn = info->speed / (1.852);
    pack->spk = info->speed;
}

user_defined_types: struct _nmeaGPVTG { double dir; char dir_t; double dec; char dec_m; double spn; char spn_n; double spk; char spk_k; }


decompiled_code:
__int64 __fastcall nmea_generate(__int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v6; // er12
int v7; // er14
int v8; // er15
int v10; // edx
int v11; // [rsp+Ch] [rbp-20Ch]
char v12[64]; // [rsp+10h] [rbp-208h] BYREF
double v13[10]; // [rsp+50h] [rbp-1C8h] BYREF
unsigned int v14[24]; // [rsp+A0h] [rbp-178h] BYREF
char v15[96]; // [rsp+100h] [rbp-118h] BYREF
__m128i v16[11]; // [rsp+160h] [rbp-B8h] BYREF

if ( !a1 )
return 0;
v6 = 0;
while ( a4 )
{
if ( (a4 & 1) != 0 )
{
a4 &= 0xFFFFFFFE;
nmea_info2GPGGA(a3, v16);
v6 += nmea_gen_GPGGA(a1 + (int)v6, a2 - v6, (__int64)v16);
if ( (int)(a2 - v6) <= 0 )
return v6;
}
else
{
v7 = a4 & 2;
if ( (a4 & 2) != 0 )
{
a4 &= 0xFFFFFFFD;
nmea_info2GPGSA(a3, (__int64)v13);
v6 += nmea_gen_GPGSA(a1 + (int)v6, a2 - v6, v13);
v8 = a2 - v6;
}
else if ( (a4 & 4) != 0 )
{
v8 = a2 - v6;
v11 = nmea_gsv_npack(*(_DWORD *)(a3 + 116));
if ( v11 > 0 )
{
do
{
if ( v8 <= 0 )
break;
v10 = v7++;
nmea_info2GPGSV(a3, (int *)v14, v10);
v6 += nmea_gen_GPGSV(a1 + (int)v6, (unsigned int)v8, v14);
v8 = a2 - v6;
}
while ( v11 != v7 );
}
a4 &= 0xFFFFFFFB;
}
else if ( (a4 & 8) != 0 )
{
a4 &= 0xFFFFFFF7;
nmea_info2GPRMC(a3, (__int64)v15);
v6 += nmea_gen_GPRMC(a1 + (int)v6, a2 - v6, (__int64)v15);
v8 = a2 - v6;
}
else
{
if ( (a4 & 0x10) == 0 )
return v6;
a4 &= 0xFFFFFFEF;
nmea_info2GPVTG(a3, (__int64)v12);
v6 += nmea_gen_GPVTG(a1 + (int)v6, a2 - v6, (__int64)v12);
v8 = a2 - v6;
}
if ( v8 <= 0 )
return v6;
}
}
return v6;
}

original_code:
int nmea_generate(
    char *buff, int buff_sz,
    const nmeaINFO *info,
    int generate_mask
    )
{
    int gen_count = 0, gsv_it, gsv_count;
    int pack_mask = generate_mask;
    nmeaGPGGA gga;
    nmeaGPGSA gsa;
    nmeaGPGSV gsv;
    nmeaGPRMC rmc;
    nmeaGPVTG vtg;
    if(!buff)
        return 0;
    while(pack_mask)
    {
        if(pack_mask & GPGGA)
        {
            nmea_info2GPGGA(info, &gga);
            gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga);
            pack_mask &= ~GPGGA;
        }
        else if(pack_mask & GPGSA)
        {
            nmea_info2GPGSA(info, &gsa);
            gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa);
            pack_mask &= ~GPGSA;
        }
        else if(pack_mask & GPGSV)
        {
            gsv_count = nmea_gsv_npack(info->satinfo.inview);
            for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it)
            {
                nmea_info2GPGSV(info, &gsv, gsv_it);
                gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv);
            }
            pack_mask &= ~GPGSV;
        }
        else if(pack_mask & GPRMC)
        {
            nmea_info2GPRMC(info, &rmc);
            gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc);
            pack_mask &= ~GPRMC;
        }
        else if(pack_mask & GPVTG)
        {
            nmea_info2GPVTG(info, &vtg);
            gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg);
            pack_mask &= ~GPVTG;
        }
        else
            break;
        if(buff_sz - gen_count <= 0)
            break;
    }
    return gen_count;
}

canonical_original_code:
int nmea_generate(char *buff, int buff_sz, struct _nmeaINFO *info, int generate_mask)
{
    int gen_count = 0; int gsv_it; int gsv_count;
    int pack_mask = generate_mask;
    struct _nmeaGPGGA gga;
    struct _nmeaGPGSA gsa;
    struct _nmeaGPGSV gsv;
    struct _nmeaGPRMC rmc;
    struct _nmeaGPVTG vtg;
    if(!buff)
        return 0;
    while(pack_mask)
    {
        if(pack_mask & GPGGA)
        {
            nmea_info2GPGGA(info, &gga);
            gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga);
            pack_mask &= ~GPGGA;
        }
        else if(pack_mask & GPGSA)
        {
            nmea_info2GPGSA(info, &gsa);
            gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa);
            pack_mask &= ~GPGSA;
        }
        else if(pack_mask & GPGSV)
        {
            gsv_count = nmea_gsv_npack(info->satinfo.inview);
            for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it)
            {
                nmea_info2GPGSV(info, &gsv, gsv_it);
                gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv);
            }
            pack_mask &= ~GPGSV;
        }
        else if(pack_mask & GPRMC)
        {
            nmea_info2GPRMC(info, &rmc);
            gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc);
            pack_mask &= ~GPRMC;
        }
        else if(pack_mask & GPVTG)
        {
            nmea_info2GPVTG(info, &vtg);
            gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg);
            pack_mask &= ~GPVTG;
        }
        else
            break;
        if(buff_sz - gen_count <= 0)
            break;
    }
    return gen_count;
}

variable_types: struct _nmeaGPGGA { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; }

variable_types: struct _nmeaGPGSA { char fix_mode; int fix_type; int sat_prn[-1]; double PDOP; double HDOP; double VDOP; }

variable_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat_data[-1]; }

variable_types: struct _nmeaGPRMC { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; }

variable_types: struct _nmeaGPVTG { double dir; char dir_t; double dec; char dec_m; double spn; char spn_n; double spk; char spk_k; }


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

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

original_code:
int nmea_igen_noise_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    return 1;
}

canonical_original_code:
int nmea_igen_noise_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    return 1;
}

variable_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; } *

variable_types:
info
struct _nmeaINFO *

user_defined_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; }


decompiled_code:
// attributes: thunk
__int64 nmea_igen_noise_reset()
{
return nmea_igen_noise_init();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
int nmea_igen_noise_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    return 1;
}

canonical_original_code:
int nmea_igen_noise_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    return 1;
}


original_code:
int nmea_igen_static_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->satinfo.inuse = 4;
    info->satinfo.inview = 4;
    info->satinfo.sat[0].id = 1;
    info->satinfo.sat[0].in_use = 1;
    info->satinfo.sat[0].elv = 50;
    info->satinfo.sat[0].azimuth = 0;
    info->satinfo.sat[0].sig = 99;
    info->satinfo.sat[1].id = 2;
    info->satinfo.sat[1].in_use = 1;
    info->satinfo.sat[1].elv = 50;
    info->satinfo.sat[1].azimuth = 90;
    info->satinfo.sat[1].sig = 99;
    info->satinfo.sat[2].id = 3;
    info->satinfo.sat[2].in_use = 1;
    info->satinfo.sat[2].elv = 50;
    info->satinfo.sat[2].azimuth = 180;
    info->satinfo.sat[2].sig = 99;
    info->satinfo.sat[3].id = 4;
    info->satinfo.sat[3].in_use = 1;
    info->satinfo.sat[3].elv = 50;
    info->satinfo.sat[3].azimuth = 270;
    info->satinfo.sat[3].sig = 99;
    return 1;
}

canonical_original_code:
int nmea_igen_static_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->satinfo.inuse = 4;
    info->satinfo.inview = 4;
    info->satinfo.sat[0].id = 1;
    info->satinfo.sat[0].in_use = 1;
    info->satinfo.sat[0].elv = 50;
    info->satinfo.sat[0].azimuth = 0;
    info->satinfo.sat[0].sig = 99;
    info->satinfo.sat[1].id = 2;
    info->satinfo.sat[1].in_use = 1;
    info->satinfo.sat[1].elv = 50;
    info->satinfo.sat[1].azimuth = 90;
    info->satinfo.sat[1].sig = 99;
    info->satinfo.sat[2].id = 3;
    info->satinfo.sat[2].in_use = 1;
    info->satinfo.sat[2].elv = 50;
    info->satinfo.sat[2].azimuth = 180;
    info->satinfo.sat[2].sig = 99;
    info->satinfo.sat[3].id = 4;
    info->satinfo.sat[3].in_use = 1;
    info->satinfo.sat[3].elv = 50;
    info->satinfo.sat[3].azimuth = 270;
    info->satinfo.sat[3].sig = 99;
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_igen_static_init(__int64 a1, _QWORD *a2)
{
a2[4] = 0x300000003LL;
nmea_igen_static_reset(a1, a2);
return 1LL;
}

original_code:
int nmea_igen_static_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_static_reset(gen, info);
    return 1;
}

canonical_original_code:
int nmea_igen_static_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_static_reset(gen, info);
    return 1;
}


original_code:
int nmea_igen_rotate_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    double deg = 360 / 8;
    double srt = 0;
    info->satinfo.inuse = 8;
    info->satinfo.inview = 8;
    for(it = 0; it < info->satinfo.inview; ++it)
    {
        info->satinfo.sat[it].id = it + 1;
        info->satinfo.sat[it].in_use = 1;
        info->satinfo.sat[it].elv = 5;
        info->satinfo.sat[it].azimuth = (int)srt;
        info->satinfo.sat[it].sig = 80;
        srt += deg;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    double deg = 360 / 8;
    double srt = 0;
    info->satinfo.inuse = 8;
    info->satinfo.inview = 8;
    for(it = 0; it < info->satinfo.inview; ++it)
    {
        info->satinfo.sat[it].id = it + 1;
        info->satinfo.sat[it].in_use = 1;
        info->satinfo.sat[it].elv = 5;
        info->satinfo.sat[it].azimuth = (int)srt;
        info->satinfo.sat[it].sig = 80;
        srt += deg;
    }
    return 1;
}

variable_types: deg double

variable_types: srt double


decompiled_code:
__int64 __fastcall nmea_igen_rotate_init(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 32) = 0x300000003LL;
nmea_igen_rotate_reset(a1, a2);
return 1LL;
}

original_code:
int nmea_igen_rotate_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_rotate_reset(gen, info);
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_rotate_reset(gen, info);
    return 1;
}


original_code:
int nmea_igen_pos_rmove_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    info->direction = info->declination = 0;
    info->speed = 20;
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    info->direction = info->declination = 0;
    info->speed = 20;
    return 1;
}


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

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

original_code:
int nmea_igen_pos_rmove_destroy(nmeaGENERATOR *gen)
{
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_destroy(struct _nmeaGENERATOR *gen)
{
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_igen_static_loop(__int64 a1, __int64 a2)
{
nmea_time_now(a2 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
nmea_time_now(a2 + 4);
return 1LL;
}

original_code:
int nmea_igen_static_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    nmea_time_now(&info->utc);
    return 1;
}

canonical_original_code:
int nmea_igen_static_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    nmea_time_now(&info->utc);
    return 1;
}


original_code:
int nmea_igen_rotate_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    int count = info->satinfo.inview;
    double deg = 360 / (count?count:1);
    double srt = (count?(info->satinfo.sat[0].azimuth):0) + 5;
    nmea_time_now(&info->utc);
    for(it = 0; it < count; ++it)
    {
        info->satinfo.sat[it].azimuth =
            (int)((srt >= 360)?srt - 360:srt);
        srt += deg;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    int count = info->satinfo.inview;
    double deg = 360 / (count?count:1);
    double srt = (count?(info->satinfo.sat[0].azimuth):0) + 5;
    nmea_time_now(&info->utc);
    for(it = 0; it < count; ++it)
    {
        info->satinfo.sat[it].azimuth =
            (int)((srt >= 360)?srt - 360:srt);
        srt += deg;
    }
    return 1;
}

variable_types: count int


decompiled_code:
double __fastcall nmea_random(double a1, double a2)
{
return (a2 - a1) * (double)rand() / 2147483647.0 + a1;
}

canonical_decompiled_code:
double __fastcall func10(double a1, double a2)
{
return (a2 - a1) * (double)rand() / 2147483647.0 + a1;
}

original_code:
double nmea_random(double min, double max)
{
    static double rand_max = 2147483647;
    double rand_val = rand();
    double bounds = max - min;
    return min + (rand_val * bounds) / rand_max;
}

variable_types: min double

variable_types: max double

variable_types: bounds double

return_type: double


original_code:
int nmea_igen_noise_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    int in_use;
    info->sig = (int)nmea_random(1, 3);
    info->PDOP = nmea_random(0, 9);
    info->HDOP = nmea_random(0, 9);
    info->VDOP = nmea_random(0, 9);
    info->fix = (int)nmea_random(2, 3);
    info->lat = nmea_random(0, 100);
    info->lon = nmea_random(0, 100);
    info->speed = nmea_random(0, 100);
    info->direction = nmea_random(0, 360);
    info->declination = nmea_random(0, 360);
    info->elv = (int)nmea_random(-100, 100);
    info->satinfo.inuse = 0;
    info->satinfo.inview = 0;
    for(it = 0; it < 12; ++it)
    {
        info->satinfo.sat[it].id = it;
        info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3);
        info->satinfo.sat[it].elv = (int)nmea_random(0, 90);
        info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359);
        info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40));
        if(in_use)
            info->satinfo.inuse++;
        if(info->satinfo.sat[it].sig > 0)
            info->satinfo.inview++;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_noise_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    int in_use;
    info->sig = (int)nmea_random(1, 3);
    info->PDOP = nmea_random(0, 9);
    info->HDOP = nmea_random(0, 9);
    info->VDOP = nmea_random(0, 9);
    info->fix = (int)nmea_random(2, 3);
    info->lat = nmea_random(0, 100);
    info->lon = nmea_random(0, 100);
    info->speed = nmea_random(0, 100);
    info->direction = nmea_random(0, 360);
    info->declination = nmea_random(0, 360);
    info->elv = (int)nmea_random(-100, 100);
    info->satinfo.inuse = 0;
    info->satinfo.inview = 0;
    for(it = 0; it < 12; ++it)
    {
        info->satinfo.sat[it].id = it;
        info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3);
        info->satinfo.sat[it].elv = (int)nmea_random(0, 90);
        info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359);
        info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40));
        if(in_use)
            info->satinfo.inuse++;
        if(info->satinfo.sat[it].sig > 0)
            info->satinfo.inview++;
    }
    return 1;
}

variable_types: it int


original_code:
int nmea_igen_pos_rmove_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    nmeaPOS crd;
    info->direction += nmea_random(-10, 10);
    info->speed += nmea_random(-2, 3);
    if(info->direction < 0)
        info->direction = 359 + info->direction;
    if(info->direction > 359)
        info->direction -= 359;
    if(info->speed > 40)
        info->speed = 40;
    if(info->speed < 1)
        info->speed = 1;
    nmea_info2pos(info, &crd);
    nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600);
    nmea_pos2info(&crd, info);
    info->declination = info->direction;
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    struct _nmeaPOS crd;
    info->direction += nmea_random(-10, 10);
    info->speed += nmea_random(-2, 3);
    if(info->direction < 0)
        info->direction = 359 + info->direction;
    if(info->direction > 359)
        info->direction -= 359;
    if(info->speed > 40)
        info->speed = 40;
    if(info->speed < 1)
        info->speed = 1;
    nmea_info2pos(info, &crd);
    nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600);
    nmea_pos2info(&crd, info);
    info->declination = info->direction;
    return 1;
}

variable_types: struct _nmeaPOS { double lat; double lon; }


decompiled_code:
__int64 __fastcall nmea_gen_init(__int64 a1, int *a2)
{
int v3; // er12
__int64 result; // rax
__int64 (__fastcall *v5)(__int64, int *); // rdx

v3 = *a2;
nmea_zero_INFO(a2);
*a2 = v3;
*((_QWORD *)a2 + 8) = LC19;
*((_QWORD *)a2 + 9) = LC20;
result = 1LL;
do
{
if ( !a1 )
break;
v5 = *(__int64 (__fastcall **)(__int64, int *))(a1 + 8);
if ( v5 )
result = v5(a1, a2);
a1 = *(_QWORD *)(a1 + 40);
}
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int *a2)
{
int v3; // er12
__int64 result; // rax
__int64 (__fastcall *v5)(__int64, int *); // rdx

v3 = *a2;
nmea_zero_INFO(a2);
*a2 = v3;
*((_QWORD *)a2 + 8) = LC19;
*((_QWORD *)a2 + 9) = LC20;
result = 1LL;
do
{
if ( !a1 )
break;
v5 = *(__int64 (__fastcall **)(__int64, int *))(a1 + 8);
if ( v5 )
result = v5(a1, a2);
a1 = *(_QWORD *)(a1 + 40);
}
while ( (_DWORD)result );
return result;
}

original_code:
int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1; int smask = info->smask;
    nmeaGENERATOR *igen = gen;
    nmea_zero_INFO(info);
    info->smask = smask;
    info->lat = (5001.2621);
    info->lon = (3613.0595);
    while(RetVal && igen)
    {
        if(igen->init_call)
            RetVal = (*igen->init_call)(igen, info);
        igen = igen->next;
    }
    return RetVal;
}

canonical_original_code:
int nmea_gen_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1; int smask = info->smask;
    struct _nmeaGENERATOR *igen = gen;
    nmea_zero_INFO(info);
    info->smask = smask;
    info->lat = (5001.2621);
    info->lon = (3613.0595);
    while(RetVal && igen)
    {
        if(igen->init_call)
            RetVal = (*igen->init_call)(igen, info);
        igen = igen->next;
    }
    return RetVal;
}

variable_types: RetVal int

variable_types: smask int


decompiled_code:
__int64 __fastcall nmea_gen_loop(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 (__fastcall *v4)(__int64, __int64); // rax

do
{
while ( 1 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 16);
if ( v4 )
break;
a1 = *(_QWORD *)(a1 + 40);
result = 1LL;
if ( !a1 )
return result;
}
result = v4(a1, a2);
if ( !(_DWORD)result )
break;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 (__fastcall *v4)(__int64, __int64); // rax

do
{
while ( 1 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 16);
if ( v4 )
break;
a1 = *(_QWORD *)(a1 + 40);
result = 1LL;
if ( !a1 )
return result;
}
result = v4(a1, a2);
if ( !(_DWORD)result )
break;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
return result;
}

original_code:
int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->loop_call)
        RetVal = (*gen->loop_call)(gen, info);
    if(RetVal && gen->next)
        RetVal = nmea_gen_loop(gen->next, info);
    return RetVal;
}

canonical_original_code:
int nmea_gen_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->loop_call)
        RetVal = (*gen->loop_call)(gen, info);
    if(RetVal && gen->next)
        RetVal = nmea_gen_loop(gen->next, info);
    return RetVal;
}


decompiled_code:
__int64 __fastcall nmea_gen_reset(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 24);
if ( v1 )
result = v1();
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 24);
if ( v1 )
result = v1();
else
result = 1LL;
return result;
}

original_code:
int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->reset_call)
        RetVal = (*gen->reset_call)(gen, info);
    return RetVal;
}

canonical_original_code:
int nmea_gen_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->reset_call)
        RetVal = (*gen->reset_call)(gen, info);
    return RetVal;
}


decompiled_code:
void __fastcall nmea_gen_destroy(_QWORD *a1)
{
void (__fastcall *v1)(_QWORD *); // rax

if ( a1[5] )
{
nmea_gen_destroy();
a1[5] = 0LL;
}
v1 = (void (__fastcall *)(_QWORD *))a1[4];
if ( v1 )
v1(a1);
free(a1);
}

canonical_decompiled_code:
void __fastcall func16(_QWORD *a1)
{
void (__fastcall *v1)(_QWORD *); // rax

if ( a1[5] )
{
func16();
a1[5] = 0LL;
}
v1 = (void (__fastcall *)(_QWORD *))a1[4];
if ( v1 )
v1(a1);
free(a1);
}

original_code:
void nmea_gen_destroy(nmeaGENERATOR *gen)
{
    if(gen->next)
    {
        nmea_gen_destroy(gen->next);
        gen->next = 0;
    }
    if(gen->destroy_call)
        (*gen->destroy_call)(gen);
    free(gen);
}

canonical_original_code:
void nmea_gen_destroy(struct _nmeaGENERATOR *gen)
{
    if(gen->next)
    {
        nmea_gen_destroy(gen->next);
        gen->next = 0;
    }
    if(gen->destroy_call)
        (*gen->destroy_call)(gen);
    free(gen);
}


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
*(_QWORD *)(result + 40) = a2;
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
*(_QWORD *)(result + 40) = a2;
return result;
}

original_code:
void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen)
{
    if(to->next)
        nmea_gen_add(to->next, gen);
    else
        to->next = gen;
}

canonical_original_code:
void nmea_gen_add(struct _nmeaGENERATOR *to, struct _nmeaGENERATOR *gen)
{
    if(to->next)
        nmea_gen_add(to->next, gen);
    else
        to->next = gen;
}

variable_types:
gen
struct _nmeaGENERATOR *


decompiled_code:
__int64 __fastcall nmea_generate_from(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

if ( (unsigned int)nmea_gen_loop(a4, a3) )
result = nmea_generate(a1, a2, a3, a5);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

if ( (unsigned int)func14(a4, a3) )
result = nmea_generate(a1, a2, a3, a5);
else
result = 0LL;
return result;
}

original_code:
int nmea_generate_from(
    char *buff, int buff_sz,
    nmeaINFO *info,
    nmeaGENERATOR *gen,
    int generate_mask
    )
{
    int retval;
    if(0 != (retval = nmea_gen_loop(gen, info)))
        retval = nmea_generate(buff, buff_sz, info, generate_mask);
    return retval;
}

canonical_original_code:
int nmea_generate_from(char *buff, int buff_sz, struct _nmeaINFO *info, struct _nmeaGENERATOR *gen, int generate_mask)
{
    int retval;
    if(0 != (retval = nmea_gen_loop(gen, info)))
        retval = nmea_generate(buff, buff_sz, info, generate_mask);
    return retval;
}

variable_types:
buff
char *

variable_types: struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *

variable_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; } *

variable_types: retval int


decompiled_code:
// attributes: thunk
void __fastcall nmea_destroy_generator(_QWORD *a1)
{
nmea_gen_destroy(a1);
}

canonical_decompiled_code:
void __fastcall func19(_QWORD *a1)
{
func16(a1);
}

original_code:
void nmea_destroy_generator(nmeaGENERATOR *gen)
{
    nmea_gen_destroy(gen);
}

canonical_original_code:
void nmea_destroy_generator(struct _nmeaGENERATOR *gen)
{
    nmea_gen_destroy(gen);
}

variable_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; } *


decompiled_code:
__int64 __fastcall nmea_parser_init(__int64 a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
__int64 result; // rax

v1 = *(_DWORD *)(nmea_property() + 16);
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x2Cu, "nmea_parser_init");
v2 = 256;
if ( v1 >= 256 )
v2 = v1;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
v3 = malloc(v2);
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
{
*(_DWORD *)(a1 + 24) = v2;
result = 1LL;
}
else
{
nmea_error("Insufficient memory!", 0.0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
__int64 result; // rax

v1 = *(_DWORD *)(nmea_property() + 16);
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x2Cu, "nmea_parser_init");
v2 = 256;
if ( v1 >= 256 )
v2 = v1;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
v3 = malloc(v2);
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
{
*(_DWORD *)(a1 + 24) = v2;
result = 1LL;
}
else
{
nmea_error("Insufficient memory!", 0.0);
result = 0LL;
}
return result;
}

original_code:
int nmea_parser_init(nmeaPARSER *parser)
{
    int resv = 0;
    int buff_size = nmea_property()->parse_buff_size;
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    if(buff_size < (256))
        buff_size = (256);
    memset(parser, 0, sizeof(nmeaPARSER));
    if(0 == (parser->buffer = malloc(buff_size)))
        nmea_error("Insufficient memory!");
    else
    {
        parser->buff_size = buff_size;
        resv = 1;
    }
    return resv;
}

canonical_original_code:
int nmea_parser_init(struct _nmeaPARSER *parser)
{
    int resv = 0;
    int buff_size = nmea_property()->parse_buff_size;
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    if(buff_size < (256))
        buff_size = (256);
    memset(parser, 0, sizeof(nmeaPARSER));
    if(0 == (parser->buffer = malloc(buff_size)))
        nmea_error("Insufficient memory!");
    else
    {
        parser->buff_size = buff_size;
        resv = 1;
    }
    return resv;
}

variable_types: struct _nmeaPARSER { void *top_node; void *end_node; unsigned char *buffer; int buff_size; int buff_use; } *

variable_types: resv int