#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 bbb_getPwmPeriod(int, int);
int bbb_setPwmDuty(int, int, int);
int bbb_setPwmPercent(int header, int pin, int duty) {
  int time = bbb_getPwmPeriod(header, pin);
  if (header > 0 && pin > 0 && duty >= 0 && duty <= 100) {
    return bbb_setPwmDuty(header, pin, ((time / 100) * duty));
  }
  return -1;
}


x86 assembly (clang, -O0):
<bbb_setPwmPercent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <bbb_getPwmPeriod@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    118b <bbb_setPwmPercent+0x6b>
cmpl   $0x0,-0xc(%rbp)
jle    118b <bbb_setPwmPercent+0x6b>
cmpl   $0x0,-0x10(%rbp)
jl     118b <bbb_setPwmPercent+0x6b>
cmpl   $0x64,-0x10(%rbp)
jg     118b <bbb_setPwmPercent+0x6b>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
imul   -0x10(%rbp),%edx
call   1040 <bbb_setPwmDuty@plt>
mov    %eax,-0x4(%rbp)
jmp    1192 <bbb_setPwmPercent+0x72>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_setPwmPercent>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
call   1030 <bbb_getPwmPeriod@plt>
cmp    $0x64,%r14d
ja     1165 <bbb_setPwmPercent+0x45>
test   %ebp,%ebp
jle    1165 <bbb_setPwmPercent+0x45>
test   %ebx,%ebx
jle    1165 <bbb_setPwmPercent+0x45>
cltq
imul   $0x51eb851f,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x25,%rdx
add    %eax,%edx
imul   %r14d,%edx
mov    %ebp,%edi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <bbb_setPwmDuty@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bbb_setPwmPercent(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* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @bbb_getPwmPeriod(i32 %9, i32 %10)
store i32 %11, i32* %8
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i32, i32* %7
%22 = icmp sle i32 %21, 100
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = sdiv i32 %26, 100
%28 = load i32, i32* %7
%29 = mul nsw i32 %27, %28
%30 = call i32 @bbb_setPwmDuty(i32 %24, i32 %25, i32 %29)
store i32 %30, i32* %4
br label %32
31: ; preds = %20, %17, %14, %3
store i32 -1, i32* %4
br label %32
32: ; preds = %31, %23
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @bbb_setPwmPercent(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @bbb_getPwmPeriod(i32 %0, i32 %1)
%5 = icmp sgt i32 %0, 0
%6 = icmp sgt i32 %1, 0
%7 = and i1 %5, %6
%8 = icmp ult i32 %2, 101
%9 = and i1 %8, %7
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = sdiv i32 %4, 100
%12 = mul nsw i32 %11, %2
%13 = tail call i32 @bbb_setPwmDuty(i32 %0, i32 %1, i32 %12)
br label %14
14: ; preds = %3, %10
%15 = phi i32 [ %13, %10 ], [ -1, %3 ]
ret i32 %15
}