#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 const *);
int /*<<< orphan*/ printf(char *);
void logError(char *errdesc, const char *caller) {
  FILE *file = fopen("./dat/debug.log", "a");
  if (!file) {
    printf("ERROR: Could not open dat/debug.log in append mode");
  } else {
    fprintf(file, "ERROR: %s\n", errdesc);
    fprintf(file, "In function %s\n\n", caller);
    fclose(file);
    printf("An error occurred and has been logged.");
    printf(" Check dat/debug.log for more details.\n");
    printf("Your previous command may have been voided due to the error.\n");
  }
}


x86 assembly (clang, -O0):
<logError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea9(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <logError+0x43>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
jmp    11d8 <logError+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xeb3(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logError>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11cb <logError+0x7b>
mov    %rax,%rbx
lea    0xec8(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1060 <fprintf@plt>
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xeb8(%rip),%rdi
call   1050 <printf@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeee(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>
lea    0xe40(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"./dat/debug.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [51 x i8] c"ERROR: Could not open dat/debug.log in append mode\00"
@.str.3 = [11 x i8] c"ERROR: %s\0A\00"
@.str.4 = [17 x i8] c"In function %s\0A\0A\00"
@.str.5 = [39 x i8] c"An error occurred and has been logged.\00"
@.str.6 = [40 x i8] c" Check dat/debug.log for more details.\0A\00"
@.str.7 = [62 x i8] c"Your previous command may have been voided due to the error.\0A\00"
define void @logError(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
br label %23
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = load i8*, i8** %3
%14 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %5
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %5
%19 = call i32 @fclose(i32* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.7, i64 0, i64 0))
br label %23
23: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"./dat/debug.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [51 x i8] c"ERROR: Could not open dat/debug.log in append mode\00"
@.str.3 = [11 x i8] c"ERROR: %s\0A\00"
@.str.4 = [17 x i8] c"In function %s\0A\0A\00"
@.str.5 = [39 x i8] c"An error occurred and has been logged.\00"
@str = [39 x i8] c" Check dat/debug.log for more details.\00"
@str.8 = [61 x i8] c"Your previous command may have been voided due to the error.\00"
define void @logError(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%10 = tail call i32 @fclose(i32* %3)
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.8, i64 0, i64 0))
br label %14
14: ; preds = %7, %5
ret void
}