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


x86 assembly (clang, -O0):
<utf16_to_utf8_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   1030 <utf16_to_utf8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    0x2ecf(%rip),%rdx
mov    $0xa,%ecx
call   1040 <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   1030 <utf16_to_utf8@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@utf16_to_utf8_alloc.funcname = internal global i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0)
@.str = [20 x i8] c"utf16_to_utf8_alloc\00"
define i32 @utf16_to_utf8_alloc(i8** %0, i16* %1) {
%3 = alloca i8**
%4 = alloca i16*
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %3
store i16* %1, i16** %4
%7 = load i8**, i8*** %3
store i8* null, i8** %7
%8 = load i16*, i16** %4
%9 = call i32 @utf16_to_utf8(i8* null, i16* %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 = load i8*, i8** @utf16_to_utf8_alloc.funcname
%14 = call i32 @willus_mem_alloc_warn(i8** %10, i32 %12, i8* %13, i32 10)
%15 = load i8**, i8*** %3
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i16*, i16** %4
%19 = load i32, i32* %5
%20 = call i32 @utf16_to_utf8(i8* %17, i16* %18, i32 %19)
%21 = load i32, i32* %5
ret i32 %21
}

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