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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sleep(int);
int main(void) {
  printf("This is running as PID %d\n", getpid());
  FILE *f = fopen("fileio-fopen-delete.temp", "w");
  fprintf(f, "Hello ");
  fflush(f);
  remove("fileio-fopen-delete.temp");
  fprintf(f, "World.");
  fflush(f);
  sleep(120);
  fclose(f);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe61(%rip),%rdi
call   1060 <printf@plt>
lea    0xe70(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <fflush@plt>
lea    0xe40(%rip),%rdi
call   1030 <remove@plt>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <fflush@plt>
mov    $0x78,%edi
call   10a0 <sleep@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
lea    0xe7b(%rip),%r14
lea    0xe8d(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
lea    0xe5b(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x78,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"This is running as PID %d\0A\00"
@.str.1 = [25 x i8] c"fileio-fopen-delete.temp\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"Hello \00"
@.str.4 = [7 x i8] c"World.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 (...) @getpid()
%4 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%8 = load i32*, i32** %2
%9 = call i32 @fflush(i32* %8)
%10 = call i32 @remove(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32*, i32** %2
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32*, i32** %2
%14 = call i32 @fflush(i32* %13)
%15 = call i32 @sleep(i32 120)
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}

LLVM IR (-O2):
@.str = [27 x i8] c"This is running as PID %d\0A\00"
@.str.1 = [25 x i8] c"fileio-fopen-delete.temp\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"Hello \00"
@.str.4 = [7 x i8] c"World.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 6, i64 1, i32* %3)
%5 = tail call i32 @fflush(i32* %3)
%6 = tail call i32 @remove(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 6, i64 1, i32* %3)
%8 = tail call i32 @fflush(i32* %3)
%9 = tail call i32 @sleep(i32 120)
%10 = tail call i32 @fclose(i32* %3)
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}