#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 errno;
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = -1;
  int write_ret = -1;
  int page_size = 131072;
  char c = '1';
  if (argc != 2) {
    printf("\nUsage: %s filepath\n", argv[0]);
    exit(-1);
  }
  fd = open(argv[1], O_RDWR | O_CREAT, 0644);
  if (fd < 0) {
    perror("open");
    exit(errno);
  }
  while (page_size) {
    write_ret = write(fd, &c, 1);
    if (write_ret != 1) {
      perror("write");
      break;
    }
    page_size--;
  }
  while (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)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x20000,-0x1c(%rbp)
movb   $0x31,-0x1d(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f1 <main+0xa1>
lea    0xe37(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11f6 <main+0xa6>
cmpl   $0x0,-0x1c(%rbp)
je     123d <main+0xed>
mov    -0x14(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     122f <main+0xdf>
lea    0xdf5(%rip),%rdi
call   1060 <perror@plt>
jmp    123d <main+0xed>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <main+0xa6>
jmp    1242 <main+0xf2>
jmp    1242 <main+0xf2>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movb   $0x31,0xf(%rsp)
cmp    $0x2,%edi
jne    11d0 <main+0x80>
mov    0x8(%rsi),%rdi
mov    0x2e73(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11e9 <main+0x99>
mov    %eax,%ebx
mov    $0xfffe0000,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11c2 <main+0x72>
inc    %ebp
jne    11a0 <main+0x50>
nopl   0x0(%rax,%rax,1)
jmp    11c0 <main+0x70>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
jmp    11c0 <main+0x70>
mov    (%rsi),%rsi
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"\0AUsage: %s filepath\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"write\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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 131072, i32* %8
store i8 49, i8* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_CREAT
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %21, i32 %24, i32 420)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @errno
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %18
br label %33
33: ; preds = %43, %32
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32, i32* %6
%38 = call i32 @write(i32 %37, i8* %9, i32 1)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %46
43: ; preds = %36
%44 = load i32, i32* %8
%45 = add nsw i32 %44, -1
store i32 %45, i32* %8
br label %33
46: ; preds = %41, %33
br label %47
47: ; preds = %46, %47
br label %47
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0AUsage: %s filepath\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
store i8 49, i8* %3
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* %11, i32 %14, i32 420)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @errno
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %23
%22 = icmp eq i32 %27, 0
br i1 %22, label %30, label %23
23: ; preds = %9, %21
%24 = phi i32 [ %27, %21 ], [ 131072, %9 ]
%25 = call i32 @write(i32 %15, i8* %3, i32 1)
%26 = icmp eq i32 %25, 1
%27 = add nsw i32 %24, -1
br i1 %26, label %21, label %28
28: ; preds = %23
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %21, %28
br label %31
31: ; preds = %30, %31
br label %31
}