#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 */
struct output {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_output(struct output *, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ perror(char *);
char *strerror(int /*<<< orphan*/);
void output_errno(struct output *output, char *str) {
  if (output == NULL)
    perror(str);
  else {
    add_output(output, str, -1);
    add_output(output, ": ", -1);
    add_output(output, strerror(errno), -1);
    add_output(output, "\n", -1);
  }
}


x86 assembly (clang, -O0):
<output_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1159 <output_errno+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <perror@plt>
jmp    11bc <output_errno+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_errno>:
test   %rdi,%rdi
je     118a <output_errno+0x5a>
push   %rbx
mov    %rdi,%rbx
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0xffffffff,%edx
call   1040 <add_output@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    $0xffffffff,%edx
pop    %rbx
jmp    1040 <add_output@plt>
mov    %rsi,%rdi
jmp    1030 <perror@plt>

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

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