#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *__strerror_r(int, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *,
                           char const *, char const *);
void perror_internal(FILE *fp, const char *s, int errnum) {
  char buf[1024];
  const char *colon;
  const char *errstring;
  if (s == NULL || *s == '\0')
    s = colon = "";
  else
    colon = ": ";
  errstring = __strerror_r(errnum, buf, sizeof buf);
  (void)fprintf(fp, "%s%s%s\n", s, colon, errstring);
}


x86 assembly (clang, -O0):
<perror_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1151 <perror_internal+0x31>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116f <perror_internal+0x4f>
lea    0xeb2(%rip),%rax
mov    %rax,-0x428(%rbp)
lea    0xea4(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    117d <perror_internal+0x5d>
lea    0xe8a(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <__strerror_r@plt>
mov    %rax,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x428(%rbp),%rcx
mov    -0x430(%rbp),%r8
lea    0xe4e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror_internal>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
lea    0xed4(%rip),%rbx
test   %rsi,%rsi
je     114f <perror_internal+0x2f>
cmpb   $0x0,(%rsi)
mov    %rbx,%r15
je     1152 <perror_internal+0x32>
lea    0xeb6(%rip),%rbx
mov    %rsi,%r15
jmp    1152 <perror_internal+0x32>
mov    %rbx,%r15
mov    %rsp,%rsi
mov    %edx,%edi
mov    $0x400,%edx
call   1040 <__strerror_r@plt>
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1030 <fprintf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@.str.2 = [8 x i8] c"%s%s%s\0A\00"
define void @perror_internal(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12, %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
br label %19
18: ; preds = %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %6
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i8* @__strerror_r(i32 %20, i8* %21, i32 1024)
store i8* %22, i8** %9
%23 = load i32*, i32** %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %8
%26 = load i8*, i8** %9
%27 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@.str.2 = [8 x i8] c"%s%s%s\0A\00"
define void @perror_internal(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %1, null
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %7
br label %11
11: ; preds = %3, %7, %10
%12 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %3 ]
%13 = phi i8* [ %1, %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %3 ]
%14 = call i8* @__strerror_r(i32 %2, i8* %5, i32 1024)
%15 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %12, i8* %14)
ret void
}