#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ iconv(int /*<<< orphan*/ *, char **, size_t *, char **,
                         size_t *);
int /*<<< orphan*/ *iconv_open(char *, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage:\ntxt infile.txt outfile.txt\n");
    return 0;
  }
  FILE *f = fopen(argv[1], "rb");
  FILE *f2 = fopen(argv[2], "wb");
  fseek(f, 0, SEEK_END);
  int sz = ftell(f);
  fseek(f, 0, SEEK_SET);
  char *chr = malloc(sz);
  fread(chr, 1, sz, f);
  fclose(f);
  char *chr2 = malloc(sz + 1);
  memset(chr2, 0, sz + 1);
  int j = 0;
  int i;
  for (i = 0; i < sz; i++) {
    if (chr[i] != 0x0) {
      chr2[j] = chr[i];
      j++;
    }
  }
  int sz2 = j;
  size_t buf1, buf2;
  buf1 = sz2 + 1;
  buf2 = sz2 * 2;
  char *chr3 = malloc(sz2 * 2 + 1);
  memset(chr3, 0, sz2 * 2 + 1);
  iconv_t *icnv;
  char *in = chr2;
  char *out = chr3;
  icnv = iconv_open("UTF-8", "cp1251");
  iconv(icnv, &in, &buf1, &out, &buf2);
  fwrite(chr3, 1, strlen(chr3), f2);
  fclose(f2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fb <main+0x3b>
lea    0xe16(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c3 <main+0x203>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe19(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe04(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x24(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130a <main+0x14a>
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12f7 <main+0x137>
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12fc <main+0x13c>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12b7 <main+0xf7>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x44(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x44(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xcc4(%rip),%rdi
lea    0xcc3(%rip),%rsi
call   10e0 <iconv_open@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x78(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1030 <iconv@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x60(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jg     11e4 <main+0x24>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
jmp    133b <main+0x17b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe0e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r15,%rdi
call   1090 <ftell@plt>
mov    %eax,%r12d
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12d,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0x1(%r12),%r13d
mov    %r13d,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1080 <memset@plt>
test   %r12d,%r12d
jle    12b0 <main+0xf0>
mov    %r12d,%esi
cmp    $0x1,%r12d
jne    134c <main+0x18c>
xor    %ecx,%ecx
xor    %ebp,%ebp
test   $0x1,%sil
je     12b0 <main+0xf0>
mov    (%rbx,%rcx,1),%al
test   %al,%al
je     12b0 <main+0xf0>
movslq %ebp,%rbp
mov    %al,(%r15,%rbp,1)
add    $0x1,%ebp
lea    0x1(%rbp),%eax
cltq
mov    %rax,0x20(%rsp)
lea    0x0(%rbp,%rbp,1),%eax
cltq
mov    %rax,0x18(%rsp)
add    %ebp,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1080 <memset@plt>
mov    %r15,0x10(%rsp)
mov    %rbx,0x8(%rsp)
lea    0xd15(%rip),%rdi
lea    0xd14(%rip),%rsi
call   10e0 <iconv_open@plt>
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %rax,%rdi
call   1030 <iconv@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %ecx,%ecx
xor    %ebp,%ebp
jmp    136d <main+0x1ad>
nopw   0x0(%rax,%rax,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
je     1299 <main+0xd9>
movzbl (%rbx,%rcx,1),%eax
test   %al,%al
je     137f <main+0x1bf>
movslq %ebp,%rbp
mov    %al,(%r15,%rbp,1)
add    $0x1,%ebp
movzbl 0x1(%rbx,%rcx,1),%eax
test   %al,%al
je     1360 <main+0x1a0>
movslq %ebp,%rbp
mov    %al,(%r15,%rbp,1)
add    $0x1,%ebp
jmp    1360 <main+0x1a0>

LLVM IR (-O0):
@.str = [35 x i8] c"Usage:\0Atxt infile.txt outfile.txt\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"UTF-8\00"
@.str.4 = [7 x i8] c"cp1251\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 i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %113
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %6
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %8
%38 = load i32*, i32** %6
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32, i32* %8
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = load i32, i32* %8
%45 = load i32*, i32** %6
%46 = call i32 @fread(i8* %43, i32 1, i32 %44, i32* %45)
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
%51 = call i8* @malloc(i32 %50)
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
%55 = call i32 @memset(i8* %52, i32 0, i32 %54)
store i32 0, i32* %11
store i32 0, i32* %12
br label %56
56: ; preds = %81, %24
%57 = load i32, i32* %12
%58 = load i32, i32* %8
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %84
60: ; preds = %56
%61 = load i8*, i8** %9
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %80
68: ; preds = %60
%69 = load i8*, i8** %9
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = load i8*, i8** %10
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 %73, i8* %77
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %80
80: ; preds = %68, %60
br label %81
81: ; preds = %80
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
br label %56
84: ; preds = %56
%85 = load i32, i32* %11
store i32 %85, i32* %13
%86 = load i32, i32* %13
%87 = add nsw i32 %86, 1
%88 = sext i32 %87 to i64
store i64 %88, i64* %14
%89 = load i32, i32* %13
%90 = mul nsw i32 %89, 2
%91 = sext i32 %90 to i64
store i64 %91, i64* %15
%92 = load i32, i32* %13
%93 = mul nsw i32 %92, 2
%94 = add nsw i32 %93, 1
%95 = call i8* @malloc(i32 %94)
store i8* %95, i8** %16
%96 = load i8*, i8** %16
%97 = load i32, i32* %13
%98 = mul nsw i32 %97, 2
%99 = add nsw i32 %98, 1
%100 = call i32 @memset(i8* %96, i32 0, i32 %99)
%101 = load i8*, i8** %10
store i8* %101, i8** %18
%102 = load i8*, i8** %16
store i8* %102, i8** %19
%103 = call i32* @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32* %103, i32** %17
%104 = load i32*, i32** %17
%105 = call i32 @iconv(i32* %104, i8** %18, i64* %14, i8** %19, i64* %15)
%106 = load i8*, i8** %16
%107 = load i8*, i8** %16
%108 = call i32 @strlen(i8* %107)
%109 = load i32*, i32** %7
%110 = call i32 @fwrite(i8* %106, i32 1, i32 %108, i32* %109)
%111 = load i32*, i32** %7
%112 = call i32 @fclose(i32* %111)
store i32 0, i32* %3
br label %113
113: ; preds = %84, %22
%114 = load i32, i32* %3
ret i32 %114
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"UTF-8\00"
@.str.4 = [7 x i8] c"cp1251\00"
@str = [34 x i8] c"Usage:\0Atxt infile.txt outfile.txt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %92
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %13, i32 0, i32 %17)
%19 = tail call i32 @ftell(i32* %13)
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %13, i32 0, i32 %20)
%22 = tail call i8* @malloc(i32 %19)
%23 = tail call i32 @fread(i8* %22, i32 1, i32 %19, i32* %13)
%24 = tail call i32 @fclose(i32* %13)
%25 = add nsw i32 %19, 1
%26 = tail call i8* @malloc(i32 %25)
%27 = tail call i32 @memset(i8* %26, i32 0, i32 %25)
%28 = icmp sgt i32 %19, 0
br i1 %28, label %29, label %74
29: ; preds = %10
%30 = zext i32 %19 to i64
%31 = and i64 %30, 1
%32 = icmp eq i32 %19, 1
br i1 %32, label %61, label %33
33: ; preds = %29
%34 = and i64 %30, 4294967294
br label %35
35: ; preds = %56, %33
%36 = phi i64 [ 0, %33 ], [ %58, %56 ]
%37 = phi i32 [ 0, %33 ], [ %57, %56 ]
%38 = phi i64 [ 0, %33 ], [ %59, %56 ]
%39 = getelementptr inbounds i8, i8* %22, i64 %36
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = sext i32 %37 to i64
%44 = getelementptr inbounds i8, i8* %26, i64 %43
store i8 %40, i8* %44
%45 = add nsw i32 %37, 1
br label %46
46: ; preds = %35, %42
%47 = phi i32 [ %45, %42 ], [ %37, %35 ]
%48 = or i64 %36, 1
%49 = getelementptr inbounds i8, i8* %22, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %46
%53 = sext i32 %47 to i64
%54 = getelementptr inbounds i8, i8* %26, i64 %53
store i8 %50, i8* %54
%55 = add nsw i32 %47, 1
br label %56
56: ; preds = %52, %46
%57 = phi i32 [ %55, %52 ], [ %47, %46 ]
%58 = add nuw nsw i64 %36, 2
%59 = add i64 %38, 2
%60 = icmp eq i64 %59, %34
br i1 %60, label %61, label %35
61: ; preds = %56, %29
%62 = phi i32 [ undef, %29 ], [ %57, %56 ]
%63 = phi i64 [ 0, %29 ], [ %58, %56 ]
%64 = phi i32 [ 0, %29 ], [ %57, %56 ]
%65 = icmp eq i64 %31, 0
br i1 %65, label %74, label %66
66: ; preds = %61
%67 = getelementptr inbounds i8, i8* %22, i64 %63
%68 = load i8, i8* %67
%69 = icmp eq i8 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %66
%71 = sext i32 %64 to i64
%72 = getelementptr inbounds i8, i8* %26, i64 %71
store i8 %68, i8* %72
%73 = add nsw i32 %64, 1
br label %74
74: ; preds = %61, %70, %66, %10
%75 = phi i32 [ 0, %10 ], [ %62, %61 ], [ %73, %70 ], [ %64, %66 ]
%76 = bitcast i64* %3 to i8*
%77 = bitcast i64* %4 to i8*
%78 = add nsw i32 %75, 1
%79 = sext i32 %78 to i64
store i64 %79, i64* %3
%80 = shl nsw i32 %75, 1
%81 = sext i32 %80 to i64
store i64 %81, i64* %4
%82 = or i32 %80, 1
%83 = tail call i8* @malloc(i32 %82)
%84 = tail call i32 @memset(i8* %83, i32 0, i32 %82)
%85 = bitcast i8** %5 to i8*
store i8* %26, i8** %5
%86 = bitcast i8** %6 to i8*
store i8* %83, i8** %6
%87 = tail call i32* @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%88 = call i32 @iconv(i32* %87, i8** %5, i64* %3, i8** %6, i64* %4)
%89 = call i32 @strlen(i8* %83)
%90 = call i32 @fwrite(i8* %83, i32 1, i32 %89, i32* %16)
%91 = call i32 @fclose(i32* %16)
br label %92
92: ; preds = %74, %8
ret i32 0
}