decompiled_code:
void __fastcall test_delete(__int64 a1, signed int a2, int a3)
{
int v3; // ebp
unsigned int v4; // er12
__int64 i; // rbx

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)delete_from_btree(a1, i) >= 0; ++i )
{
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "delete error, %d\n", v4);
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, signed int a2, int a3)
{
int v3; // ebp
unsigned int v4; // er12
__int64 i; // rbx

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)func10(a1, i) >= 0; ++i )
{
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "delete error, %d\n", v4);
}
}

original_code:
void test_delete(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    for (i = start; i < start + num; ++i) {
        rc = delete_from_btree(btree, i);
        if (rc < 0) {
            fprintf(stderr, "delete error, %d\n", i);
            break;
        }
    }
}


repo: Thirdhuku/TreeDB

decompiled_code:
void __fastcall test_search(__int64 a1, signed int a2, int a3)
{
int v3; // ebp
unsigned int v4; // er12
__int64 i; // rbx
__int64 v6[9]; // [rsp+0h] [rbp-48h] BYREF

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)search_in_btree(a1, i, v6) >= 0; ++i )
{
if ( v6[0] != i || *(__int64 *)((char *)&v6[2] + 1) != i )
_assert_fail("i == off.ino && i == off.offset", "test_btree.c", 0xFBu, "test_search");
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "search error, %d\n", v4);
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, signed int a2, int a3)
{
int v3; // ebp
unsigned int v4; // er12
__int64 i; // rbx
__int64 v6[9]; // [rsp+0h] [rbp-48h] BYREF

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)func9(a1, i, v6) >= 0; ++i )
{
if ( v6[0] != i || *(__int64 *)((char *)&v6[2] + 1) != i )
_assert_fail("i == off.ino && i == off.offset", "test_btree.c", 0xFBu, "test_search");
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "search error, %d\n", v4);
}
}

original_code:
void test_search(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    struct stp_bnode_off off;
    for (i = start; i < start + num; ++i) {
        rc = search_in_btree(btree, i, &off);
        if (rc < 0) {
            fprintf(stderr, "search error, %d\n", i);
            break;
        }
        ((void) sizeof ((i == off.ino && i == off.offset) ? 1 : 0), __extension__ ({ if (i == off.ino && i == off.offset) ; else __assert_fail ("i == off.ino && i == off.offset", "test_btree.c", 251, __extension__ __PRETTY_FUNCTION__); }));
    }
}

variable_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *

variable_types: start int

variable_types: num int

variable_types: rc int

variable_types: i int

return_type: void

user_defined_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations *ops; }

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

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; }

user_defined_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item *item; struct stp_bnode_operations *ops; }

user_defined_types: struct stp_bnode_item { struct stp_header location; struct stp_bnode_key key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; }


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

result = sync_btree(a1);
if ( result < 0 )
result = fwrite("sync error\n", 1uLL, 0xBuLL, stderr);
return result;
}

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

result = func11(a1);
if ( result < 0 )
result = fwrite("sync error\n", 1uLL, 0xBuLL, stderr);
return result;
}

original_code:
void test_sync(struct stp_btree_info *btree)
{
    int rc = 0;
    rc = sync_btree(btree);
    if (rc < 0) {
        fprintf(stderr, "sync error\n");
    }
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; }

user_defined_types: struct list { struct list *next; struct list *prev; }

user_defined_types: struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); }

user_defined_types: struct stp_bnode_key { unsigned long ino; unsigned char flags; }

user_defined_types: struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rax
char **v4; // rbp
int result; // eax

