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

/* Variables and functions */
int /*<<< orphan*/ assert(size_t);
int /*<<< orphan*/ free(int *);
size_t iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iconv_open(char *, char *);
int *malloc(size_t);
int strlen(char const *const);
void utf8ToWChar(wchar_t **out_wCharString, char const *const in_UTF8_STRING) {
  assert(*out_wCharString == NULL);
  char *utf8Ptr = (char *)in_UTF8_STRING;
  size_t utf8StringBytes = strlen(in_UTF8_STRING);
  size_t wCharStringBytes = sizeof(wchar_t) * utf8StringBytes;
  wchar_t *wCharString = malloc(wCharStringBytes);
  char *wCharPtr = (char *)wCharString;
  iconv_t c8t32 = iconv_open("WCHAR_T", "UTF-8");
  size_t error =
      iconv(c8t32, &utf8Ptr, &utf8StringBytes, &wCharPtr, &wCharStringBytes);
  assert(error != (size_t)(-1));
  free(wCharString);
  utf8Ptr = (char *)in_UTF8_STRING;
  utf8StringBytes = sizeof(char) * strlen(in_UTF8_STRING);
  wCharStringBytes =
      sizeof(wchar_t) * utf8StringBytes - wCharStringBytes + sizeof(wchar_t);
  wCharString = malloc(wCharStringBytes);
  wCharPtr = (char *)wCharString;
  error =
      iconv(c8t32, &utf8Ptr, &utf8StringBytes, &wCharPtr, &wCharStringBytes);
  assert(error != (size_t)(-1));
  iconv_close(c8t32);
  assert(wCharStringBytes = sizeof(wchar_t));
  *(wchar_t *)(wCharPtr) = L'\0';
  *out_wCharString = wCharString;
}


