// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
cmpq $0x0, 0x10(%rdi)
je 0x189e9
xorl %ebx, %ebx
leaq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x10ee8
movq 0x10(%rsp), %rax
leaq (%rax,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
notq %rdx
addq 0x18(%rsp), %rdx
shlq $0x3, %rdx
callq 0x3600
movq 0x10(%rsp), %rax
movq %rbx, (%rax,%r15,8)
movq 0x8(%rbp), %rax
movq (%rax,%rbx), %rcx
movq %rcx, %rax
andq $-0x10, %rax
leaq -0x1(%rax), %rdx
testq %rdx, %rax
jne 0x18dc6
testq %rbx, %rdx
jne 0x18dc6
cmpq $0x1f, %rcx
jbe 0x18dc6
addq %rax, %rbx
cmpq 0x10(%rbp), %rbx
jne 0x1896b
movq 0x8(%rsp), %rbx
jmp 0x189eb
xorl %ebx, %ebx
leaq 0x1(%rbx), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x10ee8
movq (%r14), %rax
leaq (%rax,%rbx,8), %rsi
leaq (%rax,%rbx,8), %rdi
addq $0x8, %rdi
movq %rbx, %rdx
notq %rdx
addq 0x8(%r14), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%r14), %rax
movq $0x0, (%rax,%rbx,8)
movq 0x8(%rbp), %rax
cmpq $0x202, (%rax)          # imm = 0x202
jne 0x18dc6
movabsq $0x100000000000000, %rcx # imm = 0x100000000000000
orq 0x8(%rax), %rcx
movabsq $0x170616d736c7261, %rdx # imm = 0x170616D736C7261
cmpq %rdx, %rcx
jne 0x18dc6
movq 0x10(%rax), %r15
movq (%rax,%r15), %r13
movq %rsp, %r14
movq 0x8(%r14), %rbx
leaq 0x1(%rbx), %rsi
movq %r14, %rdi
callq 0x10ee8
movq (%r14), %rax
leaq (%rax,%rbx,8), %rsi
leaq (%rax,%rbx,8), %rdi
addq $0x8, %rdi
movq %rbx, %rdx
notq %rdx
addq 0x8(%r14), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%r14), %rax
movq %r15, (%rax,%rbx,8)
movl %r13d, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x18dc6
cmpq $0x1ff, %r13            # imm = 0x1FF
jbe 0x18dc6
andq $-0x10, %r13
leaq 0x58(%rsp), %r14
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r14)
movq $0x0, 0x8(%r14)
movl $0x8, %esi
movq %r14, %rdi
callq 0x5afc
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
cmpq $0x11, %r13
jb 0x18c61
movl $0x10, %r12d
xorl %ecx, %ecx
xorl %r14d, %r14d
movq %r13, 0x28(%rsp)
movq %r15, 0x48(%rsp)
movq 0x8(%rbp), %rax
addq %r15, %rax
movq (%r12,%rax), %rbx
cmpq $0x1, %rbx
sbbq $-0x1, %rcx
cmpq $0x2, %rbx
jb 0x18c52
movq %rcx, 0x30(%rsp)
movq 0x8(%r12,%rax), %r13
movq %rbp, %r15
movq 0x8(%rsp), %rbp
leaq 0x1(%rbp), %rsi
movq %rsp, %rdi
callq 0x10ee8
movq (%rsp), %rax
leaq (%rax,%rbp,8), %rsi
leaq (%rax,%rbp,8), %rdi
addq $0x8, %rdi
movq %rbp, %rdx
notq %rdx
addq 0x8(%rsp), %rdx
shlq $0x3, %rdx
callq 0x3600
movq (%rsp), %rax
movq %rbx, (%rax,%rbp,8)
movq 0x8(%r15), %rax
movq (%rax,%rbx), %rcx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x1, %edx
jne 0x18dc6
movq %r15, %rbp
addq %rbx, %rax
movq %rcx, %rdi
andq $-0x10, %rdi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rsi
addq %rdx, %rsi
addq $0x18, %rsi
cmpq %rdi, %rsi
leaq 0x50(%rsp), %rbx
leaq 0x38(%rsp), %r15
ja 0x18dc6
shrq %rcx
cmpq %rcx, %rsi
jbe 0x18dc6
addq $0x18, %rax
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x18e20
cmpq $-0x1, %rax
jne 0x18dc6
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x18f0c
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x15ad7
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, %r13
jne 0x18dc6
incq %r14
movq 0x48(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rcx
addq $0x10, %r12
cmpq %r13, %r12
jb 0x18b06
jmp 0x18c66
xorl %r14d, %r14d
xorl %ecx, %ecx
movq 0x8(%rbp), %rax
cmpq 0x18(%rax), %rcx
jne 0x18dc6
cmpq 0x20(%rax), %r14
jne 0x18dc6
movl $0x5, %r14d
xorl %ecx, %ecx
movq (%rax,%r14,8), %rbx
cmpq $0x1, %rbx
sete 0x28(%rsp)
testq %rbx, %rbx
movl %ecx, 0x30(%rsp)
je 0x18d3a
cmpq $0x1, %rbx
je 0x18d43
leaq (,%r14,8), %r13
movl $0x1, %r12d
movl %r14d, %ecx
shlq %cl, %r12
movq 0x8(%rsp), %r15
leaq 0x1(%r15), %rsi
movq %rsp, %rdi
callq 0x10ee8
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 %rbx, (%rax,%r15,8)
movq 0x8(%rbp), %rax
cmpq %r12, (%rax,%rbx)
jne 0x18dc6
movq %rbx, %rcx
xorq %r12, %rcx
cmpq (%rax,%rcx), %r12
je 0x18dc6
cmpq %r13, 0x10(%rax,%rbx)
jne 0x18dc6
movq %rbx, %r13
movq 0x8(%rax,%rbx), %rcx
addq $0x8, %r13
movq %rcx, %rbx
testq %rcx, %rcx
jne 0x18cbe
jmp 0x18d43
testb $0x1, %cl
jne 0x18dc6
movl 0x30(%rsp), %ecx
orb 0x28(%rsp), %cl
incq %r14
cmpq $0x40, %r14
jne 0x18c86
leaq 0x10(%rsp), %rbx
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x192f6
movq %rsp, %r14
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x192f6
movq 0x8(%r14), %rdx
cmpq %rdx, 0x8(%rbx)
jne 0x18dc6
movq (%rsp), %rsi
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
callq 0x3380
testl %eax, %eax
jne 0x18dc6
leaq 0x50(%rsp), %rdi
callq 0x18dcc
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
nop