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


x86 assembly (clang, -O0):
<fatal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b3 <fatal+0x83>
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116f <fatal+0x3f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117f <fatal+0x4f>
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    117f <fatal+0x4f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rcx
lea    0xe63(%rip),%rdx
mov    $0x0,%al
call   1030 <logit@plt>
jmp    128a <fatal+0x15a>
mov    0x2e1e(%rip),%rax
cmpq   $0x0,(%rax)
je     1238 <fatal+0x108>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e8 <fatal+0xb8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11f8 <fatal+0xc8>
lea    0xe11(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11f8 <fatal+0xc8>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    %rax,%r8
lea    0xdda(%rip),%rdx
mov    $0x0,%al
call   1030 <logit@plt>
jmp    1285 <fatal+0x155>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     125c <fatal+0x12c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    126c <fatal+0x13c>
lea    0xd9d(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    126c <fatal+0x13c>
mov    -0x4c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xd8c(%rip),%rdx
mov    $0x0,%al
call   1030 <logit@plt>
jmp    128a <fatal+0x15a>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<fatal>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
jne    1170 <fatal+0x40>
mov    0x2ea8(%rip),%rax
mov    (%rax),%ebx
test   %rdi,%rdi
lea    0xeb4(%rip),%rbp
cmovne %rdi,%rbp
mov    0x2e81(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
lea    0xea4(%rip),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rcx
jmp    11a8 <fatal+0x78>
mov    %rsi,%r14
mov    0x2e5e(%rip),%rax
test   %rdi,%rdi
lea    0xe7c(%rip),%rbx
cmovne %rdi,%rbx
mov    (%rax),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%ebp
test   %rdi,%rdi
jne    11b9 <fatal+0x89>
lea    0xe6a(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
call   1050 <strerror@plt>
lea    0xe41(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <logit@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@LOG_CRIT = global i32 0
@.str = [6 x i8] c"fatal\00"
@.str.1 = [3 x i8] c"%s\00"
@errno = global i64 0
@.str.2 = [7 x i8] c"%s: %s\00"
define void @fatal(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = load i32, i32* @LOG_CRIT
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = load i8*, i8** %3
br label %14
13: ; preds = %7
br label %14
14: ; preds = %13, %11
%15 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %13 ]
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i32, i8*, i8*, i8*, ...) @logit(i32 %8, i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %47
19: ; preds = %2
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i32, i32* @LOG_CRIT
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i8*, i8** %3
br label %29
28: ; preds = %22
br label %29
29: ; preds = %28, %26
%30 = phi i8* [ %27, %26 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %28 ]
%31 = load i8*, i8** %4
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 (i32, i8*, i8*, i8*, ...) @logit(i32 %23, i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %33)
br label %46
35: ; preds = %19
%36 = load i32, i32* @LOG_CRIT
%37 = load i8*, i8** %3
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i8*, i8** %3
br label %42
41: ; preds = %35
br label %42
42: ; preds = %41, %39
%43 = phi i8* [ %40, %39 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %41 ]
%44 = load i8*, i8** %4
%45 = call i32 (i32, i8*, i8*, i8*, ...) @logit(i32 %36, i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %29
br label %47
47: ; preds = %46, %14
%48 = call i32 @exit(i32 1)
unreachable
}

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