#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 SEEK_CUR;
int SEEK_END;
int SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int);
int open(char *, int, ...);
int /*<<< orphan*/ pread(int, char *, int, int);
int /*<<< orphan*/ pwrite(int, char *, int, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, 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);
  pwrite(fd, "Hello Again", 11, 12);
  lseek(fd, 0, SEEK_SET);
  lseek(fd, 1, SEEK_CUR);
  lseek(-1, 0, SEEK_SET);
  lseek(fd, -1, SEEK_END);
  lseek(fd, 0, -1);
  close(fd);
  fd = open("foobar1", O_RDONLY);
  read(fd, buf, 11);
  read(fd, buf, 50);
  pread(fd, buf, 11, 10);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe54(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe4c(%rip),%rsi
mov    $0x3b,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe74(%rip),%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1070 <pwrite@plt>
mov    -0x8(%rbp),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <lseek@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xb,%edx
call   1060 <read@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1060 <read@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xb,%edx
mov    $0xa,%ecx
call   1090 <pread@plt>
mov    -0x8(%rbp),%edi
call   1050 <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    0x2e31(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe6f(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
lea    0xe5f(%rip),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <write@plt>
lea    0xe58(%rip),%rsi
mov    %ebp,%edi
mov    $0x3b,%edx
call   1030 <write@plt>
lea    0xe81(%rip),%rsi
mov    %ebp,%edi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1070 <pwrite@plt>
mov    0x2dd9(%rip),%rbx
mov    (%rbx),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <lseek@plt>
mov    (%rbx),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xffffffff,%esi
call   1040 <lseek@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1040 <lseek@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
call   1060 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1060 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
mov    $0xa,%ecx
call   1090 <pread@plt>
mov    %ebx,%edi
call   1050 <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"
@.str.3 = [12 x i8] c"Hello Again\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@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 = load i32, i32* %2
%17 = call i32 @pwrite(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11, i32 12)
%18 = load i32, i32* %2
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @lseek(i32 %18, i32 0, i32 %19)
%21 = load i32, i32* %2
%22 = load i32, i32* @SEEK_CUR
%23 = call i32 @lseek(i32 %21, i32 1, i32 %22)
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @lseek(i32 -1, i32 0, i32 %24)
%26 = load i32, i32* %2
%27 = load i32, i32* @SEEK_END
%28 = call i32 @lseek(i32 %26, i32 -1, i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @lseek(i32 %29, i32 0, i32 -1)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* @O_RDONLY
%34 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %33)
store i32 %34, i32* %2
%35 = load i32, i32* %2
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%37 = call i32 @read(i32 %35, i8* %36, i32 11)
%38 = load i32, i32* %2
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 50)
%41 = load i32, i32* %2
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%43 = call i32 @pread(i32 %41, i8* %42, i32 11, i32 10)
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
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"
@.str.3 = [12 x i8] c"Hello Again\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@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 @pwrite(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11, i32 12)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %6, i32 0, i32 %10)
%12 = load i32, i32* @SEEK_CUR
%13 = tail call i32 @lseek(i32 %6, i32 1, i32 %12)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @lseek(i32 -1, i32 0, i32 %14)
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @lseek(i32 %6, i32 -1, i32 %16)
%18 = tail call i32 @lseek(i32 %6, i32 0, i32 -1)
%19 = tail call i32 @close(i32 %6)
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @read(i32 %21, i8* %2, i32 11)
%23 = call i32 @read(i32 %21, i8* %2, i32 50)
%24 = call i32 @pread(i32 %21, i8* %2, i32 11, i32 10)
%25 = tail call i32 @close(i32 %21)
ret i32 0
}