x86 assembly (clang, -O0):
<utf8ToWChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe29(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   1090 <iconv_open@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1040 <iconv@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1060 <assert@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
sub    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1040 <iconv@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1060 <assert@plt>
mov    -0x3c(%rbp),%edi
call   1080 <iconv_close@plt>
movq   $0x4,-0x28(%rbp)
mov    $0x4,%edi
call   1060 <assert@plt>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8ToWChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
cmpq   $0x0,(%r14)
sete   %dil
call   1060 <assert@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
mov    %rdi,0x20(%rsp)
shl    $0x2,%rdi
mov    %rdi,0x8(%rsp)
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
lea    0xe3b(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <iconv_open@plt>
mov    %eax,%ebp
lea    0x18(%rsp),%rsi
lea    0x20(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%r8
mov    %eax,%edi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <iconv@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
mov    %rdi,0x20(%rsp)
shl    $0x2,%rdi
sub    0x8(%rsp),%rdi
add    $0x4,%rdi
mov    %rdi,0x8(%rsp)
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
lea    0x18(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
lea    0x8(%rsp),%r8
call   1040 <iconv@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1060 <assert@plt>
mov    %ebp,%edi
call   1080 <iconv_close@plt>
movq   $0x4,0x8(%rsp)
mov    $0x4,%edi
call   1060 <assert@plt>
mov    0x10(%rsp),%rax
movl   $0x0,(%rax)
mov    %rbx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"WCHAR_T\00"
@.str.1 = [6 x i8] c"UTF-8\00"
define void @utf8ToWChar(i32** %0, i8* %1) {
%3 = alloca i32**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
store i32** %0, i32*** %3
store i8* %1, i8** %4
%12 = load i32**, i32*** %3
%13 = load i32*, i32** %12
%14 = icmp eq i32* %13, null
%15 = zext i1 %14 to i32
%16 = sext i32 %15 to i64
%17 = call i32 @assert(i64 %16)
%18 = load i8*, i8** %4
store i8* %18, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = mul i64 4, %22
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = call i32* @malloc(i64 %24)
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = bitcast i32* %26 to i8*
store i8* %27, i8** %9
%28 = call i32 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = call i64 @iconv(i32 %29, i8** %5, i64* %6, i8** %9, i64* %7)
store i64 %30, i64* %11
%31 = load i64, i64* %11
%32 = icmp ne i64 %31, -1
%33 = zext i1 %32 to i32
%34 = sext i32 %33 to i64
%35 = call i32 @assert(i64 %34)
%36 = load i32*, i32** %8
%37 = call i32 @free(i32* %36)
%38 = load i8*, i8** %4
store i8* %38, i8** %5
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = mul i64 1, %41
store i64 %42, i64* %6
%43 = load i64, i64* %6
%44 = mul i64 4, %43
%45 = load i64, i64* %7
%46 = sub i64 %44, %45
%47 = add i64 %46, 4
store i64 %47, i64* %7
%48 = load i64, i64* %7
%49 = call i32* @malloc(i64 %48)
store i32* %49, i32** %8
%50 = load i32*, i32** %8
%51 = bitcast i32* %50 to i8*
store i8* %51, i8** %9
%52 = load i32, i32* %10
%53 = call i64 @iconv(i32 %52, i8** %5, i64* %6, i8** %9, i64* %7)
store i64 %53, i64* %11
%54 = load i64, i64* %11
%55 = icmp ne i64 %54, -1
%56 = zext i1 %55 to i32
%57 = sext i32 %56 to i64
%58 = call i32 @assert(i64 %57)
%59 = load i32, i32* %10
%60 = call i32 @iconv_close(i32 %59)
store i64 4, i64* %7
%61 = call i32 @assert(i64 4)
%62 = load i8*, i8** %9
%63 = bitcast i8* %62 to i32*
store i32 0, i32* %63
%64 = load i32*, i32** %8
%65 = load i32**, i32*** %3
store i32* %64, i32** %65
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"WCHAR_T\00"
@.str.1 = [6 x i8] c"UTF-8\00"
define void @utf8ToWChar(i32** nocapture %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = load i32*, i32** %0
%8 = icmp eq i32* %7, null
%9 = zext i1 %8 to i64
%10 = tail call i32 @assert(i64 %9)
%11 = bitcast i8** %3 to i8*
store i8* %1, i8** %3
%12 = bitcast i64* %4 to i8*
%13 = tail call i32 @strlen(i8* %1)
%14 = sext i32 %13 to i64
store i64 %14, i64* %4
%15 = bitcast i64* %5 to i8*
%16 = shl nsw i64 %14, 2
store i64 %16, i64* %5
%17 = tail call i32* @malloc(i64 %16)
%18 = bitcast i8** %6 to i8*
%19 = bitcast i8** %6 to i32**
store i32* %17, i32** %19
%20 = tail call i32 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = call i64 @iconv(i32 %20, i8** %3, i64* %4, i8** %6, i64* %5)
%22 = icmp ne i64 %21, -1
%23 = zext i1 %22 to i64
%24 = call i32 @assert(i64 %23)
%25 = call i32 @free(i32* %17)
store i8* %1, i8** %3
%26 = call i32 @strlen(i8* %1)
%27 = sext i32 %26 to i64
store i64 %27, i64* %4
%28 = shl nsw i64 %27, 2
%29 = load i64, i64* %5
%30 = sub i64 %28, %29
%31 = add i64 %30, 4
store i64 %31, i64* %5
%32 = call i32* @malloc(i64 %31)
store i32* %32, i32** %19
%33 = call i64 @iconv(i32 %20, i8** %3, i64* %4, i8** %6, i64* %5)
%34 = icmp ne i64 %33, -1
%35 = zext i1 %34 to i64
%36 = call i32 @assert(i64 %35)
%37 = call i32 @iconv_close(i32 %20)
store i64 4, i64* %5
%38 = call i32 @assert(i64 4)
%39 = load i32*, i32** %19
store i32 0, i32* %39
store i32* %32, i32** %0
ret void
}