#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 scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
uint32_t EPINonBlockingReadGet16(uint32_t ui32Base, uint32_t ui32Count,
                                 uint16_t *pui16Buf) {
  uint32_t ui32CountRead = 0;
  ASSERT(ui32Base == 0x400D0000);
  ASSERT(ui32Count < 4096);
  ASSERT(pui16Buf);
  while ((*((volatile uint32_t *)(ui32Base + 0x0000006C))) && ui32Count--) {
    *pui16Buf = (uint16_t)(*((volatile uint32_t *)(ui32Base + 0x00000070)));
    pui16Buf++;
    ui32CountRead++;
  }
  return (ui32CountRead);
}


x86 assembly (clang, -O0):
<EPINonBlockingReadGet16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x400d0000,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
cmpl   $0x1000,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1030 <ASSERT@plt>
mov    -0x4(%rbp),%eax
add    $0x6c,%eax
cltq
mov    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1188 <EPINonBlockingReadGet16+0x78>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1198 <EPINonBlockingReadGet16+0x88>
jmp    11c6 <EPINonBlockingReadGet16+0xb6>
mov    -0x4(%rbp),%eax
add    $0x70,%eax
cltq
mov    (%rax),%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <EPINonBlockingReadGet16+0x4c>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EPINonBlockingReadGet16>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x400d0000,%ebp
sete   %dil
call   1030 <ASSERT@plt>
xor    %edi,%edi
cmp    $0x1000,%ebx
setl   %dil
call   1030 <ASSERT@plt>
mov    %r14d,%edi
call   1030 <ASSERT@plt>
movslq %ebp,%rcx
xor    %eax,%eax
cmpl   $0x0,0x6c(%rcx)
je     1179 <EPINonBlockingReadGet16+0x69>
test   %ebx,%ebx
je     1179 <EPINonBlockingReadGet16+0x69>
add    $0xffffffff,%ebx
xor    %edx,%edx
nopl   0x0(%rax)
movslq 0x70(%rcx),%rax
mov    %rax,(%r14,%rdx,8)
lea    0x1(%rdx),%rax
cmpl   $0x0,0x6c(%rcx)
je     1179 <EPINonBlockingReadGet16+0x69>
cmp    %edx,%ebx
mov    %rax,%rdx
jne    1160 <EPINonBlockingReadGet16+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @EPINonBlockingReadGet16(i32 %0, i32 %1, i64* %2) {
%4 = icmp eq i32 %0, 1074593792
%5 = zext i1 %4 to i32
%6 = tail call i32 @ASSERT(i32 %5)
%7 = icmp slt i32 %1, 4096
%8 = zext i1 %7 to i32
%9 = tail call i32 @ASSERT(i32 %8)
%10 = ptrtoint i64* %2 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @ASSERT(i32 %11)
%13 = add nsw i32 %0, 108
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = load volatile i32, i32* %15
%17 = icmp eq i32 %16, 0
%18 = icmp eq i32 %1, 0
%19 = or i1 %17, %18
br i1 %19, label %37, label %20
20: ; preds = %3
%21 = add nsw i32 %0, 112
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
br label %24
24: ; preds = %20, %24
%25 = phi i32 [ 0, %20 ], [ %32, %24 ]
%26 = phi i64* [ %2, %20 ], [ %31, %24 ]
%27 = phi i32 [ %1, %20 ], [ %28, %24 ]
%28 = add nsw i32 %27, -1
%29 = load volatile i32, i32* %23
%30 = sext i32 %29 to i64
store i64 %30, i64* %26
%31 = getelementptr inbounds i64, i64* %26, i64 1
%32 = add nuw nsw i32 %25, 1
%33 = load volatile i32, i32* %15
%34 = icmp eq i32 %33, 0
%35 = icmp eq i32 %28, 0
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %37, label %24
37: ; preds = %24, %3
%38 = phi i32 [ 0, %3 ], [ %32, %24 ]
ret i32 %38
}