#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*/ 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
    pfile = fopen(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),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
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   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11b5 <errormsgshow+0x55>
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     11c5 <errormsgshow+0x65>
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %r15,%r15
je     11d4 <errormsgshow+0x74>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fputs@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebx
test   %r14,%r14
je     11e7 <errormsgshow+0x87>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    11e7 <errormsgshow+0x87>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11e7 <errormsgshow+0x87>
mov    0x2e14(%rip),%rax
mov    (%rax),%r15
test   %r15,%r15
jne    118c <errormsgshow+0x2c>
lea    0xe28(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
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* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
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 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = load i32*, i32** @stdout
br label %12
10: ; preds = %6
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = phi i32* [ %9, %8 ], [ %11, %10 ]
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail 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 %22
17: ; preds = %12
%18 = tail call i32 @fputs(i8* %1, i32* %13)
%19 = tail call i32 @putchar(i32 10)
br i1 %7, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @fclose(i32* %13)
br label %22
22: ; preds = %17, %20, %15, %4
%23 = phi i32 [ 0, %4 ], [ 0, %15 ], [ 1, %20 ], [ 1, %17 ]
ret i32 %23
}