// File: /workspace/github_c_makefile_star2_O3/TurkeyMcMac[P]ts3d/src/map.c
// Function: map_check_walls
void map_check_walls(struct map *map, d3d_vec_s *pos, d3d_scalar radius)
{
	/* Yes, I know this code repeats itself a lot. */
	// Tile coordinates:
	long x = floor(pos->x), y = floor(pos->y);
	// xs (east, west) and ys (south, north) of 8 tiles around (x, y):
	long west, south, east, north;
	west = floor(pos->x - radius);
	south = floor(pos->y - radius);
	east = floor(pos->x + radius);
	north = floor(pos->y + radius);
	// The wall bits here at (x, y):
	uint8_t here = get_wall_ck(map, x, y);
	if (south < y) {
		// Correct the south side and maybe east/west.
		bool south_corrected = bitat(here, D3D_DNEGY);
		d3d_scalar south_dist = pos->y - floor(pos->y);
		if (south_corrected) pos->y = y + radius;
		if (west < x) {
			// Correct the west.
			if (bitat(here, D3D_DNEGX)) {
				pos->x = x + radius;
			} else if (!south_corrected) {
				// Detect southwest corner collision.
				uint8_t nw = get_wall_ck(map, west, south);
				bool hit_outer_corner = bitat(nw, D3D_DPOSY)
					|| bitat(nw, D3D_DPOSX);
				if (hit_outer_corner) {
					d3d_scalar west_dist = pos->x
						- floor(pos->x);
					// Do correction needing less movement.
					if (south_dist > west_dist) {
						pos->y = y + radius;
					} else {
						pos->x = x + radius;
					}
				}
			}
		} else if (east > x) {
			// Correct the east.
			if (bitat(here, D3D_DPOSX)) {
				pos->x = x + 1.0 - radius;
			} else if (!south_corrected) {
				// Detect southeast corner collision.
				uint8_t ne = get_wall_ck(map, east, south);
				bool hit_outer_corner = bitat(ne, D3D_DPOSY)
					|| bitat(ne, D3D_DNEGX);
				if (hit_outer_corner) {
					// Do correction needing less movement.
					d3d_scalar east_dist = ceil(pos->x)
						- pos->x;
					if (south_dist > east_dist) {
						pos->y = y + radius;
					} else {
						pos->x = x + 1.0 - radius;
					}
				}
			}
		}
	} else if (north > y) {
		// Correct the north side and maybe east/west.
		bool north_corrected = bitat(here, D3D_DPOSY);
		d3d_scalar north_dist = ceil(pos->y) - pos->y;
		if (north_corrected) pos->y = y + 1.0 - radius;
		if (west < x) {
			// Correct the west.
			if (bitat(here, D3D_DNEGX)) {
				pos->x = x + radius;
			} else if (!north_corrected) {
				// Detect northwest corner collision.
				uint8_t sw = get_wall_ck(map, west, north);
				bool hit_outer_corner = bitat(sw, D3D_DNEGY)
					|| bitat(sw, D3D_DPOSX);
				if (hit_outer_corner) {
					d3d_scalar west_dist = pos->x
						- floor(pos->x);
					// Do correction needing less movement.
					if (north_dist > west_dist) {
						pos->y = y + 1.0 - radius;
					} else {
						pos->x = x + radius;
					}
				}
			}
		} else if (east > x) {
			// Correct the east.
			if (bitat(here, D3D_DPOSX)) {
				pos->x = x + 1.0 - radius;
			} else if (!north_corrected) {
				// Detect northeast corner collision.
				uint8_t se = get_wall_ck(map, east, north);
				bool hit_outer_corner = bitat(se, D3D_DNEGY)
					|| bitat(se, D3D_DNEGX);
				if (hit_outer_corner) {
					d3d_scalar east_dist = ceil(pos->x)
						- pos->x;
					if (north_dist > east_dist) {
						pos->y = y + 1.0 - radius;
					} else {
						pos->x = x + 1.0 - radius;
					}
				}
			}
		}
	} else if (west < x) {
		// Correct only the west side.
		if (bitat(here, D3D_DNEGX)) pos->x = x + radius;
	} else if (east > x) {
		// Correct only the east side.
		if (bitat(here, D3D_DPOSX)) pos->x = x + 1.0 - radius;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r12
movsd (%rsi), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x20(%rsp)
movapd %xmm1, %xmm0
callq 0x2480
cvttsd2si %xmm0, %rbx
movsd 0x20(%rsp), %xmm0
callq 0x2480
cvttsd2si %xmm0, %r15
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
callq 0x2480
cvttsd2si %xmm0, %r13
movsd 0x20(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
callq 0x2480
cvttsd2si %xmm0, %rbp
movsd 0x10(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
callq 0x2480
cvttsd2si %xmm0, %rax
movq %rax, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
callq 0x2480
movsd %xmm0, 0x18(%rsp)
movq %r12, 0x30(%rsp)
movq %r12, %rdi
movq %rbx, 0x20(%rsp)
movq %rbx, %rsi
movq %r15, %rdx
callq 0x7b6e
movl %eax, %r12d
cmpq %r15, %rbp
jge 0x78f0
movq %r14, 0x28(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x2480
testb $0x8, %r12b
je 0x785f
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
addsd 0x8(%rsp), %xmm1
movq 0x28(%rsp), %rax
movsd %xmm1, 0x8(%rax)
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x79b2
testb $0x4, %r12b
jne 0x7a5c
testb $0x8, %r12b
jne 0x7b35
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7b6e
testb $0x3, %al
je 0x7b35
movq 0x28(%rsp), %rbx
movsd (%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2480
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x7a19
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7b5c
cvttsd2si 0x18(%rsp), %rbp
cmpq %r15, %rbp
jle 0x7a31
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x20b0
testb $0x2, %r12b
je 0x7933
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
addsd 0x47e1(%rip), %xmm1     # 0xc108
subsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%r14)
subsd 0x18(%rsp), %xmm0
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x7a6f
testb $0x4, %r12b
jne 0x7a49
testb $0x2, %r12b
jne 0x7b35
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7b6e
testb $0x9, %al
je 0x7b35
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2480
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x7ace
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x7a51
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x7b35
testb $0x1, %r12b
jne 0x7b16
testb $0x8, %r12b
jne 0x7b35
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7b6e
testb $0x6, %al
je 0x7b35
movq 0x28(%rsp), %rbx
movsd (%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20b0
subsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7b44
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x7b35
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x7aec
testb $0x4, %r12b
je 0x7b35
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7b0f
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7b2c
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x7b35
testb $0x1, %r12b
jne 0x7af9
testb $0x2, %r12b
jne 0x7b35
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7b6e
testb $0xc, %al
je 0x7b35
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20b0
subsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7b62
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd 0x462a(%rip), %xmm0     # 0xc108
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%r14)
jmp 0x7b35
cmpq %rax, 0x10(%rsp)
jle 0x7b35
andb $0x1, %r12b
je 0x7b35
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x45ff(%rip), %xmm0     # 0xc108
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
jmp 0x7b35
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x45e2(%rip), %xmm0     # 0xc108
subsd 0x8(%rsp), %xmm0
movq 0x28(%rsp), %rax
movsd %xmm0, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x45b2(%rip), %xmm0     # 0xc108
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x7b35
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x7b01