#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*/ assert(int);
scalar_t__ iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_open(char *, char *);
scalar_t__ memcmp(char *, char *, int);
int main() {
  iconv_t i = iconv_open("UTF-16BE", "UTF-16");
  char foo[100] = "\xFE\xFF\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61";
  char bar[100];
  char *x = foo, *y = bar;
  size_t X = 12, Y = 100;
  assert(iconv(i, &x, &X, &y, &Y) == 0 && X == 0 && Y == 90);
  assert(memcmp(bar, "\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61", 10) == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <iconv_open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x64,%edx
call   1060 <memcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
movq   $0xc,-0xf8(%rbp)
movq   $0x64,-0x100(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xe8(%rbp),%rsi
lea    -0xf8(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    -0x100(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x101(%rbp)
jne    121c <main+0xcc>
xor    %eax,%eax
cmpq   $0x0,-0xf8(%rbp)
mov    %al,-0x101(%rbp)
jne    121c <main+0xcc>
cmpq   $0x5a,-0x100(%rbp)
5a
sete   %al
mov    %al,-0x101(%rbp)
mov    -0x101(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0xa,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <iconv_open@plt>
movaps 0xefe(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe72(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x80(%rsp)
lea    0x20(%rsp),%rcx
mov    %rcx,0x18(%rsp)
lea    0x90(%rsp),%rbx
mov    %rbx,0x10(%rsp)
movq   $0xc,0x8(%rsp)
movq   $0x64,(%rsp)
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    %eax,%edi
call   1030 <iconv@plt>
or     0x8(%rsp),%rax
mov    (%rsp),%rcx
xor    $0x5a,%rcx
xor    %edi,%edi
or     %rax,%rcx
sete   %dil
call   1050 <assert@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"UTF-16BE\00"
@.str.1 = [7 x i8] c"UTF-16\00"
@__const.main.foo = [100 x i8] c"\FE\FF\D8\08\DFE\00=\00R\00a\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [11 x i8] c"\D8\08\DFE\00=\00R\00a\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 @iconv_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %2
%10 = bitcast [100 x i8]* %3 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
store i8* %11, i8** %5
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i8* %12, i8** %6
store i64 12, i64* %7
store i64 100, i64* %8
%13 = load i32, i32* %2
%14 = call i64 @iconv(i32 %13, i8** %5, i64* %7, i8** %6, i64* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %0
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i64, i64* %8
%21 = icmp eq i64 %20, 90
br label %22
22: ; preds = %19, %16, %0
%23 = phi i1 [ false, %16 ], [ false, %0 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i64 @memcmp(i8* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"UTF-16BE\00"
@.str.1 = [7 x i8] c"UTF-16\00"
@__const.main.foo = [100 x i8] c"\FE\FF\D8\08\DFE\00=\00R\00a\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [11 x i8] c"\D8\08\DFE\00=\00R\00a\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = tail call i32 @iconv_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = bitcast i8** %3 to i8*
store i8* %8, i8** %3
%11 = bitcast i8** %4 to i8*
store i8* %9, i8** %4
%12 = bitcast i64* %5 to i8*
store i64 12, i64* %5
%13 = bitcast i64* %6 to i8*
store i64 100, i64* %6
%14 = call i64 @iconv(i32 %7, i8** %3, i64* %5, i8** %4, i64* %6)
%15 = icmp eq i64 %14, 0
%16 = load i64, i64* %5
%17 = icmp eq i64 %16, 0
%18 = select i1 %15, i1 %17, i1 false
%19 = load i64, i64* %6
%20 = icmp eq i64 %19, 90
%21 = select i1 %18, i1 %20, i1 false
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i64 @memcmp(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret i32 0
}