#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 */

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ logit(char *, char const *, char const *, ...);
char const *strerror(scalar_t__);
void fatal(const char *emsg) {
  if (emsg == NULL)
    logit("fatal: %s(%d)", strerror(errno), errno);
  else if (errno)
    logit("fatal: %s: %s(%d)", emsg, strerror(errno), errno);
  else
    logit("fatal: %s(%d)", emsg, errno);
  exit(1);
}


x86 assembly (clang, -O0):
<fatal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1176 <fatal+0x46>
mov    0x2e92(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,%rsi
mov    0x2e80(%rip),%rax
mov    (%rax),%rdx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11e3 <fatal+0xb3>
mov    0x2e63(%rip),%rax
cmpq   $0x0,(%rax)
je     11c2 <fatal+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%rsi
mov    %rax,%rdx
mov    0x2e34(%rip),%rax
mov    (%rax),%rcx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11de <fatal+0xae>
mov    -0x8(%rbp),%rsi
mov    0x2e13(%rip),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11e3 <fatal+0xb3>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<fatal>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r14
mov    (%r14),%rdi
test   %rbx,%rbx
jne    115a <fatal+0x2a>
call   1050 <strerror@plt>
mov    (%r14),%rdx
lea    0xeab(%rip),%rdi
mov    %rax,%rsi
jmp    116b <fatal+0x3b>
test   %rdi,%rdi
jne    117c <fatal+0x4c>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
call   1050 <strerror@plt>
mov    (%r14),%rcx
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"fatal: %s(%d)\00"
@errno = global i64 0
@.str.1 = [18 x i8] c"fatal: %s: %s(%d)\00"
define void @fatal(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i64, i64* @errno
%7 = call i8* @strerror(i64 %6)
%8 = load i64, i64* @errno
%9 = inttoptr i64 %8 to i8*
%10 = call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %9)
br label %26
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = load i64, i64* @errno
%19 = call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17, i64 %18)
br label %25
20: ; preds = %11
%21 = load i8*, i8** %2
%22 = load i64, i64* @errno
%23 = inttoptr i64 %22 to i8*
%24 = call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %20, %14
br label %26
26: ; preds = %25, %5
%27 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"fatal: %s(%d)\00"
@errno = global i64 0
@.str.1 = [18 x i8] c"fatal: %s: %s(%d)\00"
define void @fatal(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = load i64, i64* @errno
br i1 %2, label %4, label %9
4: ; preds = %1
%5 = tail call i8* @strerror(i64 %3)
%6 = load i64, i64* @errno
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %7)
br label %17
9: ; preds = %1
%10 = icmp eq i64 %3, 0
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = tail call i8* @strerror(i64 %3)
%13 = load i64, i64* @errno
%14 = tail call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %12, i64 %13)
br label %17
15: ; preds = %9
%16 = tail call i32 (i8*, i8*, i8*, ...) @logit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i8* null)
br label %17
17: ; preds = %11, %15, %4
%18 = tail call i32 @exit(i32 1)
unreachable
}