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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  ssize_t n;
  char buf1[64], buf2[64];
  int fd1, fd2;
  fd1 = open("./read_test", O_RDONLY);
  fd2 = open("./read_test", O_RDONLY);
  n = read(fd1, buf1, 5);
  buf1[n] = '\0';
  fprintf(stderr, "%s\n", buf1);
  n = read(fd2, buf2, 5);
  buf2[n] = '\0';
  fprintf(stderr, "%s\n", buf2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xa4(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xa8(%rbp)
mov    -0xa4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x5,%edx
call   1030 <read@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xa8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x5,%edx
call   1030 <read@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2ea2(%rip),%r14
mov    (%r14),%esi
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0x40(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <read@plt>
movb   $0x0,0x40(%rsp,%rax,1)
mov    0x2e51(%rip),%r12
mov    (%r12),%edi
lea    0xe7a(%rip),%r15
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rsp,%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1030 <read@plt>
movb   $0x0,(%rsp,%rax,1)
mov    (%r12),%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./read_test\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [64 x i8]
%8 = alloca [64 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %9
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%17 = call i64 @read(i32 %15, i8* %16, i32 5)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %10
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%25 = call i64 @read(i32 %23, i8* %24, i32 5)
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"./read_test\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i64 @read(i32 %8, i8* %5, i32 5)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %11
store i8 0, i8* %12
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%15 = call i64 @read(i32 %10, i8* %6, i32 5)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %15
store i8 0, i8* %16
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i32 0
}