#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int open_logfile(char LogFile[], FILE **fp) {
  if ((*fp = fopen(LogFile, "r")) == NULL) {
    if ((*fp = fopen(LogFile, "w")) == NULL) {
      fprintf(stderr, "Log-Datei %s konnte nicht erstellt werden\n", LogFile);
      *fp = NULL;
      return (-1);
    }
    return (1);
  } else {
    fclose(*fp);
    if ((*fp = fopen(LogFile, "a")) == NULL) {
      fprintf(stderr, "Log-Datei %s konnte nicht geoeffnet werden\n", LogFile);
      *fp = NULL;
      return (-1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<open_logfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11be <open_logfile+0x8e>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11b2 <open_logfile+0x82>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <open_logfile+0xf7>
movl   $0x1,-0x4(%rbp)
jmp    1227 <open_logfile+0xf7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1050 <fopen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    121b <open_logfile+0xeb>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <open_logfile+0xf7>
jmp    1220 <open_logfile+0xf0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_logfile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     117b <open_logfile+0x4b>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xed2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
jne    11be <open_logfile+0x8e>
lea    0xeb8(%rip),%rsi
jmp    11a1 <open_logfile+0x71>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
mov    $0x1,%eax
test   %rcx,%rcx
jne    11be <open_logfile+0x8e>
lea    0xe63(%rip),%rsi
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
movq   $0x0,(%r14)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"Log-Datei %s konnte nicht erstellt werden\0A\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [44 x i8] c"Log-Datei %s konnte nicht geoeffnet werden\0A\00"
define i32 @open_logfile(i8* %0, i32** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32**
store i8* %0, i8** %4
store i32** %1, i32*** %5
%6 = load i8*, i8** %4
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32**, i32*** %5
store i32* %7, i32** %8
%9 = icmp eq i32* %7, null
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32**, i32*** %5
store i32* %12, i32** %13
%14 = icmp eq i32* %12, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32**, i32*** %5
store i32* null, i32** %19
store i32 -1, i32* %3
br label %36
20: ; preds = %10
store i32 1, i32* %3
br label %36
21: ; preds = %2
%22 = load i32**, i32*** %5
%23 = load i32*, i32** %22
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %4
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32**, i32*** %5
store i32* %26, i32** %27
%28 = icmp eq i32* %26, null
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i32**, i32*** %5
store i32* null, i32** %33
store i32 -1, i32* %3
br label %36
34: ; preds = %21
br label %35
35: ; preds = %34
store i32 0, i32* %3
br label %36
36: ; preds = %35, %29, %20, %15
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"Log-Datei %s konnte nicht erstellt werden\0A\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [44 x i8] c"Log-Datei %s konnte nicht geoeffnet werden\0A\00"
define i32 @open_logfile(i8* %0, i32** nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %16
8: ; preds = %2
%9 = tail call i32 @fclose(i32* %3)
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8, %5
%13 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), %8 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* %13, i8* %0)
store i32* null, i32** %1
br label %16
16: ; preds = %12, %8, %5
%17 = phi i32 [ 1, %5 ], [ 0, %8 ], [ -1, %12 ]
ret i32 %17
}