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

/* Variables and functions */
int /*<<< orphan*/ copyright();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ mtf_list_decode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ mtf_list_encode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  if (argc != 4) {
    fprintf(stderr, "\n Usage : gtmtf c|d inputfile outputfile\n");
    copyright();
    return 0;
  }
  in = fopen(argv[2], "rb");
  if (!in) {
    fprintf(stderr, "\n Error opening input file!\n");
    copyright();
    return 0;
  }
  out = fopen(argv[3], "wb");
  if (!out) {
    fprintf(stderr, "\n Error opening output file!\n");
    copyright();
    return 0;
  }
  if (!strcmp(argv[1], "d") || !strcmp(argv[1], "D")) {
    fprintf(stderr, "\n MTF decoding...");
    mtf_list_decode(in, out);
  } else if (!strcmp(argv[1], "c") || !strcmp(argv[1], "C")) {
    fprintf(stderr, "\n --[ A Move-to-Front (MTF) Implementation ]--\n");
    fprintf(stderr, "\n MTF coding...");
    mtf_list_encode(in, out);
  } else {
    fprintf(stderr, "\n Error! Unknown: \"%s\"\n", argv[1]);
    copyright();
    return 0;
  }
  fprintf(stderr, "done.\n");
  copyright();
  if (in)
    fclose(in);
  if (out)
    fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11ba <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b5 <main+0x245>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1207 <main+0x97>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b5 <main+0x245>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1254 <main+0xe4>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b5 <main+0x245>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe08(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     128e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xded(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12b7 <main+0x147>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <mtf_list_decode@plt>
jmp    1368 <main+0x1f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbb(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     12f1 <main+0x181>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1331 <main+0x1c1>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <mtf_list_encode@plt>
jmp    1363 <main+0x1f3>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b5 <main+0x245>
jmp    1368 <main+0x1f8>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
cmpq   $0x0,-0x18(%rbp)
je     139a <main+0x22a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     13ae <main+0x23e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1238 <main+0xc8>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124a <main+0xda>
mov    %rax,%r12
mov    0x18(%rbx),%rdi
lea    0xe9f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125c <main+0xec>
mov    %rax,%r14
mov    0x8(%rbx),%r15
lea    0xea4(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1288 <main+0x118>
lea    0xe8f(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1288 <main+0x118>
lea    0xe8c(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     12ac <main+0x13c>
lea    0xe77(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     12ac <main+0x13c>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1273 <main+0x103>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
jmp    126c <main+0xfc>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
jmp    126c <main+0xfc>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <copyright@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <mtf_list_decode@plt>
jmp    12de <main+0x16e>
mov    0x2d2d(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xde9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <mtf_list_encode@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <copyright@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    127a <main+0x10a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"\0A Usage : gtmtf c|d inputfile outputfile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"\0A Error opening input file!\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"\0A Error opening output file!\0A\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [2 x i8] c"D\00"
@.str.7 = [18 x i8] c"\0A MTF decoding...\00"
@.str.8 = [2 x i8] c"c\00"
@.str.9 = [2 x i8] c"C\00"
@.str.10 = [48 x i8] c"\0A --[ A Move-to-Front (MTF) Implementation ]--\0A\00"
@.str.11 = [16 x i8] c"\0A MTF coding...\00"
@.str.12 = [24 x i8] c"\0A Error! Unknown: \22%s\22\0A\00"
@.str.13 = [7 x i8] c"done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 4
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %98
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %98
25: ; preds = %14
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp ne i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %98
36: ; preds = %25
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %36
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %42, %36
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%51 = load i32*, i32** %6
%52 = load i32*, i32** %7
%53 = call i32 @mtf_list_decode(i32* %51, i32* %52)
br label %82
54: ; preds = %42
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @strcmp(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %54
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %74, label %66
66: ; preds = %60, %54
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0))
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%71 = load i32*, i32** %6
%72 = load i32*, i32** %7
%73 = call i32 @mtf_list_encode(i32* %71, i32* %72)
br label %81
74: ; preds = %60
%75 = load i32, i32* @stderr
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %78)
%80 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %98
81: ; preds = %66
br label %82
82: ; preds = %81, %48
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%85 = call i32 (...) @copyright()
%86 = load i32*, i32** %6
%87 = icmp ne i32* %86, null
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = load i32*, i32** %6
%90 = call i32 @fclose(i32* %89)
br label %91
91: ; preds = %88, %82
%92 = load i32*, i32** %7
%93 = icmp ne i32* %92, null
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i32*, i32** %7
%96 = call i32 @fclose(i32* %95)
br label %97
97: ; preds = %94, %91
store i32 0, i32* %3
br label %98
98: ; preds = %97, %74, %32, %21, %10
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"\0A Usage : gtmtf c|d inputfile outputfile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"\0A Error opening input file!\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"\0A Error opening output file!\0A\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [2 x i8] c"D\00"
@.str.7 = [18 x i8] c"\0A MTF decoding...\00"
@.str.8 = [2 x i8] c"c\00"
@.str.9 = [2 x i8] c"C\00"
@.str.10 = [48 x i8] c"\0A --[ A Move-to-Front (MTF) Implementation ]--\0A\00"
@.str.11 = [16 x i8] c"\0A MTF coding...\00"
@.str.12 = [24 x i8] c"\0A Error! Unknown: \22%s\22\0A\00"
@.str.13 = [7 x i8] c"done.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @copyright()
br label %60
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 (...) @copyright()
br label %60
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 (...) @copyright()
br label %60
26: ; preds = %17
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31, %26
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%37 = tail call i32 @mtf_list_decode(i32* %11, i32* %20)
br label %54
38: ; preds = %31
%39 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41, %38
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%49 = tail call i32 @mtf_list_encode(i32* %11, i32* %20)
br label %54
50: ; preds = %41
%51 = load i32, i32* @stderr
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %28)
%53 = tail call i32 (...) @copyright()
br label %60
54: ; preds = %44, %34
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%57 = tail call i32 (...) @copyright()
%58 = tail call i32 @fclose(i32* %11)
%59 = tail call i32 @fclose(i32* %20)
br label %60
60: ; preds = %54, %50, %22, %13, %4
ret i32 0
}