LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_pair.c
// Function: hm_pair_createnx
hm_pair_t *hm_pair_createnx(const char*key, const char*val, hm_valsize_t vallen, uint32_t expires){
	/*
	Assumptions:
	1. key   is string, up to uint16_t
	2. value is blob up to uint32_t
	3. after the key we store \0 byte, so we can use it as C string.
	4. after the value we store \0 byte, so we can use it as C string.
	*/

	if (key == NULL)
		return NULL;

	// because we need to to thombstones someday, we allow empty values
	// we do not need to change the val
	if (val == NULL)
		vallen = 0;

	hm_keysize_t keylen = strlen(key);

	if (keylen >= MAX_KEYSIZE || vallen >= MAX_VALSIZE)
		return NULL;

	hm_pair_t *pair = xmalloc(sizeof(hm_pair_t) + keylen + 1 + vallen + 1);

	if (pair == NULL)
		return NULL;

#ifdef HM_PAIR_EXPIRATION
	pair->created	= htobe64(_hm_pair_now());
	pair->expires	= htobe32(expires);
#endif

	pair->keylen	= htobe16(keylen);
	pair->vallen	= htobe32(vallen);

	// memcpy so we can switch to blobs later...
	memcpy(& pair->buffer[0], key, keylen);
	pair->buffer[keylen] = '\0';

	// this is safe with NULL pointer.
	memcpy(& pair->buffer[keylen + 1], val, vallen);
	pair->buffer[keylen + 1 + vallen] = '\0';

	// this is dummy method if no checksum
	hm_pair_checksummake(pair);

#if 0
	printf("hm_pair_t @ %12p\nbuffer %12p\nkey %u\nval %u\n", pair, pair->buffer, keylen, vallen);
	size_t i;
	for(i = 0; i < keylen + 1 + vallen + 1; i++)
		printf("%3zu | %3u | %2X | %c\n", i, pair->buffer[i], pair->buffer[i], pair->buffer[i]);
#endif

	return pair;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x19fa
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r13
testq %rsi, %rsi
cmovel %ebx, %r14d
callq 0x1070
movq %rax, %r12
movl $0xffff, %eax           # imm = 0xFFFF
movl %r12d, %ebp
andl %eax, %ebp
cmpl %eax, %ebp
sete %al
cmpl $-0x1, %r14d
sete %cl
orb %al, %cl
jne 0x19fa
movzwl %r12w, %ecx
movl %r14d, %eax
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq (%rax,%rcx), %rdi
addq $0x9, %rdi
callq 0x1130
testq %rax, %rax
je 0x19f8
movq %rax, %rbx
rolw $0x8, %r12w
movw %r12w, 0x4(%rax)
movl %r14d, %eax
bswapl %eax
movl %eax, (%rbx)
leaq 0x7(%rbx), %r12
movq %r12, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x1100
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movb %r13b, 0x7(%rbx,%rax)
movl %ebp, %eax
leaq (%rax,%rbx), %rdi
addq $0x8, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1100
leal (%r14,%rbp), %eax
incl %eax
movb %r13b, 0x7(%rbx,%rax)
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl (%rbx), %ecx
bswapl %ecx
addl %ecx, %eax
addl $0x2, %eax
testl %eax, %eax
je 0x19f2
xorl %ecx, %ecx
xorl %r13d, %r13d
xorb (%r12,%rcx), %r13b
incq %rcx
cmpq %rcx, %rax
jne 0x19e6
movb %r13b, 0x6(%rbx)
jmp 0x19fa
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_pair.c
// Function: hm_pair_printf
int hm_pair_printf(const hm_pair_t *pair){
	printf("| %s | %-12p | %-20s | %-20s |\n",
			"hm_pair_t",
			pair,
			hm_pair_getkey(pair),
			hm_pair_getval(pair)
	);

	return 0;
}

// Assembly:
movq %rdi, %rdx
leaq 0x7(%rdi), %rcx
cmpl $0x0, (%rdi)
je 0x1b33
movzwl 0x4(%rdx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
leaq (%rax,%rcx), %r8
incq %r8
jmp 0x1b36
xorl %r8d, %r8d
pushq %rax
leaq 0x15b3(%rip), %rdi      # 0x30f1
leaq 0x15cc(%rip), %rsi      # 0x3111
xorl %eax, %eax
callq 0x1090
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_disktable.c
// Function: hm_disktable_open
hm_disktable_t *hm_disktable_open(hm_disktable_t *mmf, const char *filename)
{
	FILE *F = fopen(filename, "r");

	if (F == NULL)
		return NULL;

	fseek(F, 0, SEEK_END);

	off_t size = ftello(F);

	char *mem = mmap(NULL, size, PROT_READ, MAP_SHARED, fileno(F), /* offset */ 0);

	if (mem == MAP_FAILED){
		fclose(F);
		return NULL;
	}

	//printf("%s %llu %p\n", filename, size, mem);

	mmf->F = F;
	mmf->filename = filename;
	mmf->size = size;
	mmf->mem = mem;

	// memoize count instead to read it from the disk each time
	mmf->count = _hm_disktable_getcount(mem);

	return mmf;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x15b6(%rip), %rsi      # 0x311b
movq %r14, %rdi
callq 0x10e0
testq %rax, %rax
je 0x1bda
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1140
movq %r15, %rdi
callq 0x10b0
movq %rax, %r12
movq %r15, %rdi
callq 0x1110
xorl %edi, %edi
movq %r12, %rsi
movl $0x1, %edx
movl $0x1, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x1120
cmpq $-0x1, %rax
je 0x1bd2
movq %r15, 0x10(%rbx)
movq %r14, (%rbx)
movq %r12, 0x8(%rbx)
movq %rax, 0x20(%rbx)
movq (%rax), %rax
bswapq %rax
movq %rax, 0x18(%rbx)
jmp 0x1bdc
movq %r15, %rdi
callq 0x1050
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_disktable.c
// Function: hm_disktable_opena
hm_disktable_t *hm_disktable_opena(const char *filename)
{
	hm_disktable_t *mmf = malloc(sizeof(hm_disktable_t));

	if (mmf == NULL)
		return NULL;

	if (hm_disktable_open(mmf, filename))
		return mmf;

	free(mmf);

	return NULL;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x28, %edi
callq 0x1130
testq %rax, %rax
je 0x1c1c
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1b50
testq %rax, %rax
jne 0x1c1e
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_disktable.c
// Function: hm_disktable_it_open
hm_disktable_it_t *hm_disktable_it_open(const hm_disktable_t *mmf)
{
	hm_disktable_it_t *it = malloc(sizeof(hm_disktable_it_t));

	if (it == NULL)
		return NULL;

	it->mmf = mmf;
	it->pos = 0;

	return it;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl $0x10, %edi
callq 0x1130
testq %rax, %rax
je 0x1d1d
movq %rbx, (%rax)
movq $0x0, 0x8(%rax)
jmp 0x1d1f
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_disktable.c
// Function: hm_disktable_createfrommemtable
int hm_disktable_createfrommemtable(const hm_memtable_t *memtable, const char *filename_to_write)
{
	FILE *F = fopen(filename_to_write, "w");
	if (F == NULL){
		printf("Can not create a file %s...\n", filename_to_write);
		return 1;
	}

	int result = hm_disktable_createfrommemtablef(memtable, F);

	fclose(F);

	return result;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1399(%rip), %rsi      # 0x311d
movq %rbx, %rdi
callq 0x10e0
testq %rax, %rax
je 0x1dad
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x1dc9
movl %eax, %ebx
movq %r15, %rdi
callq 0x1050
movl %ebx, %eax
jmp 0x1dc3
leaq 0x136b(%rip), %rdi      # 0x311f
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1090
movl $0x1, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_disktable.c
// Function: hm_disktable_createfrommemtablef
int hm_disktable_createfrommemtablef(const hm_memtable_t *memtable, FILE *F)
{
	uint64_t be;

	const uint64_t datacount = hm_memtable_count(memtable);
	const size_t header_size = sizeof(hm_disktable_fileformat_t);
	const size_t table_size  = sizeof(uint64_t) * datacount;

	/* preallocating the file do not really speed up the fwrite process.

	const size_t total_size  = header_size + table_size + hm_memtable_sizeof(memtable);
	posix_fallocate(fileno(F), 0, total_size);
	*/

	size_t current_place = header_size + table_size;


	// write table header (currently size only)
	hm_disktable_fileformat_t header;
	header.size = htobe64(datacount);
	fwrite(& header, sizeof(header), 1, F);

	hm_memtable_it_t *it = hm_memtable_it_open(memtable);

	if (it == NULL)
		return 1;

	const hm_pair_t *pair;

	// traverse and write the table.
	for(pair = hm_memtable_it_first(it); pair; pair = hm_memtable_it_next(it)){
		be = htobe64(current_place);
		fwrite(& be, sizeof(uint64_t), 1, F);

		current_place += hm_pair_sizeof(pair);
	}

	// traverse and write the data.
	for(pair = hm_memtable_it_first(it); pair; pair = hm_memtable_it_next(it)){
		hm_pair_fwrite(pair, F);
	}

	hm_memtable_it_close(it);

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x23c6
movq %rax, %r15
bswapq %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1170
movq %r14, %rdi
callq 0x23cf
testq %rax, %rax
je 0x1e98
movq %rax, %r14
movq %rax, %rdi
callq 0x23f8
testq %rax, %rax
je 0x1e6a
movq %rax, %r12
leaq 0x8(,%r15,8), %r13
movq %rsp, %r15
movq %r13, %rax
bswapq %rax
movq %rax, (%rsp)
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x1170
movq %r12, %rdi
callq 0x1a56
addq %rax, %r13
movq %r14, %rdi
callq 0x2412
movq %rax, %r12
testq %rax, %rax
jne 0x1e30
movq %r14, %rdi
callq 0x23f8
testq %rax, %rax
je 0x1e8c
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1aed
movq %r14, %rdi
callq 0x2412
jmp 0x1e72
movq %r14, %rdi
callq 0x23f3
xorl %eax, %eax
jmp 0x1e9d
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_create
hm_skiplist_t *hm_skiplist_create(hm_skiplist_t *l, hm_skiplist_height_t height)
{
	if (height == 0 || height > MAX_HEIGHT)
		height = DEF_HEIGHT;


	l->height = height;

	l->heads = malloc(2 * sizeof(void *) * (height + 1));

	if (l->heads == NULL)
		return NULL;

	l->loc = & l->heads[height];

	return _hm_skiplist_clear(l);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leal -0x41(%rsi), %eax
cmpb $-0x40, %al
movl $0x20, %r14d
cmovael %esi, %r14d
movb %r14b, 0x10(%rdi)
leal 0x1(%r14), %eax
movzbl %al, %edi
shll $0x4, %edi
callq 0x1130
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x1f01
movzbl %r14b, %edx
shll $0x3, %edx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x20(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %rax, %rdi
xorl %esi, %esi
callq 0x10a0
jmp 0x1f03
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_createa
hm_skiplist_t *hm_skiplist_createa(hm_skiplist_height_t height)
{
	hm_skiplist_t *l = malloc(sizeof(hm_skiplist_t));

	if (l == NULL)
		return NULL;

	if (hm_skiplist_create(l, height))
		return l;

	free(l);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %edi, %ebp
movl $0x28, %edi
callq 0x1130
testq %rax, %rax
je 0x1f3e
movq %rax, %rbx
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x1eac
testq %rax, %rax
jne 0x1f40
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_removeall
void hm_skiplist_removeall(hm_skiplist_t *l)
{
	hm_skiplist_node_t *copy;
	hm_skiplist_node_t *node;
	for(node = l->heads[0]; node; ){
		copy = node;

		node = node->next[0];

		hm_pair_free(copy->data);
		free(copy);
	}

	_hm_skiplist_clear(l);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x1f8d
movq (%r14), %rdi
movq 0x10(%r14), %r15
callq 0x1a3c
movq %r14, %rdi
callq 0x1030
movq %r15, %r14
testq %r15, %r15
jne 0x1f71
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq 0x18(%rbx), %rdi
movzbl 0x10(%rbx), %edx
shll $0x3, %edx
xorl %esi, %esi
popq %rbx
popq %r14
popq %r15
jmp 0x10a0
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_put
int hm_skiplist_put(hm_skiplist_t *l, hm_pair_t *newdata)
{
	if (newdata == NULL)
		return 0;

	const char *key = hm_pair_getkey(newdata);

	hm_skiplist_node_t *node = (hm_skiplist_node_t *) _hm_skiplist_locate(l, key, 0);

	if (node){
		// update in place. node MUST be not NULL...

		hm_pair_t *olddata = node->data;

		// check if the data in database is valid
		if (! hm_pair_valid(newdata, olddata)){
			// prevent memory leak
			hm_pair_free(newdata);
			return 0;
		}

		// leave node, update only the data
		node->data = newdata;

		l->datasize = l->datasize
			- hm_pair_sizeof(olddata)
			+ hm_pair_sizeof(newdata);

		// release old data
		hm_pair_free(olddata);

		return 1;
	}

	// create new node

	unsigned char height = _hm_skiplist_height(l);

	hm_skiplist_node_t *newnode = malloc(sizeof(hm_skiplist_node_t) + height * sizeof(void *) );
	if (newnode == NULL){
		// prevent memory leak
		hm_pair_free(newdata);
		return 0;
	}

	newnode->height = height;
	newnode->data = newdata;

	// place new node where it belongs

	hm_skiplist_height_t i;
	for(i = 0; i < height; ++i){
		if (l->loc[i]){
			// we are at the middle
			hm_skiplist_node_t *node = l->loc[i];

			newnode->next[i] = node->next[i];
			node->next[i] = newnode;
		}else{
			newnode->next[i] = l->heads[i];
			l->heads[i] = newnode;
		}
	}

	l->datasize += hm_pair_sizeof(newdata);
	l->datacount++;

	return 1;
}

// Assembly:
testq %rsi, %rsi
je 0x201d
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x1a6f
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x20d8
testq %rax, %rax
je 0x2020
movq %rax, %r12
movq (%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1ab0
testl %eax, %eax
je 0x20c5
movq %r14, (%r12)
movq (%rbx), %r12
movq %r15, %rdi
callq 0x1a56
subq %rax, %r12
movq %r14, %rdi
callq 0x1a56
addq %r12, %rax
movq %rax, (%rbx)
movq %r15, %rdi
callq 0x1a3c
jmp 0x20be
xorl %eax, %eax
retq
movb $0x1, %bpl
cmpb $0x2, 0x10(%rbx)
jb 0x203e
callq 0x1190
cmpl $0x40000000, %eax       # imm = 0x40000000
jl 0x203e
incb %bpl
cmpb 0x10(%rbx), %bpl
jb 0x2029
movzbl %bpl, %r15d
leaq 0x10(,%r15,8), %rdi
callq 0x1130
testq %rax, %rax
je 0x20c5
movb %r15b, 0x8(%rax)
movq %r14, (%rax)
shll $0x3, %r15d
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x20(%rbx), %rsi
movq (%rsi,%rcx), %rsi
testq %rsi, %rsi
je 0x2079
addq %rcx, %rsi
addq $0x10, %rsi
jmp 0x2085
leaq (,%rdx,8), %rsi
addq 0x18(%rbx), %rsi
movq (%rsi), %rdi
movq %rdi, 0x10(%rax,%rcx)
movq %rax, (%rsi)
incq %rdx
addq $0x8, %rcx
cmpq %rcx, %r15
jne 0x2063
movq %r14, %rdi
callq 0x1a56
movq %rax, %xmm0
shufpd $0x2, 0x108e(%rip), %xmm0 # xmm0 = xmm0[0],mem[1]
movdqu (%rbx), %xmm1
paddq %xmm1, %xmm0
movdqu %xmm0, (%rbx)
movl $0x1, %eax
jmp 0x20cf
movq %r14, %rdi
callq 0x1a3c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_locate
static const hm_skiplist_node_t *_hm_skiplist_locate(const hm_skiplist_t *l, const char *key, int complete_evaluation)
{
	// it is extremly dangerous to have key == NULL here.
	if (key == NULL){
		_hm_error("FATAL ERROR", __FILE__, __LINE__);
	}

	// smart over-optimizations, such skip NULL lanes or
	// start from the middle of the list did not pay off.

	int cmp = 1;

	const hm_skiplist_node_t *node = NULL;
	const hm_skiplist_node_t *prev = NULL;

	hm_skiplist_height_t height = l->height;
	while(height){
		node = prev ? prev : l->heads[height - 1];

		while(node){
			cmp = strcmp(hm_pair_getkey(node->data), key);

			if (cmp >= 0)
				break;

			prev = node;
			node = node->next[height - 1];
		}


		if (cmp == 0 && complete_evaluation == 0)
			return node;

		l->loc[height - 1] = (void *) prev;

		--height;
	}

	return cmp ? NULL : node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, 0x4(%rsp)
testq %rsi, %rsi
je 0x21b1
movq %rdi, %r15
movzbl 0x10(%rdi), %r13d
testq %r13, %r13
je 0x219c
movq %rsi, %r14
movl $0x1, %eax
xorl %ebp, %ebp
movq %rbp, %r12
testq %rbp, %rbp
jne 0x2123
movq 0x18(%r15), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %r13d, %edx
movq (%rcx,%rdx,8), %r12
testq %r12, %r12
je 0x216e
movq (%r12), %rdi
callq 0x1a6f
movq %rax, %rdi
movq %r14, %rsi
callq 0x10c0
testl %eax, %eax
jns 0x216e
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leal (%rcx,%r13), %ebx
movq %r12, %rbp
movq 0x10(%r12,%rbx,8), %r12
testq %r12, %r12
je 0x216e
movq (%r12), %rdi
callq 0x1a6f
movq %rax, %rdi
movq %r14, %rsi
callq 0x10c0
testl %eax, %eax
js 0x2149
movl %eax, %ecx
orl 0x4(%rsp), %ecx
je 0x219f
movq 0x20(%r15), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %r13d, %edx
movq %rbp, (%rcx,%rdx,8)
decq %r13
testb %r13b, %r13b
jne 0x210b
xorl %ecx, %ecx
testl %eax, %eax
cmovneq %rcx, %r12
jmp 0x219f
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x11b0
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_get
const hm_pair_t *hm_skiplist_get(const hm_skiplist_t *l, const char *key)
{
	if (key == NULL)
		return NULL;

	const hm_skiplist_node_t *node = _hm_skiplist_locate(l, key, 0);

	if (node)
		return node->data;

	return NULL;
}

// Assembly:
pushq %rbx
xorl %ebx, %ebx
testq %rsi, %rsi
je 0x21cd
xorl %edx, %edx
callq 0x20d8
testq %rax, %rax
je 0x21cd
movq (%rax), %rbx
movq %rbx, %rax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_remove
int hm_skiplist_remove(hm_skiplist_t *l, const char *key)
{
	if (key == NULL)
		return 0;

	hm_skiplist_node_t *node = (hm_skiplist_node_t *) _hm_skiplist_locate(l, key, 1);

	if ( ! node){
		// the key does not exists in the list.
		return 1;
	}

	hm_skiplist_height_t i;
	for(i = 0; i < l->height; ++i){
		hm_skiplist_node_t *prev = l->loc[i];

		if (prev){
			// check if lane go to this node...
			if (prev->next[i] == node)
				prev->next[i] = node->next[i];
		}else{
			// must be first
			if (l->heads[i] == node)
				l->heads[i] = node->next[i];
		}
	}

	l->datasize -= hm_pair_sizeof(node->data);
	l->datacount--;

	hm_pair_free(node->data);
	free(node);

	return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testq %rsi, %rsi
je 0x226b
movq %rdi, %r14
movl $0x1, %ebx
movl $0x1, %edx
callq 0x20d8
testq %rax, %rax
je 0x226d
movq %rax, %r15
movzbl 0x10(%r14), %eax
testq %rax, %rax
je 0x224a
shll $0x3, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x20(%r14), %rsi
movq (%rsi,%rcx), %rsi
testq %rsi, %rsi
je 0x2228
cmpq %r15, 0x10(%rsi,%rcx)
jne 0x223e
addq %rcx, %rsi
addq $0x10, %rsi
jmp 0x2236
movq 0x18(%r14), %rsi
cmpq %r15, (%rsi,%rcx)
jne 0x223e
leaq (%rsi,%rdx,8), %rsi
movq 0x10(%r15,%rcx), %rdi
movq %rdi, (%rsi)
incq %rdx
addq $0x8, %rcx
cmpq %rcx, %rax
jne 0x220b
movq (%r15), %rdi
callq 0x1a56
subq %rax, (%r14)
decq 0x8(%r14)
movq (%r15), %rdi
callq 0x1a3c
movq %r15, %rdi
callq 0x1030
jmp 0x226d
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_printf_lanes
void hm_skiplist_printf_lanes(const hm_skiplist_t *l)
{
	hm_skiplist_height_t i;
	for(i = l->height; i >= 0; --i){
		printf("Lane # %5u :\n", i - 1);
		_hm_skiplist_printf_lane(l, i - 1);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb 0x10(%rdi), %r15b
leaq 0xeb9(%rip), %r14       # 0x3150
movzbl %r15b, %ebp
decl %ebp
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
movq 0x18(%rbx), %rax
movzbl %bpl, %r12d
movq (%rax,%r12,8), %r13
testq %r13, %r13
je 0x22d5
movb $0x12, %bpl
movq (%r13), %rdi
callq 0x1b13
decb %bpl
je 0x22d5
movq 0x10(%r13,%r12,8), %r13
testq %r13, %r13
jne 0x22bd
decb %r15b
jmp 0x2297
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_it_open
const hm_skiplist_it_t *hm_skiplist_it_open(const hm_skiplist_t *l)
{
	hm_skiplist_it_t *it = malloc(sizeof(hm_skiplist_it_t));
	if (it == NULL)
		return NULL;

	it->l = l;
	it->node = NULL;

	return it;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl $0x10, %edi
callq 0x1130
testq %rax, %rax
je 0x22fa
movq %rbx, (%rax)
movq $0x0, 0x8(%rax)
jmp 0x22fc
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/nmmmnu[P]HM2/hm_skiplist.c
// Function: hm_skiplist_it_next
const hm_pair_t *hm_skiplist_it_next(hm_skiplist_it_t *it)
{
	if (it->node == NULL)
		return NULL;

	const hm_skiplist_node_t *node = it->node;
	node = node->next[0];
	it->node = node;

	return node ? node->data : NULL;
}

// Assembly:
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x2337
movq 0x10(%rax), %rax
movq %rax, 0x8(%rdi)
testq %rax, %rax
je 0x2337
movq (%rax), %rax
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_restore.c
// Function: main
int main(int argc, const char * argv[]) {
    if(argc != 3) {
        fprintf(stderr, "Usage: <image file name> <absolute path of rm file>\n");
        exit(1);
    }
    int fd = open(argv[1], O_RDWR);
    
    // map disk img into memory
    disk = mmap(NULL, 128 * 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if(disk == MAP_FAILED) {
        perror("mmap");
        exit(1);
    }
    
    // Init utils
    ext2_utils_init();
    
    //
    unsigned long path_len = strlen(argv[2]) + 1;
    char path[path_len];
    char path_parent[path_len];
    char path_name[EXT2_NAME_LEN];
    
    strcpy(path, argv[2]);
    clear_end_slash(path);
    cut_path(path, path_parent, path_name);
    
    // check if exist
    int parent_inode_num = get_inode_number_by_path(path_parent);
    if (parent_inode_num < 0) {
        return ENOENT;
    }
    
    struct ext2_inode *parent_inode = inode_table + parent_inode_num - 1;
    
    if (restore_from_dir_entry(parent_inode, path_name)) {
        return ENOENT;
    }
    
    
    
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
cmpl $0x3, %edi
jne 0x1361
movq %rsi, %r14
movq 0x8(%rsi), %rdi
movl $0x2, %ebx
movl $0x2, %esi
xorl %eax, %eax
callq 0x10f0
movl $0x20000, %esi          # imm = 0x20000
xorl %edi, %edi
movl $0x3, %edx
movl $0x1, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x1080
movq %rax, 0x3dee(%rip)      # 0x50b0
cmpq $-0x1, %rax
je 0x1366
callq 0x136c
movq 0x10(%r14), %r14
movq %r14, %rdi
callq 0x1070
movq %rsp, %r15
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %r15, %rdi
movq %r14, %rsi
callq 0x1060
movq %r15, %rdi
callq 0x20f1
leaq -0x120(%rbp), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2108
movq %r12, %rdi
callq 0x164e
testl %eax, %eax
js 0x1352
movq 0x3d89(%rip), %rcx      # 0x50b8
movl %eax, %eax
shlq $0x7, %rax
leaq (%rcx,%rax), %rdi
addq $-0x80, %rdi
leaq -0x120(%rbp), %rsi
callq 0x1bee
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
addl %ebx, %ebx
movl %ebx, %eax
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x1140
callq 0x1165
nop
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: ext2_utils_init
void ext2_utils_init() {
    // Init global varible.
    // setup sb, gdt, block_bitmap, inode_bitmap, inode_table
    sb = (struct ext2_super_block *)(disk + EXT2_BLOCK_SIZE);
    gdt = (struct ext2_group_desc *)(disk + EXT2_BLOCK_SIZE + sizeof(struct ext2_super_block));
    block_bitmap = (unsigned char *)(disk + (gdt->bg_block_bitmap * EXT2_BLOCK_SIZE));
    inode_bitmap = (unsigned char *)(disk + (gdt->bg_inode_bitmap * EXT2_BLOCK_SIZE));
    inode_table = (struct ext2_inode *)(disk + (gdt->bg_inode_table * EXT2_BLOCK_SIZE));
    return;
}

// Assembly:
leaq 0x3d3d(%rip), %rax      # 0x50b0
movq (%rax), %rax
leaq 0x400(%rax), %rcx
leaq 0x3d3c(%rip), %rdx      # 0x50c0
movq %rcx, (%rdx)
leaq 0x800(%rax), %rcx
leaq 0x3d33(%rip), %rdx      # 0x50c8
movq %rcx, (%rdx)
movl 0x800(%rax), %ecx
shll $0xa, %ecx
addq %rax, %rcx
leaq 0x3d25(%rip), %rdx      # 0x50d0
movq %rcx, (%rdx)
movl 0x804(%rax), %ecx
shll $0xa, %ecx
addq %rax, %rcx
leaq 0x3d17(%rip), %rdx      # 0x50d8
movq %rcx, (%rdx)
movl 0x808(%rax), %ecx
shll $0xa, %ecx
addq %rax, %rcx
leaq 0x3ce1(%rip), %rax      # 0x50b8
movq %rcx, (%rax)
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: get_inode_number_by_name
int get_inode_number_by_name(int in_which_dir_num,
                             char *name)
{
    // Inode index = inode number - 1
    // Get inode by inode index.
    struct ext2_inode *in_which_inode = inode_table + in_which_dir_num - 1;
    
    int curr_i_block = 0;
    int *in_which_inode_i_block_array = read_i_block_into_array(in_which_inode);
    // walk through each datablock of parent dir
    while (in_which_inode_i_block_array[curr_i_block] != -1) {
        unsigned char *in_which_inode_data = disk + EXT2_BLOCK_SIZE * in_which_inode_i_block_array[curr_i_block];
        
        // Dir entry struct
        struct ext2_dir_entry *entry;
        // Offset in data block
        int curr_entry_off = 0;
        // walk through datablock
        while (curr_entry_off < EXT2_BLOCK_SIZE) {
            entry = (struct ext2_dir_entry *)(in_which_inode_data + curr_entry_off);
            if (strncmp(entry->name, name, entry->name_len) == 0) {
                return entry->inode;
            }
            curr_entry_off += entry->rec_len;
        }
        curr_i_block++;
    }
    // If reach here no match found
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
leaq 0x3cc5(%rip), %rax      # 0x50b8
movq (%rax), %rax
movslq %edi, %rcx
shlq $0x7, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x80, %rdi
callq 0x14ca
movq %rax, 0x10(%rsp)
leaq 0x3c9a(%rip), %rax      # 0x50b0
movq (%rax), %r15
movl $0x0, 0xc(%rsp)
movslq 0xc(%rsp), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
cmpq $-0x1, %rax
je 0x14af
shlq $0xa, %rax
leaq (%r15,%rax), %r12
leaq (%r15,%rax), %rdi
addq $0x8, %rdi
movzbl -0x2(%rdi), %edx
movq %rbx, %rsi
callq 0x1050
xorl %r14d, %r14d
testl %eax, %eax
je 0x1491
movq %r12, %r13
movzwl 0x4(%r13), %eax
movl %r14d, %r14d
addq %rax, %r14
cmpl $0x400, %r14d           # imm = 0x400
setae %bpl
jae 0x14a0
leaq (%r12,%r14), %r13
leaq (%r12,%r14), %rdi
addq $0x8, %rdi
movzbl -0x2(%rdi), %edx
movq %rbx, %rsi
callq 0x1050
testl %eax, %eax
jne 0x145b
jmp 0x1496
xorl %ebp, %ebp
movq %r12, %r13
movl (%r13), %eax
movl %eax, 0x8(%rsp)
jmp 0x14a4
incl 0xc(%rsp)
testb %bpl, %bpl
jne 0x1421
jmp 0x14b7
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl 0x8(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: read_i_block_into_array
int *read_i_block_into_array(struct ext2_inode *inode)
{
    int total_blocks = inode->i_blocks/2;
    int *result = malloc(sizeof(int) * (total_blocks + 1));
    int num_block_read = 0;
    int i;
    
    for (i = 0; i < 12; i++) {
        result[i] = inode->i_block[i];
        num_block_read++;
        if (num_block_read == total_blocks) {
            result[i + 1] = -1;
            return result;
        }
    }
    
    // If reach here, go into indirect_block
    num_block_read++;
    
    // Since disk size is 128kb, only consider the cases that
    //      there is only one indirect block.
    unsigned int *indirect_block = (unsigned int *)(disk + EXT2_BLOCK_SIZE * inode->i_block[12]);
    for (i = 0; i < EXT2_BLOCK_SIZE/4; i++) {
        result[12 + i] = indirect_block[i];
        num_block_read++;
        if (num_block_read == total_blocks) {
            result[12 + i + 1] = -1;
            return result;
        }
    }
    
    // If reach here, error
    free(result);
    return NULL;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x1c(%rdi), %r14d
shrl %r14d
leaq 0x4(,%r14,4), %rdi
callq 0x10e0
leal -0x1(%r14), %edx
cmpl $0xb, %edx
movl $0xb, %ecx
cmovbl %edx, %ecx
xorl %esi, %esi
movl 0x28(%rbx,%rsi,4), %edi
movl %edi, (%rax,%rsi,4)
cmpq %rsi, %rdx
je 0x1548
incq %rsi
cmpq $0xc, %rsi
jne 0x14f6
leaq 0x3b9e(%rip), %rsi      # 0x50b0
movl 0x58(%rbx), %edx
shll $0xa, %edx
addq (%rsi), %rdx
subl %ecx, %r14d
addl $-0x3, %r14d
xorl %ecx, %ecx
movl (%rdx,%rcx,4), %esi
movl %esi, 0x30(%rax,%rcx,4)
cmpl %ecx, %r14d
je 0x1552
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x1524
movq %rax, %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x155a
movl $0xffffffff, 0x4(%rax,%rsi,4) # imm = 0xFFFFFFFF
jmp 0x155a
movl $0xffffffff, 0x34(%rax,%rcx,4) # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: get_inode_number_by_path_helper
int get_inode_number_by_path_helper(char *path,
                                    int curr_inode_num)
{
    // Inode index = inode number - 1
    // Get inode by inode index.
    struct ext2_inode *curr_inode = inode_table + curr_inode_num - 1;
    
    // Prepare path
    // For example.
    // "d1/d2/d3" -> path_next_call: "d2/d3", dir_name: "d1"
    // "d3"       -> path_next_call: NULL   , dir_name: "d3"
    char *path_next_call = strchr(path, '/');
    char dir_name[EXT2_NAME_LEN];
    
    
    /*
     *  Base case:
     *      inode ref an reg file and not reach end return -1
     *          or
     *      reach end of path
     */
    
    if ((curr_inode->i_mode & EXT2_S_IFREG) &&
        path_next_call != NULL) {
        return -1;
    }
    
    // reach end of path, then search the inode number current dir.
    if (path_next_call == NULL) {
        memcpy(dir_name, path, strlen(path));
        return get_inode_number_by_name(curr_inode_num, dir_name);
    }
    
    
    /*
     *  Recursive part
     */
    
    // Prepare dir_name
    int i;
    int first_slash_index = 0;
    for (i = 0; i < strlen(path); i++) {
        if (path[i] == '/') {
            first_slash_index = i;
            break;
        }
    }
    memcpy(dir_name, path, first_slash_index);
    dir_name[first_slash_index] = '\0';
    
    // Enter next level dir
    // Before enter next level, check if entry exist.
    int next_level_inode = get_inode_number_by_name(curr_inode_num, dir_name);
    if (next_level_inode == -1) {
        return -1;
    }
    
    return get_inode_number_by_path_helper(path_next_call + 1, next_level_inode);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %esi, %ebx
movq %rdi, %r15
leaq 0x3b39(%rip), %rax      # 0x50b8
movq (%rax), %r12
movslq %esi, %r13
shlq $0x7, %r13
movl $0x2f, %esi
callq 0x1090
movq %rax, %r14
cmpw $0x0, -0x80(%r12,%r13)
sets %al
testq %r14, %r14
setne %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %cl, %al
jne 0x163a
movq %r15, %rdi
callq 0x1070
testq %r14, %r14
je 0x161d
testq %rax, %rax
je 0x15d7
xorl %r12d, %r12d
cmpb $0x2f, (%r15,%r12)
je 0x15da
incq %r12
cmpq %r12, %rax
jne 0x15c8
xorl %r12d, %r12d
movq %rsp, %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x10c0
movb $0x0, (%rsp,%r12)
movl %ebx, %edi
movq %r13, %rsi
callq 0x13db
cmpl $-0x1, %eax
je 0x163a
incq %r14
movq %r14, %rdi
movl %eax, %esi
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1562
movq %rsp, %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10c0
movl %ebx, %edi
movq %r14, %rsi
callq 0x13db
movl %eax, %ebp
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: inode_mkdir
int inode_mkdir(int parent,
                char *new_dir_name)
{
    struct ext2_inode *parent_inode = inode_table + parent - 1;
    
    int new_dir_inode_num = ialloc();
    int new_dir_datablock_idx = dalloc();
    if (new_dir_inode_num < 0 || new_dir_datablock_idx < 0) {
        return ENOSPC;
    }
    
    // Build inode and datablock for new dir
    struct ext2_inode *new_dir_inode = inode_table + new_dir_inode_num - 1;
    unsigned char *new_dir_datablock = disk + (EXT2_BLOCK_SIZE * new_dir_datablock_idx);
    
    new_dir_inode->i_mode           = 0x0000 | EXT2_S_IFDIR;
    new_dir_inode->i_uid            = 0;
    new_dir_inode->i_size           = EXT2_BLOCK_SIZE;
    new_dir_inode->i_ctime          = 0;
    new_dir_inode->i_mtime          = 0;
    new_dir_inode->i_dtime          = 0;
    new_dir_inode->i_gid            = 0;
    new_dir_inode->i_links_count    = 0;
    new_dir_inode->i_blocks         = new_dir_inode->i_size/512;
    new_dir_inode->i_flags          = 0;
    new_dir_inode->osd1             = 0;
    new_dir_inode->i_block[0]       = new_dir_datablock_idx;
    new_dir_inode->i_generation     = 0;
    new_dir_inode->i_file_acl       = 0;
    new_dir_inode->i_dir_acl        = 0;
    // padding
    memset(new_dir_inode->extra, 0, 3);
    
    // Init dir_entry datablock for new dir
    init_dir_entry(new_dir_datablock, new_dir_inode_num, parent);
    
    // Add inode back to parent dir entry
    add_to_dir_entry(parent_inode, new_dir_inode_num, new_dir_name, EXT2_FT_DIR);
    
    // Update gdt
    gdt->bg_used_dirs_count++;
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r15d
leaq 0x3a1e(%rip), %r13      # 0x50b8
movq (%r13), %r12
callq 0x1790
movl %eax, %ebp
callq 0x1815
movl $0x1c, %r14d
movl %ebp, %ecx
orl %eax, %ecx
js 0x177e
movslq %r15d, %rcx
movq (%r13), %rdx
movl %ebp, %esi
shlq $0x7, %rsi
leaq 0x39e2(%rip), %rdi      # 0x50b0
movq (%rdi), %r8
movl %eax, %r9d
shll $0xa, %r9d
movabsq $0x40000004000, %rdi    # imm = 0x40000004000
movq %rdi, -0x80(%rdx,%rsi)
xorps %xmm0, %xmm0
movups %xmm0, -0x74(%rdx,%rsi)
movq $0x2, -0x64(%rdx,%rsi)
xorl %r14d, %r14d
movl %r14d, -0x5c(%rdx,%rsi)
movl %eax, -0x58(%rdx,%rsi)
movq $0x0, -0x1c(%rdx,%rsi)
movl %r14d, -0x14(%rdx,%rsi)
movb $0x0, -0xa(%rdx,%rsi)
movw $0x0, -0xc(%rdx,%rsi)
movl %ebp, (%r8,%r9)
movb $0x2e, 0x8(%r8,%r9)
movl $0x201000c, 0x4(%r8,%r9) # imm = 0x201000C
movq (%r13), %rax
incw -0x66(%rax,%rsi)
movl %ecx, 0xc(%r8,%r9)
shlq $0x7, %rcx
leaq (%r12,%rcx), %rdi
addq $-0x80, %rdi
movw $0x2e2e, 0x14(%r8,%r9)  # imm = 0x2E2E
movl $0x20203f4, 0x10(%r8,%r9) # imm = 0x20203F4
incw -0x66(%rax,%rcx)
movl %ebp, %esi
movq %rbx, %rdx
movl $0x2, %ecx
callq 0x18d6
leaq 0x3951(%rip), %rax      # 0x50c8
movq (%rax), %rax
incw 0x10(%rax)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: ialloc
int ialloc(void) {
    if (gdt->bg_free_inodes_count == 0) {
        return -1;
    }
    
    unsigned char *inode_bitmap_ptr;
    int curr_byte = 0;
    int vaild_byte_count = sb->s_inodes_count/8;
    int curr_inode_num = 0;
    int i;
    
    while (curr_byte < vaild_byte_count) {
        inode_bitmap_ptr = inode_bitmap + curr_byte;
        for (i = 0; i < 8; i++) {
            curr_inode_num++;
            if (!((*inode_bitmap_ptr)>>i & 1)){
                // Set inode bitmap
                *inode_bitmap_ptr = *inode_bitmap_ptr | (1 << i);
                // Set gdt
                gdt->bg_free_inodes_count--;
                sb->s_free_inodes_count--;
                return curr_inode_num;
            }
            
        }
        curr_byte++;
    }
    
    return -1;
}

// Assembly:
leaq 0x3931(%rip), %rax      # 0x50c8
movq (%rax), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpw $0x0, 0xe(%rdx)
je 0x1812
leaq 0x3913(%rip), %rdx      # 0x50c0
movq (%rdx), %rsi
movl (%rsi), %esi
cmpq $0x8, %rsi
jb 0x1812
shrl $0x3, %esi
leaq 0x3916(%rip), %rcx      # 0x50d8
movq (%rcx), %r8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movzbl (%r8,%r9), %r10d
xorl %ecx, %ecx
movl $0x1, %r11d
shll %cl, %r11d
btl %ecx, %r10d
jae 0x17fc
incl %ecx
cmpl $0x8, %ecx
jne 0x17d4
incq %r9
addl $-0x8, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %r9
jne 0x17cd
jmp 0x1812
orl %r11d, %r10d
movb %r10b, (%r8,%r9)
movq (%rax), %rax
decw 0xe(%rax)
movq (%rdx), %rax
decl 0x10(%rax)
subl %edi, %ecx
movl %ecx, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: dalloc
int dalloc(void) {
    if (gdt->bg_free_blocks_count == 0) {
        return -1;
    }
    
    unsigned char *block_bitmap_ptr;
    int curr_byte = 0;
    int vaild_byte_count = sb->s_blocks_count/8;
    int curr_inode_num = 0;
    int i;
    
    while (curr_byte < vaild_byte_count) {
        block_bitmap_ptr = block_bitmap + curr_byte;
        for (i = 0; i < 8; i++) {
            if (!((*block_bitmap_ptr)>>i & 1)){
                // Update block bitmap
                *block_bitmap_ptr = *block_bitmap_ptr | (1 << i);
                // Update gdt
                gdt->bg_free_blocks_count--;
                sb->s_free_blocks_count--;
                return curr_inode_num;
            }
            curr_inode_num++;
        }
        curr_byte++;
    }
    
    return -1;
}

// Assembly:
pushq %rbx
leaq 0x38ab(%rip), %rdx      # 0x50c8
movq (%rdx), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpw $0x0, 0xc(%rcx)
je 0x1894
leaq 0x388d(%rip), %rsi      # 0x50c0
movq (%rsi), %rcx
movl 0x4(%rcx), %edi
cmpq $0x8, %rdi
jb 0x1894
shrl $0x3, %edi
leaq 0x3887(%rip), %rcx      # 0x50d0
movq (%rcx), %r9
xorl %r8d, %r8d
xorl %r10d, %r10d
movzbl (%r9,%r10), %r11d
xorl %ecx, %ecx
movl $0x1, %ebx
shll %cl, %ebx
btl %ecx, %r11d
jae 0x187b
incl %ecx
cmpl $0x8, %ecx
jne 0x1859
incq %r10
addl $-0x8, %r8d
cmpq %rdi, %r10
jne 0x1852
jmp 0x1894
orl %ebx, %r11d
movb %r11b, (%r9,%r10)
movq (%rdx), %rax
decw 0xc(%rax)
movq (%rsi), %rax
decl 0xc(%rax)
subl %r8d, %ecx
movl %ecx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: remove_from_dir_entry
int remove_from_dir_entry(struct ext2_inode * parent_inode,
                          char *name)
{
    int *parent_inode_iblock_array = read_i_block_into_array(parent_inode);
    struct ext2_dir_entry *prev_entry;
    struct ext2_dir_entry *curr_entry;
    
    int i = -1;
    int curr_offset = 1024;
    while (parent_inode_iblock_array[i] != -1) {
        if (curr_offset == EXT2_BLOCK_SIZE) {
            i++;
            curr_offset = 0;
            prev_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
            curr_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
        }
        
        if (strncmp(name, curr_entry->name, curr_entry->name_len) == 0) {
            // do entry del
            prev_entry->rec_len += curr_entry->rec_len;
            // update inode link count
            struct ext2_inode *curr_inode = inode_table + curr_entry->inode - 1;
            curr_inode->i_links_count--;
            
            // inode link count drop to 0
            if (curr_inode->i_links_count == 0) {
                free_inode(curr_entry->inode);
            }
            
            free(parent_inode_iblock_array);
            return 0;
        }
        
        prev_entry = curr_entry;
        curr_offset += curr_entry->rec_len;
        curr_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
    }
    
    free(parent_inode_iblock_array);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, (%rsp)
callq 0x14ca
movq %rax, %rbx
cmpl $-0x1, -0x4(%rax)
je 0x1b21
leaq 0x3603(%rip), %rax      # 0x50b0
movq (%rax), %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x400, %r12d           # imm = 0x400
cmpl $0x400, %r12d           # imm = 0x400
jne 0x1add
movslq %ebp, %rax
incl %ebp
movslq 0x4(%rbx,%rax,4), %r13
shlq $0xa, %r13
addq %r15, %r13
xorl %r12d, %r12d
movq %r13, %r14
jmp 0x1ae3
movq %r14, %r13
movq %rax, %r14
leaq 0x8(%r14), %rsi
movzbl 0x6(%r14), %edx
movq (%rsp), %rdi
callq 0x1050
movzwl 0x4(%r14), %ecx
testl %eax, %eax
je 0x1b28
movslq %r12d, %r12
addq %rcx, %r12
movslq %ebp, %rax
movslq (%rbx,%rax,4), %rcx
movq %rcx, %rdx
shlq $0xa, %rdx
movq %r12, %rax
addq %r15, %rax
addq %rdx, %rax
cmpq $-0x1, %rcx
jne 0x1abb
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1b4f
addw %cx, 0x4(%r13)
leaq 0x3584(%rip), %rax      # 0x50b8
movq (%rax), %rax
movl (%r14), %edi
movq %rdi, %rcx
shlq $0x7, %rcx
xorl %ebp, %ebp
decw -0x66(%rax,%rcx)
jne 0x1b4f
callq 0x1b68
movq %rbx, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: free_inode
void free_inode(int inode_num){
    struct ext2_inode *inode = inode_table +  inode_num - 1;
    int *inode_datablock_array = read_i_block_into_array(inode);
    
    // set del time
    inode->i_dtime = (unsigned int)time(NULL);
    
    // Mark bitmap as free
    
    int i = 0;
    while (inode_datablock_array[i] != -1) {
        dfree(inode_datablock_array[i]);
        i++;
    }
    if (i >= 12) { // free indirect block
        dfree(inode->i_block[12]);
    }
    
    // free inode
    ifree(inode_num);
    
    free(inode_datablock_array);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %edi, %ebx
leaq 0x353e(%rip), %rax      # 0x50b8
movq (%rax), %r12
movslq %edi, %r13
shlq $0x7, %r13
leaq (%r12,%r13), %r15
addq $-0x80, %r15
movq %r15, %rdi
callq 0x14ca
movq %rax, %r14
xorl %edi, %edi
callq 0x10d0
movl %eax, 0x14(%r15)
movl (%r14), %edi
cmpl $-0x1, %edi
je 0x1bd6
addq %r13, %r12
movq $-0x1, %r15
callq 0x1ffa
movl 0x8(%r14,%r15,4), %edi
incq %r15
cmpl $-0x1, %edi
jne 0x1bb4
cmpq $0xb, %r15
jb 0x1bd6
movl -0x28(%r12), %edi
callq 0x1ffa
movl %ebx, %edi
callq 0x1f9c
movq %r14, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1030
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: restore_inode_bitmap
int restore_inode_bitmap(int inode_num) {
    unsigned char *ptr;
    int in_which_byte;
    int off;
    
    in_which_byte = inode_num/8;
    if (inode_num%8) {
        in_which_byte++;
        off = inode_num%8;
    } else {
        off = 8;
    }
    
    
    ptr = inode_bitmap + (in_which_byte - 1);
    
    // check if in use
    if ((*ptr)>>(off - 1) & 1) {
        return -1;
    }
    
    // mark it back to used
    
    *ptr = *ptr | (1<<(off - 1));
    
    //update superblock and gdt
    gdt->bg_free_inodes_count--;
    sb->s_free_inodes_count--;
    
    return 0;
}

// Assembly:
leal 0x7(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
sarl $0x3, %edx
andl $-0x8, %eax
subl %eax, %edi
movl %edi, %ecx
subl $0x1, %ecx
sbbl $0x0, %edx
movl $0x1, %eax
shll %cl, %eax
cmpl $0x1, %edi
leaq 0x3281(%rip), %rcx      # 0x50d8
movq (%rcx), %rcx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %edi
movl $0x80, %esi
cmovael %eax, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %edi, %esi
je 0x1e73
retq
orb %dil, %sil
movb %sil, (%rcx,%rdx)
leaq 0x3247(%rip), %rax      # 0x50c8
movq (%rax), %rax
decw 0xe(%rax)
leaq 0x3231(%rip), %rax      # 0x50c0
movq (%rax), %rax
decl 0x10(%rax)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: restore_block_bitmap
int restore_block_bitmap(int block_num) {
    block_num++;
    
    unsigned char *ptr;
    int in_which_byte;
    int off;
    
    in_which_byte = block_num/8;
    if (block_num%8) {
        in_which_byte++;
        off = block_num%8;
    } else {
        off = 8;
    }
    
    
    ptr = block_bitmap + (in_which_byte - 1);
    
    // check if in use
    if ((*ptr)>>(off - 1) & 1) {
        return -1;
    }
    
    // mark it back to used
    
    *ptr = *ptr | (1<<(off - 1));
    
    //update superblock and gdt
    gdt->bg_free_blocks_count--;
    sb->s_free_blocks_count--;
    
    return 0;
    
}

// Assembly:
leal 0x1(%rdi), %eax
leal 0x8(%rdi), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
movl %ecx, %eax
sarl $0x3, %eax
andl $-0x8, %ecx
negl %ecx
leal (%rdi,%rcx), %edx
incl %edx
movl %edx, %ecx
subl $0x1, %ecx
sbbl $0x0, %eax
movl $0x1, %r8d
shll %cl, %r8d
cmpl $0x1, %edx
leaq 0x3203(%rip), %rcx      # 0x50d0
movq (%rcx), %rcx
movslq %eax, %rdx
movzbl (%rcx,%rdx), %edi
movl $0x80, %esi
cmovael %r8d, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %edi, %esi
je 0x1eea
retq
orb %dil, %sil
movb %sil, (%rcx,%rdx)
leaq 0x31d0(%rip), %rax      # 0x50c8
movq (%rax), %rax
decw 0xc(%rax)
leaq 0x31ba(%rip), %rax      # 0x50c0
movq (%rax), %rax
decl 0xc(%rax)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: write_array_into_i_block
void write_array_into_i_block(struct ext2_inode *inode,
                              int *array,
                              int array_size)
{
    int num_block_written = 0;
    int i;
    
    for (i = 0; i < 12; i++) {
        inode->i_block[i] = array[i];
        num_block_written++;
        if (num_block_written == array_size) {
            return;
        }
    }
    
    // If reach here, write into indirect_block
    // allocate a space for indirect_block
    int indirect_block_num = dalloc();
    if (indirect_block_num < 0) {
        exit(ENOSPC);
    }
    inode->i_block[12] = indirect_block_num;
    inode->i_blocks += 2;
    
    // Since disk size is 128kb, only consider the cases that
    //      there is only one indirect block.
    unsigned int *indirect_block = (unsigned int *)(disk + EXT2_BLOCK_SIZE * inode->i_block[12]);
    for (i = 0; i < EXT2_BLOCK_SIZE/4; i++) {
        indirect_block[i] = array[12 + i];
        num_block_written++;
        if (num_block_written == array_size) {
            return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leal -0x1(%rbx), %eax
cmpl $0xb, %eax
movl $0xb, %ebp
cmovbl %eax, %ebp
xorl %ecx, %ecx
movl (%r14,%rcx,4), %edx
movl %edx, 0x28(%r15,%rcx,4)
cmpq %rcx, %rax
je 0x1f87
incq %rcx
cmpq $0xc, %rcx
jne 0x1f2e
callq 0x1815
testl %eax, %eax
js 0x1f92
movl %eax, 0x58(%r15)
addl $0x2, 0x1c(%r15)
leaq 0x3152(%rip), %rcx      # 0x50b0
shll $0xa, %eax
addq (%rcx), %rax
subl %ebp, %ebx
addl $-0x2, %ebx
xorl %ecx, %ecx
movl 0x30(%r14,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
cmpl %ecx, %ebx
je 0x1f87
leaq 0x1(%rcx), %rdx
cmpq $0xff, %rcx
movq %rdx, %rcx
jne 0x1f6b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x1c, %edi
callq 0x1110
// File: /workspace/github_c_makefile_star2_O1/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: ifree
void ifree(int inode_num) {
    unsigned char *ptr;
    int in_which_byte;
    int off;
    
    in_which_byte = inode_num/8;
    if (inode_num%8) {
        in_which_byte++;
        off = inode_num%8;
    } else {
        off = 8;
    }
    
    
    ptr = inode_bitmap + (in_which_byte - 1);
    *ptr = *ptr & ~(1<<(off - 1));
    
    //update superblock and gdt
    gdt->bg_free_inodes_count++;
    sb->s_free_inodes_count++;
}

// Assembly:
leal 0x7(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
sarl $0x3, %edx
andl $-0x8, %eax
subl %eax, %edi
movl %edi, %ecx
subl $0x1, %ecx
sbbl $0x0, %edx
movl $0x1, %eax
shll %cl, %eax
cmpl $0x1, %edi
leaq 0x3111(%rip), %rcx      # 0x50d8
movq (%rcx), %rcx
notb %al
movzbl %al, %eax
movl $0x7f, %esi
cmovael %eax, %esi
movslq %edx, %rax
andb %sil, (%rcx,%rax)
leaq 0x30e3(%rip), %rax      # 0x50c8
movq (%rax), %rax
incw 0xe(%rax)
leaq 0x30cd(%rip), %rax      # 0x50c0
movq (%rax), %rax
incl 0x10(%rax)
retq