#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;
char *strerror(int /*<<< orphan*/);
void perror(const char *s) {
  if (s != NULL && s[0] != '\0')
    fprintf(stderr, "%s: ", s);
  fprintf(stderr, "%s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1160 <perror+0x40>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1160 <perror+0x40>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea5(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbx
test   %rdi,%rdi
je     1143 <perror+0x23>
mov    %rdi,%rdx
cmpb   $0x0,(%rdi)
je     1143 <perror+0x23>
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e96(%rip),%rax
mov    (%rax),%ebx
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xea4(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
pop    %rbx
jmp    1030 <fprintf@plt>

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

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