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

/* Variables and functions */
int /*<<< orphan*/ DEBUG_ASSERT(int);
int PWMGenValid(unsigned long);
void PWMGenPeriodSet(unsigned long ulBase, unsigned long ulGen,
                     unsigned long ulPeriod) {
  DEBUG_ASSERT((ulBase == 0x40028000) || (ulBase == 0x40029000));
  DEBUG_ASSERT(PWMGenValid(ulGen));
  ulGen = ((ulBase) + (ulGen));
  if ((*((volatile unsigned long *)(ulGen + 0x00000000))) & 0x00000002) {
    DEBUG_ASSERT((ulPeriod / 2) < 65536);
    (*((volatile unsigned long *)(ulGen + 0x00000010))) = ulPeriod / 2;
  } else {
    DEBUG_ASSERT((ulPeriod <= 65536) && (ulPeriod != 0));
    (*((volatile unsigned long *)(ulGen + 0x00000010))) = ulPeriod - 1;
  }
}


x86 assembly (clang, -O0):
<PWMGenPeriodSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x40028000,-0x8(%rbp)
40
mov    %al,-0x19(%rbp)
je     1155 <PWMGenPeriodSet+0x35>
cmpq   $0x40029000,-0x8(%rbp)
40
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rdi
call   1040 <PWMGenValid@plt>
mov    %eax,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11c3 <PWMGenPeriodSet+0xa3>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
cmp    $0x10000,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x18(%rbp),%rcx
shr    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    11fe <PWMGenPeriodSet+0xde>
xor    %eax,%eax
cmpq   $0x10000,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
ja     11e1 <PWMGenPeriodSet+0xc1>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMGenPeriodSet>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdi,%rax
and    $0xffffffffffffefff,%rax
xor    %edi,%edi
cmp    $0x40028000,%rax
sete   %dil
call   1030 <DEBUG_ASSERT@plt>
mov    %r14,%rdi
call   1040 <PWMGenValid@plt>
mov    %eax,%edi
call   1030 <DEBUG_ASSERT@plt>
lea    -0x1(%r12),%rax
xor    %ecx,%ecx
cmp    $0x10000,%rax
setb   %cl
mov    %r12,%rbx
shr    %rbx
xor    %edx,%edx
cmp    $0x20000,%r12
setb   %dl
testq  $0x2,(%r14,%r15,1)
cmovne %edx,%ecx
cmove  %rax,%rbx
movzbl %cl,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    %rbx,0x10(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @PWMGenPeriodSet(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 @PWMGenValid(i64 %1)
%9 = tail call i32 @DEBUG_ASSERT(i32 %8)
%10 = add i64 %1, %0
%11 = inttoptr i64 %10 to i64*
%12 = load volatile i64, i64* %11
%13 = and i64 %12, 2
%14 = icmp eq i64 %13, 0
%15 = add i64 %2, -1
%16 = icmp ult i64 %15, 65536
%17 = lshr i64 %2, 1
%18 = icmp ult i64 %2, 131072
%19 = select i1 %14, i1 %16, i1 %18
%20 = select i1 %14, i64 %15, i64 %17
%21 = zext i1 %19 to i32
%22 = tail call i32 @DEBUG_ASSERT(i32 %21)
%23 = add i64 %10, 16
%24 = inttoptr i64 %23 to i64*
store volatile i64 %20, i64* %24
ret void
}