// File: /workspace/github_c_makefile_star2_O3/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 %rax
leaq 0x48(%rdi), %rax
movq 0x60(%rdi), %rcx
testq %rcx, %rcx
je 0xd57d
cmpq $0x0, (%rax)
jne 0xd612
cmpq $0x0, 0x50(%rdi)
jne 0xd631
cmpq %rdi, 0x58(%rcx)
jne 0xd650
movq 0x58(%rdi), %rax
addq $0x58, %rdi
movq %rax, 0x58(%rcx)
testq %rax, %rax
je 0xd575
movq %rcx, 0x60(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
jmp 0xd5fb
movq 0x48(%rdi), %rdx
movq 0x58(%rdi), %rcx
testq %rdx, %rdx
je 0xd5b3
cmpq %rdi, 0x50(%rdx)
jne 0xd66f
testq %rcx, %rcx
je 0xd5a2
movq %rcx, 0x50(%rdx)
movq %rcx, %rsi
jmp 0xd5af
movq 0x50(%rdi), %rsi
movq %rsi, 0x50(%rdx)
testq %rsi, %rsi
je 0xd5fd
movq %rdx, 0x48(%rsi)
movq 0x50(%rdi), %rdx
testq %rdx, %rdx
je 0xd5da
testq %rcx, %rcx
je 0xd5ca
movq %rcx, 0x48(%rdx)
movq %rcx, %rsi
jmp 0xd5d6
movq (%rax), %rsi
movq %rsi, 0x48(%rdx)
testq %rsi, %rsi
je 0xd5fd
movq %rdx, 0x50(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
testq %rcx, %rcx
je 0xd5fb
cmpq %rdi, 0x60(%rcx)
jne 0xd68e
movq $0x0, 0x60(%rcx)
popq %rax
retq
leaq 0x50(%rdi), %rcx
addq $0x58, %rdi
xorl %edx, %edx
movq %rdx, (%rcx)
movq %rdx, (%rax)
jmp 0xd575
leaq 0x1390(%rip), %rdi      # 0xe9a9
leaq 0x13a3(%rip), %rsi      # 0xe9c3
leaq 0x13a5(%rip), %rcx      # 0xe9cc
movl $0x64, %edx
callq 0x4210
leaq 0x13b5(%rip), %rdi      # 0xe9ed
leaq 0x1384(%rip), %rsi      # 0xe9c3
leaq 0x1386(%rip), %rcx      # 0xe9cc
movl $0x65, %edx
callq 0x4210
leaq 0x13b1(%rip), %rdi      # 0xea08
leaq 0x1365(%rip), %rsi      # 0xe9c3
leaq 0x1367(%rip), %rcx      # 0xe9cc
movl $0x69, %edx
callq 0x4210
leaq 0x13b5(%rip), %rdi      # 0xea2b
leaq 0x1346(%rip), %rsi      # 0xe9c3
leaq 0x1348(%rip), %rcx      # 0xe9cc
movl $0x7c, %edx
callq 0x4210
leaq 0x13b8(%rip), %rdi      # 0xea4d
leaq 0x1327(%rip), %rsi      # 0xe9c3
leaq 0x1329(%rip), %rcx      # 0xe9cc
movl $0x90, %edx
callq 0x4210