v3 = stp_btree_open("sw.idx", 0);
if ( v3 )
{
v4 = v3;
test_insert((__int64)v3, 1, 90000000);
puts(L"12345678");
test_sync((__int64)v4);
puts(L"2345678");
test_search((__int64)v4, 1, 900000);
puts(L"345678");
test_delete((__int64)v4, 1, 10);
puts(L"45678");
test_sync((__int64)v4);
puts(L"5678");
test_search((__int64)v4, 100000, 800000);
puts(L"678");
test_search((__int64)v4, 12, 2);
puts(L"78");
test_search((__int64)v4, 1, 2);
puts(L"8");
stp_btree_close(v4);
result = 0;
}
else
{
fwrite("open index file error\n", 1uLL, 0x16uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    struct stp_btree_info *btree = ((void *)0);
    btree = stp_btree_open("sw.idx", 0);
    if (btree == ((void *)0)) {
        fprintf(stderr, "open index file error\n");
        return -1;
    }
    test_insert(btree, 1, 90000000);
    printf("1\n");
    test_sync(btree);
    printf("2\n");
    test_search(btree, 1, 900000);
    printf("3\n");
    test_delete(btree, 1, 10);
    printf("4\n");
    test_sync(btree);
    printf("5\n");
    test_search(btree, 100000, 800000);
    printf("6\n");
    test_search(btree, 12, 2);
    printf("7\n");
    test_search(btree, 1, 2);
    printf("8\n");
    stp_btree_close(btree);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
__int64 do_bnode_init()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_init(struct stp_bnode *bnode)
{
    return -1;
}

variable_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *


decompiled_code:
__int64 do_bnode_insert()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_insert(struct stp_bnode * node,u64 ino,size_t start,off_t offset)
{
    return -1;
}

canonical_original_code:
static int do_bnode_insert(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset)
{
    return -1;
}

variable_types:
ino
unsigned long

variable_types:
start
unsigned long

variable_types: offset long


decompiled_code:
__int64 do_bnode_delete()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_delete(struct stp_bnode *node,u64 ino)
{
    return -1;
}

canonical_original_code:
static int do_bnode_delete(struct stp_bnode *node, unsigned long ino)
{
    return -1;
}


decompiled_code:
// attributes: thunk
__int64 do_bnode_destroy()
{
return do_bnode_init();
}

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

original_code:
static int do_bnode_destroy(struct stp_bnode * node)
{
    return -1;
}

canonical_original_code:
static int do_bnode_destroy(struct stp_bnode *node)
{
    return -1;
}


decompiled_code:
__int64 do_bnode_search()
{
return 0LL;
}

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

original_code:
static struct stp_bnode* do_bnode_search(struct stp_bnode *node,u64 ino,struct stp_bnode_off *off)
{
    return ((void *)0);
}

canonical_original_code:
static struct stp_bnode *do_bnode_search(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off)
{
    return ((void *)0);
}

variable_types:
node
struct stp_bnode *

variable_types:
off
struct stp_bnode_off *

return_type: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *


decompiled_code:
// attributes: thunk
__int64 do_bnode_update()
{
return do_bnode_insert_constprop_0();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
static int do_bnode_update(struct stp_bnode * node,u64 ino,size_t start,off_t offset)
{
    return -1;
}

canonical_original_code:
static int do_bnode_update(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset)
{
    return -1;
}


original_code:
int stp_stat(STP_FILE pfile,u64 ino,struct stat *buf)
{
    struct stp_fs_info * fs = pfile->fs;
    struct stp_btree_info *btree = pfile->tree;
    struct stp_bnode_off off;
    struct stp_inode *inode;
    int ret;
    if(!buf) {
        stp_errno = 33;
        return -1;
    }
    memset(&off,0,sizeof(off));
    if(ino == 1) {
        __copy_stat(buf,&fs->super->root);
        return 0;
    }
    ret = btree->ops->search(btree,ino,&off);
    if(ret < 0) return ret;
    if(fs->ops->lookup(fs,&inode,off.ino,off.offset) < 0)
        return -1;
    printf("%s:%d,ino:%llu(%llu),offset:%llu,size:%llu,ret:%d\n",__FUNCTION__,50,off.ino,ino,off.offset,off.len,ret);
    __copy_stat(buf,inode->item);
    return 0;
}

canonical_original_code:
int stp_stat(struct STP_FILE_INFO *pfile, unsigned long ino, struct stat *buf)
{
    struct stp_fs_info *fs = pfile->fs;
    struct stp_btree_info *btree = pfile->tree;
    struct stp_bnode_off off;
    struct stp_inode *inode;
    int ret;
    if(!buf) {
        stp_errno = 33;
        return -1;
    }
    memset(&off,0,sizeof(off));
    if(ino == 1) {
        __copy_stat(buf,&fs->super->root);
        return 0;
    }
    ret = btree->ops->search(btree,ino,&off);
    if(ret < 0) return ret;
    if(fs->ops->lookup(fs,&inode,off.ino,off.offset) < 0)
        return -1;
    printf("%s:%d,ino:%llu(%llu),offset:%llu,size:%llu,ret:%d\n",__FUNCTION__,50,off.ino,ino,off.offset,off.len,ret);
    __copy_stat(buf,inode->item);
    return 0;
}

variable_types: struct STP_FILE_INFO { struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } *root; unsigned long len; } root; struct list { struct list *next; struct list *prev; } inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *fs; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; } *

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: struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } node; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node *root; unsigned long len; } root; struct list inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *

variable_types: ret int

user_defined_types: struct STP_FILE_INFO { struct stp_fs_info *fs; struct stp_btree_info *tree; }

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

user_defined_types: struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t sem; union pthread_mutex_t mutex; struct stp_fs_super *super; struct rb_root root; struct list inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations *ops; }

