#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main(void) {
  int max = 1000;
  FILE *pic;
  if ((pic = fopen("city.png", "r")) == NULL) {
    printf("Fehler beim Öffnen der Datei!");
  }
  fseek(pic, 0, SEEK_END);
  int size = ftell(pic);
  rewind(pic);
  char *buffer = (char *)malloc(size * sizeof(char));
  int read = fread(buffer, size, 1, pic);
  if (read != 1) {
    printf("Fehler beim lesen der Datei\n");
    return EXIT_FAILURE;
  }
  fwrite(buffer, size, 1, stdout);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c3 <main+0x43>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     123e <main+0xbe>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1264 <main+0xe4>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe65(%rip),%rdi
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11bb <main+0x2b>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1222 <main+0x92>
mov    0x2dc8(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    0x2da8(%rip),%rax
jmp    1235 <main+0xa5>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"city.png\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Fehler beim \C3\96ffnen der Datei!\00"
@SEEK_END = global i32 0
@.str.3 = [29 x i8] c"Fehler beim lesen der Datei\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32*, i32** %3
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = load i32*, i32** %3
%16 = call i32 @ftell(i32* %15)
store i32 %16, i32* %4
%17 = load i32*, i32** %3
%18 = call i32 @rewind(i32* %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = load i32, i32* %4
%27 = load i32*, i32** %3
%28 = call i32 @fread(i8* %25, i32 %26, i32 1, i32* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %11
%32 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %1
br label %40
34: ; preds = %11
%35 = load i8*, i8** %5
%36 = load i32, i32* %4
%37 = load i32, i32* @stdout
%38 = call i32 @fwrite(i8* %35, i32 %36, i32 1, i32 %37)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %1
br label %40
40: ; preds = %34, %31
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [9 x i8] c"city.png\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Fehler beim \C3\96ffnen der Datei!\00"
@SEEK_END = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [28 x i8] c"Fehler beim lesen der Datei\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %1, i32 0, i32 %6)
%8 = tail call i32 @ftell(i32* %1)
%9 = tail call i32 @rewind(i32* %1)
%10 = tail call i64 @malloc(i32 %8)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @fread(i8* %11, i32 %8, i32 1, i32* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %19
16: ; preds = %5
%17 = load i32, i32* @stdout
%18 = tail call i32 @fwrite(i8* %11, i32 %8, i32 1, i32 %17)
br label %19
19: ; preds = %16, %14
%20 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_SUCCESS, %16 ]
%21 = load i32, i32* %20
ret i32 %21
}