#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 EXIT_FAILURE;
int /*<<< orphan*/ close(int const);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void stub1(int);
void error(const char *err_msg, const int socket, void (*exit)(int)) {
  if (0 != errno) {
    fprintf(stderr, "\n\n%s: %s\n", err_msg, strerror(errno));
  } else {
    fprintf(stderr, "\n\n%s\n", err_msg);
  }
  if (0 != socket) {
    close(socket);
  }
  if (NULL != exit) {
    (*exit)(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
je     1195 <error+0x65>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b0 <error+0x80>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     11c3 <error+0x93>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11de <error+0xae>
mov    -0x18(%rbp),%rax
mov    0x2df6(%rip),%rcx
mov    (%rcx),%edi
call   *%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
mov    (%rax),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%ebp
test   %rdi,%rdi
je     119d <error+0x6d>
call   1050 <strerror@plt>
lea    0xe9c(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14d,%r14d
je     1180 <error+0x50>
mov    %r14d,%edi
call   1030 <close@plt>
test   %r15,%r15
je     11b7 <error+0x87>
mov    %r15,%rcx
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    *%rcx
lea    0xe66(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14d,%r14d
jne    1178 <error+0x48>
jmp    1180 <error+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [10 x i8] c"\0A\0A%s: %s\0A\00"
@.str.1 = [6 x i8] c"\0A\0A%s\0A\00"
@EXIT_FAILURE = global i32 0
define void @error(i8* %0, i32 %1, void (i32)* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca void (i32)*
store i8* %0, i8** %4
store i32 %1, i32* %5
store void (i32)* %2, void (i32)** %6
%7 = load i64, i64* @errno
%8 = icmp ne i64 0, %7
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %4
%12 = load i64, i64* @errno
%13 = call i8* @strerror(i64 %12)
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %13)
br label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %9
%20 = load i32, i32* %5
%21 = icmp ne i32 0, %20
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
br label %25
25: ; preds = %22, %19
%26 = load void (i32)*, void (i32)** %6
%27 = icmp ne void (i32)* null, %26
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load void (i32)*, void (i32)** %6
%30 = load i32, i32* @EXIT_FAILURE
br label %31
31: ; preds = %28, %25
ret void
}

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