#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 utf8_to_utf16(short *, char *, int);
int /*<<< orphan*/ willus_mem_alloc_warn(void **, int, char *, int);
int utf8_to_utf16_alloc(void **d, char *s) {
  int len;
  short *dw;
  static char *funcname = "utf8_to_utf16_alloc";
  (*d) = NULL;
  len = utf8_to_utf16(NULL, s, -1);
  willus_mem_alloc_warn(d, sizeof(short) * (len + 1), funcname, 10);
  dw = (short *)(*d);
  utf8_to_utf16(dw, s, len);
  return (len);
}


x86 assembly (clang, -O0):
<utf8_to_utf16_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%edx
call   1040 <utf8_to_utf16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x1,%rax
mov    %eax,%esi
mov    0x2ec7(%rip),%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <utf8_to_utf16@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_to_utf16_alloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,(%rdi)
xor    %edi,%edi
mov    $0xffffffff,%edx
call   1040 <utf8_to_utf16@plt>
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%esi
add    $0x2,%esi
lea    0xeb3(%rip),%rdx
mov    %r15,%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    (%r15),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <utf8_to_utf16@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@utf8_to_utf16_alloc.funcname = internal global i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0)
@.str = [20 x i8] c"utf8_to_utf16_alloc\00"
define i32 @utf8_to_utf16_alloc(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8**, i8*** %3
store i8* null, i8** %7
%8 = load i8*, i8** %4
%9 = call i32 @utf8_to_utf16(i16* null, i8* %8, i32 -1)
store i32 %9, i32* %5
%10 = load i8**, i8*** %3
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 2, %13
%15 = trunc i64 %14 to i32
%16 = load i8*, i8** @utf8_to_utf16_alloc.funcname
%17 = call i32 @willus_mem_alloc_warn(i8** %10, i32 %15, i8* %16, i32 10)
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = bitcast i8* %19 to i16*
store i16* %20, i16** %6
%21 = load i16*, i16** %6
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = call i32 @utf8_to_utf16(i16* %21, i8* %22, i32 %23)
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@.str = [20 x i8] c"utf8_to_utf16_alloc\00"
define i32 @utf8_to_utf16_alloc(i8** %0, i8* %1) {
store i8* null, i8** %0
%3 = tail call i32 @utf8_to_utf16(i16* null, i8* %1, i32 -1)
%4 = shl i32 %3, 1
%5 = add i32 %4, 2
%6 = tail call i32 @willus_mem_alloc_warn(i8** %0, i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = bitcast i8** %0 to i16**
%8 = load i16*, i16** %7
%9 = tail call i32 @utf8_to_utf16(i16* %8, i8* %1, i32 %3)
ret i32 %3
}