#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 */
typedef int uint32_t;
typedef scalar_t__ ui32PWMOut;
typedef int ui32Base;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
int _PWMOutValid(int);
uint32_t PWMPulseWidthGet(uint32_t ui32Base, uint32_t ui32PWMOut) {
  uint32_t ui32GenBase, ui32Reg, ui32Load;
  ASSERT((ui32Base == 0x40028000) || (ui32Base == 0x40029000));
  ASSERT(_PWMOutValid(ui32PWMOut));
  ui32GenBase = ((ui32Base) + ((ui32PWMOut)&0xFFFFFFC0));
  ui32Load = (*((volatile uint32_t *)(ui32GenBase + 0x00000010)));
  if (((ui32PWMOut)&0x00000001)) {
    ui32Reg = (*((volatile uint32_t *)(ui32GenBase + 0x0000001C)));
  } else {
    ui32Reg = (*((volatile uint32_t *)(ui32GenBase + 0x00000018)));
  }
  ui32Reg = ui32Load - ui32Reg;
  if ((*((volatile uint32_t *)(ui32GenBase + 0x00000000))) & 0x00000002) {
    ui32Reg = ui32Reg * 2;
  }
  return (ui32Reg);
}


x86 assembly (clang, -O0):
<PWMPulseWidthGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x1,%al
cmpl   $0x40028000,-0x4(%rbp)
mov    %al,-0x15(%rbp)
je     114d <PWMPulseWidthGet+0x2d>
cmpl   $0x40029000,-0x4(%rbp)
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0x8(%rbp),%edi
call   1030 <_PWMOutValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
and    $0xffffffc0,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11a5 <PWMPulseWidthGet+0x85>
mov    -0xc(%rbp),%eax
add    $0x1c,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    11b2 <PWMPulseWidthGet+0x92>
mov    -0xc(%rbp),%eax
add    $0x18,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x0,%eax
cltq
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11da <PWMPulseWidthGet+0xba>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMPulseWidthGet>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edi,%eax
and    $0xffffefff,%eax
xor    %edi,%edi
cmp    $0x40028000,%eax
sete   %dil
call   1040 <ASSERT@plt>
mov    %ebx,%edi
call   1030 <_PWMOutValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
mov    %ebx,%eax
and    $0xffffffc0,%eax
add    %ebp,%eax
movslq %eax,%rcx
mov    0x10(%rcx),%eax
and    $0x1,%ebx
lea    0x18(,%rbx,4),%edx
sub    (%rdx,%rcx,1),%eax
mov    (%rcx),%ecx
shr    %cl
and    $0x1,%cl
shl    %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @PWMPulseWidthGet(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1073905664
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 1073909760
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ true, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @ASSERT(i32 %15)
%17 = load i32, i32* %4
%18 = call i32 @_PWMOutValid(i32 %17)
%19 = call i32 @ASSERT(i32 %18)
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = and i32 %21, -64
%23 = add i32 %20, %22
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 16
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = load volatile i32, i32* %27
store i32 %28, i32* %7
%29 = load i32, i32* %4
%30 = and i32 %29, 1
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %13
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 28
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
%37 = load volatile i32, i32* %36
store i32 %37, i32* %6
br label %44
38: ; preds = %13
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 24
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i32*
%43 = load volatile i32, i32* %42
store i32 %43, i32* %6
br label %44
44: ; preds = %38, %32
%45 = load i32, i32* %7
%46 = load i32, i32* %6
%47 = sub nsw i32 %45, %46
store i32 %47, i32* %6
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 0
%50 = sext i32 %49 to i64
%51 = inttoptr i64 %50 to i32*
%52 = load volatile i32, i32* %51
%53 = and i32 %52, 2
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %44
%56 = load i32, i32* %6
%57 = mul nsw i32 %56, 2
store i32 %57, i32* %6
br label %58
58: ; preds = %55, %44
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
define i32 @PWMPulseWidthGet(i32 %0, i32 %1) {
%3 = and i32 %0, -4097
%4 = icmp eq i32 %3, 1073905664
%5 = zext i1 %4 to i32
%6 = tail call i32 @ASSERT(i32 %5)
%7 = tail call i32 @_PWMOutValid(i32 %1)
%8 = tail call i32 @ASSERT(i32 %7)
%9 = and i32 %1, -64
%10 = add i32 %9, %0
%11 = add nsw i32 %10, 16
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load volatile i32, i32* %13
%15 = and i32 %1, 1
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 24, i32 28
%18 = add nsw i32 %17, %10
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = load volatile i32, i32* %20
%22 = sub nsw i32 %14, %21
%23 = sext i32 %10 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load volatile i32, i32* %24
%26 = lshr i32 %25, 1
%27 = and i32 %26, 1
%28 = shl nsw i32 %22, %27
ret i32 %28
}