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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int decompress_lz(char *, char *, size_t);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftello(int /*<<< orphan*/ *);
size_t iconv(scalar_t__, char **, size_t *, char **, size_t *);
scalar_t__ iconv_open(char *, char *);
int le32toh(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ *stdin;
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  FILE *input = stdin;
  char *src = NULL;
  char *dst = NULL;
  size_t srcSize = 0;
  uint32_t dstSize;
  size_t status;
  char *srcptr;
  fseek(input, 0, SEEK_END);
  srcSize = ftello(input);
  fseek(input, 0, SEEK_SET);
  src = (char *)malloc(srcSize);
  srcptr = src;
  while ((status = fread(srcptr, 1, srcSize, input)) != 0) {
    srcptr += status;
  }
  if (srcptr - src != srcSize)
    return -1;
  dstSize = le32toh(*((uint32_t *)src));
  dst = (char *)malloc(dstSize + 2);
  memset(dst, 0, dstSize + 2);
  int lzStatus = decompress_lz(dst, src, srcSize);
  if (lzStatus)
    return lzStatus;
  char *dstAsUtf8 = (char *)malloc(dstSize * 2 + 1);
  char *in = dst;
  size_t inbytes = dstSize;
  char *out = dstAsUtf8;
  size_t outbytes = dstSize * 2 + 1;
  iconv_t conv = iconv_open("UTF-8//TRANSLIT", "UTF-16LE");
  if (conv == (iconv_t)-1) {
    perror("iconv_open");
    return 1;
  }
  if (iconv(conv, &in, &inbytes, &out, &outbytes) == (size_t)-1) {
    perror("iconv");
    return 1;
  }
  dstAsUtf8 = realloc(dstAsUtf8, strlen(dstAsUtf8) + 1);
  printf("%s", dstAsUtf8);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1040 <ftello@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1290 <main+0xc0>
mov    -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    125b <main+0x8b>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x30(%rbp),%rax
je     12b1 <main+0xe1>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f8 <main+0x228>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <le32toh@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x2,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%edx
add    $0x2,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10e0 <decompress_lz@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1308 <main+0x138>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13f8 <main+0x228>
mov    -0x34(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
movslq -0x34(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x78(%rbp)
lea    0xcb8(%rip),%rdi
lea    0xcc1(%rip),%rsi
call   10f0 <iconv_open@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0xffffffffffffffff,-0x80(%rbp)
jne    137b <main+0x1ab>
lea    0xcaf(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f8 <main+0x228>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x68(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    -0x78(%rbp),%r8
call   1050 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    13b6 <main+0x1e6>
lea    0xc7f(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f8 <main+0x228>
mov    -0x58(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xc3e(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2dfd(%rip),%rax
mov    (%rax),%r12
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
call   1040 <ftello@plt>
mov    %rax,%r15
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r15d,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <fread@plt>
mov    %r14,%rbx
test   %rax,%rax
je     125b <main+0x8b>
nopl   (%rax)
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <fread@plt>
test   %rax,%rax
jne    1240 <main+0x70>
sub    %r14,%rbx
mov    $0xffffffff,%eax
cmp    %r15,%rbx
jne    1330 <main+0x160>
mov    (%r14),%edi
call   1030 <le32toh@plt>
mov    %eax,%r12d
lea    0x2(%r12),%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1090 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10e0 <decompress_lz@plt>
test   %eax,%eax
jne    1330 <main+0x160>
lea    (%r12,%r12,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rbx,0x18(%rsp)
movslq %r12d,%rax
mov    %rax,0x10(%rsp)
mov    %r14,0x8(%rsp)
movslq %ebp,%rax
mov    %rax,(%rsp)
lea    0xd27(%rip),%rdi
lea    0xd30(%rip),%rsi
call   10f0 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     133d <main+0x16d>
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %rax,%rdi
call   1050 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
je     1346 <main+0x176>
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   10c0 <realloc@plt>
lea    0xd04(%rip),%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd5(%rip),%rdi
jmp    134d <main+0x17d>
lea    0xcd7(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
jmp    1330 <main+0x160>

LLVM IR (-O0):
@stdin = global i32* null
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [16 x i8] c"UTF-8//TRANSLIT\00"
@.str.1 = [9 x i8] c"UTF-16LE\00"
@.str.2 = [11 x i8] c"iconv_open\00"
@.str.3 = [6 x i8] c"iconv\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32*, i32** @stdin
store i32* %20, i32** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i64 0, i64* %9
%21 = load i32*, i32** %6
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32*, i32** %6
%25 = call i64 @ftello(i32* %24)
store i64 %25, i64* %9
%26 = load i32*, i32** %6
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
%29 = load i64, i64* %9
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %7
%33 = load i8*, i8** %7
store i8* %33, i8** %12
br label %34
34: ; preds = %40, %2
%35 = load i8*, i8** %12
%36 = load i64, i64* %9
%37 = load i32*, i32** %6
%38 = call i64 @fread(i8* %35, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %11
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i64, i64* %11
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i64 %41
store i8* %43, i8** %12
br label %34
44: ; preds = %34
%45 = load i8*, i8** %12
%46 = load i8*, i8** %7
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = load i64, i64* %9
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 -1, i32* %3
br label %107
53: ; preds = %44
%54 = load i8*, i8** %7
%55 = bitcast i8* %54 to i32*
%56 = load i32, i32* %55
%57 = call i32 @le32toh(i32 %56)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 2
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i8*
store i8* %61, i8** %8
%62 = load i8*, i8** %8
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 2
%65 = call i32 @memset(i8* %62, i32 0, i32 %64)
%66 = load i8*, i8** %8
%67 = load i8*, i8** %7
%68 = load i64, i64* %9
%69 = call i32 @decompress_lz(i8* %66, i8* %67, i64 %68)
store i32 %69, i32* %13
%70 = load i32, i32* %13
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %53
%73 = load i32, i32* %13
store i32 %73, i32* %3
br label %107
74: ; preds = %53
%75 = load i32, i32* %10
%76 = mul nsw i32 %75, 2
%77 = add nsw i32 %76, 1
%78 = call i64 @malloc(i32 %77)
%79 = inttoptr i64 %78 to i8*
store i8* %79, i8** %14
%80 = load i8*, i8** %8
store i8* %80, i8** %15
%81 = load i32, i32* %10
%82 = sext i32 %81 to i64
store i64 %82, i64* %16
%83 = load i8*, i8** %14
store i8* %83, i8** %17
%84 = load i32, i32* %10
%85 = mul nsw i32 %84, 2
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
store i64 %87, i64* %18
%88 = call i64 @iconv_open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i64 %88, i64* %19
%89 = load i64, i64* %19
%90 = icmp eq i64 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %74
%92 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %107
93: ; preds = %74
%94 = load i64, i64* %19
%95 = call i64 @iconv(i64 %94, i8** %15, i64* %16, i8** %17, i64* %18)
%96 = icmp eq i64 %95, -1
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %107
99: ; preds = %93
%100 = load i8*, i8** %14
%101 = load i8*, i8** %14
%102 = call i64 @strlen(i8* %101)
%103 = add nsw i64 %102, 1
%104 = call i8* @realloc(i8* %100, i64 %103)
store i8* %104, i8** %14
%105 = load i8*, i8** %14
%106 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %105)
store i32 0, i32* %3
br label %107
107: ; preds = %99, %97, %91, %72, %52
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@stdin = global i32* null
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [16 x i8] c"UTF-8//TRANSLIT\00"
@.str.1 = [9 x i8] c"UTF-16LE\00"
@.str.2 = [11 x i8] c"iconv_open\00"
@.str.3 = [6 x i8] c"iconv\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = load i32*, i32** @stdin
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %7, i32 0, i32 %8)
%10 = tail call i64 @ftello(i32* %7)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %7, i32 0, i32 %11)
%13 = trunc i64 %10 to i32
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i64 @fread(i8* %15, i32 1, i64 %10, i32* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %2, %18
%19 = phi i64 [ %22, %18 ], [ %16, %2 ]
%20 = phi i8* [ %21, %18 ], [ %15, %2 ]
%21 = getelementptr inbounds i8, i8* %20, i64 %19
%22 = tail call i64 @fread(i8* %21, i32 1, i64 %10, i32* %7)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %18
24: ; preds = %18, %2
%25 = phi i8* [ %15, %2 ], [ %21, %18 ]
%26 = ptrtoint i8* %25 to i64
%27 = sub i64 %26, %14
%28 = icmp eq i64 %27, %10
br i1 %28, label %29, label %66
29: ; preds = %24
%30 = inttoptr i64 %14 to i32*
%31 = load i32, i32* %30
%32 = tail call i32 @le32toh(i32 %31)
%33 = add nsw i32 %32, 2
%34 = tail call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = tail call i32 @memset(i8* %35, i32 0, i32 %33)
%37 = tail call i32 @decompress_lz(i8* %35, i8* %15, i64 %10)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %66
39: ; preds = %29
%40 = shl nsw i32 %32, 1
%41 = or i32 %40, 1
%42 = tail call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
%44 = bitcast i8** %3 to i8*
store i8* %35, i8** %3
%45 = bitcast i64* %4 to i8*
%46 = sext i32 %32 to i64
store i64 %46, i64* %4
%47 = bitcast i8** %5 to i8*
store i8* %43, i8** %5
%48 = bitcast i64* %6 to i8*
%49 = sext i32 %41 to i64
store i64 %49, i64* %6
%50 = tail call i64 @iconv_open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i64 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %39
%53 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %64
54: ; preds = %39
%55 = call i64 @iconv(i64 %50, i8** %3, i64* %4, i8** %5, i64* %6)
%56 = icmp eq i64 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %64
59: ; preds = %54
%60 = call i64 @strlen(i8* dereferenceable(1) %43)
%61 = add nsw i64 %60, 1
%62 = call i8* @realloc(i8* %43, i64 %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %59, %57, %52
%65 = phi i32 [ 1, %52 ], [ 1, %57 ], [ 0, %59 ]
br label %66
66: ; preds = %64, %29, %24
%67 = phi i32 [ -1, %24 ], [ %65, %64 ], [ %37, %29 ]
ret i32 %67
}