#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 wchar_t;

/* Variables and functions */
scalar_t__ UTF2UnicodeOne(char const *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char const *);
int /*<<< orphan*/ wcsncpy(char *, char *, int);
int UTF2Unicode(const char *utfBuf, wchar_t *pUnicode) {
  int len = strlen(utfBuf);
  int i = 0, count = 0;
  wchar_t w_Unicode[30];
  memset(w_Unicode, 0, 30 * sizeof(wchar_t));
  while (i < len) {
    i += UTF2UnicodeOne(utfBuf + i, &(w_Unicode[count]));
    count++;
  }
  wcsncpy(pUnicode, w_Unicode, count);
  pUnicode[count] = '\0';
  return count;
}


x86 assembly (clang, -O0):
<UTF2Unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bc <UTF2Unicode+0x7c>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
lea    -0x40(%rbp),%rsi
add    %rax,%rsi
call   1060 <UTF2UnicodeOne@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <UTF2Unicode+0x3a>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <wcsncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UTF2Unicode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <memset@plt>
test   %r12d,%r12d
jle    119b <UTF2Unicode+0x5b>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
lea    (%rsp,%rbx,1),%rsi
call   1060 <UTF2UnicodeOne@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %r12d,%ebp
jl     1180 <UTF2Unicode+0x40>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1050 <wcsncpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @UTF2Unicode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [30 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 30)
br label %13
13: ; preds = %17, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %23
%25 = call i64 @UTF2UnicodeOne(i8* %21, i8* %24)
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %6
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %13
32: ; preds = %13
%33 = load i8*, i8** %4
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i32 @wcsncpy(i8* %33, i8* %34, i32 %35)
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
define i32 @UTF2Unicode(i8* %0, i8* %1) {
%3 = alloca [30 x i8]
%4 = tail call i32 @strlen(i8* %0)
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 30)
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %21
8: ; preds = %2, %8
%9 = phi i64 [ %17, %8 ], [ 0, %2 ]
%10 = phi i32 [ %16, %8 ], [ 0, %2 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %9
%14 = call i64 @UTF2UnicodeOne(i8* %12, i8* %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %10, %15
%17 = add nuw i64 %9, 1
%18 = icmp slt i32 %16, %4
br i1 %18, label %8, label %19
19: ; preds = %8
%20 = trunc i64 %17 to i32
br label %21
21: ; preds = %19, %2
%22 = phi i32 [ 0, %2 ], [ %20, %19 ]
%23 = call i32 @wcsncpy(i8* %1, i8* %5, i32 %22)
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
ret i32 %22
}