// File: /workspace/github_c_makefile_star2_O1/theovosse[P]llgen/avl3.c
// Function: InsertNodeSingle2
static TREE InsertNodeSingle2(TREE *tree, void *key, void *info, int (*keyCmp)(void *, void *), TREE previous, TREE next)
{
	int lDepth;
	int rDepth;
	TREE n0 = *tree;
	TREE n1;
	TREE n2;
	int res;
	TREE ret;
	
	if (n0 == NULL)
	{
		if (oldNodes == NULL)
		{
			n0 = (TREE) mmalloc(sizeof(struct tree));
			if (n0 == NULL)
			{
				perror("AVL Insert");
				exit(1);
			}
		}
		else
		{
			n0 = oldNodes;
			oldNodes = oldNodes->left;
		}
		n0->key = key;
		n0->info = info;
		n0->left = n0->right = NULL;
		n0->depth = 1;
		if (next != NULL)
		{
			n0->previous = next->previous;
			if (next->previous != NULL)
			{
				next->previous->next = n0;
			}
			next->previous = n0;
			n0->next = next;
		}
		else if (previous != NULL)
		{
			n0->next = previous->next;
			if (previous->next != NULL)
			{
				previous->next->previous = n0;
			}
			previous->next = n0;
			n0->previous = previous;
		}
		else
		{
			n0->next = NULL;
			n0->previous = NULL;
		}
		*tree = n0;
		ret = n0;
	}
	else
	{
		if ((res = (*keyCmp)(n0->key, key)) > 0)
		{
			ret = InsertNodeSingle2(&(n0->left), key, info, keyCmp, NULL, n0);
		}
		else if (res < 0)
		{
			ret = InsertNodeSingle2(&(n0->right), key, info, keyCmp, n0, NULL);
		}
		else
		{
			ret = n0;
		}
		if (n0->left == NULL)
		{
			lDepth = 0;
		}
		else
		{
			lDepth = n0->left->depth;
		}
		if (n0->right == NULL)
		{
			rDepth = 0;
		}
		else
		{
			rDepth = n0->right->depth;
		}
		if (lDepth > rDepth + 1)
		{
			n1 = n0->left;
			n2 = n1->right;
			n0->left = n2;
			n1->right = n0;
			n0->depth = NDepth(n0);
			*tree = n1;
		}
		else if (rDepth > lDepth + 1)
		{
			n1 = n0->right;
			n2 = n1->left;
			n0->right = n2;
			n1->left = n0;
			n0->depth = NDepth(n0);
			*tree = n1;
		}
		(*tree)->depth = NDepth(*tree);
	}
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rdx
movq (%rdi), %r14
testq %r14, %r14
je 0xbaf8
movq %rcx, %rbx
movq %rdx, %r13
movq (%r14), %rdi
movq %r12, %rsi
callq *%rcx
testl %eax, %eax
jle 0xbb1e
leaq 0x10(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
callq 0xbab0
jmp 0xbb27
movq %r9, %rbp
movq %r8, %r13
movq 0x1012b(%rip), %rax     # 0x1bc30
testq %rax, %rax
je 0xbbf9
movq 0x10(%rax), %rcx
movq %rcx, 0x10117(%rip)     # 0x1bc30
jmp 0xbc12
movq %r14, %rax
js 0xbc6f
movq 0x10(%r14), %rcx
xorl %edx, %edx
movl $0x0, %edi
testq %rcx, %rcx
je 0xbb3a
movl 0x30(%rcx), %edi
movq 0x18(%r14), %rsi
testq %rsi, %rsi
movq %r13, %r9
je 0xbb49
movl 0x30(%rsi), %edx
leal 0x1(%rdx), %r8d
cmpl %r8d, %edi
jle 0xbb80
movq 0x18(%rcx), %rdi
movq %rdi, 0x10(%r14)
movq %r14, 0x18(%rcx)
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbb6d
movl 0x30(%rdi), %esi
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xbb79
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
jmp 0xbbb6
incl %edi
cmpl %edi, %edx
jle 0xbbbf
movq 0x10(%rsi), %rcx
movq %rcx, 0x18(%r14)
movq %r14, 0x10(%rsi)
movq 0x10(%r14), %r8
xorl %edx, %edx
movl $0x0, %edi
testq %r8, %r8
je 0xbba6
movl 0x30(%r8), %edi
testq %rcx, %rcx
je 0xbbae
movl 0x30(%rcx), %edx
cmpl %edx, %edi
cmovgl %edi, %edx
movq %rsi, %rcx
incl %edx
movl %edx, 0x30(%r14)
movq %rcx, (%r9)
movq (%r9), %rcx
testq %rcx, %rcx
je 0xbbef
movq 0x10(%rcx), %rdi
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbbda
movl 0x30(%rdi), %esi
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0xbbe6
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
jmp 0xbbf1
xorl %edx, %edx
movl %edx, 0x30(%rcx)
jmp 0xbc8e
movl $0x38, %edi
movq %rdx, %rbx
callq 0xc614
movq %rbx, %rdx
testq %rax, %rax
je 0xbc9d
movq %r12, (%rax)
movq %r15, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x1, 0x30(%rax)
testq %rbp, %rbp
je 0xbc4b
movq 0x28(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq 0x28(%rbp), %rcx
testq %rcx, %rcx
je 0xbc41
movq %rax, 0x20(%rcx)
movq %rax, 0x28(%rbp)
movq %rbp, 0x20(%rax)
jmp 0xbc8b
testq %r13, %r13
je 0xbc87
movq 0x20(%r13), %rcx
movq %rcx, 0x20(%rax)
movq 0x20(%r13), %rcx
testq %rcx, %rcx
je 0xbc65
movq %rax, 0x28(%rcx)
movq %rax, 0x20(%r13)
movq %r13, 0x28(%rax)
jmp 0xbc8b
leaq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
xorl %r9d, %r9d
jmp 0xbaf1
movups %xmm0, 0x20(%rax)
movq %rax, (%rdx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3944