#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_getPwmDuty(int, int);
int bbb_getPwmPeriod(int, int);
int bbb_getPwmPercent(int header, int pin) {
  static int ret = -1;
  if (header > 0 && pin > 0) {
    int period = bbb_getPwmPeriod(header, pin);
    int duty = bbb_getPwmDuty(header, pin);
    ret = ((duty * 100) / period);
  }
  return ret;
}


x86 assembly (clang, -O0):
<bbb_getPwmPercent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    116c <bbb_getPwmPercent+0x4c>
cmpl   $0x0,-0x8(%rbp)
jle    116c <bbb_getPwmPercent+0x4c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <bbb_getPwmPeriod@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <bbb_getPwmDuty@plt>
mov    %eax,-0x10(%rbp)
imul   $0x64,-0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,0x2ec4(%rip)
mov    0x2ebe(%rip),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_getPwmPercent>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1152 <bbb_getPwmPercent+0x32>
mov    %esi,%ebx
test   %esi,%esi
jle    1152 <bbb_getPwmPercent+0x32>
mov    %edi,%ebp
mov    %ebx,%esi
call   1030 <bbb_getPwmPeriod@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <bbb_getPwmDuty@plt>
imul   $0x64,%eax,%eax
cltd
idiv   %r14d
mov    %eax,0x2ee0(%rip)
jmp    1158 <bbb_getPwmPercent+0x38>
mov    0x2ed8(%rip),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@bbb_getPwmPercent.ret = internal global i32 -1
define i32 @bbb_getPwmPercent(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @bbb_getPwmPeriod(i32 %13, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @bbb_getPwmDuty(i32 %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = mul nsw i32 %19, 100
%21 = load i32, i32* %5
%22 = sdiv i32 %20, %21
store i32 %22, i32* @bbb_getPwmPercent.ret
br label %23
23: ; preds = %12, %9, %2
%24 = load i32, i32* @bbb_getPwmPercent.ret
ret i32 %24
}

LLVM IR (-O2):
@bbb_getPwmPercent.ret = internal unnamed_addr global i32 -1
define i32 @bbb_getPwmPercent(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 0
%4 = icmp sgt i32 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @bbb_getPwmPercent.ret
br label %13
8: ; preds = %2
%9 = tail call i32 @bbb_getPwmPeriod(i32 %0, i32 %1)
%10 = tail call i32 @bbb_getPwmDuty(i32 %0, i32 %1)
%11 = mul nsw i32 %10, 100
%12 = sdiv i32 %11, %9
store i32 %12, i32* @bbb_getPwmPercent.ret
br label %13
13: ; preds = %6, %8
%14 = phi i32 [ %7, %6 ], [ %12, %8 ]
ret i32 %14
}