#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*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
FILE *openFile(char *name) {
  char dateiName[256];
  FILE *datei = NULL;
  if (name == NULL) {
    printf("Bitte gib einen Dateinamen an: ");
    scanf("%s", dateiName);
  } else {
    strncpy(dateiName, name, 255 * sizeof(char));
  }
  if ((datei = fopen(dateiName, "r")) == NULL) {
    printf("Fehler beim Oeffnen der Datei!\n");
  }
  return datei;
}


x86 assembly (clang, -O0):
<openFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x118(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1189 <openFile+0x49>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xea1(%rip),%rdi
call   1050 <scanf@plt>
jmp    119e <openFile+0x5e>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
jne    11ce <openFile+0x8e>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x118(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFile>:
push   %rbx
sub    $0x100,%rsp
test   %rdi,%rdi
je     116f <openFile+0x1f>
mov    %rdi,%rsi
mov    %rsp,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
jmp    118a <openFile+0x3a>
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
lea    0xe92(%rip),%rsi
mov    %rsp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ad <openFile+0x5d>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Bitte gib einen Dateinamen an: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [32 x i8] c"Fehler beim Oeffnen der Datei!\0A\00"
define i32* @openFile(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
store i32* null, i32** %4
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %15
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 255)
br label %15
15: ; preds = %11, %7
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32*, i32** %4
ret i32* %22
}

LLVM IR (-O2):
@.str = [32 x i8] c"Bitte gib einen Dateinamen an: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@str = [31 x i8] c"Fehler beim Oeffnen der Datei!\00"
define noalias i32* @openFile(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %10
8: ; preds = %1
%9 = call i32 @strncpy(i8* %3, i8* %0, i32 255)
br label %10
10: ; preds = %8, %5
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
ret i32* %11
}