#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*/ loff_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ read(int, void *, int);
int /*<<< orphan*/ write(int, void *, int);
int main() {
  int fd;
  loff_t res;
  char buf[64], buf1[32], buf2[32], buf3[32];
  fd = open("foobar1", O_WRONLY | O_CREAT, 0666);
  write(fd, "Hello world", 11);
  write(fd, "Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789", 59);
  write(-1, "Hello world", 11);
  write(fd, (void *)-1, 11);
  write(-1, NULL, -1);
  close(fd);
  fd = open("foobar1", O_RDONLY);
  read(fd, buf, 11);
  read(fd, buf, 50);
  read(-1, buf, 50);
  read(fd, (void *)-1, 50);
  read(-1, NULL, -1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
lea    0xe95(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe7c(%rip),%rsi
mov    $0x3b,%edx
call   1030 <write@plt>
mov    $0xffffffff,%edi
lea    0xe5a(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0xffffffff,%edx
xor    %eax,%eax
mov    %eax,%esi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xb,%edx
call   1050 <read@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1050 <read@plt>
lea    -0x50(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x32,%edx
call   1050 <read@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x32,%edx
call   1050 <read@plt>
mov    $0xffffffff,%edx
xor    %eax,%eax
mov    %eax,%esi
mov    %edx,%edi
call   1050 <read@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    0x2e79(%rip),%rax
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xe8f(%rip),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
lea    0xe85(%rip),%rsi
mov    %ebp,%edi
mov    $0x3b,%edx
call   1030 <write@plt>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
call   1050 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1050 <read@plt>
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1050 <read@plt>
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x32,%edx
call   1050 <read@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [60 x i8] c"Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
store i32 0, i32* %1
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10, i32 438)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%14 = load i32, i32* %2
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 59)
%16 = call i32 @write(i32 -1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%17 = load i32, i32* %2
%18 = call i32 @write(i32 %17, i8* inttoptr (i64 -1 to i8*), i32 11)
%19 = call i32 @write(i32 -1, i8* null, i32 -1)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* @O_RDONLY
%23 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 11)
%27 = load i32, i32* %2
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 50)
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%31 = call i32 @read(i32 -1, i8* %30, i32 50)
%32 = load i32, i32* %2
%33 = call i32 @read(i32 %32, i8* inttoptr (i64 -1 to i8*), i32 50)
%34 = call i32 @read(i32 -1, i8* null, i32 -1)
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [60 x i8] c"Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
%7 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%8 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 59)
%9 = tail call i32 @write(i32 -1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%10 = tail call i32 @write(i32 %6, i8* inttoptr (i64 -1 to i8*), i32 11)
%11 = tail call i32 @write(i32 -1, i8* null, i32 -1)
%12 = tail call i32 @close(i32 %6)
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @read(i32 %14, i8* %2, i32 11)
%16 = call i32 @read(i32 %14, i8* %2, i32 50)
%17 = call i32 @read(i32 -1, i8* %2, i32 50)
%18 = tail call i32 @read(i32 %14, i8* inttoptr (i64 -1 to i8*), i32 50)
%19 = tail call i32 @read(i32 -1, i8* null, i32 -1)
%20 = tail call i32 @close(i32 %14)
ret i32 0
}