#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  int fd = open("sparse1.file", O_RDWR | O_CREAT);
  for (i = 0; i < 1024 * 1024 / 2; i++) {
    lseek(fd, i, SEEK_CUR);
    write(fd, "f", 1);
  }
  lseek(fd, 1024 * 1024, SEEK_CUR);
  write(fd, "f", 1);
  return 0;
}


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    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2ea2(%rip),%rax
or     (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80000,-0x14(%rbp)
jge    11b1 <main+0x81>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x18(%rbp),%edi
lea    0xe74(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <main+0x3e>
mov    -0x18(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    $0x100000,%esi
call   1040 <lseek@plt>
mov    -0x18(%rbp),%edi
lea    0xe3c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ea2(%rip),%rax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    0x2e78(%rip),%r15
lea    0xea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%ebp
cmp    $0x80000,%ebp
jne    1170 <main+0x40>
mov    (%r15),%edx
mov    %ebx,%edi
mov    $0x100000,%esi
call   1040 <lseek@plt>
lea    0xe61(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"sparse1.file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [2 x i8] c"f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %7
store i32 0, i32* %6
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 524288
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* @SEEK_CUR
%19 = call i32 @lseek(i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %7
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %22
22: ; preds = %15
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %12
25: ; preds = %12
%26 = load i32, i32* %7
%27 = load i32, i32* @SEEK_CUR
%28 = call i32 @lseek(i32 %26, i32 1048576, i32 %27)
%29 = load i32, i32* %7
%30 = call i32 @write(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"sparse1.file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [2 x i8] c"f\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %12, %7 ]
%9 = load i32, i32* @SEEK_CUR
%10 = tail call i32 @lseek(i32 %6, i32 %8, i32 %9)
%11 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, 524288
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = load i32, i32* @SEEK_CUR
%16 = tail call i32 @lseek(i32 %6, i32 1048576, i32 %15)
%17 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret i32 0
}