#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_ASYNC;
int O_CREAT;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  int res;
  char *buf;
  unlink(argv[1]);
  fd = open(argv[1], O_ASYNC | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
  buf = (char *)calloc(1, (100 * 1000 * 1000));
  printf("%u: Before write\n", time(NULL));
  res = write(fd, buf, (100 * 1000 * 1000));
  printf("%u: After write (%d)\n", time(NULL), res);
  close(fd);
  printf("%u: After close\n", time(NULL));
  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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
mov    0x2e04(%rip),%rax
or     (%rax),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    0x2e1a(%rip),%rax
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
mov    $0x5f5e100,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x5f5e100,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%esi
mov    -0x18(%rbp),%edx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1030 <unlink@plt>
mov    0x8(%rbx),%rdi
mov    0x2e3e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e1c(%rip),%rax
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
mov    0x2e34(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    $0x5f5e100,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
lea    0xe29(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5f5e100,%edx
call   1040 <write@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1080 <time@plt>
lea    0xe13(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <time@plt>
lea    0xe09(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_ASYNC = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [18 x i8] c"%u: Before write\0A\00"
@.str.1 = [22 x i8] c"%u: After write (%d)\0A\00"
@.str.2 = [17 x i8] c"%u: After close\0A\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @unlink(i8* %11)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_ASYNC
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @O_WRONLY
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %15, i32 %20, i32 %23)
store i32 %24, i32* %6
%25 = call i64 @calloc(i32 1, i32 100000000)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %8
%27 = call i32 @time(i32* null)
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = load i8*, i8** %8
%31 = call i32 @write(i32 %29, i8* %30, i32 100000000)
store i32 %31, i32* %7
%32 = call i32 @time(i32* null)
%33 = load i32, i32* %7
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
%37 = call i32 @time(i32* null)
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@O_ASYNC = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [18 x i8] c"%u: Before write\0A\00"
@.str.1 = [22 x i8] c"%u: After write (%d)\0A\00"
@.str.2 = [17 x i8] c"%u: After close\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @unlink(i8* %4)
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_ASYNC
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* %6, i32 %11, i32 %14)
%16 = tail call i64 @calloc(i32 1, i32 100000000)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @time(i32* null)
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = tail call i32 @write(i32 %15, i8* %17, i32 100000000)
%21 = tail call i32 @time(i32* null)
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %20)
%23 = tail call i32 @close(i32 %15)
%24 = tail call i32 @time(i32* null)
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}