#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 */
int errno;
int iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char *, char *);
int /*<<< orphan*/ printf(char *, char *, int);
char *strerror(int);
int code_conv(char *fromcode, char *tocode, char *inbuf, size_t inlen,
              char *outbuf, size_t outlen) {
  iconv_t cd;
  cd = iconv_open(tocode, fromcode);
  if (cd == (iconv_t)-1)
    return -1;
  if (iconv(cd, &inbuf, &inlen, &outbuf, &outlen) == -1) {
    printf("%s (%d)\n", strerror(errno), errno);
    iconv_close(cd);
    return -1;
  }
  iconv_close(cd);
  return 0;
}


x86 assembly (clang, -O0):
<code_conv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <iconv_open@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    1198 <code_conv+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <code_conv+0xb5>
mov    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    11f5 <code_conv+0xa5>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <iconv_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <code_conv+0xb5>
mov    -0x40(%rbp),%rdi
call   1050 <iconv_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<code_conv>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rax
mov    %rdx,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %r8,0x10(%rsp)
mov    %r9,0x8(%rsp)
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     11d4 <code_conv+0x84>
mov    %rax,%rbx
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
call   1030 <iconv@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    11ca <code_conv+0x7a>
mov    0x2e35(%rip),%rbp
mov    0x0(%rbp),%edi
call   1060 <strerror@plt>
mov    0x0(%rbp),%edx
lea    0xe43(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1050 <iconv_close@plt>
jmp    11d9 <code_conv+0x89>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s (%d)\0A\00"
@errno = global i32 0
define i32 @code_conv(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i8* %4, i8** %12
store i64 %5, i64* %13
%15 = load i8*, i8** %9
%16 = load i8*, i8** %8
%17 = call i64 @iconv_open(i8* %15, i8* %16)
store i64 %17, i64* %14
%18 = load i64, i64* %14
%19 = icmp eq i64 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %6
store i32 -1, i32* %7
br label %35
21: ; preds = %6
%22 = load i64, i64* %14
%23 = call i32 @iconv(i64 %22, i8** %10, i64* %11, i8** %12, i64* %13)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = load i32, i32* @errno
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %28)
%30 = load i64, i64* %14
%31 = call i32 @iconv_close(i64 %30)
store i32 -1, i32* %7
br label %35
32: ; preds = %21
%33 = load i64, i64* %14
%34 = call i32 @iconv_close(i64 %33)
store i32 0, i32* %7
br label %35
35: ; preds = %32, %25, %20
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s (%d)\0A\00"
@errno = global i32 0
define i32 @code_conv(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %2, i8** %7
store i64 %3, i64* %8
store i8* %4, i8** %9
store i64 %5, i64* %10
%11 = tail call i64 @iconv_open(i8* %1, i8* %0)
%12 = icmp eq i64 %11, -1
br i1 %12, label %24, label %13
13: ; preds = %6
%14 = call i32 @iconv(i64 %11, i8** %7, i64* %8, i8** %9, i64* %10)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19)
br label %21
21: ; preds = %13, %16
%22 = phi i32 [ -1, %16 ], [ 0, %13 ]
%23 = call i32 @iconv_close(i64 %11)
br label %24
24: ; preds = %21, %6
%25 = phi i32 [ -1, %6 ], [ %22, %21 ]
ret i32 %25
}