#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);
void PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
                      uint32_t ui32Width) {
  uint32_t ui32GenBase, ui32Reg;
  ASSERT((ui32Base == 0x40028000) || (ui32Base == 0x40029000));
  ASSERT(_PWMOutValid(ui32PWMOut));
  ui32GenBase = ((ui32Base) + ((ui32PWMOut)&0xFFFFFFC0));
  if ((*((volatile uint32_t *)(ui32GenBase + 0x00000000))) & 0x00000002) {
    ui32Width /= 2;
  }
  ui32Reg = (*((volatile uint32_t *)(ui32GenBase + 0x00000010)));
  ASSERT(ui32Width < ui32Reg);
  ui32Reg = ui32Reg - ui32Width;
  if (((ui32PWMOut)&0x00000001)) {
    (*((volatile uint32_t *)(ui32GenBase + 0x0000001C))) = ui32Reg;
  } else {
    (*((volatile uint32_t *)(ui32GenBase + 0x00000018))) = ui32Reg;
  }
}


x86 assembly (clang, -O0):
<PWMPulseWidthSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x40028000,-0x4(%rbp)
mov    %al,-0x15(%rbp)
je     1150 <PWMPulseWidthSet+0x30>
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,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x0,%eax
cltq
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     119e <PWMPulseWidthSet+0x7e>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11e8 <PWMPulseWidthSet+0xc8>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
add    $0x1c,%eax
cltq
mov    %ecx,(%rax)
jmp    11f5 <PWMPulseWidthSet+0xd5>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
add    $0x18,%eax
cltq
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMPulseWidthSet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
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,%r15
testl  $0x2,(%r15)
je     1174 <PWMPulseWidthSet+0x54>
mov    %r14d,%eax
shr    $0x1f,%eax
add    %r14d,%eax
sar    %eax
mov    %eax,%r14d
mov    0x10(%r15),%ebp
xor    %edi,%edi
sub    %r14d,%ebp
setg   %dil
call   1040 <ASSERT@plt>
and    $0x1,%ebx
lea    0x18(,%rbx,4),%eax
mov    %ebp,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @PWMPulseWidthSet(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* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1073905664
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = icmp eq i32 %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 @ASSERT(i32 %16)
%18 = load i32, i32* %5
%19 = call i32 @_PWMOutValid(i32 %18)
%20 = call i32 @ASSERT(i32 %19)
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = and i32 %22, -64
%24 = add i32 %21, %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 0
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = load volatile i32, i32* %28
%30 = and i32 %29, 2
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %14
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 2
store i32 %34, i32* %6
br label %35
35: ; preds = %32, %14
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 16
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i32*
%40 = load volatile i32, i32* %39
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
%44 = zext i1 %43 to i32
%45 = call i32 @ASSERT(i32 %44)
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = sub nsw i32 %46, %47
store i32 %48, i32* %8
%49 = load i32, i32* %5
%50 = and i32 %49, 1
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %35
%53 = load i32, i32* %8
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 28
%56 = sext i32 %55 to i64
%57 = inttoptr i64 %56 to i32*
store volatile i32 %53, i32* %57
br label %64
58: ; preds = %35
%59 = load i32, i32* %8
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 24
%62 = sext i32 %61 to i64
%63 = inttoptr i64 %62 to i32*
store volatile i32 %59, i32* %63
br label %64
64: ; preds = %58, %52
ret void
}

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