#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, ...);
int strlen(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");
  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    0xe63(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe88(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%r12d
lea    0xe5e(%rip),%r14
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe5b(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe30(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <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 = [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*, i32, ...) @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 = load i8*, i8** %13
%34 = load i32, i32* %7
%35 = load i32*, i32** %10
%36 = call i32 @fread(i8* %33, i32 1, i32 %34, i32* %35)
store i32 %36, i32* %6
%37 = load i32*, i32** %10
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* %6
%40 = load i8*, i8** %13
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %39, i8* %40)
%42 = 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.5 = [18 x i8] c"%d byte read:\0A%s\0A\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*, i32, ...) @printf(i8* 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 @fread(i8* %10, i32 1, i32 %6, i32* %11)
%13 = tail call i32 @fclose(i32* %11)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %12, i8* %10)
%15 = tail call i32 @exit(i32 0)
unreachable
}