// File: /workspace/github_c_makefile_star2_O0/TurkeyMcMac[P]ts3d/src/d3d.c
// Function: draw_sprite_dist
static void draw_sprite_dist(
	d3d_camera *cam,
	d3d_vec_s cam_pos,
	d3d_scalar cam_facing,
	const d3d_sprite_s *sp,
	d3d_scalar dist)
{
	if (sp->scale.x <= (d3d_scalar)0.0 || sp->scale.y <= (d3d_scalar)0.0)
		return;
	d3d_vec_s disp = { sp->pos.x - cam_pos.x, sp->pos.y - cam_pos.y };
	d3d_scalar angle, width, height, diff, maxdiff;
	long start_x, start_y;
	if (dist == (d3d_scalar)0.0) return;
	// The angle of the sprite relative to the +x axis:
	angle = atan2(disp.y, disp.x);
	// The view width of the sprite in radians:
	width = atan(sp->scale.x / dist) * 2;
	// The max camera-sprite angle difference so the sprite's visible:
	maxdiff = (cam->fov.x + width) / 2;
	diff = angle_diff(cam_facing, angle);
	if (fabs(diff) > maxdiff) return;
	// The height of the sprite in pixels on the camera screen:
	height = atan(sp->scale.y / dist) * 2 / cam->fov.y * cam->height;
	// The width of the sprite in pixels on the camera screen:
	width = width / cam->fov.x * cam->width;
	// The first x where the sprite appears on the screen:
	start_x = (cam->width - width) / 2 + diff / cam->fov.x * cam->width;
	// The first y where the sprite appears on the screen:
	start_y = (cam->height - height) / 2;
	for (size_t x = 0; x < width; ++x) {
		// cx is the x on the camera screen; sx is the x on the sprite's
		// texture:
		size_t cx, sx;
		cx = x + start_x;
		if (cx >= cam->width || dist >= cam->dists[cx]) continue;
		sx = (d3d_scalar)x / width * sp->txtr->width;
		if (sx >= sp->txtr->width) continue;
		for (size_t y = 0; y < height; ++y) {
			// cy and sy correspond to cx and sx above:
			size_t cy, sy;
			cy = y + start_y;
			if (cy >= cam->height) continue;
			sy = (d3d_scalar)y / height * sp->txtr->height;
			if (sy >= sp->txtr->height) continue;
			d3d_pixel p = *GET(sp->txtr, pixels, sx, sy);
			if (p != sp->transparent) *GET(cam, pixels, cx, cy) = p;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movsd %xmm0, -0x38(%rbp)
movsd %xmm1, -0x30(%rbp)
movq %rdi, -0x40(%rbp)
movsd %xmm2, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movsd %xmm3, -0x58(%rbp)
movq -0x50(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd 0x10(%rax), %xmm0
jae 0x4593
movq -0x50(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd 0x18(%rax), %xmm0
jb 0x4598
jmp 0x4b1a
movq -0x50(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
subsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x45d2
jp 0x45d2
jmp 0x4b1a
movsd -0x60(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
movsd %xmm1, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
callq 0x2050
movsd %xmm0, -0x70(%rbp)
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm0
divsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x21f0
movsd 0xca31(%rip), %xmm1     # 0x11050
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x40(%rbp), %rax
movsd (%rax), %xmm0
addsd -0x78(%rbp), %xmm0
movsd 0xca13(%rip), %xmm1     # 0x11050
divsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x4b30
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movaps 0xc997(%rip), %xmm1     # 0x11010
pand %xmm1, %xmm0
ucomisd -0x90(%rbp), %xmm0
jbe 0x468c
jmp 0x4b1a
movq -0x50(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd -0x58(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x21f0
addsd %xmm0, %xmm0
movq -0x40(%rbp), %rax
movsd 0x8(%rax), %xmm1
divsd %xmm1, %xmm0
movq 0x18(%rax), %xmm3
movaps 0xc9a6(%rip), %xmm2     # 0x11070
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movapd 0xc9aa(%rip), %xmm1     # 0x11080
subpd %xmm1, %xmm3
movaps %xmm3, %xmm4
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x78(%rbp), %xmm0
movq -0x40(%rbp), %rax
movsd (%rax), %xmm3
divsd %xmm3, %xmm0
movq 0x10(%rax), %xmm3
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
subpd %xmm1, %xmm3
movaps %xmm3, %xmm4
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %xmm4
punpckldq %xmm2, %xmm4    # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
subpd %xmm1, %xmm4
movaps %xmm4, %xmm0
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
addsd %xmm0, %xmm4
movsd -0x78(%rbp), %xmm0
movaps %xmm4, %xmm3
subsd %xmm0, %xmm3
movsd 0xc8d8(%rip), %xmm0     # 0x11028
mulsd %xmm0, %xmm3
movsd -0x88(%rbp), %xmm0
movsd (%rax), %xmm5
divsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x98(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
subsd -0x80(%rbp), %xmm0
movsd 0xc8af(%rip), %xmm1     # 0x11050
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movaps 0xc8ad(%rip), %xmm0     # 0x11070
movq -0xa8(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xc8a9(%rip), %xmm0     # 0x11080
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4b1a
movq -0xa8(%rbp), %rax
addq -0x98(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x4836
movsd -0x58(%rbp), %xmm0
movq -0x40(%rbp), %rax
movq 0x78(%rax), %rax
movq -0xb0(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jb 0x483b
jmp 0x4b03
movq -0xa8(%rbp), %xmm0
movaps 0xc826(%rip), %xmm3     # 0x11070
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0xc82a(%rip), %xmm2     # 0x11080
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd -0x78(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0xc798(%rip), %xmm1     # 0x11040
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq (%rcx), %rax
jb 0x48d7
jmp 0x4b03
movq $0x0, -0xc0(%rbp)
movaps 0xc787(%rip), %xmm0     # 0x11070
movq -0xc0(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xc783(%rip), %xmm0     # 0x11080
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4b01
movq -0xc0(%rbp), %rax
addq -0xa0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jb 0x4946
jmp 0x4aea
movq -0xc0(%rbp), %xmm0
movaps 0xc71b(%rip), %xmm3     # 0x11070
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0xc71f(%rip), %xmm2     # 0x11080
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd -0x80(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0xc68c(%rip), %xmm1     # 0x11040
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jb 0x49e4
jmp 0x4aea
movq -0xb8(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x4a43
movq -0xd0(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jae 0x4a43
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
addq $0x10, %rax
movq -0xd0(%rbp), %rcx
movq -0x50(%rbp), %rdx
movq 0x20(%rdx), %rdx
movq 0x8(%rdx), %rdx
imulq -0xb8(%rbp), %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
jmp 0x4a4e
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
jmp 0x4a4e
movq -0xe0(%rbp), %rax
movb (%rax), %al
movb %al, -0xd1(%rbp)
movzbl -0xd1(%rbp), %eax
movq -0x50(%rbp), %rcx
movzbl 0x28(%rcx), %ecx
cmpl %ecx, %eax
je 0x4ae8
movb -0xd1(%rbp), %al
movb %al, -0xe1(%rbp)
movq -0xb0(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x4ace
movq -0xc8(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x4ace
movq -0x40(%rbp), %rax
addq $0x80, %rax
movq -0xc8(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
imulq -0xb0(%rbp), %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
jmp 0x4ad9
xorl %eax, %eax
movq %rax, -0xf0(%rbp)
jmp 0x4ad9
movb -0xe1(%rbp), %cl
movq -0xf0(%rbp), %rax
movb %cl, (%rax)
jmp 0x4aea
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x48e2
jmp 0x4b03
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x47bc
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)