#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 ssize_t;
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int write(int, char *, int);
int main(void) {
  int fd = -1;
  ssize_t size = -1;
  off_t offset = -1;
  char buf1[] = "01234567";
  char buf2[] = "abcdefgh";
  char filename[] = "hole.txt";
  int len = 8;
  fd = open(filename, O_RDWR | O_CREAT, 00700);
  if (-1 == fd) {
    return -1;
  }
  size = write(fd, buf1, len);
  if (size != len) {
    return -1;
  }
  offset = lseek(fd, 32, SEEK_SET);
  if (-1 == offset) {
    return -1;
  }
  size = write(fd, buf2, len);
  if (size != len) {
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x19(%rbp)
mov    0xe93(%rip),%al
mov    %al,-0x11(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x22(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x1a(%rbp)
mov    0xe7f(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe7d(%rip),%al
mov    %al,-0x23(%rbp)
movl   $0x8,-0x30(%rbp)
lea    -0x2b(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
mov    $0x1c0,%edx
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    11e4 <main+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x13a>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     120e <main+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x13a>
mov    -0x8(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1040 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
jne    1241 <main+0x101>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x13a>
mov    -0x8(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     126b <main+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x13a>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,0x28(%rsp)
movb   $0x0,0x30(%rsp)
movabs $0x6867666564636261,%rax
66 67 68
mov    %rax,0x18(%rsp)
movb   $0x0,0x20(%rsp)
movabs $0x7478742e656c6f68,%rax
74 78 74
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
mov    0x2e57(%rip),%rax
mov    0x2e68(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x8(%rsp),%rdi
mov    $0x1c0,%edx
call   1060 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11fe <main+0xbe>
mov    %eax,%ebp
lea    0x28(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x8,%eax
jne    11fe <main+0xbe>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x20,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0xbe>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x8,%eax
jne    11fe <main+0xbe>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf1 = [9 x i8] c"01234567\00"
@__const.main.buf2 = [9 x i8] c"abcdefgh\00"
@__const.main.filename = [9 x i8] c"hole.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [9 x i8]
%6 = alloca [9 x i8]
%7 = alloca [9 x i8]
%8 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
store i32 -1, i32* %4
%9 = bitcast [9 x i8]* %5 to i8*
%10 = bitcast [9 x i8]* %6 to i8*
%11 = bitcast [9 x i8]* %7 to i8*
store i32 8, i32* %8
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %12, i32 %15, i32 448)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %20
19: ; preds = %0
store i32 -1, i32* %1
br label %48
20: ; preds = %0
%21 = load i32, i32* %2
%22 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %8
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = load i32, i32* %8
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %1
br label %48
29: ; preds = %20
%30 = load i32, i32* %2
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @lseek(i32 %30, i32 32, i32 %31)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp eq i32 -1, %33
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 -1, i32* %1
br label %48
36: ; preds = %29
%37 = load i32, i32* %2
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %8
%40 = call i32 @write(i32 %37, i8* %38, i32 %39)
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = load i32, i32* %8
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %36
store i32 -1, i32* %1
br label %48
45: ; preds = %36
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
store i32 0, i32* %1
br label %48
48: ; preds = %45, %44, %35, %28, %19
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@__const.main.buf1 = [9 x i8] c"01234567\00"
@__const.main.buf2 = [9 x i8] c"abcdefgh\00"
@__const.main.filename = [9 x i8] c"hole.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [9 x i8]
%2 = alloca [9 x i8]
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = call i32 @open(i8* %6, i32 %9, i32 448)
%11 = icmp eq i32 %10, -1
br i1 %11, label %24, label %12
12: ; preds = %0
%13 = call i32 @write(i32 %10, i8* %4, i32 8)
%14 = icmp eq i32 %13, 8
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @lseek(i32 %10, i32 32, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = call i32 @write(i32 %10, i8* %5, i32 8)
%21 = icmp eq i32 %20, 8
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @close(i32 %10)
br label %24
24: ; preds = %19, %15, %12, %0, %22
%25 = phi i32 [ 0, %22 ], [ -1, %0 ], [ -1, %12 ], [ -1, %15 ], [ -1, %19 ]
ret i32 %25
}