// File: /workspace/github_c_makefile_star2_O0/glk[P]critbit/critbit.c
// Function: critbit_insert_impl
static __inline struct critbit_key *
critbit_insert_impl(struct critbit_tree *t, struct critbit_node *newnode,
    const struct critbit_key *key, size_t keylen, critbit_keybuf_t *keybuf)
{
	const uint8_t *const ubytes = keybuf(key);
	struct critbit_node *q;
	struct critbit_ref *p;
	const uint8_t *pkey;
	uint32_t newbyte;
	uint32_t newotherbits;
	uint8_t c;

	p = t->ct_root;
	if (p == NULL) {
		critbit_ref_set_key(&t->ct_root, key);
		critbit_node_free(t, newnode);
		return (NULL);
	}

	while (critbit_ref_is_internal(p)) {
		q = critbit_ref_get_node(p);

		c = 0;
		if (q->byte < keylen)
			c = ubytes[q->byte];

		const int direction = (1 + (q->otherbits | c)) >> 8;
		p = q->child[direction];
	}

	pkey = keybuf(critbit_ref_get_key(p));
	for (newbyte = 0; newbyte < keylen; ++newbyte) {
		if (pkey[newbyte] != ubytes[newbyte]) {
			newotherbits = pkey[newbyte] ^ ubytes[newbyte];
			goto different_byte_found;
		}
	}

	if (pkey[newbyte] != 0) {
		newotherbits = pkey[newbyte];
		goto different_byte_found;
	}

	critbit_node_free(t, newnode);
	return (critbit_ref_get_key(p));

different_byte_found:

	newotherbits = ms1b8(newotherbits) ^ 255;
	const int newdirection = (1 + (newotherbits | pkey[newbyte])) >> 8;

	newnode->byte = newbyte;
	newnode->otherbits = newotherbits;
	critbit_ref_set_key(&newnode->child[1 - newdirection], key);

	struct critbit_ref **wherep = &t->ct_root;
	for (;;) {
		p = *wherep;
		if (!critbit_ref_is_internal(p))
			break;
		q = critbit_ref_get_node(p);
		if (q->byte > newbyte)
			break;
		if (q->byte == newbyte && q->otherbits > newotherbits)
			break;
		c = 0;
		if (q->byte < keylen)
			c = ubytes[q->byte];
		const int direction = (1 + (q->otherbits | c)) >> 8;
		wherep = q->child + direction;
	}

	newnode->child[newdirection] = *wherep;
	critbit_ref_set_node(wherep, newnode);

	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rdi
callq *%rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xd4b6
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xdb30
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xdb50
movq $0x0, -0x8(%rbp)
jmp 0xd707
jmp 0xd4b8
movq -0x48(%rbp), %rdi
callq 0xdad0
cmpl $0x0, %eax
je 0xd51e
movq -0x48(%rbp), %rdi
callq 0xdaf0
movq %rax, -0x40(%rbp)
movb $0x0, -0x59(%rbp)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpq -0x28(%rbp), %rax
jae 0xd4f5
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
movb (%rax,%rcx), %al
movb %al, -0x59(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x14(%rax), %eax
movzbl -0x59(%rbp), %ecx
orl %ecx, %eax
addl $0x1, %eax
sarl $0x8, %eax
movl %eax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
jmp 0xd4b8
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rdi
callq 0xdb10
movq %rax, %rdi
movq -0x80(%rbp), %rax
callq *%rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x28(%rbp), %rax
jae 0xd590
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x54(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xd583
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x54(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0xd5cf
jmp 0xd585
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xd543
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xd5b0
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
jmp 0xd5cf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xdb50
movq -0x48(%rbp), %rdi
callq 0xdb10
movq %rax, -0x8(%rbp)
jmp 0xd707
movl -0x58(%rbp), %eax
movzbl %al, %edi
callq 0xdb80
movzbl %al, %eax
xorl $0xff, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x50(%rbp), %rcx
movl -0x54(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
addl $0x1, %eax
shrl $0x8, %eax
movl %eax, -0x64(%rbp)
movl -0x54(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x58(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x14(%rax)
movq -0x18(%rbp), %rdi
movl $0x1, %eax
subl -0x64(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0xdb30
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0xdad0
cmpl $0x0, %eax
jne 0xd658
jmp 0xd6df
movq -0x48(%rbp), %rdi
callq 0xdaf0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x54(%rbp), %eax
jbe 0xd673
jmp 0xd6df
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0xd68e
movq -0x40(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl -0x58(%rbp), %eax
jbe 0xd68e
jmp 0xd6df
movb $0x0, -0x59(%rbp)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpq -0x28(%rbp), %rax
jae 0xd6b0
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
movb (%rax,%rcx), %al
movb %al, -0x59(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x14(%rax), %eax
movzbl -0x59(%rbp), %ecx
orl %ecx, %eax
addl $0x1, %eax
sarl $0x8, %eax
movl %eax, -0x74(%rbp)
movq -0x40(%rbp), %rax
movslq -0x74(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0xd63a
movq -0x70(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xdbc0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)