#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
long strlen(char *);
void report_errno(char *message) {
  long length = strlen(message);
  int index = 0;
  int errno_saved = errno;
  fprintf(stderr, "\n");
  for (; index < length; index++) {
    fprintf(stderr, "%c", message[index]);
  }
  fprintf(stderr, "\nErrno was: %d\n", errno_saved);
}


x86 assembly (clang, -O0):
<report_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11a2 <report_errno+0x82>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <report_errno+0x43>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_errno>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    0x2e9b(%rip),%rax
mov    (%rax),%r14d
mov    0x2e99(%rip),%r12
mov    (%r12),%edi
lea    0xebf(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %rbp,%rbp
jle    118d <report_errno+0x6d>
lea    0xe9b(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
movsbl 0x0(%r13,%rbx,1),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <report_errno+0x50>
mov    (%r12),%edi
lea    0xe6b(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [16 x i8] c"\0AErrno was: %d\0A\00"
define void @report_errno(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
store i32 0, i32* %4
%8 = load i32, i32* @errno
store i32 %8, i32* %5
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %25, %1
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = load i64, i64* %3
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %16
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %11
28: ; preds = %11
%29 = load i32, i32* @stderr
%30 = load i32, i32* %5
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [16 x i8] c"\0AErrno was: %d\0A\00"
define void @report_errno(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = load i32, i32* @errno
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i64 %2, 0
br i1 %6, label %7, label %16
7: ; preds = %1, %7
%8 = phi i64 [ %14, %7 ], [ 0, %1 ]
%9 = load i32, i32* @stderr
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %2
br i1 %15, label %16, label %7
16: ; preds = %7, %1
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %3)
ret void
}