#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*/ PCA9685SetOnTime(int, int, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ round(float);
void pwmTonStartTime(int ch) {
  int chPin = ch;
  if (chPin >= 8)
    chPin -= 8;
  float delayTimeMs = 2.5f * chPin;
  printf("Delay time ms       = %f\n\r", delayTimeMs);
  int delayTimePerc = delayTimeMs / 20 * 100;
  printf("Delay time %%        = %d\n\r", delayTimePerc);
  long delayTimeReg = (long)round(40.96f * delayTimePerc);
  if (delayTimeReg > 0)
    delayTimeReg -= 1;
  int onRegL = (int)(delayTimeReg & 0xff);
  int onRegH = (int)(delayTimeReg >> 8);
  printf("Delay time Reg      = 0x%04x\n\r", delayTimeReg);
  printf("Delay time Reg Low  = 0x%02x\n\r", onRegL);
  printf("Delay time Reg High = 0x%02x\n\r", onRegH);
  PCA9685SetOnTime(ch, onRegL, onRegH);
}


x86 assembly (clang, -O0):
<pwmTonStartTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jl     1154 <pwmTonStartTime+0x24>
mov    -0x8(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x8(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm1
movss  0xeab(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
cvttss2si -0xc(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
movss  0xe80(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe70(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
cvtsi2ssl -0x10(%rbp),%xmm1
movss  0xe45(%rip),%xmm0
mulss  %xmm1,%xmm0
call   1050 <round@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11df <pwmTonStartTime+0xaf>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0xff,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
sar    $0x8,%rax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <PCA9685SetOnTime@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwmTonStartTime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    -0x8(%r14),%eax
cmp    $0x8,%edi
cmovl  %edi,%eax
cvtsi2ss %eax,%xmm0
mulss  0xeaf(%rip),%xmm0
movaps %xmm0,(%rsp)
cvttss2si %xmm0,%esi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movaps (%rsp),%xmm0
divss  0xe93(%rip),%xmm0
mulss  0xe8f(%rip),%xmm0
movaps %xmm0,(%rsp)
cvttss2si %xmm0,%esi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
cvttps2dq (%rsp),%xmm0
cvtdq2ps %xmm0,%xmm0
mulss  0xe6f(%rip),%xmm0
call   1050 <round@plt>
xor    %ecx,%ecx
test   %rax,%rax
setg   %cl
sub    %rcx,%rax
movzbl %al,%ebp
mov    %rax,%rbx
shr    $0x8,%rbx
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <PCA9685SetOnTime@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Delay time ms = %f\0A\0D\00"
@.str.1 = [28 x i8] c"Delay time %% = %d\0A\0D\00"
@.str.2 = [31 x i8] c"Delay time Reg = 0x%04x\0A\0D\00"
@.str.3 = [31 x i8] c"Delay time Reg Low = 0x%02x\0A\0D\00"
@.str.4 = [31 x i8] c"Delay time Reg High = 0x%02x\0A\0D\00"
define void @pwmTonStartTime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* %2
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 8
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 8
store i32 %14, i32* %3
br label %15
15: ; preds = %12, %1
%16 = load i32, i32* %3
%17 = sitofp i32 %16 to float
%18 = fmul float 2.500000e+00, %17
store float %18, float* %4
%19 = load float, float* %4
%20 = fptosi float %19 to i32
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load float, float* %4
%23 = fdiv float %22, 2.000000e+01
%24 = fmul float %23, 1.000000e+02
%25 = fptosi float %24 to i32
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %5
%29 = sitofp i32 %28 to float
%30 = fmul float 0x40447AE140000000, %29
%31 = call i64 @round(float %30)
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %15
%35 = load i64, i64* %6
%36 = sub nsw i64 %35, 1
store i64 %36, i64* %6
br label %37
37: ; preds = %34, %15
%38 = load i64, i64* %6
%39 = and i64 %38, 255
%40 = trunc i64 %39 to i32
store i32 %40, i32* %7
%41 = load i64, i64* %6
%42 = ashr i64 %41, 8
%43 = trunc i64 %42 to i32
store i32 %43, i32* %8
%44 = load i64, i64* %6
%45 = trunc i64 %44 to i32
%46 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %7
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %8
%50 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %2
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @PCA9685SetOnTime(i32 %51, i32 %52, i32 %53)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Delay time ms = %f\0A\0D\00"
@.str.1 = [28 x i8] c"Delay time %% = %d\0A\0D\00"
@.str.2 = [31 x i8] c"Delay time Reg = 0x%04x\0A\0D\00"
@.str.3 = [31 x i8] c"Delay time Reg Low = 0x%02x\0A\0D\00"
@.str.4 = [31 x i8] c"Delay time Reg High = 0x%02x\0A\0D\00"
define void @pwmTonStartTime(i32 %0) {
%2 = icmp sgt i32 %0, 7
%3 = add nsw i32 %0, -8
%4 = select i1 %2, i32 %3, i32 %0
%5 = sitofp i32 %4 to float
%6 = fmul float %5, 2.500000e+00
%7 = fptosi float %6 to i32
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = fdiv float %6, 2.000000e+01
%10 = fmul float %9, 1.000000e+02
%11 = fptosi float %10 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = sitofp i32 %11 to float
%14 = fmul float %13, 0x40447AE140000000
%15 = tail call i64 @round(float %14)
%16 = icmp sgt i64 %15, 0
%17 = sext i1 %16 to i64
%18 = add nsw i64 %15, %17
%19 = trunc i64 %18 to i32
%20 = and i32 %19, 255
%21 = lshr i64 %18, 8
%22 = trunc i64 %21 to i32
%23 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%26 = tail call i32 @PCA9685SetOnTime(i32 %0, i32 %20, i32 %22)
ret void
}