#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 iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char *, char *);
char *malloc(int);
scalar_t__ memcmp(char *, char *, size_t);
size_t strlen(char *);
int test_iconv(void) {
  char *jp = "\x1B\x24\x42\x46\x7C\x4B\x5C\x38\x6C";
  char *utf8 = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E";
  char *transbuf = malloc(10), *trans = transbuf;
  iconv_t cd;
  size_t jp_len = strlen(jp), utf8_len = 10;
  size_t utf8_real_len = strlen(utf8);
  cd = iconv_open("UTF-8", "ISO-2022-JP");
  if (cd == (iconv_t)-1)
    return 0;
  if (iconv(cd, &jp, &jp_len, &trans, &utf8_len) == -1 || jp_len != 0) {
    iconv_close(cd);
    return 0;
  }
  if (memcmp(utf8, transbuf, utf8_real_len) != 0) {
    iconv_close(cd);
    return 0;
  }
  iconv_close(cd);
  return 1;
}


x86 assembly (clang, -O0):
<test_iconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
movq   $0xa,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1080 <iconv_open@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    11e4 <test_iconv+0x84>
movl   $0x0,-0x4(%rbp)
jmp    1266 <test_iconv+0x106>
mov    -0x30(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
je     1211 <test_iconv+0xb1>
cmpq   $0x0,-0x38(%rbp)
je     1226 <test_iconv+0xc6>
mov    -0x30(%rbp),%rdi
call   1070 <iconv_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1266 <test_iconv+0x106>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1256 <test_iconv+0xf6>
mov    -0x30(%rbp),%rdi
call   1070 <iconv_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1266 <test_iconv+0x106>
mov    -0x30(%rbp),%rdi
call   1070 <iconv_close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_iconv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,0x18(%rsp)
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
movq   $0x9,(%rsp)
movq   $0xa,0x8(%rsp)
lea    0xe86(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <iconv_open@plt>
xor    %ebp,%ebp
cmp    $0xffffffffffffffff,%rax
je     11f0 <test_iconv+0xa0>
mov    %rax,%rbx
lea    0x18(%rsp),%rsi
mov    %rsp,%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
je     11e8 <test_iconv+0x98>
cmpq   $0x0,(%rsp)
jne    11e8 <test_iconv+0x98>
lea    0xe38(%rip),%rdi
mov    $0x9,%edx
mov    %r14,%rsi
call   1040 <memcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1060 <iconv_close@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\1B$BF|K\\8l\00"
@.str.1 = [10 x i8] c"\E6\97\A5\E6\9C\AC\E8\AA\9E\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [12 x i8] c"ISO-2022-JP\00"
define i32 @test_iconv() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %3
%10 = call i8* @malloc(i32 10)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
store i8* %11, i8** %5
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
store i64 10, i64* %8
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %9
%16 = call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %0
store i32 0, i32* %1
br label %42
20: ; preds = %0
%21 = load i64, i64* %6
%22 = call i32 @iconv(i64 %21, i8** %2, i64* %7, i8** %5, i64* %8)
%23 = icmp eq i32 %22, -1
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i64, i64* %7
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24, %20
%28 = load i64, i64* %6
%29 = call i32 @iconv_close(i64 %28)
store i32 0, i32* %1
br label %42
30: ; preds = %24
%31 = load i8*, i8** %3
%32 = load i8*, i8** %4
%33 = load i64, i64* %9
%34 = call i64 @memcmp(i8* %31, i8* %32, i64 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i64, i64* %6
%38 = call i32 @iconv_close(i64 %37)
store i32 0, i32* %1
br label %42
39: ; preds = %30
%40 = load i64, i64* %6
%41 = call i32 @iconv_close(i64 %40)
store i32 1, i32* %1
br label %42
42: ; preds = %39, %36, %27, %19
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [10 x i8] c"\1B$BF|K\\8l\00"
@.str.1 = [10 x i8] c"\E6\97\A5\E6\9C\AC\E8\AA\9E\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [12 x i8] c"ISO-2022-JP\00"
define i32 @test_iconv() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i8** %1 to i8*
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %1
%6 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%7 = bitcast i8** %2 to i8*
store i8* %6, i8** %2
%8 = bitcast i64* %3 to i8*
store i64 9, i64* %3
%9 = bitcast i64* %4 to i8*
store i64 10, i64* %4
%10 = tail call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, -1
br i1 %11, label %25, label %12
12: ; preds = %0
%13 = call i32 @iconv(i64 %10, i8** %1, i64* %3, i8** %2, i64* %4)
%14 = icmp eq i32 %13, -1
%15 = load i64, i64* %3
%16 = icmp ne i64 %15, 0
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @iconv_close(i64 %10)
br label %25
20: ; preds = %12
%21 = call i64 @memcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6, i64 9)
%22 = icmp eq i64 %21, 0
%23 = call i32 @iconv_close(i64 %10)
%24 = zext i1 %22 to i32
br label %25
25: ; preds = %20, %0, %18
%26 = phi i32 [ 0, %18 ], [ 0, %0 ], [ %24, %20 ]
ret i32 %26
}