#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 calc_rudder_gain(int);
int /*<<< orphan*/ rudder_center();
int /*<<< orphan*/ rudder_left();
int /*<<< orphan*/ rudder_right();
void execute_rudder_action(int course, int heading, int rudder) {
  int coursediff = course - heading;
  int gain = calc_rudder_gain(coursediff);
  if (heading == course) {
    if (rudder == 0) {
      rudder_center();
    }
    if (rudder > 0) {
      rudder_center();
    }
    if (rudder < 0) {
      rudder_center();
    }
  }
  if (heading < course) {
    if (rudder == 0) {
      rudder_right();
    }
    if (rudder > 0) {
      rudder_center();
    }
    if (rudder < 0) {
      rudder_right();
    }
  }
  if (heading > course) {
    if (rudder == 0) {
      rudder_left();
    }
    if (rudder > 0) {
      rudder_left();
    }
    if (rudder < 0) {
      rudder_center();
    }
  }
}


x86 assembly (clang, -O0):
<execute_rudder_action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <calc_rudder_gain@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11a9 <execute_rudder_action+0x69>
cmpl   $0x0,-0xc(%rbp)
jne    1182 <execute_rudder_action+0x42>
mov    $0x0,%al
call   1040 <rudder_center@plt>
cmpl   $0x0,-0xc(%rbp)
jle    1193 <execute_rudder_action+0x53>
mov    $0x0,%al
call   1040 <rudder_center@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11a4 <execute_rudder_action+0x64>
mov    $0x0,%al
call   1040 <rudder_center@plt>
jmp    11a9 <execute_rudder_action+0x69>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ed <execute_rudder_action+0xad>
cmpl   $0x0,-0xc(%rbp)
jne    11c6 <execute_rudder_action+0x86>
mov    $0x0,%al
call   1060 <rudder_right@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11d7 <execute_rudder_action+0x97>
mov    $0x0,%al
call   1040 <rudder_center@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11e8 <execute_rudder_action+0xa8>
mov    $0x0,%al
call   1060 <rudder_right@plt>
jmp    11ed <execute_rudder_action+0xad>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1231 <execute_rudder_action+0xf1>
cmpl   $0x0,-0xc(%rbp)
jne    120a <execute_rudder_action+0xca>
mov    $0x0,%al
call   1050 <rudder_left@plt>
cmpl   $0x0,-0xc(%rbp)
jle    121b <execute_rudder_action+0xdb>
mov    $0x0,%al
call   1050 <rudder_left@plt>
cmpl   $0x0,-0xc(%rbp)
jge    122c <execute_rudder_action+0xec>
mov    $0x0,%al
call   1040 <rudder_center@plt>
jmp    1231 <execute_rudder_action+0xf1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_rudder_action>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
sub    %esi,%edi
call   1030 <calc_rudder_gain@plt>
cmp    %ebp,%ebx
jne    115f <execute_rudder_action+0x1f>
xor    %eax,%eax
call   1040 <rudder_center@plt>
jmp    116f <execute_rudder_action+0x2f>
jle    116f <execute_rudder_action+0x2f>
test   %r14d,%r14d
je     1168 <execute_rudder_action+0x28>
jg     1156 <execute_rudder_action+0x16>
xor    %eax,%eax
call   1060 <rudder_right@plt>
cmp    %ebp,%ebx
jge    1185 <execute_rudder_action+0x45>
test   %r14d,%r14d
je     117a <execute_rudder_action+0x3a>
jle    118a <execute_rudder_action+0x4a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <rudder_left@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <rudder_center@plt>

LLVM IR (-O0):
define void @execute_rudder_action(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = sub nsw i32 %9, %10
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = call i32 @calc_rudder_gain(i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %33
17: ; preds = %3
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (...) @rudder_center()
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @rudder_center()
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (...) @rudder_center()
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %3
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %53
37: ; preds = %33
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (...) @rudder_right()
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* %6
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 (...) @rudder_center()
br label %47
47: ; preds = %45, %42
%48 = load i32, i32* %6
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (...) @rudder_right()
br label %52
52: ; preds = %50, %47
br label %53
53: ; preds = %52, %33
%54 = load i32, i32* %5
%55 = load i32, i32* %4
%56 = icmp sgt i32 %54, %55
br i1 %56, label %57, label %73
57: ; preds = %53
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 (...) @rudder_left()
br label %62
62: ; preds = %60, %57
%63 = load i32, i32* %6
%64 = icmp sgt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 (...) @rudder_left()
br label %67
67: ; preds = %65, %62
%68 = load i32, i32* %6
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (...) @rudder_center()
br label %72
72: ; preds = %70, %67
br label %73
73: ; preds = %72, %53
ret void
}

LLVM IR (-O2):
define void @execute_rudder_action(i32 %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %0, %1
%5 = tail call i32 @calc_rudder_gain(i32 %4)
%6 = icmp eq i32 %0, %1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (...) @rudder_center()
br label %21
9: ; preds = %3
%10 = icmp sgt i32 %0, %1
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 (...) @rudder_right()
br label %21
15: ; preds = %11
%16 = icmp sgt i32 %2, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (...) @rudder_center()
br label %21
19: ; preds = %15
%20 = tail call i32 (...) @rudder_right()
br label %21
21: ; preds = %7, %17, %13, %19, %9
%22 = icmp slt i32 %0, %1
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = icmp eq i32 %2, 0
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = tail call i32 (...) @rudder_left()
br label %33
27: ; preds = %23
%28 = icmp sgt i32 %2, 0
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = tail call i32 (...) @rudder_left()
br label %33
31: ; preds = %27
%32 = tail call i32 (...) @rudder_center()
br label %33
33: ; preds = %29, %25, %31, %21
ret void
}