// File: /workspace/github_c_makefile_star2_O3/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
xorl %ebp, %ebp
leaq 0x14(%rsp), %rdx
xorl %esi, %esi
movq %r14, %rcx
callq 0x2030
testl %eax, %eax
js 0x1c9a
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), %r12d
decl %r12d
cmpl %ecx, %r12d
jae 0x1cd0
movl %ecx, %r13d
jmp 0x1d57
movb %bpl, 0x11(%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rdi
movl 0x4(%rax), %ecx
shrl $0x6, %ecx
movl %ecx, 0x18(%rbx)
movl %ebp, 0x14(%rbx)
movl %ebp, 0x24(%rbx)
movq $0x0, 0x1c(%rbx)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x28(%rbx)
movb %bpl, 0x12(%rbx)
movb (%rax), %cl
jmp 0x1eb2
leaq 0x1c(%rsp), %r15
movl %ecx, 0x8(%rsp)
movl %ecx, %r14d
leal (%r12,%r14), %r13d
movl %r13d, %ebp
shrl %ebp
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x2030
testl %eax, %eax
js 0x1d04
movq 0x8(%rbx), %rax
movb 0x3(%rax), %al
cmpb 0x11(%rbx), %al
je 0x1d16
cmpl $0x1, %r13d
jbe 0x1d50
decl %ebp
movl %ebp, %r12d
cmpl %ebp, %r14d
jbe 0x1cdc
jmp 0x1d50
movl 0x1c(%rsp), %r13d
leal 0x1(%r13), %esi
movq (%rbx), %rax
cmpl 0x4(%rax), %esi
jae 0x1d57
movq %rbx, %rdi
leaq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2030
testl %eax, %eax
js 0x1d57
movq 0x8(%rbx), %rax
movb 0x3(%rax), %al
cmpb 0x11(%rbx), %al
jne 0x1d57
movl 0x18(%rsp), %r14d
cmpl %r12d, %r14d
jbe 0x1cdc
movl 0x8(%rsp), %eax
movl %eax, %r13d
movq (%rbx), %rdx
movzbl 0x1(%rdx), %eax
movzbl 0x10(%rbx), %esi
movl %eax, %ecx
subl %esi, %ecx
movl $0x1, %esi
shll %cl, %esi
cmpl $0x1f, %ecx
je 0x1de7
movq %rsi, 0x8(%rsp)
leal -0x1(%rsi), %ebp
xorl %r14d, %r14d
leal (%r14,%rbp), %r12d
shrl %r12d
movb 0x10(%rbx), %cl
movl %r12d, %eax
shll %cl, %eax
movq (%rbx), %rcx
movb 0x1(%rcx), %cl
movl %r13d, %r15d
shll %cl, %r15d
orl %eax, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x285d
testl %eax, %eax
je 0x1db5
decl %r12d
movl %r12d, %ebp
movl %r14d, %r12d
jmp 0x1dd8
incl %r12d
cmpl 0x8(%rsp), %r12d
jge 0x1df1
movb 0x10(%rbx), %cl
movl $0x1, %esi
shll %cl, %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x285d
testl %eax, %eax
jne 0x1df1
movl %r12d, %r14d
cmpl %ebp, %r12d
jle 0x1d7d
movq (%rbx), %rdx
movzbl 0x1(%rdx), %eax
movl %eax, %ecx
shll %cl, %r13d
movl %r13d, %r15d
jmp 0x1df4
movq (%rbx), %rdx
movb 0x1(%rdx), %cl
movl %r15d, %ebp
shrl %cl, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shll %cl, %r12d
notl %r12d
andl %r15d, %r12d
movb 0x10(%rbx), %cl
shrl %cl, %r12d
incl %r12d
movq (%rbx), %rdi
movb 0x1(%rdi), %cl
movl %ebp, %r13d
shll %cl, %r13d
movq 0x8(%rbx), %r8
movb 0x10(%rbx), %cl
movl %r12d, %r14d
shll %cl, %r14d
movb (%rdi), %cl
leal (%r14,%r13), %esi
decl %esi
movl $0x1, %eax
shll %cl, %eax
movslq %eax, %rcx
xorl %edx, %edx
movq 0x20(%rsp), %r9
callq 0x33f0
testl %eax, %eax
jne 0x1e6c
movq 0x8(%rbx), %rdi
cmpb $0x44, (%rdi)
jne 0x1e6c
cmpb $0x68, 0x1(%rdi)
jne 0x1e6c
cmpb $0x61, 0x2(%rdi)
jne 0x1e6c
movb 0x3(%rdi), %al
cmpb 0x11(%rbx), %al
je 0x1eda
decl %r12d
jg 0x1e14
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1e81
movl $0x3, (%rax)
xorl %eax, %eax
movb %al, 0x11(%rbx)
movq (%rbx), %rcx
movq 0x8(%rbx), %rdi
movl 0x4(%rcx), %edx
shrl $0x6, %edx
movl %edx, 0x18(%rbx)
movl %eax, 0x14(%rbx)
movl %eax, 0x24(%rbx)
movq $0x0, 0x1c(%rbx)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x28(%rbx)
movb %al, 0x12(%rbx)
movb (%rcx), %cl
movl $0x1, %eax
shll %cl, %eax
movslq %eax, %rdx
movl $0xff, %esi
callq 0x1090
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl %r13d, %r14d
addl $-0x2, %r14d
movl %r14d, 0x28(%rbx)
movl 0x4(%rdi), %eax
movl %eax, 0x20(%rbx)
movl 0x8(%rdi), %eax
movl %eax, 0x14(%rbx)
movl 0xc(%rdi), %eax
movl %eax, 0x18(%rbx)
movq (%rbx), %rax
movb (%rax), %cl
movl $0x1, %eax
shll %cl, %eax
addq $0x14, %rdi
addl $-0x14, %eax
movslq %eax, %rdx
movl $0xff, %esi
callq 0x1090
movq (%rbx), %rdx
movb 0x10(%rbx), %cl
movb 0x1(%rdx), %al
movl 0x4(%rdx), %edx
leal 0x1(%r15), %esi
addl $0x2, %r15d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
notl %edi
testl %edi, %r15d
cmovnel %esi, %r15d
movl %eax, %ecx
shll %cl, %edx
xorl %r14d, %r14d
cmpl %edx, %r15d
cmovbl %r15d, %r14d
movl %r14d, 0x24(%rbx)
testl %r14d, %r14d
jne 0x1f62
movl 0x14(%rbx), %eax
movl %eax, 0x18(%rbx)
movl $0x0, 0x14(%rbx)
incb 0x11(%rbx)
movb 0x10(%rbx), %cl
movl $0x1, %r15d
shll %cl, %r15d
movl %r15d, %r13d
negl %r13d
andl %r13d, %r14d
movl %r14d, %eax
addl %r15d, %r14d
leal (%rax,%r15), %ebp
decl %ebp
xorl %r12d, %r12d
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x33b4
testl %eax, %eax
je 0x1fa4
incl %r12d
decl %ebp
movl %r13d, %eax
addl %r12d, %eax
jne 0x1f86
movl %r15d, %r12d
cmpl $0x2, %r12d
jae 0x2009
movl %r14d, 0x24(%rbx)
movq (%rbx), %rcx
movl 0x4(%rcx), %eax
movzbl 0x1(%rcx), %ecx
movl %eax, %edx
shll %cl, %edx
cmpl %edx, %r14d
jb 0x1fd5
xorl %r14d, %r14d
movl %r14d, 0x24(%rbx)
movl 0x14(%rbx), %edx
movl %edx, 0x18(%rbx)
movl %r14d, 0x14(%rbx)
incb 0x11(%rbx)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
notl %edx
testl %edx, %r14d
jne 0x1f62
movl 0x20(%rbx), %edx
xorl %edx, %r14d
shrl %cl, %r14d
testl %r14d, %r14d
jne 0x2013
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 0x2013
subl %r12d, %r14d
movl %r14d, 0x24(%rbx)
movl 0x20(%rbx), %edx
movl %edx, 0x1c(%rbx)
movq $-0x1, 0x2c(%rbx)
movl $0xffffffff, 0x34(%rbx) # imm = 0xFFFFFFFF
movb $0x0, 0x12(%rbx)
xorl %eax, %eax
jmp 0x1ecb