// File: /workspace/github_c_makefile_star2_O2/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 0x1328(%rip), %rbx      # 0x31e4
movb (%rbx), %cl
pushq $0x1
popq %rax
shll %cl, %eax
movq %rsp, -0x38(%rbp)
cltq
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
callq 0x225c
pushq $0x14
popq %r14
movl %r14d, %edi
callq 0x26b9
leaq 0x127b(%rip), %rdi      # 0x316d
callq 0x1060
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x11dc
movq %r15, %rdi
xorl %esi, %esi
callq 0x1262
movq %r15, %rdi
callq 0x21f0
pushq $0xa
popq %rdi
callq 0x1030
leaq 0x1250(%rip), %rdi      # 0x317a
callq 0x1060
pushq $0x64
popq %r12
leaq 0x10f6(%rip), %rbx      # 0x3030
leaq 0x157e(%rip), %r13      # 0x34bf
subl $0x1, %r14d
jb 0x1f94
movq %r15, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x2b3c
cmpl $0x64, %eax
jne 0x2154
movq %r15, %rdi
callq 0x1681
movq %rbx, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movq %r15, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x2df6
movq %r15, %rdi
callq 0x1681
movq %r13, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
jmp 0x1f41
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x1030
leaq 0x121d(%rip), %rdi      # 0x31c2
callq 0x1060
leaq -0x80(%rbp), %r14
movq %r14, %rdi
callq 0x21f0
movl %ebx, %edi
callq 0x1030
leaq 0x11d5(%rip), %rdi      # 0x3199
callq 0x1060
pushq $0x1
popq %r15
xorl %r13d, %r13d
cmpl $0x14, %r13d
je 0x20f7
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movb %r13b, 0x10(%rax)
movq %r14, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x2b3c
cmpl $0x64, %eax
jne 0x216d
movl %r12d, %ebx
testb $0x1, -0x6e(%rbp)
je 0x201f
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x2b3c
cmpl $0x1, %eax
jne 0x2137
incl %ebx
jmp 0x1fff
movq %r13, -0x40(%rbp)
movq %r14, %rdi
callq 0x1681
leaq 0xffe(%rip), %rdi       # 0x3030
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl -0x58(%rbp), %r12d
movl -0x60(%rbp), %r13d
movl -0x5c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq %r14, %rdi
callq 0x184b
cmpl $-0x1, -0x58(%rbp)
jne 0x2186
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1262
testl %eax, %eax
jns 0x207a
movl -0x30(%rbp), %esi
leaq 0x10a7(%rip), %rdi      # 0x311c
callq 0x29cb
cmpl -0x58(%rbp), %r12d
jne 0x21d4
cmpl -0x60(%rbp), %r13d
pushq $0x64
popq %r12
jne 0x21b8
movl -0x2c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
movq -0x40(%rbp), %r13
jne 0x219f
movq %r14, %rdi
xorl %esi, %esi
movl %ebx, %edx
callq 0x2df6
movq %r14, %rdi
callq 0x1681
leaq 0x1402(%rip), %rdi      # 0x34bf
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movq -0x48(%rbp), %rax
movzbl 0x10(%rax), %eax
leal 0x1(%r13), %ecx
cmpl %eax, %r13d
movl %ecx, %r13d
je 0x1fd0
leaq 0xf68(%rip), %rdi       # 0x304d
leaq 0xf25(%rip), %rsi       # 0x3011
leaq 0xf2e(%rip), %rcx       # 0x3021
pushq $0x6b
jmp 0x214e
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x1030
leaq 0x10ba(%rip), %rdi      # 0x31c2
callq 0x1060
leaq -0x80(%rbp), %rdi
callq 0x21f0
movl %ebx, %edi
callq 0x1030
callq 0x2788
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 0xf08(%rip), %rdi       # 0x3046
leaq 0xecc(%rip), %rsi       # 0x3011
leaq 0xed5(%rip), %rcx       # 0x3021
pushq $0x63
popq %rdx
callq 0x1080
leaq 0xea9(%rip), %rdi       # 0x3004
leaq 0xeaf(%rip), %rsi       # 0x3011
leaq 0xeb8(%rip), %rcx       # 0x3021
pushq $0x4a
jmp 0x214e
leaq 0xe90(%rip), %rdi       # 0x3004
leaq 0xe96(%rip), %rsi       # 0x3011
leaq 0xe9f(%rip), %rcx       # 0x3021
pushq $0x5d
jmp 0x214e
leaq 0xf3a(%rip), %rdi       # 0x30c7
leaq 0xe7d(%rip), %rsi       # 0x3011
leaq 0xf55(%rip), %rcx       # 0x30f0
pushq $0x22
jmp 0x214e
leaq 0xfb3(%rip), %rdi       # 0x3159
leaq 0xe64(%rip), %rsi       # 0x3011
leaq 0xf3c(%rip), %rcx       # 0x30f0
pushq $0x29
jmp 0x214e
leaq 0xf86(%rip), %rdi       # 0x3145
leaq 0xe4b(%rip), %rsi       # 0x3011
leaq 0xf23(%rip), %rcx       # 0x30f0
pushq $0x28
jmp 0x214e
leaq 0xf48(%rip), %rdi       # 0x3123
leaq 0xe2f(%rip), %rsi       # 0x3011
leaq 0xf07(%rip), %rcx       # 0x30f0
pushq $0x27
jmp 0x214e