#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int main() {
  int fd = open("testfile", O_RDONLY);
  int readCount;
  char buffer[10];
  while (readCount = read(fd, buffer, 10)) {
    printf("%d\n", readCount);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0xa,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1188 <main+0x58>
mov    -0xc(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1157 <main+0x27>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1040 <read@plt>
test   %eax,%eax
je     119d <main+0x6d>
lea    0xe9d(%rip),%r14
lea    0x6(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
test   %eax,%eax
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
br label %7
7: ; preds = %12, %0
%8 = load i32, i32* %2
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 10)
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %7
15: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = call i32 @read(i32 %3, i8* %4, i32 10)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %10, %7 ], [ %5, %0 ]
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @read(i32 %3, i8* %4, i32 10)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7, %0
ret i32 0
}