#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 wchar_t;
typedef int /*<<< orphan*/ wbuf;
typedef scalar_t__ iconv_t;

/* Variables and functions */
int /*<<< orphan*/ CODESET;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *);
char *gettext(char *);
int /*<<< orphan*/ iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char const *, char const *);
char *nl_langinfo(int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int open_conversion(const char *codeset, iconv_t *cd_towcp, iconv_t *cd_tombp,
                    wchar_t *escape_charp) {
  char buf[2];
  char *bufptr;
  size_t bufsize;
  wchar_t wbuf[2];
  char *wbufptr;
  size_t wbufsize;
  if (codeset == NULL) {
    setlocale(LC_ALL, "");
    codeset = nl_langinfo(CODESET);
    setlocale(LC_ALL, "C");
  }
  *cd_towcp = iconv_open("WCHAR_T", codeset);
  *cd_tombp = iconv_open(codeset, "WCHAR_T");
  if (*cd_towcp == (iconv_t)-1 || *cd_tombp == (iconv_t)-1) {
    error(0, 0, gettext("conversion modules not available"));
    if (*cd_towcp != (iconv_t)-1)
      iconv_close(*cd_towcp);
    return 1;
  }
  buf[0] = '\\';
  buf[1] = '\0';
  bufptr = buf;
  bufsize = 2;
  wbufptr = (char *)wbuf;
  wbufsize = sizeof(wbuf);
  iconv(*cd_towcp, &bufptr, &bufsize, &wbufptr, &wbufsize);
  if (bufsize != 0 || wbufsize != 0) {
    error(0, 0, gettext("cannot determine escape character"));
    *escape_charp = L'\\';
  } else
    *escape_charp = wbuf[0];
  return 0;
}


x86 assembly (clang, -O0):
<open_conversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <open_conversion+0x5f>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1060 <setlocale@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1060 <setlocale@plt>
mov    -0x10(%rbp),%rsi
lea    0xe28(%rip),%rdi
call   1090 <iconv_open@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1090 <iconv_open@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
je     121f <open_conversion+0xaf>
mov    -0x20(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
jne    125d <open_conversion+0xed>
lea    0xde4(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1080 <error@plt>
mov    -0x18(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
je     1251 <open_conversion+0xe1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <iconv_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ee <open_conversion+0x17e>
movb   $0x5c,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
lea    -0x2a(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x2,-0x40(%rbp)
lea    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x8,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1030 <iconv@plt>
cmpq   $0x0,-0x40(%rbp)
jne    12b7 <open_conversion+0x147>
cmpq   $0x0,-0x58(%rbp)
je     12de <open_conversion+0x16e>
lea    0xd6d(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1080 <error@plt>
mov    -0x28(%rbp),%rax
movl   $0x5c,(%rax)
jmp    12e7 <open_conversion+0x177>
mov    -0x48(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_conversion>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
test   %rdi,%rdi
jne    11c6 <open_conversion+0x56>
mov    0x2e43(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe61(%rip),%rsi
call   1060 <setlocale@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edi
lea    0xe3f(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe35(%rip),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1090 <iconv_open@plt>
mov    %rax,(%r12)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <iconv_open@plt>
mov    %rax,(%r15)
mov    (%r12),%rdi
cmp    $0xffffffffffffffff,%rdi
je     126b <open_conversion+0xfb>
cmp    $0xffffffffffffffff,%rax
je     126b <open_conversion+0xfb>
movw   $0x5c,0x6(%rsp)
lea    0x6(%rsp),%rax
mov    %rax,0x20(%rsp)
movq   $0x2,0x10(%rsp)
lea    0x28(%rsp),%rax
mov    %rax,0x18(%rsp)
movq   $0x8,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1030 <iconv@plt>
mov    0x10(%rsp),%rax
or     0x8(%rsp),%rax
je     1299 <open_conversion+0x129>
lea    0xdd8(%rip),%rdi
call   1040 <gettext@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
call   1080 <error@plt>
mov    $0x5c,%eax
jmp    129d <open_conversion+0x12d>
lea    0xd98(%rip),%rdi
call   1040 <gettext@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
call   1080 <error@plt>
mov    (%r12),%rdi
mov    $0x1,%ebx
cmp    $0xffffffffffffffff,%rdi
je     12a2 <open_conversion+0x132>
call   1070 <iconv_close@plt>
jmp    12a2 <open_conversion+0x132>
mov    0x28(%rsp),%eax
mov    %eax,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@CODESET = global i32 0
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [8 x i8] c"WCHAR_T\00"
@.str.3 = [33 x i8] c"conversion modules not available\00"
@.str.4 = [34 x i8] c"cannot determine escape character\00"
define i32 @open_conversion(i8* %0, i64* %1, i64* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca [2 x i8]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca [2 x i32]
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i32* %3, i32** %9
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %4
%19 = load i32, i32* @LC_ALL
%20 = call i32 @setlocale(i32 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @CODESET
%22 = call i8* @nl_langinfo(i32 %21)
store i8* %22, i8** %6
%23 = load i32, i32* @LC_ALL
%24 = call i32 @setlocale(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %18, %4
%26 = load i8*, i8** %6
%27 = call i64 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i64*, i64** %7
store i64 %27, i64* %28
%29 = load i8*, i8** %6
%30 = call i64 @iconv_open(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = load i64*, i64** %8
store i64 %30, i64* %31
%32 = load i64*, i64** %7
%33 = load i64, i64* %32
%34 = icmp eq i64 %33, -1
br i1 %34, label %39, label %35
35: ; preds = %25
%36 = load i64*, i64** %8
%37 = load i64, i64* %36
%38 = icmp eq i64 %37, -1
br i1 %38, label %39, label %50
39: ; preds = %35, %25
%40 = call i8* @gettext(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @error(i32 0, i32 0, i8* %40)
%42 = load i64*, i64** %7
%43 = load i64, i64* %42
%44 = icmp ne i64 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = load i64*, i64** %7
%47 = load i64, i64* %46
%48 = call i32 @iconv_close(i64 %47)
br label %49
49: ; preds = %45, %39
store i32 1, i32* %5
br label %73
50: ; preds = %35
%51 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
store i8 92, i8* %51
%52 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 1
store i8 0, i8* %52
%53 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
store i8* %53, i8** %11
store i64 2, i64* %12
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%55 = bitcast i32* %54 to i8*
store i8* %55, i8** %14
store i64 8, i64* %15
%56 = load i64*, i64** %7
%57 = load i64, i64* %56
%58 = call i32 @iconv(i64 %57, i8** %11, i64* %12, i8** %14, i64* %15)
%59 = load i64, i64* %12
%60 = icmp ne i64 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %50
%62 = load i64, i64* %15
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %61, %50
%65 = call i8* @gettext(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 @error(i32 0, i32 0, i8* %65)
%67 = load i32*, i32** %9
store i32 92, i32* %67
br label %72
68: ; preds = %61
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%70 = load i32, i32* %69
%71 = load i32*, i32** %9
store i32 %70, i32* %71
br label %72
72: ; preds = %68, %64
store i32 0, i32* %5
br label %73
73: ; preds = %72, %49
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@CODESET = global i32 0
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [8 x i8] c"WCHAR_T\00"
@.str.3 = [33 x i8] c"conversion modules not available\00"
@.str.4 = [34 x i8] c"cannot determine escape character\00"
define i32 @open_conversion(i8* %0, i64* nocapture %1, i64* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [2 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [2 x i32]
%9 = alloca i8*
%10 = alloca i64
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%12 = bitcast i8** %6 to i8*
%13 = bitcast i64* %7 to i8*
%14 = bitcast [2 x i32]* %8 to i8*
%15 = bitcast i8** %9 to i8*
%16 = bitcast i64* %10 to i8*
%17 = icmp eq i8* %0, null
br i1 %17, label %18, label %25
18: ; preds = %4
%19 = load i32, i32* @LC_ALL
%20 = tail call i32 @setlocale(i32 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @CODESET
%22 = tail call i8* @nl_langinfo(i32 %21)
%23 = load i32, i32* @LC_ALL
%24 = tail call i32 @setlocale(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %18, %4
%26 = phi i8* [ %22, %18 ], [ %0, %4 ]
%27 = tail call i64 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i64 %27, i64* %1
%28 = tail call i64 @iconv_open(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i64 %28, i64* %2
%29 = load i64, i64* %1
%30 = icmp eq i64 %29, -1
%31 = icmp eq i64 %28, -1
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = tail call i8* @gettext(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i32 @error(i32 0, i32 0, i8* %34)
%36 = load i64, i64* %1
%37 = icmp eq i64 %36, -1
br i1 %37, label %57, label %38
38: ; preds = %33
%39 = tail call i32 @iconv_close(i64 %36)
br label %57
40: ; preds = %25
store i8 92, i8* %11
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 0, i8* %41
store i8* %11, i8** %6
store i64 2, i64* %7
%42 = bitcast i8** %9 to [2 x i32]**
store [2 x i32]* %8, [2 x i32]** %42
store i64 8, i64* %10
%43 = call i32 @iconv(i64 %29, i8** %6, i64* %7, i8** %9, i64* %10)
%44 = load i64, i64* %7
%45 = icmp ne i64 %44, 0
%46 = load i64, i64* %10
%47 = icmp ne i64 %46, 0
%48 = select i1 %45, i1 true, i1 %47
br i1 %48, label %49, label %52
49: ; preds = %40
%50 = call i8* @gettext(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @error(i32 0, i32 0, i8* %50)
br label %55
52: ; preds = %40
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%54 = load i32, i32* %53
br label %55
55: ; preds = %52, %49
%56 = phi i32 [ %54, %52 ], [ 92, %49 ]
store i32 %56, i32* %3
br label %57
57: ; preds = %33, %38, %55
%58 = phi i32 [ 0, %55 ], [ 1, %38 ], [ 1, %33 ]
ret i32 %58
}