#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
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];
  vsprintf(buf, fmt, ap);
  sprintf(buf + strlen(buf), ": %s\n", strerror(errno));
  fflush(stdout);
  fprintf(stderr, "%s: %s", mode, buf);
  if (status >= 0) {
    exit(status);
  }
  return;
}


x86 assembly (clang, -O0):
<error_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <vsprintf@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1030(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1028(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1028(%rbp),%rdi
mov    %rax,%rdx
lea    0xe15(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x1020(%rbp),%rcx
lea    0xded(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x0,-0x4(%rbp)
jl     1230 <error_message+0xc0>
mov    -0x4(%rbp),%edi
call   1080 <exit@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1060 <vsprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1040 <fprintf@plt>
test   %r14d,%r14d
jns    11fd <error_message+0x8d>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c": %s\0A\00"
@errno = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [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 [4096 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = call i32 @vsprintf(i8* %10, i8* %11, i32 %12)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26)
%28 = load i32, i32* %5
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %4
%31 = load i32, i32* %5
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %4
ret void
}

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