#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ errExit(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ writeStuff(int, char *);
int main(int argc, char *argv[]) {
  int fd = open("sparse_file", O_WRONLY | O_CREAT | O_TRUNC,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
  if (fd == -1)
    errExit("Open");
  writeStuff(fd, "Beginning of file");
  if (lseek(fd, 100, SEEK_END) == -1)
    errExit("lseek");
  writeStuff(fd, "Sparse bit!");
  if (close(fd) == -1)
    errExit("close");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    0x2e72(%rip),%rax
or     (%rax),%esi
mov    0x2e61(%rip),%rax
or     (%rax),%esi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    0x2e27(%rip),%rax
or     (%rax),%edx
mov    0x2e0e(%rip),%rax
or     (%rax),%edx
mov    0x2e1d(%rip),%rax
or     (%rax),%edx
mov    0x2df4(%rip),%rax
or     (%rax),%edx
lea    0xe3b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e3 <main+0x83>
lea    0xe2e(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x14(%rbp),%edi
lea    0xe24(%rip),%rsi
call   1030 <writeStuff@plt>
mov    -0x14(%rbp),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    121d <main+0xbd>
lea    0xe0b(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x14(%rbp),%edi
lea    0xe02(%rip),%rsi
call   1030 <writeStuff@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1249 <main+0xe9>
lea    0xdf1(%rip),%rdi
call   1040 <errExit@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e28(%rip),%rax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
mov    0x2e25(%rip),%rax
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e23(%rip),%rax
or     (%rax),%edx
mov    0x2e32(%rip),%rax
or     (%rax),%edx
mov    0x2e09(%rip),%rax
or     (%rax),%edx
lea    0xe50(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11c8 <main+0x68>
lea    0xe49(%rip),%rdi
call   1040 <errExit@plt>
lea    0xe42(%rip),%rsi
mov    %ebx,%edi
call   1030 <writeStuff@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x64,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11fc <main+0x9c>
lea    0xe2c(%rip),%rdi
call   1040 <errExit@plt>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
call   1030 <writeStuff@plt>
mov    %ebx,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1222 <main+0xc2>
lea    0xe18(%rip),%rdi
call   1040 <errExit@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"sparse_file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"Open\00"
@.str.2 = [18 x i8] c"Beginning of file\00"
@SEEK_END = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [12 x i8] c"Sparse bit!\00"
@.str.5 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @errExit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
%27 = load i32, i32* %6
%28 = call i32 @writeStuff(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = load i32, i32* @SEEK_END
%31 = call i32 @lseek(i32 %29, i32 100, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = load i32, i32* %6
%37 = call i32 @writeStuff(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = load i32, i32* @EXIT_SUCCESS
%45 = call i32 @exit(i32 %44)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"sparse_file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"Open\00"
@.str.2 = [18 x i8] c"Beginning of file\00"
@SEEK_END = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [12 x i8] c"Sparse bit!\00"
@.str.5 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IWGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IROTH
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = tail call i32 @errExit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = tail call i32 @writeStuff(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @SEEK_END
%24 = tail call i32 @lseek(i32 %17, i32 100, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = tail call i32 @writeStuff(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%30 = tail call i32 @close(i32 %17)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = load i32, i32* @EXIT_SUCCESS
%36 = tail call i32 @exit(i32 %35)
unreachable
}