#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 volatile uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
uint32_t _USBIndexRead(uint32_t ui32Base, uint32_t ui32Endpoint,
                       uint32_t ui32IndexedReg, uint32_t ui32Size) {
  uint8_t ui8Index;
  uint32_t ui32Value;
  ASSERT(ui32Base == 0x40050000);
  ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
         (ui32Endpoint == 3));
  ASSERT((ui32Size == 1) || (ui32Size == 2));
  ui8Index = (*((volatile uint8_t *)(ui32Base + 0x0000000E)));
  (*((volatile uint8_t *)(ui32Base + 0x0000000E))) = ui32Endpoint;
  if (ui32Size == 1) {
    ui32Value = (*((volatile uint8_t *)(ui32Base + ui32IndexedReg)));
  } else {
    ui32Value = (*((volatile uint16_t *)(ui32Base + ui32IndexedReg)));
  }
  (*((volatile uint8_t *)(ui32Base + 0x0000000E))) = ui8Index;
  return (ui32Value);
}


x86 assembly (clang, -O0):
<_USBIndexRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x40050000,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     116f <_USBIndexRead+0x5f>
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     116f <_USBIndexRead+0x5f>
mov    $0x1,%al
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     116f <_USBIndexRead+0x5f>
cmpl   $0x3,-0x8(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    $0x1,%al
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x1a(%rbp)
je     1195 <_USBIndexRead+0x85>
cmpl   $0x2,-0x10(%rbp)
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    -0x4(%rbp),%eax
add    $0xe,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
add    $0xe,%eax
cltq
mov    %ecx,(%rax)
cmpl   $0x1,-0x10(%rbp)
jne    11d8 <_USBIndexRead+0xc8>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11e5 <_USBIndexRead+0xd5>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
add    $0xe,%eax
cltq
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_USBIndexRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x40050000,%ebp
sete   %dil
call   1030 <ASSERT@plt>
xor    %edi,%edi
cmp    $0x4,%r15d
setb   %dil
call   1030 <ASSERT@plt>
add    $0xffffffff,%ebx
xor    %edi,%edi
cmp    $0x2,%ebx
setb   %dil
call   1030 <ASSERT@plt>
movslq %ebp,%rcx
mov    0xe(%rcx),%eax
mov    %eax,0x4(%rsp)
mov    %r15d,0xe(%rcx)
movslq %r14d,%rax
mov    (%rax,%rcx,1),%eax
mov    0x4(%rsp),%edx
mov    %edx,0xe(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_USBIndexRead(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1074069504
%13 = zext i1 %12 to i32
%14 = call i32 @ASSERT(i32 %13)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %4
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 1
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 2
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 3
br label %26
26: ; preds = %23, %20, %17, %4
%27 = phi i1 [ true, %20 ], [ true, %17 ], [ true, %4 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @ASSERT(i32 %28)
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 2
br label %35
35: ; preds = %32, %26
%36 = phi i1 [ true, %26 ], [ %34, %32 ]
%37 = zext i1 %36 to i32
%38 = call i32 @ASSERT(i32 %37)
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 14
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i32*
%43 = load volatile i32, i32* %42
store volatile i32 %43, i32* %9
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 14
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
store volatile i32 %44, i32* %48
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %58
51: ; preds = %35
%52 = load i32, i32* %5
%53 = load i32, i32* %7
%54 = add nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i32*
%57 = load volatile i32, i32* %56
store i32 %57, i32* %10
br label %65
58: ; preds = %35
%59 = load i32, i32* %5
%60 = load i32, i32* %7
%61 = add nsw i32 %59, %60
%62 = sext i32 %61 to i64
%63 = inttoptr i64 %62 to i32*
%64 = load volatile i32, i32* %63
store i32 %64, i32* %10
br label %65
65: ; preds = %58, %51
%66 = load volatile i32, i32* %9
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 14
%69 = sext i32 %68 to i64
%70 = inttoptr i64 %69 to i32*
store volatile i32 %66, i32* %70
%71 = load i32, i32* %10
ret i32 %71
}

LLVM IR (-O2):
define i32 @_USBIndexRead(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32 %0, 1074069504
%8 = zext i1 %7 to i32
%9 = tail call i32 @ASSERT(i32 %8)
%10 = icmp ult i32 %1, 4
%11 = zext i1 %10 to i32
%12 = tail call i32 @ASSERT(i32 %11)
%13 = add i32 %3, -1
%14 = icmp ult i32 %13, 2
%15 = zext i1 %14 to i32
%16 = tail call i32 @ASSERT(i32 %15)
%17 = add nsw i32 %0, 14
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load volatile i32, i32* %19
store volatile i32 %20, i32* %5
store volatile i32 %1, i32* %19
%21 = add nsw i32 %2, %0
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = load volatile i32, i32* %23
%25 = load volatile i32, i32* %5
store volatile i32 %25, i32* %19
ret i32 %24
}