// File: /workspace/github_c_makefile_star2_O0/kernfel[P]fNEAT/robot-simplistic.c
// Function: get_sensor_readings_in_tilemaze
void get_sensor_readings_in_tilemaze( Robot *bot, TileMaze *maze, struct Robot_Params *params, double *sensor_inputs ) {
	int i;
	for ( i=0; i<params->num_dist_sensors; i++ ) {
		double s_cos = cos(bot->heading + params->dist_sensor_pos[i]);
		double s_sin = sin(bot->heading + params->dist_sensor_pos[i]);
		double s_x = s_cos * params->dist_sensor_length;
		double s_y = s_sin * params->dist_sensor_length;
		double root_x = bot->x + s_cos * params->radius;
		double root_y = bot->y + s_sin * params->radius;
		int root_tile_x = (int)(root_x / maze->tile_width);
		int root_tile_y = (int)(root_y / maze->tile_width);
		int cross_x = (int)((root_x + s_x) / maze->tile_width) - root_tile_x;
		int cross_y = (int)((root_y + s_y) / maze->tile_width) - root_tile_y;
		
		sensor_inputs[i] = params->invert_dist_sensors ? 1 : 0;

		if ( ! cross_x && ! cross_y )
			continue;

		double reading=0;
		
		// Penetration of the sensor stub into the space outside of the root tile
		double depth_x = (root_x + s_x - (cross_x>0 ? root_tile_x+1 : root_tile_x)*maze->tile_width) / s_x;
		double depth_y = (root_y + s_y - (cross_y>0 ? root_tile_y+1 : root_tile_y)*maze->tile_width) / s_y;
		
		// X crossing only, solid/invalid target tile
		if ( cross_x && ! cross_y
		 && (  root_tile_x+cross_x == maze->x || root_tile_x+cross_x == -1
		    || ! maze->tiles[root_tile_x+cross_x + maze->x*root_tile_y]
		    )
		) {
			reading = depth_x;

		// Y crossing only, solid/invalid target tile
		} else if ( cross_y && ! cross_x
		 && (  root_tile_y+cross_y == maze->y || root_tile_y+cross_y == -1
		    || ! maze->tiles[root_tile_x + maze->x*(root_tile_y+cross_y)]
		    )
		) {
			reading = depth_y;

		// Diagonal crossing
		} else if ( cross_x && cross_y ) {
			// Larger proportion of the x vector outside the tile => sensor stub reaches into diagonal tile via x-adjacent neighbour
			if ( depth_x > depth_y ) {
				// x-adjacent neighbour is solid/invalid target
				if ( root_tile_x+cross_x == -1 || root_tile_x+cross_x == maze->x || ! maze->tiles[root_tile_x+cross_x + maze->x*root_tile_y] )
					reading = depth_x;
				// Diagonally adjacent neighbour is solid/invalid target
				else if ( root_tile_y+cross_y == -1 || root_tile_y+cross_y == maze->y \
				 || ! maze->tiles[root_tile_x+cross_x + maze->x*(root_tile_y+cross_y)] )
					reading = depth_y;
			} else {
				if ( root_tile_y+cross_y == -1 || root_tile_y+cross_y == maze->y || ! maze->tiles[root_tile_x + maze->x*(root_tile_y+cross_y)] )
					reading = depth_y;
				else if ( root_tile_x+cross_x == -1 || root_tile_x+cross_x == maze->x \
				 || ! maze->tiles[root_tile_x+cross_x + maze->x*(root_tile_y+cross_y)] )
					reading = depth_x;
			}
		}

		sensor_inputs[i] = params->invert_dist_sensors ? 1-reading : reading;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x9205
movq -0x8(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
callq 0x1090
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
callq 0x1140
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x18(%rbp), %rax
mulsd 0x30(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
movq -0x18(%rbp), %rax
mulsd 0x30(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x30(%rbp), %xmm0
movq -0x18(%rbp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movsd 0x8(%rax), %xmm1
movsd -0x38(%rbp), %xmm0
movq -0x18(%rbp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x5c(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x64(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
subl -0x60(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x40(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpl $0x0, -0x64(%rbp)
jne 0x8eac
cmpl $0x0, -0x68(%rbp)
jne 0x8eac
jmp 0x91f7
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x50(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0x8eda
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x8ee3
movl -0x5c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movsd -0x88(%rbp), %xmm1
movl -0x8c(%rbp), %eax
cvtsi2sd %eax, %xmm0
movq -0x10(%rbp), %rax
movsd (%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
cmpl $0x0, -0x68(%rbp)
jle 0x8f4c
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x8f55
movl -0x60(%rbp), %eax
movl %eax, -0x9c(%rbp)
movsd -0x98(%rbp), %xmm1
movl -0x9c(%rbp), %eax
cvtsi2sd %eax, %xmm0
movq -0x10(%rbp), %rax
movsd (%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x8ff1
cmpl $0x0, -0x68(%rbp)
jne 0x8ff1
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x8fe2
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
cmpl $-0x1, %eax
je 0x8fe2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
imull -0x60(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x8ff1
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x91b1
cmpl $0x0, -0x68(%rbp)
je 0x904c
cmpl $0x0, -0x64(%rbp)
jne 0x904c
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x903d
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
cmpl $-0x1, %eax
je 0x903d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
movl -0x60(%rbp), %esi
addl -0x68(%rbp), %esi
imull %esi, %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x904c
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x91af
cmpl $0x0, -0x64(%rbp)
je 0x91ad
cmpl $0x0, -0x68(%rbp)
je 0x91ad
movsd -0x78(%rbp), %xmm0
ucomisd -0x80(%rbp), %xmm0
jbe 0x910e
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
cmpl $-0x1, %eax
je 0x90ae
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x90ae
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
imull -0x60(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x90ba
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x9109
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
cmpl $-0x1, %eax
je 0x90fd
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x90fd
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
movl -0x60(%rbp), %esi
addl -0x68(%rbp), %esi
imull %esi, %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x9107
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x9109
jmp 0x91ab
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
cmpl $-0x1, %eax
je 0x914e
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x914e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
movl -0x60(%rbp), %esi
addl -0x68(%rbp), %esi
imull %esi, %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x915a
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x91a9
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
cmpl $-0x1, %eax
je 0x919d
movl -0x5c(%rbp), %eax
addl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x919d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
movl -0x60(%rbp), %esi
addl -0x68(%rbp), %esi
imull %esi, %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x91a7
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x91a9
jmp 0x91ab
jmp 0x91ad
jmp 0x91af
jmp 0x91b1
movq -0x18(%rbp), %rax
movzbl 0x40(%rax), %eax
cmpl $0x0, %eax
je 0x91d5
movsd 0xea2(%rip), %xmm0      # 0xa068
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x91e2
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8d52
addq $0xb0, %rsp
popq %rbp
retq
nop