#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);
void PWMPulseWidthSet(unsigned long ulBase, unsigned long ulPWMOut,
                      unsigned long ulWidth) {
  unsigned long ulGenBase, ulReg;
  DEBUG_ASSERT((ulBase == 0x40028000) || (ulBase == 0x40029000));
  DEBUG_ASSERT(PWMOutValid(ulPWMOut));
  ulGenBase = ((ulBase) + ((ulPWMOut)&0xFFFFFFC0));
  if ((*((volatile unsigned long *)(ulGenBase + 0x00000000))) & 0x00000002) {
    ulWidth /= 2;
  }
  ulReg = (*((volatile unsigned long *)(ulGenBase + 0x00000010)));
  DEBUG_ASSERT(ulWidth < ulReg);
  ulReg = ulReg - ulWidth;
  if (((ulPWMOut)&0x00000001)) {
    (*((volatile unsigned long *)(ulGenBase + 0x0000001C))) = ulReg;
  } else {
    (*((volatile unsigned long *)(ulGenBase + 0x00000018))) = ulReg;
  }
}


x86 assembly (clang, -O0):
<PWMPulseWidthSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x40028000,-0x8(%rbp)
40
mov    %al,-0x29(%rbp)
je     1155 <PWMPulseWidthSet+0x35>
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,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11ac <PWMPulseWidthSet+0x8c>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <DEBUG_ASSERT@plt>
mov    -0x28(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11fc <PWMPulseWidthSet+0xdc>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x1c(%rax)
jmp    1208 <PWMPulseWidthSet+0xe8>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
add    $0x30,%rsp
pop    %rbp
ret

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

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

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