#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 */
typedef char const wchar_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
char *malloc(int);
size_t mbstowcs(char const *, char const *, size_t);
char *strerror(int /*<<< orphan*/);
size_t strlen(char const *);
const wchar_t *bt_error(void *fd_) {
  (void)fd_;
  const char *errstr = strerror(errno);
  size_t wlen = strlen(errstr);
  wchar_t *werrstr = malloc(sizeof(wchar_t[wlen]));
  return (mbstowcs(werrstr, errstr, wlen) != (size_t)-1)
             ? werrstr
             : L"Error in printing error";
}


x86 assembly (clang, -O0):
<bt_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <mbstowcs@plt>
cmp    $0xffffffffffffffff,%rax
je     11a2 <bt_error+0x62>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11b2 <bt_error+0x72>
lea    0xe57(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b2 <bt_error+0x72>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bt_error>:
push   %r15
push   %r14
push   %rbx
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <mbstowcs@plt>
cmp    $0xffffffffffffffff,%rax
lea    0xe7c(%rip),%rax
cmovne %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [24 x i32] [i32 69, i32 114, i32 114, i32 111, i32 114, i32 32, i32 105, i32 110, i32 32, i32 112, i32 114, i32 105, i32 110, i32 116, i32 105, i32 110, i32 103, i32 32, i32 101, i32 114, i32 114, i32 111, i32 114, i32 0]
define i8* @bt_error(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = call i64 @mbstowcs(i8* %14, i8* %15, i64 %16)
%18 = icmp ne i64 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = load i8*, i8** %5
br label %22
21: ; preds = %1
br label %22
22: ; preds = %21, %19
%23 = phi i8* [ %20, %19 ], [ bitcast ([24 x i32]* @.str to i8*), %21 ]
ret i8* %23
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [24 x i32] [i32 69, i32 114, i32 114, i32 111, i32 114, i32 32, i32 105, i32 110, i32 32, i32 112, i32 114, i32 105, i32 110, i32 116, i32 105, i32 110, i32 103, i32 32, i32 101, i32 114, i32 114, i32 111, i32 114, i32 0]
define i8* @bt_error(i8* nocapture readnone %0) {
%2 = load i32, i32* @errno
%3 = tail call i8* @strerror(i32 %2)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = trunc i64 %4 to i32
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i64 @mbstowcs(i8* %6, i8* %3, i64 %4)
%8 = icmp eq i64 %7, -1
%9 = select i1 %8, i8* bitcast ([24 x i32]* @.str to i8*), i8* %6
ret i8* %9
}