#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 abs(float);
float atan(int);
int /*<<< orphan*/ printf(char *, int, ...);
int turn_to_heading(void) {
  int game_coords_now_x = 0;
  int game_coords_now_y = 0;
  int game_coords_new_x = 10;
  int game_coords_new_y = 9;
  float game_coords_now_theta = 0;
  printf("x_now: %d and y_now: %d and x_goal: %d and y_goal: %d\n",
         game_coords_now_x, game_coords_now_y, game_coords_new_x,
         game_coords_new_y);
  float kp = 0.06;
  float desired_heading = atan((game_coords_new_y - game_coords_now_y) /
                               (game_coords_new_x - game_coords_now_x));
  if (game_coords_new_y > game_coords_now_y && desired_heading < 0) {
    desired_heading += 3.14159265;
  } else if (game_coords_new_y < game_coords_now_y && desired_heading > 0) {
    desired_heading -= 3.14159265;
  }
  printf("desired heading %.3f\n", desired_heading);
  float actual_heading = game_coords_now_theta;
  printf("actual heading %.3f\n", actual_heading);
  float error_angle = desired_heading - actual_heading;
  printf("error_angle %.3f\n", error_angle);
  int controller_output;
  if (abs(error_angle) < 10) {
    controller_output = 0;
  } else
    controller_output = (int)(kp * error_angle);
  printf("controller_output: %d\n", controller_output);
  return ((desired_heading - actual_heading) > 20);
}


x86 assembly (clang, -O0):
<turn_to_heading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
movl   $0x9,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  0xe81(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x4(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <atan@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11db <turn_to_heading+0xab>
xorps  %xmm0,%xmm0
ucomiss -0x1c(%rbp),%xmm0
jbe    11db <turn_to_heading+0xab>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3f(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    121b <turn_to_heading+0xeb>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1216 <turn_to_heading+0xe6>
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1216 <turn_to_heading+0xe6>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdff(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    121b <turn_to_heading+0xeb>
cvttss2si -0x1c(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
cvttss2si -0x20(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x1c(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
cvttss2si -0x24(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x24(%rbp),%xmm0
call   1030 <abs@plt>
cmp    $0xa,%eax
jge    128c <turn_to_heading+0x15c>
movl   $0x0,-0x28(%rbp)
jmp    129d <turn_to_heading+0x16d>
movss  -0x18(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x1c(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
movss  0xd44(%rip),%xmm1
ucomiss %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turn_to_heading>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xed3(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
xor    %edx,%edx
mov    $0xa,%ecx
mov    $0x9,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <atan@plt>
cvtss2sd %xmm0,%xmm1
addsd  0xe98(%rip),%xmm1
cvtsd2ss %xmm1,%xmm1
xorps  %xmm2,%xmm2
movaps %xmm0,%xmm3
cmpltss %xmm2,%xmm3
movaps %xmm3,%xmm2
andnps %xmm0,%xmm2
andps  %xmm1,%xmm3
orps   %xmm2,%xmm3
movaps %xmm3,(%rsp)
cvttss2si %xmm3,%ebx
lea    0xeb5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movaps (%rsp),%xmm0
call   1030 <abs@plt>
cmp    $0xa,%eax
movss  0xe39(%rip),%xmm0
mulss  (%rsp),%xmm0
cvttss2si %xmm0,%esi
cmovl  %ebp,%esi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
movaps (%rsp),%xmm0
ucomiss 0xe16(%rip),%xmm0
seta   %al
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"x_now: %d and y_now: %d and x_goal: %d and y_goal: %d\0A\00"
@.str.1 = [22 x i8] c"desired heading %.3f\0A\00"
@.str.2 = [21 x i8] c"actual heading %.3f\0A\00"
@.str.3 = [18 x i8] c"error_angle %.3f\0A\00"
@.str.4 = [23 x i8] c"controller_output: %d\0A\00"
define i32 @turn_to_heading() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 10, i32* %3
store i32 9, i32* %4
store float 0.000000e+00, float* %5
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13, i32 %14)
store float 0x3FAEB851E0000000, float* %6
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = sub nsw i32 %16, %17
%19 = load i32, i32* %3
%20 = load i32, i32* %1
%21 = sub nsw i32 %19, %20
%22 = sdiv i32 %18, %21
%23 = call float @atan(i32 %22)
store float %23, float* %7
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %0
%28 = load float, float* %7
%29 = fcmp olt float %28, 0.000000e+00
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = fadd double %32, 0x400921FB53C8D4F1
%34 = fptrunc double %33 to float
store float %34, float* %7
br label %48
35: ; preds = %27, %0
%36 = load i32, i32* %4
%37 = load i32, i32* %2
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = load float, float* %7
%41 = fcmp ogt float %40, 0.000000e+00
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load float, float* %7
%44 = fpext float %43 to double
%45 = fsub double %44, 0x400921FB53C8D4F1
%46 = fptrunc double %45 to float
store float %46, float* %7
br label %47
47: ; preds = %42, %39, %35
br label %48
48: ; preds = %47, %30
%49 = load float, float* %7
%50 = fptosi float %49 to i32
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = load float, float* %5
store float %52, float* %8
%53 = load float, float* %8
%54 = fptosi float %53 to i32
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = load float, float* %7
%57 = load float, float* %8
%58 = fsub float %56, %57
store float %58, float* %9
%59 = load float, float* %9
%60 = fptosi float %59 to i32
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = load float, float* %9
%63 = call i32 @abs(float %62)
%64 = icmp slt i32 %63, 10
br i1 %64, label %65, label %66
65: ; preds = %48
store i32 0, i32* %10
br label %71
66: ; preds = %48
%67 = load float, float* %6
%68 = load float, float* %9
%69 = fmul float %67, %68
%70 = fptosi float %69 to i32
store i32 %70, i32* %10
br label %71
71: ; preds = %66, %65
%72 = load i32, i32* %10
%73 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %72)
%74 = load float, float* %7
%75 = load float, float* %8
%76 = fsub float %74, %75
%77 = fcmp ogt float %76, 2.000000e+01
%78 = zext i1 %77 to i32
ret i32 %78
}

LLVM IR (-O2):
@.str = [55 x i8] c"x_now: %d and y_now: %d and x_goal: %d and y_goal: %d\0A\00"
@.str.1 = [22 x i8] c"desired heading %.3f\0A\00"
@.str.2 = [21 x i8] c"actual heading %.3f\0A\00"
@.str.3 = [18 x i8] c"error_angle %.3f\0A\00"
@.str.4 = [23 x i8] c"controller_output: %d\0A\00"
define i32 @turn_to_heading() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 0, i32 0, i32 10, i32 9)
%2 = tail call float @atan(i32 0)
%3 = fcmp olt float %2, 0.000000e+00
%4 = fpext float %2 to double
%5 = fadd double %4, 0x400921FB53C8D4F1
%6 = fptrunc double %5 to float
%7 = select i1 %3, float %6, float %2
%8 = fptosi float %7 to i32
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 0)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%12 = tail call i32 @abs(float %7)
%13 = icmp slt i32 %12, 10
%14 = fmul float %7, 0x3FAEB851E0000000
%15 = fptosi float %14 to i32
%16 = select i1 %13, i32 0, i32 %15
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = fcmp ogt float %7, 2.000000e+01
%19 = zext i1 %18 to i32
ret i32 %19
}