#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;
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = -1, i;
  ssize_t size = -1;
  off_t offset = -1;
  char buf1[] = "01234567890";
  char buf2[] = "ABCDEFGHIJKLMN";
  char filename[] = "hole.txt";
  int len1 = sizeof(buf1) - 1;
  int len2 = sizeof(buf2) - 1;
  printf("sizeof(buf1) = %d ,sizeof(buf2) = %d\n", sizeof(buf1), sizeof(buf2));
  fd = open(filename, O_RDWR | O_CREAT, S_IRWXU);
  if (-1 == fd) {
    return -1;
  }
  size = write(fd, buf1, len1);
  if (size != len1) {
    close(fd);
    return -1;
  }
  offset = lseek(fd, 32, SEEK_SET);
  if (-1 == offset) {
    close(fd);
    return -1;
  }
  size = write(fd, buf2, len2);
  if (size != len2) {
    close(fd);
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xe7c(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    0xe76(%rip),%rax
mov    %rax,-0x3b(%rbp)
mov    0xe74(%rip),%eax
mov    %eax,-0x33(%rbp)
mov    0xe6e(%rip),%ax
mov    %ax,-0x2f(%rbp)
mov    0xe66(%rip),%al
mov    %al,-0x2d(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x44(%rbp)
mov    0xe5b(%rip),%al
mov    %al,-0x3c(%rbp)
movl   $0xb,-0x48(%rbp)
movl   $0xe,-0x4c(%rbp)
lea    0xe44(%rip),%rdi
mov    $0xc,%esi
mov    $0xf,%edx
call   1040 <printf@plt>
lea    -0x44(%rbp),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    0x2df5(%rip),%rax
or     (%rax),%esi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1230 <main+0xe0>
movl   $0xffffffff,-0x4(%rbp)
jmp    12de <main+0x18e>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x48(%rbp),%eax
je     1262 <main+0x112>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12de <main+0x18e>
mov    -0x14(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1050 <lseek@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    129d <main+0x14d>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12de <main+0x18e>
mov    -0x14(%rbp),%edi
lea    -0x3b(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4c(%rbp),%eax
je     12cf <main+0x17f>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12de <main+0x18e>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,0x18(%rsp)
movl   $0x303938,0x20(%rsp)
movabs $0x4e4d4c4b4a4948,%rax
mov    %rax,0x2f(%rsp)
movabs $0x4847464544434241,%rax
46 47 48
mov    %rax,0x28(%rsp)
movabs $0x7478742e656c6f68,%rax
74 78 74
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe7e(%rip),%rdi
mov    $0xc,%esi
mov    $0xf,%edx
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
call   1070 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1241 <main+0xf1>
mov    %eax,%ebp
lea    0x18(%rsp),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xb,%eax
jne    123a <main+0xea>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x20,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     123a <main+0xea>
lea    0x28(%rsp),%rsi
mov    %ebp,%edi
mov    $0xe,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
cmp    $0xe,%eax
setne  %bl
mov    %ebp,%edi
call   1060 <close@plt>
neg    %ebx
jmp    1241 <main+0xf1>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.main.buf1 = [12 x i8] c"01234567890\00"
@__const.main.buf2 = [15 x i8] c"ABCDEFGHIJKLMN\00"
@__const.main.filename = [9 x i8] c"hole.txt\00"
@.str = [38 x i8] c"sizeof(buf1) = %d ,sizeof(buf2) = %d\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = alloca [15 x i8]
%5 = alloca [9 x i8]
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 12, i32 15)
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IRWXU
%14 = call i32 @open(i8* %8, i32 %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %32, label %16
16: ; preds = %2
%17 = call i32 @write(i32 %14, i8* %6, i32 11)
%18 = icmp eq i32 %17, 11
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @close(i32 %14)
br label %32
21: ; preds = %16
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @lseek(i32 %14, i32 32, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @close(i32 %14)
br label %32
27: ; preds = %21
%28 = call i32 @write(i32 %14, i8* %7, i32 14)
%29 = icmp ne i32 %28, 14
%30 = tail call i32 @close(i32 %14)
%31 = sext i1 %29 to i32
br label %32
32: ; preds = %27, %2, %25, %19
%33 = phi i32 [ -1, %19 ], [ -1, %25 ], [ -1, %2 ], [ %31, %27 ]
ret i32 %33
}