#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*/ iconv_t;

/* Variables and functions */
size_t iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iconv_open(char *, char *);
size_t sutUTF16_to_UTF8(char *inUTF16, size_t inUTF16Len, char *outUTF8,
                        size_t outUTF8Len) {
  iconv_t icCtx = iconv_open("UTF-8", "UTF-16");
  size_t len = iconv(icCtx, &inUTF16, &inUTF16Len, &outUTF8, &outUTF8Len);
  iconv_close(icCtx);
  return len;
}


x86 assembly (clang, -O0):
<sutUTF16_to_UTF8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    0xeb1(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1050 <iconv_open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <iconv_close@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sutUTF16_to_UTF8>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x20(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rcx,0x8(%rsp)
lea    0xeae(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <iconv_open@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %eax,%edi
call   1030 <iconv@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1040 <iconv_close@plt>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [7 x i8] c"UTF-16\00"
define i64 @sutUTF16_to_UTF8(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i64 @iconv(i32 %12, i8** %5, i64* %6, i8** %7, i64* %8)
store i64 %13, i64* %10
%14 = load i32, i32* %9
%15 = call i32 @iconv_close(i32 %14)
%16 = load i64, i64* %10
ret i64 %16
}

LLVM IR (-O2):
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [7 x i8] c"UTF-16\00"
define i64 @sutUTF16_to_UTF8(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = tail call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @iconv(i32 %9, i8** %5, i64* %6, i8** %7, i64* %8)
%11 = call i32 @iconv_close(i32 %9)
ret i64 %10
}