#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*/ snprintf(char *, int, char *, int, int);
int strerror_r(int, char *, int);
char *libbpf_strerror_r(int err, char *dst, int len) {
  int ret = strerror_r(err < 0 ? -err : err, dst, len);
  if (ret)
    snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
  return dst;
}


x86 assembly (clang, -O0):
<libbpf_strerror_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1149 <libbpf_strerror_r+0x29>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <libbpf_strerror_r+0x2f>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strerror_r@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1185 <libbpf_strerror_r+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe80(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libbpf_strerror_r>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
neg    %edi
cmovs  %ebp,%edi
call   1040 <strerror_r@plt>
test   %eax,%eax
je     1151 <libbpf_strerror_r+0x31>
lea    0xebf(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ERROR: strerror_r(%d)=%d\00"
define i8* @libbpf_strerror_r(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %4
%12 = sub nsw i32 0, %11
br label %15
13: ; preds = %3
%14 = load i32, i32* %4
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ %14, %13 ]
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call i32 @strerror_r(i32 %16, i8* %17, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = load i32, i32* %7
%27 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %22, %15
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@.str = [25 x i8] c"ERROR: strerror_r(%d)=%d\00"
define i8* @libbpf_strerror_r(i32 %0, i8* returned %1, i32 %2) {
%4 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%5 = tail call i32 @strerror_r(i32 %4, i8* %1, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %5)
br label %9
9: ; preds = %7, %3
ret i8* %1
}