// File: /workspace/github_c_makefile_star2_O0/bobrippling[P]tim/window.c
// Function: window_evict
void window_evict(window *const evictee)
{
	if(evictee->neighbours.above){
		/* we are just a child in the chain */
		assert(!evictee->neighbours.left);
		assert(!evictee->neighbours.right);

		window *above = evictee->neighbours.above;

		assert(above->neighbours.below == evictee);
		above->neighbours.below = evictee->neighbours.below;

		if(evictee->neighbours.below)
			evictee->neighbours.below->neighbours.above = above;

		evictee->neighbours.above = evictee->neighbours.below = NULL;
		return;
	}

	/* we are a top-most chain.
	 * remove ourselves from the left-right hierarchy
	 * if we have a child below, it takes our place.
	 */
	window *const child = evictee->neighbours.below;

	if(evictee->neighbours.left){
		window *left = evictee->neighbours.left;

		assert(left->neighbours.right == evictee);

		window *target = child ? child : evictee->neighbours.right;
		left->neighbours.right = target;
		if(target)
			target->neighbours.left = left;
	}

	if(evictee->neighbours.right){
		window *right = evictee->neighbours.right;

		window *target = child ? child : evictee->neighbours.left;
		right->neighbours.left = target;
		if(target)
			target->neighbours.right = right;
	}

	evictee->neighbours.left = evictee->neighbours.right = NULL;
	evictee->neighbours.above = evictee->neighbours.below = NULL;
	if(child){
		assert(child->neighbours.above == evictee);
		child->neighbours.above = NULL;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x131e6
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x13118
jmp 0x13137
leaq 0x297a(%rip), %rdi      # 0x15a99
leaq 0x298d(%rip), %rsi      # 0x15ab3
movl $0x64, %edx
leaq 0x298a(%rip), %rcx      # 0x15abc
callq 0x4210
movq -0x8(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x13144
jmp 0x13163
leaq 0x2992(%rip), %rdi      # 0x15add
leaq 0x2961(%rip), %rsi      # 0x15ab3
movl $0x65, %edx
leaq 0x295e(%rip), %rcx      # 0x15abc
callq 0x4210
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x1317f
jmp 0x1319e
leaq 0x2972(%rip), %rdi      # 0x15af8
leaq 0x2926(%rip), %rsi      # 0x15ab3
movl $0x69, %edx
leaq 0x2923(%rip), %rcx      # 0x15abc
callq 0x4210
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x131c9
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x13351
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x13282
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x1321d
jmp 0x1323c
leaq 0x28f7(%rip), %rdi      # 0x15b1b
leaq 0x2888(%rip), %rsi      # 0x15ab3
movl $0x7c, %edx
leaq 0x2885(%rip), %rcx      # 0x15abc
callq 0x4210
cmpq $0x0, -0x18(%rbp)
je 0x1324d
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x13259
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x50(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x13280
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x13282
movq -0x8(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x132df
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x132aa
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x132b6
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpq $0x0, -0x38(%rbp)
je 0x132dd
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
jmp 0x132df
movq -0x8(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x60(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x13351
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x13326
jmp 0x13345
leaq 0x2810(%rip), %rdi      # 0x15b3d
leaq 0x277f(%rip), %rsi      # 0x15ab3
movl $0x90, %edx
leaq 0x277c(%rip), %rcx      # 0x15abc
callq 0x4210
movq -0x18(%rbp), %rax
movq $0x0, 0x60(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)