#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int fabs(float);
int fabsf(float);
float fmod(float, double);
int /*<<< orphan*/ grid_check(int, int);
float tan(float);
void cast_horz(float x, float y, float theta) {
  theta = fmod(theta, 360.0);
  int y_direction = (theta > 0 && theta < 180) ? 1 : -1;
  int x_direction = (theta < 90 || theta > 270) ? 1 : -1;
  float b_y = (int)y + 1 - y;
  float b_x = fabs(b_y / tan(theta * 3.14159 / 180));
  float dy = y_direction;
  float dx = x_direction * (b_x / b_y);
  float start_x = x + (x_direction * b_x);
  float start_y = y + (y_direction * b_y);
  float check_x = start_x;
  float check_y = start_y;
  while (fabsf(check_x - x) < 35 && fabs(check_y - y) < 35) {
    int grid_check_x = (int)check_x;
    int grid_check_y = (y_direction == 1) ? (int)check_y : (int)check_y - 1;
    grid_check(grid_check_x, grid_check_y);
    check_x += dx;
    check_y += dy;
  }
}


x86 assembly (clang, -O0):
<cast_horz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
call   1040 <fmod@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x3d(%rbp)
jbe    11a6 <cast_horz+0x56>
movss  0xe7c(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
seta   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%dl
mov    $0xffffffff,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%al
movss  0xe56(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
mov    %al,-0x3e(%rbp)
ja     11e9 <cast_horz+0x99>
movss  -0xc(%rbp),%xmm0
movss  0xe40(%rip),%xmm1
ucomiss %xmm1,%xmm0
seta   %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%dl
mov    $0xffffffff,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
cvttss2si -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde0(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdcc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1060 <tan@plt>
movaps %xmm0,%xmm1
movss  -0x44(%rbp),%xmm0
divss  %xmm1,%xmm0
call   1050 <fabs@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
cvtsi2ssl -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
cvtsi2ssl -0x14(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
divss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm1
cvtsi2ssl -0x14(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm1
cvtsi2ssl -0x10(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x23,%ecx
mov    %al,-0x45(%rbp)
jge    1308 <cast_horz+0x1b8>
movss  -0x34(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1050 <fabs@plt>
cmp    $0x23,%eax
setl   %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    1318 <cast_horz+0x1c8>
jmp    1376 <cast_horz+0x226>
cvttss2si -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    1337 <cast_horz+0x1e7>
cvttss2si -0x34(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1342 <cast_horz+0x1f2>
cvttss2si -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1070 <grid_check@plt>
movss  -0x24(%rbp),%xmm0
addss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12d1 <cast_horz+0x181>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_horz>:
push   %rbx
sub    $0x40,%rsp
movss  %xmm1,0x4(%rsp)
movss  %xmm0,0x8(%rsp)
movsd  0xe97(%rip),%xmm1
movaps %xmm2,%xmm0
call   1040 <fmod@plt>
movss  %xmm0,0x10(%rsp)
movss  0x4(%rsp),%xmm1
cvttss2si %xmm1,%eax
add    $0x1,%eax
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
subss  %xmm1,%xmm2
movss  %xmm2,(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulsd  0xe65(%rip),%xmm1
divsd  0xe65(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1060 <tan@plt>
movss  (%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1050 <fabs@plt>
cvtsi2ss %eax,%xmm3
movss  0xe48(%rip),%xmm4
movss  0xe44(%rip),%xmm2
movss  0xe40(%rip),%xmm0
movss  0x10(%rsp),%xmm5
cmpltss %xmm5,%xmm0
movaps %xmm0,%xmm1
andps  %xmm4,%xmm1
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
movaps %xmm5,%xmm2
cmpltss 0xe21(%rip),%xmm2
movaps %xmm2,%xmm1
andnps %xmm0,%xmm1
andps  %xmm4,%xmm2
orps   %xmm1,%xmm2
movaps %xmm2,0x20(%rsp)
movaps %xmm2,%xmm0
movss  %xmm3,0xc(%rsp)
mulss  %xmm3,%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm1,%xmm0
movaps %xmm0,0x30(%rsp)
subss  %xmm1,%xmm0
call   1030 <fabsf@plt>
cmp    $0x22,%eax
jg     1337 <cast_horz+0x1e7>
movss  0x10(%rsp),%xmm3
movaps %xmm3,%xmm0
cmpltss 0xdc0(%rip),%xmm0
movss  0xdbc(%rip),%xmm4
andps  %xmm0,%xmm4
movss  0xdb5(%rip),%xmm2
andnps %xmm2,%xmm0
orps   %xmm4,%xmm0
xorps  %xmm1,%xmm1
xorps  %xmm4,%xmm4
cmpltss %xmm3,%xmm4
andps  %xmm4,%xmm0
andnps %xmm2,%xmm4
orps   %xmm0,%xmm4
movss  (%rsp),%xmm2
movss  0xc(%rsp),%xmm5
divss  %xmm2,%xmm5
movss  0xd7c(%rip),%xmm0
ucomiss %xmm3,%xmm0
setbe  %al
ucomiss %xmm1,%xmm3
movaps 0x20(%rsp),%xmm0
mulss  %xmm5,%xmm0
movaps %xmm0,0x20(%rsp)
setbe  %cl
movaps %xmm4,0x10(%rsp)
mulss  %xmm4,%xmm2
addss  0x4(%rsp),%xmm2
movss  %xmm2,(%rsp)
or     %al,%cl
movzbl %cl,%ebx
neg    %ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
call   1050 <fabs@plt>
cmp    $0x22,%eax
jg     1337 <cast_horz+0x1e7>
cvttss2si 0x30(%rsp),%edi
cvttss2si (%rsp),%esi
add    %ebx,%esi
call   1070 <grid_check@plt>
movaps 0x30(%rsp),%xmm0
addss  0x20(%rsp),%xmm0
movss  (%rsp),%xmm1
addss  0x10(%rsp),%xmm1
movss  %xmm1,(%rsp)
movaps %xmm0,0x30(%rsp)
subss  0x8(%rsp),%xmm0
call   1030 <fabsf@plt>
cmp    $0x23,%eax
jl     12e0 <cast_horz+0x190>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @cast_horz(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca i32
%18 = alloca i32
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%19 = load float, float* %6
%20 = call float @fmod(float %19, double 3.600000e+02)
store float %20, float* %6
%21 = load float, float* %6
%22 = fcmp ogt float %21, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load float, float* %6
%25 = fcmp olt float %24, 1.800000e+02
br label %26
26: ; preds = %23, %3
%27 = phi i1 [ false, %3 ], [ %25, %23 ]
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 1, i32 -1
store i32 %29, i32* %7
%30 = load float, float* %6
%31 = fcmp olt float %30, 9.000000e+01
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load float, float* %6
%34 = fcmp ogt float %33, 2.700000e+02
br label %35
35: ; preds = %32, %26
%36 = phi i1 [ true, %26 ], [ %34, %32 ]
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 1, i32 -1
store i32 %38, i32* %8
%39 = load float, float* %5
%40 = fptosi float %39 to i32
%41 = add nsw i32 %40, 1
%42 = sitofp i32 %41 to float
%43 = load float, float* %5
%44 = fsub float %42, %43
store float %44, float* %9
%45 = load float, float* %9
%46 = load float, float* %6
%47 = fpext float %46 to double
%48 = fmul double %47, 3.141590e+00
%49 = fdiv double %48, 1.800000e+02
%50 = fptrunc double %49 to float
%51 = call float @tan(float %50)
%52 = fdiv float %45, %51
%53 = call i32 @fabs(float %52)
%54 = sitofp i32 %53 to float
store float %54, float* %10
%55 = load i32, i32* %7
%56 = sitofp i32 %55 to float
store float %56, float* %11
%57 = load i32, i32* %8
%58 = sitofp i32 %57 to float
%59 = load float, float* %10
%60 = load float, float* %9
%61 = fdiv float %59, %60
%62 = fmul float %58, %61
store float %62, float* %12
%63 = load float, float* %4
%64 = load i32, i32* %8
%65 = sitofp i32 %64 to float
%66 = load float, float* %10
%67 = call float @llvm.fmuladd.f32(float %65, float %66, float %63)
store float %67, float* %13
%68 = load float, float* %5
%69 = load i32, i32* %7
%70 = sitofp i32 %69 to float
%71 = load float, float* %9
%72 = call float @llvm.fmuladd.f32(float %70, float %71, float %68)
store float %72, float* %14
%73 = load float, float* %13
store float %73, float* %15
%74 = load float, float* %14
store float %74, float* %16
br label %75
75: ; preds = %101, %35
%76 = load float, float* %15
%77 = load float, float* %4
%78 = fsub float %76, %77
%79 = call i32 @fabsf(float %78)
%80 = icmp slt i32 %79, 35
br i1 %80, label %81, label %87
81: ; preds = %75
%82 = load float, float* %16
%83 = load float, float* %5
%84 = fsub float %82, %83
%85 = call i32 @fabs(float %84)
%86 = icmp slt i32 %85, 35
br label %87
87: ; preds = %81, %75
%88 = phi i1 [ false, %75 ], [ %86, %81 ]
br i1 %88, label %89, label %112
89: ; preds = %87
%90 = load float, float* %15
%91 = fptosi float %90 to i32
store i32 %91, i32* %17
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, 1
br i1 %93, label %94, label %97
94: ; preds = %89
%95 = load float, float* %16
%96 = fptosi float %95 to i32
br label %101
97: ; preds = %89
%98 = load float, float* %16
%99 = fptosi float %98 to i32
%100 = sub nsw i32 %99, 1
br label %101
101: ; preds = %97, %94
%102 = phi i32 [ %96, %94 ], [ %100, %97 ]
store i32 %102, i32* %18
%103 = load i32, i32* %17
%104 = load i32, i32* %18
%105 = call i32 @grid_check(i32 %103, i32 %104)
%106 = load float, float* %12
%107 = load float, float* %15
%108 = fadd float %107, %106
store float %108, float* %15
%109 = load float, float* %11
%110 = load float, float* %16
%111 = fadd float %110, %109
store float %111, float* %16
br label %75
112: ; preds = %87
ret void
}

LLVM IR (-O2):
define void @cast_horz(float %0, float %1, float %2) {
%4 = tail call float @fmod(float %2, double 3.600000e+02)
%5 = fcmp ogt float %4, 0.000000e+00
%6 = fcmp olt float %4, 1.800000e+02
%7 = and i1 %5, %6
%8 = fcmp olt float %4, 9.000000e+01
%9 = fcmp ogt float %4, 2.700000e+02
%10 = or i1 %8, %9
%11 = fptosi float %1 to i32
%12 = add nsw i32 %11, 1
%13 = sitofp i32 %12 to float
%14 = fsub float %13, %1
%15 = fpext float %4 to double
%16 = fmul double %15, 3.141590e+00
%17 = fdiv double %16, 1.800000e+02
%18 = fptrunc double %17 to float
%19 = tail call float @tan(float %18)
%20 = fdiv float %14, %19
%21 = tail call i32 @fabs(float %20)
%22 = sitofp i32 %21 to float
%23 = select i1 %7, float 1.000000e+00, float -1.000000e+00
%24 = select i1 %10, float 1.000000e+00, float -1.000000e+00
%25 = fdiv float %22, %14
%26 = fmul float %24, %25
%27 = tail call float @llvm.fmuladd.f32(float %24, float %22, float %0)
%28 = fsub float %27, %0
%29 = tail call i32 @fabsf(float %28)
%30 = icmp slt i32 %29, 35
br i1 %30, label %31, label %52
31: ; preds = %3
%32 = tail call float @llvm.fmuladd.f32(float %23, float %14, float %1)
%33 = and i1 %5, %6
%34 = xor i1 %33, true
%35 = sext i1 %34 to i32
br label %36
36: ; preds = %31, %42
%37 = phi float [ %27, %31 ], [ %47, %42 ]
%38 = phi float [ %32, %31 ], [ %48, %42 ]
%39 = fsub float %38, %1
%40 = tail call i32 @fabs(float %39)
%41 = icmp slt i32 %40, 35
br i1 %41, label %42, label %52
42: ; preds = %36
%43 = fptosi float %37 to i32
%44 = fptosi float %38 to i32
%45 = add nsw i32 %44, %35
%46 = tail call i32 @grid_check(i32 %43, i32 %45)
%47 = fadd float %26, %37
%48 = fadd float %23, %38
%49 = fsub float %47, %0
%50 = tail call i32 @fabsf(float %49)
%51 = icmp slt i32 %50, 35
br i1 %51, label %36, label %52
52: ; preds = %36, %42, %3
ret void
}