#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 ssize_t;
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, ...);
int read(int, unsigned char **, int);
int main(void) {
  int fd;
  ssize_t res;
  unsigned char ev[4];
  fd = open("/dev/sequencer", O_RDWR);
  if (fd < 0) {
    perror("open ("
           "/dev/sequencer"
           ")");
    return EXIT_FAILURE;
  }
  while ((res = read(fd, &ev, sizeof(ev))) == sizeof(ev)) {
    printf("read event: bytes = 0x%x,0x%x,0x%x,0x%x\n", ev[0], ev[1], ev[2],
           ev[3]);
  }
  printf("end res = %li\n", (long)res);
  close(fd);
  return 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   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119e <main+0x4e>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <main+0xbf>
jmp    11a3 <main+0x53>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cltq
cmp    $0x4,%rax
jne    11e9 <main+0x99>
movzbl -0x10(%rbp),%eax
mov    %eax,%esi
movzbl -0xf(%rbp),%edx
movzbl -0xe(%rbp),%ecx
movzbl -0xd(%rbp),%r8d
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a3 <main+0x53>
movslq -0xc(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11fe <main+0xae>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11d3 <main+0x83>
lea    0xe90(%rip),%r14
lea    0xc(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movzbl 0xc(%rsp),%esi
movzbl 0xd(%rsp),%edx
movzbl 0xe(%rsp),%ecx
movzbl 0xf(%rsp),%r8d
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     11a0 <main+0x50>
movslq %eax,%rsi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe0a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc7(%rip),%rax
jmp    11f2 <main+0xa2>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/sequencer\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"open (/dev/sequencer)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [41 x i8] c"read event: bytes = 0x%x,0x%x,0x%x,0x%x\0A\00"
@.str.3 = [15 x i8] c"end res = %li\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %40
12: ; preds = %0
br label %13
13: ; preds = %19, %12
%14 = load i32, i32* %2
%15 = bitcast [4 x i8]* %4 to i8**
%16 = call i32 @read(i32 %14, i8** %15, i32 4)
store i32 %16, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, 4
br i1 %18, label %19, label %33
19: ; preds = %13
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i64
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %22, i32 %25, i32 %28, i32 %31)
br label %13
33: ; preds = %13
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %35)
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %1
br label %40
40: ; preds = %33, %9
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/sequencer\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"open (/dev/sequencer)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [41 x i8] c"read event: bytes = 0x%x,0x%x,0x%x,0x%x\0A\00"
@.str.3 = [15 x i8] c"end res = %li\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = bitcast [4 x i8]* %1 to i8**
%8 = call i32 @read(i32 %4, i8** %7, i32 4)
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
br label %16
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %33
16: ; preds = %10, %16
%17 = load i8, i8* %2
%18 = zext i8 %17 to i64
%19 = load i8, i8* %11
%20 = zext i8 %19 to i32
%21 = load i8, i8* %12
%22 = zext i8 %21 to i32
%23 = load i8, i8* %13
%24 = zext i8 %23 to i32
%25 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %18, i32 %20, i32 %22, i32 %24)
%26 = call i32 @read(i32 %4, i8** %7, i32 4)
%27 = icmp eq i32 %26, 4
br i1 %27, label %16, label %28
28: ; preds = %16, %6
%29 = phi i32 [ %8, %6 ], [ %26, %16 ]
%30 = sext i32 %29 to i64
%31 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %30)
%32 = tail call i32 @close(i32 %4)
br label %33
33: ; preds = %28, %14
%34 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_SUCCESS, %28 ]
%35 = load i32, i32* %34
ret i32 %35
}