// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]dhara/tests/journal.c
// Function: main
int main(void)
{
	struct dhara_journal journal;
	const size_t page_size = 1 << sim_nand.log2_page_size;
	uint8_t page_buf[page_size];
	int rep;

	sim_reset();
	sim_inject_bad(20);

	printf("Journal init\n");
	dhara_journal_init(&journal, &sim_nand, page_buf);
	dhara_journal_resume(&journal, NULL);
	dump_info(&journal);
	printf("\n");

	printf("Enqueue/dequeue, 100 pages x20\n");
	for (rep = 0; rep < 20; rep++) {
		int count;

		count = jt_enqueue_sequence(&journal, 0, 100);
		assert(count == 100);

		printf("    size     = %d -> ", dhara_journal_size(&journal));
		jt_dequeue_sequence(&journal, 0, count);
		printf("%d\n", dhara_journal_size(&journal));
	}
	printf("\n");

	printf("Journal stats:\n");
	dump_info(&journal);
	printf("\n");

	printf("Enqueue/dequeue, ~100 pages x20 (resume)\n");
	for (rep = 0; rep < 20; rep++) {
		uint8_t *cookie = dhara_journal_cookie(&journal);
		int count;

		cookie[0] = rep;
		count = jt_enqueue_sequence(&journal, 0, 100);
		assert(count == 100);

		while (!dhara_journal_is_clean(&journal)) {
			const int c = jt_enqueue_sequence(&journal,
				count++, 1);

			assert(c == 1);
		}

		printf("    size     = %d -> ", dhara_journal_size(&journal));
		suspend_resume(&journal);
		jt_dequeue_sequence(&journal, 0, count);
		printf("%d\n", dhara_journal_size(&journal));

		assert(cookie[0] == rep);
	}
	printf("\n");

	printf("Journal stats:\n");
	dump_info(&journal);
	printf("\n");

	sim_dump();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
leaq 0x21ef(%rip), %rax      # 0x51d8
movb (%rax), %cl
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rsp, %rcx
movq %rcx, -0x50(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
callq 0x3500
movl $0x14, %edi
callq 0x3cc0
leaq 0x1fcf(%rip), %rdi      # 0x5004
movb $0x0, %al
callq 0x1050
movq -0x78(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq 0x218d(%rip), %rsi      # 0x51d8
callq 0x11c0
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1330
leaq -0x40(%rbp), %rdi
callq 0x3300
leaq 0x22e9(%rip), %rdi      # 0x5356
movb $0x0, %al
callq 0x1050
leaq 0x1f97(%rip), %rdi      # 0x5012
movb $0x0, %al
callq 0x1050
movl $0x0, -0x5c(%rbp)
cmpl $0x14, -0x5c(%rbp)
jge 0x311b
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x43c0
movl %eax, -0x60(%rbp)
cmpl $0x64, -0x60(%rbp)
jne 0x30ae
jmp 0x30cd
leaq 0x1f7d(%rip), %rdi      # 0x5032
leaq 0x1f83(%rip), %rsi      # 0x503f
movl $0x4a, %edx
leaq 0x1f87(%rip), %rcx      # 0x504f
callq 0x1060
leaq -0x40(%rbp), %rdi
callq 0x1cb0
movl %eax, %esi
leaq 0x1f7f(%rip), %rdi      # 0x505e
movb $0x0, %al
callq 0x1050
movl -0x60(%rbp), %edx
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x4700
leaq -0x40(%rbp), %rdi
callq 0x1cb0
movl %eax, %esi
leaq 0x23c5(%rip), %rdi      # 0x54cb
movb $0x0, %al
callq 0x1050
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x3089
leaq 0x2234(%rip), %rdi      # 0x5356
movb $0x0, %al
callq 0x1050
leaq 0x1f44(%rip), %rdi      # 0x5074
movb $0x0, %al
callq 0x1050
leaq -0x40(%rbp), %rdi
callq 0x3300
leaq 0x220f(%rip), %rdi      # 0x5356
movb $0x0, %al
callq 0x1050
leaq 0x1f2f(%rip), %rdi      # 0x5084
movb $0x0, %al
callq 0x1050
movl $0x0, -0x5c(%rbp)
cmpl $0x14, -0x5c(%rbp)
jge 0x32a3
leaq -0x40(%rbp), %rdi
callq 0x3380
movq %rax, -0x68(%rbp)
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x68(%rbp), %rax
movb %cl, (%rax)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x43c0
movl %eax, -0x6c(%rbp)
cmpl $0x64, -0x6c(%rbp)
jne 0x31a0
jmp 0x31bf
leaq 0x1e8b(%rip), %rdi      # 0x5032
leaq 0x1e91(%rip), %rsi      # 0x503f
movl $0x5d, %edx
leaq 0x1e95(%rip), %rcx      # 0x504f
callq 0x1060
jmp 0x31c1
leaq -0x40(%rbp), %rdi
callq 0x33a0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x31d8
jmp 0x321d
movl -0x6c(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
leaq -0x40(%rbp), %rdi
movl $0x1, %edx
callq 0x43c0
movl %eax, -0x70(%rbp)
cmpl $0x1, -0x70(%rbp)
jne 0x31fc
jmp 0x321b
leaq 0x1eab(%rip), %rdi      # 0x50ae
leaq 0x1e35(%rip), %rsi      # 0x503f
movl $0x63, %edx
leaq 0x1e39(%rip), %rcx      # 0x504f
callq 0x1060
jmp 0x31c1
leaq -0x40(%rbp), %rdi
callq 0x1cb0
movl %eax, %esi
leaq 0x1e2f(%rip), %rdi      # 0x505e
movb $0x0, %al
callq 0x1050
leaq -0x40(%rbp), %rdi
callq 0x33c0
movl -0x6c(%rbp), %edx
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x4700
leaq -0x40(%rbp), %rdi
callq 0x1cb0
movl %eax, %esi
leaq 0x226c(%rip), %rdi      # 0x54cb
movb $0x0, %al
callq 0x1050
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
cmpl -0x5c(%rbp), %eax
jne 0x3274
jmp 0x3293
leaq 0x1e3a(%rip), %rdi      # 0x50b5
leaq 0x1dbd(%rip), %rsi      # 0x503f
movl $0x6b, %edx
leaq 0x1dc1(%rip), %rcx      # 0x504f
callq 0x1060
jmp 0x3295
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x3163
leaq 0x20ac(%rip), %rdi      # 0x5356
movb $0x0, %al
callq 0x1050
leaq 0x1dbc(%rip), %rdi      # 0x5074
movb $0x0, %al
callq 0x1050
leaq -0x40(%rbp), %rdi
callq 0x3300
leaq 0x2087(%rip), %rdi      # 0x5356
movb $0x0, %al
callq 0x1050
callq 0x3df0
movl $0x0, -0x4(%rbp)
movq -0x50(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)