#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*/ SIGQUIT;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *stringAdd(char *, int /*<<< orphan*/, char *, char *,
                int /*<<< orphan*/ *);
void i8086errorEx(const char *filename, int linenum, const char *msg1,
                  const char *msg2) {
  FILE *file;
  char lnum[16];
  char *linfilename;
  linfilename = (char *)calloc(1, sizeof(char));
  linfilename =
      stringAdd(linfilename, getenv("HOME"), "/.i8086emu/", "emu.log", NULL);
  file = fopen(linfilename, "a");
  if (file != NULL) {
    fputs("[Error] ", file);
    fputs(filename, file);
    fputs(": Line ", file);
    sprintf(lnum, "%d", linenum);
    fputs(lnum, file);
    fputs(": ", file);
    fputs(msg1, file);
    fputs(": ", file);
    fputs(msg2, file);
    fputc('\n', file);
    fclose(file);
  }
  printf("\n\n%s\n%s\n", msg1, msg2);
  raise(SIGQUIT);
}


x86 assembly (clang, -O0):
<i8086errorEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1090 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xe2a(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
lea    0xe1d(%rip),%rdx
lea    0xe22(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10b0 <stringAdd@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12ba <i8086errorEx+0x11a>
mov    -0x28(%rbp),%rsi
lea    0xdf4(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1070 <fputs@plt>
lea    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xdd5(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xdbb(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1080 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd69(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1040 <raise@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i8086errorEx>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbp
mov    $0x1,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%rbx
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe18(%rip),%rdx
lea    0xe1d(%rip),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %r8d,%r8d
call   10b0 <stringAdd@plt>
lea    0xe11(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d5 <i8086errorEx+0x125>
mov    %rax,%rbx
lea    0xdf8(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
lea    0xddd(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
lea    0xdcc(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r12d,%edx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
lea    0xdaf(%rip),%rbp
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xd56(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <printf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <raise@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [12 x i8] c"/.i8086emu/\00"
@.str.2 = [8 x i8] c"emu.log\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [9 x i8] c"[Error] \00"
@.str.5 = [8 x i8] c": Line \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [3 x i8] c": \00"
@.str.8 = [9 x i8] c"\0A\0A%s\0A%s\0A\00"
@SIGQUIT = global i32 0
define void @i8086errorEx(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [16 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = call i64 @calloc(i32 1, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i8* @stringAdd(i8* %14, i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i8* %16, i8** %11
%17 = load i8*, i8** %11
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %9
%19 = load i32*, i32** %9
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %49
21: ; preds = %4
%22 = load i32*, i32** %9
%23 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %22)
%24 = load i8*, i8** %5
%25 = load i32*, i32** %9
%26 = call i32 @fputs(i8* %24, i32* %25)
%27 = load i32*, i32** %9
%28 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %27)
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%33 = load i32*, i32** %9
%34 = call i32 @fputs(i8* %32, i32* %33)
%35 = load i32*, i32** %9
%36 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %35)
%37 = load i8*, i8** %7
%38 = load i32*, i32** %9
%39 = call i32 @fputs(i8* %37, i32* %38)
%40 = load i32*, i32** %9
%41 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %40)
%42 = load i8*, i8** %8
%43 = load i32*, i32** %9
%44 = call i32 @fputs(i8* %42, i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fputc(i8 signext 10, i32* %45)
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %21, %4
%50 = load i8*, i8** %7
%51 = load i8*, i8** %8
%52 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %50, i8* %51)
%53 = load i32, i32* @SIGQUIT
%54 = call i32 @raise(i32 %53)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [12 x i8] c"/.i8086emu/\00"
@.str.2 = [8 x i8] c"emu.log\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [9 x i8] c"[Error] \00"
@.str.5 = [8 x i8] c": Line \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [3 x i8] c": \00"
@.str.8 = [9 x i8] c"\0A\0A%s\0A%s\0A\00"
@SIGQUIT = global i32 0
define void @i8086errorEx(i8* nocapture %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @calloc(i32 1, i32 1)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = tail call i8* @stringAdd(i8* %8, i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %25, label %13
13: ; preds = %4
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64 8, i64 1, i32* %11)
%15 = tail call i32 @fputs(i8* %0, i32* %11)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 7, i64 1, i32* %11)
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %1)
%18 = call i32 @fputs(i8* %6, i32* %11)
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %11)
%20 = tail call i32 @fputs(i8* %2, i32* %11)
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %11)
%22 = tail call i32 @fputs(i8* %3, i32* %11)
%23 = tail call i32 @fputc(i8 signext 10, i32* %11)
%24 = tail call i32 @fclose(i32* %11)
br label %25
25: ; preds = %13, %4
%26 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %2, i8* %3)
%27 = load i32, i32* @SIGQUIT
%28 = tail call i32 @raise(i32 %27)
ret void
}