#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 UTFConvert(char *sourceCode, char *targetCode, const void **sourceStart,
                  const void *sourceEnd, void **targetStart, void *targetEnd) {
  size_t result = 0;
  char *source = *(char **)sourceStart;
  char *target = *(char **)targetStart;
  size_t inbytesleft = sourceEnd - *sourceStart;
  size_t outbytesleft = targetEnd - *targetStart;
  iconv_t ic;
  ic = iconv_open(targetCode, sourceCode);
  while (inbytesleft > 0 && result != (size_t)-1) {
    result = iconv(ic, &source, &inbytesleft, &target, &outbytesleft);
  }
  *sourceStart = source;
  *targetStart = target;
  iconv_close(ic);
  return result;
}


x86 assembly (clang, -O0):
<UTFConvert>:
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    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <iconv_open@plt>
mov    %eax,-0x5c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x50(%rbp)
mov    %al,-0x5d(%rbp)
jbe    11bd <UTFConvert+0x8d>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
setne  %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    11cd <UTFConvert+0x9d>
jmp    11ee <UTFConvert+0xbe>
mov    -0x5c(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x38(%rbp)
jmp    11a2 <UTFConvert+0x72>
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x5c(%rbp),%edi
call   1040 <iconv_close@plt>
mov    -0x38(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UTFConvert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rdi,%rax
mov    (%rdx),%r14
mov    %r14,0x18(%rsp)
mov    (%r8),%r15
mov    %r15,0x10(%rsp)
sub    %r14,%rcx
mov    %rcx,0x8(%rsp)
sub    %r15,%r9
mov    %r9,0x30(%rsp)
mov    %rsi,%rdi
mov    %rax,%rsi
call   1050 <iconv_open@plt>
mov    %eax,%ebp
cmp    %r14,%rbx
je     11da <UTFConvert+0xaa>
mov    %r13,0x20(%rsp)
mov    %r12,0x28(%rsp)
lea    0x18(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%r14
lea    0x30(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1030 <iconv@plt>
mov    %rax,%rbx
cmpq   $0x0,0x8(%rsp)
je     11c4 <UTFConvert+0x94>
cmp    $0xffffffffffffffff,%rbx
jne    11a0 <UTFConvert+0x70>
mov    0x18(%rsp),%r14
mov    0x10(%rsp),%r15
mov    0x28(%rsp),%r12
mov    0x20(%rsp),%r13
jmp    11dc <UTFConvert+0xac>
xor    %ebx,%ebx
mov    %r14,0x0(%r13)
mov    %r15,(%r12)
mov    %ebp,%edi
call   1040 <iconv_close@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @UTFConvert(i8* %0, i8* %1, i8** %2, i8* %3, i8** %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8** %2, i8*** %9
store i8* %3, i8** %10
store i8** %4, i8*** %11
store i8* %5, i8** %12
store i64 0, i64* %13
%19 = load i8**, i8*** %9
%20 = load i8*, i8** %19
store i8* %20, i8** %14
%21 = load i8**, i8*** %11
%22 = load i8*, i8** %21
store i8* %22, i8** %15
%23 = load i8*, i8** %10
%24 = load i8**, i8*** %9
%25 = load i8*, i8** %24
%26 = ptrtoint i8* %23 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
store i64 %28, i64* %16
%29 = load i8*, i8** %12
%30 = load i8**, i8*** %11
%31 = load i8*, i8** %30
%32 = ptrtoint i8* %29 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
store i64 %34, i64* %17
%35 = load i8*, i8** %8
%36 = load i8*, i8** %7
%37 = call i32 @iconv_open(i8* %35, i8* %36)
store i32 %37, i32* %18
br label %38
38: ; preds = %46, %6
%39 = load i64, i64* %16
%40 = icmp ugt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i64, i64* %13
%43 = icmp ne i64 %42, -1
br label %44
44: ; preds = %41, %38
%45 = phi i1 [ false, %38 ], [ %43, %41 ]
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = load i32, i32* %18
%48 = call i64 @iconv(i32 %47, i8** %14, i64* %16, i8** %15, i64* %17)
store i64 %48, i64* %13
br label %38
49: ; preds = %44
%50 = load i8*, i8** %14
%51 = load i8**, i8*** %9
store i8* %50, i8** %51
%52 = load i8*, i8** %15
%53 = load i8**, i8*** %11
store i8* %52, i8** %53
%54 = load i32, i32* %18
%55 = call i32 @iconv_close(i32 %54)
%56 = load i64, i64* %13
ret i64 %56
}

LLVM IR (-O2):
define i64 @UTFConvert(i8* %0, i8* %1, i8** nocapture %2, i8* %3, i8** nocapture %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = bitcast i8** %7 to i8*
%12 = load i8*, i8** %2
store i8* %12, i8** %7
%13 = bitcast i8** %8 to i8*
%14 = load i8*, i8** %4
store i8* %14, i8** %8
%15 = bitcast i64* %9 to i8*
%16 = ptrtoint i8* %3 to i64
%17 = ptrtoint i8* %12 to i64
%18 = sub i64 %16, %17
store i64 %18, i64* %9
%19 = bitcast i64* %10 to i8*
%20 = ptrtoint i8* %5 to i64
%21 = ptrtoint i8* %14 to i64
%22 = sub i64 %20, %21
store i64 %22, i64* %10
%23 = tail call i32 @iconv_open(i8* %1, i8* %0)
%24 = icmp eq i64 %18, 0
br i1 %24, label %34, label %25
25: ; preds = %6, %25
%26 = call i64 @iconv(i32 %23, i8** %7, i64* %9, i8** %8, i64* %10)
%27 = load i64, i64* %9
%28 = icmp ne i64 %27, 0
%29 = icmp ne i64 %26, -1
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %25, label %31
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
br label %34
34: ; preds = %31, %6
%35 = phi i8* [ %14, %6 ], [ %33, %31 ]
%36 = phi i8* [ %12, %6 ], [ %32, %31 ]
%37 = phi i64 [ 0, %6 ], [ %26, %31 ]
store i8* %36, i8** %2
store i8* %35, i8** %4
%38 = call i32 @iconv_close(i32 %23)
ret i64 %37
}