#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ out_buf;
typedef int /*<<< orphan*/ iconv_t;
struct TYPE_3__ {
  char *map;
  scalar_t__ release;
  scalar_t__ convert;
  scalar_t__ data;
};
typedef TYPE_1__ XML_Encoding;
typedef int /*<<< orphan*/ XML_Char;

/* 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 *, int /*<<< orphan*/ const *);
int encoding_hnd(void *data, const XML_Char *name, XML_Encoding *info) {
  int i;
  iconv_t conv_hnd;
  char in_buf[16], out_buf[16];
  char *p_in_buf, *p_out_buf;
  size_t in_size, out_size, conv_size;
  if ((conv_hnd = iconv_open("utf-16le", name)) == (iconv_t)-1)
    return 0;
  info->data = 0;
  info->convert = 0;
  info->release = 0;
  for (i = 0; i < 256; i++) {
    in_size = 1;
    p_in_buf = in_buf;
    in_buf[0] = i;
    out_size = sizeof(out_buf);
    p_out_buf = out_buf;
    conv_size = iconv(conv_hnd, &p_in_buf, &in_size, &p_out_buf, &out_size);
    if (conv_size == (size_t)-1) {
      info->map[i] = '?';
      out_size = sizeof(out_buf);
      p_out_buf = out_buf;
      iconv(conv_hnd, 0, 0, &p_out_buf, &out_size);
    } else {
      info->map[i] = out_buf[0] | (out_buf[1] << 8);
    }
  }
  iconv_close(conv_hnd);
  return 1;
}


