// File: /workspace/github_cpp_makefile_star2_O1/Alcaro[P]bridges/arlib/staticmap.cpp
// Function: staticmap::fsck()
void staticmap::fsck()
{
	array<uint64_t> objects_file;
	array<uint64_t> objects_reachable;
	uint64_t pos = 0;
	while (pos != mmap.size())
	{
		objects_file.append(pos);
		uint64_t head = rd64(pos);
		uint64_t size = head & ~t_typemask;
		if (size & (size-1)) abort(); // size must be power of two
		if ((size-1) & pos) abort(); // every object must be correctly aligned
		if (size < 32) abort(); // size must be at least 32
		pos += size;
	}
	
	objects_reachable.append(0);
	if (rd64(0) != off_r_objsize + t_meta) abort();
	if (rd64(off_r_sig) != sig_passive && rd64(off_r_sig) != sig_active) abort();
	
	uint64_t hashmap_pos = rd64(off_r_hm_ptr);
	uint64_t hashmap_head = rd64(hashmap_pos + off_header);
	objects_reachable.append(hashmap_pos);
	if ((hashmap_head & t_typemask) != t_meta) abort();
	uint64_t hashmap_size = hashmap_head & ~t_typemask;
	if (hashmap_size < 512) abort();
	
	set<bytesr> keys_seen;
	uint64_t hashmap_load = 0;
	uint64_t hashmap_items = 0;
	uint64_t hashmap_iter = 16;
	while (hashmap_iter < hashmap_size)
	{
		uint64_t ptr = rd64(hashmap_pos + hashmap_iter + off_h_ptr);
		uint64_t hash = rd64(hashmap_pos + hashmap_iter + off_h_hash);
		hashmap_iter += 16;
		
		if (ptr >= 1) hashmap_load++;
		if (ptr <= 1) continue;
		hashmap_items++;
		
		objects_reachable.append(ptr);
		uint64_t obj_head = rd64(ptr + off_header);
		if ((obj_head & t_typemask) != t_data) abort();
		uint64_t obj_size = obj_head & ~t_typemask;
		uint64_t key_size = rd64(ptr+off_d_keysz);
		uint64_t val_size = rd64(ptr+off_d_valsz);
		if (off_d_keystart+key_size+val_size > obj_size) abort();
		if (off_d_keystart+key_size+val_size <= obj_size/2) abort();
		
		bytesr by = mmap.slice(ptr+off_d_keystart, key_size);
		if (keys_seen.contains(by)) abort();
		keys_seen.add(by);
		if (hash != sm_hash(by)) abort();
	}
	
	if (hashmap_load != rd64(off_r_hm_load)) abort();
	if (hashmap_items != rd64(off_r_entries)) abort();
	
	bool last = false;
	for (int i=5;i<=63;i++)
	{
		uint64_t prev = off_r_freespace(i);
		uint64_t ptr = rd64(prev);
		if (ptr == 1) last = true;
		if (ptr == 0 && last) abort();
		if (ptr > 1)
		{
		again:
			objects_reachable.append(ptr);
			uint64_t size = uint64_t(1)<<i;
			uint64_t sibling = ptr ^ size;
			if (rd64(ptr + off_header) != size+t_free) abort();
			if (rd64(ptr + off_header) == rd64(sibling + off_header)) abort(); // should've been merged
			if (rd64(ptr + off_f_prevptr) != prev) abort();
			uint64_t next = rd64(ptr + off_f_nextobj);
			prev = ptr + off_f_nextobj;
			
			if (next != 0)
			{
				ptr = next;
				goto again;
			}
		}
	}
	
	objects_file.sort();
	objects_reachable.sort();
	if (objects_file != objects_reachable) abort();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
cmpq $0x0, 0x10(%rdi)
je 0x18712
xorl %r15d, %r15d
leaq 0x10(%rsp), %r14
movq 0x18(%rsp), %r12
leaq 0x1(%r12), %rsi
movq %r14, %rdi
callq 0x10b32
movq 0x10(%rsp), %rax
leaq (%rax,%r12,8), %rsi
leaq (%rax,%r12,8), %rdi
addq $0x8, %rdi
movq %r12, %rdx
notq %rdx
addq 0x18(%rsp), %rdx
shlq $0x3, %rdx
callq 0x3600
movq 0x10(%rsp), %rax
movq %r15, (%rax,%r12,8)
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rcx
movq %rcx, %rax
andq $-0x10, %rax
leaq -0x1(%rax), %rdx
testq %rdx, %rax
jne 0x18b0f
testq %r15, %rdx
jne 0x18b0f
cmpq $0x1f, %rcx
jbe 0x18b0f
addq %rax, %r15
cmpq 0x10(%rbx), %r15
jne 0x1869a
movq %rsp, %r14
movq 0x8(%r14), %r15
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x10b32
movq (%r14), %rax
leaq (%rax,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
notq %rdx
addq 0x8(%r14), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%r14), %rax
movq $0x0, (%rax,%r15,8)
movq 0x8(%rbx), %rax
cmpq $0x202, (%rax)          # imm = 0x202
jne 0x18b0f
movabsq $0x100000000000000, %rcx # imm = 0x100000000000000
orq 0x8(%rax), %rcx
movabsq $0x170616d736c7261, %rdx # imm = 0x170616D736C7261
cmpq %rdx, %rcx
jne 0x18b0f
movq 0x10(%rax), %r13
movq (%rax,%r13), %r12
movq %rsp, %r14
movq 0x8(%r14), %r15
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x10b32
movq (%r14), %rax
leaq (%rax,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
notq %rdx
addq 0x8(%r14), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%r14), %rax
movq %r13, (%rax,%r15,8)
movq %r12, %r15
movl %r15d, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x18b0f
cmpq $0x1ff, %r15            # imm = 0x1FF
jbe 0x18b0f
andq $-0x10, %r15
leaq 0x58(%rsp), %r14
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r14)
movq $0x0, 0x8(%r14)
movl $0x8, %esi
movq %r14, %rdi
callq 0x51ac
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
cmpq $0x11, %r15
jb 0x189a0
movl $0x10, %r12d
xorl %ecx, %ecx
leaq 0x50(%rsp), %r14
xorl %edx, %edx
movq %r13, %rsi
movq %r13, 0x38(%rsp)
movq 0x8(%rbx), %rax
addq %rsi, %rax
movq (%r12,%rax), %rbp
cmpq $0x1, %rbp
sbbq $-0x1, %rcx
cmpq $0x2, %rbp
jb 0x18991
movq %r14, %r13
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %r15, %r14
movq 0x8(%r12,%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %r15
leaq 0x1(%r15), %rsi
movq %rsp, %rdi
callq 0x10b32
movq (%rsp), %rax
leaq (%rax,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
notq %rdx
addq 0x8(%rsp), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%rsp), %rax
movq %rbp, (%rax,%r15,8)
movq 0x8(%rbx), %rax
movq (%rax,%rbp), %rcx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x1, %edx
jne 0x18b0f
movq %rcx, %rdi
andq $-0x10, %rdi
movq 0x8(%rax,%rbp), %rdx
movq 0x10(%rax,%rbp), %rsi
addq %rdx, %rsi
addq $0x18, %rsi
cmpq %rdi, %rsi
ja 0x18b0f
shrq %rcx
cmpq %rcx, %rsi
jbe 0x18b0f
movq %r14, %r15
addq %rbp, %rax
addq $0x18, %rax
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %r13, %r14
movq %r13, %rdi
leaq 0x28(%rsp), %r13
movq %r13, %rsi
callq 0x18b68
cmpq $-0x1, %rax
jne 0x18b0f
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x18ca4
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x15897
movq %rax, %rcx
shrq $0x1e, %rcx
xorq %rax, %rcx
movabsq $-0x40a7b892e31b1a47, %rax # imm = 0xBF58476D1CE4E5B9
imulq %rax, %rcx
movq %rcx, %rax
shrq $0x1b, %rax
xorq %rcx, %rax
movabsq $-0x6b2fb644ecceee15, %rcx # imm = 0x94D049BB133111EB
imulq %rcx, %rax
movq %rax, %rcx
shrq $0x1f, %rcx
xorq %rax, %rcx
cmpq %rcx, 0x20(%rsp)
jne 0x18b0f
movq 0x40(%rsp), %rdx
incq %rdx
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rcx
addq $0x10, %r12
cmpq %r15, %r12
jb 0x18836
jmp 0x189a4
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x8(%rbx), %rax
cmpq 0x18(%rax), %rcx
jne 0x18b0f
cmpq 0x20(%rax), %rdx
jne 0x18b0f
movl $0x5, %r14d
xorl %ecx, %ecx
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %r13
cmpq $0x1, %r13
movzbl %cl, %ecx
movl $0x1, %eax
cmovel %eax, %ecx
testq %r13, %r13
jne 0x189e9
testb $0x1, %cl
jne 0x18b0f
movl %ecx, 0x20(%rsp)
cmpq $0x2, %r13
jb 0x18a90
leaq (,%r14,8), %rbp
movl $0x1, %r12d
movl %r14d, %ecx
shlq %cl, %r12
movq %rbx, %r15
movq 0x8(%rsp), %rbx
leaq 0x1(%rbx), %rsi
movq %rsp, %rdi
callq 0x10b32
movq (%rsp), %rax
leaq (%rax,%rbx,8), %rsi
leaq (%rax,%rbx,8), %rdi
addq $0x8, %rdi
movq %rbx, %rdx
notq %rdx
addq 0x8(%rsp), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%rsp), %rax
movq %r13, (%rax,%rbx,8)
movq 0x8(%r15), %rax
movq (%rax,%r13), %rcx
cmpq %r12, %rcx
jne 0x18b0f
movq %r13, %rdx
xorq %r12, %rdx
cmpq (%rax,%rdx), %rcx
je 0x18b0f
cmpq %rbp, 0x10(%rax,%r13)
jne 0x18b0f
movq %r15, %rbx
leaq 0x8(%r13), %rbp
movq 0x8(%rax,%r13), %rax
testq %rax, %rax
cmovneq %rax, %r13
jne 0x18a0b
incq %r14
cmpq $0x40, %r14
movl 0x20(%rsp), %ecx
jne 0x189c4
leaq 0x10(%rsp), %rbx
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x190e2
movq %rsp, %r14
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x190e2
movq 0x8(%rbx), %rdx
cmpq 0x8(%r14), %rdx
jne 0x18b0f
movq (%rsp), %rsi
movq 0x10(%rsp), %rdi
shlq $0x3, %rdx
callq 0x3380
testl %eax, %eax
jne 0x18b0f
leaq 0x50(%rsp), %rdi
callq 0x18b14
movq (%rsp), %rdi
callq 0x3430
movq 0x10(%rsp), %rdi
callq 0x3430
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3180