// File: /workspace/github_c_makefile_star2_O2/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 0x2490
cvttsd2si %xmm0, %rbx
movsd 0x20(%rsp), %xmm0
callq 0x2490
cvttsd2si %xmm0, %r15
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
callq 0x2490
cvttsd2si %xmm0, %r13
movsd 0x20(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
callq 0x2490
cvttsd2si %xmm0, %rbp
movsd 0x10(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
callq 0x2490
cvttsd2si %xmm0, %rax
movq %rax, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
callq 0x2490
movsd %xmm0, 0x18(%rsp)
movq %r12, 0x30(%rsp)
movq %r12, %rdi
movq %rbx, 0x20(%rsp)
movq %rbx, %rsi
movq %r15, %rdx
callq 0x75a2
movl %eax, %r12d
cmpq %r15, %rbp
jge 0x7342
movq %r14, 0x28(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x2490
testb $0x8, %r12b
je 0x72b4
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 0x73fe
testb $0x4, %r12b
jne 0x74a2
testb $0x8, %r12b
jne 0x756f
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x75a2
testb $0x3, %al
je 0x756f
movq 0x28(%rsp), %rbx
movsd (%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2490
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x7465
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7593
cvttsd2si 0x18(%rsp), %rbp
cmpq %r15, %rbp
jle 0x747a
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x20b0
testb $0x2, %r12b
je 0x7382
cvtsi2sd %r15, %xmm1
addsd 0x3d7a(%rip), %xmm1     # 0xb0f0
subsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%r14)
subsd 0x18(%rsp), %xmm0
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x74b2
testb $0x4, %r12b
jne 0x7492
testb $0x2, %r12b
jne 0x756f
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x75a2
testb $0x9, %al
je 0x756f
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2490
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x7511
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x7497
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x756f
testb $0x1, %r12b
jne 0x7553
testb $0x8, %r12b
jne 0x756f
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x75a2
testb $0x6, %al
je 0x756f
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 0x757e
cvtsi2sd %r15, %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x756f
movq 0x20(%rsp), %rax
cmpq %rax, %r13
jge 0x752c
testb $0x4, %r12b
je 0x756f
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x754c
cvtsi2sd %rax, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7566
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
jle 0x756f
testb $0x1, %r12b
jne 0x7539
testb $0x2, %r12b
jne 0x756f
movq 0x30(%rsp), %rdi
movq %rbp, %rdx
movsd %xmm0, 0x18(%rsp)
callq 0x75a2
testb $0xc, %al
je 0x756f
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20b0
subsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7599
cvtsi2sd %r15, %xmm0
addsd 0x3bd2(%rip), %xmm0     # 0xb0f0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%r14)
jmp 0x756f
cmpq %rax, 0x10(%rsp)
jle 0x756f
andb $0x1, %r12b
je 0x756f
cvtsi2sd %rax, %xmm0
addsd 0x3baa(%rip), %xmm0     # 0xb0f0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
jmp 0x756f
cvtsi2sd %rax, %xmm0
addsd 0x3b90(%rip), %xmm0     # 0xb0f0
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
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x3b63(%rip), %xmm0     # 0xb0f0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x756f
cvtsi2sdq 0x20(%rsp), %xmm0
jmp 0x753e