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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
int main(void) {
  char buf1[] = "abcdefghij";
  char buf2[] = "ABCDEFGHIJ";
  int fd;
  if ((fd = creat("file.hole", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    perror("cannot create file.hole");
    exit(1);
  }
  if (write(fd, buf1, sizeof(buf1)) != sizeof(buf1)) {
    perror("cannot write buf1");
    exit(1);
  }
  if (lseek(fd, 16384, SEEK_SET) == -1) {
    perror("lseek error");
    exit(1);
  }
  if (write(fd, buf2, sizeof(buf2)) != sizeof(buf2)) {
    perror("cannot write buf2");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xe97(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe8f(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xe86(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xe83(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xe7b(%rip),%al
mov    %al,-0x10(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2e09(%rip),%rax
or     (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11ef <main+0x9f>
lea    0xe36(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cltq
cmp    $0xb,%rax
je     1222 <main+0xd2>
lea    0xe1b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
mov    $0x4000,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1257 <main+0x107>
lea    0xdf8(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cltq
cmp    $0xb,%rax
je     128a <main+0x13a>
lea    0xdd1(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movabs $0x6867666564636261,%rax
66 67 68
mov    %rax,0x10(%rsp)
movl   $0x6a6968,0x17(%rsp)
mov    0x2e4d(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movabs $0x4847464544434241,%rax
46 47 48
mov    %rax,(%rsp)
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
movl   $0x4a4948,0x7(%rsp)
mov    0x2e24(%rip),%rax
or     (%rax),%esi
lea    0xe77(%rip),%rdi
call   1060 <creat@plt>
test   %eax,%eax
js     1204 <main+0xb4>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xb,%eax
jne    120d <main+0xbd>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x4000,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1216 <main+0xc6>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xb,%eax
jne    121f <main+0xcf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
jmp    1226 <main+0xd6>
lea    0xe1a(%rip),%rdi
jmp    1226 <main+0xd6>
lea    0xe23(%rip),%rdi
jmp    1226 <main+0xd6>
lea    0xe26(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.buf1 = [11 x i8] c"abcdefghij\00"
@__const.main.buf2 = [11 x i8] c"ABCDEFGHIJ\00"
@.str = [10 x i8] c"file.hole\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [24 x i8] c"cannot create file.hole\00"
@.str.2 = [18 x i8] c"cannot write buf1\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"lseek error\00"
@.str.4 = [18 x i8] c"cannot write buf2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca [11 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [11 x i8]* %2 to i8*
%6 = bitcast [11 x i8]* %3 to i8*
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = load i32, i32* %4
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 11)
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %23, 11
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i32, i32* %4
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @lseek(i32 %29, i32 16384, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = load i32, i32* %4
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%39 = call i32 @write(i32 %37, i8* %38, i32 11)
%40 = sext i32 %39 to i64
%41 = icmp ne i64 %40, 11
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf1 = [11 x i8] c"abcdefghij\00"
@__const.main.buf2 = [11 x i8] c"ABCDEFGHIJ\00"
@.str = [10 x i8] c"file.hole\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [24 x i8] c"cannot create file.hole\00"
@.str.2 = [18 x i8] c"cannot write buf1\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"lseek error\00"
@.str.4 = [18 x i8] c"cannot write buf2\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IROTH
%11 = or i32 %9, %10
%12 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 @write(i32 %12, i8* %3, i32 11)
%19 = icmp eq i32 %18, 11
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %12, i32 16384, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = call i32 @write(i32 %12, i8* %4, i32 11)
%32 = icmp eq i32 %31, 11
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %30
ret i32 0
}