decompiled_code:
// attributes: thunk
__int64 __fastcall crypt_hmac_size(char *a1)
{
return crypt_hash_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
return func4(a1);
}

original_code:
int crypt_hmac_size(const char *name)
{
 return crypt_hash_size(name);
}

canonical_original_code:
int crypt_hmac_size(char *name)
{
 return crypt_hash_size(name);
}


repo: mradugin/dmcryptfile

decompiled_code:
__int64 __fastcall crypt_hmac_write(__int64 a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax

v4 = send(*(_DWORD *)(a1 + 4), a2, a3, 0x8000);
if ( v4 < 0 || v4 < a3 )
result = 4294967291LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax

v4 = send(*(_DWORD *)(a1 + 4), a2, a3, 0x8000);
if ( v4 < 0 || v4 < a3 )
result = 4294967291LL;
else
result = 0LL;
return result;
}

original_code:
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
{
 ssize_t r;
 r = send(ctx->opfd, buffer, length, MSG_MORE);
 if (r < 0 || (size_t)r < length)
  return -5;
 return 0;
}

canonical_original_code:
int crypt_hmac_write(struct crypt_hmac *ctx, char *buffer, unsigned long length)
{
 long r;
 r = send(ctx->opfd, buffer, length, MSG_MORE);
 if (r < 0 || (unsigned long)r < length)
  return -5;
 return 0;
}

variable_types: struct crypt_hmac { int tfmfd; int opfd; int hash_len; } *

variable_types:
buffer
char *

variable_types:
length
unsigned long

variable_types: r long

return_type: int


decompiled_code:
ssize_t __fastcall crypt_hmac_final(__int64 a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( *(int *)(a1 + 8) < a3 )
result = 4294967274LL;
else
result = (read(*(_DWORD *)(a1 + 4), a2, a3) >> 63) & 0xFFFFFFFBLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(__int64 a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( *(int *)(a1 + 8) < a3 )
result = 4294967274LL;
else
result = (read(*(_DWORD *)(a1 + 4), a2, a3) >> 63) & 0xFFFFFFFBLL;
return result;
}

original_code:
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
{
 ssize_t r;
 if (length > (size_t)ctx->hash_len)
  return -22;
 r = read(ctx->opfd, buffer, length);
 if (r < 0)
  return -5;
 return 0;
}

canonical_original_code:
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, unsigned long length)
{
 long r;
 if (length > (unsigned long)ctx->hash_len)
  return -22;
 r = read(ctx->opfd, buffer, length);
 if (r < 0)
  return -5;
 return 0;
}

user_defined_types: struct crypt_hmac { int tfmfd; int opfd; int hash_len; }


decompiled_code:
__int64 __fastcall crypt_hmac_destroy(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

original_code:
int crypt_hmac_destroy(struct crypt_hmac *ctx)
{
 if (ctx->tfmfd != -1)
  close(ctx->tfmfd);
 if (ctx->opfd != -1)
  close(ctx->opfd);
 memset(ctx, 0, sizeof(*ctx));
 free(ctx);
 return 0;
}


original_code:
int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
      const void *buffer, size_t length)
{
 struct crypt_hmac *h;
 struct hash_alg *ha;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "hash",
 };
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 ha = _get_alg(name);
 if (!ha) {
  free(h);
  return -22;
 }
 h->hash_len = ha->length;
 snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
   "hmac(%s)", ha->kernel_name);
 if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
  free(h);
  return -22;
 }
 if (setsockopt(h->tfmfd, 279, 1, buffer, length) == -1) {
  crypt_hmac_destroy(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

canonical_original_code:
int crypt_hmac_init(struct crypt_hmac **ctx, char *name, void *buffer, unsigned long length)
{
 struct crypt_hmac *h;
 struct hash_alg *ha;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "hash",
 };
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 ha = _get_alg(name);
 if (!ha) {
  free(h);
  return -22;
 }
 h->hash_len = ha->length;
 snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
   "hmac(%s)", ha->kernel_name);
 if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
  free(h);
  return -22;
 }
 if (setsockopt(h->tfmfd, 279, 1, buffer, length) == -1) {
  crypt_hmac_destroy(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

variable_types: struct crypt_hmac { int tfmfd; int opfd; int hash_len; } **

variable_types:
name
char *

variable_types:
buffer
void *

variable_types: struct hash_alg { char *name; char *kernel_name; int length; } *

variable_types: struct sockaddr_alg { unsigned short salg_family; unsigned char salg_type[14]; unsigned int salg_feat; unsigned int salg_mask; unsigned char salg_name[64]; }


decompiled_code:
__int64 crypt_backend_rng()
{
return 4294967274LL;
}

original_code:
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
{
 return -22;
}

canonical_original_code:
int crypt_backend_rng(char *buffer, unsigned long length, int quality, int fips)
{
 return -22;
}

variable_types: quality int

variable_types: fips int


decompiled_code:
int __fastcall display_usage(const char *a1)
{
puts("Encrypts/decrypts file in dm-crypt compatible way, using kernel crypto API.");
puts("Copyright (c) 2013 Maxim Radugin.\n");
printf("Usage: %s <arguments>\n\n", a1);
puts("This utility is designed to encrypt disk/partition image files in userspace");
puts("without root priviledges and without using device mapper and cryptsetup.");
puts("Currently supports only plain mode, no LUKS support!");
puts("Backend code is taken from cryptsetup.");
puts("Input key size should be of desired cipher key size.");
puts("Key is passed directly to the cipher algorithm, no hashing or any other");
puts("processing is performed. It is up to the user to provide strong key.");
puts("For available ciphers, chain modes and key sizes check /proc/crypto.");
puts("Only plain IV mode is supported.");
printf("Input file size must be multiple of sector size i.e. %lu bytes.\n", 512LL);
puts("If input file is not multiple of sector size, output will be truncated.\n");
puts("Mandatory arguments:");
puts(" --cipher,-c Cipher-chainmode-ivmode, for example, aes-xts-plain");
puts(" --key-size,-s Size of key in bytes");
puts(" --key-file,-f Input key file, should be at least key-size bytes.");
puts(" Key data after key-size is ignored.");
puts(" --in-file,-i Input file");
puts(" --out-file,-o Output file");
puts(" --enc,-e Perform encryption operation from input to output file.");
puts(" --dec,-d Perform decryption operation from input to output file.");
return puts(" --help,-h,-? Display this text.");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Encrypts/decrypts file in dm-crypt compatible way, using kernel crypto API.");
puts("Copyright (c) 2013 Maxim Radugin.\n");
printf("Usage: %s <arguments>\n\n", a1);
puts("This utility is designed to encrypt disk/partition image files in userspace");
puts("without root priviledges and without using device mapper and cryptsetup.");
puts("Currently supports only plain mode, no LUKS support!");
puts("Backend code is taken from cryptsetup.");
puts("Input key size should be of desired cipher key size.");
puts("Key is passed directly to the cipher algorithm, no hashing or any other");
puts("processing is performed. It is up to the user to provide strong key.");
puts("For available ciphers, chain modes and key sizes check /proc/crypto.");
puts("Only plain IV mode is supported.");
printf("Input file size must be multiple of sector size i.e. %lu bytes.\n", 512LL);
puts("If input file is not multiple of sector size, output will be truncated.\n");
puts("Mandatory arguments:");
puts(" --cipher,-c Cipher-chainmode-ivmode, for example, aes-xts-plain");
puts(" --key-size,-s Size of key in bytes");
puts(" --key-file,-f Input key file, should be at least key-size bytes.");
puts(" Key data after key-size is ignored.");
puts(" --in-file,-i Input file");
puts(" --out-file,-o Output file");
puts(" --enc,-e Perform encryption operation from input to output file.");
puts(" --dec,-d Perform decryption operation from input to output file.");
return puts(" --help,-h,-? Display this text.");
}

original_code:
void display_usage(char* name) {
    printf("Encrypts/decrypts file in dm-crypt compatible way, using kernel crypto API.\n");
    printf("Copyright (c) 2013 Maxim Radugin.\n\n");
    printf("Usage: %s <arguments>\n\n", name);
    printf("This utility is designed to encrypt disk/partition image files in userspace\n");
    printf("without root priviledges and without using device mapper and cryptsetup.\n");
    printf("Currently supports only plain mode, no LUKS support!\n");
    printf("Backend code is taken from cryptsetup.\n");
    printf("Input key size should be of desired cipher key size.\n");
    printf("Key is passed directly to the cipher algorithm, no hashing or any other\n");
    printf("processing is performed. It is up to the user to provide strong key.\n");
    printf("For available ciphers, chain modes and key sizes check /proc/crypto.\n");
    printf("Only plain IV mode is supported.\n");
    printf("Input file size must be multiple of sector size i.e. %lu bytes.\n", SECTOR_SIZE);
    printf("If input file is not multiple of sector size, output will be truncated.\n\n");
    printf("Mandatory arguments:\n");
    printf(" --cipher,-c   Cipher-chainmode-ivmode, for example, aes-xts-plain\n");
    printf(" --key-size,-s Size of key in bytes\n");
    printf(" --key-file,-f Input key file, should be at least key-size bytes.\n");
    printf("               Key data after key-size is ignored.\n");
    printf(" --in-file,-i  Input file\n");
    printf(" --out-file,-o Output file\n");
    printf(" --enc,-e      Perform encryption operation from input to output file.\n");
    printf(" --dec,-d      Perform decryption operation from input to output file.\n");
    printf(" --help,-h,-?  Display this text.\n");
}

canonical_original_code:
void display_usage(char *name) {
    printf("Encrypts/decrypts file in dm-crypt compatible way, using kernel crypto API.\n");
    printf("Copyright (c) 2013 Maxim Radugin.\n\n");
    printf("Usage: %s <arguments>\n\n", name);
    printf("This utility is designed to encrypt disk/partition image files in userspace\n");
    printf("without root priviledges and without using device mapper and cryptsetup.\n");
    printf("Currently supports only plain mode, no LUKS support!\n");
    printf("Backend code is taken from cryptsetup.\n");
    printf("Input key size should be of desired cipher key size.\n");
    printf("Key is passed directly to the cipher algorithm, no hashing or any other\n");
    printf("processing is performed. It is up to the user to provide strong key.\n");
    printf("For available ciphers, chain modes and key sizes check /proc/crypto.\n");
    printf("Only plain IV mode is supported.\n");
    printf("Input file size must be multiple of sector size i.e. %lu bytes.\n", SECTOR_SIZE);
    printf("If input file is not multiple of sector size, output will be truncated.\n\n");
    printf("Mandatory arguments:\n");
    printf(" --cipher,-c   Cipher-chainmode-ivmode, for example, aes-xts-plain\n");
    printf(" --key-size,-s Size of key in bytes\n");
    printf(" --key-file,-f Input key file, should be at least key-size bytes.\n");
    printf("               Key data after key-size is ignored.\n");
    printf(" --in-file,-i  Input file\n");
    printf(" --out-file,-o Output file\n");
    printf(" --enc,-e      Perform encryption operation from input to output file.\n");
    printf(" --dec,-d      Perform decryption operation from input to output file.\n");
    printf(" --help,-h,-?  Display this text.\n");
}

return_type: void


decompiled_code:
void *__fastcall load_key(const char *a1, unsigned int a2)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
void *v5; // rdi
void *result; // rax

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror("Unable to open key file");
result = 0LL;
}
else
{
v3 = v2;
v4 = malloc((int)a2);
if ( read(v3, v4, (int)a2) == a2 )
{
printf("Key loaded from %s, %d bits\n", a1, 8 * a2);
}
else
{
fprintf(stderr, "Key file size should be at exactly %d bytes\n", a2);
v5 = v4;
v4 = 0LL;
free(v5);
}
close(v3);
result = v4;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(const char *a1, unsigned int a2)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
void *v5; // rdi
void *result; // rax

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror("Unable to open key file");
result = 0LL;
}
else
{
v3 = v2;
v4 = malloc((int)a2);
if ( read(v3, v4, (int)a2) == a2 )
{
printf("Key loaded from %s, %d bits\n", a1, 8 * a2);
}
else
{
fprintf(stderr, "Key file size should be at exactly %d bytes\n", a2);
v5 = v4;
v4 = 0LL;
free(v5);
}
close(v3);
result = v4;
}
return result;
}

