#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);
uint32_t PWMGenPeriodGet(uint32_t ui32Base, uint32_t ui32Gen) {
  ASSERT((ui32Base == 0x40028000) || (ui32Base == 0x40029000));
  ASSERT(_PWMGenValid(ui32Gen));
  ui32Gen = ((ui32Base) + (ui32Gen));
  if ((*((volatile uint32_t *)(ui32Gen + 0x00000000))) & 0x00000002) {
    return ((*((volatile uint32_t *)(ui32Gen + 0x00000010))) * 2);
  } else {
    return ((*((volatile uint32_t *)(ui32Gen + 0x00000010))) + 1);
  }
}


x86 assembly (clang, -O0):
<PWMGenPeriodGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x40028000,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     114d <PWMGenPeriodGet+0x2d>
cmpl   $0x40029000,-0x8(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    -0xc(%rbp),%edi
call   1030 <_PWMGenValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x0,%eax
cltq
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     119d <PWMGenPeriodGet+0x7d>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <PWMGenPeriodGet+0x8d>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMGenPeriodGet>:
push   %rbp
push   %rbx
push   %rax
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 <_PWMGenValid@plt>
mov    %eax,%edi
call   1040 <ASSERT@plt>
movslq %ebx,%rax
movslq %ebp,%rcx
mov    (%rax,%rcx,1),%edx
mov    0x10(%rax,%rcx,1),%eax
lea    (%rax,%rax,1),%ecx
add    $0x1,%eax
test   $0x2,%edx
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @PWMGenPeriodGet(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1073905664
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1073909760
br label %11
11: ; preds = %8, %2
%12 = phi i1 [ true, %2 ], [ %10, %8 ]
%13 = zext i1 %12 to i32
%14 = call i32 @ASSERT(i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @_PWMGenValid(i32 %15)
%17 = call i32 @ASSERT(i32 %16)
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 0
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load volatile i32, i32* %24
%26 = and i32 %25, 2
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %11
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 16
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
%33 = load volatile i32, i32* %32
%34 = mul nsw i32 %33, 2
store i32 %34, i32* %3
br label %42
35: ; preds = %11
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 16
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i32*
%40 = load volatile i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %42
42: ; preds = %35, %28
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @PWMGenPeriodGet(i32 %0, i32 %1) {
%3 = and i32 %0, -4097
%4 = icmp eq i32 %3, 1073905664
%5 = zext i1 %4 to i32
%6 = tail call i32 @ASSERT(i32 %5)
%7 = tail call i32 @_PWMGenValid(i32 %1)
%8 = tail call i32 @ASSERT(i32 %7)
%9 = add nsw i32 %1, %0
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = load volatile i32, i32* %11
%13 = and i32 %12, 2
%14 = icmp eq i32 %13, 0
%15 = add nsw i32 %9, 16
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = load volatile i32, i32* %17
%19 = shl nsw i32 %18, 1
%20 = add nsw i32 %18, 1
%21 = select i1 %14, i32 %20, i32 %19
ret i32 %21
}