#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf_color(int /*<<< orphan*/, char *, char *, char *,
                                 ...);
int /*<<< orphan*/ stderr;
scalar_t__ strerror(int /*<<< orphan*/);
void br_perror(char *str) {
  if (str == NULL)
    fprintf_color(stderr, "\033[01;37m", "%s\n", (char *)strerror(errno));
  else
    fprintf_color(stderr, "\033[01;37m", "%s: %s\n", str,
                  (char *)strerror(errno));
}


x86 assembly (clang, -O0):
<br_perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1171 <br_perror+0x51>
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rcx
lea    0xea2(%rip),%rsi
lea    0xea8(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf_color@plt>
jmp    11b2 <br_perror+0x92>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rcx
mov    %rax,%r8
lea    0xe5c(%rip),%rsi
lea    0xe5e(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf_color@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_perror>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eb3(%rip),%rax
mov    (%rax),%ebp
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xebc(%rip),%rsi
test   %rbx,%rbx
je     1165 <br_perror+0x45>
lea    0xeb9(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fprintf_color@plt>
lea    0xea1(%rip),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fprintf_color@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"\1B[01;37m\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define void @br_perror(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = call i64 @strerror(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf_color(i32 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %18
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %2
%14 = load i32, i32* @errno
%15 = call i64 @strerror(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf_color(i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %16)
br label %18
18: ; preds = %11, %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"\1B[01;37m\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define void @br_perror(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = load i32, i32* @stderr
%4 = load i32, i32* @errno
%5 = tail call i64 @strerror(i32 %4)
%6 = inttoptr i64 %5 to i8*
br i1 %2, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf_color(i32 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %11
9: ; preds = %1
%10 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf_color(i32 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %6)
br label %11
11: ; preds = %9, %7
ret void
}