// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x2068(%rip), %r14      # 0x41e4
movb (%r14), %cl
movl $0x1, %eax
shll %cl, %eax
movq %rsp, -0x38(%rbp)
cltq
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
callq 0x2548
movl $0x14, %r12d
movl $0x14, %edi
callq 0x28e5
leaq 0x1fb4(%rip), %rdi      # 0x416d
callq 0x1060
leaq -0x78(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x12ec
movq %rbx, %rdi
xorl %esi, %esi
callq 0x137b
movq %rbx, %rdi
callq 0x24dc
movl $0xa, %edi
callq 0x1030
leaq 0x1f87(%rip), %rdi      # 0x417a
callq 0x1060
leaq 0x1e31(%rip), %r14      # 0x4030
leaq 0x22b9(%rip), %r15      # 0x44bf
movq %rbx, %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x2dd0
cmpl $0x64, %eax
jne 0x2403
movq %rbx, %rdi
callq 0x1896
movq %r14, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x308a
movq %rbx, %rdi
callq 0x1896
movq %r15, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
decl %r12d
jne 0x2206
movl $0xa, %edi
callq 0x1030
leaq 0x1f57(%rip), %rdi      # 0x41c2
callq 0x1060
leaq -0x78(%rbp), %rbx
movq %rbx, %rdi
callq 0x24dc
movl $0xa, %edi
callq 0x1030
leaq 0x1f0c(%rip), %rdi      # 0x4199
callq 0x1060
xorl %r14d, %r14d
movq -0x70(%rbp), %r15
movb %r14b, 0x10(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x2dd0
cmpl $0x64, %eax
jne 0x2422
movl $0x64, %r12d
testb $0x1, -0x66(%rbp)
je 0x22df
movq %rbx, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x2dd0
cmpl $0x1, %eax
jne 0x23e4
incl %r12d
jmp 0x22bb
movq %r15, -0x40(%rbp)
movl %r14d, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x1896
leaq 0x1d3a(%rip), %rdi      # 0x4030
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl -0x50(%rbp), %r14d
movl -0x58(%rbp), %r15d
movl -0x54(%rbp), %r13d
movq %rbx, %rdi
callq 0x1a68
cmpl $-0x1, -0x50(%rbp)
jne 0x24bd
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
callq 0x137b
testl %eax, %eax
jns 0x233c
movl -0x30(%rbp), %esi
leaq 0x1de5(%rip), %rdi      # 0x411c
callq 0x2c45
cmpl -0x50(%rbp), %r14d
jne 0x249e
cmpl -0x58(%rbp), %r15d
jne 0x247f
cmpl -0x54(%rbp), %r13d
jne 0x2460
movq %rbx, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x308a
movq %rbx, %rdi
callq 0x1896
leaq 0x2149(%rip), %rdi      # 0x44bf
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movq -0x40(%rbp), %rax
movzbl 0x10(%rax), %eax
movl -0x2c(%rbp), %r14d
cmpl %eax, %r14d
jne 0x2441
incl %r14d
cmpl $0x14, %r14d
jne 0x2295
movl $0xa, %edi
callq 0x1030
leaq 0x1e10(%rip), %rdi      # 0x41c2
callq 0x1060
leaq -0x78(%rbp), %rdi
callq 0x24dc
movl $0xa, %edi
callq 0x1030
callq 0x29f2
movq -0x38(%rbp), %rsp
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c5b(%rip), %rdi      # 0x4046
leaq 0x1c1f(%rip), %rsi      # 0x4011
leaq 0x1c28(%rip), %rcx      # 0x4021
movl $0x63, %edx
callq 0x1080
leaq 0x1bfa(%rip), %rdi      # 0x4004
leaq 0x1c00(%rip), %rsi      # 0x4011
leaq 0x1c09(%rip), %rcx      # 0x4021
movl $0x4a, %edx
callq 0x1080
leaq 0x1bdb(%rip), %rdi      # 0x4004
leaq 0x1be1(%rip), %rsi      # 0x4011
leaq 0x1bea(%rip), %rcx      # 0x4021
movl $0x5d, %edx
callq 0x1080
leaq 0x1c05(%rip), %rdi      # 0x404d
leaq 0x1bc2(%rip), %rsi      # 0x4011
leaq 0x1bcb(%rip), %rcx      # 0x4021
movl $0x6b, %edx
callq 0x1080
leaq 0x1cf2(%rip), %rdi      # 0x4159
leaq 0x1ba3(%rip), %rsi      # 0x4011
leaq 0x1c7b(%rip), %rcx      # 0x40f0
movl $0x29, %edx
callq 0x1080
leaq 0x1cbf(%rip), %rdi      # 0x4145
leaq 0x1b84(%rip), %rsi      # 0x4011
leaq 0x1c5c(%rip), %rcx      # 0x40f0
movl $0x28, %edx
callq 0x1080
leaq 0x1c7e(%rip), %rdi      # 0x4123
leaq 0x1b65(%rip), %rsi      # 0x4011
leaq 0x1c3d(%rip), %rcx      # 0x40f0
movl $0x27, %edx
callq 0x1080
leaq 0x1c03(%rip), %rdi      # 0x40c7
leaq 0x1b46(%rip), %rsi      # 0x4011
leaq 0x1c1e(%rip), %rcx      # 0x40f0
movl $0x22, %edx
callq 0x1080