#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 */
int /*<<< orphan*/ LOG_CRIT;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ logit(int /*<<< orphan*/, char *, char const *, ...);
char const *strerror(scalar_t__);
void fatal(const char *emsg) {
  if (emsg == NULL)
    logit(LOG_CRIT, "fatal: %s", strerror(errno));
  else if (errno)
    logit(LOG_CRIT, "fatal: %s: %s", emsg, strerror(errno));
  else
    logit(LOG_CRIT, "fatal: %s", emsg);
  exit(1);
}


x86 assembly (clang, -O0):
<fatal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117b <fatal+0x4b>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11ec <fatal+0xbc>
mov    0x2e56(%rip),%rax
cmpq   $0x0,(%rax)
je     11cc <fatal+0x9c>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11e7 <fatal+0xb7>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <logit@plt>
jmp    11ec <fatal+0xbc>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<fatal>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
jne    115e <fatal+0x2e>
mov    0x2ea9(%rip),%rax
mov    (%rax),%ebx
mov    0x2e90(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
lea    0xea9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    1185 <fatal+0x55>
mov    %rdi,%rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%ebp
test   %rdi,%rdi
jne    1196 <fatal+0x66>
lea    0xe80(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
call   1050 <strerror@plt>
lea    0xe68(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@LOG_CRIT = global i32 0
@.str = [10 x i8] c"fatal: %s\00"
@errno = global i64 0
@.str.1 = [14 x i8] c"fatal: %s: %s\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 %10
5: ; preds = %1
%6 = load i32, i32* @LOG_CRIT
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = call i32 (i32, i8*, i8*, ...) @logit(i32 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %24
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @LOG_CRIT
%15 = load i8*, i8** %2
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i32, i8*, i8*, ...) @logit(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
br label %23
19: ; preds = %10
%20 = load i32, i32* @LOG_CRIT
%21 = load i8*, i8** %2
%22 = call i32 (i32, i8*, i8*, ...) @logit(i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %13
br label %24
24: ; preds = %23, %5
%25 = call i32 @exit(i32 1)
unreachable
}

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