user_defined_types: struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations *ops; }

user_defined_types: struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item root; }

user_defined_types: struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); }

user_defined_types: struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); }

user_defined_types: struct stp_inode_item { struct stp_header location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution extend; }; char checksum[32]; char address[32]; }

user_defined_types: struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations *ops; }


original_code:
int stp_readdir(STP_FILE file,u64 ino,dir_t *items,u32 len)
{
    struct stp_fs_info *fs;
    struct stp_btree_info *tree;
    struct stp_inode *inode;
    int i;
    if(!file) {
        stp_errno = 33;
        return -1;
    }
    fs = file->fs;
    tree = file->tree;
    inode = ((void *)0);
    if((!(tree->mode & (1<<2))) && (!(tree->mode & (1<<0)))) {
        stp_errno = 10;
        return -1;
    }
    if(__fs_read_inode(fs,ino,tree,&inode) < 0)
        return -1;
    if(!(inode->item->mode & 0040000)) {
        stp_errno = 44;
        return -1;
    }
    struct stp_dir_item *item;
    if(!(item = calloc(inode->item->nritem,sizeof(struct stp_dir_item)))) {
        stp_errno = 31;
        return -1;
    }
    if(inode->ops->readdir(inode,item) < 0)
    {
        free(item);
        return -1;
    }
    if(!item || !len) {
        free(item);
        return 0;
    }
    for(i = 0;i < inode->item->nritem && i < len;++i) {
        memcpy(&items[i],&item[i],sizeof(*items));
    }
    free(item);
    return 0;
}

canonical_original_code:
int stp_readdir(struct STP_FILE_INFO *file, unsigned long ino, struct stp_dir_item *items, unsigned int len)
{
    struct stp_fs_info *fs;
    struct stp_btree_info *tree;
    struct stp_inode *inode;
    int i;
    if(!file) {
        stp_errno = 33;
        return -1;
    }
    fs = file->fs;
    tree = file->tree;
    inode = ((void *)0);
    if((!(tree->mode & (1<<2))) && (!(tree->mode & (1<<0)))) {
        stp_errno = 10;
        return -1;
    }
    if(__fs_read_inode(fs,ino,tree,&inode) < 0)
        return -1;
    if(!(inode->item->mode & 0040000)) {
        stp_errno = 44;
        return -1;
    }
    struct stp_dir_item *item;
    if(!(item = calloc(inode->item->nritem,sizeof(struct stp_dir_item)))) {
        stp_errno = 31;
        return -1;
    }
    if(inode->ops->readdir(inode,item) < 0)
    {
        free(item);
        return -1;
    }
    if(!item || !len) {
        free(item);
        return 0;
    }
    for(i = 0;i < inode->item->nritem && i < len;++i) {
        memcpy(&items[i],&item[i],sizeof(*items));
    }
    free(item);
    return 0;
}

variable_types:
items
struct stp_dir_item *

variable_types:
len
unsigned int

variable_types: struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } *root; unsigned long len; } root; struct list { struct list *next; struct list *prev; } inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *

variable_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *

user_defined_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations *ops; }

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

user_defined_types: struct rb_root { struct rb_node *root; unsigned long len; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; }

user_defined_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item *item; struct stp_bnode_operations *ops; }

user_defined_types: struct stp_bnode_item { struct stp_header location; struct stp_bnode_key key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; }


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

result = "Unknown error";
if ( a1 <= 0x2E )
result = stp_errlist[a1];
return result;
}

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

result = "Unknown error";
if ( a1 <= 0x2E )
result = stp_errlist[a1];
return result;
}

original_code:
const char * stp_strerror(stp_error error)
{
    if((((int) error) < 0) || ((int)error > 46))
        return ((const char *)"Unknown error");
    else
        return ((const char *)stp_errlist[(int)error]);
}

canonical_original_code:
char *stp_strerror(unsigned int error)
{
    if((((int) error) < 0) || ((int)error > 46))
        return ((char *)"Unknown error");
    else
        return ((char *)stp_errlist[(int)error]);
}

variable_types:
error
unsigned int

