#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ iconv(int /*<<< orphan*/, char **, size_t *, char **,
                         size_t *);
int /*<<< orphan*/ iconv_open(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  iconv_t cd = iconv_open("GBK", "UTF-8");
  FILE *file = fopen("iconv.txt", "r");
  char ori[2 * 1024 * 1024];
  char out[1024];
  size_t *size = 1024;
  fgets(ori, 1024, file);
  printf("%s\n", ori);
  iconv(cd, &ori, size, &out, size);
  printf("%s\n", out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <iconv_open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe84(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x400,%eax
mov    %rax,-0x200428(%rbp)
lea    -0x200020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x200020(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x200020(%rbp),%rsi
mov    -0x200428(%rbp),%rdx
lea    -0x200420(%rbp),%rcx
mov    -0x200428(%rbp),%r8
call   1030 <iconv@plt>
lea    -0x200420(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x200430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x200408,%rsp
lea    0xe9c(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <iconv_open@plt>
mov    %eax,%r14d
lea    0xe90(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
lea    0xe71(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rsp,%rbp
mov    $0x400,%edx
mov    $0x400,%r8d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rcx
call   1030 <iconv@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x200408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"GBK\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [10 x i8] c"iconv.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [2097152 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i64*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @iconv_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %6
%12 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %7
store i64* inttoptr (i64 1024 to i64*), i64** %10
%13 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%14 = load i32*, i32** %7
%15 = call i32 @fgets(i8* %13, i32 1024, i32* %14)
%16 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %6
%19 = bitcast [2097152 x i8]* %8 to i8**
%20 = load i64*, i64** %10
%21 = bitcast [1024 x i8]* %9 to i8**
%22 = load i64*, i64** %10
%23 = call i32 @iconv(i32 %18, i8** %19, i64* %20, i8** %21, i64* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"GBK\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [10 x i8] c"iconv.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2097152 x i8]
%4 = alloca [1024 x i8]
%5 = tail call i32 @iconv_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @fgets(i8* %7, i32 1024, i32* %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%11 = bitcast [2097152 x i8]* %3 to i8**
%12 = bitcast [1024 x i8]* %4 to i8**
%13 = call i32 @iconv(i32 %5, i8** %11, i64* inttoptr (i64 1024 to i64*), i8** %12, i64* inttoptr (i64 1024 to i64*))
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
ret i32 0
}