// File: /workspace/github_c_makefile_star2_O1/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, %rdx
movq (%rdi), %r14
testq %r14, %r14
je 0xbced
movq %rcx, %rbx
movq %rdx, %r12
movq (%r14), %rdi
movq %r13, %rsi
callq *%rcx
testl %eax, %eax
jle 0xbd13
leaq 0x10(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
jmp 0xbd26
movq %r9, %rbp
movq %r8, %r12
movq 0xff36(%rip), %rax      # 0x1bc30
testq %rax, %rax
je 0xbdfa
movq 0x10(%rax), %rcx
movq %rcx, 0xff22(%rip)      # 0x1bc30
jmp 0xbe0f
leaq 0x18(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0xbcaa
movq 0x10(%r14), %rcx
xorl %edx, %edx
movl $0x0, %edi
testq %rcx, %rcx
movq %r12, %r9
je 0xbd41
movl 0x30(%rcx), %edi
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0xbd4d
movl 0x30(%rsi), %edx
leal 0x1(%rdx), %r8d
cmpl %r8d, %edi
jle 0xbd84
movq 0x18(%rcx), %rdi
movq %rdi, 0x10(%r14)
movq %r14, 0x18(%rcx)
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbd71
movl 0x30(%rdi), %esi
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xbd7d
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
jmp 0xbdba
incl %edi
cmpl %edi, %edx
jle 0xbdc3
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 0xbdaa
movl 0x30(%r8), %edi
testq %rcx, %rcx
je 0xbdb2
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 0xbdf3
movq 0x10(%rcx), %rdi
xorl %edx, %edx
movl $0x0, %esi
testq %rdi, %rdi
je 0xbdde
movl 0x30(%rdi), %esi
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0xbdea
movl 0x30(%rdi), %edx
cmpl %edx, %esi
cmovgl %esi, %edx
incl %edx
jmp 0xbdf5
xorl %edx, %edx
movl %edx, 0x30(%rcx)
jmp 0xbe76
movl $0x38, %edi
movq %rdx, %rbx
callq 0xc614
movq %rbx, %rdx
testq %rax, %rax
je 0xbe85
movq %r13, (%rax)
movq %r15, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x1, 0x30(%rax)
testq %rbp, %rbp
je 0xbe48
movq 0x28(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq 0x28(%rbp), %rcx
testq %rcx, %rcx
je 0xbe3e
movq %rax, 0x20(%rcx)
movq %rax, 0x28(%rbp)
movq %rbp, 0x20(%rax)
jmp 0xbe73
testq %r12, %r12
je 0xbe6f
movq 0x20(%r12), %rcx
movq %rcx, 0x20(%rax)
movq 0x20(%r12), %rcx
testq %rcx, %rcx
je 0xbe64
movq %rax, 0x28(%rcx)
movq %rax, 0x20(%r12)
movq %r12, 0x28(%rax)
jmp 0xbe73
movups %xmm0, 0x20(%rax)
movq %rax, (%rdx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3959