original_code:
char* load_key(const char* keyfile, int keysize)
{
    char* key = ((void *)0);
    int key_fd = open(keyfile, 00);
    if (key_fd < 0) {
        perror("Unable to open key file");
    }
    else {
        key = (char*)malloc(keysize);
        if (read(key_fd, key, keysize) != keysize) {
            fprintf(stderr, "Key file size should be at exactly %d bytes\n", keysize);
            free(key);
            key = ((void *)0);
        }
        else {
            printf("Key loaded from %s, %d bits\n", keyfile, keysize*8);
        }
        close(key_fd);
    }
    return key;
}

canonical_original_code:
char *load_key(char *keyfile, int keysize)
{
    char *key = ((void *)0);
    int key_fd = open(keyfile, 00);
    if (key_fd < 0) {
        perror("Unable to open key file");
    }
    else {
        key = (char *)malloc(keysize);
        if (read(key_fd, key, keysize) != keysize) {
            fprintf(stderr, "Key file size should be at exactly %d bytes\n", keysize);
            free(key);
            key = ((void *)0);
        }
        else {
            printf("Key loaded from %s, %d bits\n", keyfile, keysize*8);
        }
        close(key_fd);
    }
    return key;
}

variable_types:
keyfile
char *

variable_types: keysize int

variable_types:
key
char *

return_type: char *


main

canonical_name: main

repo: mrdomino/mdcolor

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // rdi
int v5; // ebx
__int64 v6; // rax
int result; // eax
_BYTE v8[32]; // [rsp+0h] [rbp-58h] BYREF
char v9[56]; // [rsp+20h] [rbp-38h] BYREF

v3 = argv;
if ( argc == 2 && (v4 = argv[1], argv = (const char **)v8, (int)read_digest(v4, v8, envp) >= 0) )
{
v5 = 0;
mdcolor(v8, 32LL, v9);
do
{
v6 = v5++;
printrgbhex(*(unsigned __int16 *)&v9[3 * v6] | ((unsigned __int64)(unsigned __int8)v9[3 * v6 + 2] << 16));
}
while ( v5 != 16 );
result = 0;
}
else
{
usage(*v3, argv, envp);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // rdi
int v5; // ebx
__int64 v6; // rax
int result; // eax
_BYTE v8[32]; // [rsp+0h] [rbp-58h] BYREF
char v9[56]; // [rsp+20h] [rbp-38h] BYREF

v3 = argv;
if ( argc == 2 && (v4 = argv[1], argv = (const char **)v8, (int)func11(v4, v8, envp) >= 0) )
{
v5 = 0;
func10(v8, 32LL, v9);
do
{
v6 = v5++;
func9(*(unsigned __int16 *)&v9[3 * v6] | ((unsigned __int64)(unsigned __int8)v9[3 * v6 + 2] << 16));
}
while ( v5 != 16 );
result = 0;
}
else
{
func7(*v3, argv, envp);
result = 1;
}
return result;
}

