#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 /*<<< orphan*/ nint;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, unsigned long *, int);
int /*<<< orphan*/ stderr;
int main() {
  int fd;
  unsigned long nint;
  if ((fd = open("/dev/uio0", O_RDONLY)) < 0) {
    perror("Failed to open /dev/uio0\n");
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "Started uio test driver.\n");
  while (read(fd, &nint, sizeof(nint)) >= 0)
    fprintf(stderr, "Interrupts: %ld\n", nint);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    119a <main+0x4a>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jl     11ec <main+0x9c>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b1 <main+0x61>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    118b <main+0x3b>
lea    0xe92(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %eax,%ebx
mov    0x2e44(%rip),%r12
mov    (%r12),%edi
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <read@plt>
test   %rax,%rax
js     11f6 <main+0xa6>
lea    0xe7d(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
mov    (%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <read@plt>
test   %rax,%rax
jns    11d0 <main+0x80>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/uio0\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Failed to open /dev/uio0\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Started uio test driver.\0A\00"
@.str.3 = [17 x i8] c"Interrupts: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %18, %11
%15 = load i32, i32* %2
%16 = call i64 @read(i32 %15, i64* %3, i32 8)
%17 = icmp sge i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i64, i64* %3
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %20)
br label %14
22: ; preds = %14
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/uio0\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Failed to open /dev/uio0\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Started uio test driver.\0A\00"
@.str.3 = [17 x i8] c"Interrupts: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @read(i32 %4, i64* %1, i32 8)
%14 = icmp sgt i64 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %10, %15
%16 = load i32, i32* @stderr
%17 = load i64, i64* %1
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %17)
%19 = call i64 @read(i32 %4, i64* %1, i32 8)
%20 = icmp sgt i64 %19, -1
br i1 %20, label %15, label %21
21: ; preds = %15, %10
%22 = load i32, i32* @EXIT_SUCCESS
%23 = tail call i32 @exit(i32 %22)
unreachable
}