#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*/ com_fopen(int /*<<< orphan*/ **, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdout;
int errormsgshow(char *filename, char *msg) {
  FILE *pfile;
  if (msg == NULL) {
    printf("errormsgshow: message is empty.\n");
    return 0;
  }
  if (filename == NULL)
    pfile = stdout;
  else
    com_fopen(&pfile, filename, "a+");
  if (pfile == NULL) {
    printf("errormsgshow: could not open %s.\n", filename);
    return 0;
  }
  fputs(msg, pfile);
  printf("\n");
  if (filename != NULL)
    fclose(pfile);
  return 1;
}


x86 assembly (clang, -O0):
<errormsgshow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1175 <errormsgshow+0x35>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1206 <errormsgshow+0xc6>
cmpq   $0x0,-0x10(%rbp)
jne    1193 <errormsgshow+0x53>
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <errormsgshow+0x67>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
lea    0xe7f(%rip),%rdx
call   1060 <com_fopen@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <errormsgshow+0x90>
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1206 <errormsgshow+0xc6>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ff <errormsgshow+0xbf>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errormsgshow>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     11b6 <errormsgshow+0x56>
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     11c6 <errormsgshow+0x66>
lea    0xe85(%rip),%rdx
mov    %rsp,%rdi
mov    %r14,%rsi
call   1080 <com_fopen@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     11d9 <errormsgshow+0x79>
mov    %rbx,%rdi
call   1070 <fputs@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebx
test   %r14,%r14
je     11ec <errormsgshow+0x8c>
mov    (%rsp),%rdi
call   1050 <fclose@plt>
jmp    11ec <errormsgshow+0x8c>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11ec <errormsgshow+0x8c>
mov    0x2e13(%rip),%rax
mov    (%rax),%rsi
mov    %rsi,(%rsp)
test   %rsi,%rsi
jne    118f <errormsgshow+0x2f>
lea    0xe23(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"errormsgshow: message is empty.\0A\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [34 x i8] c"errormsgshow: could not open %s.\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @errormsgshow(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %36
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32*, i32** @stdout
store i32* %15, i32** %6
br label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i32 @com_fopen(i32** %6, i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %14
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 0, i32* %3
br label %36
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i32*, i32** %6
%28 = call i32 @fputs(i8* %26, i32* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %25
store i32 1, i32* %3
br label %36
36: ; preds = %35, %22, %9
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@stdout = global i32* null
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [34 x i8] c"errormsgshow: could not open %s.\0A\00"
@str = [32 x i8] c"errormsgshow: message is empty.\00"
define i32 @errormsgshow(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %26
8: ; preds = %2
%9 = icmp eq i8* %0, null
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = load i32*, i32** @stdout
store i32* %11, i32** %3
br label %15
12: ; preds = %8
%13 = call i32 @com_fopen(i32** %3, i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32*, i32** %3
br label %15
15: ; preds = %12, %10
%16 = phi i32* [ %14, %12 ], [ %11, %10 ]
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %26
20: ; preds = %15
%21 = call i32 @fputs(i8* %1, i32* %16)
%22 = call i32 @putchar(i32 10)
br i1 %9, label %26, label %23
23: ; preds = %20
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %20, %23, %18, %6
%27 = phi i32 [ 0, %6 ], [ 0, %18 ], [ 1, %23 ], [ 1, %20 ]
ret i32 %27
}