// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/dhara/journal.c
// Function: dhara_journal_resume
int dhara_journal_resume(struct dhara_journal *j, dhara_error_t *err)
{
	dhara_block_t first, last;
	dhara_page_t last_group;

	/* Find the first checkpoint-containing block */
	if (find_checkblock(j, 0, &first, err) < 0) {
		reset_journal(j);
		return -1;
	}

	/* Find the last checkpoint-containing block in this epoch */
	j->epoch = hdr_get_epoch(j->page_buf);
	last = find_last_checkblock(j, first);

	/* Find the last programmed checkpoint group in the block */
	last_group = find_last_group(j, last);

	/* Perform a linear scan to find the last good checkpoint (and
	 * therefore the root).
	 */
	if (find_root(j, last_group, err) < 0) {
		reset_journal(j);
		return -1;
	}

	/* Restore settings from checkpoint */
	j->tail = hdr_get_tail(j->page_buf);
	j->bb_current = hdr_get_bb_current(j->page_buf);
	j->bb_last = hdr_get_bb_last(j->page_buf);
	hdr_clear_user(j->page_buf, j->nand->log2_page_size);

	/* Perform another linear scan to find the next free user page */
	if (find_head(j, last_group, err) < 0) {
		reset_journal(j);
		return -1;
	}

	j->flags = 0;
	j->tail_sync = j->tail;

	clear_recovery(j);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x14(%rsp), %rdx
xorl %esi, %esi
movq %r14, %rcx
callq 0x1dc1
testl %eax, %eax
js 0x1c86
movq %r14, 0x20(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movb 0x3(%rcx), %cl
movb %cl, 0x11(%rbx)
movl 0x14(%rsp), %ecx
movl 0x4(%rax), %r13d
decl %r13d
leaq 0x1c(%rsp), %r15
movl %ecx, 0x8(%rsp)
movl %ecx, %r14d
cmpl %r13d, %r14d
ja 0x1b59
leal (%r14,%r13), %r12d
movl %r12d, %ebp
shrl %ebp
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1dc1
testl %eax, %eax
js 0x1b13
movq 0x8(%rbx), %rax
movb 0x3(%rax), %al
cmpb 0x11(%rbx), %al
je 0x1b20
cmpl $0x1, %r12d
jbe 0x1b59
decl %ebp
movl %ebp, %r13d
jmp 0x1ae6
movl 0x1c(%rsp), %eax
movq %rax, (%rsp)
leal 0x1(%rax), %esi
movq (%rbx), %rax
cmpl 0x4(%rax), %esi
jae 0x1b61
movq %rbx, %rdi
leaq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0x1dc1
testl %eax, %eax
js 0x1b61
movq 0x8(%rbx), %rax
movb 0x3(%rax), %al
cmpb 0x11(%rbx), %al
jne 0x1b61
movl 0x18(%rsp), %r14d
jmp 0x1ae6
movl 0x8(%rsp), %eax
movq %rax, (%rsp)
movq (%rbx), %rax
movzbl 0x1(%rax), %ecx
subl 0x10(%rbx), %ecx
pushq $0x1
popq %r15
shll %cl, %r15d
xorl %r12d, %r12d
movl %r15d, %r13d
leal -0x1(%r13), %eax
movq %rax, 0x8(%rsp)
cmpl %r13d, %r12d
jge 0x1be9
movq 0x8(%rsp), %rax
leal (%r12,%rax), %r14d
shrl %r14d
movb 0x10(%rbx), %cl
movl %r14d, %eax
shll %cl, %eax
movq (%rbx), %rcx
movb 0x1(%rcx), %cl
movq (%rsp), %rdx
movl %edx, %ebp
shll %cl, %ebp
orl %eax, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2642
testl %eax, %eax
jne 0x1bdb
incl %r14d
cmpl %r15d, %r14d
jge 0x1be0
movb 0x10(%rbx), %cl
pushq $0x1
popq %rsi
shll %cl, %esi
addl %ebp, %esi
movq %rbx, %rdi
callq 0x2642
movl %r14d, %r12d
testl %eax, %eax
je 0x1b81
jmp 0x1be0
movl %r14d, %r13d
jmp 0x1b78
movq (%rbx), %rax
movzbl 0x1(%rax), %ecx
jmp 0x1bf8
movq (%rbx), %rax
movzbl 0x1(%rax), %ecx
movq (%rsp), %rax
shll %cl, %eax
movl %eax, %ebp
movl %ebp, %eax
shrl %cl, %eax
movl %eax, (%rsp)
pushq $-0x1
popq %r13
shll %cl, %r13d
notl %r13d
andl %ebp, %r13d
movb 0x10(%rbx), %cl
shrl %cl, %r13d
testl %r13d, %r13d
js 0x1c76
movq (%rbx), %rdi
movb 0x1(%rdi), %cl
movl (%rsp), %eax
movl %eax, %r14d
shll %cl, %r14d
movq 0x8(%rbx), %r8
movb 0x10(%rbx), %cl
incl %r13d
movl %r13d, %r15d
shll %cl, %r15d
movb (%rdi), %cl
leal (%r15,%r14), %esi
decl %esi
pushq $0x1
popq %rax
shll %cl, %eax
movslq %eax, %rcx
xorl %edx, %edx
movq 0x20(%rsp), %r9
callq 0x310d
testl %eax, %eax
jne 0x1c70
movq 0x8(%rbx), %r12
movq %r12, %rdi
callq 0x262b
testl %eax, %eax
je 0x1c70
movb 0x3(%r12), %al
cmpb 0x11(%rbx), %al
je 0x1ca0
addl $-0x2, %r13d
jmp 0x1c12
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c86
movl $0x3, (%rax)
movq %rbx, %rdi
callq 0x1a4d
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl %r14d, %r15d
addl $-0x2, %r15d
movl %r15d, 0x28(%rbx)
movl 0x4(%r12), %eax
movl %eax, 0x20(%rbx)
movl 0x8(%r12), %eax
movl %eax, 0x14(%rbx)
movl 0xc(%r12), %eax
movl %eax, 0x18(%rbx)
movq (%rbx), %rax
movb (%rax), %cl
pushq $0x1
popq %rax
shll %cl, %eax
addq $0x14, %r12
addl $-0x14, %eax
movslq %eax, %rdx
movq %r12, %rdi
movl $0xff, %esi
callq 0x1090
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2053
movl %eax, %ebp
movl %eax, 0x24(%rbx)
testl %eax, %eax
jne 0x1d04
movl 0x14(%rbx), %eax
movl %eax, 0x18(%rbx)
andl $0x0, 0x14(%rbx)
incb 0x11(%rbx)
pushq $-0x1
popq %r15
movb 0x10(%rbx), %cl
pushq $0x1
popq %rax
movl %eax, %r12d
shll %cl, %r12d
movl %r12d, %eax
negl %eax
andl %ebp, %eax
movl %eax, %ebp
addl %r12d, %ebp
leal (%rax,%r12), %r14d
decl %r14d
xorl %r13d, %r13d
cmpl %r13d, %r12d
je 0x1d49
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x30b9
testl %eax, %eax
je 0x1d46
incl %r13d
decl %r14d
jmp 0x1d2a
movl %r13d, %r12d
cmpl $0x2, %r12d
jae 0x1da1
movl %ebp, 0x24(%rbx)
movq (%rbx), %rcx
movl 0x4(%rcx), %eax
movzbl 0x1(%rcx), %ecx
movl %eax, %edx
shll %cl, %edx
cmpl %edx, %ebp
jb 0x1d77
andl $0x0, 0x24(%rbx)
movl 0x14(%rbx), %edx
movl %edx, 0x18(%rbx)
andl $0x0, 0x14(%rbx)
incb 0x11(%rbx)
xorl %ebp, %ebp
movl %r15d, %edx
shll %cl, %edx
notl %edx
testl %edx, %ebp
jne 0x1d08
movl 0x20(%rbx), %edx
xorl %edx, %ebp
shrl %cl, %ebp
testl %ebp, %ebp
jne 0x1daa
shrl %cl, %edx
incl %edx
xorl %esi, %esi
cmpl %eax, %edx
cmovbl %edx, %esi
shll %cl, %esi
movl %esi, 0x20(%rbx)
movl %esi, %edx
jmp 0x1daa
subl %r12d, %ebp
movl %ebp, 0x24(%rbx)
movl 0x20(%rbx), %edx
movl %edx, 0x1c(%rbx)
orq $-0x1, 0x2c(%rbx)
orl $-0x1, 0x34(%rbx)
movb $0x0, 0x12(%rbx)
xorl %eax, %eax
jmp 0x1c91