#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*/ abort();
char *checkedMalloc(int);
int errno;
int /*<<< orphan*/ printf(char *, int const, int, int);
int strerror_r(int, char *, int);
char *errnoToString(int errnoToTranslate) {
  char *buffer = checkedMalloc(80);
  const int retVal = strerror_r(errnoToTranslate, buffer, 80);
  if (retVal < 0) {
    printf("strerror_r error retVal = %d errnoToTranslate = %d errno = %d\n",
           retVal, errnoToTranslate, errno);
    abort();
  }
  return buffer;
}


x86 assembly (clang, -O0):
<errnoToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x50,%edi
call   1040 <checkedMalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x50,%edx
call   1060 <strerror_r@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1199 <errnoToString+0x59>
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errnoToString>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x50,%edi
call   1040 <checkedMalloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x50,%edx
call   1060 <strerror_r@plt>
test   %eax,%eax
js     116f <errnoToString+0x2f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%ecx
lea    0xe81(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"strerror_r error retVal = %d errnoToTranslate = %d errno = %d\0A\00"
@errno = global i32 0
define i8* @errnoToString(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i8* @checkedMalloc(i32 80)
store i8* %5, i8** %3
%6 = load i32, i32* %2
%7 = load i8*, i8** %3
%8 = call i32 @strerror_r(i32 %6, i8* %7, i32 80)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = load i32, i32* @errno
%15 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i32 %14)
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %1
%18 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
@.str = [63 x i8] c"strerror_r error retVal = %d errnoToTranslate = %d errno = %d\0A\00"
@errno = global i32 0
define i8* @errnoToString(i32 %0) {
%2 = tail call i8* @checkedMalloc(i32 80)
%3 = tail call i32 @strerror_r(i32 %0, i8* %2, i32 80)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %0, i32 %6)
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %1
ret i8* %2
}