#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int fwrite(void *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int strlen(char const *);
int /*<<< orphan*/ unlink(char const *);
int main(int argc, char *argv[]) {
  int k, m, n;
  FILE *out;
  FILE *in;
  const char *FILENAME = "/tmp/out-highlevel.txt";
  const char *CONTENT = "Dies ist ein Beispieltext";
  char *buffer;
  n = strlen(CONTENT) + 1;
  out = fopen(FILENAME, "w");
  m = fwrite((void *)CONTENT, 1, n, out);
  fclose(out);
  printf("%d bytes written (lenght %d)\n", m, n);
  buffer = (char *)malloc(m);
  in = fopen(FILENAME, "r");
  printf("file opened\n");
  unlink(FILENAME);
  printf("file \"deleted\"\n");
  sleep(5);
  printf("reading from deleted file\n");
  k = fread((void *)buffer, 1, m, in);
  fclose(in);
  printf("%d byte read:\n%s\n", k, buffer);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe4f(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <unlink@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe58(%rip),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%ebx
lea    0xe2f(%rip),%r14
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xe2c(%rip),%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%edi
call   10d0 <sleep@plt>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xdc9(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/tmp/out-highlevel.txt\00"
@.str.1 = [26 x i8] c"Dies ist ein Beispieltext\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [30 x i8] c"%d bytes written (lenght %d)\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [13 x i8] c"file opened\0A\00"
@.str.6 = [16 x i8] c"file \22deleted\22\0A\00"
@.str.7 = [27 x i8] c"reading from deleted file\0A\00"
@.str.8 = [18 x i8] c"%d byte read:\0A%s\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 i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8** %12
%14 = load i8*, i8** %12
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
store i32 %16, i32* %8
%17 = load i8*, i8** %11
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %9
%19 = load i8*, i8** %12
%20 = load i32, i32* %8
%21 = load i32*, i32** %9
%22 = call i32 @fwrite(i8* %19, i32 1, i32 %20, i32* %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %9
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26)
%28 = load i32, i32* %7
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %13
%31 = load i8*, i8** %11
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%34 = load i8*, i8** %11
%35 = call i32 @unlink(i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @sleep(i32 5)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%39 = load i8*, i8** %13
%40 = load i32, i32* %7
%41 = load i32*, i32** %10
%42 = call i32 @fread(i8* %39, i32 1, i32 %40, i32* %41)
store i32 %42, i32* %6
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %6
%46 = load i8*, i8** %13
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %45, i8* %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [23 x i8] c"/tmp/out-highlevel.txt\00"
@.str.1 = [26 x i8] c"Dies ist ein Beispieltext\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [30 x i8] c"%d bytes written (lenght %d)\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.8 = [18 x i8] c"%d byte read:\0A%s\0A\00"
@str = [12 x i8] c"file opened\00"
@str.9 = [15 x i8] c"file \22deleted\22\00"
@str.10 = [26 x i8] c"reading from deleted file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%4 = add nsw i32 %3, 1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %4, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %4)
%9 = tail call i64 @malloc(i32 %6)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @unlink(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
%15 = tail call i32 @sleep(i32 5)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%17 = tail call i32 @fread(i8* %10, i32 1, i32 %6, i32* %11)
%18 = tail call i32 @fclose(i32* %11)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %17, i8* %10)
%20 = tail call i32 @exit(i32 0)
unreachable
}