original_code:
int
main(int argc, char **argv)
{
 int i;
 mdcolor_t cs;
 u_int16_t buf[(256 / 16)];
 if (argc != 2 || read_digest(argv[1], buf) < 0) {
  usage(argv[0]);
  return 1;
 }
 mdcolor(buf, sizeof buf, &cs);
 for (i = 0; i < (256 / 16); ++i) {
  printrgbhex(cs.c[i]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 struct mdcolor_t cs;
 unsigned int buf[-1];
 if (argc != 2 || read_digest(argv[1], buf) < 0) {
  usage(argv[0]);
  return 1;
 }
 mdcolor(buf, sizeof buf, &cs);
 for (i = 0; i < (256 / 16); ++i) {
  printrgbhex(cs.c[i]);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: struct mdcolor_t { struct rgb_t { unsigned char r; unsigned char g; unsigned char b; } c[-1]; }

variable_types:
buf
unsigned int [-1]

user_defined_types: struct mdcolor_t { struct rgb_t c[-1]; }


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "usage: %s <sha256>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "usage: %s <sha256>\n", a1);
}

original_code:
static void
usage(const char *progname)
{
 fprintf(stderr, "usage: %s <sha256>\n", progname);
}

canonical_original_code:
static void usage(char *progname)
{
 fprintf(stderr, "usage: %s <sha256>\n", progname);
}

variable_types:
progname
char *


printrgbhex

decompiled_code:
int __fastcall printrgbhex(int a1)
{
return printf("%02hhx%02hhx%02hhx\n", (unsigned __int8)a1, BYTE1(a1), BYTE2(a1));
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return printf("%02hhx%02hhx%02hhx\n", (unsigned __int8)a1, BYTE1(a1), BYTE2(a1));
}

original_code:
void
printrgbhex(rgb_t c)
{
 printf("%02hhx%02hhx%02hhx\n", c.r, c.g, c.b);
}

canonical_original_code:
void printrgbhex(struct rgb_t c)
{
 printf("%02hhx%02hhx%02hhx\n", c.r, c.g, c.b);
}

variable_types: struct rgb_t { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall read_digest(const char *a1, __int64 a2)
{
const char *v3; // rbx

v3 = a1;
if ( strlen(a1) == 64 )
{
while ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 += 4;
a2 += 2LL;
if ( !*v3 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, __int64 a2)
{
const char *v3; // rbx

v3 = a1;
if ( strlen(a1) == 64 )
{
while ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 += 4;
a2 += 2LL;
if ( !*v3 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int
read_digest(const char *str, u_int16_t *out)
{
 if (strlen(str) != (256 / 16) * 4) {
  return -1;
 }
 do {
  if (sscanf(str, "%04hx", out) != 1) {
   return -1;
  }
  str += 4;
  out++;
 } while (*str != '\0');
 return 0;
}

canonical_original_code:
int read_digest(char *str, unsigned int *out)
{
 if (strlen(str) != (256 / 16) * 4) {
  return -1;
 }
 do {
  if (sscanf(str, "%04hx", out) != 1) {
   return -1;
  }
  str += 4;
  out++;
 } while (*str != '\0');
 return 0;
}

variable_types:
str
char *

variable_types:
out
unsigned int *


repo: mrdragonraaar/libmobipocket

decompiled_code:
__int64 __fastcall get_pdb_record_info(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rax
char v9[32]; // [rsp+8h] [rbp-20h] BYREF

get_header_field(v9, 8LL, a2, a3);
init_pdb_record_info(a1);
v4 = v3;
v6 = get_header_field_l(a1, 0LL, v5);
v7 = get_header_field_c(a1 + 4, v6, v9);
get_header_field_uint24(a1 + 8, v7, v9);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rax
char v9[32]; // [rsp+8h] [rbp-20h] BYREF

get_header_field(v9, 8LL, a2, a3);
func3(a1);
v4 = v3;
v6 = get_header_field_l(a1, 0LL, v5);
v7 = get_header_field_c(a1 + 4, v6, v9);
get_header_field_uint24(a1 + 8, v7, v9);
return v4;
}

original_code:
size_t get_pdb_record_info(pdb_record_t *pdb_record, size_t offset,
   const char *rec_info_buf)
{
 char info[8];
 size_t info_offset = 0;
 offset = get_header_field(info, sizeof(info), offset, rec_info_buf);
 init_pdb_record_info(pdb_record);
 info_offset = get_header_field_l(&pdb_record->record_offset,
    info_offset, info);
 info_offset = get_header_field_c(&pdb_record->record_attributes,
    info_offset, info);
 get_header_field_uint24(&pdb_record->unique_id, info_offset, info);
 return offset;
}

canonical_original_code:
unsigned long get_pdb_record_info(struct pdb_record_t *pdb_record, unsigned long offset, char *rec_info_buf)
{
 char info[8];
 unsigned long info_offset = 0;
 offset = get_header_field(info, sizeof(info), offset, rec_info_buf);
 init_pdb_record_info(pdb_record);
 info_offset = get_header_field_l(&pdb_record->record_offset,
    info_offset, info);
 info_offset = get_header_field_c(&pdb_record->record_attributes,
    info_offset, info);
 get_header_field_uint24(&pdb_record->unique_id, info_offset, info);
 return offset;
}

variable_types: struct pdb_record_t { unsigned int record_offset; unsigned char record_attributes; unsigned int unique_id; char *data; } *

variable_types:
offset
unsigned long

variable_types:
info
char [8]

return_type: unsigned long


decompiled_code:
__int64 __fastcall get_pdb_record_data_len(unsigned __int16 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, __int64 a18)
{
__int64 v18; // rcx
__int64 v19; // rsi
__int64 result; // rax

if ( !WORD2(a17) || !a18 )
return 0LL;
v18 = 24LL * a1;
v19 = *(unsigned int *)(a18 + v18);
if ( a1 >= WORD2(a17) - 1 )
result = a7 - v19;
else
result = (unsigned int)(*(_DWORD *)(a18 + v18 + 24) - v19);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, __int64 a18)
{
__int64 v18; // rcx
__int64 v19; // rsi
__int64 result; // rax

if ( !WORD2(a17) || !a18 )
return 0LL;
v18 = 24LL * a1;
v19 = *(unsigned int *)(a18 + v18);
if ( a1 >= WORD2(a17) - 1 )
result = a7 - v19;
else
result = (unsigned int)(*(_DWORD *)(a18 + v18 + 24) - v19);
return result;
}

original_code:
size_t get_pdb_record_data_len(const pdb_t pdb, uint16_t index)
{
 if (pdb.records.num_records && (pdb.records.record != ((void *)0)))
 {
  if (index < pdb.records.num_records - 1)
   return pdb.records.record[index+1].record_offset -
      pdb.records.record[index].record_offset;
  return pdb.filesize - pdb.records.record[index].record_offset;
 }
 return 0;
}

canonical_original_code:
unsigned long get_pdb_record_data_len(struct pdb_t pdb, unsigned short index)
{
 if (pdb.records.num_records && (pdb.records.record != ((void *)0)))
 {
  if (index < pdb.records.num_records - 1)
   return pdb.records.record[index+1].record_offset -
      pdb.records.record[index].record_offset;
  return pdb.filesize - pdb.records.record[index].record_offset;
 }
 return 0;
}

variable_types: struct pdb_t { unsigned long filesize; struct pdb_header_t { char name[32]; unsigned short attributes; unsigned short version; unsigned int ctime; unsigned int mtime; unsigned int baktime; unsigned int modnum; unsigned int appinfo_id; unsigned int sortinfo_id; char type[4]; char creator[4]; unsigned int unique_id_seed; } header; struct pdb_records_t { unsigned int next_record_id; unsigned short num_records; struct pdb_record_t { unsigned int record_offset; unsigned char record_attributes; unsigned int unique_id; char *data; } *record; } records; }

variable_types:
index
unsigned short

user_defined_types: struct pdb_t { unsigned long filesize; struct pdb_header_t header; struct pdb_records_t records; }

user_defined_types: struct pdb_records_t { unsigned int next_record_id; unsigned short num_records; struct pdb_record_t *record; }


original_code:
void free_pdb_records(pdb_t *pdb)
{
 if (pdb->records.record != ((void *)0))
 {
  uint16_t num_records = pdb->records.num_records;
  uint16_t i;
  for (i = 0; i < num_records; i++)
  {
   if (pdb->records.record[i].data != ((void *)0))
    free(pdb->records.record[i].data);
  }
  free(pdb->records.record);
  pdb->records.record = ((void *)0);
 }
}

canonical_original_code:
void free_pdb_records(struct pdb_t *pdb)
{
 if (pdb->records.record != ((void *)0))
 {
  unsigned short num_records = pdb->records.num_records;
  unsigned short i;
  for (i = 0; i < num_records; i++)
  {
   if (pdb->records.record[i].data != ((void *)0))
    free(pdb->records.record[i].data);
  }
  free(pdb->records.record);
  pdb->records.record = ((void *)0);
 }
}

variable_types: struct pdb_t { unsigned long filesize; struct pdb_header_t { char name[32]; unsigned short attributes; unsigned short version; unsigned int ctime; unsigned int mtime; unsigned int baktime; unsigned int modnum; unsigned int appinfo_id; unsigned int sortinfo_id; char type[4]; char creator[4]; unsigned int unique_id_seed; } header; struct pdb_records_t { unsigned int next_record_id; unsigned short num_records; struct pdb_record_t { unsigned int record_offset; unsigned char record_attributes; unsigned int unique_id; char *data; } *record; } records; } *

variable_types:
i
unsigned short


decompiled_code:
bool __fastcall is_pdb_type(_DWORD *a1, _DWORD *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15, int a16)
{
bool result; // al

result = 0;
if ( HIDWORD(a15) == *a1 )
result = a16 == *a2;
return result;
}

canonical_decompiled_code:
bool __fastcall func12(_DWORD *a1, _DWORD *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15, int a16)
{
bool result; // al

result = 0;
if ( HIDWORD(a15) == *a1 )
result = a16 == *a2;
return result;
}

original_code:
uint8_t is_pdb_type(const pdb_t pdb, const char *type, const char *creator)
{
 if (!memcmp(pdb.header.type, type, sizeof(pdb.header.type)) &&
    !memcmp(pdb.header.creator, creator, sizeof(pdb.header.creator)))
  return 1;
 return 0;
}

canonical_original_code:
unsigned char is_pdb_type(struct pdb_t pdb, char *type, char *creator)
{
 if (!memcmp(pdb.header.type, type, sizeof(pdb.header.type)) &&
    !memcmp(pdb.header.creator, creator, sizeof(pdb.header.creator)))
  return 1;
 return 0;
}

variable_types:
type
char *

variable_types:
creator
char *

return_type: unsigned char

user_defined_types: struct pdb_header_t { char name[32]; unsigned short attributes; unsigned short version; unsigned int ctime; unsigned int mtime; unsigned int baktime; unsigned int modnum; unsigned int appinfo_id; unsigned int sortinfo_id; char type[4]; char creator[4]; unsigned int unique_id_seed; }

user_defined_types: struct pdb_record_t { unsigned int record_offset; unsigned char record_attributes; unsigned int unique_id; char *data; }


decompiled_code:
int __fastcall print_pdb_header(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, char a8, int a9, int a10, int a11, __int64 a12, __int64 a13, __int64 a14, __int64 a15, __int64 a16)
{
printf("Name: %s\n", &a8);
printf("Attributes: %i\n", (unsigned __int16)a12);
printf("Version: %i\n", WORD1(a12));
printf("CTime: %i\n", HIDWORD(a12));
printf("MTime: %i\n", (unsigned int)a13);
printf("BakTime: %i\n", HIDWORD(a13));
printf("ModNum: %i\n", (unsigned int)a14);
printf("AppInfo ID: %i\n", HIDWORD(a14));
printf("SortInfo ID: %i\n", (unsigned int)a15);
printf(
"Type: %c%c%c%c\n",
(unsigned int)SBYTE4(a15),
(unsigned int)SBYTE5(a15),
(unsigned int)SBYTE6(a15),
(unsigned int)SHIBYTE(a15));
printf(
"Creator: %c%c%c%c\n",
(unsigned int)(char)a16,
(unsigned int)SBYTE1(a16),
(unsigned int)SBYTE2(a16),
(unsigned int)SBYTE3(a16));
return printf("Unique ID Seed: %i\n", HIDWORD(a16));
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, char a8, int a9, int a10, int a11, __int64 a12, __int64 a13, __int64 a14, __int64 a15, __int64 a16)
{
printf("Name: %s\n", &a8);
printf("Attributes: %i\n", (unsigned __int16)a12);
printf("Version: %i\n", WORD1(a12));
printf("CTime: %i\n", HIDWORD(a12));
printf("MTime: %i\n", (unsigned int)a13);
printf("BakTime: %i\n", HIDWORD(a13));
printf("ModNum: %i\n", (unsigned int)a14);
printf("AppInfo ID: %i\n", HIDWORD(a14));
printf("SortInfo ID: %i\n", (unsigned int)a15);
printf(
"Type: %c%c%c%c\n",
(unsigned int)SBYTE4(a15),
(unsigned int)SBYTE5(a15),
(unsigned int)SBYTE6(a15),
(unsigned int)SHIBYTE(a15));
printf(
"Creator: %c%c%c%c\n",
(unsigned int)(char)a16,
(unsigned int)SBYTE1(a16),
(unsigned int)SBYTE2(a16),
(unsigned int)SBYTE3(a16));
return printf("Unique ID Seed: %i\n", HIDWORD(a16));
}

original_code:
void print_pdb_header(const pdb_t pdb)
{
 printf("Name: %s\n", pdb.header.name);
 printf("Attributes: %i\n", pdb.header.attributes);
 printf("Version: %i\n", pdb.header.version);
 printf("CTime: %i\n", pdb.header.ctime);
 printf("MTime: %i\n", pdb.header.mtime);
 printf("BakTime: %i\n", pdb.header.baktime);
 printf("ModNum: %i\n", pdb.header.modnum);
 printf("AppInfo ID: %i\n", pdb.header.appinfo_id);
 printf("SortInfo ID: %i\n", pdb.header.sortinfo_id);
 printf("Type: %c%c%c%c\n", pdb.header.type[0], pdb.header.type[1],
    pdb.header.type[2], pdb.header.type[3]);
 printf("Creator: %c%c%c%c\n", pdb.header.creator[0],
    pdb.header.creator[1], pdb.header.creator[2], pdb.header.creator[3]);
 printf("Unique ID Seed: %i\n", pdb.header.unique_id_seed);
}

canonical_original_code:
void print_pdb_header(struct pdb_t pdb)
{
 printf("Name: %s\n", pdb.header.name);
 printf("Attributes: %i\n", pdb.header.attributes);
 printf("Version: %i\n", pdb.header.version);
 printf("CTime: %i\n", pdb.header.ctime);
 printf("MTime: %i\n", pdb.header.mtime);
 printf("BakTime: %i\n", pdb.header.baktime);
 printf("ModNum: %i\n", pdb.header.modnum);
 printf("AppInfo ID: %i\n", pdb.header.appinfo_id);
 printf("SortInfo ID: %i\n", pdb.header.sortinfo_id);
 printf("Type: %c%c%c%c\n", pdb.header.type[0], pdb.header.type[1],
    pdb.header.type[2], pdb.header.type[3]);
 printf("Creator: %c%c%c%c\n", pdb.header.creator[0],
    pdb.header.creator[1], pdb.header.creator[2], pdb.header.creator[3]);
 printf("Unique ID Seed: %i\n", pdb.header.unique_id_seed);
}


decompiled_code:
int __fastcall print_pdb_records_header(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14, __int64 a15, __int64 a16, __int64 a17)
{
printf("Next Record ID: %i\n", (unsigned int)a17);
return printf("Num of Records: %i\n", WORD2(a17));
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14, __int64 a15, __int64 a16, __int64 a17)
{
printf("Next Record ID: %i\n", (unsigned int)a17);
return printf("Num of Records: %i\n", WORD2(a17));
}

original_code:
void print_pdb_records_header(const pdb_t pdb)
{
 printf("Next Record ID: %i\n", pdb.records.next_record_id);
 printf("Num of Records: %i\n", pdb.records.num_records);
}

canonical_original_code:
void print_pdb_records_header(struct pdb_t pdb)
{
 printf("Next Record ID: %i\n", pdb.records.next_record_id);
 printf("Num of Records: %i\n", pdb.records.num_records);
}


decompiled_code:
int __fastcall print_pdb_record_info(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, unsigned int *a18)
{
int result; // eax
unsigned int *v19; // rbx
__int64 v20; // rsi

result = WORD2(a17);
v19 = a18;
if ( WORD2(a17) )
{
do
{
v20 = *v19;
v19 += 6;
printf("Record Offset: %i\n", v20);
printf("Record Attributes: %i\n", *((unsigned __int8 *)v19 - 20));
result = printf("Unique ID: %i\n", *(v19 - 4));
}
while ( v19 != &a18[6 * (unsigned __int16)(WORD2(a17) - 1) + 6] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, unsigned int *a18)
{
int result; // eax
unsigned int *v19; // rbx
__int64 v20; // rsi

result = WORD2(a17);
v19 = a18;
if ( WORD2(a17) )
{
do
{
v20 = *v19;
v19 += 6;
printf("Record Offset: %i\n", v20);
printf("Record Attributes: %i\n", *((unsigned __int8 *)v19 - 20));
result = printf("Unique ID: %i\n", *(v19 - 4));
}
while ( v19 != &a18[6 * (unsigned __int16)(WORD2(a17) - 1) + 6] );
}
return result;
}

original_code:
void print_pdb_record_info(const pdb_t pdb)
{
 uint16_t num_records = pdb.records.num_records;
 uint16_t i;
 for (i = 0; i < num_records; i++)
 {
  printf("Record Offset: %i\n",
     pdb.records.record[i].record_offset);
  printf("Record Attributes: %i\n",
     pdb.records.record[i].record_attributes);
  printf("Unique ID: %i\n", pdb.records.record[i].unique_id);
 }
}

canonical_original_code:
void print_pdb_record_info(struct pdb_t pdb)
{
 unsigned short num_records = pdb.records.num_records;
 unsigned short i;
 for (i = 0; i < num_records; i++)
 {
  printf("Record Offset: %i\n",
     pdb.records.record[i].record_offset);
  printf("Record Attributes: %i\n",
     pdb.records.record[i].record_attributes);
  printf("Unique ID: %i\n", pdb.records.record[i].unique_id);
 }
}


decompiled_code:
int __fastcall print_pdb_record_data(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, __int64 a18)
{
unsigned int v18; // ebx
const char **v19; // rbp
__int64 v20; // rsi
const char *v21; // rdi
int result; // eax

if ( WORD2(a17) )
{
v18 = 0;
v19 = (const char **)(a18 + 16);
do
{
v20 = v18++;
printf("Record %i\n", v20);
v21 = *v19;
v19 += 3;
result = puts(v21);
}
while ( WORD2(a17) > (unsigned __int16)v18 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, __int64 a18)
{
unsigned int v18; // ebx
const char **v19; // rbp
__int64 v20; // rsi
const char *v21; // rdi
int result; // eax

if ( WORD2(a17) )
{
v18 = 0;
v19 = (const char **)(a18 + 16);
do
{
v20 = v18++;
printf("Record %i\n", v20);
v21 = *v19;
v19 += 3;
result = puts(v21);
}
while ( WORD2(a17) > (unsigned __int16)v18 );
}
return result;
}

original_code:
void print_pdb_record_data(const pdb_t pdb)
{
 uint16_t num_records = pdb.records.num_records;
 uint16_t i;
 for (i = 0; i < num_records; i++)
 {
  printf("Record %i\n", i);
  printf("%s\n", pdb.records.record[i].data);
 }
}

canonical_original_code:
void print_pdb_record_data(struct pdb_t pdb)
{
 unsigned short num_records = pdb.records.num_records;
 unsigned short i;
 for (i = 0; i < num_records; i++)
 {
  printf("Record %i\n", i);
  printf("%s\n", pdb.records.record[i].data);
 }
}


decompiled_code:
bool __fastcall is_header_type(int a1, __int64 a2, _DWORD *a3)
{
return *a3 == a1;
}

canonical_decompiled_code:
bool __fastcall func2(int a1, __int64 a2, _DWORD *a3)
{
return *a3 == a1;
}

original_code:
uint8_t is_header_type(const base_header_t base_h, const char *header_type)
{
 if (!memcmp(base_h.identifier, header_type, sizeof(base_h.identifier)))
  return 1;
 return 0;
}

canonical_original_code:
unsigned char is_header_type(struct base_header_t base_h, char *header_type)
{
 if (!memcmp(base_h.identifier, header_type, sizeof(base_h.identifier)))
  return 1;
 return 0;
}

variable_types: struct base_header_t { char identifier[4]; unsigned int header_length; char *data; }


decompiled_code:
bool __fastcall valid_base_identifier(int a1)
{
bool result; // al

result = 0;
if ( (char)a1 > 64 && SBYTE1(a1) > 64 && (char)((unsigned int)(a1 << 8) >> 24) > 64 )
result = SHIBYTE(a1) > 64;
return result;
}

canonical_decompiled_code:
bool __fastcall func3(int a1)
{
bool result; // al

result = 0;
if ( (char)a1 > 64 && SBYTE1(a1) > 64 && (char)((unsigned int)(a1 << 8) >> 24) > 64 )
result = SHIBYTE(a1) > 64;
return result;
}

original_code:
uint8_t valid_base_identifier(const base_header_t base_h)
{
 return ((base_h.identifier[0] >= 'A') &&
    (base_h.identifier[1] >= 'A') &&
    (base_h.identifier[2] >= 'A') &&
    (base_h.identifier[3] >= 'A'));
}

canonical_original_code:
unsigned char valid_base_identifier(struct base_header_t base_h)
{
 return ((base_h.identifier[0] >= 'A') &&
    (base_h.identifier[1] >= 'A') &&
    (base_h.identifier[2] >= 'A') &&
    (base_h.identifier[3] >= 'A'));
}

user_defined_types: struct base_header_t { char identifier[4]; unsigned int header_length; char *data; }


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

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

original_code:
uint8_t valid_base_header_length(const base_header_t base_h)
{
 return (base_h.header_length >= 0);
}

canonical_original_code:
unsigned char valid_base_header_length(struct base_header_t base_h)
{
 return (base_h.header_length >= 0);
}


decompiled_code:
bool __fastcall valid_base_header(int a1)
{
bool result; // al
__int64 v2; // r8

result = valid_base_identifier(a1);
if ( result )
result = (unsigned __int8)valid_base_header_length(v2) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(int a1)
{
bool result; // al
__int64 v2; // r8

result = func3(a1);
if ( result )
result = (unsigned __int8)func4(v2) != 0;
return result;
}

original_code:
uint8_t valid_base_header(const base_header_t base_h)
{
 return (valid_base_identifier(base_h) &&
    valid_base_header_length(base_h));
}

canonical_original_code:
unsigned char valid_base_header(struct base_header_t base_h)
{
 return (valid_base_identifier(base_h) &&
    valid_base_header_length(base_h));
}


decompiled_code:
__int64 __fastcall get_base_header(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
size_t v6; // rbp
void *v7; // rax

init_base_header((_OWORD *)a1);
v4 = get_header_field(a1, 4LL);
get_header_field_l(a1 + 4, v4, a3);
if ( !valid_base_header(*(_QWORD *)a1) )
return -1LL;
v6 = (unsigned int)(*(_DWORD *)(a1 + 4) - 8);
v7 = malloc(v6);
*(_QWORD *)(a1 + 8) = v7;
return get_header_field(v7, v6);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
size_t v6; // rbp
void *v7; // rax

func0((_OWORD *)a1);
v4 = get_header_field(a1, 4LL);
get_header_field_l(a1 + 4, v4, a3);
if ( !func5(*(_QWORD *)a1) )
return -1LL;
v6 = (unsigned int)(*(_DWORD *)(a1 + 4) - 8);
v7 = malloc(v6);
*(_QWORD *)(a1 + 8) = v7;
return get_header_field(v7, v6);
}

original_code:
size_t get_base_header(base_header_t *base_h, size_t offset,
   const char *pdb_record_0)
{
 init_base_header(base_h);
 offset = get_header_field(&base_h->identifier,
    sizeof(base_h->identifier), offset, pdb_record_0);
 offset = get_header_field_l(&base_h->header_length, offset,
    pdb_record_0);
 if (valid_base_header(*base_h))
 {
  size_t data_length = base_h->header_length - 8;;
  base_h->data = malloc(data_length * sizeof(char));
  offset = get_header_field(base_h->data, data_length,
     offset, pdb_record_0);
  return offset;
 }
 return -1;
}

canonical_original_code:
unsigned long get_base_header(struct base_header_t *base_h, unsigned long offset, char *pdb_record_0)
{
 init_base_header(base_h);
 offset = get_header_field(&base_h->identifier,
    sizeof(base_h->identifier), offset, pdb_record_0);
 offset = get_header_field_l(&base_h->header_length, offset,
    pdb_record_0);
 if (valid_base_header(*base_h))
 {
  unsigned long data_length = base_h->header_length - 8;;
  base_h->data = malloc(data_length * sizeof(char));
  offset = get_header_field(base_h->data, data_length,
     offset, pdb_record_0);
  return offset;
 }
 return -1;
}

variable_types: struct base_header_t { char identifier[4]; unsigned int header_length; char *data; } *


decompiled_code:
int __fastcall print_base_header(__int64 a1, const char *a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
const char *v4; // [rsp+8h] [rbp-10h]

v3 = a1;
v4 = a2;
printf("Identifier: %s\n", (const char *)&v3);
printf("Header Length: %i\n", HIDWORD(v3));
return printf("Data: %s\n", v4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, const char *a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
const char *v4; // [rsp+8h] [rbp-10h]

v3 = a1;
v4 = a2;
printf("Identifier: %s\n", (const char *)&v3);
printf("Header Length: %i\n", HIDWORD(v3));
return printf("Data: %s\n", v4);
}

original_code:
void print_base_header(const base_header_t base_h)
{
 printf("Identifier: %s\n", base_h.identifier);
 printf("Header Length: %i\n", base_h.header_length);
 printf("Data: %s\n", base_h.data);
}

canonical_original_code:
void print_base_header(struct base_header_t base_h)
{
 printf("Identifier: %s\n", base_h.identifier);
 printf("Header Length: %i\n", base_h.header_length);
 printf("Data: %s\n", base_h.data);
}


decompiled_code:
bool __fastcall is_palmdoc_compression(__int16 a1, __int64 a2, __int16 a3)
{
return a3 == a1;
}

canonical_decompiled_code:
bool __fastcall func1(__int16 a1, __int64 a2, __int16 a3)
{
return a3 == a1;
}

original_code:
uint8_t is_palmdoc_compression(const palmdoc_header_t palmdoc_h,
   uint16_t compression)
{
 return palmdoc_h.compression == compression;
}

canonical_original_code:
unsigned char is_palmdoc_compression(struct palmdoc_header_t palmdoc_h, unsigned short compression)
{
 return palmdoc_h.compression == compression;
}

variable_types: struct palmdoc_header_t { unsigned short compression; unsigned short unused; unsigned int text_length; unsigned short record_count; unsigned short record_size; unsigned short encryption_type; unsigned short unknown; }

variable_types:
compression
unsigned short


decompiled_code:
__int64 __fastcall valid_palmdoc_compression(__int16 a1, __int64 a2)
{
unsigned int v2; // er8
unsigned int v4; // er8

if ( is_palmdoc_compression(a1, a2, 0) || is_palmdoc_compression(a1, a2, 2) )
return v2;
LOBYTE(v4) = is_palmdoc_compression(a1, a2, 17480);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int64 a2)
{
unsigned int v2; // er8
unsigned int v4; // er8

if ( func1(a1, a2, 0) || func1(a1, a2, 2) )
return v2;
LOBYTE(v4) = func1(a1, a2, 17480);
return v4;
}

original_code:
uint8_t valid_palmdoc_compression(const palmdoc_header_t palmdoc_h)
{
 return (is_palmdoc_compression(palmdoc_h, 0) ||
    is_palmdoc_compression(palmdoc_h, 2) ||
    is_palmdoc_compression(palmdoc_h, 17480));
}

canonical_original_code:
unsigned char valid_palmdoc_compression(struct palmdoc_header_t palmdoc_h)
{
 return (is_palmdoc_compression(palmdoc_h, 0) ||
    is_palmdoc_compression(palmdoc_h, 2) ||
    is_palmdoc_compression(palmdoc_h, 17480));
}

user_defined_types: struct palmdoc_header_t { unsigned short compression; unsigned short unused; unsigned int text_length; unsigned short record_count; unsigned short record_size; unsigned short encryption_type; unsigned short unknown; }


decompiled_code:
bool __fastcall is_palmdoc_encryption(__int64 a1, __int64 a2, unsigned __int16 a3)
{
return WORD2(a2) == a3;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1, __int64 a2, unsigned __int16 a3)
{
return WORD2(a2) == a3;
}

original_code:
uint8_t is_palmdoc_encryption(const palmdoc_header_t palmdoc_h,
   uint16_t encryption_type)
{
 return palmdoc_h.encryption_type == encryption_type;
}

canonical_original_code:
unsigned char is_palmdoc_encryption(struct palmdoc_header_t palmdoc_h, unsigned short encryption_type)
{
 return palmdoc_h.encryption_type == encryption_type;
}


decompiled_code:
__int64 __fastcall valid_palmdoc_encryption(__int64 a1, __int64 a2)
{
__int64 v2; // r8
unsigned int v3; // er9
__int64 v4; // r8
unsigned int v6; // er9

if ( is_palmdoc_encryption(a1, a2, 0) || is_palmdoc_encryption(a1, v2, 1u) )
return v3;
LOBYTE(v6) = is_palmdoc_encryption(a1, v4, 2u);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r8
unsigned int v3; // er9
__int64 v4; // r8
unsigned int v6; // er9

if ( func3(a1, a2, 0) || func3(a1, v2, 1u) )
return v3;
LOBYTE(v6) = func3(a1, v4, 2u);
return v6;
}

original_code:
uint8_t valid_palmdoc_encryption(const palmdoc_header_t palmdoc_h)
{
 return (is_palmdoc_encryption(palmdoc_h, 0) ||
    is_palmdoc_encryption(palmdoc_h, 1) ||
    is_palmdoc_encryption(palmdoc_h, 2));
}

canonical_original_code:
unsigned char valid_palmdoc_encryption(struct palmdoc_header_t palmdoc_h)
{
 return (is_palmdoc_encryption(palmdoc_h, 0) ||
    is_palmdoc_encryption(palmdoc_h, 1) ||
    is_palmdoc_encryption(palmdoc_h, 2));
}


decompiled_code:
char __fastcall valid_palmdoc(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // r10

result = 0;
if ( (_WORD)a2 )
{
result = valid_palmdoc_encryption(a1, a2);
if ( result )
result = (unsigned __int8)valid_palmdoc_compression(a1, v3) != 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // r10

result = 0;
if ( (_WORD)a2 )
{
result = func4(a1, a2);
if ( result )
result = (unsigned __int8)func2(a1, v3) != 0;
}
return result;
}

original_code:
uint8_t valid_palmdoc(const palmdoc_header_t palmdoc_h)
{
 return ((palmdoc_h.record_count != 0) &&
    valid_palmdoc_encryption(palmdoc_h) &&
    valid_palmdoc_compression(palmdoc_h));
}

canonical_original_code:
unsigned char valid_palmdoc(struct palmdoc_header_t palmdoc_h)
{
 return ((palmdoc_h.record_count != 0) &&
    valid_palmdoc_encryption(palmdoc_h) &&
    valid_palmdoc_compression(palmdoc_h));
}


decompiled_code:
__int64 __fastcall get_palmdoc_header(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
_BYTE v9[40]; // [rsp+0h] [rbp-28h] BYREF

init_palmdoc_header((_OWORD *)a1);
v1 = get_header_field(v9, 16LL);
v2 = get_header_field_s(a1, 0LL, v9);
v3 = get_header_field_s(a1 + 2, v2, v9);
v4 = get_header_field_l(a1 + 4, v3, v9);
v5 = get_header_field_s(a1 + 8, v4, v9);
v6 = get_header_field_s(a1 + 10, v5, v9);
v7 = get_header_field_s(a1 + 12, v6, v9);
get_header_field_s(a1 + 14, v7, v9);
if ( !valid_palmdoc(*(_QWORD *)a1, *(_QWORD *)(a1 + 8)) )
v1 = -1LL;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
_BYTE v9[40]; // [rsp+0h] [rbp-28h] BYREF

func0((_OWORD *)a1);
v1 = get_header_field(v9, 16LL);
v2 = get_header_field_s(a1, 0LL, v9);
v3 = get_header_field_s(a1 + 2, v2, v9);
v4 = get_header_field_l(a1 + 4, v3, v9);
v5 = get_header_field_s(a1 + 8, v4, v9);
v6 = get_header_field_s(a1 + 10, v5, v9);
v7 = get_header_field_s(a1 + 12, v6, v9);
get_header_field_s(a1 + 14, v7, v9);
if ( !func5(*(_QWORD *)a1, *(_QWORD *)(a1 + 8)) )
v1 = -1LL;
return v1;
}

original_code:
size_t get_palmdoc_header(palmdoc_header_t *palmdoc_h, char *pdb_record_0)
{
 char header[16];
 size_t header_offset = 0;
 size_t offset = 0;
 init_palmdoc_header(palmdoc_h);
 offset = get_header_field(header, sizeof(header), offset,
    pdb_record_0);
 header_offset = get_header_field_s(&palmdoc_h->compression,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->unused, header_offset,
    header);
 header_offset = get_header_field_l(&palmdoc_h->text_length,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->record_count,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->record_size,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->encryption_type,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->unknown, header_offset,
    header);
 if (valid_palmdoc(*palmdoc_h))
  return offset;
 return -1;
}

canonical_original_code:
unsigned long get_palmdoc_header(struct palmdoc_header_t *palmdoc_h, char *pdb_record_0)
{
 char header[16];
 unsigned long header_offset = 0;
 unsigned long offset = 0;
 init_palmdoc_header(palmdoc_h);
 offset = get_header_field(header, sizeof(header), offset,
    pdb_record_0);
 header_offset = get_header_field_s(&palmdoc_h->compression,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->unused, header_offset,
    header);
 header_offset = get_header_field_l(&palmdoc_h->text_length,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->record_count,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->record_size,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->encryption_type,
    header_offset, header);
 header_offset = get_header_field_s(&palmdoc_h->unknown, header_offset,
    header);
 if (valid_palmdoc(*palmdoc_h))
  return offset;
 return -1;
}

variable_types: struct palmdoc_header_t { unsigned short compression; unsigned short unused; unsigned int text_length; unsigned short record_count; unsigned short record_size; unsigned short encryption_type; unsigned short unknown; } *

variable_types:
header
char [16]


decompiled_code:
int __fastcall print_palmdoc_header(unsigned __int64 a1, unsigned __int64 a2)
{
printf("Compression: %i\n", (unsigned __int16)a1);
printf("Unused: %i\n", WORD1(a1));
printf("Text Length: %i\n", HIDWORD(a1));
printf("Record Count: %i\n", (unsigned __int16)a2);
printf("Record Size: %i\n", WORD1(a2));
printf("Encryption: %i\n", WORD2(a2));
return printf("Unknown: %i\n", HIWORD(a2));
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 a1, unsigned __int64 a2)
{
printf("Compression: %i\n", (unsigned __int16)a1);
printf("Unused: %i\n", WORD1(a1));
printf("Text Length: %i\n", HIDWORD(a1));
printf("Record Count: %i\n", (unsigned __int16)a2);
printf("Record Size: %i\n", WORD1(a2));
printf("Encryption: %i\n", WORD2(a2));
return printf("Unknown: %i\n", HIWORD(a2));
}

original_code:
void print_palmdoc_header(const palmdoc_header_t palmdoc_h)
{
 printf("Compression: %i\n", palmdoc_h.compression);
 printf("Unused: %i\n", palmdoc_h.unused);
 printf("Text Length: %i\n", palmdoc_h.text_length);
 printf("Record Count: %i\n", palmdoc_h.record_count);
 printf("Record Size: %i\n", palmdoc_h.record_size);
 printf("Encryption: %i\n", palmdoc_h.encryption_type);
 printf("Unknown: %i\n", palmdoc_h.unknown);
}

canonical_original_code:
void print_palmdoc_header(struct palmdoc_header_t palmdoc_h)
{
 printf("Compression: %i\n", palmdoc_h.compression);
 printf("Unused: %i\n", palmdoc_h.unused);
 printf("Text Length: %i\n", palmdoc_h.text_length);
 printf("Record Count: %i\n", palmdoc_h.record_count);
 printf("Record Size: %i\n", palmdoc_h.record_size);
 printf("Encryption: %i\n", palmdoc_h.encryption_type);
 printf("Unknown: %i\n", palmdoc_h.unknown);
}


decompiled_code:
__int64 __fastcall get_exth_record(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax
int v6; // edx

init_exth_record((_OWORD *)a1);
v4 = ((__int64 (*)(void))get_header_field_l)();
result = get_header_field_l(a1 + 4, v4, a3);
v6 = *(_DWORD *)(a1 + 4);
if ( v6 )
result = get_header_field_str(a1 + 8, (unsigned int)(v6 - 8), result, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax
int v6; // edx

func1((_OWORD *)a1);
v4 = ((__int64 (*)(void))get_header_field_l)();
result = get_header_field_l(a1 + 4, v4, a3);
v6 = *(_DWORD *)(a1 + 4);
if ( v6 )
result = get_header_field_str(a1 + 8, (unsigned int)(v6 - 8), result, a3);
return result;
}

original_code:
size_t get_exth_record(exth_record_t *exth_r, size_t offset,
   const char *exth_rec_buf)
{
 init_exth_record(exth_r);
 offset = get_header_field_l(&exth_r->record_type, offset, exth_rec_buf);
 offset = get_header_field_l(&exth_r->record_length, offset,
    exth_rec_buf);
 if (exth_r->record_length)
 {
  size_t data_length = exth_r->record_length -
     8;
  offset = get_header_field_str(&exth_r->record_data,
     data_length, offset, exth_rec_buf);
 }
 return offset;
}

canonical_original_code:
unsigned long get_exth_record(struct exth_record_t *exth_r, unsigned long offset, char *exth_rec_buf)
{
 init_exth_record(exth_r);
 offset = get_header_field_l(&exth_r->record_type, offset, exth_rec_buf);
 offset = get_header_field_l(&exth_r->record_length, offset,
    exth_rec_buf);
 if (exth_r->record_length)
 {
  unsigned long data_length = exth_r->record_length -
     8;
  offset = get_header_field_str(&exth_r->record_data,
     data_length, offset, exth_rec_buf);
 }
 return offset;
}

variable_types: struct exth_record_t { unsigned int record_type; unsigned int record_length; char *record_data; } *


decompiled_code:
__int64 __fastcall get_exth_records(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // er12
__int64 result; // rax
__int64 v6; // r13
void *v7; // rax
__int64 v8; // r12

v3 = *(_DWORD *)(a1 + 8);
if ( !v3 )
return a2;
v6 = 0LL;
v7 = malloc(16LL * v3);
v8 = 16LL * (v3 - 1);
*(_QWORD *)(a1 + 16) = v7;
while ( 1 )
{
result = get_exth_record((__int64)v7 + v6, a2, a3);
a2 = result;
if ( v6 == v8 )
break;
v7 = *(void **)(a1 + 16);
v6 += 16LL;
}
return result;
}

original_code:
size_t get_exth_records(exth_header_t *exth_h, size_t offset,
   const char *exth_rec_buf)
{
 uint32_t record_count = exth_h->record_count;
 if (record_count)
 {
  exth_h->record = malloc(record_count * sizeof(exth_record_t));
  uint32_t i;
  for (i = 0; i < record_count; i++)
  {
   offset = get_exth_record(&exth_h->record[i], offset,
      exth_rec_buf);
  }
 }
 return offset;
}

canonical_original_code:
unsigned long get_exth_records(struct exth_header_t *exth_h, unsigned long offset, char *exth_rec_buf)
{
 unsigned int record_count = exth_h->record_count;
 if (record_count)
 {
  exth_h->record = malloc(record_count * sizeof(exth_record_t));
  unsigned int i;
  for (i = 0; i < record_count; i++)
  {
   offset = get_exth_record(&exth_h->record[i], offset,
      exth_rec_buf);
  }
 }
 return offset;
}

variable_types: struct exth_header_t { char identifier[4]; unsigned int header_length; unsigned int record_count; struct exth_record_t { unsigned int record_type; unsigned int record_length; char *record_data; } *record; } *

variable_types:
i
unsigned int

user_defined_types: struct exth_header_t { char identifier[4]; unsigned int header_length; unsigned int record_count; struct exth_record_t *record; }


decompiled_code:
__int64 __fastcall convert_base2exth(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
__int64 v5; // rax

init_exth_header((__int64)a1);
*a1 = a2;
v5 = get_header_field_l(a1 + 1, 0LL, v4);
return get_exth_records((__int64)a1, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
__int64 v5; // rax

func0((__int64)a1);
*a1 = a2;
v5 = get_header_field_l(a1 + 1, 0LL, v4);
return func3((__int64)a1, v5, a3);
}

original_code:
void convert_base2exth(exth_header_t *exth_h, const base_header_t base_h)
{
 init_exth_header(exth_h);
 memcpy(&exth_h->identifier, base_h.identifier,
    sizeof(exth_h->identifier));
 exth_h->header_length = base_h.header_length;
 size_t offset = 0;
 offset = get_header_field_l(&exth_h->record_count, offset, base_h.data);
 get_exth_records(exth_h, offset, base_h.data);
}

canonical_original_code:
void convert_base2exth(struct exth_header_t *exth_h, struct base_header_t base_h)
{
 init_exth_header(exth_h);
 memcpy(&exth_h->identifier, base_h.identifier,
    sizeof(exth_h->identifier));
 exth_h->header_length = base_h.header_length;
 unsigned long offset = 0;
 offset = get_header_field_l(&exth_h->record_count, offset, base_h.data);
 get_exth_records(exth_h, offset, base_h.data);
}

variable_types:
offset
unsigned long

user_defined_types: struct exth_record_t { unsigned int record_type; unsigned int record_length; char *record_data; }


decompiled_code:
__int64 __fastcall get_exth_header(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // r12
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]

v1 = get_base_header(&v4);
if ( v1 == 1 )
return 1LL;
if ( (unsigned __int8)is_header_type(v4, v5, "EXTH") )
{
convert_base2exth((_QWORD *)a1, v4, v5);
v3 = 4 - (*(_DWORD *)(a1 + 4) & 3u) + v1;
}
else
{
v3 = -1LL;
}
free_base_header(&v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // r12
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]

v1 = get_base_header(&v4);
if ( v1 == 1 )
return 1LL;
if ( (unsigned __int8)is_header_type(v4, v5, "EXTH") )
{
func4((_QWORD *)a1, v4, v5);
v3 = 4 - (*(_DWORD *)(a1 + 4) & 3u) + v1;
}
else
{
v3 = -1LL;
}
free_base_header(&v4);
return v3;
}

original_code:
size_t get_exth_header(exth_header_t *exth_h, size_t offset,
   const char *pdb_record_0)
{
 base_header_t base_h;
 offset = get_base_header(&base_h, offset, pdb_record_0);
 if (offset != 1)
 {
  if (is_header_type(base_h, "EXTH"))
  {
   convert_base2exth(exth_h, base_h);
   offset += 4 - (exth_h->header_length % 4);
  }
  else
   offset = -1;
  free_base_header(&base_h);
 }
 return offset;
}

canonical_original_code:
unsigned long get_exth_header(struct exth_header_t *exth_h, unsigned long offset, char *pdb_record_0)
{
 struct base_header_t base_h;
 offset = get_base_header(&base_h, offset, pdb_record_0);
 if (offset != 1)
 {
  if (is_header_type(base_h, "EXTH"))
  {
   convert_base2exth(exth_h, base_h);
   offset += 4 - (exth_h->header_length % 4);
  }
  else
   offset = -1;
  free_base_header(&base_h);
 }
 return offset;
}


decompiled_code:
__int64 __fastcall exth_record_index(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, unsigned int a8, __int64 a9)
{
_DWORD *i; // rax

if ( a8 <= a1 )
return 0xFFFFFFFFLL;
for ( i = (_DWORD *)(a9 + 16LL * a1); !a9 || *i != a2; i += 4 )
{
if ( a8 == ++a1 )
return 0xFFFFFFFFLL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, unsigned int a8, __int64 a9)
{
_DWORD *i; // rax

if ( a8 <= a1 )
return 0xFFFFFFFFLL;
for ( i = (_DWORD *)(a9 + 16LL * a1); !a9 || *i != a2; i += 4 )
{
if ( a8 == ++a1 )
return 0xFFFFFFFFLL;
}
return a1;
}

original_code:
uint32_t exth_record_index(const exth_header_t exth_h,
   uint32_t offset_index, uint32_t record_type)
{
 uint32_t index;
 for (index = offset_index; index < exth_h.record_count; index++)
 {
  if (exth_h.record != ((void *)0) &&
     exth_h.record[index].record_type == record_type)
   return index;
 }
 return -1;
}

canonical_original_code:
unsigned int exth_record_index(struct exth_header_t exth_h, unsigned int offset_index, unsigned int record_type)
{
 unsigned int index;
 for (index = offset_index; index < exth_h.record_count; index++)
 {
  if (exth_h.record != ((void *)0) &&
     exth_h.record[index].record_type == record_type)
   return index;
 }
 return -1;
}

variable_types: struct exth_header_t { char identifier[4]; unsigned int header_length; unsigned int record_count; struct exth_record_t { unsigned int record_type; unsigned int record_length; char *record_data; } *record; }

variable_types:
index
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall exth_record_data(_QWORD *a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax
_QWORD *v10; // r8

*a1 = 0LL;
result = exth_record_index(a2, a3, a3, a4, (__int64)a1, a6, a7, a8, a9);
if ( (_DWORD)result != -1 )
*v10 = *(_QWORD *)(a9 + 16LL * (unsigned int)result + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax
_QWORD *v10; // r8

*a1 = 0LL;
result = func7(a2, a3, a3, a4, (__int64)a1, a6, a7, a8, a9);
if ( (_DWORD)result != -1 )
*v10 = *(_QWORD *)(a9 + 16LL * (unsigned int)result + 8);
return result;
}

original_code:
uint32_t exth_record_data(char **record_data, const exth_header_t exth_h,
   uint32_t offset_index, uint32_t record_type)
{
 *record_data = ((void *)0);
 offset_index = exth_record_index(exth_h, offset_index, record_type);
 if (offset_index != -1)
  *record_data = exth_h.record[offset_index].record_data;
 return offset_index;
}

canonical_original_code:
unsigned int exth_record_data(char **record_data, struct exth_header_t exth_h, unsigned int offset_index, unsigned int record_type)
{
 *record_data = ((void *)0);
 offset_index = exth_record_index(exth_h, offset_index, record_type);
 if (offset_index != -1)
  *record_data = exth_h.record[offset_index].record_data;
 return offset_index;
}


decompiled_code:
__int64 __fastcall exth_record(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v10; // [rsp+8h] [rbp-8h] BYREF

v10 = 0LL;
exth_record_data(&v10, 0, a1, a4, a5, a6, a7, a8, a9);
return v10;
}

original_code:
char* exth_record(const exth_header_t exth_h, uint32_t record_type)
{
 char *record_data = ((void *)0);
 exth_record_data(&record_data, exth_h, 0, record_type);
 return record_data;
}

canonical_original_code:
char *exth_record(struct exth_header_t exth_h, unsigned int record_type)
{
 char *record_data = ((void *)0);
 exth_record_data(&record_data, exth_h, 0, record_type);
 return record_data;
}


decompiled_code:
__int64 __fastcall exth_record_l(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rax
unsigned int v11[3]; // [rsp+Ch] [rbp-Ch] BYREF

v11[0] = 0;
v9 = exth_record(a1, a2, a3, a4, a5, a6, a7, a8, a9);
get_header_field_l(v11, 0LL, v9);
return v11[0];
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rax
unsigned int v11[3]; // [rsp+Ch] [rbp-Ch] BYREF

v11[0] = 0;
v9 = func9(a1, a2, a3, a4, a5, a6, a7, a8, a9);
get_header_field_l(v11, 0LL, v9);
return v11[0];
}

original_code:
uint32_t exth_record_l(const exth_header_t exth_h, uint32_t record_type)
{
 uint32_t record_data = 0;
 get_header_field_l(&record_data, 0, exth_record(exth_h, record_type));
 return record_data;
}

canonical_original_code:
unsigned int exth_record_l(struct exth_header_t exth_h, unsigned int record_type)
{
 unsigned int record_data = 0;
 get_header_field_l(&record_data, 0, exth_record(exth_h, record_type));
 return record_data;
}


decompiled_code:
const char *__fastcall exth_creator_software_str(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
unsigned int v9; // eax
unsigned int v10; // edx
const char *result; // rax

v9 = exth_record_l(0xCCu, a2, a3, a4, a5, a6, a7, a8, a9);
if ( v9 == 200 )
return "kindlegen (Windows)";
v10 = v9;
if ( v9 <= 0xC8 )
{
result = "mobigen";
if ( v10 != 1 )
{
result = "MobiPocket Creator";
if ( v10 != 2 )
result = 0LL;
}
}
else
{
result = "kindlegen (Linux)";
if ( v10 != 201 )
{
result = "kindlegen (Mac)";
if ( v10 != 202 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
unsigned int v9; // eax
unsigned int v10; // edx
const char *result; // rax

v9 = func10(0xCCu, a2, a3, a4, a5, a6, a7, a8, a9);
if ( v9 == 200 )
return "kindlegen (Windows)";
v10 = v9;
if ( v9 <= 0xC8 )
{
result = "mobigen";
if ( v10 != 1 )
{
result = "MobiPocket Creator";
if ( v10 != 2 )
result = 0LL;
}
}
else
{
result = "kindlegen (Linux)";
if ( v10 != 201 )
{
result = "kindlegen (Mac)";
if ( v10 != 202 )
result = 0LL;
}
}
return result;
}

original_code:
char* exth_creator_software_str(const exth_header_t exth_h)
{
 switch(exth_record_l(exth_h, 204))
 {
  case 1:
   return "mobigen";
  case 2:
   return "MobiPocket Creator";
  case 200:
   return "kindlegen (Windows)";
  case 201:
   return "kindlegen (Linux)";
  case 202:
   return "kindlegen (Mac)";
  default:
   return ((void *)0);
 }
}

canonical_original_code:
char *exth_creator_software_str(struct exth_header_t exth_h)
{
 switch(exth_record_l(exth_h, 204))
 {
  case 1:
   return "mobigen";
  case 2:
   return "MobiPocket Creator";
  case 200:
   return "kindlegen (Windows)";
  case 201:
   return "kindlegen (Linux)";
  case 202:
   return "kindlegen (Mac)";
  default:
   return ((void *)0);
 }
}


original_code:
uint8_t is_exth_cde_type(const exth_header_t exth_h, const char *cde_type)
{
 char *exth_cde_type = exth_record(exth_h, 501);
 if ((exth_cde_type != ((void *)0)) &&
    !memcmp(exth_cde_type, cde_type, (sizeof(char) * 4)))
  return 1;
 return 0;
}

canonical_original_code:
unsigned char is_exth_cde_type(struct exth_header_t exth_h, char *cde_type)
{
 char *exth_cde_type = exth_record(exth_h, 501);
 if ((exth_cde_type != ((void *)0)) &&
    !memcmp(exth_cde_type, cde_type, (sizeof(char) * 4)))
  return 1;
 return 0;
}


decompiled_code:
const char *__fastcall exth_cde_type_str(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
const char *result; // rax
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
bool v18; // zf

v11 = (unsigned int)is_exth_cde_type((__int64)"PDOC", a2, a3, a4, a5, a6, a7, a8, a9);
result = "Personal Doc";
if ( !(_BYTE)v11 )
{
v16 = (unsigned int)is_exth_cde_type((__int64)"EBOK", a2, v9, v10, v11, v12, a7, a8, a9);
result = "EBook";
if ( !(_BYTE)v16 )
{
v18 = (unsigned __int8)is_exth_cde_type((__int64)"EBSP", a2, v14, v15, v16, v17, a7, a8, a9) == 0;
result = "EBook Sample";
if ( v18 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
const char *result; // rax
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
bool v18; // zf

v11 = (unsigned int)func12((__int64)"PDOC", a2, a3, a4, a5, a6, a7, a8, a9);
result = "Personal Doc";
if ( !(_BYTE)v11 )
{
v16 = (unsigned int)func12((__int64)"EBOK", a2, v9, v10, v11, v12, a7, a8, a9);
result = "EBook";
if ( !(_BYTE)v16 )
{
v18 = (unsigned __int8)func12((__int64)"EBSP", a2, v14, v15, v16, v17, a7, a8, a9) == 0;
result = "EBook Sample";
if ( v18 )
result = 0LL;
}
}
return result;
}

original_code:
char* exth_cde_type_str(const exth_header_t exth_h)
{
 if (is_exth_cde_type(exth_h, "PDOC"))
  return "Personal Doc";
 if (is_exth_cde_type(exth_h, "EBOK"))
  return "EBook";
 if (is_exth_cde_type(exth_h, "EBSP"))
  return "EBook Sample";
 return ((void *)0);
}

canonical_original_code:
char *exth_cde_type_str(struct exth_header_t exth_h)
{
 if (is_exth_cde_type(exth_h, "PDOC"))
  return "Personal Doc";
 if (is_exth_cde_type(exth_h, "EBOK"))
  return "EBook";
 if (is_exth_cde_type(exth_h, "EBSP"))
  return "EBook Sample";
 return ((void *)0);
}


decompiled_code:
time_t __fastcall exth_publishing_date_utc(struct tm *tp, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
const char *v9; // rax
const char *v10; // r12

v9 = (const char *)exth_record(0x6Au, a2, a3, a4, a5, a6, a7, a8, a9);
if ( !v9 )
return -1LL;
v10 = v9;
if ( strlen(v9) <= 0xA || sscanf(v10, "%d-%d-%d", &tp->tm_year, &tp->tm_mon, &tp->tm_mday) != 3 )
return -1LL;
--tp->tm_mon;
tp->tm_year -= 1900;
return mktime(tp);
}

canonical_decompiled_code:
time_t __fastcall func14(struct tm *tp, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
const char *v9; // rax
const char *v10; // r12

v9 = (const char *)func9(0x6Au, a2, a3, a4, a5, a6, a7, a8, a9);
if ( !v9 )
return -1LL;
v10 = v9;
if ( strlen(v9) <= 0xA || sscanf(v10, "%d-%d-%d", &tp->tm_year, &tp->tm_mon, &tp->tm_mday) != 3 )
return -1LL;
--tp->tm_mon;
tp->tm_year -= 1900;
return mktime(tp);
}

original_code:
time_t exth_publishing_date_utc(struct tm *time, const exth_header_t exth_h)
{
 char *pubdate = exth_record(exth_h, 106);
 const char *format = "%d-%d-%d";
 if ((pubdate != ((void *)0)) && (strlen(pubdate) > 10) &&
    (sscanf(pubdate, format, &time->tm_year, &time->tm_mon,
       &time->tm_mday) == 3))
 {
  time->tm_mon--;
  time->tm_year -= 1900;
  return mktime(time);
 }
 return -1;
}

canonical_original_code:
long exth_publishing_date_utc(struct tm *time, struct exth_header_t exth_h)
{
 char *pubdate = exth_record(exth_h, 106);
 char *format = "%d-%d-%d";
 if ((pubdate != ((void *)0)) && (strlen(pubdate) > 10) &&
    (sscanf(pubdate, format, &time->tm_year, &time->tm_mon,
       &time->tm_mday) == 3))
 {
  time->tm_mon--;
  time->tm_year -= 1900;
  return mktime(time);
 }
 return -1;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types:
pubdate
char *

variable_types:
format
char *

return_type: long


decompiled_code:
int __fastcall print_exth_header(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8, __int64 a9)
{
int result; // eax
unsigned int i; // ebx
__int64 v11; // rsi
__int64 v12; // rbp

printf("Identifier: %s\n", (const char *)&a7);
printf("Header Length: %i\n", HIDWORD(a7));
printf("Record Count: %i\n", a8);
result = a8;
if ( a8 )
{
for ( i = 0; i < a8; ++i )
{
v11 = i;
v12 = 16LL * i;
printf("Record %i: Type: %i Length: %i\n", v11, *(unsigned int *)(v12 + a9), *(unsigned int *)(v12 + a9 + 4));
result = printf("Record Data: %s\n", *(const char **)(a9 + v12 + 8));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8, __int64 a9)
{
int result; // eax
unsigned int i; // ebx
__int64 v11; // rsi
__int64 v12; // rbp

printf("Identifier: %s\n", (const char *)&a7);
printf("Header Length: %i\n", HIDWORD(a7));
printf("Record Count: %i\n", a8);
result = a8;
if ( a8 )
{
for ( i = 0; i < a8; ++i )
{
v11 = i;
v12 = 16LL * i;
printf("Record %i: Type: %i Length: %i\n", v11, *(unsigned int *)(v12 + a9), *(unsigned int *)(v12 + a9 + 4));
result = printf("Record Data: %s\n", *(const char **)(a9 + v12 + 8));
}
}
return result;
}

original_code:
void print_exth_header(const exth_header_t exth_h)
{
 printf("Identifier: %s\n", exth_h.identifier);
 printf("Header Length: %i\n", exth_h.header_length);
 printf("Record Count: %i\n", exth_h.record_count);
 uint32_t i;
 for (i = 0; i < exth_h.record_count; i++)
 {
  printf("Record %i: Type: %i Length: %i\n", i,
     exth_h.record[i].record_type,
     exth_h.record[i].record_length);
  printf("Record Data: %s\n", exth_h.record[i].record_data);
 }
}

canonical_original_code:
void print_exth_header(struct exth_header_t exth_h)
{
 printf("Identifier: %s\n", exth_h.identifier);
 printf("Header Length: %i\n", exth_h.header_length);
 printf("Record Count: %i\n", exth_h.record_count);
 unsigned int i;
 for (i = 0; i < exth_h.record_count; i++)
 {
  printf("Record %i: Type: %i Length: %i\n", i,
     exth_h.record[i].record_type,
     exth_h.record[i].record_length);
  printf("Record Data: %s\n", exth_h.record[i].record_data);
 }
}


decompiled_code:
size_t __fastcall get_header_field(void *a1, size_t a2, __int64 a3, __int64 a4)
{
if ( a4 )
memcpy(a1, (const void *)(a4 + a3), a2);
return a3 + a2;
}

canonical_decompiled_code:
size_t __fastcall func3(void *a1, size_t a2, __int64 a3, __int64 a4)
{
if ( a4 )
memcpy(a1, (const void *)(a4 + a3), a2);
return a3 + a2;
}

original_code:
size_t get_header_field(void *field, size_t size, size_t offset,
   const char *field_buf)
{
 if (field_buf != ((void *)0))
  memcpy(field, field_buf+offset, size);
 offset += size;
 return offset;
}

canonical_original_code:
unsigned long get_header_field(void *field, unsigned long size, unsigned long offset, char *field_buf)
{
 if (field_buf != ((void *)0))
  memcpy(field, field_buf+offset, size);
 offset += size;
 return offset;
}

variable_types:
field
void *

variable_types:
size
unsigned long


decompiled_code:
size_t __fastcall get_header_field_str(_QWORD *a1, size_t a2, __int64 a3, __int64 a4)
{
void *v6; // rax
size_t result; // rax

v6 = malloc(a2 + 1);
*a1 = v6;
result = get_header_field(v6, a2, a3, a4);
*(_BYTE *)(*a1 + a2) = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(_QWORD *a1, size_t a2, __int64 a3, __int64 a4)
{
void *v6; // rax
size_t result; // rax

v6 = malloc(a2 + 1);
*a1 = v6;
result = func3(v6, a2, a3, a4);
*(_BYTE *)(*a1 + a2) = 0;
return result;
}

original_code:
size_t get_header_field_str(char **field, size_t size, size_t offset,
   const char *field_buf)
{
 *field = malloc((size + 1) * sizeof(char));
 offset = get_header_field(*field, size, offset, field_buf);
 (*field)[size] = '\0';
 return offset;
}

canonical_original_code:
unsigned long get_header_field_str(char **field, unsigned long size, unsigned long offset, char *field_buf)
{
 *field = malloc((size + 1) * sizeof(char));
 offset = get_header_field(*field, size, offset, field_buf);
 (*field)[size] = '\0';
 return offset;
}

variable_types:
field
char **


decompiled_code:
size_t __fastcall get_header_field_c(void *a1, __int64 a2, __int64 a3)
{
return get_header_field(a1, 1uLL, a2, a3);
}

canonical_decompiled_code:
size_t __fastcall func5(void *a1, __int64 a2, __int64 a3)
{
return func3(a1, 1uLL, a2, a3);
}

original_code:
size_t get_header_field_c(uint8_t *field, size_t offset, const char *field_buf)
{
 return get_header_field(field, sizeof(uint8_t), offset, field_buf);
}

canonical_original_code:
unsigned long get_header_field_c(unsigned char *field, unsigned long offset, char *field_buf)
{
 return get_header_field(field, sizeof(unsigned char), offset, field_buf);
}

variable_types:
field
unsigned char *


decompiled_code:
__int64 __fastcall get_header_field_s(__int16 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r8

get_header_field(a1, 2uLL, a2, a3);
*a1 = _bswap_16(*a1);
return v3;
}

original_code:
size_t get_header_field_s(uint16_t *field, size_t offset, const char *field_buf)
{
 offset = get_header_field(field, sizeof(uint16_t), offset, field_buf);
 *field = ntohs(*field);
 return offset;
}

canonical_original_code:
unsigned long get_header_field_s(unsigned short *field, unsigned long offset, char *field_buf)
{
 offset = get_header_field(field, sizeof(unsigned short), offset, field_buf);
 *field = ntohs(*field);
 return offset;
}

variable_types:
field
unsigned short *


decompiled_code:
size_t __fastcall get_header_field_uint24(int *a1, __int64 a2, __int64 a3)
{
size_t result; // rax
char v4[11]; // [rsp+Dh] [rbp-Bh] BYREF

result = get_header_field(v4, 3uLL, a2, a3);
*a1 = (unsigned __int8)v4[2] | ((unsigned __int8)v4[1] << 8) | ((unsigned __int8)v4[0] << 16);
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(int *a1, __int64 a2, __int64 a3)
{
size_t result; // rax
char v4[11]; // [rsp+Dh] [rbp-Bh] BYREF

result = func3(v4, 3uLL, a2, a3);
*a1 = (unsigned __int8)v4[2] | ((unsigned __int8)v4[1] << 8) | ((unsigned __int8)v4[0] << 16);
return result;
}

original_code:
size_t get_header_field_uint24(uint32_t *field, size_t offset,
   const char *field_buf)
{
 uint8_t field_arr[3];
 offset = get_header_field(field_arr, sizeof(field_arr), offset,
    field_buf);
 *field = (field_arr[0] << 16) | (field_arr[1] << 8) | field_arr[2];
 return offset;
}

canonical_original_code:
unsigned long get_header_field_uint24(unsigned int *field, unsigned long offset, char *field_buf)
{
 unsigned char field_arr[3];
 offset = get_header_field(field_arr, sizeof(field_arr), offset,
    field_buf);
 *field = (field_arr[0] << 16) | (field_arr[1] << 8) | field_arr[2];
 return offset;
}

variable_types:
field
unsigned int *


decompiled_code:
__int64 __fastcall get_header_field_l(_DWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r8

get_header_field(a1, 4uLL, a2, a3);
*a1 = _bswap_32(*a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r8

func3(a1, 4uLL, a2, a3);
*a1 = func1(*a1);
return v3;
}

original_code:
size_t get_header_field_l(uint32_t *field, size_t offset, const char *field_buf)
{
 offset = get_header_field(field, sizeof(uint32_t), offset, field_buf);
 *field = ntohl(*field);
 return offset;
}

canonical_original_code:
unsigned long get_header_field_l(unsigned int *field, unsigned long offset, char *field_buf)
{
 offset = get_header_field(field, sizeof(unsigned int), offset, field_buf);
 *field = ntohl(*field);
 return offset;
}


repo: mregmi/manrix

decompiled_code:
__int64 __fastcall bsd_signal(int signo, __int64 a2)
{
bool v2; // zf
__int64 result; // rax
_DWORD v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+18h] [rbp-10h]

v5 = a2;
v4[1] = 2;
sigemptyset((sigset_t *)v4);
sigaddset((sigset_t *)v4, signo);
v2 = (unsigned int)sigaction(signo) == -1;
result = -1LL;
if ( !v2 )
result = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int signo, __int64 a2)
{
bool v2; // zf
__int64 result; // rax
_DWORD v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+18h] [rbp-10h]

v5 = a2;
v4[1] = 2;
sigemptyset((sigset_t *)v4);
sigaddset((sigset_t *)v4, signo);
v2 = (unsigned int)func6(signo) == -1;
result = -1LL;
if ( !v2 )
result = v6;
return result;
}

original_code:
void (*bsd_signal(int sig, void (*func)(int)))(int)
{
    struct sigaction act, oact;
    act.action.sa_handler = func;
    act.sa_flags = 2;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, sig);
    if (sigaction(sig, &act, &oact) == -1)
        return(((sighandler_t) -1));
    return(oact.action.sa_handler);
}

canonical_original_code:
void (*bsd_signal(int sig, void (*func)(int)))(int)
{
    struct sigaction act; struct sigaction oact;
    act.action.sa_handler = func;
    act.sa_flags = 2;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, sig);
    if (sigaction(sig, &act, &oact) == -1)
        return(((sighandler_t) -1));
    return(oact.action.sa_handler);
}

variable_types: sig int

variable_types:
func
void (*)(int)

variable_types: struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; long si_band; union sigval { int sigval_int; void *sigval_ptr; } si_value; }, void *); } action; }

return_type: void (*)(int)

user_defined_types: struct sigaction { int sa_mask; int sa_flags; union handler action; }

user_defined_types: union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo, void *); }

user_defined_types: struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; long si_band; union sigval si_value; }


signal

decompiled_code:
__int64 __fastcall signal(int signo, __int64 a2)
{
bool v2; // zf
__int64 result; // rax
_DWORD v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+18h] [rbp-10h]

v5 = a2;
v4[1] = 8;
sigemptyset((sigset_t *)v4);
sigaddset((sigset_t *)v4, signo);
v2 = (unsigned int)sigaction(signo) == -1;
result = -1LL;
if ( !v2 )
result = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int signo, __int64 a2)
{
bool v2; // zf
__int64 result; // rax
_DWORD v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+18h] [rbp-10h]

v5 = a2;
v4[1] = 8;
sigemptyset((sigset_t *)v4);
sigaddset((sigset_t *)v4, signo);
v2 = (unsigned int)func6(signo) == -1;
result = -1LL;
if ( !v2 )
result = v6;
return result;
}

original_code:
void (*signal(int sig, void (*func)(int)))(int)
{
 struct sigaction act, oact;
 act.action.sa_handler = func;
 act.sa_flags = 8;
 sigemptyset(&act.sa_mask);
 sigaddset(&act.sa_mask, sig);
 if (sigaction(sig, &act, &oact) == -1)
  return(((sighandler_t) -1));
    return(oact.action.sa_handler);
}

canonical_original_code:
void (*signal(int sig, void (*func)(int)))(int)
{
 struct sigaction act; struct sigaction oact;
 act.action.sa_handler = func;
 act.sa_flags = 8;
 sigemptyset(&act.sa_mask);
 sigaddset(&act.sa_mask, sig);
 if (sigaction(sig, &act, &oact) == -1)
  return(((sighandler_t) -1));
    return(oact.action.sa_handler);
}

user_defined_types: union sigval { int sigval_int; void *sigval_ptr; }


kill

decompiled_code:
__int64 __fastcall kill(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v2 = syscall_kill_constprop_0(a1, a2, 2LL);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v2 = func3(a1, a2, 2LL);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int kill(pid_t pid, int sig)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(pid, sig, 2, ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int kill(int pid, int sig)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(pid, sig, 2, ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: pid int

variable_types: ret int


killpg

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

if ( a1 <= 1 )
result = kill(0LL, a2);
else
result = kill((unsigned int)-a1, a2);
return result;
}

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

if ( a1 <= 1 )
result = func9(0LL, a2);
else
result = func9((unsigned int)-a1, a2);
return result;
}

original_code:
int killpg(pid_t pgrp, int sig)
{
 if(pgrp > 1)
  return kill(-pgrp, sig);
 else
  return kill(0, sig);
}

canonical_original_code:
int killpg(int pgrp, int sig)
{
 if(pgrp > 1)
  return kill(-pgrp, sig);
 else
  return kill(0, sig);
}

variable_types: pgrp int


decompiled_code:
__int64 __fastcall pthread_kill(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v2 = syscall_kill_constprop_0(a1, a2, 1LL);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v2 = func3(a1, a2, 1LL);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int pthread_kill(pthread_t thread, int sig)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(thread, sig, 1, ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int pthread_kill(int thread, int sig)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(thread, sig, 1, ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: thread int


raise

decompiled_code:
__int64 __fastcall raise(unsigned int a1)
{
unsigned int v1; // eax

v1 = pthread_self();
return pthread_kill(v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
unsigned int v1; // eax

v1 = pthread_self();
return func11(v1, a1);
}

original_code:
int raise(int sig)
{
 return pthread_kill(pthread_self(), sig);
}


decompiled_code:
// attributes: thunk
__int64 pthread_sigmask()
{
return sigprocmask();
}

canonical_decompiled_code:
__int64 func14()
{
return func13();
}

original_code:
int pthread_sigmask(int how, const sigset_t *__restrict set,
       sigset_t *__restrict oset)
{
 return sigprocmask(how, set, oset);
}

canonical_original_code:
int pthread_sigmask(int how, int *set, int *oset)
{
 return sigprocmask(how, set, oset);
}

variable_types: how int

variable_types:
set
int *

variable_types:
oset
int *


siginterrupt

decompiled_code:
__int64 __fastcall siginterrupt(unsigned int a1)
{
sigaction(a1);
return sigaction(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
func6(a1);
return func6(a1);
}

original_code:
int siginterrupt(int sig, int flag)
{
 int ret;
 struct sigaction act;
 sigaction(sig, ((void *) 0), &act);
 if (flag)
  act.sa_flags &= ~2;
 else
  act.sa_flags |= 2;
 ret = sigaction(sig, &act, ((void *) 0));
 return ret;
}

variable_types: flag int


sigpending

decompiled_code:
__int64 __fastcall sigpending(__int64 a1)
{
if ( a1 )
return sigprocmask(1LL, 0LL, a1);
errno = 29;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
if ( a1 )
return func13(1LL, 0LL, a1);
errno = 29;
return 0xFFFFFFFFLL;
}

original_code:
int sigpending(sigset_t *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 return sigprocmask(1, ((void *) 0), set);
}

canonical_original_code:
int sigpending(int *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 return sigprocmask(1, ((void *) 0), set);
}


sigset

decompiled_code:
// attributes: thunk
__int64 __fastcall sigset(int signo, __int64 a2)
{
return signal(signo, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(int signo, __int64 a2)
{
return func8(signo, a2);
}

original_code:
void (*sigset(int sig, void (*disp)(int)))(int)
{
 return signal(sig, disp);
}

variable_types:
disp
void (*)(int)


sighold

decompiled_code:
int __fastcall sighold(int signo)
{
int result; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

sigemptyset((sigset_t *)v2);
result = sigaddset((sigset_t *)v2, signo);
if ( result != -1 )
result = sigprocmask(1LL, v2, 0LL);
return result;
}

canonical_decompiled_code:
int __fastcall func20(int signo)
{
int result; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

sigemptyset((sigset_t *)v2);
result = sigaddset((sigset_t *)v2, signo);
if ( result != -1 )
result = func13(1LL, v2, 0LL);
return result;
}

original_code:
int sighold(int sig)
{
 sigset_t set;
 sigemptyset(&set);
 if(sigaddset(&set, sig) == -1)
   return -1;
 return sigprocmask(1, &set, ((void *) 0));
}

canonical_original_code:
int sighold(int sig)
{
 int set;
 sigemptyset(&set);
 if(sigaddset(&set, sig) == -1)
   return -1;
 return sigprocmask(1, &set, ((void *) 0));
}

variable_types: set int


sigrelse

decompiled_code:
int __fastcall sigrelse(int signo)
{
int result; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

sigemptyset((sigset_t *)v2);
result = sigaddset((sigset_t *)v2, signo);
if ( result != -1 )
result = sigprocmask(2LL, v2, 0LL);
return result;
}

canonical_decompiled_code:
int __fastcall func21(int signo)
{
int result; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

sigemptyset((sigset_t *)v2);
result = sigaddset((sigset_t *)v2, signo);
if ( result != -1 )
result = func13(2LL, v2, 0LL);
return result;
}

original_code:
int sigrelse(int sig)
{
 sigset_t set;
 sigemptyset(&set);
 if(sigaddset(&set, sig) == -1)
  return -1;
 return sigprocmask(2, &set, ((void *) 0));
}

canonical_original_code:
int sigrelse(int sig)
{
 int set;
 sigemptyset(&set);
 if(sigaddset(&set, sig) == -1)
  return -1;
 return sigprocmask(2, &set, ((void *) 0));
}


sigignore

decompiled_code:
__int64 __fastcall sigignore(unsigned int a1)
{
return sigaction(a1);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1)
{
return func6(a1);
}

original_code:
int sigignore(int sig)
{
 struct sigaction act;
 act.action.sa_handler = ((sighandler_t) 1);
 return sigaction(sig, &act, ((void *) 0));
}

canonical_original_code:
int sigignore(int sig)
{
 struct sigaction act;
 act.action.sa_handler = ((void (*)(int)) 1);
 return sigaction(sig, &act, ((void *) 0));
}


sigpause

decompiled_code:
__int64 sigpause()
{
int v0; // er8
__int64 result; // rax
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)sigpending((__int64)&v2) == -1
|| (v3[0] = v2, sigaddset((sigset_t *)&v2, v0) == -1)
|| (unsigned int)sigsuspend(&v2) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = sigprocmask(3LL, v3, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func23()
{
int v0; // er8
__int64 result; // rax
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func17((__int64)&v2) == -1
|| (v3[0] = v2, sigaddset((sigset_t *)&v2, v0) == -1)
|| (unsigned int)func18(&v2) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = func13(3LL, v3, 0LL);
}
return result;
}

original_code:
int sigpause(int sig)
{
 sigset_t set, oset;
 if(sigpending(&set) == -1)
  return -1;
 oset = set;
 if(sigaddset(&set, sig) == -1)
  return -1;
 if(sigsuspend(&set) == -1)
  return -1;
 return sigprocmask(3, &oset, ((void *) 0));
}

canonical_original_code:
int sigpause(int sig)
{
 int set; int oset;
 if(sigpending(&set) == -1)
  return -1;
 oset = set;
 if(sigaddset(&set, sig) == -1)
  return -1;
 if(sigsuspend(&set) == -1)
  return -1;
 return sigprocmask(3, &oset, ((void *) 0));
}

variable_types: oset int


sigwait

decompiled_code:
__int64 __fastcall sigwait(unsigned int *a1, _DWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
result = syscall_signal_wait_constprop_0_isra_0(*a1);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
else
{
*a2 = result;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(unsigned int *a1, _DWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
result = func4(*a1);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
else
{
*a2 = result;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sigwait(const sigset_t *__restrict set, int *__restrict sig)
{
 int ret;
 if(set == ((void *) 0))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_signal_wait(set, ((void *) 0), ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 *sig = ret;
 return ret;
}

canonical_original_code:
int sigwait(int *set, int *sig)
{
 int ret;
 if(set == ((void *) 0))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_signal_wait(set, ((void *) 0), ((void *) 0));
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 *sig = ret;
 return ret;
}

variable_types:
sig
int *


sigaction

decompiled_code:
__int64 __fastcall sigaction(unsigned int a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v1 = syscall_signal_action();
if ( v1 < 0 )
{
errno = -v1;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v1 = func0();
if ( v1 < 0 )
{
errno = -v1;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int sigaction(int sig, const struct sigaction *__restrict act,
       struct sigaction *__restrict oact)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_signal_action(sig, act, oact);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sigaction(int sig, struct sigaction *act, struct sigaction *oact)
{
 int ret;
 if((sig < 0) || (sig > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_signal_action(sig, act, oact);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; long si_band; union sigval { int sigval_int; void *sigval_ptr; } si_value; }, void *); } action; } *

variable_types:
oact
struct sigaction *


sigprocmask

decompiled_code:
__int64 sigprocmask()
{
int v0; // eax

v0 = syscall_sig_mask();
if ( v0 >= 0 )
return 0LL;
errno = -v0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // eax

v0 = func1();
if ( v0 >= 0 )
return 0LL;
errno = -v0;
return 0xFFFFFFFFLL;
}

original_code:
int sigprocmask(int how, const sigset_t *__restrict set,
       sigset_t *__restrict oset)
{
 int ret;
 ret = syscall_sig_mask(how, set, oset);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sigprocmask(int how, int *set, int *oset)
{
 int ret;
 ret = syscall_sig_mask(how, set, oset);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}


sigaltstack

decompiled_code:
__int64 sigaltstack()
{
int v0; // eax

v0 = syscall_signal_stack();
if ( v0 >= 0 )
return 0LL;
errno = -v0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // eax

v0 = func2();
if ( v0 >= 0 )
return 0LL;
errno = -v0;
return 0xFFFFFFFFLL;
}

original_code:
int sigaltstack(const stack_t *__restrict ss, stack_t *__restrict oss)
{
 int ret;
 ret = syscall_signal_stack(ss, oss);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sigaltstack(struct stack *ss, struct stack *oss)
{
 int ret;
 ret = syscall_signal_stack(ss, oss);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: struct stack { void *ss_sp; unsigned int ss_size; int ss_flags; } *

variable_types:
oss
struct stack *


sigsuspend

decompiled_code:
__int64 __fastcall sigsuspend(unsigned int *a1)
{
int v1; // eax

v1 = syscall_signal_suspend_isra_0(*a1);
if ( v1 >= 0 )
return 0LL;
errno = -v1;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int *a1)
{
int v1; // eax

v1 = func5(*a1);
if ( v1 >= 0 )
return 0LL;
errno = -v1;
return 0xFFFFFFFFLL;
}

original_code:
int sigsuspend(const sigset_t *sigmask)
{
 int ret;
 ret = syscall_signal_suspend(sigmask);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sigsuspend(int *sigmask)
{
 int ret;
 ret = syscall_signal_suspend(sigmask);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types:
sigmask
int *


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

result = 58LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

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

result = 58LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

original_code:
static inline int syscall_timer_gettime(timer_t timerid, struct itimerspec *value)
{
 register int ret;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(ret)
  :"0"(58),"b"(timerid),"c"(value)
  );
 return ret;
}

canonical_original_code:
static inline int syscall_timer_gettime(int timerid, struct itimerspec *value)
{
 register int ret;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(ret)
  :"0"(58),"b"(timerid),"c"(value)
  );
 return ret;
}

variable_types: timerid int

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } *

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


clock

decompiled_code:
__int64 clock()
{
return (int)syscall_clock_constprop_0();
}

canonical_decompiled_code:
__int64 func8()
{
return (int)func3();
}

original_code:
clock_t clock()
{
 return syscall_clock(((void *) 0));
}

canonical_original_code:
long clock()
{
 return syscall_clock(((void *) 0));
}


decompiled_code:
__int64 __fastcall clock_getres(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v2 = syscall_getresolution_constprop_0(a2);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v2 = func5(a2);
if ( v2 < 0 )
{
errno = -v2;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int clock_getres(clockid_t clock, struct timespec *res)
 {
 int ret;
 if(clock != 1)
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_getresolution(clock, res);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int clock_getres(unsigned long clock, struct timespec *res)
 {
 int ret;
 if(clock != 1)
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_getresolution(clock, res);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types:
clock
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall clock_gettime(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v4 = syscall_gettime_constprop_0(a2, (__int64)a2, a3, a4);
if ( v4 < 0 )
{
errno = -v4;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v4 = func2(a2, (__int64)a2, a3, a4);
if ( v4 < 0 )
{
errno = -v4;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int clock_gettime(clockid_t clock_id, struct timespec *tp)
{
 int ret;
 if(clock_id != 1)
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_gettime(clock_id, tp);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int clock_gettime(unsigned long clock_id, struct timespec *tp)
{
 int ret;
 if(clock_id != 1)
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_gettime(clock_id, tp);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }