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

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fchmod(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *malloc(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int pwrite(int, char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int unlink(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  if (argc < 2)
    usage();
  int hfile = open(argv[1], O_CREAT | O_EXCL | O_RDWR);
  if (hfile == -1) {
    fprintf(stderr, "Can not create file %s: %s\n", argv[1], strerror(errno));
    _exit(-1);
  }
  fchmod(hfile, 0644);
  printf("file %s has been created\n", argv[1]);
  printf("writing %d + %d bytes ... ", (50 * 1024 * 1024), (50 * 1024 * 1024));
  char *buf = malloc((50 * 1024 * 1024));
  ssize_t write = pwrite(hfile, buf, (50 * 1024 * 1024), (50 * 1024 * 1024));
  if (write == -1 || write < (50 * 1024 * 1024)) {
    printf("%s\n", strerror(errno));
  } else {
    printf("done: %ld bytes\n", write);
  }
  if (unlink(argv[1]) == -1) {
    printf("Error delete file %s: %s\n", argv[1], strerror(errno));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c7 <main+0x27>
mov    $0x0,%al
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2df8(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1242 <main+0xa2>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdcd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <_exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1a4,%esi
call   10a0 <fchmod@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdca(%rip),%rdi
mov    $0x3200000,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3200000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x3200000,%ecx
mov    %ecx,%edx
call   1080 <pwrite@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     12b5 <main+0x115>
cmpl   $0x3200000,-0x24(%rbp)
jge    12d9 <main+0x139>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ea <main+0x14a>
mov    -0x24(%rbp),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    132f <main+0x18f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11c2 <main+0x12>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    0x2e2f(%rip),%rax
mov    0x2df8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%rbx),%rdi
mov    0x2e01(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     12b1 <main+0x101>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1a4,%esi
call   10b0 <fchmod@plt>
mov    0x8(%rbx),%rsi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x3200000,%esi
mov    $0x3200000,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x3200000,%edi
call   1080 <malloc@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x3200000,%edx
mov    $0x3200000,%ecx
call   1090 <pwrite@plt>
cmp    $0x31fffff,%eax
jg     1264 <main+0xb4>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
jmp    1274 <main+0xc4>
lea    0xde6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    12a8 <main+0xf8>
mov    0x8(%rbx),%rbx
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdc7(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d18(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd2d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Can not create file %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"file %s has been created\0A\00"
@.str.2 = [27 x i8] c"writing %d + %d bytes ... \00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [17 x i8] c"done: %ld bytes\0A\00"
@.str.5 = [26 x i8] c"Error delete file %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_EXCL
%19 = or i32 %17, %18
%20 = load i32, i32* @O_RDWR
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %16, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %34
25: ; preds = %13
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %31)
%33 = call i32 @_exit(i32 -1)
unreachable
34: ; preds = %13
%35 = load i32, i32* %6
%36 = call i32 @fchmod(i32 %35, i32 420)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 52428800, i32 52428800)
%42 = call i8* @malloc(i32 52428800)
store i8* %42, i8** %7
%43 = load i32, i32* %6
%44 = load i8*, i8** %7
%45 = call i32 @pwrite(i32 %43, i8* %44, i32 52428800, i32 52428800)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, -1
br i1 %47, label %51, label %48
48: ; preds = %34
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 52428800
br i1 %50, label %51, label %55
51: ; preds = %48, %34
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %58
55: ; preds = %48
%56 = load i32, i32* %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %51
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @unlink(i8* %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %71
64: ; preds = %58
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %67, i8* %69)
br label %71
71: ; preds = %64, %58
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Can not create file %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"file %s has been created\0A\00"
@.str.2 = [27 x i8] c"writing %d + %d bytes ... \00"
@.str.4 = [17 x i8] c"done: %ld bytes\0A\00"
@.str.5 = [26 x i8] c"Error delete file %s: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_EXCL
%11 = or i32 %10, %9
%12 = load i32, i32* @O_RDWR
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* %8, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %6
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %7
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
%22 = tail call i32 @_exit(i32 -1)
unreachable
23: ; preds = %6
%24 = tail call i32 @fchmod(i32 %14, i32 420)
%25 = load i8*, i8** %7
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 52428800, i32 52428800)
%28 = tail call dereferenceable_or_null(52428800) i8* @malloc(i32 52428800)
%29 = tail call i32 @pwrite(i32 %14, i8* %28, i32 52428800, i32 52428800)
%30 = icmp slt i32 %29, 52428800
br i1 %30, label %31, label %35
31: ; preds = %23
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 @puts(i8* dereferenceable(1) %33)
br label %37
35: ; preds = %23
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %37
37: ; preds = %35, %31
%38 = load i8*, i8** %7
%39 = tail call i32 @unlink(i8* %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i8*, i8** %7
%43 = load i32, i32* @errno
%44 = tail call i8* @strerror(i32 %43)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %42, i8* %44)
br label %46
46: ; preds = %41, %37
ret i32 0
}