// File: /workspace/github_c_makefile_star2_O3/theovosse[P]llgen/avl3.c
// Function: InsertNodeDupl2
static TREE InsertNodeDupl2(TREE *root, void *key, void *info, int (*keyCmp)(void *, void *), TREE previous, TREE next)
{
	int lDepth;
	int rDepth;
	TREE n0 = *root;
	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;
		}
		*root = n0;
		ret = n0;
	}
	else
	{
		if ((res = (*keyCmp)(n0->key, key)) > 0)
		{
			ret = InsertNodeDupl2(&(n0->left), key, info, keyCmp, NULL, n0);
		}
		else
		{
			ret = InsertNodeDupl2(&(n0->right), key, info, keyCmp, n0, NULL);
		}
		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);
			*root = n1;
		}
		else if (rDepth > lDepth + 1)
		{
			n1 = n0->right;
			n2 = n1->left;
			n0->right = n2;
			n1->left = n0;
			n0->depth = NDepth(n0);
			*root = n1;
		}
		(*root)->depth = NDepth(*root);
	}
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r13
movq (%rdi), %r14
testq %r14, %r14
je 0xba35
movq %rcx, %rbx
movq %rdi, %r12
movq (%r14), %rdi
movq %r13, %rsi
callq *%rcx
testl %eax, %eax
jle 0xba5b
leaq 0x10(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
jmp 0xba6e
movq %r9, %rbp
movq %r8, %r12
movq 0x101ee(%rip), %rax     # 0x1bc30
testq %rax, %rax
je 0xbb44
movq 0x10(%rax), %rcx
movq %rcx, 0x101da(%rip)     # 0x1bc30
jmp 0xbb59
leaq 0x18(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0xb9f5
movq 0x10(%r14), %rcx
xorl %esi, %esi
movl $0x0, %edi
testq %rcx, %rcx
je 0xba86
movl 0x30(%rcx), %edi
movq 0x18(%r14), %rdx
testq %rdx, %rdx
je 0xba92
movl 0x30(%rdx), %esi
leal 0x1(%rsi), %r8d
cmpl %r8d, %edi
jle 0xbad3
movq 0x18(%rcx), %rdi
movq %rdi, 0x10(%r14)
movq %r14, 0x18(%rcx)
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbab6
movl 0x30(%rdi), %esi
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xbac2
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
movl %edx, 0x30(%r14)
movq %rcx, (%r12)
jmp 0xbb19
incl %edi
cmpl %edi, %esi
jle 0xbb15
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 0xbaf9
movl 0x30(%r8), %edi
testq %rsi, %rsi
je 0xbb01
movl 0x30(%rsi), %ecx
cmpl %ecx, %edi
cmovgl %edi, %ecx
incl %ecx
movl %ecx, 0x30(%r14)
movq %rdx, (%r12)
movq %rdx, %rcx
jmp 0xbb19
movq (%r12), %rcx
movq 0x10(%rcx), %rdi
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbb2c
movl 0x30(%rdi), %esi
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0xbb38
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
movl %edx, 0x30(%rcx)
jmp 0xbbb7
movq %rdi, %rbx
movl $0x38, %edi
callq 0xc2f0
movq %rbx, %rdi
testq %rax, %rax
je 0xbbc6
movq %r13, (%rax)
movq %r15, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x1, 0x30(%rax)
testq %rbp, %rbp
je 0xbb8e
movq 0x28(%rbp), %rcx
movq %rcx, 0x28(%rax)
testq %rcx, %rcx
je 0xbb84
movq %rax, 0x20(%rcx)
movq %rax, 0x28(%rbp)
movq %rbp, 0x20(%rax)
jmp 0xbbb4
testq %r12, %r12
je 0xbbb0
movq 0x20(%r12), %rcx
movq %rcx, 0x20(%rax)
testq %rcx, %rcx
je 0xbba5
movq %rax, 0x28(%rcx)
movq %rax, 0x20(%r12)
movq %r12, 0x28(%rax)
jmp 0xbbb4
movups %xmm0, 0x20(%rax)
movq %rax, (%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x393e