#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);
unsigned long PWMGenPeriodGet(unsigned long ulBase, unsigned long ulGen) {
  DEBUG_ASSERT((ulBase == 0x40028000) || (ulBase == 0x40029000));
  DEBUG_ASSERT(PWMGenValid(ulGen));
  ulGen = ((ulBase) + (ulGen));
  if ((*((volatile unsigned long *)(ulGen + 0x00000000))) & 0x00000002) {
    return ((*((volatile unsigned long *)(ulGen + 0x00000010))) * 2);
  } else {
    return ((*((volatile unsigned long *)(ulGen + 0x00000010))) + 1);
  }
}


x86 assembly (clang, -O0):
<PWMGenPeriodGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x40028000,-0x10(%rbp)
40
mov    %al,-0x19(%rbp)
je     1151 <PWMGenPeriodGet+0x31>
cmpq   $0x40029000,-0x10(%rbp)
40
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x18(%rbp),%rdi
call   1040 <PWMGenValid@plt>
mov    %eax,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11a4 <PWMGenPeriodGet+0x84>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
shl    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <PWMGenPeriodGet+0x94>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMGenPeriodGet>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
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>
mov    (%r14,%rbx,1),%rcx
mov    0x10(%r14,%rbx,1),%rax
lea    (%rax,%rax,1),%rdx
add    $0x1,%rax
test   $0x2,%rcx
cmovne %rdx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @PWMGenPeriodGet(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 1073905664
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp eq i64 %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 @DEBUG_ASSERT(i32 %13)
%15 = load i64, i64* %5
%16 = call i32 @PWMGenValid(i64 %15)
%17 = call i32 @DEBUG_ASSERT(i32 %16)
%18 = load i64, i64* %4
%19 = load i64, i64* %5
%20 = add i64 %18, %19
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = add i64 %21, 0
%23 = inttoptr i64 %22 to i64*
%24 = load volatile i64, i64* %23
%25 = and i64 %24, 2
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %11
%28 = load i64, i64* %5
%29 = add i64 %28, 16
%30 = inttoptr i64 %29 to i64*
%31 = load volatile i64, i64* %30
%32 = mul i64 %31, 2
store i64 %32, i64* %3
br label %39
33: ; preds = %11
%34 = load i64, i64* %5
%35 = add i64 %34, 16
%36 = inttoptr i64 %35 to i64*
%37 = load volatile i64, i64* %36
%38 = add i64 %37, 1
store i64 %38, i64* %3
br label %39
39: ; preds = %33, %27
%40 = load i64, i64* %3
ret i64 %40
}

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