x86 assembly (clang, -O0):
<encoding_hnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xeae(%rip),%rdi
call   1050 <iconv_open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    116f <encoding_hnd+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    126e <encoding_hnd+0x13e>
mov    -0x20(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    125f <encoding_hnd+0x12f>
movq   $0x1,-0x68(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,-0x40(%rbp)
movq   $0x10,-0x70(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x68(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x70(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0xffffffffffffffff,-0x78(%rbp)
jne    122f <encoding_hnd+0xff>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0x3f,(%rax,%rcx,1)
movq   $0x10,-0x70(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x60(%rbp),%rcx
lea    -0x70(%rbp),%r8
mov    %rdx,%rsi
call   1030 <iconv@plt>
jmp    124c <encoding_hnd+0x11c>
movsbl -0x50(%rbp),%eax
movsbl -0x4f(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1251 <encoding_hnd+0x121>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <encoding_hnd+0x6a>
mov    -0x28(%rbp),%edi
call   1040 <iconv_close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encoding_hnd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
lea    0xeb8(%rip),%rdi
call   1050 <iconv_open@plt>
cmp    $0xffffffff,%eax
je     1211 <encoding_hnd+0xe1>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rbx)
movq   $0x0,0x18(%rbx)
xor    %r14d,%r14d
lea    0x20(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%r13
jmp    1199 <encoding_hnd+0x69>
nopl   0x0(%rax)
movzbl 0x20(%rsp),%eax
mov    (%rbx),%rcx
mov    %al,(%rcx,%r14,1)
add    $0x1,%r14
cmp    $0x100,%r14
je     1203 <encoding_hnd+0xd3>
movq   $0x1,0x10(%rsp)
lea    0x30(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %r14b,0x30(%rsp)
movq   $0x10,(%rsp)
mov    %r15,0x8(%rsp)
mov    %ebp,%edi
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    1180 <encoding_hnd+0x50>
mov    (%rbx),%rax
movb   $0x3f,(%rax,%r14,1)
movq   $0x10,(%rsp)
mov    %r15,0x8(%rsp)
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <iconv@plt>
jmp    118c <encoding_hnd+0x5c>
mov    %ebp,%edi
call   1040 <iconv_close@plt>
mov    $0x1,%eax
jmp    1213 <encoding_hnd+0xe3>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8*, i64, i64, i64 }
@.str = [9 x i8] c"utf-16le\00"
define i32 @encoding_hnd(i8* %0, i32* %1, %struct.TYPE_3__* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.TYPE_3__*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i8* %0, i8** %5
store i32* %1, i32** %6
store %struct.TYPE_3__* %2, %struct.TYPE_3__** %7
%17 = load i32*, i32** %6
%18 = call i32 @iconv_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %17)
store i32 %18, i32* %9
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 0, i32* %4
br label %74
21: ; preds = %3
%22 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 3
store i64 0, i64* %23
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 2
store i64 0, i64* %25
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 1
store i64 0, i64* %27
store i32 0, i32* %8
br label %28
28: ; preds = %68, %21
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 256
br i1 %30, label %31, label %71
31: ; preds = %28
store i64 1, i64* %14
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
store i8* %32, i8** %12
%33 = load i32, i32* %8
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
store i8 %34, i8* %35
store i64 16, i64* %15
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
store i8* %36, i8** %13
%37 = load i32, i32* %9
%38 = call i64 @iconv(i32 %37, i8** %12, i64* %14, i8** %13, i64* %15)
store i64 %38, i64* %16
%39 = load i64, i64* %16
%40 = icmp eq i64 %39, -1
br i1 %40, label %41, label %51
41: ; preds = %31
%42 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 63, i8* %47
store i64 16, i64* %15
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
store i8* %48, i8** %13
%49 = load i32, i32* %9
%50 = call i64 @iconv(i32 %49, i8** null, i64* null, i8** %13, i64* %15)
br label %67
51: ; preds = %31
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 1
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = shl i32 %57, 8
%59 = or i32 %54, %58
%60 = trunc i32 %59 to i8
%61 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 %60, i8* %66
br label %67
67: ; preds = %51, %41
br label %68
68: ; preds = %67
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %28
71: ; preds = %28
%72 = load i32, i32* %9
%73 = call i32 @iconv_close(i32 %72)
store i32 1, i32* %4
br label %74
74: ; preds = %71, %20
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8*, i64, i64, i64 }
@.str = [9 x i8] c"utf-16le\00"
define i32 @encoding_hnd(i8* nocapture readnone %0, i32* %1, %struct.TYPE_3__* nocapture %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = bitcast i8** %6 to i8*
%13 = bitcast i8** %7 to i8*
%14 = bitcast i64* %8 to i8*
%15 = bitcast i64* %9 to i8*
%16 = tail call i32 @iconv_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %40, label %18
18: ; preds = %3
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
%21 = bitcast i64* %19 to i8*
br label %22
22: ; preds = %18, %35
%23 = phi i64 [ 0, %18 ], [ %36, %35 ]
store i64 1, i64* %8
store i8* %10, i8** %6
%24 = trunc i64 %23 to i8
store i8 %24, i8* %10
store i64 16, i64* %9
store i8* %11, i8** %7
%25 = call i64 @iconv(i32 %16, i8** %6, i64* %8, i8** %7, i64* %9)
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i8*, i8** %20
%29 = getelementptr inbounds i8, i8* %28, i64 %23
store i8 63, i8* %29
store i64 16, i64* %9
store i8* %11, i8** %7
%30 = call i64 @iconv(i32 %16, i8** null, i64* null, i8** %7, i64* %9)
br label %35
31: ; preds = %22
%32 = load i8, i8* %11
%33 = load i8*, i8** %20
%34 = getelementptr inbounds i8, i8* %33, i64 %23
store i8 %32, i8* %34
br label %35
35: ; preds = %27, %31
%36 = add nuw nsw i64 %23, 1
%37 = icmp eq i64 %36, 256
br i1 %37, label %38, label %22
38: ; preds = %35
%39 = call i32 @iconv_close(i32 %16)
br label %40
40: ; preds = %3, %38
%41 = phi i32 [ 1, %38 ], [ 0, %3 ]
ret i32 %41
}