#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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strerror_r(int /*<<< orphan*/, char *, int);
int strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int);
void perror(const char *prefix) {
  char buff[256];
  strerror_r(errno, buff, sizeof(buff));
  if (prefix) {
    write(2, prefix, strlen(prefix));
    write(2, ": ", 2);
  }
  write(2, buff, strlen(buff));
  write(2, "\n", 1);
}


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <strerror_r@plt>
cmpq   $0x0,-0x8(%rbp)
je     119e <perror+0x6e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x118(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x2,%edx
lea    0xe69(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x2,%edi
lea    0xe2c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x100,%edx
call   1050 <strerror_r@plt>
test   %rbx,%rbx
je     1183 <perror+0x53>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe8c(%rip),%rsi
mov    $0x2,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe5f(%rip),%rsi
mov    $0x2,%edi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [3 x i8] c": \00"
@.str.1 = [2 x i8] c"\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 ne i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @write(i32 2, i8* %10, i32 %12)
%14 = call i32 @write(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %15
15: ; preds = %9, %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @write(i32 2, i8* %16, i32 %18)
%20 = call i32 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [3 x i8] c": \00"
@.str.1 = [2 x i8] c"\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
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = call i32 @strlen(i8* %0)
%9 = call i32 @write(i32 2, i8* %0, i32 %8)
%10 = call i32 @write(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %11
11: ; preds = %7, %1
%12 = call i32 @strlen(i8* %3)
%13 = call i32 @write(i32 2, i8* %3, i32 %12)
%14 = call i32 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}