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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char n;
  int devfd;
  ssize_t nr;
  int count;
  devfd = open("/dev/fifo0", O_RDONLY);
  if (-1 == n) {
    perror("open()");
    return EXIT_FAILURE;
  }
  count = -1;
  if (2 == argc) {
    count = atoi(argv[1]);
  }
  while (count-- != 0) {
    nr = read(devfd, &n, sizeof(n));
    if (-1 == nr) {
      perror("write()");
      return EXIT_FAILURE;
    } else if (nr > 0) {
      printf("%u\n", n);
    } else {
      break;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x11(%rbp),%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ac <main+0x5c>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <main+0x113>
movl   $0xffffffff,-0x20(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    11d1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    11d6 <main+0x86>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1257 <main+0x107>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1229 <main+0xd9>
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <main+0x113>
cmpl   $0x0,-0x1c(%rbp)
jle    1248 <main+0xf8>
lea    0xde0(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
jmp    124d <main+0xfd>
jmp    1257 <main+0x107>
jmp    1252 <main+0x102>
jmp    11d6 <main+0x86>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    $0xffffffff,%ebp
cmp    $0x2,%r15d
jne    1193 <main+0x43>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11de <main+0x8e>
lea    0xf(%rsp),%r14
mov    0x2e31(%rip),%r12
lea    0xe6d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0xa6>
test   %eax,%eax
jle    11e5 <main+0x95>
add    $0xffffffff,%ebp
movsbl 0xf(%rsp),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
test   %ebp,%ebp
jne    11b0 <main+0x60>
jmp    11e5 <main+0x95>
mov    0x2deb(%rip),%r12
mov    (%r12),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dcf(%rip),%r12
jmp    11e5 <main+0x95>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/fifo0\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"write()\00"
@.str.3 = [4 x i8] c"%u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %7
%12 = load i8, i8* %6
%13 = sext i8 %12 to i32
%14 = icmp eq i32 -1, %13
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %50
18: ; preds = %2
store i32 -1, i32* %9
%19 = load i32, i32* %4
%20 = icmp eq i32 2, %19
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %21, %18
br label %27
27: ; preds = %47, %26
%28 = load i32, i32* %9
%29 = add nsw i32 %28, -1
store i32 %29, i32* %9
%30 = icmp ne i32 %28, 0
br i1 %30, label %31, label %48
31: ; preds = %27
%32 = load i32, i32* %7
%33 = call i32 @read(i32 %32, i8* %6, i32 1)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp eq i32 -1, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %50
39: ; preds = %31
%40 = load i32, i32* %8
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8, i8* %6
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %43)
br label %46
45: ; preds = %39
br label %48
46: ; preds = %42
br label %47
47: ; preds = %46
br label %27
48: ; preds = %45, %27
%49 = load i32, i32* @EXIT_SUCCESS
store i32 %49, i32* %3
br label %50
50: ; preds = %48, %36, %15
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/fifo0\00"
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"write()\00"
@.str.3 = [4 x i8] c"%u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %2, %7
%13 = phi i32 [ -1, %2 ], [ %10, %7 ]
br label %14
14: ; preds = %12, %23
%15 = phi i32 [ %16, %23 ], [ %13, %12 ]
%16 = add nsw i32 %15, -1
%17 = call i32 @read(i32 %5, i8* %3, i32 1)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %27
21: ; preds = %14
%22 = icmp sgt i32 %17, 0
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = load i8, i8* %3
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %24)
%26 = icmp eq i32 %16, 0
br i1 %26, label %27, label %14
27: ; preds = %21, %23, %7, %19
%28 = phi i32* [ @EXIT_FAILURE, %19 ], [ @EXIT_SUCCESS, %7 ], [ @EXIT_SUCCESS, %23 ], [ @EXIT_SUCCESS, %21 ]
%29 = load i32, i32* %28
ret i32 %29
}