#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*/ PCA9685SetOffTime(int, int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ round(float);
void setPwmValue(int ch, float perc) {
  if (perc > 100)
    exit(1);
  float tonMs = 0.48f + 0.02f * perc;
  float tonPerc = tonMs / 20 * 100;
  int tonDec = (int)round(40.96f * tonPerc);
  int chPin = ch;
  if (chPin >= 8)
    chPin -= 8;
  float delayTimeMs = 2.5f * chPin;
  int delayTimePerc = delayTimeMs / 20 * 100;
  long delayTimeReg = (long)round(40.96f * delayTimePerc);
  if (delayTimeReg > 0)
    delayTimeReg -= 1;
  long tOffDec = tonDec + delayTimeReg;
  int offRegL = (int)(tOffDec & 0xff);
  int offRegH = (int)(tOffDec >> 8);
  PCA9685SetOffTime(ch, offRegL, offRegH);
}


x86 assembly (clang, -O0):
<setPwmValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  0xeb3(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1160 <setPwmValue+0x30>
mov    $0x1,%edi
call   1050 <exit@plt>
movss  -0x8(%rbp),%xmm0
movss  0xe9f(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe97(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe79(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe65(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xe58(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
call   1030 <round@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jl     11d2 <setPwmValue+0xa2>
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x18(%rbp)
cvtsi2ssl -0x18(%rbp),%xmm1
movss  0xe35(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe13(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xdff(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
cvtsi2ssl -0x20(%rbp),%xmm1
movss  0xdeb(%rip),%xmm0
mulss  %xmm1,%xmm0
call   1030 <round@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    123d <setPwmValue+0x10d>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0xff,%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
sar    $0x8,%rax
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1040 <PCA9685SetOffTime@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setPwmValue>:
push   %r14
push   %rbx
push   %rax
ucomiss 0xec5(%rip),%xmm0
ja     11d5 <setPwmValue+0xa5>
mov    %edi,%ebx
mulss  0xeb9(%rip),%xmm0
addss  0xeb5(%rip),%xmm0
divss  0xeb1(%rip),%xmm0
mulss  0xe9d(%rip),%xmm0
mulss  0xea5(%rip),%xmm0
call   1030 <round@plt>
lea    -0x8(%rbx),%ecx
cmp    $0x8,%ebx
cmovl  %ebx,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
mov    %rax,%r14
mulss  0xe89(%rip),%xmm0
divss  0xe79(%rip),%xmm0
mulss  0xe65(%rip),%xmm0
cvttps2dq %xmm0,%xmm0
cvtdq2ps %xmm0,%xmm0
mulss  0xe66(%rip),%xmm0
call   1030 <round@plt>
xor    %ecx,%ecx
test   %rax,%rax
setg   %cl
movslq %r14d,%rdx
add    %rax,%rdx
sub    %rcx,%rdx
movzbl %dl,%esi
shr    $0x8,%rdx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <PCA9685SetOffTime@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @setPwmValue(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %3
store float %1, float* %4
%15 = load float, float* %4
%16 = fcmp ogt float %15, 1.000000e+02
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load float, float* %4
%21 = call float @llvm.fmuladd.f32(float 0x3F947AE140000000, float %20, float 0x3FDEB851E0000000)
store float %21, float* %5
%22 = load float, float* %5
%23 = fdiv float %22, 2.000000e+01
%24 = fmul float %23, 1.000000e+02
store float %24, float* %6
%25 = load float, float* %6
%26 = fmul float 0x40447AE140000000, %25
%27 = call i64 @round(float %26)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
%29 = load i32, i32* %3
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp sge i32 %30, 8
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 8
store i32 %34, i32* %8
br label %35
35: ; preds = %32, %19
%36 = load i32, i32* %8
%37 = sitofp i32 %36 to float
%38 = fmul float 2.500000e+00, %37
store float %38, float* %9
%39 = load float, float* %9
%40 = fdiv float %39, 2.000000e+01
%41 = fmul float %40, 1.000000e+02
%42 = fptosi float %41 to i32
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = sitofp i32 %43 to float
%45 = fmul float 0x40447AE140000000, %44
%46 = call i64 @round(float %45)
store i64 %46, i64* %11
%47 = load i64, i64* %11
%48 = icmp sgt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %35
%50 = load i64, i64* %11
%51 = sub nsw i64 %50, 1
store i64 %51, i64* %11
br label %52
52: ; preds = %49, %35
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = load i64, i64* %11
%56 = add nsw i64 %54, %55
store i64 %56, i64* %12
%57 = load i64, i64* %12
%58 = and i64 %57, 255
%59 = trunc i64 %58 to i32
store i32 %59, i32* %13
%60 = load i64, i64* %12
%61 = ashr i64 %60, 8
%62 = trunc i64 %61 to i32
store i32 %62, i32* %14
%63 = load i32, i32* %3
%64 = load i32, i32* %13
%65 = load i32, i32* %14
%66 = call i32 @PCA9685SetOffTime(i32 %63, i32 %64, i32 %65)
ret void
}

LLVM IR (-O2):
define void @setPwmValue(i32 %0, float %1) {
%3 = fcmp ogt float %1, 1.000000e+02
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %2
%7 = tail call float @llvm.fmuladd.f32(float %1, float 0x3F947AE140000000, float 0x3FDEB851E0000000)
%8 = fdiv float %7, 2.000000e+01
%9 = fmul float %8, 1.000000e+02
%10 = fmul float %9, 0x40447AE140000000
%11 = tail call i64 @round(float %10)
%12 = icmp sgt i32 %0, 7
%13 = add nsw i32 %0, -8
%14 = select i1 %12, i32 %13, i32 %0
%15 = sitofp i32 %14 to float
%16 = fmul float %15, 2.500000e+00
%17 = fdiv float %16, 2.000000e+01
%18 = fmul float %17, 1.000000e+02
%19 = fptosi float %18 to i32
%20 = sitofp i32 %19 to float
%21 = fmul float %20, 0x40447AE140000000
%22 = tail call i64 @round(float %21)
%23 = icmp sgt i64 %22, 0
%24 = sext i1 %23 to i64
%25 = shl i64 %11, 32
%26 = ashr exact i64 %25, 32
%27 = add i64 %26, %22
%28 = add i64 %27, %24
%29 = trunc i64 %28 to i32
%30 = and i32 %29, 255
%31 = lshr i64 %28, 8
%32 = trunc i64 %31 to i32
%33 = tail call i32 @PCA9685SetOffTime(i32 %0, i32 %30, i32 %32)
ret void
}