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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strerror(int const);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void err_handler(int is_exit, const int err, char *fmt, va_list ap) {
  char s[1024];
  *s = 0;
  strcat(s, fmt);
  if (err) {
    strcat(s, " [");
    strcat(s, strerror(err));
    strcat(s, "]");
  }
  strcat(s, "\n");
  vfprintf(stderr, s, ap);
  if (is_exit)
    exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<err_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movb   $0x0,-0x420(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c4 <err_handler+0x84>
lea    -0x420(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strcat@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x428(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1040 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1040 <strcat@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <vfprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1207 <err_handler+0xc7>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %ecx,%r15d
mov    %esi,%ebx
mov    %edi,%r14d
movb   $0x0,(%rsp)
mov    %rsp,%rdi
mov    %rdx,%rsi
call   1040 <strcat@plt>
test   %ebx,%ebx
je     119b <err_handler+0x5b>
lea    0xe91(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strcat@plt>
mov    %ebx,%edi
call   1060 <strerror@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <strcat@plt>
lea    0xe70(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcat@plt>
lea    0xe63(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <vfprintf@plt>
test   %r14d,%r14d
jne    11d4 <err_handler+0x94>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c" [\00"
@.str.1 = [2 x i8] c"]\00"
@.str.2 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define void @err_handler(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
store i8 0, i8* %6
%7 = call i32 @strcat(i8* %6, i8* %2)
%8 = icmp eq i32 %1, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = call i8* @strerror(i32 %1)
%12 = call i32 @strcat(i8* %6, i8* %11)
%13 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %9, %4
%15 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 @vfprintf(i32 %16, i8* %6, i32 %3)
%18 = icmp eq i32 %0, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
ret void
}