#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(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror_r(int /*<<< orphan*/, char *, int);
void perror(const char *s) {
  char buffer[256];
  strerror_r(errno, buffer, 256);
  if (s == NULL) {
    fprintf(stderr, "%s\n", buffer);
  } else {
    fprintf(stderr, "%s: %s\n", s, buffer);
  };
}


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <strerror_r@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1177 <perror+0x57>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1199 <perror+0x79>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    -0x110(%rbp),%rcx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x100,%edx
call   1040 <strerror_r@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
test   %rbx,%rbx
je     1165 <perror+0x45>
lea    0xeaa(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1176 <perror+0x56>
lea    0xe98(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x100,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
define void @perror(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @errno
%5 = call i32 @strerror_r(i32 %4, i8* %3, i32 256)
%6 = icmp eq i8* %0, null
%7 = load i32, i32* @stderr
br i1 %6, label %8, label %10
8: ; preds = %1
%9 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %12
10: ; preds = %1
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %3)
br label %12
12: ; preds = %10, %8
ret void
}