#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 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);
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);
  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);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
lea    0xe95(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe86(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <lseek@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2e0c(%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>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%rax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea3(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe98(%rip),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <write@plt>
mov    0x2e45(%rip),%r14
mov    (%r14),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <lseek@plt>
mov    (%r14),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xffffffff,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1040 <lseek@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = 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 @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 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %14, i32 0, i32 %15)
%17 = load i32, i32* %2
%18 = load i32, i32* @SEEK_CUR
%19 = call i32 @lseek(i32 %17, i32 1, i32 %18)
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 -1, i32 0, i32 %20)
%22 = load i32, i32* %2
%23 = load i32, i32* @SEEK_END
%24 = call i32 @lseek(i32 %22, i32 -1, i32 %23)
%25 = load i32, i32* %2
%26 = call i32 @lseek(i32 %25, i32 0, i32 -1)
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
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"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438)
%5 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %4, i32 0, i32 %6)
%8 = load i32, i32* @SEEK_CUR
%9 = tail call i32 @lseek(i32 %4, i32 1, i32 %8)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 -1, i32 0, i32 %10)
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @lseek(i32 %4, i32 -1, i32 %12)
%14 = tail call i32 @lseek(i32 %4, i32 0, i32 -1)
%15 = tail call i32 @close(i32 %4)
ret i32 0
}