return_type: char *


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall buf_realloc(__int64 a1, __int64 a2)
{
size_t v3; // rsi
void *v4; // rax
__int64 v5; // rbp
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 40) + a2;
if ( v3 > *(_QWORD *)(a1 + 32) )
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
else
{
v4 = realloc(*(void **)(a1 + 16), v3);
if ( v4 )
{
v5 = *(_QWORD *)(a1 + 40) + a2;
*(_QWORD *)(a1 + 16) = v4;
result = 0LL;
*(_QWORD *)(a1 + 24) = v5;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
size_t v3; // rsi
void *v4; // rax
__int64 v5; // rbp
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 40) + a2;
if ( v3 > *(_QWORD *)(a1 + 32) )
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
else
{
v4 = realloc(*(void **)(a1 + 16), v3);
if ( v4 )
{
v5 = *(_QWORD *)(a1 + 40) + a2;
*(_QWORD *)(a1 + 16) = v4;
result = 0LL;
*(_QWORD *)(a1 + 24) = v5;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
buf_realloc(struct buf *buf, size_t len)
{
 u_char *b;
 if (buf->wpos + len > buf->max) {
  (*__errno_location ()) = 12;
  return (-1);
 }
 b = realloc(buf->buf, buf->wpos + len);
 if (b == ((void *)0))
  return (-1);
 buf->buf = b;
 buf->size = buf->wpos + len;
 return (0);
}

canonical_original_code:
int buf_realloc(struct buf *buf, unsigned long len)
{
 unsigned char *b;
 if (buf->wpos + len > buf->max) {
  (*__errno_location ()) = 12;
  return (-1);
 }
 b = realloc(buf->buf, buf->wpos + len);
 if (b == ((void *)0))
  return (-1);
 buf->buf = b;
 buf->size = buf->wpos + len;
 return (0);
}

variable_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *

variable_types:
len
unsigned long

variable_types:
b
unsigned char *


decompiled_code:
__int64 __fastcall buf_add(_QWORD *a1, const void *a2, size_t a3)
{
__int64 v5; // rdi
__int64 result; // rax

v5 = a1[5];
if ( v5 + a3 > a1[3] )
{
result = buf_realloc((__int64)a1, a3);
if ( (_DWORD)result == -1 )
return result;
v5 = a1[5];
}
memcpy((void *)(a1[2] + v5), a2, a3);
a1[5] += a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, const void *a2, size_t a3)
{
__int64 v5; // rdi
__int64 result; // rax

v5 = a1[5];
if ( v5 + a3 > a1[3] )
{
result = func0((__int64)a1, a3);
if ( (_DWORD)result == -1 )
return result;
v5 = a1[5];
}
memcpy((void *)(a1[2] + v5), a2, a3);
a1[5] += a3;
return 0LL;
}

original_code:
int
buf_add(struct buf *buf, const void *data, size_t len)
{
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (-1);
 memcpy(buf->buf + buf->wpos, data, len);
 buf->wpos += len;
 return (0);
}

canonical_original_code:
int buf_add(struct buf *buf, void *data, unsigned long len)
{
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (-1);
 memcpy(buf->buf + buf->wpos, data, len);
 buf->wpos += len;
 return (0);
}

variable_types:
data
void *

user_defined_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }


decompiled_code:
__int64 __fastcall buf_reserve(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

v2 = a1[5];
v3 = v2 + a2;
if ( (unsigned __int64)(v2 + a2) <= a1[3] )
goto LABEL_2;
if ( (unsigned int)buf_realloc((__int64)a1, a2) != -1 )
{
v2 = a1[5];
v3 = a2 + v2;
LABEL_2:
a1[5] = v3;
return a1[2] + v2;
}
return 0LL;
}

original_code:
void *
buf_reserve(struct buf *buf, size_t len)
{
 void *b;
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (((void *)0));
 b = buf->buf + buf->wpos;
 buf->wpos += len;
 return (b);
}

canonical_original_code:
void *buf_reserve(struct buf *buf, unsigned long len)
{
 void *b;
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (((void *)0));
 b = buf->buf + buf->wpos;
 buf->wpos += len;
 return (b);
}

variable_types:
b
void *

return_type: void *


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

if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 40) )
result = 0LL;
else
result = a2 + *(_QWORD *)(a1 + 16);
return result;
}

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

if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 40) )
result = 0LL;
else
result = a2 + *(_QWORD *)(a1 + 16);
return result;
}

original_code:
void *
buf_seek(struct buf *buf, size_t pos, size_t len)
{
 if (pos + len > buf->wpos)
  return (((void *)0));
 return (buf->buf + pos);
}

canonical_original_code:
void *buf_seek(struct buf *buf, unsigned long pos, unsigned long len)
{
 if (pos + len > buf->wpos)
  return (((void *)0));
 return (buf->buf + pos);
}

variable_types:
pos
unsigned long


