// File: /workspace/github_c_makefile_star2_O3/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), %r14
testq %r14, %r14
je 0xb849
movq %rcx, %rbx
movq %rdi, %r13
movq (%r14), %rdi
movq %r12, %rsi
callq *%rcx
testl %eax, %eax
jle 0xb86f
leaq 0x10(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
callq 0xb804
jmp 0xb878
movq %r9, %rbp
movq %r8, %r13
movq 0x103da(%rip), %rax     # 0x1bc30
testq %rax, %rax
je 0xb94c
movq 0x10(%rax), %rcx
movq %rcx, 0x103c6(%rip)     # 0x1bc30
jmp 0xb965
movq %r14, %rax
js 0xb9ba
movq 0x10(%r14), %rcx
xorl %esi, %esi
movl $0x0, %edi
testq %rcx, %rcx
je 0xb88b
movl 0x30(%rcx), %edi
movq 0x18(%r14), %rdx
testq %rdx, %rdx
je 0xb897
movl 0x30(%rdx), %esi
leal 0x1(%rsi), %r8d
cmpl %r8d, %edi
jle 0xb8d8
movq 0x18(%rcx), %rdi
movq %rdi, 0x10(%r14)
movq %r14, 0x18(%rcx)
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xb8bb
movl 0x30(%rdi), %esi
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xb8c7
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
movl %edx, 0x30(%r14)
movq %rcx, (%r13)
jmp 0xb91e
incl %edi
cmpl %edi, %esi
jle 0xb91a
movq 0x10(%rdx), %rsi
movq %rsi, 0x18(%r14)
movq %r14, 0x10(%rdx)
movq 0x10(%r14), %r8
xorl %ecx, %ecx
movl $0x0, %edi
testq %r8, %r8
je 0xb8fe
movl 0x30(%r8), %edi
testq %rsi, %rsi
je 0xb906
movl 0x30(%rsi), %ecx
cmpl %ecx, %edi
cmovgl %edi, %ecx
incl %ecx
movl %ecx, 0x30(%r14)
movq %rdx, (%r13)
movq %rdx, %rcx
jmp 0xb91e
movq (%r13), %rcx
movq 0x10(%rcx), %rdi
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xb931
movl 0x30(%rdi), %esi
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0xb93d
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
movl %edx, 0x30(%rcx)
jmp 0xb9d9
movq %rdi, %rbx
movl $0x38, %edi
callq 0xc2f0
movq %rbx, %rdi
testq %rax, %rax
je 0xb9e8
movq %r12, (%rax)
movq %r15, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x1, 0x30(%rax)
testq %rbp, %rbp
je 0xb99a
movq 0x28(%rbp), %rcx
movq %rcx, 0x28(%rax)
testq %rcx, %rcx
je 0xb990
movq %rax, 0x20(%rcx)
movq %rax, 0x28(%rbp)
movq %rbp, 0x20(%rax)
jmp 0xb9d6
testq %r13, %r13
je 0xb9d2
movq 0x20(%r13), %rcx
movq %rcx, 0x20(%rax)
testq %rcx, %rcx
je 0xb9b0
movq %rax, 0x28(%rcx)
movq %rax, 0x20(%r13)
movq %r13, 0x28(%rax)
jmp 0xb9d6
leaq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
xorl %r9d, %r9d
jmp 0xb842
movups %xmm0, 0x20(%rax)
movq %rax, (%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3929