// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]dhara/tests/map.c
// Function: test
static void test(void)
{
	const size_t page_size = 1 << sim_nand.log2_page_size;
	uint8_t page_buf[page_size];
	struct dhara_map map;
	int i;

	printf("%d\n", (int)sizeof(map));

	sim_reset();
	sim_inject_bad(10);
	sim_inject_timebombs(30, 20);

	printf("Map init\n");
	dhara_map_init(&map, &sim_nand, page_buf, GC_RATIO);
	dhara_map_resume(&map, NULL);
	printf("  capacity: %d\n", dhara_map_capacity(&map));
	printf("  sector count: %d\n", NUM_SECTORS);
	printf("\n");

	printf("Sync...\n");
	dhara_map_sync(&map, NULL);
	printf("Resume...\n");
	dhara_map_init(&map, &sim_nand, page_buf, GC_RATIO);
	dhara_map_resume(&map, NULL);

	printf("Writing sectors...\n");
	shuffle(0);
	for (i = 0; i < NUM_SECTORS; i++) {
		const dhara_sector_t s = sector_list[i];

		mt_write(&map, s, s);
		mt_check(&map);
	}

	printf("Sync...\n");
	dhara_map_sync(&map, NULL);
	printf("Resume...\n");
	dhara_map_init(&map, &sim_nand, page_buf, GC_RATIO);
	dhara_map_resume(&map, NULL);
	printf("  capacity: %d\n", dhara_map_capacity(&map));
	printf("  use count: %d\n", dhara_map_size(&map));
	printf("\n");

	printf("Read back...\n");
	shuffle(1);
	for (i = 0; i < NUM_SECTORS; i++) {
		const dhara_sector_t s = sector_list[i];

		mt_assert(&map, s, s);
	}

	printf("Rewrite/trim half...\n");
	shuffle(2);
	for (i = 0; i < NUM_SECTORS; i += 2) {
		const dhara_sector_t s0 = sector_list[i];
		const dhara_sector_t s1 = sector_list[i + 1];

		mt_write(&map, s0, ~s0);
		mt_check(&map);
		mt_trim(&map, s1);
		mt_check(&map);
	}

	printf("Sync...\n");
	dhara_map_sync(&map, NULL);
	printf("Resume...\n");
	dhara_map_init(&map, &sim_nand, page_buf, GC_RATIO);
	dhara_map_resume(&map, NULL);
	printf("  capacity: %d\n", dhara_map_capacity(&map));
	printf("  use count: %d\n", dhara_map_size(&map));
	printf("\n");

	printf("Read back...\n");
	for (i = 0; i < NUM_SECTORS; i += 2) {
		const dhara_sector_t s0 = sector_list[i];
		const dhara_sector_t s1 = sector_list[i + 1];

		mt_assert(&map, s0, ~s0);
		mt_assert_blank(&map, s1);
	}

	printf("\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x1be4(%rip), %r12      # 0x4344
movb (%r12), %cl
pushq $0x1
popq %rax
shll %cl, %eax
cltq
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
leaq 0x1e9c(%rip), %rdi      # 0x461f
xorl %r14d, %r14d
pushq $0x40
popq %rsi
xorl %eax, %eax
callq 0x1070
callq 0x2dac
pushq $0xa
popq %r13
movl %r13d, %edi
callq 0x3209
pushq $0x1e
popq %rdi
pushq $0x14
popq %rsi
callq 0x3279
leaq 0x1b2e(%rip), %rdi      # 0x42e1
callq 0x1060
leaq -0x80(%rbp), %r15
pushq $0x4
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %ecx, %r12d
callq 0x11dc
movq %r15, %rdi
xorl %esi, %esi
callq 0x11fc
movq %r15, %rdi
callq 0x122e
leaq 0x18fb(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
leaq 0x18fb(%rip), %rdi      # 0x40f4
movl $0xc8, %esi
xorl %eax, %eax
callq 0x1070
movl %r13d, %edi
callq 0x1030
leaq 0x1afe(%rip), %rdi      # 0x4312
callq 0x1060
movq %r15, %rdi
xorl %esi, %esi
callq 0x1812
leaq 0x1af0(%rip), %rdi      # 0x431a
callq 0x1060
movq %r15, %rdi
leaq 0x1b0b(%rip), %rsi      # 0x4344
movq %rbx, -0x38(%rbp)
movq %rbx, %rdx
movl %r12d, %ecx
callq 0x11dc
movq %r15, %rdi
xorl %esi, %esi
callq 0x11fc
leaq 0x1a91(%rip), %rdi      # 0x42ea
callq 0x1060
xorl %edi, %edi
callq 0x2ad1
leaq 0x4824(%rip), %rbx      # 0x7090
cmpq $0x320, %r14            # imm = 0x320
je 0x2891
movl (%r14,%rbx), %edx
movq %r15, %rdi
movl %edx, %esi
callq 0x2b34
movq %r15, %rdi
callq 0x2b9e
addq $0x4, %r14
jmp 0x286c
leaq 0x1a7a(%rip), %rdi      # 0x4312
callq 0x1060
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1812
leaq 0x1a65(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x1a83(%rip), %rsi      # 0x4344
pushq $0x4
popq %rcx
movq %r14, %rdi
movq -0x38(%rbp), %rdx
callq 0x11dc
movq %r14, %rdi
xorl %esi, %esi
callq 0x11fc
movq %r14, %rdi
callq 0x122e
leaq 0x17fb(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x180b(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
pushq $0xa
popq %rdi
callq 0x1030
leaq 0x1a11(%rip), %rdi      # 0x4324
callq 0x1060
pushq $0x1
popq %rdi
callq 0x2ad1
cmpq $0x320, %r15            # imm = 0x320
je 0x293d
movl (%r15,%rbx), %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x2bec
addq $0x4, %r15
jmp 0x2920
leaq 0x19b9(%rip), %rdi      # 0x42fd
callq 0x1060
pushq $0x2
popq %rdi
callq 0x2ad1
xorl %r12d, %r12d
leaq -0x80(%rbp), %r14
leaq -0x2c(%rbp), %r15
cmpq $0xc7, %r12
ja 0x29b1
movl (%rbx,%r12,4), %esi
movl 0x4(%rbx,%r12,4), %r13d
movl %esi, %edx
notl %edx
movq %r14, %rdi
callq 0x2b34
movq %r14, %rdi
callq 0x2b9e
movq %r14, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x1691
testl %eax, %eax
jns 0x29a3
movl -0x2c(%rbp), %esi
leaq 0x18a1(%rip), %rdi      # 0x423f
callq 0x351b
movq %r14, %rdi
callq 0x2b9e
addq $0x2, %r12
jmp 0x295c
leaq 0x195a(%rip), %rdi      # 0x4312
callq 0x1060
xorl %r13d, %r13d
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1812
leaq 0x1945(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x1963(%rip), %rsi      # 0x4344
pushq $0x4
popq %rcx
movq %r14, %rdi
movq -0x38(%rbp), %rdx
callq 0x11dc
movq %r14, %rdi
xorl %esi, %esi
callq 0x11fc
movq %r14, %rdi
callq 0x122e
leaq 0x16db(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x16eb(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
pushq $0xa
popq %rdi
callq 0x1030
leaq 0x18f1(%rip), %rdi      # 0x4324
callq 0x1060
leaq -0x2c(%rbp), %r15
cmpq $0xc7, %r13
ja 0x2a7c
movl (%rbx,%r13,4), %esi
movl 0x4(%rbx,%r13,4), %r12d
movl %esi, %edx
notl %edx
movq %r14, %rdi
callq 0x2bec
movq %r14, %rdi
movl %r12d, %esi
leaq -0x3c(%rbp), %rdx
movq %r15, %rcx
callq 0x125b
testl %eax, %eax
jns 0x2a93
cmpl $0x6, -0x2c(%rbp)
jne 0x2ab2
addq $0x2, %r13
jmp 0x2a3c
pushq $0xa
popq %rdi
callq 0x1030
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17ae(%rip), %rdi      # 0x4248
leaq 0x1694(%rip), %rsi      # 0x4135
leaq 0x17a6(%rip), %rcx      # 0x424e
movl $0x91, %edx
callq 0x1080
leaq 0x17ce(%rip), %rdi      # 0x4287
leaq 0x1675(%rip), %rsi      # 0x4135
leaq 0x1787(%rip), %rcx      # 0x424e
movl $0x92, %edx
callq 0x1080