// File: /workspace/github_c_makefile_star2_O3/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 0x18a6(%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 0x1b5d(%rip), %rdi      # 0x461f
xorl %r12d, %r12d
movl $0x40, %esi
xorl %eax, %eax
callq 0x1070
callq 0x3138
movl $0xa, %edi
callq 0x34d1
movl $0x1e, %edi
movl $0x14, %esi
callq 0x356c
leaq 0x17eb(%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 0x15b9(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
leaq 0x15b9(%rip), %rdi      # 0x40f4
movl $0xc8, %esi
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x17ba(%rip), %rdi      # 0x4312
callq 0x1060
movq %r15, %rdi
xorl %esi, %esi
callq 0x19ae
leaq 0x17ac(%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 0x1753(%rip), %rdi      # 0x42ea
callq 0x1060
xorl %edi, %edi
callq 0x2e22
leaq 0x44e6(%rip), %rbx      # 0x7090
movl (%r12,%rbx), %edx
movq %r15, %rdi
movl %edx, %esi
callq 0x2e80
movq %r15, %rdi
callq 0x2eec
addq $0x4, %r12
cmpq $0x320, %r12            # imm = 0x320
jne 0x2baa
leaq 0x173e(%rip), %rdi      # 0x4312
callq 0x1060
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x19ae
leaq 0x1729(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x1747(%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 0x14ba(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x14ca(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x16ce(%rip), %rdi      # 0x4324
callq 0x1060
movl $0x1, %edi
callq 0x2e22
movl (%r15,%rbx), %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x2f3c
addq $0x4, %r15
cmpq $0x320, %r15            # imm = 0x320
jne 0x2c65
leaq 0x1676(%rip), %rdi      # 0x42fd
callq 0x1060
movl $0x2, %edi
callq 0x2e22
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 0x2e80
movq %r14, %rdi
callq 0x2eec
movq %r14, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x17fe
testl %eax, %eax
jns 0x2ce4
movl -0x2c(%rbp), %esi
leaq 0x1560(%rip), %rdi      # 0x423f
callq 0x3815
movq %r14, %rdi
callq 0x2eec
addq $0x2, %r12
cmpq $0xc6, %r12
jb 0x2ca5
leaq 0x1612(%rip), %rdi      # 0x4312
callq 0x1060
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x19ae
leaq 0x1600(%rip), %rdi      # 0x431a
callq 0x1060
leaq 0x161e(%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 0x1394(%rip), %rdi      # 0x40e4
movl %eax, %esi
xorl %eax, %eax
callq 0x1070
movl 0x3c(%r14), %esi
leaq 0x13a4(%rip), %rdi      # 0x4108
xorl %eax, %eax
callq 0x1070
movl $0xa, %edi
callq 0x1030
leaq 0x15a8(%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 0x2f3c
movq %r14, %rdi
movl %r12d, %esi
leaq -0x3c(%rbp), %rdx
movq %r15, %rcx
callq 0x1372
testl %eax, %eax
jns 0x2e03
cmpl $0x6, -0x2c(%rbp)
jne 0x2de4
addq $0x2, %r13
cmpq $0xc6, %r13
jb 0x2d8c
movl $0xa, %edi
callq 0x1030
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x149c(%rip), %rdi      # 0x4287
leaq 0x1343(%rip), %rsi      # 0x4135
leaq 0x1455(%rip), %rcx      # 0x424e
movl $0x92, %edx
callq 0x1080
leaq 0x143e(%rip), %rdi      # 0x4248
leaq 0x1324(%rip), %rsi      # 0x4135
leaq 0x1436(%rip), %rcx      # 0x424e
movl $0x91, %edx
callq 0x1080