#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*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int read(int, int *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, int *, int);
int main() {
  int fd1, fd2, fd3, ret, buf[10];
  fd1 = open("/sys/kernel/Paul_kobject/bar", O_RDONLY);
  if (fd1 < 0) {
    perror("Error in opening bar file \n");
    exit(1);
  }
  fd2 = open("/sys/kernel/Paul_kobject/foo", O_RDONLY);
  if (fd2 < 0) {
    perror("Error in opening foo file \n");
    exit(1);
  }
  fd3 = open("/sys/kernel/Paul_kobject/baz", O_RDONLY);
  if (fd3 < 0) {
    perror("Error in opening baz file \n");
    exit(1);
  }
  while (1) {
    ret = read(fd1, buf, 10);
    if (ret == 0)
      break;
    printf("bar : # of chars returned is %d\n", ret);
    if (ret > 0) {
      write(STDOUT_FILENO, buf, ret);
    }
  }
  while (1) {
    ret = read(fd2, buf, 10);
    if (ret == 0)
      break;
    printf("foo : # of chars returned is %d\n", ret);
    if (ret > 0) {
      write(STDOUT_FILENO, buf, ret);
    }
  }
  while (1) {
    ret = read(fd3, buf, 10);
    if (ret == 0)
      break;
    printf("baz : # of chars returned is %d\n", ret);
    if (ret > 0) {
      write(STDOUT_FILENO, buf, ret);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a7 <main+0x47>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11df <main+0x7f>
lea    0xe86(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1217 <main+0xb7>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121c <main+0xbc>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123f <main+0xdf>
jmp    1272 <main+0x112>
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    126d <main+0x10d>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    121c <main+0xbc>
jmp    1277 <main+0x117>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    129a <main+0x13a>
jmp    12cd <main+0x16d>
mov    -0x14(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    12c8 <main+0x168>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    1277 <main+0x117>
jmp    12d2 <main+0x172>
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12f5 <main+0x195>
jmp    1328 <main+0x1c8>
mov    -0x14(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1323 <main+0x1c3>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    12d2 <main+0x172>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%esi
lea    0xe82(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1190 <main+0x30>
lea    0xe8f(%rip),%rdi
jmp    11ca <main+0x6a>
mov    %eax,%r13d
mov    (%rbx),%esi
lea    0xe9d(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    11ae <main+0x4e>
lea    0xeaa(%rip),%rdi
jmp    11ca <main+0x6a>
mov    %eax,%r15d
mov    (%rbx),%esi
lea    0xeb8(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    11d9 <main+0x79>
lea    0xec5(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1223 <main+0xc3>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1279 <main+0x119>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    12c8 <main+0x168>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
lea    0xe7f(%rip),%r12
mov    %rsp,%rbp
jmp    1256 <main+0xf6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11f0 <main+0x90>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1240 <main+0xe0>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
jmp    1240 <main+0xe0>
mov    %eax,%ebx
lea    0xe4a(%rip),%r12
mov    0x2d67(%rip),%r13
mov    %rsp,%rbp
jmp    12aa <main+0x14a>
xchg   %ax,%ax
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1204 <main+0xa4>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1290 <main+0x130>
mov    0x0(%r13),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
jmp    1290 <main+0x130>
mov    %eax,%ebx
lea    0xe1c(%rip),%r15
mov    0x2d18(%rip),%r12
mov    %rsp,%rbp
jmp    12fa <main+0x19a>
nopl   (%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     121c <main+0xbc>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
test   %ebx,%ebx
jle    12e0 <main+0x180>
mov    (%r12),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
jmp    12e0 <main+0x180>

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/kernel/Paul_kobject/bar\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"Error in opening bar file \0A\00"
@.str.2 = [29 x i8] c"/sys/kernel/Paul_kobject/foo\00"
@.str.3 = [28 x i8] c"Error in opening foo file \0A\00"
@.str.4 = [29 x i8] c"/sys/kernel/Paul_kobject/baz\00"
@.str.5 = [28 x i8] c"Error in opening baz file \0A\00"
@.str.6 = [33 x i8] c"bar : # of chars returned is %d\0A\00"
@STDOUT_FILENO = global i32 0
@.str.7 = [33 x i8] c"foo : # of chars returned is %d\0A\00"
@.str.8 = [33 x i8] c"baz : # of chars returned is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
br label %31
31: ; preds = %30, %48
%32 = load i32, i32* %2
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%34 = call i32 @read(i32 %32, i32* %33, i32 10)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
br label %49
38: ; preds = %31
%39 = load i32, i32* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %5
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i32, i32* @STDOUT_FILENO
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @write(i32 %44, i32* %45, i32 %46)
br label %48
48: ; preds = %43, %38
br label %31
49: ; preds = %37
br label %50
50: ; preds = %49, %67
%51 = load i32, i32* %3
%52 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%53 = call i32 @read(i32 %51, i32* %52, i32 10)
store i32 %53, i32* %5
%54 = load i32, i32* %5
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
br label %68
57: ; preds = %50
%58 = load i32, i32* %5
%59 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %5
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = load i32, i32* @STDOUT_FILENO
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%65 = load i32, i32* %5
%66 = call i32 @write(i32 %63, i32* %64, i32 %65)
br label %67
67: ; preds = %62, %57
br label %50
68: ; preds = %56
br label %69
69: ; preds = %68, %86
%70 = load i32, i32* %4
%71 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%72 = call i32 @read(i32 %70, i32* %71, i32 10)
store i32 %72, i32* %5
%73 = load i32, i32* %5
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %69
br label %87
76: ; preds = %69
%77 = load i32, i32* %5
%78 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %5
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %76
%82 = load i32, i32* @STDOUT_FILENO
%83 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%84 = load i32, i32* %5
%85 = call i32 @write(i32 %82, i32* %83, i32 %84)
br label %86
86: ; preds = %81, %76
br label %69
87: ; preds = %75
%88 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/kernel/Paul_kobject/bar\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"Error in opening bar file \0A\00"
@.str.2 = [29 x i8] c"/sys/kernel/Paul_kobject/foo\00"
@.str.3 = [28 x i8] c"Error in opening foo file \0A\00"
@.str.4 = [29 x i8] c"/sys/kernel/Paul_kobject/baz\00"
@.str.5 = [28 x i8] c"Error in opening baz file \0A\00"
@.str.6 = [33 x i8] c"bar : # of chars returned is %d\0A\00"
@STDOUT_FILENO = global i32 0
@.str.7 = [33 x i8] c"foo : # of chars returned is %d\0A\00"
@.str.8 = [33 x i8] c"baz : # of chars returned is %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%22 = call i32 @read(i32 %4, i32* %21, i32 10)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %30
24: ; preds = %16
%25 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %37, %20
%28 = call i32 @read(i32 %11, i32* %21, i32 10)
%29 = icmp eq i32 %28, 0
br i1 %29, label %40, label %43
30: ; preds = %20, %37
%31 = phi i32 [ %38, %37 ], [ %22, %20 ]
%32 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = icmp sgt i32 %31, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @STDOUT_FILENO
%36 = call i32 @write(i32 %35, i32* %21, i32 %31)
br label %37
37: ; preds = %34, %30
%38 = call i32 @read(i32 %4, i32* %21, i32 10)
%39 = icmp eq i32 %38, 0
br i1 %39, label %27, label %30
40: ; preds = %50, %27
%41 = call i32 @read(i32 %18, i32* %21, i32 10)
%42 = icmp eq i32 %41, 0
br i1 %42, label %63, label %53
43: ; preds = %27, %50
%44 = phi i32 [ %51, %50 ], [ %28, %27 ]
%45 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %44)
%46 = icmp sgt i32 %44, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @STDOUT_FILENO
%49 = call i32 @write(i32 %48, i32* %21, i32 %44)
br label %50
50: ; preds = %47, %43
%51 = call i32 @read(i32 %11, i32* %21, i32 10)
%52 = icmp eq i32 %51, 0
br i1 %52, label %40, label %43
53: ; preds = %40, %60
%54 = phi i32 [ %61, %60 ], [ %41, %40 ]
%55 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %54)
%56 = icmp sgt i32 %54, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32, i32* @STDOUT_FILENO
%59 = call i32 @write(i32 %58, i32* %21, i32 %54)
br label %60
60: ; preds = %57, %53
%61 = call i32 @read(i32 %18, i32* %21, i32 10)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %53
63: ; preds = %60, %40
%64 = tail call i32 @exit(i32 0)
unreachable
}