// File: /workspace/github_c_makefile_star2_O1/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 0x7bc2
movl %eax, %r12d
cmpq %r15, %rbp
jge 0x7944
movq %r14, 0x28(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x2480
testb $0x8, %r12b
je 0x78b3
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 0x7a06
testb $0x4, %r12b
jne 0x7ab0
testb $0x8, %r12b
jne 0x7b89
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7bc2
testb $0x3, %al
je 0x7b89
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 0x7a6d
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7bb0
cvttsd2si 0x18(%rsp), %rbp
cmpq %r15, %rbp
jle 0x7a85
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x20b0
testb $0x2, %r12b
je 0x7987
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
addsd 0x46c5(%rip), %xmm1     # 0xc040
subsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%r14)
subsd 0x18(%rsp), %xmm0
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x7ac3
testb $0x4, %r12b
jne 0x7a9d
testb $0x2, %r12b
jne 0x7b89
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7bc2
testb $0x9, %al
je 0x7b89
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2480
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x7b22
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x7aa5
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x7b89
testb $0x1, %r12b
jne 0x7b6a
testb $0x8, %r12b
jne 0x7b89
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7bc2
testb $0x6, %al
je 0x7b89
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 0x7b98
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x7b89
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x7b40
testb $0x4, %r12b
je 0x7b89
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7b63
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7b80
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x7b89
testb $0x1, %r12b
jne 0x7b4d
testb $0x2, %r12b
jne 0x7b89
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x7bc2
testb $0xc, %al
je 0x7b89
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20b0
subsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7bb6
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd 0x450e(%rip), %xmm0     # 0xc040
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%r14)
jmp 0x7b89
cmpq %rax, 0x10(%rsp)
jle 0x7b89
andb $0x1, %r12b
je 0x7b89
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x44e3(%rip), %xmm0     # 0xc040
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
jmp 0x7b89
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x44c6(%rip), %xmm0     # 0xc040
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 0x4496(%rip), %xmm0     # 0xc040
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x7b89
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x7b55