// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/redblack.c
// Function: rb_lookup
static struct RB_ENTRY(node) *
RB_ENTRY(_lookup)(int mode, const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
{
	struct RB_ENTRY(node) *x,*y;
	int cmp;
	int found=0;

	y=RBNULL; /* points to the parent of x */
	x=rbinfo->rb_root;

	if (mode==RB_LUFIRST)
	{
		/* Keep going left until we hit a NULL */
		while(x!=RBNULL)
		{
			y=x;
			x=x->left;
		}

		return(y);
	}
	else if (mode==RB_LULAST)
	{
		/* Keep going right until we hit a NULL */
		while(x!=RBNULL)
		{
			y=x;
			x=x->right;
		}

		return(y);
	}

	/* walk x down the tree */
	while(x!=RBNULL && found==0)
	{
		y=x;
		/* printf("key=%s, RB_GET(x, key)=%s\n", key, RB_GET(x, key)); */
#ifndef RB_CUSTOMIZE
		cmp=RB_CMP(key, RB_GET(x, key), rbinfo->rb_config);
#else
		cmp=RB_CMP(key, RB_GET(x, key));
#endif /* RB_CUSTOMIZE */


		if (cmp<0)
			x=x->left;
		else if (cmp>0)
			x=x->right;
		else
			found=1;
	}

	if (found && (mode==RB_LUEQUAL || mode==RB_LUGTEQ || mode==RB_LULTEQ))
		return(x);
	
	if (!found && (mode==RB_LUEQUAL || mode==RB_LUNEXT || mode==RB_LUPREV))
		return(RBNULL);
	
	if (mode==RB_LUGTEQ || (!found && mode==RB_LUGREAT))
	{
		if (cmp>0)
			return(RB_ENTRY(_successor)(y));
		else
			return(y);
	}

	if (mode==RB_LULTEQ || (!found && mode==RB_LULESS))
	{
		if (cmp<0)
			return(RB_ENTRY(_predecessor)(y));
		else
			return(y);
	}

	if (mode==RB_LUNEXT || (found && mode==RB_LUGREAT))
		return(RB_ENTRY(_successor)(x));

	if (mode==RB_LUPREV || (found && mode==RB_LULESS))
		return(RB_ENTRY(_predecessor)(x));
	
	/* Shouldn't get here */
	return(RBNULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x38(%rbp)
leaq 0x115e5f(%rip), %rax    # 0x526200
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpl $0x7, -0xc(%rbp)
jne 0x4103e8
jmp 0x4103b9
leaq 0x115e40(%rip), %rax    # 0x526200
cmpq %rax, -0x28(%rbp)
je 0x4103db
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x4103b9
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x8, -0xc(%rbp)
jne 0x410420
jmp 0x4103f0
leaq 0x115e09(%rip), %rax    # 0x526200
cmpq %rax, -0x28(%rbp)
je 0x410413
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x4103f0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4105a2
jmp 0x410422
jmp 0x410424
xorl %eax, %eax
leaq 0x115dd3(%rip), %rcx    # 0x526200
cmpq %rcx, -0x28(%rbp)
movb %al, -0x39(%rbp)
je 0x410440
cmpl $0x0, -0x38(%rbp)
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x410449
jmp 0x4104a3
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq 0x20(%rcx), %rsi
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rdx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x410484
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x4104a1
cmpl $0x0, -0x34(%rbp)
jle 0x410498
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x41049f
movl $0x1, -0x38(%rbp)
jmp 0x4104a1
jmp 0x410424
cmpl $0x0, -0x38(%rbp)
je 0x4104c8
cmpl $0x0, -0xc(%rbp)
je 0x4104bb
cmpl $0x1, -0xc(%rbp)
je 0x4104bb
cmpl $0x2, -0xc(%rbp)
jne 0x4104c8
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x0, -0x38(%rbp)
jne 0x4104f0
cmpl $0x0, -0xc(%rbp)
je 0x4104e0
cmpl $0x5, -0xc(%rbp)
je 0x4104e0
cmpl $0x6, -0xc(%rbp)
jne 0x4104f0
leaq 0x115d19(%rip), %rax    # 0x526200
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x1, -0xc(%rbp)
je 0x410502
cmpl $0x0, -0x38(%rbp)
jne 0x410524
cmpl $0x4, -0xc(%rbp)
jne 0x410524
cmpl $0x0, -0x34(%rbp)
jle 0x41051a
movq -0x30(%rbp), %rdi
callq 0x410760
movq %rax, -0x8(%rbp)
jmp 0x4105a2
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x2, -0xc(%rbp)
je 0x410536
cmpl $0x0, -0x38(%rbp)
jne 0x410555
cmpl $0x3, -0xc(%rbp)
jne 0x410555
cmpl $0x0, -0x34(%rbp)
jge 0x41054b
movq -0x30(%rbp), %rdi
callq 0x410800
movq %rax, -0x8(%rbp)
jmp 0x4105a2
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x5, -0xc(%rbp)
je 0x410567
cmpl $0x0, -0x38(%rbp)
je 0x410576
cmpl $0x4, -0xc(%rbp)
jne 0x410576
movq -0x28(%rbp), %rdi
callq 0x410760
movq %rax, -0x8(%rbp)
jmp 0x4105a2
cmpl $0x6, -0xc(%rbp)
je 0x410588
cmpl $0x0, -0x38(%rbp)
je 0x410597
cmpl $0x3, -0xc(%rbp)
jne 0x410597
movq -0x28(%rbp), %rdi
callq 0x410800
movq %rax, -0x8(%rbp)
jmp 0x4105a2
leaq 0x115c62(%rip), %rax    # 0x526200
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)