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

if ( *(_BYTE *)a2 == 1 )
{
result = sp_vnewh(a1, *(_QWORD *)(a2 + 1));
}
else
{
result = 0LL;
if ( *(_BYTE *)a2 != 2 )
return result;
result = (__int64)sp_vdup(a1, *(unsigned __int16 **)(a2 + 1));
}
if ( result )
{
*(_DWORD *)result = a3;
*(_BYTE *)(result + 10) = 0;
}
return result;
}

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

if ( *(_BYTE *)a2 == 1 )
{
result = func13(a1, *(_QWORD *)(a2 + 1));
}
else
{
result = 0LL;
if ( *(_BYTE *)a2 != 2 )
return result;
result = (__int64)func14(a1, *(unsigned __int16 **)(a2 + 1));
}
if ( result )
{
*(_DWORD *)result = a3;
*(_BYTE *)(result + 10) = 0;
}
return result;
}

original_code:
spv *sp_vdupref(sp *s, spref *r, uint32_t epoch)
{
 spv *vn = ((void *)0);
 switch (r->type) {
 case 2: vn = sp_vdup(s, r->v.v);
  break;
 case 1: vn = sp_vnewh(s, r->v.vh);
  break;
 }
 if (__builtin_expect(!! (vn == ((void *)0)), 0))
  return ((void *)0);
 vn->epoch = epoch;
 vn->flags = 0;
 return vn;
}

canonical_original_code:
struct spv *sp_vdupref(struct sp *s, struct spref *r, unsigned int epoch)
{
 struct spv *vn = ((void *)0);
 switch (r->type) {
 case 2: vn = sp_vdup(s, r->v.v);
  break;
 case 1: vn = sp_vnewh(s, r->v.vh);
  break;
 }
 if (__builtin_expect(!! (vn == ((void *)0)), 0))
  return ((void *)0);
 vn->epoch = epoch;
 vn->flags = 0;
 return vn;
}

variable_types:
r
struct spref *

variable_types:
epoch
unsigned int

user_defined_types: struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; }

user_defined_types: struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; }

