#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 */
scalar_t__ ENOSYS;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
int /*<<< orphan*/ vsprintf(char *, char const *, int /*<<< orphan*/);
void error_message(int status, const char *mode, const char *fmt, va_list ap) {
  char buf[4096 / 2];
  char msg[4096];
  vsprintf(buf, fmt, ap);
  if (errno == 0 || errno == ENOSYS) {
    snprintf(msg, sizeof msg, "%s\n", buf);
  } else {
    snprintf(msg, sizeof msg, "%s: %s\n", buf, strerror(errno));
  }
  fflush(stdout);
  fprintf(stderr, "%s: %s", mode, msg);
  if (status >= 0) {
    exit(status);
  }
  return;
}


x86 assembly (clang, -O0):
<error_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <vsprintf@plt>
mov    0x2e3d(%rip),%rax
cmpq   $0x0,(%rax)
je     11b7 <error_message+0x57>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <error_message+0x7d>
lea    -0x1820(%rbp),%rdi
lea    -0x820(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe33(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122c <error_message+0xcc>
lea    -0x1820(%rbp),%rax
mov    %rax,-0x1830(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x1828(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x1830(%rbp),%rdi
mov    -0x1828(%rbp),%rcx
mov    %rax,%r8
mov    $0x1000,%esi
lea    0xddb(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x1820(%rbp),%rcx
lea    0xdb3(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x0,-0x4(%rbp)
jl     126c <error_message+0x10c>
mov    -0x4(%rbp),%edi
call   1070 <exit@plt>
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_message>:
push   %rbp
push   %rbx
sub    $0x1808,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1060 <vsprintf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     11be <error_message+0x5e>
mov    0x2e57(%rip),%rax
cmp    (%rax),%rdi
je     11be <error_message+0x5e>
call   1080 <strerror@plt>
lea    0xe5e(%rip),%rdx
lea    0x800(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x1000,%esi
mov    %rax,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11dc <error_message+0x7c>
lea    0xe3f(%rip),%rdx
lea    0x800(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x1000,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
lea    0x800(%rsp),%rcx
mov    %rbx,%rdx
call   1040 <fprintf@plt>
test   %ebp,%ebp
jns    1218 <error_message+0xb8>
add    $0x1808,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [7 x i8] c"%s: %s\00"
define void @error_message(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2048 x i8]
%10 = alloca [4096 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = call i32 @vsprintf(i8* %11, i8* %12, i32 %13)
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOSYS
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17, %4
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %22, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %31
25: ; preds = %17
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
%30 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %26, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
br label %31
31: ; preds = %25, %21
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i32, i32* %5
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %31
%41 = load i32, i32* %5
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %31
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [7 x i8] c"%s: %s\00"
define void @error_message(i32 %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = alloca [4096 x i8]
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = call i32 @vsprintf(i8* %7, i8* %2, i32 %3)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
%12 = load i64, i64* @ENOSYS
%13 = icmp eq i64 %10, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %20
17: ; preds = %4
%18 = tail call i8* @strerror(i64 %10)
%19 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %18)
br label %20
20: ; preds = %17, %15
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %8)
%25 = icmp sgt i32 %0, -1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @exit(i32 %0)
unreachable
28: ; preds = %20
ret void
}