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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  int fd, j, rc;
  char buf[64];
  char *fname = "/sys/kernel/debug/my_rc_file0";
  if (argc > 1)
    fname = argv[1];
  fd = open(fname, O_RDONLY);
  printf("opening %s, fd=%d\n", fname, fd);
  for (j = 1; j < 20; j++) {
    rc = read(fd, buf, 64);
    printf("rc=%d    %s::", rc, buf);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x68(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1177 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    11e9 <main+0xa9>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a8 <main+0x68>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
cmp    $0x2,%edi
jl     1154 <main+0x14>
mov    0x8(%rsi),%r14
jmp    115b <main+0x1b>
lea    0xea5(%rip),%r14
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xea9(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
lea    0xe97(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/kernel/debug/my_rc_file0\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"opening %s, fd=%d\0A\00"
@.str.2 = [14 x i8] c"rc=%d %s::\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 i32
%9 = alloca [64 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %10
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %10
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i8*, i8** %10
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22)
store i32 1, i32* %7
br label %24
24: ; preds = %34, %17
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 20
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32, i32* %6
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 64)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %31, i8* %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %24
37: ; preds = %24
%38 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/kernel/debug/my_rc_file0\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"opening %s, fd=%d\0A\00"
@.str.2 = [14 x i8] c"rc=%d %s::\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %12)
%14 = call i32 @read(i32 %12, i8* %4, i32 64)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %4)
%16 = call i32 @read(i32 %12, i8* %4, i32 64)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %4)
%18 = call i32 @read(i32 %12, i8* %4, i32 64)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %4)
%20 = call i32 @read(i32 %12, i8* %4, i32 64)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* %4)
%22 = call i32 @read(i32 %12, i8* %4, i32 64)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %4)
%24 = call i32 @read(i32 %12, i8* %4, i32 64)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %4)
%26 = call i32 @read(i32 %12, i8* %4, i32 64)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %4)
%28 = call i32 @read(i32 %12, i8* %4, i32 64)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %28, i8* %4)
%30 = call i32 @read(i32 %12, i8* %4, i32 64)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %4)
%32 = call i32 @read(i32 %12, i8* %4, i32 64)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %4)
%34 = call i32 @read(i32 %12, i8* %4, i32 64)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %4)
%36 = call i32 @read(i32 %12, i8* %4, i32 64)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %36, i8* %4)
%38 = call i32 @read(i32 %12, i8* %4, i32 64)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* %4)
%40 = call i32 @read(i32 %12, i8* %4, i32 64)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %40, i8* %4)
%42 = call i32 @read(i32 %12, i8* %4, i32 64)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %42, i8* %4)
%44 = call i32 @read(i32 %12, i8* %4, i32 64)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %4)
%46 = call i32 @read(i32 %12, i8* %4, i32 64)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %46, i8* %4)
%48 = call i32 @read(i32 %12, i8* %4, i32 64)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %48, i8* %4)
%50 = call i32 @read(i32 %12, i8* %4, i32 64)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %50, i8* %4)
%52 = call i32 @exit(i32 0)
unreachable
}