user_defined_types: struct spi { struct spa *a; int pagesize; struct spipage **i; unsigned int itop; unsigned int icount; unsigned int count; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct spref { unsigned char type; union { struct spvh *vh; struct spv *v; } v; }


repo: Peaker/bindings-sophia

decompiled_code:
__int64 __fastcall sp_filesvp(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = result;
return result;
}

original_code:
static inline void
sp_filesvp(spfile *f) {
 f->svp = f->used;
}

canonical_original_code:
static inline void sp_filesvp(struct spfile *f) {
 f->svp = f->used;
}

variable_types: struct spfile { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } *

return_type: void

user_defined_types: struct spfile { struct spa *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; }


decompiled_code:
__off_t __fastcall sp_mapsizeof(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == -1;
result = -1LL;
if ( !v1 )
result = v3.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func1(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == -1;
result = -1LL;
if ( !v1 )
result = v3.st_size;
return result;
}

original_code:
static inline ssize_t
sp_mapsizeof(char *path) {
 struct stat st;
 int rc = lstat(path, &st);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return st.st_size;
}

canonical_original_code:
static inline long sp_mapsizeof(char *path) {
 struct stat st;
 int rc = lstat(path, &st);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return st.st_size;
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: rc int

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int __fastcall sp_mapresize(__int64 a1, __off_t a2)
{
int result; // eax

result = ftruncate(*(_DWORD *)(a1 + 48), a2);
if ( result != -1 )
{
*(_QWORD *)(a1 + 24) = a2;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __off_t a2)
{
int result; // eax

result = ftruncate(*(_DWORD *)(a1 + 48), a2);
if ( result != -1 )
{
*(_QWORD *)(a1 + 24) = a2;
result = 0;
}
return result;
}

original_code:
static inline int
sp_mapresize(spfile *f, size_t size) {
 int rc = ftruncate(f->fd, size);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 f->size = size;
 return 0;
}

canonical_original_code:
static inline int sp_mapresize(struct spfile *f, unsigned long size) {
 int rc = ftruncate(f->fd, size);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 f->size = size;
 return 0;
}

variable_types:
size
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall sp_map(__int64 a1, int a2)
{
void *v2; // rax

v2 = mmap(0LL, *(_QWORD *)(a1 + 24), a2, 1, *(_DWORD *)(a1 + 48), 0LL);
if ( v2 == (void *)-1LL )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 56) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
void *v2; // rax

v2 = mmap(0LL, *(_QWORD *)(a1 + 24), a2, 1, *(_DWORD *)(a1 + 48), 0LL);
if ( v2 == (void *)-1LL )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 56) = v2;
return 0LL;
}

original_code:
static inline int
sp_map(spfile *f, int flags) {
 void *p = mmap(((void *)0), f->size, flags, 0x01, f->fd, 0);
 if (p == ((void *) -1))
  return -1;
 f->map = p;
 return 0;
}

canonical_original_code:
static inline int sp_map(struct spfile *f, int flags) {
 void *p = mmap(((void *)0), f->size, flags, 0x01, f->fd, 0);
 if (p == ((void *) -1))
  return -1;
 f->map = p;
 return 0;
}

variable_types: flags int

variable_types:
p
void *


decompiled_code:
int __fastcall sp_unmap(__int64 a1)
{
void *v2; // rdi
int result; // eax

v2 = *(void **)(a1 + 56);
result = 0;
if ( v2 )
{
result = munmap(v2, *(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 56) = 0LL;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
void *v2; // rdi
int result; // eax

v2 = *(void **)(a1 + 56);
result = 0;
if ( v2 )
{
result = munmap(v2, *(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 56) = 0LL;
}
return result;
}

original_code:
static inline int
sp_unmap(spfile *f) {
 int rc;
 if (f->map) {
  rc = munmap(f->map, f->size);
  f->map = ((void *)0);
  return rc;
 }
 return 0;
}

canonical_original_code:
static inline int sp_unmap(struct spfile *f) {
 int rc;
 if (f->map) {
  rc = munmap(f->map, f->size);
  f->map = ((void *)0);
  return rc;
 }
 return 0;
}


decompiled_code:
int __fastcall sp_logsync(__int64 a1)
{
int result; // eax

if ( *(_DWORD *)(a1 + 8) )
result = fsync(*(_DWORD *)(a1 + 48));
else
result = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax

if ( *(_DWORD *)(a1 + 8) )
result = fsync(*(_DWORD *)(a1 + 48));
else
result = 0;
return result;
}

original_code:
static inline int
sp_logsync(spfile *f) {
 return (f->creat ? fsync(f->fd) : 0);
}

canonical_original_code:
static inline int sp_logsync(struct spfile *f) {
 return (f->creat ? fsync(f->fd) : 0);
}


decompiled_code:
__int64 __fastcall sp_mapcut(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( sp_mapsync_isra_0(*(_QWORD *)(a1 + 24), *(void **)(a1 + 56)) == -1 || sp_unmap(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(sp_mapresize(a1, *(_QWORD *)(a1 + 16)) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( func6(*(_QWORD *)(a1 + 24), *(void **)(a1 + 56)) == -1 || func4(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(func2(a1, *(_QWORD *)(a1 + 16)) == -1);
}
return result;
}

original_code:
static inline int
sp_mapcut(spfile *f)
{
 if (f->creat == 0)
  return 0;
 int rc = sp_mapsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_unmap(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_mapresize(f, f->used);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}

canonical_original_code:
static inline int sp_mapcut(struct spfile *f)
{
 if (f->creat == 0)
  return 0;
 int rc = sp_mapsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_unmap(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_mapresize(f, f->used);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}


decompiled_code:
int __fastcall sp_fileclose(__int64 a1)
{
__int64 v1; // rdx
int v3; // edi
int result; // eax

v1 = *(_QWORD *)(a1 + 40);
if ( v1 )
{
sp_free_isra_0(**(__int64 (__fastcall ***)(__int64, _QWORD, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), v1);
*(_QWORD *)(a1 + 40) = 0LL;
}
v3 = *(_DWORD *)(a1 + 48);
result = 0;
if ( v3 != -1 )
{
result = close(v3);
if ( result != -1 )
{
*(_DWORD *)(a1 + 48) = -1;
result = 0;
}
}
return result;
}

original_code:
static inline int
sp_fileclose(spfile *f)
{
 if (__builtin_expect(!! (f->file), 1)) {
  sp_free(f->a, f->file);
  f->file = ((void *)0);
 }
 int rc;
 if (__builtin_expect(!! (f->fd != -1), 0)) {
  rc = close(f->fd);
  if (__builtin_expect(!! (rc == -1), 0))
   return -1;
  f->fd = -1;
 }
 return 0;
}

canonical_original_code:
static inline int sp_fileclose(struct spfile *f)
{
 if (__builtin_expect(!! (f->file), 1)) {
  sp_free(f->a, f->file);
  f->file = ((void *)0);
 }
 int rc;
 if (__builtin_expect(!! (f->fd != -1), 0)) {
  rc = close(f->fd);
  if (__builtin_expect(!! (rc == -1), 0))
   return -1;
  f->fd = -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall sp_filecomplete(__int64 a1)
{
char *v1; // rax
void *v2; // r12
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

*(_DWORD *)(a1 + 8) = 0;
snprintf(v4, 0x400uLL, "%s", *(const char **)(a1 + 40));
v1 = strstr(v4, ".incomplete");
if ( !v1 )
return 0LL;
*v1 = 0;
if ( rename(*(const char **)(a1 + 40), v4) == -1 )
return 0xFFFFFFFFLL;
v2 = sp_strdup_isra_0(**(__int64 (__fastcall ***)(_QWORD, size_t, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), v4);
if ( !v2 )
return 0xFFFFFFFFLL;
sp_free_isra_0(
**(__int64 (__fastcall ***)(__int64, _QWORD, __int64))a1,
*(_QWORD *)(*(_QWORD *)a1 + 8LL),
*(_QWORD *)(a1 + 40));
*(_QWORD *)(a1 + 40) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
char *v1; // rax
void *v2; // r12
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

*(_DWORD *)(a1 + 8) = 0;
snprintf(v4, 0x400uLL, "%s", *(const char **)(a1 + 40));
v1 = strstr(v4, ".incomplete");
if ( !v1 )
return 0LL;
*v1 = 0;
if ( rename(*(const char **)(a1 + 40), v4) == -1 )
return 0xFFFFFFFFLL;
v2 = func10(**(__int64 (__fastcall ***)(_QWORD, size_t, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), v4);
if ( !v2 )
return 0xFFFFFFFFLL;
func8(
**(__int64 (__fastcall ***)(__int64, _QWORD, __int64))a1,
*(_QWORD *)(*(_QWORD *)a1 + 8LL),
*(_QWORD *)(a1 + 40));
*(_QWORD *)(a1 + 40) = v2;
return 0LL;
}

original_code:
static inline int
sp_filecomplete(spfile *f)
{
 f->creat = 0;
 char path[1024];
 snprintf(path, sizeof(path), "%s", f->file);
 char *ext = strstr(path, ".incomplete");
 if (__builtin_expect(!! (ext == ((void *)0)), 0))
  return 0;
 *ext = 0;
 int rc = rename(f->file, path);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 char *p = sp_strdup(f->a, path);
 if (__builtin_expect(!! (p == ((void *)0)), 0))
  return -1;
 sp_free(f->a, f->file);
 f->file = p;
 return 0;
}

canonical_original_code:
static inline int sp_filecomplete(struct spfile *f)
{
 f->creat = 0;
 char path[1024];
 snprintf(path, sizeof(path), "%s", f->file);
 char *ext = strstr(path, ".incomplete");
 if (__builtin_expect(!! (ext == ((void *)0)), 0))
  return 0;
 *ext = 0;
 int rc = rename(f->file, path);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 char *p = sp_strdup(f->a, path);
 if (__builtin_expect(!! (p == ((void *)0)), 0))
  return -1;
 sp_free(f->a, f->file);
 f->file = p;
 return 0;
}

variable_types:
path
char [1024]

variable_types:
ext
char *

variable_types:
p
char *


original_code:
static inline int
sp_mapopenof(spfile *f, char *path, int flags, uint64_t size)
{
 f->fd = open(path, flags, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 f->used = 0;
 f->creat = (flags & 0100 ? 1 : 0);
 int rc;
 if (! f->creat) {
  ssize_t sz = sp_mapsizeof(path);
  if (__builtin_expect(!! (sz == -1), 0))
   goto err;
  f->size = sz;
  rc = sp_map(f, 0x1);
  if (__builtin_expect(!! (rc == -1), 0))
   goto err;
  return 0;
 }
 f->size = 0;
 rc = sp_mapresize(f, size);
 if (__builtin_expect(!! (rc == -1), 0))
  goto err;
 rc = sp_map(f, 0x1|0x2);
 if (__builtin_expect(!! (rc == -1), 0))
  goto err;
 return 0;
err:
 close(f->fd);
 f->fd = -1;
 sp_free(f->a, f->file);
 f->file = ((void *)0);
 return -1;
}

canonical_original_code:
static inline int sp_mapopenof(struct spfile *f, char *path, int flags, unsigned long size)
{
 f->fd = open(path, flags, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 f->used = 0;
 f->creat = (flags & 0100 ? 1 : 0);
 int rc;
 if (! f->creat) {
  long sz = sp_mapsizeof(path);
  if (__builtin_expect(!! (sz == -1), 0))
   goto err;
  f->size = sz;
  rc = sp_map(f, 0x1);
  if (__builtin_expect(!! (rc == -1), 0))
   goto err;
  return 0;
 }
 f->size = 0;
 rc = sp_mapresize(f, size);
 if (__builtin_expect(!! (rc == -1), 0))
  goto err;
 rc = sp_map(f, 0x1|0x2);
 if (__builtin_expect(!! (rc == -1), 0))
  goto err;
 return 0;
err:
 close(f->fd);
 f->fd = -1;
 sp_free(f->a, f->file);
 f->file = ((void *)0);
 return -1;
}

variable_types: sz long


decompiled_code:
int __fastcall sp_logopenof(__int64 a1, const char *a2, int a3)
{
int result; // eax
void *v4; // rax

*(_DWORD *)(a1 + 8) = 1;
result = open(a2, a3, 384LL);
*(_DWORD *)(a1 + 48) = result;
if ( result != -1 )
{
v4 = sp_strdup_isra_0(**(__int64 (__fastcall ***)(_QWORD, size_t, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), a2);
*(_QWORD *)(a1 + 40) = v4;
if ( v4 )
{
*(_QWORD *)(a1 + 24) = 0LL;
result = 0;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, const char *a2, int a3)
{
int result; // eax
void *v4; // rax

*(_DWORD *)(a1 + 8) = 1;
result = open(a2, a3, 384LL);
*(_DWORD *)(a1 + 48) = result;
if ( result != -1 )
{
v4 = func10(**(__int64 (__fastcall ***)(_QWORD, size_t, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), a2);
*(_QWORD *)(a1 + 40) = v4;
if ( v4 )
{
*(_QWORD *)(a1 + 24) = 0LL;
result = 0;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
result = -1;
}
}
return result;
}

original_code:
static inline int
sp_logopenof(spfile *f, char *path, int flags)
{
 f->creat = 1;
 f->fd = open(path, flags, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 f->size = 0;
 f->used = 0;
 return 0;
}

canonical_original_code:
static inline int sp_logopenof(struct spfile *f, char *path, int flags)
{
 f->creat = 1;
 f->fd = open(path, flags, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 f->size = 0;
 f->used = 0;
 return 0;
}


decompiled_code:
_BOOL8 __fastcall sp_fileexists(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return lstat(a1, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return lstat(a1, &v2) == 0;
}

original_code:
int sp_fileexists(char *path) {
 struct stat st;
 int rc = lstat(path, &st);
 return rc == 0;
}

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


decompiled_code:
// attributes: thunk
int sp_filerm(const char *name)
{
return unlink(name);
}

canonical_decompiled_code:
int func15(const char *name)
{
return unlink(name);
}

original_code:
int sp_filerm(char *path) {
 return unlink(path);
}


decompiled_code:
int __fastcall sp_mapopen(__int64 a1, const char *a2)
{
return sp_mapopenof(a1, a2, 0, 0LL);
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, const char *a2)
{
return func12(a1, a2, 0, 0LL);
}

original_code:
int sp_mapopen(spfile *f, char *path) {
 return sp_mapopenof(f, path, 00, 0);
}

canonical_original_code:
int sp_mapopen(struct spfile *f, char *path) {
 return sp_mapopenof(f, path, 00, 0);
}


decompiled_code:
int __fastcall sp_mapnew(__int64 a1, const char *a2, __off_t a3)
{
return sp_mapopenof(a1, a2, 66, a3);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, const char *a2, __off_t a3)
{
return func12(a1, a2, 66, a3);
}

original_code:
int sp_mapnew(spfile *f, char *path, uint64_t size) {
 return sp_mapopenof(f, path, 02|0100, size);
}

canonical_original_code:
int sp_mapnew(struct spfile *f, char *path, unsigned long size) {
 return sp_mapopenof(f, path, 02|0100, size);
}


decompiled_code:
int __fastcall sp_mapunlink(__int64 a1)
{
return sp_filerm(*(const char **)(a1 + 40));
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
return func15(*(const char **)(a1 + 40));
}

original_code:
int sp_mapunlink(spfile *f) {
 return sp_filerm(f->file);
}

canonical_original_code:
int sp_mapunlink(struct spfile *f) {
 return sp_filerm(f->file);
}


decompiled_code:
// attributes: thunk
int __fastcall sp_mapunmap(__int64 a1)
{
return sp_unmap(a1);
}

canonical_decompiled_code:
int __fastcall func19(__int64 a1)
{
return func4(a1);
}

original_code:
int sp_mapunmap(spfile *f) {
 return sp_unmap(f);
}

canonical_original_code:
int sp_mapunmap(struct spfile *f) {
 return sp_unmap(f);
}


decompiled_code:
int __fastcall sp_mapclose(__int64 a1)
{
int result; // eax

if ( (unsigned int)sp_mapcut(a1) == -1 || *(_QWORD *)(a1 + 56) && sp_unmap(a1) == -1 )
result = -1;
else
result = sp_fileclose(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1)
{
int result; // eax

if ( (unsigned int)func7(a1) == -1 || *(_QWORD *)(a1 + 56) && func4(a1) == -1 )
result = -1;
else
result = func9(a1);
return result;
}

original_code:
int sp_mapclose(spfile *f)
{
 int rc = sp_mapcut(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 if (f->map) {
  rc = sp_unmap(f);
  if (__builtin_expect(!! (rc == -1), 0))
   return -1;
 }
 return sp_fileclose(f);
}

canonical_original_code:
int sp_mapclose(struct spfile *f)
{
 int rc = sp_mapcut(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 if (f->map) {
  rc = sp_unmap(f);
  if (__builtin_expect(!! (rc == -1), 0))
   return -1;
 }
 return sp_fileclose(f);
}


decompiled_code:
__int64 __fastcall sp_mapcomplete(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( (unsigned int)sp_mapcut(a1) == -1 || (unsigned int)sp_filecomplete(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = sp_map(a1, 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( (unsigned int)func7(a1) == -1 || (unsigned int)func11(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = func3(a1, 1);
}
return result;
}

original_code:
int sp_mapcomplete(spfile *f)
{
 if (f->creat == 0)
  return 0;
 int rc = sp_mapcut(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_filecomplete(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_map(f, 0x1);
}

canonical_original_code:
int sp_mapcomplete(struct spfile *f)
{
 if (f->creat == 0)
  return 0;
 int rc = sp_mapcut(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 rc = sp_filecomplete(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_map(f, 0x1);
}


original_code:
int sp_mapensure(spfile *f, uint64_t size, float grow)
{
 if (__builtin_expect(!! ((f->used + size) <= f->size), 1))
  return 0;
 int rc = sp_unmap(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 uint64_t nsz = f->used + f->size * grow;
 if (__builtin_expect(!! (nsz < size), 0))
  nsz = f->used + size;
 ((void) (0));
 rc = sp_mapresize(f, nsz);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_map(f, 0x1|0x2);
}

canonical_original_code:
int sp_mapensure(struct spfile *f, unsigned long size, float grow)
{
 if (__builtin_expect(!! ((f->used + size) <= f->size), 1))
  return 0;
 int rc = sp_unmap(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 unsigned long nsz = f->used + f->size * grow;
 if (__builtin_expect(!! (nsz < size), 0))
  nsz = f->used + size;
 ((void) (0));
 rc = sp_mapresize(f, nsz);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_map(f, 0x1|0x2);
}

variable_types: grow float

variable_types:
nsz
unsigned long


decompiled_code:
__int64 __fastcall sp_lognew(__int64 a1, const char *a2, unsigned int a3)
{
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%u.log.incomplete", a2, a3);
return (unsigned int)-(sp_logopenof(a1, v4, 1089) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, const char *a2, unsigned int a3)
{
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%u.log.incomplete", a2, a3);
return (unsigned int)-(func13(a1, v4, 1089) == -1);
}

original_code:
int sp_lognew(spfile *f, char *dir, uint32_t epoch)
{
 char path[1024];
 snprintf(path, sizeof(path), "%s/%""u"".log.incomplete",
          dir, epoch);
 int rc = sp_logopenof(f, path, 01|02000|0100);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}

canonical_original_code:
int sp_lognew(struct spfile *f, char *dir, unsigned int epoch)
{
 char path[1024];
 snprintf(path, sizeof(path), "%s/%""u"".log.incomplete",
          dir, epoch);
 int rc = sp_logopenof(f, path, 01|02000|0100);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}

variable_types:
dir
char *


decompiled_code:
__int64 __fastcall sp_logcontinue(__int64 a1, const char *a2, unsigned int a3)
{
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%u.log.incomplete", a2, a3);
return (unsigned int)-(sp_logopenof(a1, v4, 1025) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, const char *a2, unsigned int a3)
{
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%u.log.incomplete", a2, a3);
return (unsigned int)-(func13(a1, v4, 1025) == -1);
}

original_code:
int sp_logcontinue(spfile *f, char *dir, uint32_t epoch) {
 char path[1024];
 snprintf(path, sizeof(path), "%s/%""u"".log.incomplete",
          dir, epoch);
 int rc = sp_logopenof(f, path, 01|02000);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}

canonical_original_code:
int sp_logcontinue(struct spfile *f, char *dir, unsigned int epoch) {
 char path[1024];
 snprintf(path, sizeof(path), "%s/%""u"".log.incomplete",
          dir, epoch);
 int rc = sp_logopenof(f, path, 01|02000);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return 0;
}


decompiled_code:
// attributes: thunk
int __fastcall sp_logclose(__int64 a1)
{
return sp_fileclose(a1);
}

canonical_decompiled_code:
int __fastcall func25(__int64 a1)
{
return func9(a1);
}

original_code:
int sp_logclose(spfile *f) {
 return sp_fileclose(f);
}

canonical_original_code:
int sp_logclose(struct spfile *f) {
 return sp_fileclose(f);
}


decompiled_code:
__int64 __fastcall sp_logcomplete(__int64 a1)
{
__int64 result; // rax

if ( sp_logsync(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = sp_filecomplete(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
__int64 result; // rax

if ( func5(a1) == -1 )
result = 0xFFFFFFFFLL;
else
result = func11(a1);
return result;
}

original_code:
int sp_logcomplete(spfile *f)
{
 int rc = sp_logsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_filecomplete(f);
}

canonical_original_code:
int sp_logcomplete(struct spfile *f)
{
 int rc = sp_logsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 return sp_filecomplete(f);
}


decompiled_code:
int __fastcall sp_logcompleteforce(__int64 a1)
{
int result; // eax
int v2; // ebp

result = sp_logsync(a1);
if ( result != -1 )
{
v2 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 1;
result = sp_filecomplete(a1);
*(_DWORD *)(a1 + 8) = v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func27(__int64 a1)
{
int result; // eax
int v2; // ebp

result = func5(a1);
if ( result != -1 )
{
v2 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 1;
result = func11(a1);
*(_DWORD *)(a1 + 8) = v2;
}
return result;
}

original_code:
int sp_logcompleteforce(spfile *f) {
 int rc = sp_logsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 int oldcreat = f->creat;
 f->creat = 1;
 rc = sp_filecomplete(f);
 f->creat = oldcreat;
 return rc;
}

canonical_original_code:
int sp_logcompleteforce(struct spfile *f) {
 int rc = sp_logsync(f);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 int oldcreat = f->creat;
 f->creat = 1;
 rc = sp_filecomplete(f);
 f->creat = oldcreat;
 return rc;
}

variable_types: oldcreat int


decompiled_code:
// attributes: thunk
int __fastcall sp_logunlink(__int64 a1)
{
return sp_mapunlink(a1);
}

canonical_decompiled_code:
int __fastcall func28(__int64 a1)
{
return func18(a1);
}

original_code:
int sp_logunlink(spfile *f) {
 return sp_filerm(f->file);
}

canonical_original_code:
int sp_logunlink(struct spfile *f) {
 return sp_filerm(f->file);
}


decompiled_code:
__int64 __fastcall sp_logwrite(__int64 a1, char *a2, __int64 a3)
{
__int64 v3; // r14
char *i; // rbp
ssize_t v6; // rax

v3 = 0LL;
for ( i = a2; ; i = &a2[v3] )
{
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 48), i, a3 - v3);
if ( v6 != -1 )
break;
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
if ( v6 <= 0 )
return 0xFFFFFFFFLL;
v3 += v6;
if ( a3 == v3 )
break;
}
*(_QWORD *)(a1 + 16) += a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1, char *a2, __int64 a3)
{
__int64 v3; // r14
char *i; // rbp
ssize_t v6; // rax

v3 = 0LL;
for ( i = a2; ; i = &a2[v3] )
{
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 48), i, a3 - v3);
if ( v6 != -1 )
break;
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
if ( v6 <= 0 )
return 0xFFFFFFFFLL;
v3 += v6;
if ( a3 == v3 )
break;
}
*(_QWORD *)(a1 + 16) += a3;
return 0LL;
}

original_code:
int sp_logwrite(spfile *f, void *buf, size_t size)
{
 size_t n = 0;
 do {
  ssize_t r;
  do {
   r = write(f->fd, (char*)buf + n, size - n);
  } while (r == -1 && (*__errno_location ()) == 4);
  if (r <= 0)
   return -1;
  n += r;
 } while (n != size);
 f->used += size;
 return 0;
}

canonical_original_code:
int sp_logwrite(struct spfile *f, void *buf, unsigned long size)
{
 unsigned long n = 0;
 do {
  long r;
  do {
   r = write(f->fd, (char *)buf + n, size - n);
  } while (r == -1 && (*__errno_location ()) == 4);
  if (r <= 0)
   return -1;
  n += r;
 } while (n != size);
 f->used += size;
 return 0;
}

variable_types:
buf
void *

variable_types:
n
unsigned long

variable_types: r long


decompiled_code:
__int64 __fastcall sp_logput(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // ebp
const struct iovec *v4; // rbx
int v5; // eax
int v6; // edx
unsigned __int64 v7; // rax
__int64 result; // rax

v2 = 0LL;
v3 = *(_DWORD *)(a2 + 0x4000);
v4 = (const struct iovec *)a2;
do
{
while ( 1 )
{
v5 = writev(*(_DWORD *)(a1 + 48), v4, v3);
v6 = v5;
if ( v5 == -1 )
break;
if ( v5 < 0 )
goto LABEL_11;
v2 += v5;
if ( v3 <= 0 )
{
LABEL_9:
*(_QWORD *)(a1 + 16) += v2;
result = 0LL;
*(_DWORD *)(a2 + 0x4000) = 0;
return result;
}
while ( 1 )
{
v7 = v4->iov_len;
if ( v7 > v6 )
break;
v6 -= v7;
++v4;
if ( !--v3 )
goto LABEL_9;
}
v4->iov_base = (char *)v4->iov_base + v6;
v4->iov_len = v7 - v6;
}
}
while ( *_errno_location() == 4 );
LABEL_11:
result = 0xFFFFFFFFLL;
*(_DWORD *)(a2 + 0x4000) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // ebp
const struct iovec *v4; // rbx
int v5; // eax
int v6; // edx
unsigned __int64 v7; // rax
__int64 result; // rax

v2 = 0LL;
v3 = *(_DWORD *)(a2 + 0x4000);
v4 = (const struct iovec *)a2;
do
{
while ( 1 )
{
v5 = writev(*(_DWORD *)(a1 + 48), v4, v3);
v6 = v5;
if ( v5 == -1 )
break;
if ( v5 < 0 )
goto LABEL_11;
v2 += v5;
if ( v3 <= 0 )
{
LABEL_9:
*(_QWORD *)(a1 + 16) += v2;
result = 0LL;
*(_DWORD *)(a2 + 0x4000) = 0;
return result;
}
while ( 1 )
{
v7 = v4->iov_len;
if ( v7 > v6 )
break;
v6 -= v7;
++v4;
if ( !--v3 )
goto LABEL_9;
}
v4->iov_base = (char *)v4->iov_base + v6;
v4->iov_len = v7 - v6;
}
}
while ( *_errno_location() == 4 );
LABEL_11:
result = 0xFFFFFFFFLL;
*(_DWORD *)(a2 + 0x4000) = 0;
return result;
}

original_code:
int sp_logput(spfile *f, spbatch *b)
{
 register struct iovec *v = b->iov;
 register uint64_t size = 0;
 register int n = b->iovc;
 do {
  int r;
  do {
   r = writev(f->fd, v, n);
  } while (r == -1 && (*__errno_location ()) == 4);
  if (r < 0) {
   b->iovc = 0;
   return -1;
  }
  size += r;
  while (n > 0) {
   if (v->iov_len > (size_t)r) {
    v->iov_base = (char*)v->iov_base + r;
    v->iov_len -= r;
    break;
   } else {
    r -= v->iov_len;
    v++;
    n--;
   }
  }
 } while (n > 0);
 f->used += size;
 b->iovc = 0;
 return 0;
}

canonical_original_code:
int sp_logput(struct spfile *f, struct spbatch *b)
{
 register struct iovec *v = b->iov;
 register unsigned long size = 0;
 register int n = b->iovc;
 do {
  int r;
  do {
   r = writev(f->fd, v, n);
  } while (r == -1 && (*__errno_location ()) == 4);
  if (r < 0) {
   b->iovc = 0;
   return -1;
  }
  size += r;
  while (n > 0) {
   if (v->iov_len > (unsigned long)r) {
    v->iov_base = (char *)v->iov_base + r;
    v->iov_len -= r;
    break;
   } else {
    r -= v->iov_len;
    v++;
    n--;
   }
  }
 } while (n > 0);
 f->used += size;
 b->iovc = 0;
 return 0;
}

variable_types: struct spfile { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } *

variable_types: struct spbatch { struct iovec { void *iov_base; unsigned long iov_len; } iov[1024]; int iovc; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types: n int

variable_types: r int

user_defined_types: struct spbatch { struct iovec iov[1024]; int iovc; }


decompiled_code:
int __fastcall sp_logrlb(__int64 a1)
{
int result; // eax
__off_t v3; // rsi
int v4; // edi

result = ftruncate(*(_DWORD *)(a1 + 48), *(_QWORD *)(a1 + 32));
if ( result != -1 )
{
v3 = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 32) = 0LL;
v4 = *(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 16) = v3;
result = lseek(v4, v3, 0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func31(__int64 a1)
{
int result; // eax
__off_t v3; // rsi
int v4; // edi

result = ftruncate(*(_DWORD *)(a1 + 48), *(_QWORD *)(a1 + 32));
if ( result != -1 )
{
v3 = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 32) = 0LL;
v4 = *(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 16) = v3;
result = lseek(v4, v3, 0);
}
return result;
}

original_code:
int sp_logrlb(spfile *f)
{
 int rc = ftruncate(f->fd, f->svp);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 f->used = f->svp;
 f->svp = 0;
 return lseek(f->fd, f->used, 0);
}

canonical_original_code:
int sp_logrlb(struct spfile *f)
{
 int rc = ftruncate(f->fd, f->svp);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 f->used = f->svp;
 f->svp = 0;
 return lseek(f->fd, f->used, 0);
}

variable_types: rc int


decompiled_code:
__int64 __fastcall sp_logeof(__int64 a1)
{
__int64 v1; // rdx
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

sp_filesvp(a1);
v3[0] = 11202301;
if ( (unsigned int)sp_logwrite(a1, (char *)v3, v1) != -1 )
return 0LL;
sp_logrlb(a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func32(__int64 a1)
{
__int64 v1; // rdx
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func0(a1);
v3[0] = 11202301;
if ( (unsigned int)func29(a1, (char *)v3, v1) != -1 )
return 0LL;
func31(a1);
return 0xFFFFFFFFLL;
}

original_code:
int sp_logeof(spfile *f)
{
 sp_filesvp(f);
 speofh eof = { 0x00aaeefdL };
 int rc = sp_logwrite(f, &eof, sizeof(eof));
 if (__builtin_expect(!! (rc == -1), 0)) {
  sp_logrlb(f);
  return -1;
 }
 return 0;
}

canonical_original_code:
int sp_logeof(struct spfile *f)
{
 sp_filesvp(f);
 struct speofh eof = { 0x00aaeefdL };
 int rc = sp_logwrite(f, &eof, sizeof(eof));
 if (__builtin_expect(!! (rc == -1), 0)) {
  sp_logrlb(f);
  return -1;
 }
 return 0;
}

variable_types:
eof
struct speofh { unsigned int magic; }


decompiled_code:
int __fastcall sp_lockfile(__int64 a1, const char *a2)
{
int result; // eax
void *v4; // rax
int v5; // edi
int v6; // er8
__int128 v7[3]; // [rsp+0h] [rbp-38h] BYREF

*(_DWORD *)(a1 + 8) = 0;
result = open(a2, 65, 384LL);
*(_DWORD *)(a1 + 48) = result;
if ( result != -1 )
{
v4 = sp_strdup_isra_0(**(__int64 (__fastcall ***)(_QWORD, size_t, __int64))a1, *(_QWORD *)(*(_QWORD *)a1 + 8LL), a2);
*(_QWORD *)(a1 + 40) = v4;
if ( v4 )
{
v5 = *(_DWORD *)(a1 + 48);
v7[0] = 0LL;
LOWORD(v7[0]) = 1;
v7[1] = 0LL;
v6 = fcntl(v5, 6, v7);
result = 0;
if ( v6 == -1 )
{
sp_fileclose(a1);
result = 1;
}
}
else
{
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
result = -1;
}
}
return result;
}

original_code:
int sp_lockfile(spfile *f, char *path)
{
 f->creat = 0;
 f->fd = open(path, 0100|01, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 struct flock l;
 memset(&l, 0, sizeof(l));
 l.l_whence = 0;
 l.l_start = 0;
 l.l_len = 0;
 l.l_type = 1;
 int rc = fcntl(f->fd, 6, &l);
 if (__builtin_expect(!! (rc == -1), 0)) {
  sp_fileclose(f);
  return 1;
 }
 return 0;
}

canonical_original_code:
int sp_lockfile(struct spfile *f, char *path)
{
 f->creat = 0;
 f->fd = open(path, 0100|01, 0600);
 if (__builtin_expect(!! (f->fd == -1), 0))
  return -1;
 f->file = sp_strdup(f->a, path);
 if (__builtin_expect(!! (f->file == ((void *)0)), 0)) {
  close(f->fd);
  f->fd = -1;
  return -1;
 }
 struct flock l;
 memset(&l, 0, sizeof(l));
 l.l_whence = 0;
 l.l_start = 0;
 l.l_len = 0;
 l.l_type = 1;
 int rc = fcntl(f->fd, 6, &l);
 if (__builtin_expect(!! (rc == -1), 0)) {
  sp_fileclose(f);
  return 1;
 }
 return 0;
}

variable_types:
path
char *

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
int __fastcall sp_unlockfile(__int64 a1)
{
int v2; // edi
__int128 v4[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = *(_DWORD *)(a1 + 48);
if ( v2 == -1 )
return 0;
v4[0] = 0LL;
LOWORD(v4[0]) = 2;
v4[1] = 0LL;
fcntl(v2, 6, v4);
unlink(*(const char **)(a1 + 40));
return sp_fileclose(a1);
}

original_code:
int sp_unlockfile(spfile *f)
{
 if (__builtin_expect(!! (f->fd == -1), 0))
  return 0;
 struct flock l;
 memset(&l, 0, sizeof(l));
 l.l_whence = 0;
 l.l_start = 0;
 l.l_len = 0;
 l.l_type = 2;
 fcntl(f->fd, 6, &l);
 unlink(f->file);
 return sp_fileclose(f);
}

canonical_original_code:
int sp_unlockfile(struct spfile *f)
{
 if (__builtin_expect(!! (f->fd == -1), 0))
  return 0;
 struct flock l;
 memset(&l, 0, sizeof(l));
 l.l_whence = 0;
 l.l_start = 0;
 l.l_len = 0;
 l.l_type = 2;
 fcntl(f->fd, 6, &l);
 unlink(f->file);
 return sp_fileclose(f);
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


cmp

decompiled_code:
__int64 __fastcall cmp(_DWORD *a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a3 )
result = *a3 < *a1 ? 1 : -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a3 )
result = *a3 < *a1 ? 1 : -1;
return result;
}

original_code:
static inline int
cmp(char *a, size_t asz, char *b, size_t bsz, void *arg) {
 register uint32_t av = *(uint32_t*)a;
 register uint32_t bv = *(uint32_t*)b;
 if (av == bv)
  return 0;
 return (av > bv) ? 1 : -1;
}

canonical_original_code:
static inline int cmp(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg) {
 register unsigned int av = *(uint32_t*)a;
 register unsigned int bv = *(uint32_t*)b;
 if (av == bv)
  return 0;
 return (av > bv) ? 1 : -1;
}

variable_types:
a
char *

variable_types:
asz
unsigned long

variable_types:
b
char *

variable_types:
bsz
unsigned long

variable_types:
arg
void *

variable_types:
av
unsigned int

variable_types:
bv
unsigned int


decompiled_code:
__int64 single_process()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r12
const char *v6; // rcx
__int64 v7; // rdx

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 31LL;
goto LABEL_12;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 32LL;
LABEL_12:
printf("fail (%s:%d) %s\n", "concurrent.c", v7, v6);
fflush(0LL);
abort();
}
v2 = sp_open(v1);
if ( !v2 )
{
v6 = "db != NULL";
v7 = 34LL;
goto LABEL_12;
}
v3 = sp_env();
v4 = v3;
if ( !v3 )
{
v6 = "env2 != NULL";
v7 = 36LL;
goto LABEL_12;
}
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 37LL;
goto LABEL_12;
}
if ( sp_open(v4) )
{
v6 = "db2 == NULL";
v7 = 39LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v4) )
{
v6 = "sp_destroy(env2) == 0";
v7 = 40LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v2) )
{
v6 = "sp_destroy(db) == 0";
v7 = 41LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v1) )
{
v6 = "sp_destroy(env) == 0";
v7 = 42LL;
goto LABEL_12;
}
return rmrf("./rep");
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r12
const char *v6; // rcx
__int64 v7; // rdx

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 31LL;
goto LABEL_12;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 32LL;
LABEL_12:
printf("fail (%s:%d) %s\n", "concurrent.c", v7, v6);
fflush(0LL);
abort();
}
v2 = sp_open(v1);
if ( !v2 )
{
v6 = "db != NULL";
v7 = 34LL;
goto LABEL_12;
}
v3 = sp_env();
v4 = v3;
if ( !v3 )
{
v6 = "env2 != NULL";
v7 = 36LL;
goto LABEL_12;
}
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 37LL;
goto LABEL_12;
}
if ( sp_open(v4) )
{
v6 = "db2 == NULL";
v7 = 39LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v4) )
{
v6 = "sp_destroy(env2) == 0";
v7 = 40LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v2) )
{
v6 = "sp_destroy(db) == 0";
v7 = 41LL;
goto LABEL_12;
}
if ( (unsigned int)sp_destroy(v1) )
{
v6 = "sp_destroy(env) == 0";
v7 = 42LL;
goto LABEL_12;
}
return func1("./rep");
}

original_code:
static void
single_process(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 31, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 32, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 34, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 36, "env2 != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 37, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db2 = sp_open(env2);
 ({ if (! (db2 == ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 39, "db2 == NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 40, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 41, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 42, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep1);
}

canonical_original_code:
static void single_process() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 31, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 32, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 34, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 36, "env2 != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 37, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db2 = sp_open(env2);
 ({ if (! (db2 == ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 39, "db2 == NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 40, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 41, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 42, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep1);
}

variable_types:
env
void *

variable_types:
db
void *


decompiled_code:
__int64 single_process_2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r13
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // r14
__int64 result; // rax
const char *v7; // rcx
__int64 v8; // rdx
int v9; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-38h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v7 = "env != NULL";
v8 = 49LL;
goto LABEL_24;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v7 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v8 = 50LL;
LABEL_24:
printf("fail (%s:%d) %s\n", "concurrent.c", v8, v7);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v8 = 51LL;
goto LABEL_24;
}
v2 = sp_open(v1);
if ( !v2 )
{
v7 = "db != NULL";
v8 = 53LL;
goto LABEL_24;
}
v3 = sp_env();
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep2") )
{
v7 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0";
v8 = 56LL;
goto LABEL_24;
}
if ( (unsigned int)sp_ctl(v3, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env2, SPCMP, cmp, NULL) == 0";
v8 = 57LL;
goto LABEL_24;
}
v4 = sp_open(v3);
v5 = v4;
if ( !v4 )
{
v7 = "db2 != NULL";
v8 = 59LL;
goto LABEL_24;
}
v9 = 1;
if ( (unsigned int)sp_set(v4, &v9, 4LL, &v9, 4LL) )
{
v7 = "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 61LL;
goto LABEL_24;
}
v10 = 0LL;
ptr[0] = 0LL;
if ( (unsigned int)sp_get(v5, &v9, 4LL, ptr, &v10) != 1 )
{
v7 = "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 64LL;
goto LABEL_24;
}
if ( v10 != 4 )
{
v7 = "vsize == sizeof(k)";
v8 = 65LL;
goto LABEL_24;
}
if ( *(_DWORD *)ptr[0] != v9 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 66LL;
goto LABEL_24;
}
free(ptr[0]);
v9 = 3;
if ( (unsigned int)sp_set(v2, &v9, 4LL, &v9, 4LL) )
{
v7 = "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 69LL;
goto LABEL_24;
}
if ( (unsigned int)sp_get(v2, &v9, 4LL, ptr, &v10) != 1 )
{
v7 = "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 70LL;
goto LABEL_24;
}
if ( v10 != 4 )
{
v7 = "vsize == sizeof(k)";
v8 = 71LL;
goto LABEL_24;
}
if ( *(_DWORD *)ptr[0] != v9 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 72LL;
goto LABEL_24;
}
free(ptr[0]);
if ( (unsigned int)sp_destroy(v2) )
{
v7 = "sp_destroy(db) == 0";
v8 = 74LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v1) )
{
v7 = "sp_destroy(env) == 0";
v8 = 75LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v5) )
{
v7 = "sp_destroy(db2) == 0";
v8 = 76LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v3) )
{
v7 = "sp_destroy(env2) == 0";
v8 = 77LL;
goto LABEL_24;
}
if ( (unsigned int)rmrf("./rep") )
{
v7 = "rmrf(dbrep1) == 0";
v8 = 78LL;
goto LABEL_24;
}
result = rmrf("./rep2");
if ( (_DWORD)result )
{
v7 = "rmrf(dbrep2) == 0";
v8 = 79LL;
goto LABEL_24;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r13
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // r14
__int64 result; // rax
const char *v7; // rcx
__int64 v8; // rdx
int v9; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-38h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v7 = "env != NULL";
v8 = 49LL;
goto LABEL_24;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v7 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v8 = 50LL;
LABEL_24:
printf("fail (%s:%d) %s\n", "concurrent.c", v8, v7);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v8 = 51LL;
goto LABEL_24;
}
v2 = sp_open(v1);
if ( !v2 )
{
v7 = "db != NULL";
v8 = 53LL;
goto LABEL_24;
}
v3 = sp_env();
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep2") )
{
v7 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0";
v8 = 56LL;
goto LABEL_24;
}
if ( (unsigned int)sp_ctl(v3, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env2, SPCMP, cmp, NULL) == 0";
v8 = 57LL;
goto LABEL_24;
}
v4 = sp_open(v3);
v5 = v4;
if ( !v4 )
{
v7 = "db2 != NULL";
v8 = 59LL;
goto LABEL_24;
}
v9 = 1;
if ( (unsigned int)sp_set(v4, &v9, 4LL, &v9, 4LL) )
{
v7 = "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 61LL;
goto LABEL_24;
}
v10 = 0LL;
ptr[0] = 0LL;
if ( (unsigned int)sp_get(v5, &v9, 4LL, ptr, &v10) != 1 )
{
v7 = "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 64LL;
goto LABEL_24;
}
if ( v10 != 4 )
{
v7 = "vsize == sizeof(k)";
v8 = 65LL;
goto LABEL_24;
}
if ( *(_DWORD *)ptr[0] != v9 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 66LL;
goto LABEL_24;
}
free(ptr[0]);
v9 = 3;
if ( (unsigned int)sp_set(v2, &v9, 4LL, &v9, 4LL) )
{
v7 = "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 69LL;
goto LABEL_24;
}
if ( (unsigned int)sp_get(v2, &v9, 4LL, ptr, &v10) != 1 )
{
v7 = "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 70LL;
goto LABEL_24;
}
if ( v10 != 4 )
{
v7 = "vsize == sizeof(k)";
v8 = 71LL;
goto LABEL_24;
}
if ( *(_DWORD *)ptr[0] != v9 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 72LL;
goto LABEL_24;
}
free(ptr[0]);
if ( (unsigned int)sp_destroy(v2) )
{
v7 = "sp_destroy(db) == 0";
v8 = 74LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v1) )
{
v7 = "sp_destroy(env) == 0";
v8 = 75LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v5) )
{
v7 = "sp_destroy(db2) == 0";
v8 = 76LL;
goto LABEL_24;
}
if ( (unsigned int)sp_destroy(v3) )
{
v7 = "sp_destroy(env2) == 0";
v8 = 77LL;
goto LABEL_24;
}
if ( (unsigned int)func1("./rep") )
{
v7 = "rmrf(dbrep1) == 0";
v8 = 78LL;
goto LABEL_24;
}
result = func1("./rep2");
if ( (_DWORD)result )
{
v7 = "rmrf(dbrep2) == 0";
v8 = 79LL;
goto LABEL_24;
}
return result;
}

original_code:
static void
single_process_2(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 49, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 50, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 51, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 53, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 55, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 56, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 57, "sp_ctl(env2, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db2 = sp_open(env2);
 ({ if (! (db2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 59, "db2 != NULL"); fflush(((void *)0)); abort(); } });
 uint32_t k = 1;
 ({ if (! (sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 61, "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 size_t vsize = 0;
 void *vp = ((void *)0);
 ({ if (! (sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 64, "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 65, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(uint32_t*)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 66, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 k = 3;
 ({ if (! (sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 69, "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_get(db, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 70, "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 71, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(uint32_t*)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 72, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 74, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 75, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 76, "sp_destroy(db2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 77, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 78, "rmrf(dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 79, "rmrf(dbrep2) == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void single_process_2() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 49, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 50, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 51, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 53, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 55, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 56, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 57, "sp_ctl(env2, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db2 = sp_open(env2);
 ({ if (! (db2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 59, "db2 != NULL"); fflush(((void *)0)); abort(); } });
 unsigned int k = 1;
 ({ if (! (sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 61, "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 unsigned long vsize = 0;
 void *vp = ((void *)0);
 ({ if (! (sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 64, "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 65, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(unsigned int *)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 66, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 k = 3;
 ({ if (! (sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 69, "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_get(db, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 70, "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 71, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(unsigned int *)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 72, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 74, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 75, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 76, "sp_destroy(db2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 77, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 78, "rmrf(dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 79, "rmrf(dbrep2) == 0"); fflush(((void *)0)); abort(); } });
}

variable_types:
k
unsigned int

variable_types:
vsize
unsigned long

variable_types:
vp
void *


decompiled_code:
__int64 multi_process()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r12
__pid_t v3; // eax
__pid_t v4; // ebx
__int64 v5; // rax
const char *v6; // rcx
__int64 v7; // rdx
__int64 v8; // rbp
int v9; // eax
__int64 v10; // rax
int v11; // eax
__pid_t v12; // eax
int v13; // eax
int v14; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 85LL;
goto LABEL_17;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 86LL;
goto LABEL_17;
}
v2 = sp_open(v1);
if ( !v2 )
{
v6 = "db != NULL";
v7 = 88LL;
goto LABEL_17;
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v6 = "pid != -1";
v7 = 90LL;
goto LABEL_17;
}
if ( !v3 )
{
v5 = sp_env();
v6 = "env2 != NULL";
v7 = 94LL;
v8 = v5;
if ( v5 )
{
v9 = sp_ctl(v5, 0LL, 6LL, "./rep");
v6 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 95LL;
if ( !v9 )
{
v10 = sp_open(v8);
v6 = "db2 == NULL";
v7 = 97LL;
if ( !v10 )
{
v11 = sp_destroy(v8);
v6 = "sp_destroy(env2) == 0";
v7 = 98LL;
if ( !v11 )
exit(0);
}
}
}
LABEL_17:
printf("fail (%s:%d) %s\n", "concurrent.c", v7, v6);
fflush(0LL);
abort();
}
stat_loc[0] = 0;
v12 = waitpid(v3, stat_loc, 0);
v6 = "waitpid(pid, &status, 0) == pid";
v7 = 106LL;
if ( v12 != v4 )
goto LABEL_17;
v6 = "status == 0";
v7 = 107LL;
if ( stat_loc[0] )
goto LABEL_17;
v13 = sp_destroy(v2);
v6 = "sp_destroy(db) == 0";
v7 = 109LL;
if ( v13 )
goto LABEL_17;
v14 = sp_destroy(v1);
v6 = "sp_destroy(env) == 0";
v7 = 110LL;
if ( v14 )
goto LABEL_17;
return rmrf("./rep");
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r12
__pid_t v3; // eax
__pid_t v4; // ebx
__int64 v5; // rax
const char *v6; // rcx
__int64 v7; // rdx
__int64 v8; // rbp
int v9; // eax
__int64 v10; // rax
int v11; // eax
__pid_t v12; // eax
int v13; // eax
int v14; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 85LL;
goto LABEL_17;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 86LL;
goto LABEL_17;
}
v2 = sp_open(v1);
if ( !v2 )
{
v6 = "db != NULL";
v7 = 88LL;
goto LABEL_17;
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v6 = "pid != -1";
v7 = 90LL;
goto LABEL_17;
}
if ( !v3 )
{
v5 = sp_env();
v6 = "env2 != NULL";
v7 = 94LL;
v8 = v5;
if ( v5 )
{
v9 = sp_ctl(v5, 0LL, 6LL, "./rep");
v6 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v7 = 95LL;
if ( !v9 )
{
v10 = sp_open(v8);
v6 = "db2 == NULL";
v7 = 97LL;
if ( !v10 )
{
v11 = sp_destroy(v8);
v6 = "sp_destroy(env2) == 0";
v7 = 98LL;
if ( !v11 )
exit(0);
}
}
}
LABEL_17:
printf("fail (%s:%d) %s\n", "concurrent.c", v7, v6);
fflush(0LL);
abort();
}
stat_loc[0] = 0;
v12 = waitpid(v3, stat_loc, 0);
v6 = "waitpid(pid, &status, 0) == pid";
v7 = 106LL;
if ( v12 != v4 )
goto LABEL_17;
v6 = "status == 0";
v7 = 107LL;
if ( stat_loc[0] )
goto LABEL_17;
v13 = sp_destroy(v2);
v6 = "sp_destroy(db) == 0";
v7 = 109LL;
if ( v13 )
goto LABEL_17;
v14 = sp_destroy(v1);
v6 = "sp_destroy(env) == 0";
v7 = 110LL;
if ( v14 )
goto LABEL_17;
return func1("./rep");
}

original_code:
static void
multi_process(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 85, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 86, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 88, "db != NULL"); fflush(((void *)0)); abort(); } });
 int pid = fork();
 ({ if (! (pid != -1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 90, "pid != -1"); fflush(((void *)0)); abort(); } });
 if (pid == 0) {
  void *env2 = sp_env();
  ({ if (! (env2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 94, "env2 != NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 95, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
  void *db2 = sp_open(env2);
  ({ if (! (db2 == ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 97, "db2 == NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 98, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
  exit(0);
 } else {
  int status = 0;
  ({ if (! (waitpid(pid, &status, 0) == pid)) { printf("fail (%s:%d) %s\n", "concurrent.c", 106, "waitpid(pid, &status, 0) == pid"); fflush(((void *)0)); abort(); } });
  ({ if (! (status == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 107, "status == 0"); fflush(((void *)0)); abort(); } });
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 109, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 110, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep1);
}

canonical_original_code:
static void multi_process() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 85, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 86, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 88, "db != NULL"); fflush(((void *)0)); abort(); } });
 int pid = fork();
 ({ if (! (pid != -1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 90, "pid != -1"); fflush(((void *)0)); abort(); } });
 if (pid == 0) {
  void *env2 = sp_env();
  ({ if (! (env2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 94, "env2 != NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 95, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
  void *db2 = sp_open(env2);
  ({ if (! (db2 == ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 97, "db2 == NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 98, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
  exit(0);
 } else {
  int status = 0;
  ({ if (! (waitpid(pid, &status, 0) == pid)) { printf("fail (%s:%d) %s\n", "concurrent.c", 106, "waitpid(pid, &status, 0) == pid"); fflush(((void *)0)); abort(); } });
  ({ if (! (status == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 107, "status == 0"); fflush(((void *)0)); abort(); } });
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 109, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 110, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep1);
}

variable_types: pid int

variable_types: status int


decompiled_code:
__pid_t multi_process_2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // r13
__pid_t v4; // eax
__pid_t v5; // ebx
int v6; // eax
const char *v7; // rcx
__int64 v8; // rdx
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
__pid_t result; // eax
__int64 v14; // rax
__int64 v15; // rbp
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
int v20; // eax
int v21; // [rsp+8h] [rbp-40h] BYREF
int stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v23; // [rsp+10h] [rbp-38h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v7 = "env != NULL";
v8 = 117LL;
goto LABEL_29;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v7 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v8 = 118LL;
goto LABEL_29;
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v8 = 119LL;
goto LABEL_29;
}
v2 = sp_open(v1);
if ( !v2 )
{
v7 = "db != NULL";
v8 = 121LL;
goto LABEL_29;
}
v3 = sp_env();
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep2") )
{
v7 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0";
v8 = 124LL;
goto LABEL_29;
}
if ( (unsigned int)sp_ctl(v3, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env2, SPCMP, cmp, NULL) == 0";
v8 = 125LL;
goto LABEL_29;
}
v21 = 1;
v23 = 0LL;
ptr[0] = 0LL;
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
v7 = "pid != -1";
v8 = 130LL;
goto LABEL_29;
}
if ( !v4 )
{
v14 = sp_open(v3);
v7 = "db2 != NULL";
v8 = 133LL;
v15 = v14;
if ( v14 )
{
v16 = sp_set(v14, &v21, 4LL, &v21, 4LL);
v7 = "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 134LL;
if ( !v16 )
{
v17 = sp_get(v15, &v21, 4LL, ptr, &v23);
v7 = "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 135LL;
if ( v17 == 1 )
{
v7 = "vsize == sizeof(k)";
v8 = 136LL;
if ( v23 == 4 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 137LL;
if ( *(_DWORD *)ptr[0] == v21 )
{
free(ptr[0]);
v18 = sp_destroy(v15);
v7 = "sp_destroy(db2) == 0";
v8 = 139LL;
if ( !v18 )
{
v19 = sp_destroy(v3);
v7 = "sp_destroy(env2) == 0";
v8 = 140LL;
if ( !v19 )
{
v20 = rmrf("./rep2");
v7 = "rmrf(dbrep2) == 0";
v8 = 141LL;
if ( !v20 )
exit(0);
}
}
}
}
}
}
}
LABEL_29:
printf("fail (%s:%d) %s\n", "concurrent.c", v8, v7);
fflush(0LL);
abort();
}
v21 = 3;
v6 = sp_set(v2, &v21, 4LL, &v21, 4LL);
v7 = "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 149LL;
if ( v6 )
goto LABEL_29;
v9 = sp_get(v2, &v21, 4LL, ptr, &v23);
v7 = "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 150LL;
if ( v9 != 1 )
goto LABEL_29;
v7 = "vsize == sizeof(k)";
v8 = 151LL;
if ( v23 != 4 )
goto LABEL_29;
v7 = "*(uint32_t*)vp == k";
v8 = 152LL;
if ( *(_DWORD *)ptr[0] != v21 )
goto LABEL_29;
free(ptr[0]);
v10 = sp_destroy(v2);
v7 = "sp_destroy(db) == 0";
v8 = 154LL;
if ( v10 )
goto LABEL_29;
v11 = sp_destroy(v1);
v7 = "sp_destroy(env) == 0";
v8 = 155LL;
if ( v11 )
goto LABEL_29;
v12 = rmrf("./rep");
v7 = "rmrf(dbrep1) == 0";
v8 = 156LL;
if ( v12 )
goto LABEL_29;
stat_loc = 0;
result = waitpid(v5, &stat_loc, 0);
v7 = "waitpid(pid, &status, 0) == pid";
v8 = 158LL;
if ( result != v5 )
goto LABEL_29;
v7 = "status == 0";
v8 = 159LL;
if ( stat_loc )
goto LABEL_29;
return result;
}

canonical_decompiled_code:
__pid_t func5()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // r13
__pid_t v4; // eax
__pid_t v5; // ebx
int v6; // eax
const char *v7; // rcx
__int64 v8; // rdx
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
__pid_t result; // eax
__int64 v14; // rax
__int64 v15; // rbp
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
int v20; // eax
int v21; // [rsp+8h] [rbp-40h] BYREF
int stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v23; // [rsp+10h] [rbp-38h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v7 = "env != NULL";
v8 = 117LL;
goto LABEL_29;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v7 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0";
v8 = 118LL;
goto LABEL_29;
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v8 = 119LL;
goto LABEL_29;
}
v2 = sp_open(v1);
if ( !v2 )
{
v7 = "db != NULL";
v8 = 121LL;
goto LABEL_29;
}
v3 = sp_env();
if ( (unsigned int)sp_ctl(v3, 0LL, 6LL, "./rep2") )
{
v7 = "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0";
v8 = 124LL;
goto LABEL_29;
}
if ( (unsigned int)sp_ctl(v3, 2LL, cmp, 0LL) )
{
v7 = "sp_ctl(env2, SPCMP, cmp, NULL) == 0";
v8 = 125LL;
goto LABEL_29;
}
v21 = 1;
v23 = 0LL;
ptr[0] = 0LL;
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
v7 = "pid != -1";
v8 = 130LL;
goto LABEL_29;
}
if ( !v4 )
{
v14 = sp_open(v3);
v7 = "db2 != NULL";
v8 = 133LL;
v15 = v14;
if ( v14 )
{
v16 = sp_set(v14, &v21, 4LL, &v21, 4LL);
v7 = "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 134LL;
if ( !v16 )
{
v17 = sp_get(v15, &v21, 4LL, ptr, &v23);
v7 = "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 135LL;
if ( v17 == 1 )
{
v7 = "vsize == sizeof(k)";
v8 = 136LL;
if ( v23 == 4 )
{
v7 = "*(uint32_t*)vp == k";
v8 = 137LL;
if ( *(_DWORD *)ptr[0] == v21 )
{
free(ptr[0]);
v18 = sp_destroy(v15);
v7 = "sp_destroy(db2) == 0";
v8 = 139LL;
if ( !v18 )
{
v19 = sp_destroy(v3);
v7 = "sp_destroy(env2) == 0";
v8 = 140LL;
if ( !v19 )
{
v20 = func1("./rep2");
v7 = "rmrf(dbrep2) == 0";
v8 = 141LL;
if ( !v20 )
exit(0);
}
}
}
}
}
}
}
LABEL_29:
printf("fail (%s:%d) %s\n", "concurrent.c", v8, v7);
fflush(0LL);
abort();
}
v21 = 3;
v6 = sp_set(v2, &v21, 4LL, &v21, 4LL);
v7 = "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0";
v8 = 149LL;
if ( v6 )
goto LABEL_29;
v9 = sp_get(v2, &v21, 4LL, ptr, &v23);
v7 = "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1";
v8 = 150LL;
if ( v9 != 1 )
goto LABEL_29;
v7 = "vsize == sizeof(k)";
v8 = 151LL;
if ( v23 != 4 )
goto LABEL_29;
v7 = "*(uint32_t*)vp == k";
v8 = 152LL;
if ( *(_DWORD *)ptr[0] != v21 )
goto LABEL_29;
free(ptr[0]);
v10 = sp_destroy(v2);
v7 = "sp_destroy(db) == 0";
v8 = 154LL;
if ( v10 )
goto LABEL_29;
v11 = sp_destroy(v1);
v7 = "sp_destroy(env) == 0";
v8 = 155LL;
if ( v11 )
goto LABEL_29;
v12 = func1("./rep");
v7 = "rmrf(dbrep1) == 0";
v8 = 156LL;
if ( v12 )
goto LABEL_29;
stat_loc = 0;
result = waitpid(v5, &stat_loc, 0);
v7 = "waitpid(pid, &status, 0) == pid";
v8 = 158LL;
if ( result != v5 )
goto LABEL_29;
v7 = "status == 0";
v8 = 159LL;
if ( stat_loc )
goto LABEL_29;
return result;
}

original_code:
static void
multi_process_2(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 117, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 118, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 119, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 121, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 123, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 124, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 125, "sp_ctl(env2, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 uint32_t k = 1;
 size_t vsize = 0;
 void *vp = ((void *)0);
 int pid = fork();
 ({ if (! (pid != -1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 130, "pid != -1"); fflush(((void *)0)); abort(); } });
 if (pid == 0) {
  void *db2 = sp_open(env2);
  ({ if (! (db2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 133, "db2 != NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 134, "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 135, "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
  ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 136, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
  ({ if (! (*(uint32_t*)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 137, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
  free(vp);
  ({ if (! (sp_destroy(db2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 139, "sp_destroy(db2) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 140, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (rmrf(dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 141, "rmrf(dbrep2) == 0"); fflush(((void *)0)); abort(); } });
  exit(0);
 }
 k = 3;
 ({ if (! (sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 149, "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_get(db, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 150, "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 151, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(uint32_t*)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 152, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 154, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 155, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 156, "rmrf(dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 int status = 0;
 ({ if (! (waitpid(pid, &status, 0) == pid)) { printf("fail (%s:%d) %s\n", "concurrent.c", 158, "waitpid(pid, &status, 0) == pid"); fflush(((void *)0)); abort(); } });
 ({ if (! (status == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 159, "status == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void multi_process_2() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 117, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 118, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 119, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 121, "db != NULL"); fflush(((void *)0)); abort(); } });
 void *env2 = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 123, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 124, "sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env2, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 125, "sp_ctl(env2, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 unsigned int k = 1;
 unsigned long vsize = 0;
 void *vp = ((void *)0);
 int pid = fork();
 ({ if (! (pid != -1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 130, "pid != -1"); fflush(((void *)0)); abort(); } });
 if (pid == 0) {
  void *db2 = sp_open(env2);
  ({ if (! (db2 != ((void *)0))) { printf("fail (%s:%d) %s\n", "concurrent.c", 133, "db2 != NULL"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 134, "sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 135, "sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
  ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 136, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
  ({ if (! (*(unsigned int *)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 137, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
  free(vp);
  ({ if (! (sp_destroy(db2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 139, "sp_destroy(db2) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (sp_destroy(env2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 140, "sp_destroy(env2) == 0"); fflush(((void *)0)); abort(); } });
  ({ if (! (rmrf(dbrep2) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 141, "rmrf(dbrep2) == 0"); fflush(((void *)0)); abort(); } });
  exit(0);
 }
 k = 3;
 ({ if (! (sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 149, "sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_get(db, &k, sizeof(k), &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "concurrent.c", 150, "sp_get(db, &k, sizeof(k), &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (vsize == sizeof(k))) { printf("fail (%s:%d) %s\n", "concurrent.c", 151, "vsize == sizeof(k)"); fflush(((void *)0)); abort(); } });
 ({ if (! (*(unsigned int *)vp == k)) { printf("fail (%s:%d) %s\n", "concurrent.c", 152, "*(uint32_t*)vp == k"); fflush(((void *)0)); abort(); } });
 free(vp);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 154, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 155, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep1) == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 156, "rmrf(dbrep1) == 0"); fflush(((void *)0)); abort(); } });
 int status = 0;
 ({ if (! (waitpid(pid, &status, 0) == pid)) { printf("fail (%s:%d) %s\n", "concurrent.c", 158, "waitpid(pid, &status, 0) == pid"); fflush(((void *)0)); abort(); } });
 ({ if (! (status == 0)) { printf("fail (%s:%d) %s\n", "concurrent.c", 159, "status == 0"); fflush(((void *)0)); abort(); } });
}


decompiled_code:
__int64 gh_5()
{
__int64 v0; // rax
__int64 v1; // r13
__int64 v2; // rax
__int64 v3; // rbp
char *v4; // r12
__int64 result; // rax
const char *v6; // rcx
__int64 v7; // rdx
char v8[10]; // [rsp+6h] [rbp-42h] BYREF
char v9[11]; // [rsp+12h] [rbp-36h] BYREF
char v10[11]; // [rsp+1Dh] [rbp-2Bh] BYREF
char *s2; // [rsp+28h] [rbp-20h] BYREF

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 19LL;
goto LABEL_14;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v7 = 20LL;
LABEL_14:
printf("fail (%s:%d) %s\n", "issues.c", v7, v6);
fflush(0LL);
abort();
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v6 = "db != NULL";
v7 = 22LL;
goto LABEL_14;
}
strcpy(v8, "key-1");
strcpy(&v8[6], "val-1");
if ( (unsigned int)sp_set(v2, v8, 6LL, &v8[6], 6LL) )
{
v6 = "sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0";
v7 = 26LL;
goto LABEL_14;
}
strcpy(v9, "key-10");
strcpy(&v9[7], "val-10");
if ( (unsigned int)sp_set(v3, v9, 7LL, &v9[7], 7LL) )
{
v6 = "sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0";
v7 = 30LL;
goto LABEL_14;
}
*(_QWORD *)&v10[3] = 0LL;
s2 = 0LL;
if ( (unsigned int)sp_get(v3, v8, 6LL, &s2, &v10[3]) != 1 )
{
v6 = "sp_get(db, k1, sizeof(k1), &res, &ressize) == 1";
v7 = 34LL;
goto LABEL_14;
}
if ( *(_QWORD *)&v10[3] != 6LL )
{
v6 = "ressize == sizeof(v1)";
v7 = 36LL;
goto LABEL_14;
}
v4 = s2;
if ( strcmp(&v8[6], s2) )
{
v6 = "strcmp(v1, res) == 0";
v7 = 37LL;
goto LABEL_14;
}
free(v4);
if ( (unsigned int)sp_destroy(v3) )
{
v6 = "sp_destroy(db) == 0";
v7 = 41LL;
goto LABEL_14;
}
if ( (unsigned int)sp_destroy(v1) )
{
v6 = "sp_destroy(env) == 0";
v7 = 42LL;
goto LABEL_14;
}
result = rmrf("./rep");
if ( (_DWORD)result )
{
v6 = "rmrf(dbrep) == 0";
v7 = 43LL;
goto LABEL_14;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // r13
__int64 v2; // rax
__int64 v3; // rbp
char *v4; // r12
__int64 result; // rax
const char *v6; // rcx
__int64 v7; // rdx
char v8[10]; // [rsp+6h] [rbp-42h] BYREF
char v9[11]; // [rsp+12h] [rbp-36h] BYREF
char v10[11]; // [rsp+1Dh] [rbp-2Bh] BYREF
char *s2; // [rsp+28h] [rbp-20h] BYREF

v0 = sp_env();
if ( !v0 )
{
v6 = "env != NULL";
v7 = 19LL;
goto LABEL_14;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v6 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v7 = 20LL;
LABEL_14:
printf("fail (%s:%d) %s\n", "issues.c", v7, v6);
fflush(0LL);
abort();
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v6 = "db != NULL";
v7 = 22LL;
goto LABEL_14;
}
strcpy(v8, "key-1");
strcpy(&v8[6], "val-1");
if ( (unsigned int)sp_set(v2, v8, 6LL, &v8[6], 6LL) )
{
v6 = "sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0";
v7 = 26LL;
goto LABEL_14;
}
strcpy(v9, "key-10");
strcpy(&v9[7], "val-10");
if ( (unsigned int)sp_set(v3, v9, 7LL, &v9[7], 7LL) )
{
v6 = "sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0";
v7 = 30LL;
goto LABEL_14;
}
*(_QWORD *)&v10[3] = 0LL;
s2 = 0LL;
if ( (unsigned int)sp_get(v3, v8, 6LL, &s2, &v10[3]) != 1 )
{
v6 = "sp_get(db, k1, sizeof(k1), &res, &ressize) == 1";
v7 = 34LL;
goto LABEL_14;
}
if ( *(_QWORD *)&v10[3] != 6LL )
{
v6 = "ressize == sizeof(v1)";
v7 = 36LL;
goto LABEL_14;
}
v4 = s2;
if ( strcmp(&v8[6], s2) )
{
v6 = "strcmp(v1, res) == 0";
v7 = 37LL;
goto LABEL_14;
}
free(v4);
if ( (unsigned int)sp_destroy(v3) )
{
v6 = "sp_destroy(db) == 0";
v7 = 41LL;
goto LABEL_14;
}
if ( (unsigned int)sp_destroy(v1) )
{
v6 = "sp_destroy(env) == 0";
v7 = 42LL;
goto LABEL_14;
}
result = func0("./rep");
if ( (_DWORD)result )
{
v6 = "rmrf(dbrep) == 0";
v7 = 43LL;
goto LABEL_14;
}
return result;
}

original_code:
static void
gh_5(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 19, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 20, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 22, "db != NULL"); fflush(((void *)0)); abort(); } });
 char k1[] = "key-1";
 char v1[] = "val-1";
 ({ if (! (sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 26, "sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0"); fflush(((void *)0)); abort(); } });
 char k2[] = "key-10";
 char v2[] = "val-10";
 ({ if (! (sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 30, "sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0"); fflush(((void *)0)); abort(); } });
 size_t ressize = 0;
 void *res = ((void *)0);
 ({ if (! (sp_get(db, k1, sizeof(k1), &res, &ressize) == 1)) { printf("fail (%s:%d) %s\n", "issues.c", 34, "sp_get(db, k1, sizeof(k1), &res, &ressize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (ressize == sizeof(v1))) { printf("fail (%s:%d) %s\n", "issues.c", 36, "ressize == sizeof(v1)"); fflush(((void *)0)); abort(); } });
 ({ if (! (strcmp(v1, res) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 37, "strcmp(v1, res) == 0"); fflush(((void *)0)); abort(); } });
 free(res);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 41, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 42, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 43, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void gh_5() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 19, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 20, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 22, "db != NULL"); fflush(((void *)0)); abort(); } });
 char k1[] = "key-1";
 char v1[] = "val-1";
 ({ if (! (sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 26, "sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0"); fflush(((void *)0)); abort(); } });
 char k2[] = "key-10";
 char v2[] = "val-10";
 ({ if (! (sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 30, "sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0"); fflush(((void *)0)); abort(); } });
 unsigned long ressize = 0;
 void *res = ((void *)0);
 ({ if (! (sp_get(db, k1, sizeof(k1), &res, &ressize) == 1)) { printf("fail (%s:%d) %s\n", "issues.c", 34, "sp_get(db, k1, sizeof(k1), &res, &ressize) == 1"); fflush(((void *)0)); abort(); } });
 ({ if (! (ressize == sizeof(v1))) { printf("fail (%s:%d) %s\n", "issues.c", 36, "ressize == sizeof(v1)"); fflush(((void *)0)); abort(); } });
 ({ if (! (strcmp(v1, res) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 37, "strcmp(v1, res) == 0"); fflush(((void *)0)); abort(); } });
 free(res);
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 41, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 42, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 43, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

variable_types:
ressize
unsigned long

variable_types:
res
void *


decompiled_code:
__int64 gh_29()
{
__int64 v0; // rax
__int64 v1; // r13
__int64 v2; // rbp
unsigned int i; // er12
int v4; // eax
unsigned int j; // ebx
size_t v6; // r12
void *v7; // r14
__int64 result; // rax
const char *v9; // rcx
__int64 v10; // rdx
char s1[4]; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v12; // [rsp+10h] [rbp-38h] BYREF
char s[8]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v9 = "env != NULL";
v10 = 49LL;
goto LABEL_17;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v9 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v10 = 50LL;
goto LABEL_17;
}
v2 = sp_open(v1);
if ( !v2 )
{
v9 = "db != NULL";
v10 = 52LL;
LABEL_17:
printf("fail (%s:%d) %s\n", "issues.c", v10, v9);
fflush(0LL);
abort();
}
for ( i = 1; i != 11; ++i )
{
v4 = snprintf(s, 4uLL, "%d", i);
if ( (unsigned int)sp_set(v2, s, v4, s, v4) )
{
v9 = "sp_set(db, key, len, key, len) == 0";
v10 = 57LL;
goto LABEL_17;
}
}
for ( j = 1; j != 11; ++j )
{
v6 = snprintf(s1, 4uLL, "%d", j);
v12 = 0LL;
*(_QWORD *)s = 0LL;
if ( (unsigned int)sp_get(v2, s1, v6, s, &v12) != 1 )
{
v9 = "sp_get(db, key, len, &vp, &vsize) == 1";
v10 = 64LL;
goto LABEL_17;
}
if ( v6 != v12 )
{
v9 = "vsize == len";
v10 = 65LL;
goto LABEL_17;
}
v7 = *(void **)s;
if ( memcmp(s1, *(const void **)s, v6) )
{
v9 = "memcmp(key, vp, len) == 0";
v10 = 66LL;
goto LABEL_17;
}
free(v7);
}
if ( (unsigned int)sp_destroy(v2) )
{
v9 = "sp_destroy(db) == 0";
v10 = 69LL;
goto LABEL_17;
}
if ( (unsigned int)sp_destroy(v1) )
{
v9 = "sp_destroy(env) == 0";
v10 = 70LL;
goto LABEL_17;
}
result = rmrf("./rep");
if ( (_DWORD)result )
{
v9 = "rmrf(dbrep) == 0";
v10 = 71LL;
goto LABEL_17;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // r13
__int64 v2; // rbp
unsigned int i; // er12
int v4; // eax
unsigned int j; // ebx
size_t v6; // r12
void *v7; // r14
__int64 result; // rax
const char *v9; // rcx
__int64 v10; // rdx
char s1[4]; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v12; // [rsp+10h] [rbp-38h] BYREF
char s[8]; // [rsp+18h] [rbp-30h] BYREF

v0 = sp_env();
if ( !v0 )
{
v9 = "env != NULL";
v10 = 49LL;
goto LABEL_17;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v9 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v10 = 50LL;
goto LABEL_17;
}
v2 = sp_open(v1);
if ( !v2 )
{
v9 = "db != NULL";
v10 = 52LL;
LABEL_17:
printf("fail (%s:%d) %s\n", "issues.c", v10, v9);
fflush(0LL);
abort();
}
for ( i = 1; i != 11; ++i )
{
v4 = snprintf(s, 4uLL, "%d", i);
if ( (unsigned int)sp_set(v2, s, v4, s, v4) )
{
v9 = "sp_set(db, key, len, key, len) == 0";
v10 = 57LL;
goto LABEL_17;
}
}
for ( j = 1; j != 11; ++j )
{
v6 = snprintf(s1, 4uLL, "%d", j);
v12 = 0LL;
*(_QWORD *)s = 0LL;
if ( (unsigned int)sp_get(v2, s1, v6, s, &v12) != 1 )
{
v9 = "sp_get(db, key, len, &vp, &vsize) == 1";
v10 = 64LL;
goto LABEL_17;
}
if ( v6 != v12 )
{
v9 = "vsize == len";
v10 = 65LL;
goto LABEL_17;
}
v7 = *(void **)s;
if ( memcmp(s1, *(const void **)s, v6) )
{
v9 = "memcmp(key, vp, len) == 0";
v10 = 66LL;
goto LABEL_17;
}
free(v7);
}
if ( (unsigned int)sp_destroy(v2) )
{
v9 = "sp_destroy(db) == 0";
v10 = 69LL;
goto LABEL_17;
}
if ( (unsigned int)sp_destroy(v1) )
{
v9 = "sp_destroy(env) == 0";
v10 = 70LL;
goto LABEL_17;
}
result = func0("./rep");
if ( (_DWORD)result )
{
v9 = "rmrf(dbrep) == 0";
v10 = 71LL;
goto LABEL_17;
}
return result;
}

original_code:
static void
gh_29(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 49, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 50, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 52, "db != NULL"); fflush(((void *)0)); abort(); } });
 int i;
 for (i = 1; i <= 10; i++) {
  char key[4];
  int len = snprintf(key, sizeof(key), "%d", i);
  ({ if (! (sp_set(db, key, len, key, len) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 57, "sp_set(db, key, len, key, len) == 0"); fflush(((void *)0)); abort(); } });
 }
 for (i = 1; i <= 10; i++) {
  char key[4];
  int len = snprintf(key, sizeof(key), "%d", i);
  size_t vsize = 0;
  void *vp = ((void *)0);
  ({ if (! (sp_get(db, key, len, &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "issues.c", 64, "sp_get(db, key, len, &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
  ({ if (! (vsize == len)) { printf("fail (%s:%d) %s\n", "issues.c", 65, "vsize == len"); fflush(((void *)0)); abort(); } });
  ({ if (! (memcmp(key, vp, len) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 66, "memcmp(key, vp, len) == 0"); fflush(((void *)0)); abort(); } });
  free(vp);
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 69, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 70, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 71, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void gh_29() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 49, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 50, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 52, "db != NULL"); fflush(((void *)0)); abort(); } });
 int i;
 for (i = 1; i <= 10; i++) {
  char key[4];
  int len = snprintf(key, sizeof(key), "%d", i);
  ({ if (! (sp_set(db, key, len, key, len) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 57, "sp_set(db, key, len, key, len) == 0"); fflush(((void *)0)); abort(); } });
 }
 for (i = 1; i <= 10; i++) {
  char key[4];
  int len = snprintf(key, sizeof(key), "%d", i);
  unsigned long vsize = 0;
  void *vp = ((void *)0);
  ({ if (! (sp_get(db, key, len, &vp, &vsize) == 1)) { printf("fail (%s:%d) %s\n", "issues.c", 64, "sp_get(db, key, len, &vp, &vsize) == 1"); fflush(((void *)0)); abort(); } });
  ({ if (! (vsize == len)) { printf("fail (%s:%d) %s\n", "issues.c", 65, "vsize == len"); fflush(((void *)0)); abort(); } });
  ({ if (! (memcmp(key, vp, len) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 66, "memcmp(key, vp, len) == 0"); fflush(((void *)0)); abort(); } });
  free(vp);
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 69, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 70, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 71, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

variable_types: i int

variable_types:
key
char [4]

variable_types: len int


original_code:
static void
gh_37(void)
{
 const int size = 999;
 const int watermark = 3996;
 const int pagesize = 1022;
 char data[size];
 memset(data, 0, sizeof(data));
 void *env = sp_env();
 int rc = sp_ctl(env, SPDIR, SPO_CREAT | SPO_RDWR, dbrep);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 86, "rc == 0"); fflush(((void *)0)); abort(); } });
 if (rc == -1)
 rc = sp_ctl(env, SPMERGE, 0);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 90, "rc == 0"); fflush(((void *)0)); abort(); } });
 rc = sp_ctl(env, SPMERGEWM, watermark);
 if (rc == -1)
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 94, "rc == 0"); fflush(((void *)0)); abort(); } });
 sp_ctl(env, SPPAGE, pagesize);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 97, "rc == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 100, "db != NULL"); fflush(((void *)0)); abort(); } });
 int byteCount = 0;
 int i;
 for (i = 0; i < 100000; ++i) {
  rc = sp_set(db, &i, sizeof(int), data, size);
  ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 106, "rc == 0"); fflush(((void *)0)); abort(); } });
 }
 byteCount += size;
 if (i != 0 && i % watermark == 0) {
  rc = sp_ctl(db, SPMERGEFORCE);
  ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 112, "rc == 0"); fflush(((void *)0)); abort(); } });
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 115, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 116, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 117, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void gh_37()
{
 int size = 999;
 int watermark = 3996;
 int pagesize = 1022;
 char data[-1];
 memset(data, 0, sizeof(data));
 void *env = sp_env();
 int rc = sp_ctl(env, SPDIR, SPO_CREAT | SPO_RDWR, dbrep);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 86, "rc == 0"); fflush(((void *)0)); abort(); } });
 if (rc == -1)
 rc = sp_ctl(env, SPMERGE, 0);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 90, "rc == 0"); fflush(((void *)0)); abort(); } });
 rc = sp_ctl(env, SPMERGEWM, watermark);
 if (rc == -1)
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 94, "rc == 0"); fflush(((void *)0)); abort(); } });
 sp_ctl(env, SPPAGE, pagesize);
 ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 97, "rc == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "issues.c", 100, "db != NULL"); fflush(((void *)0)); abort(); } });
 int byteCount = 0;
 int i;
 for (i = 0; i < 100000; ++i) {
  rc = sp_set(db, &i, sizeof(int), data, size);
  ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 106, "rc == 0"); fflush(((void *)0)); abort(); } });
 }
 byteCount += size;
 if (i != 0 && i % watermark == 0) {
  rc = sp_ctl(db, SPMERGEFORCE);
  ({ if (! (rc == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 112, "rc == 0"); fflush(((void *)0)); abort(); } });
 }
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 115, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 116, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "issues.c", 117, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

variable_types: size int

variable_types: watermark int

variable_types: pagesize int

variable_types:
data
char [-1]

variable_types: rc int

variable_types: byteCount int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
rmrf("./rep");
printf("%s: ", "gh_5");
fflush(0LL);
gh_5();
puts("ok");
fflush(0LL);
printf("%s: ", "gh_29");
fflush(0LL);
gh_29();
puts("ok");
fflush(0LL);
printf("%s: ", "gh_37");
fflush(0LL);
gh_37();
puts("ok");
fflush(0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0("./rep");
printf("%s: ", "gh_5");
fflush(0LL);
func1();
puts("ok");
fflush(0LL);
printf("%s: ", "gh_29");
fflush(0LL);
func2();
puts("ok");
fflush(0LL);
printf("%s: ", "gh_37");
fflush(0LL);
func3();
puts("ok");
fflush(0LL);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 rmrf(dbrep);
 ({ printf("%s: ", "gh_5"); fflush(((void *)0)); gh_5(); printf("ok\n"); fflush(((void *)0)); });
 ({ printf("%s: ", "gh_29"); fflush(((void *)0)); gh_29(); printf("ok\n"); fflush(((void *)0)); });
 ({ printf("%s: ", "gh_37"); fflush(((void *)0)); gh_37(); printf("ok\n"); fflush(((void *)0)); });
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]