#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 /*<<< orphan*/ filename;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fsync(int);
char *getenv(char *);
int getpid();
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd;
  int i;
  char buf[32 * 1024];
  char filename[PATH_MAX];
  printf("Starting dirty tests...\n");
  snprintf(filename, sizeof(filename), "%s/aiodio/file.xx.%d",
           getenv("TMP") ? getenv("TMP") : "/tmp", getpid());
  fd = open(filename, O_CREAT | O_WRONLY, 0666);
  memset(buf, 0xaa, sizeof(buf));
  for (i = 0; i < 3000; i++)
    write(fd, buf, sizeof(buf));
  fsync(fd);
  close(fd);
  unlink(filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8050,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x8030(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x8018(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x8038(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x8020(%rbp)
lea    0xe0b(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8030(%rbp),%rax
mov    %eax,-0x8024(%rbp)
lea    0xe20(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1235 <main+0x95>
lea    0xe0a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8040(%rbp)
jmp    1248 <main+0xa8>
lea    0xdf6(%rip),%rax
mov    %rax,-0x8040(%rbp)
jmp    1248 <main+0xa8>
mov    -0x8040(%rbp),%rax
mov    %rax,-0x8048(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x8024(%rbp),%esi
mov    -0x8048(%rbp),%rcx
mov    -0x8038(%rbp),%rdi
mov    %eax,%r8d
lea    0xd9e(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x8038(%rbp),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
mov    0x2d31(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10c0 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x8010(%rbp),%rdi
mov    $0xaa,%esi
mov    $0x8000,%edx
call   1090 <memset@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xbb8,-0xc(%rbp)
jge    12f2 <main+0x152>
mov    -0x8(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    $0x8000,%edx
call   1050 <write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12c3 <main+0x123>
mov    -0x8(%rbp),%edi
call   10b0 <fsync@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    -0x8038(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x8018(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8008,%rsp
mov    %rsp,%r12
mov    0x2e2a(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe42(%rip),%rdi
call   1050 <puts@plt>
lea    0xe2d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe22(%rip),%rbx
cmovne %rax,%rbx
xor    %eax,%eax
call   1070 <getpid@plt>
lea    0xdf7(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
mov    %eax,%r8d
call   1080 <snprintf@plt>
mov    0x2dd7(%rip),%rax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x1b6,%edx
call   10c0 <open@plt>
mov    %eax,%r13d
lea    -0x8030(%rbp),%r14
mov    %r14,%rdi
mov    $0xaa,%esi
mov    $0x8000,%edx
call   1090 <memset@plt>
mov    $0xbb8,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x8000,%edx
call   1060 <write@plt>
add    $0xffffffff,%ebx
jne    1260 <main+0xc0>
mov    %r13d,%edi
call   10b0 <fsync@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    %r15,%rdi
call   1040 <unlink@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [25 x i8] c"Starting dirty tests...\0A\00"
@.str.1 = [21 x i8] c"%s/aiodio/file.xx.%d\00"
@.str.2 = [4 x i8] c"TMP\00"
@.str.3 = [5 x i8] c"/tmp\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32768 x i8]
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = trunc i64 %8 to i32
%13 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %18
17: ; preds = %0
br label %18
18: ; preds = %17, %15
%19 = phi i8* [ %16, %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %17 ]
%20 = call i32 (...) @getpid()
%21 = call i32 @snprintf(i8* %10, i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %20)
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_WRONLY
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %10, i32 %24, i32 438)
store i32 %25, i32* %2
%26 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 170, i32 32768)
store i32 0, i32* %3
br label %28
28: ; preds = %35, %18
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 3000
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %2
%33 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 32768)
br label %35
35: ; preds = %31
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %28
38: ; preds = %28
%39 = load i32, i32* %2
%40 = call i32 @fsync(i32 %39)
%41 = load i32, i32* %2
%42 = call i32 @close(i32 %41)
%43 = call i32 @unlink(i8* %10)
store i32 0, i32* %1
%44 = load i8*, i8** %5
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str.1 = [21 x i8] c"%s/aiodio/file.xx.%d\00"
@.str.2 = [4 x i8] c"TMP\00"
@.str.3 = [5 x i8] c"/tmp\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@str = [24 x i8] c"Starting dirty tests...\00"
define i32 @main() {
%1 = alloca [32768 x i8]
%2 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca i8, i64 %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %8
%11 = tail call i32 (...) @getpid()
%12 = call i32 @snprintf(i8* %6, i32 %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11)
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %14, %13
%16 = call i32 @open(i8* %6, i32 %15, i32 438)
%17 = call i32 @memset(i8* %2, i32 170, i32 32768)
br label %18
18: ; preds = %0, %18
%19 = phi i32 [ 0, %0 ], [ %21, %18 ]
%20 = call i32 @write(i32 %16, i8* %2, i32 32768)
%21 = add nuw nsw i32 %19, 1
%22 = icmp eq i32 %21, 3000
br i1 %22, label %23, label %18
23: ; preds = %18
%24 = call i32 @fsync(i32 %16)
%25 = call i32 @close(i32 %16)
%26 = call i32 @unlink(i8* %6)
ret i32 0
}