#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 int ui32Base;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
int _PWMGenValid(int);
void PWMGenPeriodSet(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Period) {
  ASSERT((ui32Base == 0x40028000) || (ui32Base == 0x40029000));
  ASSERT(_PWMGenValid(ui32Gen));
  ui32Gen = ((ui32Base) + (ui32Gen));
  if ((*((volatile uint32_t *)(ui32Gen + 0x00000000))) & 0x00000002) {
    ASSERT((ui32Period / 2) < 65536);
    (*((volatile uint32_t *)(ui32Gen + 0x00000010))) = ui32Period / 2;
  } else {
    ASSERT((ui32Period <= 65536) && (ui32Period != 0));
    (*((volatile uint32_t *)(ui32Gen + 0x00000010))) = ui32Period - 1;
  }
}


x86 assembly (clang, -O0):
<PWMGenPeriodSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x40028000,-0x4(%rbp)
mov    %al,-0xd(%rbp)
je     1150 <PWMGenPeriodSet+0x30>
cmpl   $0x40029000,-0x4(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0x8(%rbp),%edi
call   1030 <_PWMGenValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x0,%eax
cltq
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11c4 <PWMGenPeriodSet+0xa4>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x10000,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
add    $0x10,%eax
cltq
mov    %ecx,(%rax)
jmp    11fd <PWMGenPeriodSet+0xdd>
xor    %eax,%eax
cmpl   $0x10000,-0xc(%rbp)
mov    %al,-0xe(%rbp)
jg     11e0 <PWMGenPeriodSet+0xc0>
cmpl   $0x0,-0xc(%rbp)
setne  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%eax
add    $0x10,%eax
cltq
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMGenPeriodSet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %edi,%eax
and    $0xffffefff,%eax
xor    %edi,%edi
cmp    $0x40028000,%eax
sete   %dil
call   1040 <ASSERT@plt>
mov    %ebp,%edi
call   1030 <_PWMGenValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
movslq %ebp,%r15
movslq %ebx,%rbx
testl  $0x2,(%r15,%rbx,1)
jne    1183 <PWMGenPeriodSet+0x63>
cmp    $0x10001,%r14d
setl   %al
add    $0xffffffff,%r14d
setb   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <ASSERT@plt>
mov    %r14d,%ebp
jmp    11a0 <PWMGenPeriodSet+0x80>
mov    %r14d,%ebp
shr    $0x1f,%ebp
add    %r14d,%ebp
sar    %ebp
xor    %edi,%edi
cmp    $0x20000,%r14d
setl   %dil
call   1040 <ASSERT@plt>
mov    %ebp,0x10(%rbx,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @PWMGenPeriodSet(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 @_PWMGenValid(i32 %1)
%9 = tail call i32 @ASSERT(i32 %8)
%10 = add nsw i32 %1, %0
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = load volatile i32, i32* %12
%14 = and i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = sdiv i32 %2, 2
%18 = icmp slt i32 %2, 131072
%19 = zext i1 %18 to i32
%20 = tail call i32 @ASSERT(i32 %19)
br label %28
21: ; preds = %3
%22 = icmp slt i32 %2, 65537
%23 = icmp ne i32 %2, 0
%24 = and i1 %22, %23
%25 = zext i1 %24 to i32
%26 = tail call i32 @ASSERT(i32 %25)
%27 = add nsw i32 %2, -1
br label %28
28: ; preds = %21, %16
%29 = phi i32 [ %27, %21 ], [ %17, %16 ]
%30 = add nsw i32 %10, 16
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
store volatile i32 %29, i32* %32
ret void
}