#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*/ iconv_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *);
int iconv(int /*<<< orphan*/, char const **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_open(char *, char *);
char *malloc(size_t);
size_t strlen(char *);
int main(void) {
  iconv_t cd;
  size_t inbytes, outbytes;
  char *str1 = "FOOBAR";
  const char *str2 = "FOOBAR";
  char **in1;
  const char **in2 = &str2;
  char *out1, *out2;
  inbytes = outbytes = strlen("FOOBAR");
  if ((cd = iconv_open("UTF-8", "ASCII")) == (iconv_t)-1)
    err(1, NULL);
  if ((out2 = malloc(inbytes)) == NULL)
    err(1, NULL);
  if (iconv(cd, in2, &inbytes, &out2, &outbytes) == -1)
    err(1, NULL);
  in1 = &str1;
  inbytes = outbytes = strlen("FOOBAR");
  if ((out1 = malloc(inbytes)) == NULL)
    err(1, NULL);
  if (iconv(cd, in1, &inbytes, &out1, &outbytes) == -1)
    err(1, NULL);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe7c(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <iconv_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11be <main+0x6e>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11e3 <main+0x93>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    1212 <main+0xc2>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xddf(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1253 <main+0x103>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    1282 <main+0x132>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xeb4(%rip),%rax
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x6,(%rsp)
movq   $0x6,0x8(%rsp)
lea    0xe99(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <iconv_open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    118d <main+0x4d>
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <err@plt>
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
jne    11ad <main+0x6d>
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <err@plt>
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edi
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    11d7 <main+0x97>
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <err@plt>
movq   $0x6,(%rsp)
movq   $0x6,0x8(%rsp)
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
jne    1208 <main+0xc8>
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <err@plt>
lea    0x28(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edi
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    1232 <main+0xf2>
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <err@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"FOOBAR\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [6 x i8] c"ASCII\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
store i8** %6, i8*** %8
%11 = call i64 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i64 %11, i64* %4
store i64 %11, i64* %3
%12 = call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 %12, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @err(i32 1, i32* null)
br label %16
16: ; preds = %14, %0
%17 = load i64, i64* %3
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @err(i32 1, i32* null)
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* %2
%24 = load i8**, i8*** %8
%25 = call i32 @iconv(i32 %23, i8** %24, i64* %3, i8** %10, i64* %4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @err(i32 1, i32* null)
br label %29
29: ; preds = %27, %22
store i8** %5, i8*** %7
%30 = call i64 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i64 %30, i64* %4
store i64 %30, i64* %3
%31 = load i64, i64* %3
%32 = call i8* @malloc(i64 %31)
store i8* %32, i8** %9
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @err(i32 1, i32* null)
br label %36
36: ; preds = %34, %29
%37 = load i32, i32* %2
%38 = load i8**, i8*** %7
%39 = call i32 @iconv(i32 %37, i8** %38, i64* %3, i8** %9, i64* %4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @err(i32 1, i32* null)
br label %43
43: ; preds = %41, %36
%44 = load i32, i32* @EXIT_SUCCESS
ret i32 %44
}

LLVM IR (-O2):
@.str = [7 x i8] c"FOOBAR\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [6 x i8] c"ASCII\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i64* %1 to i8*
%8 = bitcast i64* %2 to i8*
%9 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3
%10 = bitcast i8** %4 to i8*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
%11 = bitcast i8** %5 to i8*
%12 = bitcast i8** %6 to i8*
store i64 6, i64* %2
store i64 6, i64* %1
%13 = tail call i32 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = tail call i32 @err(i32 1, i32* null)
br label %17
17: ; preds = %15, %0
%18 = tail call dereferenceable_or_null(6) i8* @malloc(i64 6)
store i8* %18, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @err(i32 1, i32* null)
br label %22
22: ; preds = %20, %17
%23 = call i32 @iconv(i32 %13, i8** %4, i64* %1, i8** %6, i64* %2)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @err(i32 1, i32* null)
br label %27
27: ; preds = %25, %22
store i64 6, i64* %2
store i64 6, i64* %1
%28 = call dereferenceable_or_null(6) i8* @malloc(i64 6)
store i8* %28, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @err(i32 1, i32* null)
br label %32
32: ; preds = %30, %27
%33 = call i32 @iconv(i32 %13, i8** %3, i64* %1, i8** %5, i64* %2)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @err(i32 1, i32* null)
br label %37
37: ; preds = %35, %32
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}