#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 scalar_t__ ulPWMOut;
typedef unsigned long ulBase;

/* Variables and functions */
int /*<<< orphan*/ DEBUG_ASSERT(int);
int PWMOutValid(unsigned long);
unsigned long PWMPulseWidthGet(unsigned long ulBase, unsigned long ulPWMOut) {
  unsigned long ulGenBase, ulReg, ulLoad;
  DEBUG_ASSERT((ulBase == 0x40028000) || (ulBase == 0x40029000));
  DEBUG_ASSERT(PWMOutValid(ulPWMOut));
  ulGenBase = ((ulBase) + ((ulPWMOut)&0xFFFFFFC0));
  ulLoad = (*((volatile unsigned long *)(ulGenBase + 0x00000010)));
  if (((ulPWMOut)&0x00000001)) {
    ulReg = (*((volatile unsigned long *)(ulGenBase + 0x0000001C)));
  } else {
    ulReg = (*((volatile unsigned long *)(ulGenBase + 0x00000018)));
  }
  ulReg = ulLoad - ulReg;
  if ((*((volatile unsigned long *)(ulGenBase + 0x00000000))) & 0x00000002) {
    ulReg = ulReg * 2;
  }
  return (ulReg);
}


x86 assembly (clang, -O0):
<PWMPulseWidthGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%al
cmpq   $0x40028000,-0x8(%rbp)
40
mov    %al,-0x29(%rbp)
je     1151 <PWMPulseWidthGet+0x31>
cmpq   $0x40029000,-0x8(%rbp)
40
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rdi
call   1030 <PWMOutValid@plt>
mov    %eax,%edi
call   1040 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rax
movabs $0xffffffc0,%rcx
and    -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11b6 <PWMPulseWidthGet+0x96>
mov    -0x18(%rbp),%rax
mov    0x1c(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11c2 <PWMPulseWidthGet+0xa2>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11ef <PWMPulseWidthGet+0xcf>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMPulseWidthGet>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rdi,%rax
and    $0xffffffffffffefff,%rax
xor    %edi,%edi
cmp    $0x40028000,%rax
sete   %dil
call   1040 <DEBUG_ASSERT@plt>
mov    %rbx,%rdi
call   1030 <PWMOutValid@plt>
mov    %eax,%edi
call   1040 <DEBUG_ASSERT@plt>
mov    %ebx,%ecx
and    $0xffffffc0,%ecx
lea    (%rcx,%r14,1),%rdx
mov    0x10(%rcx,%r14,1),%rax
and    $0x1,%ebx
sub    0x18(%rdx,%rbx,4),%rax
mov    (%rcx,%r14,1),%rcx
shr    %cl
and    $0x1,%cl
shl    %cl,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @PWMPulseWidthGet(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 1073905664
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i64, i64* %3
%12 = icmp eq i64 %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 @DEBUG_ASSERT(i32 %15)
%17 = load i64, i64* %4
%18 = call i32 @PWMOutValid(i64 %17)
%19 = call i32 @DEBUG_ASSERT(i32 %18)
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = and i64 %21, 4294967232
%23 = add i64 %20, %22
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = add i64 %24, 16
%26 = inttoptr i64 %25 to i64*
%27 = load volatile i64, i64* %26
store i64 %27, i64* %7
%28 = load i64, i64* %4
%29 = and i64 %28, 1
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %13
%32 = load i64, i64* %5
%33 = add i64 %32, 28
%34 = inttoptr i64 %33 to i64*
%35 = load volatile i64, i64* %34
store i64 %35, i64* %6
br label %41
36: ; preds = %13
%37 = load i64, i64* %5
%38 = add i64 %37, 24
%39 = inttoptr i64 %38 to i64*
%40 = load volatile i64, i64* %39
store i64 %40, i64* %6
br label %41
41: ; preds = %36, %31
%42 = load i64, i64* %7
%43 = load i64, i64* %6
%44 = sub i64 %42, %43
store i64 %44, i64* %6
%45 = load i64, i64* %5
%46 = add i64 %45, 0
%47 = inttoptr i64 %46 to i64*
%48 = load volatile i64, i64* %47
%49 = and i64 %48, 2
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %41
%52 = load i64, i64* %6
%53 = mul i64 %52, 2
store i64 %53, i64* %6
br label %54
54: ; preds = %51, %41
%55 = load i64, i64* %6
ret i64 %55
}

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