// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rsi, %r13
movq (%rdi), %r15
testq %r15, %r15
je 0xaf1d
movq %rcx, %rbp
movq %rdi, (%rsp)
movq (%r15), %rdi
movq %r13, %rsi
callq *%rcx
testl %eax, %eax
jle 0xaf40
leaq 0x10(%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0xaed4
movq %rax, %r14
jmp 0xaf49
movq %r9, %rbx
movq 0xfd09(%rip), %r14      # 0x1ac30
testq %r14, %r14
je 0xafd5
movq 0x10(%r14), %rax
movq %rax, 0xfcf5(%rip)      # 0x1ac30
jmp 0xaff5
movq %r15, %r14
js 0xb04c
movq 0x10(%r15), %rbx
xorl %eax, %eax
movl $0x0, %ecx
testq %rbx, %rbx
je 0xaf5c
movl 0x30(%rbx), %ecx
movq 0x18(%r15), %r12
testq %r12, %r12
je 0xaf6a
movl 0x30(%r12), %eax
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0xaf92
movq 0x18(%rbx), %rax
movq %rax, 0x10(%r15)
movq %r15, 0x18(%rbx)
movq %r15, %rdi
callq 0xb6bd
movl %eax, 0x30(%r15)
movq (%rsp), %rax
movq %rbx, (%rax)
jmp 0xafc5
incl %ecx
cmpl %ecx, %eax
jle 0xafbe
movq 0x10(%r12), %rax
movq %rax, 0x18(%r15)
movq %r15, 0x10(%r12)
movq %r15, %rdi
callq 0xb6bd
movl %eax, 0x30(%r15)
movq (%rsp), %rax
movq %r12, (%rax)
movq %r12, %rbx
jmp 0xafc5
movq (%rsp), %rax
movq (%rax), %rbx
movq %rbx, %rdi
callq 0xb6bd
movl %eax, 0x30(%rbx)
jmp 0xb06c
movq %rdi, %r14
pushq $0x38
popq %rdi
movq %r8, %r15
callq 0xb85c
movq %r15, %r8
movq %r14, %rdi
movq %rax, %r14
testq %rax, %rax
je 0xb07e
movq %r13, (%r14)
movq %r12, 0x8(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movl $0x1, 0x30(%r14)
testq %rbx, %rbx
je 0xb02c
movq 0x28(%rbx), %rax
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0xb022
movq %r14, 0x20(%rax)
movq %r14, 0x28(%rbx)
movq %rbx, 0x20(%r14)
jmp 0xb069
testq %r8, %r8
je 0xb064
movq 0x20(%r8), %rax
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0xb042
movq %r14, 0x28(%rax)
movq %r14, 0x20(%r8)
movq %r8, 0x28(%r14)
jmp 0xb069
leaq 0x18(%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
xorl %r9d, %r9d
jmp 0xaf13
movups %xmm0, 0x20(%r14)
movq %r14, (%rdi)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ddc(%rip), %rdi      # 0x11e61
callq 0x31c0
pushq $0x1
popq %rdi
callq 0x3200