#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 int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ *bmalloc(size_t);
size_t os_mbs_to_wcs(char const *, size_t, int /*<<< orphan*/ *, size_t);
size_t os_mbs_to_wcs_ptr(const char *str, size_t len, wchar_t **pstr) {
  if (str) {
    size_t out_len = os_mbs_to_wcs(str, len, NULL, 0);
    *pstr = bmalloc((out_len + 1) * sizeof(wchar_t));
    return os_mbs_to_wcs(str, len, *pstr, out_len + 1);
  } else {
    *pstr = NULL;
    return 0;
  }
}


x86 assembly (clang, -O0):
<os_mbs_to_wcs_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1197 <os_mbs_to_wcs_ptr+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <os_mbs_to_wcs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
shl    $0x2,%rdi
call   1030 <bmalloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
call   1040 <os_mbs_to_wcs@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <os_mbs_to_wcs_ptr+0x8a>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_mbs_to_wcs_ptr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %rdi,%rdi
je     116f <os_mbs_to_wcs_ptr+0x4f>
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <os_mbs_to_wcs@plt>
lea    0x4(,%rax,4),%rdi
lea    0x1(%rax),%r12
call   1030 <bmalloc@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <os_mbs_to_wcs@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @os_mbs_to_wcs_ptr(i8* %0, i64 %1, i32** %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32**
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32** %2, i32*** %7
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %27
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i64 @os_mbs_to_wcs(i8* %12, i64 %13, i32* null, i64 0)
store i64 %14, i64* %8
%15 = load i64, i64* %8
%16 = add i64 %15, 1
%17 = mul i64 %16, 4
%18 = call i32* @bmalloc(i64 %17)
%19 = load i32**, i32*** %7
store i32* %18, i32** %19
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = load i32**, i32*** %7
%23 = load i32*, i32** %22
%24 = load i64, i64* %8
%25 = add i64 %24, 1
%26 = call i64 @os_mbs_to_wcs(i8* %20, i64 %21, i32* %23, i64 %25)
store i64 %26, i64* %4
br label %29
27: ; preds = %3
%28 = load i32**, i32*** %7
store i32* null, i32** %28
store i64 0, i64* %4
br label %29
29: ; preds = %27, %11
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
define i64 @os_mbs_to_wcs_ptr(i8* %0, i64 %1, i32** nocapture writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i64 @os_mbs_to_wcs(i8* %0, i64 %1, i32* null, i64 0)
%7 = add i64 %6, 1
%8 = shl i64 %7, 2
%9 = tail call i32* @bmalloc(i64 %8)
store i32* %9, i32** %2
%10 = tail call i64 @os_mbs_to_wcs(i8* %0, i64 %1, i32* %9, i64 %7)
br label %12
11: ; preds = %3
store i32* null, i32** %2
br label %12
12: ; preds = %11, %5
%13 = phi i64 [ %10, %5 ], [ 0, %11 ]
ret i64 %13
}