#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*/ uc;
typedef int /*<<< orphan*/ iconv_t;
typedef int /*<<< orphan*/ c;

/* Variables and functions */
int /*<<< orphan*/ iconv(int /*<<< orphan*/, void *, size_t *, void *,
                         size_t *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iconv_open(char *, char *);
int vbi_ucs2be(void) {
  iconv_t cd;
  char c = 'b', *cp = &c;
  char uc[2] = {'a', 'a'}, *up = uc;
  size_t in = sizeof(c), out = sizeof(uc);
  int endianess = -1;
  if ((cd = iconv_open("UCS-2", "ISO-8859-1")) != (iconv_t)-1) {
    iconv(cd, (void *)&cp, &in, (void *)&up, &out);
    if (uc[0] == 0 && uc[1] == 'b')
      endianess = 1;
    else if (uc[1] == 0 && uc[0] == 'b')
      endianess = 0;
    iconv_close(cd);
  }
  return endianess;
}


x86 assembly (clang, -O0):
<vbi_ucs2be>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movb   $0x62,-0x5(%rbp)
lea    -0x5(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0x12(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
movq   $0x2,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <iconv_open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     11f9 <vbi_ucs2be+0xc9>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%r8
call   1030 <iconv@plt>
movsbl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    11cb <vbi_ucs2be+0x9b>
movsbl -0x11(%rbp),%eax
cmp    $0x62,%eax
jne    11cb <vbi_ucs2be+0x9b>
movl   $0x1,-0x34(%rbp)
jmp    11f1 <vbi_ucs2be+0xc1>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    11ec <vbi_ucs2be+0xbc>
movsbl -0x12(%rbp),%eax
cmp    $0x62,%eax
jne    11ec <vbi_ucs2be+0xbc>
movl   $0x0,-0x34(%rbp)
jmp    11f1 <vbi_ucs2be+0xc1>
mov    -0x4(%rbp),%edi
call   1040 <iconv_close@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vbi_ucs2be>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movb   $0x62,0x7(%rsp)
lea    0x7(%rsp),%rax
mov    %rax,0x20(%rsp)
movw   $0x6161,0x4(%rsp)
lea    0x4(%rsp),%rax
mov    %rax,0x18(%rsp)
movq   $0x1,0x10(%rsp)
movq   $0x2,0x8(%rsp)
lea    0xe91(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1050 <iconv_open@plt>
cmp    $0xffffffff,%eax
je     11cd <vbi_ucs2be+0x9d>
mov    %eax,%ebx
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %eax,%edi
call   1030 <iconv@plt>
mov    0x4(%rsp),%sil
mov    0x5(%rsp),%cl
mov    %ecx,%edx
xor    $0x62,%dl
mov    %esi,%eax
xor    $0x62,%al
xor    %edi,%edi
or     %cl,%al
setne  %dil
neg    %edi
or     %sil,%dl
mov    $0x1,%ebp
cmovne %edi,%ebp
mov    %ebx,%edi
call   1040 <iconv_close@plt>
jmp    11d2 <vbi_ucs2be+0xa2>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.vbi_ucs2be.uc = [2 x i8] c"aa"
@.str = [6 x i8] c"UCS-2\00"
@.str.1 = [11 x i8] c"ISO-8859-1\00"
define i32 @vbi_ucs2be() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8 98, i8* %2
store i8* %2, i8** %3
%9 = bitcast [2 x i8]* %4 to i8*
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8* %10, i8** %5
store i64 1, i64* %6
store i64 2, i64* %7
store i32 -1, i32* %8
%11 = call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %1
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %43
13: ; preds = %0
%14 = load i32, i32* %1
%15 = bitcast i8** %3 to i8*
%16 = bitcast i8** %5 to i8*
%17 = call i32 @iconv(i32 %14, i8* %15, i64* %6, i8* %16, i64* %7)
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 98
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %8
br label %40
28: ; preds = %22, %13
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 98
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 0, i32* %8
br label %39
39: ; preds = %38, %33, %28
br label %40
40: ; preds = %39, %27
%41 = load i32, i32* %1
%42 = call i32 @iconv_close(i32 %41)
br label %43
43: ; preds = %40, %0
%44 = load i32, i32* %8
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"UCS-2\00"
@.str.1 = [11 x i8] c"ISO-8859-1\00"
define i32 @vbi_ucs2be() {
%1 = alloca i8
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8 98, i8* %1
%7 = bitcast i8** %2 to i8*
store i8* %1, i8** %2
%8 = bitcast i16* %3 to i8*
store i16 24929, i16* %3
%9 = bitcast i8** %4 to i8*
%10 = bitcast i8** %4 to i16**
store i16* %3, i16** %10
%11 = bitcast i64* %5 to i8*
store i64 1, i64* %5
%12 = bitcast i64* %6 to i8*
store i64 2, i64* %6
%13 = call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %30, label %15
15: ; preds = %0
%16 = bitcast i16* %3 to [2 x i8]*
%17 = call i32 @iconv(i32 %13, i8* %7, i64* %5, i8* %9, i64* %6)
%18 = load i8, i8* %8
%19 = icmp eq i8 %18, 0
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %16, i64 0, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 98
%23 = select i1 %19, i1 %22, i1 false
%24 = icmp ne i8 %21, 0
%25 = icmp ne i8 %18, 98
%26 = select i1 %24, i1 true, i1 %25
%27 = sext i1 %26 to i32
%28 = select i1 %23, i32 1, i32 %27
%29 = call i32 @iconv_close(i32 %13)
br label %30
30: ; preds = %15, %0
%31 = phi i32 [ %28, %15 ], [ -1, %0 ]
ret i32 %31
}