#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*/ FILE;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int S_IWUSR;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ mkstemp(char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  long int count = 0;
  int fd;
  FILE *fp;
  char filename[100];
  FILE *fp2;
  char *dir = getenv("DMTCP_TMPDIR");
  if (!dir) {
    dir = getenv("TMPDIR");
  }
  if (!dir) {
    dir = "/tmp";
  }
  if (sizeof(filename) < strlen(dir) + sizeof("/ff_jdl_XXXXXX")) {
    printf("Directory string too large.\n");
    return 1;
  }
  strcpy(filename, dir);
  strcat(filename, "/ff_jdl_XXXXXX");
  fp2 = fopen("/proc/self/exe", "r");
  if (fp2 == NULL) {
    abort();
  }
  close(mkstemp(filename));
  fd = open(filename, O_WRONLY | O_CREAT, S_IWUSR | S_IWUSR);
  if (fd == -1) {
    abort();
  }
  fp = fdopen(fd, "w");
  fprintf(stdout, "Opened ff_jdl\n");
  fprintf(stdout, "Deleting ff_jdl\n");
  unlink(filename);
  while (1) {
    if (count % (int)1e6 == 0) {
      printf("%ld ", count);
      fflush(stdout);
    }
    fprintf(fp, "%ld", count++);
  }
  fprintf(stdout, "I have returned\n");
  sleep(2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xdff(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    122e <main+0x4e>
lea    0xde4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    124a <main+0x6a>
lea    0xdca(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rdi
call   1070 <strlen@plt>
movslq %eax,%rcx
add    $0xf,%rcx
mov    $0x64,%eax
cmp    %rcx,%rax
jae    1287 <main+0xa7>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret
lea    -0x90(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1060 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1100 <strcat@plt>
lea    0xd8a(%rip),%rdi
lea    0xd92(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    12dc <main+0xfc>
mov    $0x0,%al
call   1040 <abort@plt>
lea    -0x90(%rbp),%rdi
call   10c0 <mkstemp@plt>
mov    %eax,%edi
call   1090 <close@plt>
lea    -0x90(%rbp),%rdi
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
mov    0x2cf2(%rip),%rax
or     (%rax),%esi
mov    0x2cd1(%rip),%rax
mov    (%rax),%edx
mov    0x2cc8(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1333 <main+0x153>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x14(%rbp),%edi
lea    0xd12(%rip),%rsi
call   10d0 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x90(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    13b8 <main+0x1d8>
mov    -0x10(%rbp),%rsi
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rdx
mov    %rdx,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    0xca2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1380 <main+0x1a0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xdfb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    121b <main+0x2b>
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xde8(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
cltq
add    $0xffffffffffffffaa,%rax
cmp    $0xffffffffffffff9a,%rax
ja     125d <main+0x6d>
lea    0xe19(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcpy@plt>
lea    0xda0(%rip),%rsi
mov    %r14,%rdi
call   1110 <strcat@plt>
lea    0xda0(%rip),%rdi
lea    0xda8(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1382 <main+0x192>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10d0 <mkstemp@plt>
mov    %eax,%edi
call   10a0 <close@plt>
mov    0x2d11(%rip),%rax
mov    0x2d42(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     1382 <main+0x192>
lea    0xd57(%rip),%rsi
mov    %eax,%edi
call   10e0 <fdopen@plt>
mov    %rax,%r12
mov    0x2ce4(%rip),%rbx
mov    (%rbx),%edi
lea    0xd3f(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd3e(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rsp,%rdi
call   1050 <unlink@plt>
movabs $0x431bde82d7b634db,%rbp
de 1b 43
lea    0xd34(%rip),%r15
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    134b <main+0x15b>
nopl   0x0(%rax)
lea    0x1(%rbx),%r14
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0xffffffffffffffff,%r13
mov    %r14,%rbx
mov    %rbx,%rax
mul    %rbp
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
add    %r13,%rax
jne    1330 <main+0x140>
lea    0xcec(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
jmp    1330 <main+0x140>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"DMTCP_TMPDIR\00"
@.str.1 = [7 x i8] c"TMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [29 x i8] c"Directory string too large.\0A\00"
@.str.4 = [15 x i8] c"/ff_jdl_XXXXXX\00"
@.str.5 = [15 x i8] c"/proc/self/exe\00"
@.str.6 = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.8 = [15 x i8] c"Opened ff_jdl\0A\00"
@.str.9 = [17 x i8] c"Deleting ff_jdl\0A\00"
@.str.10 = [5 x i8] c"%ld \00"
@.str.11 = [4 x i8] c"%ld\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [100 x i8]
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %1
store i64 0, i64* %2
%8 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %7
br label %13
13: ; preds = %11, %0
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %17
17: ; preds = %16, %13
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = add i64 %20, 15
%22 = icmp ult i64 100, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
25: ; preds = %17
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 (...) @abort()
unreachable
36: ; preds = %25
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%38 = call i32 @mkstemp(i8* %37)
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%41 = load i32, i32* @O_WRONLY
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWUSR
%45 = load i32, i32* @S_IWUSR
%46 = or i32 %44, %45
%47 = call i32 @open(i8* %40, i32 %43, i32 %46)
store i32 %47, i32* %3
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %36
%51 = call i32 (...) @abort()
unreachable
52: ; preds = %36
%53 = load i32, i32* %3
%54 = call i32* @fdopen(i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %54, i32** %4
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%60 = call i32 @unlink(i8* %59)
br label %61
61: ; preds = %52, %70
%62 = load i64, i64* %2
%63 = srem i64 %62, 1000000
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i64, i64* %2
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64 %66)
%68 = load i32, i32* @stdout
%69 = call i32 @fflush(i32 %68)
br label %70
70: ; preds = %65, %61
%71 = load i32*, i32** %4
%72 = ptrtoint i32* %71 to i32
%73 = load i64, i64* %2
%74 = add nsw i64 %73, 1
store i64 %74, i64* %2
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64 %73)
br label %61
}

LLVM IR (-O2):
@.str = [13 x i8] c"DMTCP_TMPDIR\00"
@.str.1 = [7 x i8] c"TMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.4 = [15 x i8] c"/ff_jdl_XXXXXX\00"
@.str.5 = [15 x i8] c"/proc/self/exe\00"
@.str.6 = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.8 = [15 x i8] c"Opened ff_jdl\0A\00"
@.str.9 = [17 x i8] c"Deleting ff_jdl\0A\00"
@.str.10 = [5 x i8] c"%ld \00"
@.str.11 = [4 x i8] c"%ld\00"
@str = [28 x i8] c"Directory string too large.\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = phi i8* [ %3, %0 ], [ %6, %5 ]
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8
%11 = tail call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, -86
%14 = icmp ult i64 %13, -101
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
ret i32 1
17: ; preds = %7
%18 = call i32 @strcpy(i8* %2, i8* %10)
%19 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %17
%25 = call i32 @mkstemp(i8* %2)
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %28, %27
%30 = load i32, i32* @S_IWUSR
%31 = call i32 @open(i8* %2, i32 %29, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %24
%36 = call i32* @fdopen(i32 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%41 = call i32 @unlink(i8* %2)
%42 = ptrtoint i32* %36 to i64
%43 = trunc i64 %42 to i32
br label %44
44: ; preds = %52, %35
%45 = phi i64 [ 0, %35 ], [ %53, %52 ]
%46 = urem i64 %45, 1000000
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64 %45)
%50 = load i32, i32* @stdout
%51 = call i32 @fflush(i32 %50)
br label %52
52: ; preds = %48, %44
%53 = add nuw nsw i64 %45, 1
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64 %45)
br label %44
}