#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void perror(const char *s) {
  if (s && *s) {
    fputs(s, stderr);
    fputs(": ", stderr);
  }
  fputs(strerror(errno), stderr);
  fputc('\n', stderr);
}


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     117e <perror+0x4e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117e <perror+0x4e>
mov    -0x8(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbx
test   %rdi,%rdi
je     1157 <perror+0x27>
cmpb   $0x0,(%rdi)
je     1157 <perror+0x27>
mov    0x2e9e(%rip),%rbx
mov    (%rbx),%esi
call   1030 <fputs@plt>
mov    (%rbx),%esi
lea    0xeae(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    0x2e74(%rip),%rbx
mov    (%rbx),%esi
mov    %rax,%rdi
call   1030 <fputs@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
pop    %rbx
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c": \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 %16
5: ; preds = %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* %11, i32 %12)
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %10, %5, %1
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* %18, i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 @fputc(i8 signext 10, i32 %21)
ret void
}

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