#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*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  int fd1 = -1, fd2 = -1;
  char buff1[2] = {0};
  char buff2[3] = {0};
  fd1 = open("./test1", O_RDONLY);
  fd2 = open("./test2", O_RDONLY);
  while (read(fd1, buff1, 2) > 0) {
    buff1[2 - 1] = '\0';
    printf("READ1: %s\n", buff1);
    sleep(1);
  }
  while (read(fd2, buff2, 3) > 0) {
    buff1[3 - 1] = '\0';
    printf("READ2: %s\n", buff2);
    sleep(1);
  }
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
lea    -0x11(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    120b <main+0xab>
movb   $0x0,-0xd(%rbp)
lea    -0xe(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11cd <main+0x6d>
jmp    1210 <main+0xb0>
mov    -0xc(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x3,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    124e <main+0xee>
movb   $0x0,-0xc(%rbp)
lea    -0x11(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1210 <main+0xb0>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movw   $0x0,0x2(%rsp)
movb   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
mov    0x2e77(%rip),%rbx
mov    (%rbx),%esi
lea    0xe86(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0xe7d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0x2(%rsp),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11ef <main+0x9f>
lea    0xe60(%rip),%r15
lea    0x2(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,0x3(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     11c0 <main+0x70>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    124e <main+0xfe>
lea    0xe0f(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x4(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1220 <main+0xd0>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"./test1\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"./test2\00"
@.str.2 = [11 x i8] c"READ1: %s\0A\00"
@.str.3 = [11 x i8] c"READ2: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca [3 x i8]
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
%6 = bitcast [2 x i8]* %4 to i8*
%7 = bitcast [3 x i8]* %5 to i8*
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
br label %12
12: ; preds = %17, %0
%13 = load i32, i32* %2
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 2)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %18
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32 @sleep(i32 1)
br label %12
22: ; preds = %12
br label %23
23: ; preds = %28, %22
%24 = load i32, i32* %3
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%26 = call i64 @read(i32 %24, i8* %25, i32 3)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 2
store i8 0, i8* %29
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = call i32 @sleep(i32 1)
br label %23
33: ; preds = %23
%34 = load i32, i32* %2
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"./test1\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"./test2\00"
@.str.2 = [11 x i8] c"READ1: %s\0A\00"
@.str.3 = [11 x i8] c"READ2: %s\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca [3 x i8]
%3 = bitcast i16* %1 to i8*
store i16 0, i16* %1
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i64 @read(i32 %6, i8* %3, i32 2)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = bitcast i16* %1 to [2 x i8]*
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 1
br label %20
14: ; preds = %20, %0
%15 = call i64 @read(i32 %8, i8* %4, i32 3)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = getelementptr inbounds i16, i16* %1, i64 1
%19 = bitcast i16* %18 to i8*
br label %25
20: ; preds = %11, %20
store i8 0, i8* %13
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%22 = call i32 @sleep(i32 1)
%23 = call i64 @read(i32 %6, i8* %3, i32 2)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %20, label %14
25: ; preds = %17, %25
store i8 0, i8* %19
%26 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%27 = call i32 @sleep(i32 1)
%28 = call i64 @read(i32 %8, i8* %4, i32 3)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %25, label %30
30: ; preds = %25, %14
%31 = call i32 @close(i32 %6)
%32 = call i32 @close(i32 %8)
ret i32 0
}