// File: /workspace/github_c_makefile_star2_O3/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 0x2084(%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 0x252c
movl $0x14, %r12d
movl $0x14, %edi
callq 0x28c5
leaq 0x1fd0(%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 0x24c0
movl $0xa, %edi
callq 0x1030
leaq 0x1fa3(%rip), %rdi      # 0x417a
callq 0x1060
leaq 0x1e4d(%rip), %r14      # 0x4030
leaq 0x22d5(%rip), %r15      # 0x44bf
movq %rbx, %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x2d94
cmpl $0x64, %eax
jne 0x23e7
movq %rbx, %rdi
callq 0x186d
movq %r14, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
xorl %esi, %esi
movl $0x64, %edx
callq 0x303c
movq %rbx, %rdi
callq 0x186d
movq %r15, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
decl %r12d
jne 0x21ea
movl $0xa, %edi
callq 0x1030
leaq 0x1f73(%rip), %rdi      # 0x41c2
callq 0x1060
leaq -0x78(%rbp), %rbx
movq %rbx, %rdi
callq 0x24c0
movl $0xa, %edi
callq 0x1030
leaq 0x1f28(%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 0x2d94
cmpl $0x64, %eax
jne 0x2406
movl $0x64, %r12d
testb $0x1, -0x66(%rbp)
je 0x22c3
movq %rbx, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x2d94
cmpl $0x1, %eax
jne 0x23c8
incl %r12d
jmp 0x229f
movq %r15, -0x40(%rbp)
movl %r14d, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x186d
leaq 0x1d56(%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 0x1a36
cmpl $-0x1, -0x50(%rbp)
jne 0x24a1
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
callq 0x137b
testl %eax, %eax
jns 0x2320
movl -0x30(%rbp), %esi
leaq 0x1e01(%rip), %rdi      # 0x411c
callq 0x2c09
cmpl -0x50(%rbp), %r14d
jne 0x2482
cmpl -0x58(%rbp), %r15d
jne 0x2463
cmpl -0x54(%rbp), %r13d
jne 0x2444
movq %rbx, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x303c
movq %rbx, %rdi
callq 0x186d
leaq 0x2165(%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 0x2425
incl %r14d
cmpl $0x14, %r14d
jne 0x2279
movl $0xa, %edi
callq 0x1030
leaq 0x1e2c(%rip), %rdi      # 0x41c2
callq 0x1060
leaq -0x78(%rbp), %rdi
callq 0x24c0
movl $0xa, %edi
callq 0x1030
callq 0x29d2
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 0x1c77(%rip), %rdi      # 0x4046
leaq 0x1c3b(%rip), %rsi      # 0x4011
leaq 0x1c44(%rip), %rcx      # 0x4021
movl $0x63, %edx
callq 0x1080
leaq 0x1c16(%rip), %rdi      # 0x4004
leaq 0x1c1c(%rip), %rsi      # 0x4011
leaq 0x1c25(%rip), %rcx      # 0x4021
movl $0x4a, %edx
callq 0x1080
leaq 0x1bf7(%rip), %rdi      # 0x4004
leaq 0x1bfd(%rip), %rsi      # 0x4011
leaq 0x1c06(%rip), %rcx      # 0x4021
movl $0x5d, %edx
callq 0x1080
leaq 0x1c21(%rip), %rdi      # 0x404d
leaq 0x1bde(%rip), %rsi      # 0x4011
leaq 0x1be7(%rip), %rcx      # 0x4021
movl $0x6b, %edx
callq 0x1080
leaq 0x1d0e(%rip), %rdi      # 0x4159
leaq 0x1bbf(%rip), %rsi      # 0x4011
leaq 0x1c97(%rip), %rcx      # 0x40f0
movl $0x29, %edx
callq 0x1080
leaq 0x1cdb(%rip), %rdi      # 0x4145
leaq 0x1ba0(%rip), %rsi      # 0x4011
leaq 0x1c78(%rip), %rcx      # 0x40f0
movl $0x28, %edx
callq 0x1080
leaq 0x1c9a(%rip), %rdi      # 0x4123
leaq 0x1b81(%rip), %rsi      # 0x4011
leaq 0x1c59(%rip), %rcx      # 0x40f0
movl $0x27, %edx
callq 0x1080
leaq 0x1c1f(%rip), %rdi      # 0x40c7
leaq 0x1b62(%rip), %rsi      # 0x4011
leaq 0x1c3a(%rip), %rcx      # 0x40f0
movl $0x22, %edx
callq 0x1080