decompiled_code:
__int64 __fastcall buf_size(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

original_code:
size_t
buf_size(struct buf *buf)
{
 return (buf->wpos);
}

canonical_original_code:
unsigned long buf_size(struct buf *buf)
{
 return (buf->wpos);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall buf_left(__int64 a1)
{
return *(_QWORD *)(a1 + 32) - *(_QWORD *)(a1 + 40);
}

original_code:
size_t
buf_left(struct buf *buf)
{
 return (buf->max - buf->wpos);
}

canonical_original_code:
unsigned long buf_left(struct buf *buf)
{
 return (buf->max - buf->wpos);
}


decompiled_code:
void __fastcall buf_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
buf_free(struct buf *buf)
{
 free(buf->buf);
 free(buf);
}


decompiled_code:
unsigned __int64 __fastcall msgbuf_init(_QWORD *a1)
{
unsigned __int64 result; // rax

result = 0xFFFFFFFF00000000LL;
*a1 = 0LL;
a1[2] = 0xFFFFFFFF00000000LL;
a1[1] = a1;
return result;
}

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

result = 0xFFFFFFFF00000000LL;
*a1 = 0LL;
a1[2] = 0xFFFFFFFF00000000LL;
a1[1] = a1;
return result;
}

original_code:
void
msgbuf_init(struct msgbuf *msgbuf)
{
 msgbuf->queued = 0;
 msgbuf->fd = -1;
 do { (&msgbuf->bufs)->tqh_first = ((void *)0); (&msgbuf->bufs)->tqh_last = &(&msgbuf->bufs)->tqh_first; } while (0);
}

variable_types: struct msgbuf { struct { struct ibuf { struct { struct ibuf *tqe_next; struct ibuf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct ibuf **tqh_last; } bufs; unsigned int queued; int fd; } *

user_defined_types: struct msgbuf { struct { struct ibuf *tqh_first; struct ibuf **tqh_last; } bufs; unsigned int queued; int fd; }


original_code:
void
buf_dequeue(struct msgbuf *msgbuf, struct buf *buf)
{
 do { if (((buf)->entry.tqe_next) != ((void *)0)) (buf)->entry.tqe_next->entry.tqe_prev = (buf)->entry.tqe_prev; else (&msgbuf->bufs)->tqh_last = (buf)->entry.tqe_prev; *(buf)->entry.tqe_prev = (buf)->entry.tqe_next; ; ; } while (0);
 if (buf->fd != -1)
  close(buf->fd);
 msgbuf->queued--;
 buf_free(buf);
}

variable_types: struct msgbuf { struct { struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; } *

variable_types:
buf
struct buf *

user_defined_types: struct msgbuf { struct { struct buf *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; }


original_code:
int
buf_write(struct msgbuf *msgbuf)
{
 struct iovec iov[1024];
 struct buf *buf;
 unsigned int i = 0;
 ssize_t n;
 bzero(&iov, sizeof(iov));
 for((buf) = ((&msgbuf->bufs)->tqh_first); (buf) != ((void *)0); (buf) = ((buf)->entry.tqe_next)) {
  if (i >= 1024)
   break;
  iov[i].iov_base = buf->buf + buf->rpos;
  iov[i].iov_len = buf->wpos - buf->rpos;
  i++;
 }
 if ((n = writev(msgbuf->fd, iov, i)) == -1) {
  if ((*__errno_location ()) == 11 || (*__errno_location ()) == 105 ||
      (*__errno_location ()) == 4)
   return (0);
  else
   return (-1);
 }
 if (n == 0) {
  (*__errno_location ()) = 0;
  return (-2);
 }
 msgbuf_drain(msgbuf, n);
 return (0);
}

canonical_original_code:
int buf_write(struct msgbuf *msgbuf)
{
 struct iovec iov[1024];
 struct buf *buf;
 unsigned int i = 0;
 long n;
 bzero(&iov, sizeof(iov));
 for((buf) = ((&msgbuf->bufs)->tqh_first); (buf) != ((void *)0); (buf) = ((buf)->entry.tqe_next)) {
  if (i >= 1024)
   break;
  iov[i].iov_base = buf->buf + buf->rpos;
  iov[i].iov_len = buf->wpos - buf->rpos;
  i++;
 }
 if ((n = writev(msgbuf->fd, iov, i)) == -1) {
  if ((*__errno_location ()) == 11 || (*__errno_location ()) == 105 ||
      (*__errno_location ()) == 4)
   return (0);
  else
   return (-1);
 }
 if (n == 0) {
  (*__errno_location ()) = 0;
  return (-2);
 }
 msgbuf_drain(msgbuf, n);
 return (0);
}

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

variable_types:
i
unsigned int

variable_types: n long


original_code:
void
colour_set_fg(struct grid_cell *gc, int c)
{
 if (c & 0x100)
  gc->flags |= 0x1;
 gc->fg = c;
}

variable_types: struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } *

variable_types: c int


original_code:
void
colour_set_bg(struct grid_cell *gc, int c)
{
 if (c & 0x100)
  gc->flags |= 0x2;
 gc->bg = c;
}

user_defined_types: struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; }


decompiled_code:
__int64 __fastcall colour_256to16(unsigned __int8 a1)
{
return (unsigned __int8)table_1[a1];
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return (unsigned __int8)table_1[a1];
}

variable_types:
c
unsigned char

variable_types:
table
unsigned char [256]

return_type: unsigned char


decompiled_code:
__int64 __fastcall colour_256to88(unsigned __int8 a1)
{
return (unsigned __int8)table_0[a1];
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
return (unsigned __int8)table_0[a1];
}


unvis

decompiled_code:
__int64 __fastcall unvis(_BYTE *a1, char a2, unsigned int *a3, char a4)
{
unsigned int v5; // edi
__int64 result; // rax
unsigned __int8 v7; // si
char v8; // al
unsigned __int8 v9; // si

v5 = *a3;
result = a4 & 1;
if ( (a4 & 1) != 0 )
{
if ( v5 - 5 <= 1 )
*a3 = 0;
else
result = v5 == 0 ? 3 : -1;
}
else
{
switch ( v5 )
{
case 0u:
*a1 = 0;
if ( a2 != 92 )
goto LABEL_17;
*a3 = 1;
result = v5;
break;
case 1u:
switch ( a2 )
{
case 10:
case 36:
*a3 = 0;
result = 3LL;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
*a1 = a2 - 48;
*a3 = 5;
break;
case 69:
*a1 = 27;
result = v5;
*a3 = 0;
break;
case 77:
*a1 = 0x80;
*a3 = 2;
break;
case 92:
*a1 = 92;
result = v5;
*a3 = 0;
break;
case 94:
goto LABEL_14;
case 97:
*a1 = 7;
result = v5;
*a3 = 0;
break;
case 98:
*a1 = 8;
result = v5;
*a3 = 0;
break;
case 102:
*a1 = 12;
result = v5;
*a3 = 0;
break;
case 110:
*a1 = 10;
result = v5;
*a3 = 0;
break;
case 114:
*a1 = 13;
result = v5;
*a3 = 0;
break;
case 115:
*a1 = 32;
result = v5;
*a3 = 0;
break;
case 116:
*a1 = 9;
result = v5;
*a3 = 0;
break;
case 118:
*a1 = 11;
result = v5;
*a3 = 0;
break;
default:
goto LABEL_21;
}
break;
case 2u:
if ( a2 == 45 )
{
*a3 = 3;
}
else
{
if ( a2 != 94 )
goto LABEL_21;
LABEL_14:
*a3 = 4;
}
break;
case 3u:
*a3 = 0;
result = 1LL;
*a1 |= a2;
break;
case 4u:
v8 = *a1 | a2 & 0x1F;
if ( a2 == 63 )
v8 = *a1 | 0x7F;
*a1 = v8;
result = 1LL;
*a3 = 0;
break;
case 5u:
v7 = a2 - 48;
if ( v7 <= 7u )
{
*a1 = v7 + 8 * *a1;
*a3 = 6;
}
else
{
*a3 = 0;
result = 2LL;
}
break;
case 6u:
v9 = a2 - 48;
*a3 = 0;
result = 2LL;
if ( v9 <= 7u )
{
a2 = v9 + 8 * *a1;
LABEL_17:
*a1 = a2;
result = 1LL;
}
break;
default:
LABEL_21:
*a3 = 0;
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2, unsigned int *a3, char a4)
{
unsigned int v5; // edi
__int64 result; // rax
unsigned __int8 v7; // si
char v8; // al
unsigned __int8 v9; // si

v5 = *a3;
result = a4 & 1;
if ( (a4 & 1) != 0 )
{
if ( v5 - 5 <= 1 )
*a3 = 0;
else
result = v5 == 0 ? 3 : -1;
}
else
{
switch ( v5 )
{
case 0u:
*a1 = 0;
if ( a2 != 92 )
goto LABEL_17;
*a3 = 1;
result = v5;
break;
case 1u:
switch ( a2 )
{
case 10:
case 36:
*a3 = 0;
result = 3LL;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
*a1 = a2 - 48;
*a3 = 5;
break;
case 69:
*a1 = 27;
result = v5;
*a3 = 0;
break;
case 77:
*a1 = 0x80;
*a3 = 2;
break;
case 92:
*a1 = 92;
result = v5;
*a3 = 0;
break;
case 94:
goto LABEL_14;
case 97:
*a1 = 7;
result = v5;
*a3 = 0;
break;
case 98:
*a1 = 8;
result = v5;
*a3 = 0;
break;
case 102:
*a1 = 12;
result = v5;
*a3 = 0;
break;
case 110:
*a1 = 10;
result = v5;
*a3 = 0;
break;
case 114:
*a1 = 13;
result = v5;
*a3 = 0;
break;
case 115:
*a1 = 32;
result = v5;
*a3 = 0;
break;
case 116:
*a1 = 9;
result = v5;
*a3 = 0;
break;
case 118:
*a1 = 11;
result = v5;
*a3 = 0;
break;
default:
goto LABEL_21;
}
break;
case 2u:
if ( a2 == 45 )
{
*a3 = 3;
}
else
{
if ( a2 != 94 )
goto LABEL_21;
LABEL_14:
*a3 = 4;
}
break;
case 3u:
*a3 = 0;
result = 1LL;
*a1 |= a2;
break;
case 4u:
v8 = *a1 | a2 & 0x1F;
if ( a2 == 63 )
v8 = *a1 | 0x7F;
*a1 = v8;
result = 1LL;
*a3 = 0;
break;
case 5u:
v7 = a2 - 48;
if ( v7 <= 7u )
{
*a1 = v7 + 8 * *a1;
*a3 = 6;
}
else
{
*a3 = 0;
result = 2LL;
}
break;
case 6u:
v9 = a2 - 48;
*a3 = 0;
result = 2LL;
if ( v9 <= 7u )
{
a2 = v9 + 8 * *a1;
LABEL_17:
*a1 = a2;
result = 1LL;
}
break;
default:
LABEL_21:
*a3 = 0;
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}

original_code:
int
unvis(char *cp, char c, int *astate, int flag)
{
 if (flag & 1) {
  if (*astate == 5 || *astate == 6) {
   *astate = 0;
   return (1);
  }
  return (*astate == 0 ? 3 : -1);
 }
 switch (*astate) {
 case 0:
  *cp = 0;
  if (c == '\\') {
   *astate = 1;
   return (0);
  }
  *cp = c;
  return (1);
 case 1:
  switch(c) {
  case '\\':
   *cp = c;
   *astate = 0;
   return (1);
  case '0': case '1': case '2': case '3':
  case '4': case '5': case '6': case '7':
   *cp = (c - '0');
   *astate = 5;
   return (0);
  case 'M':
   *cp = (char) 0200;
   *astate = 2;
   return (0);
  case '^':
   *astate = 4;
   return (0);
  case 'n':
   *cp = '\n';
   *astate = 0;
   return (1);
  case 'r':
   *cp = '\r';
   *astate = 0;
   return (1);
  case 'b':
   *cp = '\b';
   *astate = 0;
   return (1);
  case 'a':
   *cp = '\007';
   *astate = 0;
   return (1);
  case 'v':
   *cp = '\v';
   *astate = 0;
   return (1);
  case 't':
   *cp = '\t';
   *astate = 0;
   return (1);
  case 'f':
   *cp = '\f';
   *astate = 0;
   return (1);
  case 's':
   *cp = ' ';
   *astate = 0;
   return (1);
  case 'E':
   *cp = '\033';
   *astate = 0;
   return (1);
  case '\n':
   *astate = 0;
   return (3);
  case '$':
   *astate = 0;
   return (3);
  }
  *astate = 0;
  return (-1);
 case 2:
  if (c == '-')
   *astate = 3;
  else if (c == '^')
   *astate = 4;
  else {
   *astate = 0;
   return (-1);
  }
  return (0);
 case 3:
  *astate = 0;
  *cp |= c;
  return (1);
 case 4:
  if (c == '?')
   *cp |= 0177;
  else
   *cp |= c & 037;
  *astate = 0;
  return (1);
 case 5:
  if ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')) {
   *cp = (*cp << 3) + (c - '0');
   *astate = 6;
   return (0);
  }
  *astate = 0;
  return (2);
 case 6:
  *astate = 0;
  if ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')) {
   *cp = (*cp << 3) + (c - '0');
   return (1);
  }
  return (2);
 default:
  *astate = 0;
  return (-1);
 }
}

variable_types:
cp
char *

variable_types: c char

variable_types:
astate
int *

variable_types: flag int


strunvis

decompiled_code:
__int64 __fastcall strunvis(_BYTE *a1, char *a2)
{
_BYTE *v2; // r10
char v3; // al
char v4; // r9
int v5; // eax
char *v6; // r11
int v7; // eax
__int64 v8; // r10
_BYTE *v9; // r10
unsigned int v11[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a1;
v3 = *a2;
v11[0] = 0;
if ( !v3 )
{
LABEL_9:
v7 = unvis(v2, 0, v11, 1);
v9 = (_BYTE *)((v7 == 1) + v8);
*v9 = 0;
return (unsigned int)((_DWORD)v9 - (_DWORD)a1);
}
while ( 1 )
{
v4 = v3;
while ( 1 )
{
v5 = unvis(v2, v4, v11, 0);
if ( v5 != 2 )
break;
++v2;
}
if ( v5 > 2 )
break;
if ( v5 )
{
if ( v5 != 1 )
goto LABEL_11;
++v2;
}
LABEL_8:
v3 = *v6;
if ( !*v6 )
goto LABEL_9;
}
if ( v5 == 3 )
goto LABEL_8;
LABEL_11:
*v2 = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, char *a2)
{
_BYTE *v2; // r10
char v3; // al
char v4; // r9
int v5; // eax
char *v6; // r11
int v7; // eax
__int64 v8; // r10
_BYTE *v9; // r10
unsigned int v11[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a1;
v3 = *a2;
v11[0] = 0;
if ( !v3 )
{
LABEL_9:
v7 = func0(v2, 0, v11, 1);
v9 = (_BYTE *)((v7 == 1) + v8);
*v9 = 0;
return (unsigned int)((_DWORD)v9 - (_DWORD)a1);
}
while ( 1 )
{
v4 = v3;
while ( 1 )
{
v5 = func0(v2, v4, v11, 0);
if ( v5 != 2 )
break;
++v2;
}
if ( v5 > 2 )
break;
if ( v5 )
{
if ( v5 != 1 )
goto LABEL_11;
++v2;
}
LABEL_8:
v3 = *v6;
if ( !*v6 )
goto LABEL_9;
}
if ( v5 == 3 )
goto LABEL_8;
LABEL_11:
*v2 = 0;
return 0xFFFFFFFFLL;
}

original_code:
int
strunvis(char *dst, const char *src)
{
 char c;
 char *start = dst;
 int state = 0;
 while ((c = *src++)) {
 again:
  switch (unvis(dst, c, &state, 0)) {
  case 1:
   dst++;
   break;
  case 2:
   dst++;
   goto again;
  case 0:
  case 3:
   break;
  default:
   *dst = '\0';
   return (-1);
  }
 }
 if (unvis(dst, c, &state, 1) == 1)
  dst++;
 *dst = '\0';
 return (dst - start);
}

canonical_original_code:
int strunvis(char *dst, char *src)
{
 char c;
 char *start = dst;
 int state = 0;
 while ((c = *src++)) {
 again:
  switch (unvis(dst, c, &state, 0)) {
  case 1:
   dst++;
   break;
  case 2:
   dst++;
   goto again;
  case 0:
  case 3:
   break;
  default:
   *dst = '\0';
   return (-1);
  }
 }
 if (unvis(dst, c, &state, 1) == 1)
  dst++;
 *dst = '\0';
 return (dst - start);
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
start
char *

variable_types: state int


strnunvis

original_code:
ssize_t
strnunvis(char *dst, const char *src, size_t sz)
{
 char c, p;
 char *start = dst, *end = dst + sz - 1;
 int state = 0;
 if (sz > 0)
  *end = '\0';
 while ((c = *src++)) {
 again:
  switch (unvis(&p, c, &state, 0)) {
  case 1:
   if (dst < end)
    *dst = p;
   dst++;
   break;
  case 2:
   if (dst < end)
    *dst = p;
   dst++;
   goto again;
  case 0:
  case 3:
   break;
  default:
   if (dst <= end)
    *dst = '\0';
   return (-1);
  }
 }
 if (unvis(&p, c, &state, 1) == 1) {
  if (dst < end)
   *dst = p;
  dst++;
 }
 if (dst <= end)
  *dst = '\0';
 return (dst - start);
}

canonical_original_code:
long strnunvis(char *dst, char *src, unsigned long sz)
{
 char c; char p;
 char *start = dst; char *end = dst + sz - 1;
 int state = 0;
 if (sz > 0)
  *end = '\0';
 while ((c = *src++)) {
 again:
  switch (unvis(&p, c, &state, 0)) {
  case 1:
   if (dst < end)
    *dst = p;
   dst++;
   break;
  case 2:
   if (dst < end)
    *dst = p;
   dst++;
   goto again;
  case 0:
  case 3:
   break;
  default:
   if (dst <= end)
    *dst = '\0';
   return (-1);
  }
 }
 if (unvis(&p, c, &state, 1) == 1) {
  if (dst < end)
   *dst = p;
  dst++;
 }
 if (dst <= end)
  *dst = '\0';
 return (dst - start);
}

variable_types:
sz
unsigned long

variable_types: p char

variable_types:
end
char *

return_type: long