#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 */
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*/ sprintf(char *, char *, int);
char *stringAdd(char *, int /*<<< orphan*/, char *, char *,
                int /*<<< orphan*/ *);
void i8086warningEx(const char *filename, int linenum, const char *msg) {
  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("[Warning] ", file);
    fputs(filename, file);
    fputs(": Line ", file);
    sprintf(lnum, "%d", linenum);
    fputs(lnum, file);
    fputs(": ", file);
    fputs(msg, file);
    fputc('\n', file);
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<i8086warningEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe4e(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
lea    0xe41(%rip),%rdx
lea    0xe46(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <stringAdd@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1279 <i8086warningEx+0xf9>
mov    -0x20(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1050 <fputs@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xdfb(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i8086warningEx>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
mov    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe3d(%rip),%rdx
lea    0xe42(%rip),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %r8d,%r8d
call   1090 <stringAdd@plt>
lea    0xe36(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1297 <i8086warningEx+0x107>
mov    %rax,%rbx
lea    0xe1d(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
lea    0xe04(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0xdf3(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15d,%edx
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
lea    0xdd6(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [11 x i8] c"[Warning] \00"
@.str.5 = [8 x i8] c": Line \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [3 x i8] c": \00"
define void @i8086warningEx(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [16 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = call i64 @calloc(i32 1, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i8* @stringAdd(i8* %12, i32 %13, 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* %14, i8** %9
%15 = load i8*, i8** %9
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %42
19: ; preds = %3
%20 = load i32*, i32** %7
%21 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32* %20)
%22 = load i8*, i8** %4
%23 = load i32*, i32** %7
%24 = call i32 @fputs(i8* %22, i32* %23)
%25 = load i32*, i32** %7
%26 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %25)
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%31 = load i32*, i32** %7
%32 = call i32 @fputs(i8* %30, i32* %31)
%33 = load i32*, i32** %7
%34 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %33)
%35 = load i8*, i8** %6
%36 = load i32*, i32** %7
%37 = call i32 @fputs(i8* %35, i32* %36)
%38 = load i32*, i32** %7
%39 = call i32 @fputc(i8 signext 10, i32* %38)
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %19, %3
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 = [11 x i8] c"[Warning] \00"
@.str.5 = [8 x i8] c": Line \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [3 x i8] c": \00"
define void @i8086warningEx(i8* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @calloc(i32 1, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = tail call i8* @stringAdd(i8* %7, i32 %8, 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)
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %22, label %12
12: ; preds = %3
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 10, i64 1, i32* %10)
%14 = tail call i32 @fputs(i8* %0, i32* %10)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 7, i64 1, i32* %10)
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %1)
%17 = call i32 @fputs(i8* %5, i32* %10)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %10)
%19 = tail call i32 @fputs(i8* %2, i32* %10)
%20 = tail call i32 @fputc(i8 signext 10, i32* %10)
%21 = tail call i32 @fclose(i32* %10)
br label %22
22: ; preds = %12, %3
ret void
}