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


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118f <perror+0x5f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118f <perror+0x5f>
mov    -0x8(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    $0x3a,%edi
call   1040 <putc@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1040 <putc@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbx
test   %rdi,%rdi
je     1161 <perror+0x31>
cmpb   $0x0,(%rdi)
je     1161 <perror+0x31>
mov    0x2e9e(%rip),%rbx
mov    (%rbx),%esi
call   1030 <fputs@plt>
mov    (%rbx),%esi
mov    $0x3a,%edi
call   1040 <putc@plt>
mov    (%rbx),%esi
mov    $0x20,%edi
call   1040 <putc@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    0x2e6a(%rip),%rbx
mov    (%rbx),%esi
mov    %rax,%rdi
call   1030 <fputs@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
pop    %rbx
jmp    1040 <putc@plt>

LLVM IR (-O0):
@stderr = global i32 0
@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 %18
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 %18
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 @putc(i8 signext 58, i32 %14)
%16 = load i32, i32* @stderr
%17 = call i32 @putc(i8 signext 32, i32 %16)
br label %18
18: ; preds = %10, %5, %1
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 @fputs(i8* %20, i32 %21)
%23 = load i32, i32* @stderr
%24 = call i32 @putc(i8 signext 10, i32 %23)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@errno = global i32 0
define void @perror(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %13, 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 @putc(i8 signext 58, i32 %9)
%11 = load i32, i32* @stderr
%12 = tail call i32 @putc(i8 signext 32, i32 %11)
br label %13
13: ; preds = %6, %3, %1
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* %15, i32 %16)
%18 = load i32, i32* @stderr
%19 = tail call i32 @putc(i8 signext 10, i32 %18)
ret void
}