// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/kvlds/serialize.c
// Function: serialize_size
size_t
serialize_size(struct node * N)
{
	size_t size;
	size_t i;

	/* If we have a stored size, return it immediately. */
	if (N->pagesize != (uint32_t)(-1))
		return (N->pagesize);

	/* "KVLDS\0". */
	size = 6;

	/* BE number of keys. */
	size += 2;

	/* Rootedness and height. */
	size += 1;

	/* Matching prefix length. */
	size += 1;

	/* Sanity check vs. values in serialize.h. */
	assert(size == SERIALIZE_OVERHEAD);

	/* Extra root data. */
	if (N->root) {
		size += 8;
		assert(size == SERIALIZE_OVERHEAD + SERIALIZE_ROOT);
	}

	/* Node data and keys. */
	if (N->type == NODE_TYPE_LEAF) {
		for (i = 0; i < N->nkeys; i++) {
			size += kvldskey_serial_size(N->u.pairs[i].k);
			size += kvldskey_serial_size(N->u.pairs[i].v);
		}
	} else {
		for (i = 0; i < N->nkeys; i++) {
			if (N->v.children[i]->merging == 0) {
				/* Child. */
				size += SERIALIZE_PERCHILD;

				/* Separator key. */
				size += kvldskey_serial_size(N->u.keys[i]);
			}
		}

		/* Last child. */
		size += SERIALIZE_PERCHILD;
	}

	/* Sanity check: we can't store more than this in the node. */
	assert(size <= UINT32_MAX);

	/* Cache the page size. */
	N->pagesize = (uint32_t)size;

	/* Return the computed size. */
	return (size);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
je 0xecd6
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq %rax, -0x8(%rbp)
jmp 0xeeb4
movq $0x6, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
cmpq $0xa, -0x18(%rbp)
jne 0xed0b
jmp 0xed2a
leaq 0x10e97(%rip), %rdi     # 0x1fba9
leaq 0x10d53(%rip), %rsi     # 0x1fa6c
movl $0x1a1, %edx            # imm = 0x1A1
leaq 0x10e9f(%rip), %rcx     # 0x1fbc4
callq 0x21d0
movq -0x10(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xed74
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
cmpq $0x12, -0x18(%rbp)
jne 0xed53
jmp 0xed72
leaq 0x10e8f(%rip), %rdi     # 0x1fbe9
leaq 0x10d0b(%rip), %rsi     # 0x1fa6c
movl $0x1a6, %edx            # imm = 0x1A6
leaq 0x10e57(%rip), %rcx     # 0x1fbc4
callq 0x21d0
jmp 0xed74
movq -0x10(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xedf6
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0xedf4
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movzbl (%rax), %eax
addq $0x1, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
addq $0x1, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xed8d
jmp 0xee73
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0xee67
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb 0x1c(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xee57
movq -0x18(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movzbl (%rax), %eax
addq $0x1, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xee59
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xedfe
movq -0x18(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x18(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
ja 0xee80
jmp 0xee9f
leaq 0x10d8e(%rip), %rdi     # 0x1fc15
leaq 0x10bde(%rip), %rsi     # 0x1fa6c
movl $0x1bf, %edx            # imm = 0x1BF
leaq 0x10d2a(%rip), %rcx     # 0x1fbc4
callq 0x21d0
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nop