#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 /*<<< orphan*/ printf(char *, ...);
int rc_send_servo_pulse_us(int, float);
int rc_send_servo_pulse_normalized(int ch, float input) {
  if (ch < 1 || ch > 8) {
    printf("ERROR: Servo Channel must be between 1&%d\n", 8);
    return -1;
  }
  if (input < -1.5 || input > 1.5) {
    printf("ERROR: normalized input must be between -1 & 1\n");
    return -1;
  }
  float micros = 1500 + (input * (1200 / 2));
  return rc_send_servo_pulse_us(ch, micros);
}


x86 assembly (clang, -O0):
<rc_send_servo_pulse_normalized>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1144 <rc_send_servo_pulse_normalized+0x24>
cmpl   $0x8,-0x8(%rbp)
jle    1163 <rc_send_servo_pulse_normalized+0x43>
lea    0xecd(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <rc_send_servo_pulse_normalized+0xc5>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe8c(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1199 <rc_send_servo_pulse_normalized+0x79>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b3 <rc_send_servo_pulse_normalized+0x93>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <rc_send_servo_pulse_normalized+0xc5>
movss  -0xc(%rbp),%xmm0
movss  0xe50(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe48(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
movss  -0x10(%rbp),%xmm0
call   1040 <rc_send_servo_pulse_us@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_send_servo_pulse_normalized>:
push   %rax
lea    -0x9(%rdi),%eax
cmp    $0xfffffff7,%eax
ja     114e <rc_send_servo_pulse_normalized+0x1e>
lea    0xed0(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1186 <rc_send_servo_pulse_normalized+0x56>
movss  0xeaa(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     117a <rc_send_servo_pulse_normalized+0x4a>
ucomiss 0xea2(%rip),%xmm0
ja     117a <rc_send_servo_pulse_normalized+0x4a>
mulss  0xe9c(%rip),%xmm0
addss  0xe98(%rip),%xmm0
pop    %rax
jmp    1050 <rc_send_servo_pulse_us@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"ERROR: Servo Channel must be between 1&%d\0A\00"
@.str.1 = [48 x i8] c"ERROR: normalized input must be between -1 & 1\0A\00"
define i32 @rc_send_servo_pulse_normalized(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
store i32 %0, i32* %4
store float %1, float* %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 8
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 8)
store i32 -1, i32* %3
br label %30
14: ; preds = %9
%15 = load float, float* %5
%16 = fpext float %15 to double
%17 = fcmp olt double %16, -1.500000e+00
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load float, float* %5
%20 = fpext float %19 to double
%21 = fcmp ogt double %20, 1.500000e+00
br i1 %21, label %22, label %24
22: ; preds = %18, %14
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
24: ; preds = %18
%25 = load float, float* %5
%26 = call float @llvm.fmuladd.f32(float %25, float 6.000000e+02, float 1.500000e+03)
store float %26, float* %6
%27 = load i32, i32* %4
%28 = load float, float* %6
%29 = call i32 @rc_send_servo_pulse_us(i32 %27, float %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %24, %22, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [43 x i8] c"ERROR: Servo Channel must be between 1&%d\0A\00"
@str = [47 x i8] c"ERROR: normalized input must be between -1 & 1\00"
define i32 @rc_send_servo_pulse_normalized(i32 %0, float %1) {
%3 = add i32 %0, -9
%4 = icmp ult i32 %3, -8
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 8)
br label %16
7: ; preds = %2
%8 = fcmp olt float %1, -1.500000e+00
%9 = fcmp ogt float %1, 1.500000e+00
%10 = or i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %16
13: ; preds = %7
%14 = tail call float @llvm.fmuladd.f32(float %1, float 6.000000e+02, float 1.500000e+03)
%15 = tail call i32 @rc_send_servo_pulse_us(i32 %0, float %14)
br label %16
16: ; preds = %13, %11, %5
%17 = phi i32 [ -1, %5 ], [ -1, %11 ], [ %15, %13 ]
ret i32 %17
}