#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 */
int /*<<< orphan*/ iconv(int /*<<< orphan*/, char **, size_t *, char **,
                         size_t *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iconv_open(char *, char *);
scalar_t__ malloc(size_t);
scalar_t__ realloc(char *, size_t);
void sk_iconv_utf8(char *fromcode, char *inString, size_t inLen,
                   char **outString) {
  iconv_t cd = iconv_open("UTF-8", fromcode);
  size_t inbytesleft = inLen;
  size_t outbytesleft = inLen * 2;
  char *temp = (char *)malloc(inLen * 2);
  char *inbuf = inString;
  char *outbuf = temp;
  iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
  size_t newLen = inLen * 2 - outbytesleft + 1;
  temp[newLen - 1] = 0;
  temp = (char *)realloc(temp, newLen);
  *outString = temp;
  iconv_close(cd);
}


x86 assembly (clang, -O0):
<sk_iconv_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1070 <iconv_open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1030 <iconv@plt>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
sub    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x58(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%edi
call   1060 <iconv_close@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sk_iconv_utf8>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0xe91(%rip),%rdi
call   1070 <iconv_open@plt>
mov    %eax,%r12d
mov    %rbx,0x18(%rsp)
add    %rbx,%rbx
mov    %rbx,(%rsp)
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %r15,0x10(%rsp)
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %r12d,%edi
call   1030 <iconv@plt>
sub    (%rsp),%rbx
movb   $0x0,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,(%r14)
mov    %r12d,%edi
call   1060 <iconv_close@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"UTF-8\00"
define void @sk_iconv_utf8(i8* %0, i8* %1, i64 %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8** %3, i8*** %8
%16 = load i8*, i8** %5
%17 = call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 %17, i32* %9
%18 = load i64, i64* %7
store i64 %18, i64* %10
%19 = load i64, i64* %7
%20 = mul i64 %19, 2
store i64 %20, i64* %11
%21 = load i64, i64* %7
%22 = mul i64 %21, 2
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %12
%25 = load i8*, i8** %6
store i8* %25, i8** %13
%26 = load i8*, i8** %12
store i8* %26, i8** %14
%27 = load i32, i32* %9
%28 = call i32 @iconv(i32 %27, i8** %13, i64* %10, i8** %14, i64* %11)
%29 = load i64, i64* %7
%30 = mul i64 %29, 2
%31 = load i64, i64* %11
%32 = sub i64 %30, %31
%33 = add i64 %32, 1
store i64 %33, i64* %15
%34 = load i8*, i8** %12
%35 = load i64, i64* %15
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %12
%39 = load i64, i64* %15
%40 = call i64 @realloc(i8* %38, i64 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %12
%42 = load i8*, i8** %12
%43 = load i8**, i8*** %8
store i8* %42, i8** %43
%44 = load i32, i32* %9
%45 = call i32 @iconv_close(i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"UTF-8\00"
define void @sk_iconv_utf8(i8* %0, i8* %1, i64 %2, i8** nocapture writeonly %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = tail call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = bitcast i64* %5 to i8*
store i64 %2, i64* %5
%11 = bitcast i64* %6 to i8*
%12 = shl i64 %2, 1
store i64 %12, i64* %6
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = bitcast i8** %7 to i8*
store i8* %1, i8** %7
%16 = bitcast i8** %8 to i8*
store i8* %14, i8** %8
%17 = call i32 @iconv(i32 %9, i8** %7, i64* %5, i8** %8, i64* %6)
%18 = load i64, i64* %6
%19 = sub i64 %12, %18
%20 = add i64 %19, 1
%21 = getelementptr inbounds i8, i8* %14, i64 %19
store i8 0, i8* %21
%22 = call i64 @realloc(i8* %14, i64 %20)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %3
%24 = call i32 @iconv_close(i32 %9)
ret void
}