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


x86 assembly (clang, -O0):
<msg_perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1176 <msg_perror+0x56>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1176 <msg_perror+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <msg_error@plt>
jmp    1195 <msg_perror+0x75>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
movslq %eax,%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <msg_error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_perror>:
push   %rbx
test   %rdi,%rdi
je     1150 <msg_perror+0x30>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1150 <msg_perror+0x30>
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xebd(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1030 <msg_error@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
movslq %eax,%rsi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1030 <msg_error@plt>

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

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