#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 O_CREAT;
int O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd1 = open("fff", O_RDONLY | O_CREAT, 0777);
  int fd2 = open("fff", O_WRONLY);
  int fd3 = open("fff", O_RDWR);
  write(fd2, "hello world", 11);
  char buff[20];
  read(fd3, buff, 6);
  write(1, buff, 6);
  int cnt = read(fd1, buff, 5);
  write(1, buff, cnt);
  write(fd3, "chil", 4);
  write(fd2, "!!!", 3);
  read(fd1, buff, 9);
  write(1, buff, 9);
  close(fd1);
  close(fd2);
  close(fd3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe4f(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x6,%edx
call   1050 <read@plt>
lea    -0x30(%rbp),%rsi
mov    $0x1,%edi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x5,%edx
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
lea    0xdfe(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xdef(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x9,%edx
call   1050 <read@plt>
lea    -0x30(%rbp),%rsi
mov    $0x1,%edi
mov    $0x9,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e87(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe9d(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r15d
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe5d(%rip),%rsi
mov    %r15d,%edi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %rsp,%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe12(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe04(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x9,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x9,%edx
call   1030 <write@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"fff\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"hello world\00"
@.str.2 = [5 x i8] c"chil\00"
@.str.3 = [4 x i8] c"!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9, i32 511)
store i32 %10, i32* %2
%11 = load i32, i32* @O_WRONLY
%12 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* @O_RDWR
%14 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 6)
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%21 = call i32 @write(i32 1, i8* %20, i32 6)
%22 = load i32, i32* %2
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 5)
store i32 %24, i32* %6
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* %6
%27 = call i32 @write(i32 1, i8* %25, i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%30 = load i32, i32* %3
%31 = call i32 @write(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%32 = load i32, i32* %2
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 9)
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%36 = call i32 @write(i32 1, i8* %35, i32 9)
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* %3
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %4
%42 = call i32 @close(i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"fff\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"hello world\00"
@.str.2 = [5 x i8] c"chil\00"
@.str.3 = [4 x i8] c"!!!\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4, i32 511)
%6 = load i32, i32* @O_WRONLY
%7 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%12 = call i32 @read(i32 %9, i8* %11, i32 6)
%13 = call i32 @write(i32 1, i8* %11, i32 6)
%14 = call i32 @read(i32 %5, i8* %11, i32 5)
%15 = call i32 @write(i32 1, i8* %11, i32 %14)
%16 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%17 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%18 = call i32 @read(i32 %5, i8* %11, i32 9)
%19 = call i32 @write(i32 1, i8* %11, i32 9)
%20 = tail call i32 @close(i32 %5)
%21 = tail call i32 @close(i32 %7)
%22 = tail call i32 @close(i32 %9)
ret i32 0
}