#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, cnt, res;
  ssize_t ret;
  fd = open(argv[1], O_WRONLY);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  res = lseek(fd, 1073741824, SEEK_SET);
  if (res < 0) {
    perror("lseek");
    exit(1);
  }
  cnt = 16;
  do {
    ret = write(fd, "XXXXXXXXXXXXXXXX", 16);
    if (ret < 0) {
      perror("write");
      exit(1);
    }
    cnt -= ret;
  } while (cnt > 0);
  if (close(fd) < 0) {
    perror("close");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11af <main+0x4f>
lea    0xe60(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    $0x40000000,%esi
call   1040 <lseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e8 <main+0x88>
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x10,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe12(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1228 <main+0xc8>
lea    0xe03(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rcx
movslq -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     11ef <main+0x8f>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    1268 <main+0x108>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11f7 <main+0x97>
mov    %eax,%ebp
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x40000000,%esi
call   1040 <lseek@plt>
test   %eax,%eax
js     1200 <main+0xa0>
mov    $0x10,%ebx
lea    0xe6a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <write@plt>
test   %rax,%rax
js     11e1 <main+0x81>
movslq %ebx,%rbx
sub    %rax,%rbx
test   %ebx,%ebx
jg     11b0 <main+0x50>
mov    %ebp,%edi
call   1050 <close@plt>
test   %rax,%rax
js     1209 <main+0xa9>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe02(%rip),%rdi
jmp    11e8 <main+0x88>
lea    0xdfe(%rip),%rdi
jmp    11e8 <main+0x88>
lea    0xe12(%rip),%rdi
jmp    11e8 <main+0x88>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [17 x i8] c"XXXXXXXXXXXXXXXX\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [6 x i8] c"close\00"
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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %6
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @lseek(i32 %21, i32 1073741824, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
store i32 16, i32* %7
br label %30
30: ; preds = %44, %29
%31 = load i32, i32* %6
%32 = call i64 @write(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 16)
store i64 %32, i64* %9
%33 = load i64, i64* %9
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %30
%39 = load i64, i64* %9
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = sub nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %7
br label %44
44: ; preds = %38
%45 = load i32, i32* %7
%46 = icmp sgt i32 %45, 0
br i1 %46, label %30, label %47
47: ; preds = %44
%48 = load i32, i32* %6
%49 = call i64 @close(i32 %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [17 x i8] c"XXXXXXXXXXXXXXXX\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* %4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @lseek(i32 %6, i32 1073741824, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %25
%19 = phi i64 [ %28, %25 ], [ 16, %11 ]
%20 = tail call i64 @write(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 16)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = shl i64 %19, 32
%27 = ashr exact i64 %26, 32
%28 = sub nsw i64 %27, %20
%29 = trunc i64 %28 to i32
%30 = icmp sgt i32 %29, 0
br i1 %30, label %18, label %31
31: ; preds = %25
%32 = tail call i64 @close(i32 %6)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %31
ret i32 0
}