#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__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
scalar_t__ *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                 int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(scalar_t__ *, int);
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
void seek_write(char *filename) {
  int fd;
  uint8_t *map;
  int i;
  fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
  lseek(fd, 1048576 - 1, SEEK_SET);
  write(fd, "\xff", 1);
  map = mmap(NULL, 1048576, PROT_READ, MAP_PRIVATE, fd, 0);
  for (i = 0; i < (1048576 - 1); i++) {
    if (map[i] != 0)
      abort();
  }
  munmap(map, 1048576);
  close(fd);
}


x86 assembly (clang, -O0):
<seek_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    $0xfffff,%esi
call   1060 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    0x2dd6(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100000,%esi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xfffff,-0x1c(%rbp)
jge    123e <seek_write+0xce>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     122b <seek_write+0xbb>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1230 <seek_write+0xc0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <seek_write+0x94>
mov    -0x18(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seek_write>:
push   %rbx
mov    0x2e58(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1090 <open@plt>
mov    %eax,%ebx
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffff,%esi
call   1060 <lseek@plt>
lea    0xe4c(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    0x2de8(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x100000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    $0x4,%ecx
nopl   0x0(%rax)
cmpq   $0x0,-0x20(%rax,%rcx,8)
jne    1239 <seek_write+0xc9>
cmpq   $0x0,-0x18(%rax,%rcx,8)
jne    1239 <seek_write+0xc9>
cmpq   $0x0,-0x10(%rax,%rcx,8)
jne    1239 <seek_write+0xc9>
cmpq   $0x0,-0x8(%rax,%rcx,8)
jne    1239 <seek_write+0xc9>
cmpq   $0x0,(%rax,%rcx,8)
jne    1239 <seek_write+0xc9>
add    $0x5,%rcx
cmp    $0x100003,%rcx
jne    11f0 <seek_write+0x80>
mov    %rax,%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1070 <close@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\FF\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define void @seek_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %6, i32 %11, i32 384)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 1048575, i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @MAP_PRIVATE
%20 = load i32, i32* %3
%21 = call i64* @mmap(i32* null, i32 1048576, i32 %18, i32 %19, i32 %20, i32 0)
store i64* %21, i64** %4
store i32 0, i32* %5
br label %22
22: ; preds = %35, %1
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 1048575
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i64*, i64** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
%30 = load i64, i64* %29
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %25
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %22
38: ; preds = %22
%39 = load i64*, i64** %4
%40 = call i32 @munmap(i64* %39, i32 1048576)
%41 = load i32, i32* %3
%42 = call i32 @close(i32 %41)
ret void
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\FF\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define void @seek_write(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* %0, i32 %6, i32 384)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %7, i32 1048575, i32 %8)
%10 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_PRIVATE
%13 = tail call i64* @mmap(i32* null, i32 1048576, i32 %11, i32 %12, i32 %7, i32 0)
br label %37
14: ; preds = %37
%15 = add nuw nsw i64 %38, 1
%16 = getelementptr inbounds i64, i64* %13, i64 %15
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %42
19: ; preds = %14
%20 = add nuw nsw i64 %38, 2
%21 = getelementptr inbounds i64, i64* %13, i64 %20
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %19
%25 = add nuw nsw i64 %38, 3
%26 = getelementptr inbounds i64, i64* %13, i64 %25
%27 = load i64, i64* %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %24
%30 = add nuw nsw i64 %38, 4
%31 = getelementptr inbounds i64, i64* %13, i64 %30
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = add nuw nsw i64 %38, 5
%36 = icmp eq i64 %35, 1048575
br i1 %36, label %44, label %37
37: ; preds = %34, %1
%38 = phi i64 [ 0, %1 ], [ %35, %34 ]
%39 = getelementptr inbounds i64, i64* %13, i64 %38
%40 = load i64, i64* %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %14, label %42
42: ; preds = %29, %24, %19, %14, %37
%43 = tail call i32 (...) @abort()
unreachable
44: ; preds = %34
%45 = tail call i32 @munmap(i64* %13, i32 1048576)
%46 = tail call i32 @close(i32 %7)
ret void
}