#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 scalar_t__ iconv_t;

/* Variables and functions */
size_t iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char *, char *);
int /*<<< orphan*/ warn(char *);
int convert_ctn_id(char *in, char *out) {
  iconv_t ic;
  size_t inlen = sizeof(unsigned long long);
  size_t outlen = sizeof(unsigned long long);
  ic = iconv_open("ISO-8859-1", "EBCDIC-US");
  if (ic == (iconv_t)-1) {
    warn("Could not initialize EBCDIC to ISO-8859-1 conversion table");
    return -1;
  }
  if (iconv(ic, &in, &inlen, (char **)&out, &outlen) == (size_t)-1) {
    warn("Code page translation EBCDIC to ISO-8859-1 failed");
    iconv_close(ic);
    return -1;
  }
  iconv_close(ic);
  return 0;
}


x86 assembly (clang, -O0):
<convert_ctn_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x8,-0x28(%rbp)
movq   $0x8,-0x30(%rbp)
lea    0xe99(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <iconv_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    119a <convert_ctn_id+0x5a>
lea    0xe8c(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <convert_ctn_id+0xae>
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1040 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    11de <convert_ctn_id+0x9e>
lea    0xe8c(%rip),%rdi
call   1030 <warn@plt>
mov    -0x20(%rbp),%rdi
call   1050 <iconv_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <convert_ctn_id+0xae>
mov    -0x20(%rbp),%rdi
call   1050 <iconv_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_ctn_id>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,0x18(%rsp)
mov    %rsi,0x10(%rsp)
movq   $0x8,0x8(%rsp)
movq   $0x8,(%rsp)
lea    0xe99(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     11a8 <convert_ctn_id+0x68>
mov    %rax,%rbx
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    %rax,%rdi
call   1040 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
je     11b6 <convert_ctn_id+0x76>
mov    %rbx,%rdi
call   1050 <iconv_close@plt>
xor    %eax,%eax
jmp    11cf <convert_ctn_id+0x8f>
lea    0xe66(%rip),%rdi
call   1030 <warn@plt>
jmp    11ca <convert_ctn_id+0x8a>
lea    0xe93(%rip),%rdi
call   1030 <warn@plt>
mov    %rbx,%rdi
call   1050 <iconv_close@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"ISO-8859-1\00"
@.str.1 = [10 x i8] c"EBCDIC-US\00"
@.str.2 = [59 x i8] c"Could not initialize EBCDIC to ISO-8859-1 conversion table\00"
@.str.3 = [50 x i8] c"Code page translation EBCDIC to ISO-8859-1 failed\00"
define i32 @convert_ctn_id(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 8, i64* %7
store i64 8, i64* %8
%9 = call i64 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @warn(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
14: ; preds = %2
%15 = load i64, i64* %6
%16 = call i64 @iconv(i64 %15, i8** %4, i64* %7, i8** %5, i64* %8)
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = call i32 @warn(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%20 = load i64, i64* %6
%21 = call i32 @iconv_close(i64 %20)
store i32 -1, i32* %3
br label %25
22: ; preds = %14
%23 = load i64, i64* %6
%24 = call i32 @iconv_close(i64 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %22, %18, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [11 x i8] c"ISO-8859-1\00"
@.str.1 = [10 x i8] c"EBCDIC-US\00"
@.str.2 = [59 x i8] c"Could not initialize EBCDIC to ISO-8859-1 conversion table\00"
@.str.3 = [50 x i8] c"Code page translation EBCDIC to ISO-8859-1 failed\00"
define i32 @convert_ctn_id(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 8, i64* %5
%8 = bitcast i64* %6 to i8*
store i64 8, i64* %6
%9 = tail call i64 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @warn(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
br label %21
13: ; preds = %2
%14 = call i64 @iconv(i64 %9, i8** %3, i64* %5, i8** %4, i64* %6)
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @warn(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @iconv_close(i64 %9)
br label %21
19: ; preds = %13
%20 = call i32 @iconv_close(i64 %9)
br label %21
21: ; preds = %19, %16, %11
%22 = phi i32 [ -1, %11 ], [ -1, %16 ], [ 0, %19 ]
ret i32 %22
}