#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);
scalar_t__ floor(float);
int calc_rudder_gain(int diff) {
  float gain;
  diff = abs(diff);
  if (diff > 90)
    diff = 90;
  if (diff < 10)
    gain = diff / 4;
  if (diff >= 10 && diff < 20)
    gain = diff / 3.5;
  if (diff >= 20 && diff < 30)
    gain = diff / 3;
  if (diff >= 30 && diff < 40)
    gain = diff / 2;
  if (diff >= 40 && diff < 50)
    gain = diff / 1.4;
  if (diff >= 50 && diff < 70)
    gain = diff / 1.3;
  if (diff >= 70 && diff < 90)
    gain = diff / 1.2;
  if (diff >= 90)
    gain = diff / 1.1;
  gain = gain / 1.8;
  return (int)floor(gain);
}


x86 assembly (clang, -O0):
<calc_rudder_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x5a,-0x4(%rbp)
jle    1147 <calc_rudder_gain+0x27>
movl   $0x5a,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    1165 <calc_rudder_gain+0x45>
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0xa,-0x4(%rbp)
jl     1193 <calc_rudder_gain+0x73>
cmpl   $0x14,-0x4(%rbp)
jge    1193 <calc_rudder_gain+0x73>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x14,-0x4(%rbp)
jl     11bb <calc_rudder_gain+0x9b>
cmpl   $0x1e,-0x4(%rbp)
jge    11bb <calc_rudder_gain+0x9b>
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x1e,-0x4(%rbp)
jl     11e3 <calc_rudder_gain+0xc3>
cmpl   $0x28,-0x4(%rbp)
jge    11e3 <calc_rudder_gain+0xc3>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x28,-0x4(%rbp)
jl     1211 <calc_rudder_gain+0xf1>
cmpl   $0x32,-0x4(%rbp)
jge    1211 <calc_rudder_gain+0xf1>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe04(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x32,-0x4(%rbp)
jl     123f <calc_rudder_gain+0x11f>
cmpl   $0x46,-0x4(%rbp)
jge    123f <calc_rudder_gain+0x11f>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xdde(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x46,-0x4(%rbp)
jl     126d <calc_rudder_gain+0x14d>
cmpl   $0x5a,-0x4(%rbp)
jge    126d <calc_rudder_gain+0x14d>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x5a,-0x4(%rbp)
jl     1291 <calc_rudder_gain+0x171>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xd9c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd86(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_rudder_gain>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
cmp    $0x5a,%ecx
mov    $0x5a,%eax
cmovb  %ecx,%eax
lea    -0xa(%rax),%ecx
cmp    $0x9,%ecx
ja     113c <calc_rudder_gain+0x2c>
cvtsi2sd %eax,%xmm0
divsd  0xeca(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
jmp    115b <calc_rudder_gain+0x4b>
lea    -0x14(%rax),%ecx
cmp    $0x9,%ecx
ja     1152 <calc_rudder_gain+0x42>
movzbl %al,%ecx
imul   $0xab,%ecx,%ecx
shr    $0x9,%ecx
jmp    1157 <calc_rudder_gain+0x47>
mov    %eax,%ecx
shr    $0x2,%ecx
cvtsi2ss %ecx,%xmm0
lea    -0x1e(%rax),%ecx
cmp    $0xa,%ecx
jae    116e <calc_rudder_gain+0x5e>
mov    %eax,%ecx
shr    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
lea    -0x28(%rax),%ecx
cmp    $0x9,%ecx
ja     1187 <calc_rudder_gain+0x77>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe9b(%rip),%xmm0
jmp    11cd <calc_rudder_gain+0xbd>
lea    -0x32(%rax),%ecx
cmp    $0x13,%ecx
ja     11a0 <calc_rudder_gain+0x90>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe7a(%rip),%xmm0
jmp    11cd <calc_rudder_gain+0xbd>
lea    -0x46(%rax),%ecx
cmp    $0x13,%ecx
ja     11b9 <calc_rudder_gain+0xa9>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe59(%rip),%xmm0
jmp    11cd <calc_rudder_gain+0xbd>
cmp    $0x5a,%eax
jb     11d1 <calc_rudder_gain+0xc1>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe3b(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
divsd  0xe4b(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
jmp    1030 <floor@plt>

LLVM IR (-O0):
define i32 @calc_rudder_gain(i32 %0) {
%2 = alloca i32
%3 = alloca float
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @abs(i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 90
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 90, i32* %2
br label %9
9: ; preds = %8, %1
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 4
%15 = sitofp i32 %14 to float
store float %15, float* %3
br label %16
16: ; preds = %12, %9
%17 = load i32, i32* %2
%18 = icmp sge i32 %17, 10
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 20
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %2
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 3.500000e+00
%26 = fptrunc double %25 to float
store float %26, float* %3
br label %27
27: ; preds = %22, %19, %16
%28 = load i32, i32* %2
%29 = icmp sge i32 %28, 20
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 30
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %2
%35 = sdiv i32 %34, 3
%36 = sitofp i32 %35 to float
store float %36, float* %3
br label %37
37: ; preds = %33, %30, %27
%38 = load i32, i32* %2
%39 = icmp sge i32 %38, 30
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 40
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* %2
%45 = sdiv i32 %44, 2
%46 = sitofp i32 %45 to float
store float %46, float* %3
br label %47
47: ; preds = %43, %40, %37
%48 = load i32, i32* %2
%49 = icmp sge i32 %48, 40
br i1 %49, label %50, label %58
50: ; preds = %47
%51 = load i32, i32* %2
%52 = icmp slt i32 %51, 50
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i32, i32* %2
%55 = sitofp i32 %54 to double
%56 = fdiv double %55, 1.400000e+00
%57 = fptrunc double %56 to float
store float %57, float* %3
br label %58
58: ; preds = %53, %50, %47
%59 = load i32, i32* %2
%60 = icmp sge i32 %59, 50
br i1 %60, label %61, label %69
61: ; preds = %58
%62 = load i32, i32* %2
%63 = icmp slt i32 %62, 70
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = load i32, i32* %2
%66 = sitofp i32 %65 to double
%67 = fdiv double %66, 1.300000e+00
%68 = fptrunc double %67 to float
store float %68, float* %3
br label %69
69: ; preds = %64, %61, %58
%70 = load i32, i32* %2
%71 = icmp sge i32 %70, 70
br i1 %71, label %72, label %80
72: ; preds = %69
%73 = load i32, i32* %2
%74 = icmp slt i32 %73, 90
br i1 %74, label %75, label %80
75: ; preds = %72
%76 = load i32, i32* %2
%77 = sitofp i32 %76 to double
%78 = fdiv double %77, 1.200000e+00
%79 = fptrunc double %78 to float
store float %79, float* %3
br label %80
80: ; preds = %75, %72, %69
%81 = load i32, i32* %2
%82 = icmp sge i32 %81, 90
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* %2
%85 = sitofp i32 %84 to double
%86 = fdiv double %85, 1.100000e+00
%87 = fptrunc double %86 to float
store float %87, float* %3
br label %88
88: ; preds = %83, %80
%89 = load float, float* %3
%90 = fpext float %89 to double
%91 = fdiv double %90, 1.800000e+00
%92 = fptrunc double %91 to float
store float %92, float* %3
%93 = load float, float* %3
%94 = call i64 @floor(float %93)
%95 = trunc i64 %94 to i32
ret i32 %95
}

LLVM IR (-O2):
define i32 @calc_rudder_gain(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = icmp ult i32 %2, 90
%4 = select i1 %3, i32 %2, i32 90
%5 = add nsw i32 %4, -10
%6 = icmp ult i32 %5, 10
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = sitofp i32 %4 to double
%9 = fdiv double %8, 3.500000e+00
%10 = fptrunc double %9 to float
br label %22
11: ; preds = %1
%12 = icmp ult i32 %4, 10
%13 = lshr i32 %4, 2
%14 = sitofp i32 %13 to float
%15 = select i1 %12, float %14, float undef
%16 = add nsw i32 %4, -20
%17 = icmp ult i32 %16, 10
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = trunc i32 %4 to i8
%20 = udiv i8 %19, 3
%21 = uitofp i8 %20 to float
br label %22
22: ; preds = %7, %18, %11
%23 = phi float [ %21, %18 ], [ %15, %11 ], [ %10, %7 ]
%24 = add nsw i32 %4, -30
%25 = icmp ult i32 %24, 10
%26 = lshr i32 %4, 1
%27 = sitofp i32 %26 to float
%28 = select i1 %25, float %27, float %23
%29 = add nsw i32 %4, -40
%30 = icmp ult i32 %29, 10
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = sitofp i32 %4 to double
%33 = fdiv double %32, 1.400000e+00
%34 = fptrunc double %33 to float
br label %55
35: ; preds = %22
%36 = add nsw i32 %4, -50
%37 = icmp ult i32 %36, 20
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = sitofp i32 %4 to double
%40 = fdiv double %39, 1.300000e+00
%41 = fptrunc double %40 to float
br label %55
42: ; preds = %35
%43 = add nsw i32 %4, -70
%44 = icmp ult i32 %43, 20
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = sitofp i32 %4 to double
%47 = fdiv double %46, 1.200000e+00
%48 = fptrunc double %47 to float
br label %55
49: ; preds = %42
%50 = icmp ugt i32 %4, 89
br i1 %50, label %51, label %55
51: ; preds = %49
%52 = sitofp i32 %4 to double
%53 = fdiv double %52, 1.100000e+00
%54 = fptrunc double %53 to float
br label %55
55: ; preds = %38, %31, %45, %51, %49
%56 = phi float [ %54, %51 ], [ %28, %49 ], [ %48, %45 ], [ %34, %31 ], [ %41, %38 ]
%57 = fpext float %56 to double
%58 = fdiv double %57, 1.800000e+00
%59 = fptrunc double %58 to float
%60 = tail call i64 @floor(float %59)
%61 = trunc i64 %60 to i32
ret i32 %61
}