LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/heap.c
// Function: tt_heap_init
int tt_heap_init(struct tt_heap *heap)
{
	int ret = _tt_key_select(&heap->num);
	if (ret)
		return ret;

	if (heap->htype == TT_HEAP_MIN) {
		tt_debug("Min-heap initialized");
		heap->_heapify = tt_heap_heapify_min;
		heap->_adjust = tt_heap_adjust_min;
	} else {
		tt_debug("Max-heap initialized");
		heap->_heapify = tt_heap_heapify_max;
		heap->_adjust = tt_heap_adjust_max;
	}

	heap->__heaplen = 0;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x2818
movl %eax, %ebp
testl %eax, %eax
jne 0x38cd
cmpl $0x1, 0x2c(%rbx)
leaq 0x1e91(%rip), %rax      # 0x5712
leaq 0x1e9f(%rip), %rdx      # 0x5727
cmoveq %rax, %rdx
leaq 0x47(%rip), %rax        # 0x38da
leaq 0x55(%rip), %r14        # 0x38ef
cmoveq %rax, %r14
leaq 0x3e(%rip), %rax        # 0x38e3
leaq 0x49(%rip), %r15        # 0x38f5
cmoveq %rax, %r15
leaq 0x1e4e(%rip), %rsi      # 0x5705
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x258c
movq %r14, 0x38(%rbx)
movq %r15, 0x40(%rbx)
andl $0x0, 0x30(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/heap.c
// Function: tt_heap_heapify_internal
static inline void tt_heap_heapify_internal(
		struct tt_heap *heap, int index,
		int (*cmp)(const struct tt_key *, const void *, const void*))
{
	while (index < heap->__heaplen / 2) {
		/* Compare and swap with [2*index+1], [2*index+2] */
		void *iptr = heap_ptr(heap, index);
		index = index * 2 + 1;	/* Left child */
		void *lptr = heap_ptr(heap, index);
		void *rptr = lptr + heap->num.size;

		void *swaptr = iptr;
		if (cmp(&heap->num, swaptr, lptr) < 0)
			swaptr = lptr;
		if (index < heap->__heaplen - 1 &&
				cmp(&heap->num, swaptr, rptr) < 0) {
			swaptr = rptr;
			index++;	/* Right child */
		}
		if (swaptr != iptr)
			heap->num.swap(&heap->num, iptr, swaptr);
		else
			break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, 0x8(%rsp)
movl %esi, %ebx
movq %rdi, %r14
movl 0x30(%r14), %eax
shrl %eax
cmpl %eax, %ebx
jae 0x39aa
movq 0x20(%r14), %rax
movslq (%r14), %r15
movl %r15d, %ecx
imull %ebx, %ecx
movslq %ecx, %r12
addq %rax, %r12
movq %rbx, 0x10(%rsp)
leal 0x1(,%rbx,2), %ebx
movl %r15d, %ecx
imull %ebx, %ecx
movslq %ecx, %rbp
addq %rax, %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x8(%rsp)
movq %rbp, %r13
testl %eax, %eax
js 0x3966
movq %r12, %r13
movl 0x30(%r14), %eax
decl %eax
cmpl %eax, %ebx
jae 0x3993
addq %r15, %rbp
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq *0x8(%rsp)
testl %eax, %eax
jns 0x3993
movq 0x10(%rsp), %rax
addl %eax, %eax
addl $0x2, %eax
movl %eax, %ebx
movq %rbp, %r13
cmpq %r12, %r13
je 0x39aa
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *0x10(%r14)
jmp 0x3916
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/heap.c
// Function: tt_heap_adjust_internal
static inline void tt_heap_adjust_internal(
		struct tt_heap *heap, int index,
		int (*cmp)(const struct tt_key *, const void *, const void*))
{
	/* Buffer for one element */
	char tmp[heap->num.size] _tt_align(8);	/* C99 VLA, huha! */
	void *v = heap_ptr(heap, index);
	heap->num._set(&heap->num, tmp, v);

	while (index > 0) {
		int parent = (index - 1) / 2;
		void *pv = heap_ptr(heap, parent);
		if (cmp(&heap->num, tmp, pv) <= 0)
			break;
		heap->num._set(&heap->num, v, pv);
		v = pv;
		index = parent;
	}

	heap->num._set(&heap->num, v, tmp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, -0x30(%rbp)
movl %esi, %r14d
movq %rdi, %rbx
movl (%rdi), %eax
movq %rsp, %r12
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
subq %rcx, %r12
movq %r12, %rsp
imull %esi, %eax
movslq %eax, %r13
addq 0x20(%rdi), %r13
movq %r12, %rsi
movq %r13, %rdx
callq *0x18(%rdi)
testl %r14d, %r14d
jle 0x3a3c
decl %r14d
shrl %r14d
movslq (%rbx), %rax
movq %r14, %r15
imulq %rax, %r15
addq 0x20(%rbx), %r15
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *-0x30(%rbp)
testl %eax, %eax
jle 0x3a3c
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x18(%rbx)
movq %r15, %r13
jmp 0x3a02
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq *0x18(%rbx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_bintree_init
void tt_bintree_init(struct tt_bintree *tree)
{
	if (!tree->ops) {
		tt_debug("Red-Black tree initialized");
		tree->ops = &tt_rbtree_ops;
	} else {
		tt_debug("Binary tree initialized");
	}

	if (!tree->knum.swap)
		tree->knum.swap = tt_bintree_swap_dummy;
	_tt_key_select(&tree->knum);

	tree->_root = NULL;
	tree->_count = 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0x20(%rdi)
je 0x3a7d
leaq 0x1cd2(%rip), %rsi      # 0x573c
leaq 0x1cf6(%rip), %rdx      # 0x5767
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x258c
jmp 0x3aa0
leaq 0x1cb8(%rip), %rsi      # 0x573c
leaq 0x1cc1(%rip), %rdx      # 0x574c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x258c
leaq 0x463c(%rip), %rax      # 0x80d8
movq %rax, 0x20(%rbx)
cmpq $0x0, 0x10(%rbx)
jne 0x3ab2
leaq 0x17(%rip), %rax        # 0x3ac5
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x2818
andq $0x0, 0x28(%rbx)
andl $0x0, 0x30(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_bintree_free_internal
static void tt_bintree_free_internal(struct tt_bintree_node *node)
{
	if (node) {
		tt_bintree_free_internal(node->left);
		tt_bintree_free_internal(node->right);
		free(node);
	}
}

// Assembly:
testq %rdi, %rdi
je 0x3b19
pushq %rbx
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
callq 0x3af5
movq 0x20(%rbx), %rdi
callq 0x3af5
movq %rbx, %rdi
popq %rbx
jmp 0x1030
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_min
static inline struct tt_bintree_node *tt_rbtree_min(
		struct tt_bintree_node *node)
{
	if (node) {
		while (node->left)
			node = node->left;
	}
	return node;
}

// Assembly:
testq %rdi, %rdi
je 0x3b2c
movq %rdi, %rax
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
jne 0x3b1f
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_max
static inline struct tt_bintree_node *tt_rbtree_max(
		struct tt_bintree_node *node)
{
	if (node) {
		while (node->right)
			node = node->right;
	}
	return node;
}

// Assembly:
testq %rdi, %rdi
je 0x3b41
movq %rdi, %rax
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
jne 0x3b34
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_search
static struct tt_bintree_node *tt_rbtree_search(
		const struct tt_bintree *tree, const void *key)
{
	struct tt_bintree_node *node = tree->_root;
	while (node) {
		int c = tree->knum.cmp(&tree->knum, key, node->key);
		if (c == 0)
			break;
		else if (c < 0)
			node = node->left;
		else
			node = node->right;
	}
	return node;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x28(%rdi), %rax
movq (%rax), %r15
testq %r15, %r15
je 0x3b7b
movq (%r15), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x8(%r14)
testl %eax, %eax
je 0x3b7b
notl %eax
shrl $0x1f, %eax
leaq (%r15,%rax,8), %rax
addq $0x18, %rax
jmp 0x3b53
movq %r15, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_walk_in
static int tt_rbtree_walk_in(const struct tt_bintree_node *node, void *context,
		bool (*walk)(const void *key, const void *v, void *context))
{
	while (node) {
		if (tt_rbtree_walk_in(node->left, context, walk))
			return TT_ESTOP;
		if (!walk(node->key, node->data, context))
			return TT_ESTOP;
		node = node->right;
	}

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
pushq $0x5
popq %rbx
testq %r12, %r12
je 0x3fe1
movq 0x18(%r12), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3f9a
testl %eax, %eax
jne 0x3fe3
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, %rdx
callq *%r14
testb %al, %al
je 0x3fe3
movq 0x20(%r12), %r12
jmp 0x3fae
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_rotate_left
static void tt_rbtree_rotate_left(struct tt_bintree *tree,
		struct tt_bintree_node *x)
{
	struct tt_bintree_node *y = x->right;
	x->right = y->left;
	if (y->left)
		y->left->parent = x;
	y->parent = x->parent;
	if (!x->parent)
		tree->_root = y;
	else if (x == x->parent->left)
		x->parent->left = y;
	else
		x->parent->right = y;
	y->left = x;
	x->parent = y;
}

// Assembly:
movq 0x20(%rsi), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x20(%rsi)
testq %rcx, %rcx
je 0x4006
movq %rsi, 0x10(%rcx)
movq 0x10(%rsi), %rcx
movq %rcx, 0x10(%rax)
testq %rcx, %rcx
je 0x4025
leaq 0x18(%rcx), %rdx
leaq 0x20(%rcx), %rdi
cmpq %rsi, 0x18(%rcx)
cmoveq %rdx, %rdi
jmp 0x4029
addq $0x28, %rdi
movq %rax, (%rdi)
movq %rsi, 0x18(%rax)
movq %rax, 0x10(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_rotate_right
static void tt_rbtree_rotate_right(struct tt_bintree *tree,
		struct tt_bintree_node *y)
{
	struct tt_bintree_node *x = y->left;
	y->left = x->right;
	if (x->right)
		x->right->parent = y;
	x->parent = y->parent;
	if (!y->parent)
		tree->_root = x;
	else if (y == y->parent->left)
		y->parent->left = x;
	else
		y->parent->right = x;
	x->right = y;
	y->parent = x;
}

// Assembly:
movq 0x18(%rsi), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x18(%rsi)
testq %rcx, %rcx
je 0x404a
movq %rsi, 0x10(%rcx)
movq 0x10(%rsi), %rcx
movq %rcx, 0x10(%rax)
testq %rcx, %rcx
je 0x4069
leaq 0x18(%rcx), %rdx
leaq 0x20(%rcx), %rdi
cmpq %rsi, 0x18(%rcx)
cmoveq %rdx, %rdi
jmp 0x406d
addq $0x28, %rdi
movq %rax, (%rdi)
movq %rsi, 0x20(%rax)
movq %rax, 0x10(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_trans
static void tt_rbtree_trans(struct tt_bintree *tree,
		struct tt_bintree_node *u, struct tt_bintree_node *v)
{
	if (!u->parent)
		tree->_root = v;
	else if (u == u->parent->left)
		u->parent->left = v;
	else
		u->parent->right = v;
	if (v)
		v->parent = u->parent;
}

// Assembly:
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0x4094
leaq 0x18(%rax), %rcx
leaq 0x20(%rax), %rdi
cmpq %rsi, 0x18(%rax)
cmoveq %rcx, %rdi
jmp 0x4098
addq $0x28, %rdi
movq %rdx, (%rdi)
testq %rdx, %rdx
je 0x40a4
movq %rax, 0x10(%rdx)
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_capacity
dhara_sector_t dhara_map_capacity(const struct dhara_map *m)
{
	const dhara_sector_t cap = dhara_journal_capacity(&m->journal);
	const dhara_sector_t reserve = cap / (m->gc_ratio + 1);
	const dhara_sector_t safety_margin =
		DHARA_MAX_RETRIES << m->journal.nand->log2_ppb;

	if (reserve + safety_margin >= cap)
		return 0;

	return cap - reserve - safety_margin;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x1e8a
movl %eax, %esi
movzbl 0x38(%rbx), %ecx
incl %ecx
xorl %edx, %edx
divl %ecx
movq (%rbx), %rcx
movb 0x1(%rcx), %cl
pushq $0x8
popq %rdx
shll %cl, %edx
xorl %ecx, %ecx
addl %eax, %edx
subl %edx, %esi
cmovbl %ecx, %esi
movl %esi, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: trace_path
static int trace_path(struct dhara_map *m, dhara_sector_t target,
		      dhara_page_t *loc, uint8_t *new_meta,
		      dhara_error_t *err)
{
	uint8_t meta[DHARA_META_SIZE];
	int depth = 0;
	dhara_page_t p = dhara_journal_root(&m->journal);

	if (new_meta)
		meta_set_id(new_meta, target);

	if (p == DHARA_PAGE_NONE)
		goto not_found;

	if (dhara_journal_read_meta(&m->journal, p, meta, err) < 0)
		return -1;

	while (depth < DHARA_RADIX_DEPTH) {
		const dhara_sector_t id = meta_get_id(meta);

		if (id == DHARA_SECTOR_NONE)
			goto not_found;

		if ((target ^ id) & d_bit(depth)) {
			if (new_meta)
				meta_set_alt(new_meta, depth, p);

			p = meta_get_alt(meta, depth);
			if (p == DHARA_PAGE_NONE) {
				depth++;
				goto not_found;
			}

			if (dhara_journal_read_meta(&m->journal, p,
						    meta, err) < 0)
				return -1;
		} else {
			if (new_meta)
				meta_set_alt(new_meta, depth,
					meta_get_alt(meta, depth));
		}

		depth++;
	}

	if (loc)
		*loc = p;

	return 0;

not_found:
	if (new_meta) {
		while (depth < DHARA_RADIX_DEPTH)
			meta_set_alt(new_meta, depth++, DHARA_SECTOR_NONE);
	}

	dhara_set_error(err, DHARA_E_NOT_FOUND);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %r14
movq %rcx, %r15
movl %esi, %r12d
movq %rdi, %rbx
movl 0x28(%rdi), %ebp
testq %rcx, %rcx
je 0x128a
movl %r12d, (%r15)
pushq $-0x1
popq %r13
cmpl $-0x1, %ebp
je 0x131f
movq %rdx, 0x8(%rsp)
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rcx
callq 0x1eed
testl %eax, %eax
js 0x135b
xorl %r13d, %r13d
cmpq $0x20, %r13
je 0x1370
movl 0x10(%rsp), %eax
cmpl $-0x1, %eax
je 0x1322
xorl %r12d, %eax
movl %r13d, %ecx
shll %cl, %eax
testl $0x80000000, %eax       # imm = 0x80000000
je 0x130b
testq %r15, %r15
je 0x12e5
movl %ebp, 0x4(%r15,%r13,4)
movl 0x14(%rsp,%r13,4), %ebp
cmpl $-0x1, %ebp
je 0x1381
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x1eed
testl %eax, %eax
jns 0x131a
jmp 0x1357
testq %r15, %r15
je 0x131a
movl 0x14(%rsp,%r13,4), %eax
movl %eax, 0x4(%r15,%r13,4)
incq %r13
jmp 0x12b9
xorl %r13d, %r13d
testq %r15, %r15
je 0x134b
cmpl $0x1f, %r13d
ja 0x134b
shll $0x2, %r13d
leaq (%r15,%r13), %rdi
addq $0x4, %rdi
movl $0x80, %edx
subl %r13d, %edx
movl $0xff, %esi
callq 0x1090
testq %r14, %r14
je 0x1357
movl $0x6, (%r14)
pushq $-0x1
popq %r13
movl %r13d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x135b
movl %ebp, (%rax)
jmp 0x135b
incl %r13d
jmp 0x1322
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_read
int dhara_map_read(struct dhara_map *m, dhara_sector_t s,
		   uint8_t *data, dhara_error_t *err)
{
	const struct dhara_nand *n = m->journal.nand;
	dhara_error_t my_err;
	dhara_page_t p;

	if (dhara_map_find(m, s, &p, &my_err) < 0) {
		if (my_err == DHARA_E_NOT_FOUND) {
			memset(data, 0xff, 1 << n->log2_page_size);
			return 0;
		}

		dhara_set_error(err, my_err);
		return -1;
	}

	return dhara_nand_read(n, p, 0, 1 << n->log2_page_size, data, err);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq (%rdi), %r15
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x125b
testl %eax, %eax
js 0x13cc
movl 0x8(%rsp), %esi
movb (%r15), %cl
pushq $0x1
popq %rax
shll %cl, %eax
movslq %eax, %rcx
movq %r15, %rdi
xorl %edx, %edx
movq %rbx, %r8
movq %r14, %r9
callq 0x310d
jmp 0x13fc
movl 0xc(%rsp), %ecx
cmpl $0x6, %ecx
jne 0x13f1
movb (%r15), %cl
pushq $0x1
popq %rax
shll %cl, %eax
movslq %eax, %rdx
movq %rbx, %rdi
movl $0xff, %esi
callq 0x1090
xorl %eax, %eax
jmp 0x13fc
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x13fc
movl %ecx, (%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_write
int dhara_map_write(struct dhara_map *m, dhara_sector_t dst,
		    const uint8_t *data, dhara_error_t *err)
{
	for (;;) {
		uint8_t meta[DHARA_META_SIZE];
		dhara_error_t my_err;
		const dhara_sector_t old_count = m->count;

		if (prepare_write(m, dst, meta, err) < 0)
			return -1;

		if (!dhara_journal_enqueue(&m->journal, data, meta, &my_err))
			break;

		m->count = old_count;

		if (try_recover(m, my_err, err) < 0)
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
leaq 0x10(%rsp), %r12
movl 0x3c(%r15), %r13d
movq %r15, %rdi
movl %ebp, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1486
testl %eax, %eax
js 0x146d
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
leaq 0xc(%rsp), %rcx
callq 0x20ab
testl %eax, %eax
je 0x1472
movl %r13d, 0x3c(%r15)
movl 0xc(%rsp), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x151d
testl %eax, %eax
jns 0x1427
pushq $-0x1
popq %rax
jmp 0x1474
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: prepare_write
static int prepare_write(struct dhara_map *m, dhara_sector_t dst,
			 uint8_t *meta, dhara_error_t *err)
{
	dhara_error_t my_err;

	if (auto_gc(m, err) < 0)
		return -1;

	if (trace_path(m, dst, NULL, meta, &my_err) < 0) {
		if (my_err != DHARA_E_NOT_FOUND) {
			dhara_set_error(err, my_err);
			return -1;
		}

		if (m->count >= dhara_map_capacity(m)) {
			dhara_set_error(err, DHARA_E_MAP_FULL);
			return -1;
		}

		m->count++;
	}

	ck_set_count(dhara_journal_cookie(&m->journal), m->count);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r14
movq %rcx, %rsi
callq 0x17bc
pushq $-0x1
popq %rbx
testl %eax, %eax
js 0x14d1
leaq 0xc(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
movq %r12, %rcx
callq 0x1262
testl %eax, %eax
js 0x14e0
movl 0x3c(%r14), %eax
movq 0x8(%r14), %rcx
movl %eax, 0x10(%rcx)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %eax
cmpl $0x6, %eax
jne 0x1505
movl 0x3c(%r14), %ebp
movq %r14, %rdi
callq 0x122e
cmpl %eax, %ebp
jae 0x150f
movl 0x3c(%r14), %eax
incl %eax
movl %eax, 0x3c(%r14)
jmp 0x14c8
testq %r15, %r15
je 0x14d1
movl %eax, (%r15)
jmp 0x14d1
testq %r15, %r15
je 0x14d1
movl $0x7, (%r15)
jmp 0x14d1
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: try_recover
static int try_recover(struct dhara_map *m, dhara_error_t cause,
		       dhara_error_t *err)
{
	int restart_count = 0;

	if (cause != DHARA_E_RECOVER) {
		dhara_set_error(err, cause);
		return -1;
	}

	while (dhara_journal_in_recovery(&m->journal)) {
		dhara_page_t p = dhara_journal_next_recoverable(&m->journal);
		dhara_error_t my_err;
		int ret;

		if (p == DHARA_PAGE_NONE)
			ret = pad_queue(m, &my_err);
		else
			ret = raw_gc(m, p, &my_err);

		if (ret < 0) {
			if (my_err != DHARA_E_RECOVER) {
				dhara_set_error(err, my_err);
				return -1;
			}

			if (restart_count >= DHARA_MAX_RETRIES) {
				dhara_set_error(err, DHARA_E_TOO_BAD);
				return -1;
			}

			restart_count++;
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
cmpl $0x4, %esi
jne 0x1581
movq %rdi, %r14
xorl %ebp, %ebp
leaq 0xc(%rsp), %r15
xorl %r12d, %r12d
testb $0x4, 0x12(%r14)
je 0x15a1
movq %r14, %rdi
callq 0x25ea
movq %r14, %rdi
cmpl $-0x1, %eax
je 0x1561
movl %eax, %esi
movq %r15, %rdx
callq 0x18f7
jmp 0x1569
movq %r15, %rsi
callq 0x1885
testl %eax, %eax
jns 0x153e
movl 0xc(%rsp), %eax
cmpl $0x4, %eax
jne 0x158d
cmpl $0x8, %r12d
jge 0x1594
incl %r12d
jmp 0x153e
pushq $-0x1
popq %rbp
testq %rbx, %rbx
je 0x15a1
movl %esi, (%rbx)
jmp 0x15a1
testq %rbx, %rbx
jne 0x159c
jmp 0x159e
testq %rbx, %rbx
je 0x159e
pushq $0x3
popq %rax
movl %eax, (%rbx)
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_copy_page
int dhara_map_copy_page(struct dhara_map *m, dhara_page_t src,
			dhara_sector_t dst, dhara_error_t *err)
{
	for (;;) {
		uint8_t meta[DHARA_META_SIZE];
		dhara_error_t my_err;
		const dhara_sector_t old_count = m->count;

		if (prepare_write(m, dst, meta, err) < 0)
			return -1;

		if (!dhara_journal_copy(&m->journal, src, meta, &my_err))
			break;

		m->count = old_count;

		if (try_recover(m, my_err, err) < 0)
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %r15
leaq 0x10(%rsp), %r12
movl 0x3c(%r15), %r13d
movq %r15, %rdi
movl %ebp, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1486
testl %eax, %eax
js 0x1617
movq %r15, %rdi
movl %r14d, %esi
movq %r12, %rdx
leaq 0xc(%rsp), %rcx
callq 0x2552
testl %eax, %eax
je 0x161c
movl %r13d, 0x3c(%r15)
movl 0xc(%rsp), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x151d
testl %eax, %eax
jns 0x15d1
pushq $-0x1
popq %rax
jmp 0x161e
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_copy_sector
int dhara_map_copy_sector(struct dhara_map *m, dhara_sector_t src,
			  dhara_sector_t dst, dhara_error_t *err)
{
	dhara_error_t my_err;
	dhara_page_t p;

	if (dhara_map_find(m, src, &p, &my_err) < 0) {
		if (my_err == DHARA_E_NOT_FOUND)
			return dhara_map_trim(m, dst, err);

		dhara_set_error(err, my_err);
		return -1;
	}

	return dhara_map_copy_page(m, p, dst, err);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movq %rdi, %r14
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x125b
testl %eax, %eax
js 0x1666
movl 0x8(%rsp), %esi
movq %r14, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x15b0
jmp 0x1688
movl 0xc(%rsp), %ecx
cmpl $0x6, %ecx
jne 0x167e
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1691
jmp 0x1688
pushq $-0x1
popq %rax
testq %rbx, %rbx
je 0x1688
movl %ecx, (%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_trim
int dhara_map_trim(struct dhara_map *m, dhara_sector_t s, dhara_error_t *err)
{
	for (;;) {
		dhara_error_t my_err;

		if (auto_gc(m, err) < 0)
			return -1;

		if (!try_delete(m, s, &my_err))
			break;

		if (try_recover(m, my_err, err) < 0)
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x17bc
testl %eax, %eax
js 0x1792
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
leaq 0xc(%rsp), %r8
callq 0x1262
testl %eax, %eax
js 0x16fd
pushq $0x7c
popq %rax
pushq $0x1f
popq %r12
testq %r12, %r12
js 0x1797
movslq %eax, %r15
movl 0x14(%rsp,%r15), %r13d
cmpl $-0x1, %r13d
jne 0x1710
decq %r12
addl $-0x4, %eax
jmp 0x16de
movl 0xc(%rsp), %eax
cmpl $0x6, %eax
je 0x17a3
movl %eax, 0x8(%rsp)
jmp 0x177b
movq %rbx, %rdi
movl %r13d, %esi
leaq 0xa0(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x1eed
testl %eax, %eax
js 0x177b
movl 0xa0(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %r12d, %eax
cmpq $0x1e, %rax
ja 0x1750
movl 0xa8(%rsp,%rax,4), %ecx
movl %ecx, 0x18(%rsp,%rax,4)
incq %rax
jmp 0x173a
orl $-0x1, 0x14(%rsp,%r15)
movq 0x8(%rbx), %rax
movl 0x3c(%rbx), %ecx
decl %ecx
movl %ecx, 0x10(%rax)
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x10(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x2552
testl %eax, %eax
jns 0x17b7
movl 0x8(%rsp), %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x151d
testl %eax, %eax
jns 0x16aa
pushq $-0x1
popq %rax
jmp 0x17a5
andl $0x0, 0x3c(%rbx)
movq %rbx, %rdi
callq 0x207b
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decl 0x3c(%rbx)
jmp 0x17a3
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: auto_gc
static int auto_gc(struct dhara_map *m, dhara_error_t *err)
{
	int i;

	if (dhara_journal_size(&m->journal) < dhara_map_capacity(m))
		return 0;

	for (i = 0; i <= m->gc_ratio; i++)
		if (dhara_map_gc(m, err) < 0)
			return -1;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
callq 0x1eb1
movl %eax, %r15d
movq %r14, %rdi
callq 0x122e
xorl %ebp, %ebp
cmpl %eax, %r15d
jb 0x1807
pushq $-0x1
popq %r15
movl %r15d, %r12d
movzbl 0x38(%r14), %eax
incl %r12d
cmpl %eax, %r12d
ja 0x1807
movq %r14, %rdi
movq %rbx, %rsi
callq 0x199c
testl %eax, %eax
jns 0x17e8
movl %r15d, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_sync
int dhara_map_sync(struct dhara_map *m, dhara_error_t *err)
{
	while (!dhara_journal_is_clean(&m->journal)) {
		dhara_page_t p = dhara_journal_peek(&m->journal);
		dhara_error_t my_err;
		int ret;

		if (p == DHARA_PAGE_NONE) {
			ret = pad_queue(m, &my_err);
		} else {
			ret = raw_gc(m, p, &my_err);
			if (!ret)
				dhara_journal_dequeue(&m->journal);
		}

		if ((ret < 0) && (try_recover(m, my_err, err) < 0))
			return -1;
	}

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %r15
testb $0x1, 0x12(%r14)
je 0x1879
movq %r14, %rdi
callq 0x1f70
movq %r14, %rdi
cmpl $-0x1, %eax
je 0x1855
movl %eax, %esi
movq %r15, %rdx
callq 0x18f7
testl %eax, %eax
jne 0x1861
movq %r14, %rdi
callq 0x1ffd
jmp 0x1826
movq %r15, %rsi
callq 0x1885
testl %eax, %eax
jns 0x1826
movl 0xc(%rsp), %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x151d
testl %eax, %eax
jns 0x1826
pushq $-0x1
popq %rax
jmp 0x187b
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: pad_queue
static int pad_queue(struct dhara_map *m, dhara_error_t *err)
{
	dhara_page_t p = dhara_journal_root(&m->journal);
	uint8_t root_meta[DHARA_META_SIZE];

	ck_set_count(dhara_journal_cookie(&m->journal), m->count);

	if (p == DHARA_PAGE_NONE)
		return dhara_journal_enqueue(&m->journal, NULL, NULL, err);

	if (dhara_journal_read_meta(&m->journal, p, root_meta, err) < 0)
		return -1;

	return dhara_journal_copy(&m->journal, p, root_meta, err);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x28(%rdi), %ebp
movq 0x8(%rdi), %rax
movl 0x3c(%rdi), %ecx
movl %ecx, 0x10(%rax)
cmpl $-0x1, %ebp
je 0x18ce
movq %rsp, %rdx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x1eed
testl %eax, %eax
js 0x18e8
movq %rsp, %rdx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x2552
jmp 0x18eb
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x20ab
pushq $-0x1
popq %rax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: raw_gc
static int raw_gc(struct dhara_map *m, dhara_page_t src,
		  dhara_error_t *err)
{
	dhara_sector_t target;
	dhara_page_t current;
	dhara_error_t my_err;
	uint8_t meta[DHARA_META_SIZE];

	if (dhara_journal_read_meta(&m->journal, src, meta, err) < 0)
		return -1;

	/* Is the page just filler/garbage? */
	target = meta_get_id(meta);
	if (target == DHARA_SECTOR_NONE)
		return 0;

	/* Find out where the sector once represented by this page
	 * currently resides (if anywhere).
	 */
	if (trace_path(m, target, &current, meta, &my_err) < 0) {
		if (my_err == DHARA_E_NOT_FOUND)
			return 0;

		dhara_set_error(err, my_err);
		return -1;
	}

	/* Is this page still the most current representative? If not,
	 * do nothing.
	 */
	if (current != src)
		return 0;

	/* Rewrite it at the front of the journal with updated metadata */
	ck_set_count(dhara_journal_cookie(&m->journal), m->count);
	if (dhara_journal_copy(&m->journal, src, meta, err) < 0)
		return -1;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x1eed
pushq $-0x1
popq %r12
testl %eax, %eax
js 0x1986
movl 0x10(%rsp), %esi
xorl %r15d, %r15d
cmpl $-0x1, %esi
je 0x1989
leaq 0xc(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r14, %rdi
callq 0x1262
testl %eax, %eax
js 0x1976
cmpl %ebp, 0xc(%rsp)
jne 0x1989
movq 0x8(%r14), %rax
movl 0x3c(%r14), %ecx
movl %ecx, 0x10(%rax)
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x2552
movl %eax, %r15d
sarl $0x1f, %r15d
jmp 0x1989
movl 0x8(%rsp), %eax
cmpl $0x6, %eax
je 0x1989
testq %rbx, %rbx
je 0x1986
movl %eax, (%rbx)
movl %r12d, %r15d
movl %r15d, %eax
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/map.c
// Function: dhara_map_gc
int dhara_map_gc(struct dhara_map *m, dhara_error_t *err)
{
	if (!m->count)
		return 0;

	for (;;) {
		dhara_page_t tail = dhara_journal_peek(&m->journal);
		dhara_error_t my_err;

		if (tail == DHARA_PAGE_NONE)
			break;

		if (!raw_gc(m, tail, &my_err)) {
			dhara_journal_dequeue(&m->journal);
			break;
		}

		if (try_recover(m, my_err, err) < 0)
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
xorl %ebx, %ebx
cmpl $0x0, 0x3c(%rdi)
je 0x19fb
movq %rsi, %r15
movq %rdi, %r14
leaq 0xc(%rsp), %r12
pushq $-0x1
popq %rbp
movq %r14, %rdi
callq 0x1f70
cmpl $-0x1, %eax
je 0x19fb
movq %r14, %rdi
movl %eax, %esi
movq %r12, %rdx
callq 0x18f7
testl %eax, %eax
je 0x19f3
movl 0xc(%rsp), %esi
movq %r14, %rdi
movq %r15, %rdx
callq 0x151d
testl %eax, %eax
jns 0x19be
movl %ebp, %ebx
jmp 0x19fb
movq %r14, %rdi
callq 0x1ffd
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_init
void dhara_journal_init(struct dhara_journal *j,
			const struct dhara_nand *n,
			uint8_t *page_buf)
{
	/* Set fixed parameters */
	j->nand = n;
	j->page_buf = page_buf;
	j->log2_ppc = choose_ppc(n->log2_page_size, n->log2_ppb);

	reset_journal(j);
}

// Assembly:
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
movb (%rsi), %cl
pushq $0x1
popq %rax
movl %eax, %edx
shll %cl, %edx
movzbl 0x1(%rsi), %esi
addl $-0x14, %edx
cmpl $0x1, %esi
movl %esi, %ecx
adcl $0x0, %ecx
movl $0x84, %r8d
cmpl %esi, %eax
jae 0x1a48
leal 0x84(,%r8,2), %r8d
cmpl %edx, %r8d
jg 0x1a46
incl %eax
jmp 0x1a31
movl %eax, %ecx
movb %cl, 0x10(%rdi)
jmp 0x1a4d
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: find_checkblock
static int find_checkblock(struct dhara_journal *j,
			   dhara_block_t blk, dhara_block_t *where,
			   dhara_error_t *err)
{
	int i;

	for (i = 0; (blk < j->nand->num_blocks) &&
		    (i < DHARA_MAX_RETRIES); i++) {
		const dhara_page_t p =
			(blk << j->nand->log2_ppb) |
			((1 << j->log2_ppc) - 1);

		if (!(dhara_nand_is_bad(j->nand, blk) ||
		      dhara_nand_read(j->nand, p,
				      0, 1 << j->nand->log2_page_size,
				      j->page_buf, err)) &&
		    hdr_has_magic(j->page_buf)) {
			*where = blk;
			return 0;
		}

		blk++;
	}

	dhara_set_error(err, DHARA_E_TOO_BAD);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movl %esi, %r12d
movq %rdi, %r13
xorl %r14d, %r14d
pushq $-0x1
popq %rax
movl %eax, 0x4(%rsp)
leal (%r12,%r14), %ebp
movq (%r13), %rdi
cmpl 0x4(%rdi), %ebp
jae 0x1e56
cmpl $0x7, %r14d
ja 0x1e56
movzbl 0x1(%rdi), %ebx
movzbl 0x10(%r13), %r15d
movl %ebp, %esi
callq 0x2e0a
testl %eax, %eax
jne 0x1e51
movl %ebp, %eax
movl %ebx, %ecx
shll %cl, %eax
pushq $-0x1
popq %rsi
movl %r15d, %ecx
shll %cl, %esi
notl %esi
orl %eax, %esi
movq (%r13), %rdi
movq 0x8(%r13), %r8
movb (%rdi), %cl
pushq $0x1
popq %rax
shll %cl, %eax
movslq %eax, %rcx
xorl %edx, %edx
movq 0x8(%rsp), %r9
callq 0x310d
testl %eax, %eax
jne 0x1e51
movq 0x8(%r13), %rdi
callq 0x262b
testl %eax, %eax
jne 0x1e79
incl %r14d
jmp 0x1de9
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1e66
movl $0x3, (%rax)
movl 0x4(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
movl $0x0, 0x4(%rsp)
jmp 0x1e66
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_read_meta
int dhara_journal_read_meta(struct dhara_journal *j, dhara_page_t p,
			    uint8_t *buf, dhara_error_t *err)
{
	/* Offset of metadata within the metadata page */
	const dhara_page_t ppc_mask = (1 << j->log2_ppc) - 1;
	const size_t offset = hdr_user_offset(p & ppc_mask);

	/* Special case: buffered metadata */
	if (align_eq(p, j->head, j->log2_ppc)) {
		memcpy(buf, j->page_buf + offset, DHARA_META_SIZE);
		return 0;
	}

	/* Special case: incomplete metadata dumped at start of
	 * recovery.
	 */
	if ((j->recover_meta != DHARA_PAGE_NONE) &&
	    align_eq(p, j->recover_root, j->log2_ppc))
		return dhara_nand_read(j->nand, j->recover_meta,
				       offset, DHARA_META_SIZE,
				       buf, err);

	/* General case: fetch from metadata page for checkpoint group */
	return dhara_nand_read(j->nand, p | ppc_mask,
			       offset, DHARA_META_SIZE,
			       buf, err);
}

// Assembly:
movq %rcx, %r9
movq %rdx, %r8
movl %esi, %edx
movzbl 0x10(%rdi), %ecx
pushq $-0x1
popq %rsi
shll %cl, %esi
notl %esi
movl %edx, %eax
andl %esi, %eax
movzbl %al, %eax
imull $0x84, %eax, %eax
addl $0x14, %eax
movl 0x24(%rdi), %r10d
xorl %edx, %r10d
shrl %cl, %r10d
testl %r10d, %r10d
je 0x1f44
movl 0x34(%rdi), %r10d
cmpl $-0x1, %r10d
je 0x1f38
movl 0x30(%rdi), %r11d
xorl %edx, %r11d
shrl %cl, %r11d
testl %r11d, %r11d
je 0x1f5d
movq (%rdi), %rdi
orl %edx, %esi
movl $0x84, %ecx
jmp 0x1f68
pushq %rax
addq 0x8(%rdi), %rax
movl $0x84, %edx
movq %r8, %rdi
movq %rax, %rsi
callq 0x10c0
xorl %eax, %eax
popq %rcx
retq
movq (%rdi), %rdi
movl $0x84, %ecx
movl %r10d, %esi
movq %rax, %rdx
jmp 0x310d
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_peek
dhara_page_t dhara_journal_peek(struct dhara_journal *j)
{
	if (j->head == j->tail)
		return DHARA_PAGE_NONE;

	if (is_aligned(j->tail, j->nand->log2_ppb)) {
		dhara_block_t blk = j->tail >> j->nand->log2_ppb;
		int i;

		for (i = 0; i < DHARA_MAX_RETRIES; i++) {
			if ((blk == (j->head >> j->nand->log2_ppb)) ||
			    !dhara_nand_is_bad(j->nand, blk)) {
				j->tail = blk << j->nand->log2_ppb;

				if (j->tail == j->head)
					j->root = DHARA_PAGE_NONE;

				return j->tail;
			}

			blk = next_block(j->nand, blk);
		}
	}

	return j->tail;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl 0x20(%rdi), %ebx
cmpl %ebx, 0x24(%rdi)
jne 0x1f84
pushq $-0x1
popq %rbx
jmp 0x1f99
movq %rdi, %r14
movq (%rdi), %rdi
movzbl 0x1(%rdi), %ecx
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
testl %eax, %ebx
je 0x1fa6
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
shrl %cl, %ebx
pushq $0x8
popq %rbp
xorl %r15d, %r15d
subl $0x1, %ebp
jb 0x1fdc
movl 0x24(%r14), %eax
movzbl 0x1(%rdi), %ecx
movl %eax, %edx
shrl %cl, %edx
cmpl %edx, %ebx
je 0x1fea
movl %ebx, %esi
callq 0x2e0a
movq (%r14), %rdi
testl %eax, %eax
je 0x1fe2
incl %ebx
cmpl 0x4(%rdi), %ebx
cmovael %r15d, %ebx
jmp 0x1fae
movl 0x20(%r14), %ebx
jmp 0x1f99
movzbl 0x1(%rdi), %ecx
movl 0x24(%r14), %eax
shll %cl, %ebx
movl %ebx, 0x20(%r14)
cmpl %eax, %ebx
jne 0x1f99
orl $-0x1, 0x28(%r14)
movl %eax, %ebx
jmp 0x1f99
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_dequeue
void dhara_journal_dequeue(struct dhara_journal *j)
{
	if (j->head == j->tail)
		return;

	j->tail = next_upage(j, j->tail);

	/* If the journal is clean at the time of dequeue, then this
	 * data was always obsolete, and can be reused immediately.
	 */
	if (!(j->flags & (DHARA_JOURNAL_F_DIRTY | DHARA_JOURNAL_F_RECOVERY)))
		j->tail_sync = j->tail;

	const dhara_page_t chip_size = j->nand->num_blocks << j->nand->log2_ppb;
	const dhara_page_t raw_size = wrap(j->head + chip_size - j->tail,
		chip_size);
	const dhara_page_t root_offset = wrap(j->head + chip_size - j->root,
		chip_size);

	if (root_offset > raw_size)
		j->root = DHARA_PAGE_NONE;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl 0x20(%rdi), %esi
movl 0x24(%rdi), %ebp
cmpl %esi, %ebp
je 0x204c
movq %rdi, %rbx
callq 0x2053
movl %eax, 0x20(%rbx)
testb $0x5, 0x12(%rbx)
jne 0x201e
movl %eax, 0x1c(%rbx)
movq (%rbx), %rcx
movl 0x4(%rcx), %edx
movb 0x1(%rcx), %cl
shll %cl, %edx
addl %edx, %ebp
movl %ebp, %ecx
subl %eax, %ecx
xorl %eax, %eax
cmpl %edx, %ecx
movl %edx, %esi
cmovbl %eax, %esi
subl %esi, %ecx
subl 0x28(%rbx), %ebp
cmpl %edx, %ebp
cmovbl %eax, %edx
subl %edx, %ebp
cmpl %ecx, %ebp
jbe 0x204c
orl $-0x1, 0x28(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: next_upage
static dhara_page_t next_upage(const struct dhara_journal *j,
			       dhara_page_t p)
{
	p++;
	if (is_aligned(p + 1, j->log2_ppc))
		p++;

	if (p >= (j->nand->num_blocks << j->nand->log2_ppb))
		p = 0;

	return p;
}

// Assembly:
leal 0x1(%rsi), %edx
leal 0x2(%rsi), %eax
movb 0x10(%rdi), %cl
pushq $-0x1
popq %rsi
shll %cl, %esi
notl %esi
testl %esi, %eax
cmovel %eax, %edx
movq (%rdi), %rax
movl 0x4(%rax), %esi
movb 0x1(%rax), %cl
shll %cl, %esi
xorl %eax, %eax
cmpl %esi, %edx
cmovbl %edx, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_clear
void dhara_journal_clear(struct dhara_journal *j)
{
	j->tail = j->head;
	j->root = DHARA_PAGE_NONE;
	j->flags |= DHARA_JOURNAL_F_DIRTY;

	hdr_clear_user(j->page_buf, j->nand->log2_page_size);
}

// Assembly:
movl 0x24(%rdi), %eax
movl %eax, 0x20(%rdi)
orl $-0x1, 0x28(%rdi)
orb $0x1, 0x12(%rdi)
movq (%rdi), %rax
movq 0x8(%rdi), %rdi
movb (%rax), %cl
addq $0x14, %rdi
pushq $0x1
popq %rax
shll %cl, %eax
addl $-0x14, %eax
movslq %eax, %rdx
movl $0xff, %esi
jmp 0x1090
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_enqueue
int dhara_journal_enqueue(struct dhara_journal *j,
			  const uint8_t *data, const uint8_t *meta,
			  dhara_error_t *err)
{
	dhara_error_t my_err;
	int i;

	for (i = 0; i < DHARA_MAX_RETRIES; i++) {
		if (!(prepare_head(j, &my_err) ||
		      (data && dhara_nand_prog(j->nand, j->head, data,
					       &my_err))))
			return push_meta(j, meta, err);

		if (recover_from(j, my_err, err) < 0)
			return -1;
	}

	dhara_set_error(err, DHARA_E_TOO_BAD);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %r12
pushq $0x9
popq %r15
leaq 0xc(%rsp), %rbp
pushq $-0x1
popq %rbx
decl %r15d
je 0x2119
movq %r12, %rdi
movq %rbp, %rsi
callq 0x214a
testl %eax, %eax
jne 0x2104
testq %r13, %r13
je 0x2127
movq (%r12), %rdi
movl 0x24(%r12), %esi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x2f9d
testl %eax, %eax
je 0x2127
movl 0xc(%rsp), %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x2375
testl %eax, %eax
jns 0x20d3
jmp 0x2139
testq %r14, %r14
je 0x2139
movl $0x3, (%r14)
jmp 0x2139
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2204
movl %eax, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: prepare_head
static int prepare_head(struct dhara_journal *j, dhara_error_t *err)
{
	const dhara_page_t next = next_upage(j, j->head);
	int i;

	/* We can't write if doing so would cause the head pointer to
	 * roll onto the same block as the last-synced tail.
	 */
	if (align_eq(next, j->tail_sync, j->nand->log2_ppb) &&
	    !align_eq(next, j->head, j->nand->log2_ppb)) {
		dhara_set_error(err, DHARA_E_JOURNAL_FULL);
		return -1;
	}

	j->flags |= DHARA_JOURNAL_F_DIRTY;
	if (!is_aligned(j->head, j->nand->log2_ppb))
		return 0;

	for (i = 0; i < DHARA_MAX_RETRIES; i++) {
		const dhara_block_t blk = j->head >> j->nand->log2_ppb;

		if (!dhara_nand_is_bad(j->nand, blk))
			return dhara_nand_erase(j->nand, blk, err);

		j->bb_current++;
		if (skip_block(j, err) < 0)
			return -1;
	}

	dhara_set_error(err, DHARA_E_TOO_BAD);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movl 0x24(%rdi), %ebp
movl %ebp, %esi
callq 0x2053
movq (%r14), %rcx
movzbl 0x1(%rcx), %ecx
movl 0x1c(%r14), %edx
xorl %eax, %edx
shrl %cl, %edx
testl %edx, %edx
je 0x21c0
orb $0x1, 0x12(%r14)
pushq $-0x1
popq %r15
movl %r15d, %edx
shll %cl, %edx
notl %edx
xorl %eax, %eax
testl %edx, %ebp
jne 0x21e6
pushq $0x9
popq %r12
decl %r12d
je 0x21d8
movl 0x24(%r14), %ebp
movq (%r14), %rdi
movb 0x1(%rdi), %cl
shrl %cl, %ebp
movl %ebp, %esi
callq 0x2e0a
testl %eax, %eax
je 0x21ef
incl 0x14(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2686
testl %eax, %eax
jns 0x218f
jmp 0x21e3
xorl %ebp, %eax
shrl %cl, %eax
testl %eax, %eax
je 0x2175
pushq $-0x1
popq %rax
testq %rbx, %rbx
je 0x21e6
movl $0x5, (%rbx)
jmp 0x21e6
testq %rbx, %rbx
je 0x21e3
movl $0x3, (%rbx)
movl %r15d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
movl %ebp, %esi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2e98
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_copy
int dhara_journal_copy(struct dhara_journal *j,
		       dhara_page_t p, const uint8_t *meta,
		       dhara_error_t *err)
{
	dhara_error_t my_err;
	int i;

	for (i = 0; i < DHARA_MAX_RETRIES; i++) {
		if (!(prepare_head(j, &my_err) ||
		      dhara_nand_copy(j->nand, p, j->head, &my_err)))
			return push_meta(j, meta, err);

		if (recover_from(j, my_err, err) < 0)
			return -1;
	}

	dhara_set_error(err, DHARA_E_TOO_BAD);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, 0x10(%rsp)
movl %esi, %ebp
movq %rdi, %r12
pushq $0x9
popq %r15
leaq 0xc(%rsp), %r13
pushq $-0x1
popq %rbx
decl %r15d
je 0x25b9
movq %r12, %rdi
movq %r13, %rsi
callq 0x214a
testl %eax, %eax
jne 0x25a4
movq (%r12), %rdi
movl 0x24(%r12), %edx
movl %ebp, %esi
movq %r13, %rcx
callq 0x31aa
testl %eax, %eax
je 0x25c7
movl 0xc(%rsp), %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x2375
testl %eax, %eax
jns 0x2579
jmp 0x25d9
testq %r14, %r14
je 0x25d9
movl $0x3, (%r14)
jmp 0x25d9
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2204
movl %eax, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_next_recoverable
dhara_page_t dhara_journal_next_recoverable(struct dhara_journal *j)
{
	const dhara_page_t n = j->recover_next;

	if (!dhara_journal_in_recovery(j))
		return DHARA_PAGE_NONE;

	if (j->flags & DHARA_JOURNAL_F_ENUM_DONE)
		return DHARA_PAGE_NONE;

	if (j->recover_next == j->recover_root)
		j->flags |= DHARA_JOURNAL_F_ENUM_DONE;
	else
		j->recover_next = next_upage(j, j->recover_next);

	return n;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movb 0x12(%rdi), %al
movl %eax, %ecx
andb $0xc, %cl
cmpb $0x4, %cl
jne 0x260e
movq %rdi, %r14
movl 0x2c(%rdi), %ebx
cmpl 0x30(%rdi), %ebx
jne 0x2613
orb $0x8, %al
movb %al, 0x12(%r14)
jmp 0x2621
pushq $-0x1
popq %rbx
jmp 0x2621
movq %r14, %rdi
movl %ebx, %esi
callq 0x2053
movl %eax, 0x2c(%r14)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: skip_block
static int skip_block(struct dhara_journal *j, dhara_error_t *err)
{
	const dhara_block_t next = next_block(j->nand,
		j->head >> j->nand->log2_ppb);

	/* We can't roll onto the same block as the tail */
	if ((j->tail_sync >> j->nand->log2_ppb) == next) {
		dhara_set_error(err, DHARA_E_JOURNAL_FULL);
		return -1;
	}

	j->head = next << j->nand->log2_ppb;
	if (!j->head)
		roll_stats(j);

	return 0;
}

// Assembly:
movq (%rdi), %r8
movl 0x24(%rdi), %edx
movzbl 0x1(%r8), %ecx
shrl %cl, %edx
incl %edx
xorl %eax, %eax
cmpl 0x4(%r8), %edx
cmovael %eax, %edx
movl 0x1c(%rdi), %r8d
shrl %cl, %r8d
cmpl %edx, %r8d
jne 0x26b9
pushq $-0x1
popq %rax
testq %rsi, %rsi
je 0x26c2
movl $0x5, (%rsi)
retq
shll %cl, %edx
movl %edx, 0x24(%rdi)
testl %edx, %edx
je 0x26c3
retq
movl 0x14(%rdi), %ecx
movl %ecx, 0x18(%rdi)
andl $0x0, 0x14(%rdi)
incb 0x11(%rdi)
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/tests/map.c
// Function: main
int main(void)
{
	for (int i = 0; i < 1000; i++) {
		printf("--------------------------------"
		       "--------------------------------\n");
		printf("Seed: %d\n", i);
		srandom(i);
		test();
	}

	sim_dump();
	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
leaq 0x1b99(%rip), %rbx      # 0x42a0
leaq 0x19cc(%rip), %r14      # 0x40da
xorl %ebp, %ebp
cmpl $0x3e8, %ebp            # imm = 0x3E8
je 0x273c
movq %rbx, %rdi
callq 0x1060
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1070
movl %ebp, %edi
callq 0x1050
callq 0x2748
incl %ebp
jmp 0x2710
callq 0x32d8
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/tests/map.c
// Function: shuffle
static void shuffle(int seed)
{
	int i;

	srandom(seed);
	for (i = 0; i < NUM_SECTORS; i++)
		sector_list[i] = i;

	for (i = NUM_SECTORS - 1; i > 0; i--) {
		const int j = random() % i;
		const int tmp = sector_list[i];

		sector_list[i] = sector_list[j];
		sector_list[j] = tmp;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
callq 0x1050
leaq 0x45ae(%rip), %rax      # 0x7090
xorl %ecx, %ecx
cmpq $0xc8, %rcx
je 0x2af8
movl %ecx, (%rax)
incq %rcx
addq $0x4, %rax
jmp 0x2ae4
movl $0xc7, %r14d
leaq 0x458b(%rip), %rbx      # 0x7090
movl $0xc7, %r15d
subq $0x1, %r15
jb 0x2b2e
callq 0x10d0
cqto
idivq %r14
movl (%rbx,%r14,4), %eax
movl (%rbx,%rdx,4), %ecx
movl %ecx, (%rbx,%r14,4)
movl %eax, (%rbx,%rdx,4)
movq %r15, %r14
jmp 0x2b0b
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/tests/map.c
// Function: mt_write
static void mt_write(struct dhara_map *m, dhara_sector_t s, int seed)
{
	const size_t page_size = 1 << m->journal.nand->log2_page_size;
	uint8_t buf[page_size];
	dhara_error_t err;

	seq_gen(seed, buf, sizeof(buf));
	if (dhara_map_write(m, s, buf, &err) < 0)
		dabort("map_write", err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %eax
movq %rdi, %rbx
movq (%rdi), %rcx
movb (%rcx), %cl
pushq $0x1
popq %rdx
shll %cl, %edx
movl %esi, %r14d
movslq %edx, %rdx
leaq 0xf(%rdx), %rcx
andq $-0x10, %rcx
movq %rsp, %r15
subq %rcx, %r15
movq %r15, %rsp
movl %eax, %edi
movq %r15, %rsi
callq 0x348c
leaq -0x1c(%rbp), %rcx
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x1406
testl %eax, %eax
jns 0x2b93
movl -0x1c(%rbp), %esi
leaq 0x158b(%rip), %rdi      # 0x4119
callq 0x351b
leaq -0x18(%rbp), %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/tests/map.c
// Function: mt_check
static void mt_check(struct dhara_map *m)
{
	int count;

	sim_freeze();
	count = check_recurse(m, m->journal.head,
		dhara_journal_root(&m->journal), 0, 0);
	sim_thaw();

	assert(m->count == count);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x32ca
movl 0x24(%rbx), %esi
movl 0x28(%rbx), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2c4d
movl %eax, %ebp
callq 0x32d1
cmpl %ebp, 0x3c(%rbx)
jne 0x2bcf
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x154d(%rip), %rdi      # 0x4123
leaq 0x1558(%rip), %rsi      # 0x4135
leaq 0x155d(%rip), %rcx      # 0x4141
pushq $0x68
popq %rdx
callq 0x1080