#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fsetcolor(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char const *,
                            int /*<<< orphan*/);
void vabortmsgerrno(int no, const char *fmt, va_list args) {
  fsetcolor(stderr, "1;31");
  fputs("chg: abort: ", stderr);
  vfprintf(stderr, fmt, args);
  if (no != 0)
    fprintf(stderr, " (errno = %d, %s)", no, strerror(no));
  fsetcolor(stderr, "");
  fputc('\n', stderr);
  exit(255);
}


x86 assembly (clang, -O0):
<vabortmsgerrno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1060 <fsetcolor@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <vfprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     11fa <vabortmsgerrno+0x8a>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1060 <fsetcolor@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    $0xff,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<vabortmsgerrno>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e5a(%rip),%r15
mov    (%r15),%edi
lea    0xe70(%rip),%rsi
call   1060 <fsetcolor@plt>
mov    (%r15),%esi
lea    0xe66(%rip),%rdi
call   1030 <fputs@plt>
mov    (%r15),%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1070 <vfprintf@plt>
test   %ebx,%ebx
je     11d3 <vabortmsgerrno+0x63>
mov    (%r15),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe34(%rip),%rsi
call   1060 <fsetcolor@plt>
mov    (%r15),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    $0xff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"1;31\00"
@.str.1 = [13 x i8] c"chg: abort: \00"
@.str.2 = [18 x i8] c" (errno = %d, %s)\00"
@.str.3 = [1 x i8] zeroinitializer
define void @vabortmsgerrno(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* @stderr
%8 = call i32 @fsetcolor(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @vfprintf(i32 %11, i8* %12, i32 %13)
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* %4
%20 = load i32, i32* %4
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %21)
br label %23
23: ; preds = %17, %3
%24 = load i32, i32* @stderr
%25 = call i32 @fsetcolor(i32 %24, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 @fputc(i8 signext 10, i32 %26)
%28 = call i32 @exit(i32 255)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"1;31\00"
@.str.1 = [13 x i8] c"chg: abort: \00"
@.str.2 = [18 x i8] c" (errno = %d, %s)\00"
@.str.3 = [1 x i8] zeroinitializer
define void @vabortmsgerrno(i32 %0, i8* %1, i32 %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 @fsetcolor(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 @vfprintf(i32 %8, i8* %1, i32 %2)
%10 = icmp eq i32 %0, 0
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i8* @strerror(i32 %0)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %13)
br label %15
15: ; preds = %11, %3
%16 = load i32, i32* @stderr
%17 = tail call i32 @fsetcolor(i32 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputc(i8 signext 10, i32 %18)
%20 = tail call i32 @exit(i32 255)
unreachable
}