#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 */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void perror(const char *s) {
  if (errno) {
    if (s) {
      fprintf(stderr, "%s: %s\n", s, strerror(errno));
    } else {
      fprintf(stderr, "%s\n", strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
cmpq   $0x0,(%rax)
je     11bc <perror+0x9c>
cmpq   $0x0,-0x8(%rbp)
je     1188 <perror+0x68>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    %rax,%rcx
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b7 <perror+0x97>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11bc <perror+0x9c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1164 <perror+0x44>
mov    0x2ea4(%rip),%rax
mov    (%rax),%ebp
call   1040 <strerror@plt>
test   %rbx,%rbx
je     116b <perror+0x4b>
lea    0xeb1(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fprintf@plt>

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

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