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

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
char *strerror(int const);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  int fd = open("data.txt", O_RDONLY);
  if (fd == -1) {
    const int e = errno;
    printf("failed to open, %d %s\n", e, strerror(e));
    perror("open");
  }
  fd = open("/dev/null", O_RDONLY);
  if (fd == -1) {
    printf("failed to open, %d %s\n", errno, strerror(errno));
    exit(1);
  }
  printf("Successfully opened /dev/random\n");
  unsigned long word;
  ssize_t nr;
  nr = read(fd, &word, sizeof(unsigned long));
  if (nr == -1) {
    perror("read");
  }
  printf("Attempted to read %ld bytes, got %d bytes\n", sizeof(unsigned long),
         (int)nr);
  close(fd);
  fd = open("test_input.txt", O_RDONLY);
  if (fd == -1) {
    printf("failed to open, %d %s\n", errno, strerror(errno));
    exit(1);
  }
  char buf[1024];
  int len = 20;
  ssize_t ret;
  int rd = 0;
  int pass = 0;
  while (len != 0 && (ret = read(fd, buf, len)) != 0) {
    if (ret == -1) {
      if (errno == EINTR)
        continue;
      perror("read");
      break;
    }
    len -= ret;
    rd += (int)ret;
    pass++;
  }
  printf("Attempted to read %d bytes in %d passes, got %d bytes in buffer\n",
         (int)rd, pass, (int)strlen(buf));
  printf("Buffer: '%s'\n", buf);
  close(fd);
  printf("Reading from closed fd\n");
  ret = read(fd, buf, 10);
  if (ret == -1) {
    printf("Reading on closed file descriptor: %d, error %d, %s\n", fd, errno,
           strerror(errno));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fb <main+0x7b>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x18(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x444(%rbp),%esi
mov    %rax,%rdx
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    125b <main+0xdb>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x448(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x448(%rbp),%esi
mov    %rax,%rdx
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1295 <main+0x115>
lea    0xdc0(%rip),%rdi
call   1080 <perror@plt>
mov    -0x24(%rbp),%edx
lea    0xdb6(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
lea    0xdbd(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1313 <main+0x193>
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44c(%rbp),%esi
mov    %rax,%rdx
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x14,-0x434(%rbp)
movl   $0x0,-0x43c(%rbp)
movl   $0x0,-0x440(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x434(%rbp)
mov    %al,-0x44d(%rbp)
je     136f <main+0x1ef>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x438(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x44d(%rbp)
mov    -0x44d(%rbp),%al
test   $0x1,%al
jne    1382 <main+0x202>
jmp    13f7 <main+0x277>
cmpl   $0xffffffff,-0x438(%rbp)
jne    13bd <main+0x23d>
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
mov    0x2c31(%rip),%rcx
cmp    (%rcx),%eax
jne    13ac <main+0x22c>
jmp    1331 <main+0x1b1>
lea    0xc9d(%rip),%rdi
call   1080 <perror@plt>
jmp    13f7 <main+0x277>
mov    -0x438(%rbp),%ecx
mov    -0x434(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x434(%rbp)
mov    -0x438(%rbp),%eax
add    -0x43c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x440(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x440(%rbp)
jmp    1331 <main+0x1b1>
mov    -0x43c(%rbp),%eax
mov    %eax,-0x458(%rbp)
mov    -0x440(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x458(%rbp),%esi
mov    -0x454(%rbp),%edx
mov    %eax,%ecx
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rsi
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0xffffffff,-0x438(%rbp)
jne    14ce <main+0x34e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x460(%rbp)
mov    0x2b3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x45c(%rbp)
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x460(%rbp),%esi
mov    -0x45c(%rbp),%edx
mov    %rax,%rcx
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    0x2e40(%rip),%r14
mov    (%r14),%esi
lea    0xe4e(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     128e <main+0xfe>
mov    (%r14),%esi
lea    0xe5b(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1371 <main+0x1e1>
mov    %eax,%ebx
lea    0xf11(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     12c2 <main+0x132>
lea    0xe29(%rip),%rdi
mov    $0x8,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    (%r14),%esi
lea    0xe35(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1371 <main+0x1e1>
mov    %eax,%ebx
mov    $0x14,%ebp
lea    0x10(%rsp),%r12
mov    0x2d8d(%rip),%r13
mov    0x2d7e(%rip),%r14
movl   $0x0,0x4(%rsp)
xor    %r15d,%r15d
jmp    1269 <main+0xd9>
nop
mov    0x0(%r13),%eax
cmp    (%r14),%eax
jne    12d3 <main+0x143>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0xd0>
test   %eax,%eax
je     12df <main+0x14f>
add    %eax,%r15d
addl   $0x1,0x4(%rsp)
sub    %eax,%ebp
jne    1269 <main+0xd9>
jmp    12df <main+0x14f>
mov    0x2d43(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xd64(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd68(%rip),%rdi
call   1090 <perror@plt>
jmp    11c0 <main+0x30>
lea    0xd66(%rip),%rdi
call   1090 <perror@plt>
jmp    1204 <main+0x74>
lea    0xd55(%rip),%rdi
call   1090 <perror@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0xd7b(%rip),%rdi
mov    %r15d,%esi
mov    0x4(%rsp),%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xda5(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    135d <main+0x1cd>
mov    0x0(%r13),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd6e(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c60(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xc81(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [23 x i8] c"failed to open, %d %s\0A\00"
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@.str.4 = [33 x i8] c"Successfully opened /dev/random\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [43 x i8] c"Attempted to read %ld bytes, got %d bytes\0A\00"
@.str.7 = [15 x i8] c"test_input.txt\00"
@EINTR = global i32 0
@.str.8 = [65 x i8] c"Attempted to read %d bytes in %d passes, got %d bytes in buffer\0A\00"
@.str.9 = [14 x i8] c"Buffer: '%s'\0A\00"
@.str.10 = [24 x i8] c"Reading from closed fd\0A\00"
@.str.11 = [53 x i8] c"Reading on closed file descriptor: %d, error %d, %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @errno
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* %7
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %23)
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %19, %2
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %32, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %6
%40 = call i32 (i32, ...) @read(i32 %39, i64* %8, i64 8)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i64 8, i32 %46)
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* @O_RDONLY
%51 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %45
%55 = load i32, i32* @errno
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %55, i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %45
store i32 20, i32* %11
store i32 0, i32* %13
store i32 0, i32* %14
br label %61
61: ; preds = %82, %79, %60
%62 = load i32, i32* %11
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32, i32* %6
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%67 = load i32, i32* %11
%68 = call i32 (i32, ...) @read(i32 %65, i8* %66, i32 %67)
store i32 %68, i32* %12
%69 = icmp ne i32 %68, 0
br label %70
70: ; preds = %64, %61
%71 = phi i1 [ false, %61 ], [ %69, %64 ]
br i1 %71, label %72, label %91
72: ; preds = %70
%73 = load i32, i32* %12
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %82
75: ; preds = %72
%76 = load i32, i32* @errno
%77 = load i32, i32* @EINTR
%78 = icmp eq i32 %76, %77
br i1 %78, label %79, label %80
79: ; preds = %75
br label %61
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %91
82: ; preds = %72
%83 = load i32, i32* %12
%84 = load i32, i32* %11
%85 = sub nsw i32 %84, %83
store i32 %85, i32* %11
%86 = load i32, i32* %12
%87 = load i32, i32* %13
%88 = add nsw i32 %87, %86
store i32 %88, i32* %13
%89 = load i32, i32* %14
%90 = add nsw i32 %89, 1
store i32 %90, i32* %14
br label %61
91: ; preds = %80, %70
%92 = load i32, i32* %13
%93 = load i32, i32* %14
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%95 = call i64 @strlen(i8* %94)
%96 = trunc i64 %95 to i32
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.8, i64 0, i64 0), i32 %92, i32 %93, i32 %96)
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = load i32, i32* %6
%101 = call i32 @close(i32 %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%103 = load i32, i32* %6
%104 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%105 = call i32 (i32, ...) @read(i32 %103, i8* %104, i32 10)
store i32 %105, i32* %12
%106 = load i32, i32* %12
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %114
108: ; preds = %91
%109 = load i32, i32* %6
%110 = load i32, i32* @errno
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0), i32 %109, i32 %110, i8* %112)
br label %114
114: ; preds = %108, %91
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [23 x i8] c"failed to open, %d %s\0A\00"
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [43 x i8] c"Attempted to read %ld bytes, got %d bytes\0A\00"
@.str.7 = [15 x i8] c"test_input.txt\00"
@EINTR = global i32 0
@.str.8 = [65 x i8] c"Attempted to read %d bytes in %d passes, got %d bytes in buffer\0A\00"
@.str.9 = [14 x i8] c"Buffer: '%s'\0A\00"
@.str.11 = [53 x i8] c"Reading on closed file descriptor: %d, error %d, %s\0A\00"
@str = [32 x i8] c"Successfully opened /dev/random\00"
@str.12 = [23 x i8] c"Reading from closed fd\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [1024 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %10)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %8, %2
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%24 = bitcast i64* %3 to i8*
%25 = call i32 (i32, ...) @read(i32 %15, i64* %3, i64 8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i64 8, i32 %25)
%31 = call i32 @close(i32 %15)
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %36, i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %42
42: ; preds = %40, %54
%43 = phi i32 [ 0, %40 ], [ %57, %54 ]
%44 = phi i32 [ 0, %40 ], [ %56, %54 ]
%45 = phi i32 [ 20, %40 ], [ %55, %54 ]
br label %46
46: ; preds = %42, %48
%47 = call i32 (i32, ...) @read(i32 %33, i8* %41, i32 %45)
switch i32 %47, label %54 [
i32 0, label %59
i32 -1, label %48
]
48: ; preds = %46
%49 = load i32, i32* @errno
%50 = load i32, i32* @EINTR
%51 = icmp eq i32 %49, %50
br i1 %51, label %46, label %52
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %59
54: ; preds = %46
%55 = sub nsw i32 %45, %47
%56 = add nsw i32 %47, %44
%57 = add nuw nsw i32 %43, 1
%58 = icmp eq i32 %55, 0
br i1 %58, label %59, label %42
59: ; preds = %54, %46, %52
%60 = phi i32 [ %44, %52 ], [ %44, %46 ], [ %56, %54 ]
%61 = phi i32 [ %43, %52 ], [ %43, %46 ], [ %57, %54 ]
%62 = call i64 @strlen(i8* %41)
%63 = trunc i64 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.8, i64 0, i64 0), i32 %60, i32 %61, i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %41)
%66 = call i32 @close(i32 %33)
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
%68 = call i32 (i32, ...) @read(i32 %33, i8* %41, i32 10)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %74
70: ; preds = %59
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0), i32 %33, i32 %71, i8* %72)
br label %74
74: ; preds = %70, %59
ret i32 0
}