#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 int /*<<< orphan*/ buf1;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd1;
  int fd2;
  char buf1[1024] = {};
  char buf2[1024] = {};
  if ((fd1 = open("furong", O_RDONLY)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day03/file.c",
              23, "open", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if ((fd2 = open("furong", O_RDWR)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day03/file.c",
              25, "open", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  read(fd1, buf1, 5);
  read(fd2, buf2, 5);
  printf("buf1=%s\n", buf1);
  printf("buf2=%s\n", buf2);
  write(fd2, "AAAAA", 5);
  memset(buf1, 0x00, sizeof(buf1));
  read(fd1, buf1, 5);
  printf("buf1=%s\n", buf1);
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1241 <main+0xb1>
jmp    11ee <main+0x5e>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x814(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x814(%rbp),%edi
mov    %rax,%r9
lea    0xdec(%rip),%rsi
lea    0xdf5(%rip),%rdx
mov    $0x17,%ecx
lea    0xe7c(%rip),%r8
call   1080 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0xdaf(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12ba <main+0x12a>
jmp    1267 <main+0xd7>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x818(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x818(%rbp),%edi
mov    %rax,%r9
lea    0xd73(%rip),%rsi
lea    0xd7c(%rip),%rdx
mov    $0x19,%ecx
lea    0xe03(%rip),%r8
call   1080 <fprintf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x5,%edx
call   1070 <read@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x5,%edx
call   1070 <read@plt>
lea    -0x410(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
lea    -0x810(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xdaf(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x5,%edx
call   1070 <read@plt>
lea    -0x410(%rbp),%rsi
lea    0xd5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12a8 <main+0x118>
mov    %eax,%ebx
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe0e(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12dd <main+0x14d>
mov    %eax,%ebp
lea    0x400(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1070 <read@plt>
mov    %rsp,%r12
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x5,%edx
call   1070 <read@plt>
lea    0xe7d(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
lea    0xe6e(%rip),%rsi
mov    %ebp,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1070 <read@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d21(%rip),%rax
mov    (%rax),%ebx
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd41(%rip),%rsi
lea    0xd4a(%rip),%rdx
lea    0xdd6(%rip),%r8
mov    %ebx,%edi
mov    $0x17,%ecx
jmp    1310 <main+0x180>
mov    0x2cec(%rip),%rax
mov    (%rax),%ebx
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd0c(%rip),%rsi
lea    0xd15(%rip),%rdx
lea    0xda1(%rip),%r8
mov    %ebx,%edi
mov    $0x19,%ecx
mov    %rax,%r9
call   1080 <fprintf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"furong\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day03/file.c\00"
@.str.3 = [5 x i8] c"open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@.str.4 = [9 x i8] c"buf1=%s\0A\00"
@.str.5 = [9 x i8] c"buf2=%s\0A\00"
@.str.6 = [6 x i8] c"AAAAA\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = bitcast [1024 x i8]* %4 to i8*
%7 = bitcast [1024 x i8]* %5 to i8*
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %0
br label %12
12: ; preds = %11
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; No predecessors!
br label %20
20: ; preds = %19, %0
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %3
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %33
24: ; preds = %20
br label %25
25: ; preds = %24
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; No predecessors!
br label %33
33: ; preds = %32, %20
%34 = load i32, i32* %2
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 5)
%37 = load i32, i32* %3
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 5)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %3
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i32 0, i32 1024)
%48 = load i32, i32* %2
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%50 = call i32 @read(i32 %48, i8* %49, i32 5)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%52 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %2
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %3
%56 = call i32 @close(i32 %55)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"furong\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day03/file.c\00"
@.str.3 = [5 x i8] c"open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@.str.4 = [9 x i8] c"buf1=%s\0A\00"
@.str.5 = [9 x i8] c"buf2=%s\0A\00"
@.str.6 = [6 x i8] c"AAAAA\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = call i32 @read(i32 %6, i8* %3, i32 5)
%28 = call i32 @read(i32 %17, i8* %4, i32 5)
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%30 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%31 = call i32 @write(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%32 = call i32 @memset(i8* %3, i32 0, i32 1024)
%33 = call i32 @read(i32 %6, i8* %3, i32 5)
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%35 = call i32 @close(i32 %6)
%36 = call i32 @close(i32 %17)
ret i32 0
}