// File: /workspace/github_c_makefile_star2_O1/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 0x1802(%rip), %r14      # 0x4344
movb (%r14), %cl
movl $0x1, %eax
shll %cl, %eax
cltq
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
leaq 0x1ab9(%rip), %rdi      # 0x461f
xorl %r12d, %r12d
movl $0x40, %esi
xorl %eax, %eax
callq 0x1070
callq 0x31dc
movl $0xa, %edi
callq 0x3579
movl $0x1e, %edi
movl $0x14, %esi
callq 0x3614
leaq 0x1747(%rip), %rdi      # 0x42e1
callq 0x1060
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl $0x4, %ecx
callq 0x12ec
movq %r15, %rdi
xorl %esi, %esi
callq 0x130c
movq %r15, %rdi
callq 0x1343
leaq 0x1515(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
leaq 0x1515(%rip), %rdi      # 0x40f4
movl $0xc8, %esi
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x1716(%rip), %rdi      # 0x4312
callq 0x1060
movq %r15, %rdi
xorl %esi, %esi
callq 0x1a31
leaq 0x1708(%rip), %rdi      # 0x431a
callq 0x1060
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl $0x4, %ecx
callq 0x12ec
movq %r15, %rdi
xorl %esi, %esi
callq 0x130c
leaq 0x16af(%rip), %rdi      # 0x42ea
callq 0x1060
xorl %edi, %edi
callq 0x2ec6
leaq 0x4442(%rip), %rbx      # 0x7090
movl (%r12,%rbx), %edx
movq %r15, %rdi
movl %edx, %esi
callq 0x2f27
movq %r15, %rdi
callq 0x2f93
addq $0x4, %r12
cmpq $0x320, %r12            # imm = 0x320
jne 0x2c4e
leaq 0x169a(%rip), %rdi      # 0x4312
callq 0x1060
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a31
leaq 0x1685(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x16a3(%rip), %rsi      # 0x4344
movq %r14, %rdi
movq %r13, -0x38(%rbp)
movq %r13, %rdx
movl $0x4, %ecx
callq 0x12ec
movq %r14, %rdi
xorl %esi, %esi
callq 0x130c
movq %r14, %rdi
callq 0x1343
leaq 0x1416(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x1426(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x162a(%rip), %rdi      # 0x4324
callq 0x1060
movl $0x1, %edi
callq 0x2ec6
movl (%r15,%rbx), %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x2fe3
addq $0x4, %r15
cmpq $0x320, %r15            # imm = 0x320
jne 0x2d09
leaq 0x15d2(%rip), %rdi      # 0x42fd
callq 0x1060
movl $0x2, %edi
callq 0x2ec6
movq $-0x2, %r12
leaq -0x80(%rbp), %r14
leaq -0x2c(%rbp), %r15
movl 0x8(%rbx,%r12,4), %esi
movl 0xc(%rbx,%r12,4), %r13d
movl %esi, %edx
notl %edx
movq %r14, %rdi
callq 0x2f27
movq %r14, %rdi
callq 0x2f93
movq %r14, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x1844
testl %eax, %eax
jns 0x2d88
movl -0x2c(%rbp), %esi
leaq 0x14bc(%rip), %rdi      # 0x423f
callq 0x38d9
movq %r14, %rdi
callq 0x2f93
addq $0x2, %r12
cmpq $0xc6, %r12
jb 0x2d49
leaq 0x156e(%rip), %rdi      # 0x4312
callq 0x1060
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a31
leaq 0x155c(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x157a(%rip), %rsi      # 0x4344
movq %r14, %rdi
movq -0x38(%rbp), %rdx
movl $0x4, %ecx
callq 0x12ec
movq %r14, %rdi
xorl %esi, %esi
callq 0x130c
movq %r14, %rdi
callq 0x1343
leaq 0x12f0(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x1300(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x1504(%rip), %rdi      # 0x4324
callq 0x1060
movq $-0x2, %r13
leaq -0x2c(%rbp), %r15
movl 0x8(%rbx,%r13,4), %esi
movl 0xc(%rbx,%r13,4), %r12d
movl %esi, %edx
notl %edx
movq %r14, %rdi
callq 0x2fe3
movq %r14, %rdi
movl %r12d, %esi
leaq -0x3c(%rbp), %rdx
movq %r15, %rcx
callq 0x1372
testl %eax, %eax
jns 0x2ea7
cmpl $0x6, -0x2c(%rbp)
jne 0x2e88
addq $0x2, %r13
cmpq $0xc6, %r13
jb 0x2e30
movl $0xa, %edi
callq 0x1030
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13f8(%rip), %rdi      # 0x4287
leaq 0x129f(%rip), %rsi      # 0x4135
leaq 0x13b1(%rip), %rcx      # 0x424e
movl $0x92, %edx
callq 0x1080
leaq 0x139a(%rip), %rdi      # 0x4248
leaq 0x1280(%rip), %rsi      # 0x4135
leaq 0x1392(%rip), %rcx      # 0x424e
movl $0x91, %edx
callq 0x1080