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


x86 assembly (clang, -O0):
<errnoToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e92(%rip),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
call   1050 <strerror@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e79(%rip),%rax
cmpl   $0x0,(%rax)
je     118f <errnoToString+0x5f>
mov    -0x4(%rbp),%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%ecx
mov    0x2e47(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errnoToString>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2ea2(%rip),%rbx
mov    (%rbx),%ebp
movl   $0x0,(%rbx)
call   1050 <strerror@plt>
mov    (%rbx),%edx
test   %edx,%edx
jne    1158 <errnoToString+0x28>
mov    %ebp,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea1(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

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