#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(int);
int /*<<< orphan*/ print_to_screen(char *, char *, int /*<<< orphan*/);
int coursehold_pid(int selected_course, int actual_heading,
                   int current_rudder_angle) {
  print_to_screen("coursehold", "pid equation", 0);
  int factor = 1;
  int delta = 0;
  int diff = 0;
  diff = selected_course - actual_heading;
  if (diff < 0) {
    factor = -1;
  }
  diff = abs(diff);
  if (diff > 44 && diff <= 50)
    delta = 9;
  if (diff > 30 && diff <= 40)
    delta = 8;
  if (diff > 20 && diff <= 30)
    delta = 7;
  if (diff == 20)
    delta = 6;
  if (diff > 17 && diff <= 19)
    delta = 5;
  if (diff > 14 && diff <= 17)
    delta = 3;
  if (diff > 10 && diff <= 14)
    delta = 2;
  if (diff > 5 && diff <= 10)
    delta = 1;
  return delta * factor;
}


x86 assembly (clang, -O0):
<coursehold_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    0xec8(%rip),%rdi
lea    0xecc(%rip),%rsi
xor    %edx,%edx
call   1040 <print_to_screen@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1175 <coursehold_pid+0x55>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2c,-0x18(%rbp)
jle    119b <coursehold_pid+0x7b>
cmpl   $0x32,-0x18(%rbp)
jg     119b <coursehold_pid+0x7b>
movl   $0x9,-0x14(%rbp)
cmpl   $0x1e,-0x18(%rbp)
jle    11b6 <coursehold_pid+0x96>
cmpl   $0x28,-0x18(%rbp)
jg     11b6 <coursehold_pid+0x96>
movl   $0x8,-0x14(%rbp)
cmpl   $0x14,-0x18(%rbp)
jle    11d1 <coursehold_pid+0xb1>
cmpl   $0x1e,-0x18(%rbp)
jg     11d1 <coursehold_pid+0xb1>
movl   $0x7,-0x14(%rbp)
cmpl   $0x14,-0x18(%rbp)
jne    11e2 <coursehold_pid+0xc2>
movl   $0x6,-0x14(%rbp)
cmpl   $0x11,-0x18(%rbp)
jle    11fd <coursehold_pid+0xdd>
cmpl   $0x13,-0x18(%rbp)
jg     11fd <coursehold_pid+0xdd>
movl   $0x5,-0x14(%rbp)
cmpl   $0xe,-0x18(%rbp)
jle    1218 <coursehold_pid+0xf8>
cmpl   $0x11,-0x18(%rbp)
jg     1218 <coursehold_pid+0xf8>
movl   $0x3,-0x14(%rbp)
cmpl   $0xa,-0x18(%rbp)
jle    1233 <coursehold_pid+0x113>
cmpl   $0xe,-0x18(%rbp)
jg     1233 <coursehold_pid+0x113>
movl   $0x2,-0x14(%rbp)
cmpl   $0x5,-0x18(%rbp)
jle    124e <coursehold_pid+0x12e>
cmpl   $0xa,-0x18(%rbp)
jg     124e <coursehold_pid+0x12e>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coursehold_pid>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xee2(%rip),%rdi
lea    0xee6(%rip),%rsi
xor    %edx,%edx
call   1030 <print_to_screen@plt>
sub    %ebp,%ebx
mov    %ebx,%eax
neg    %eax
cmovs  %ebx,%eax
lea    -0x2d(%rax),%ecx
xor    %edx,%edx
cmp    $0x6,%ecx
setb   %dl
lea    (%rdx,%rdx,8),%ecx
lea    -0x1f(%rax),%edx
cmp    $0xa,%edx
mov    $0x8,%edx
cmovae %ecx,%edx
lea    -0x15(%rax),%ecx
cmp    $0xa,%ecx
mov    $0x7,%ecx
cmovae %edx,%ecx
cmp    $0x14,%eax
mov    $0x6,%edx
cmovne %ecx,%edx
mov    %eax,%ecx
and    $0x7ffffffe,%ecx
cmp    $0x12,%ecx
mov    $0x5,%ecx
cmovne %edx,%ecx
lea    -0xf(%rax),%edx
cmp    $0x3,%edx
mov    $0x3,%edx
cmovae %ecx,%edx
lea    -0xb(%rax),%ecx
cmp    $0x4,%ecx
mov    $0x2,%ecx
cmovae %edx,%ecx
add    $0xfffffffa,%eax
cmp    $0x5,%eax
mov    $0x1,%edx
cmovae %ecx,%edx
mov    %edx,%eax
neg    %eax
test   %ebx,%ebx
cmovns %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"coursehold\00"
@.str.1 = [13 x i8] c"pid equation\00"
define i32 @coursehold_pid(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = call i32 @print_to_screen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %7
br label %17
17: ; preds = %16, %3
%18 = load i32, i32* %9
%19 = call i32 @abs(i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp sgt i32 %20, 44
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %9
%24 = icmp sle i32 %23, 50
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 9, i32* %8
br label %26
26: ; preds = %25, %22, %17
%27 = load i32, i32* %9
%28 = icmp sgt i32 %27, 30
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %9
%31 = icmp sle i32 %30, 40
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 8, i32* %8
br label %33
33: ; preds = %32, %29, %26
%34 = load i32, i32* %9
%35 = icmp sgt i32 %34, 20
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* %9
%38 = icmp sle i32 %37, 30
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 7, i32* %8
br label %40
40: ; preds = %39, %36, %33
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 20
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 6, i32* %8
br label %44
44: ; preds = %43, %40
%45 = load i32, i32* %9
%46 = icmp sgt i32 %45, 17
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* %9
%49 = icmp sle i32 %48, 19
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 5, i32* %8
br label %51
51: ; preds = %50, %47, %44
%52 = load i32, i32* %9
%53 = icmp sgt i32 %52, 14
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* %9
%56 = icmp sle i32 %55, 17
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 3, i32* %8
br label %58
58: ; preds = %57, %54, %51
%59 = load i32, i32* %9
%60 = icmp sgt i32 %59, 10
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = load i32, i32* %9
%63 = icmp sle i32 %62, 14
br i1 %63, label %64, label %65
64: ; preds = %61
store i32 2, i32* %8
br label %65
65: ; preds = %64, %61, %58
%66 = load i32, i32* %9
%67 = icmp sgt i32 %66, 5
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i32, i32* %9
%70 = icmp sle i32 %69, 10
br i1 %70, label %71, label %72
71: ; preds = %68
store i32 1, i32* %8
br label %72
72: ; preds = %71, %68, %65
%73 = load i32, i32* %8
%74 = load i32, i32* %7
%75 = mul nsw i32 %73, %74
ret i32 %75
}

LLVM IR (-O2):
@.str = [11 x i8] c"coursehold\00"
@.str.1 = [13 x i8] c"pid equation\00"
define i32 @coursehold_pid(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @print_to_screen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = sub nsw i32 %0, %1
%6 = icmp sgt i32 %5, -1
%7 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
%8 = add nsw i32 %7, -45
%9 = icmp ult i32 %8, 6
%10 = select i1 %9, i32 9, i32 0
%11 = add nsw i32 %7, -31
%12 = icmp ult i32 %11, 10
%13 = select i1 %12, i32 8, i32 %10
%14 = add nsw i32 %7, -21
%15 = icmp ult i32 %14, 10
%16 = select i1 %15, i32 7, i32 %13
%17 = icmp eq i32 %7, 20
%18 = select i1 %17, i32 6, i32 %16
%19 = and i32 %7, 2147483646
%20 = icmp eq i32 %19, 18
%21 = select i1 %20, i32 5, i32 %18
%22 = add nsw i32 %7, -15
%23 = icmp ult i32 %22, 3
%24 = select i1 %23, i32 3, i32 %21
%25 = add nsw i32 %7, -11
%26 = icmp ult i32 %25, 4
%27 = select i1 %26, i32 2, i32 %24
%28 = add nsw i32 %7, -6
%29 = icmp ult i32 %28, 5
%30 = select i1 %29, i32 1, i32 %27
%31 = sub nsw i32 0, %30
%32 = select i1 %6, i32 %30, i32 %31
ret i32 %32
}