#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*/ build_histogram(char *);
int /*<<< orphan*/ build_itemlist();
int /*<<< orphan*/ build_pool();
int /*<<< orphan*/ build_tree();
int /*<<< orphan*/ build_valueencode();
int /*<<< orphan*/ compress_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free_tree();
int /*<<< orphan*/ gen_itemencoding();
int /*<<< orphan*/ gen_tree2();
int /*<<< orphan*/ init_itemlist();
int /*<<< orphan*/ init_tree();
int /*<<< orphan*/ print_tree(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_tree2(int /*<<< orphan*/ *);
int /*<<< orphan*/ reset_histogram();
int /*<<< orphan*/ sort_itemlist();
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write_tree(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i;
  FILE *gf;
  FILE *fin;
  FILE *fout;
  for (i = 1; i < argc; ++i) {
    char fnameout[strlen(argv[i]) + 20];
    strcpy(fnameout, argv[i]);
    strcat(fnameout, ".hfm");
    reset_histogram();
    build_histogram(argv[i]);
    build_pool();
    init_tree();
    build_tree();
    gf = fopen("testgraph.dot", "w");
    print_tree(gf);
    fclose(gf);
    init_itemlist();
    build_itemlist();
    free_tree();
    sort_itemlist();
    gen_itemencoding();
    gen_tree2();
    gf = fopen("testgraph2.dot", "w");
    print_tree2(gf);
    fclose(gf);
    build_valueencode();
    fin = fopen(argv[i], "r");
    fout = fopen(fnameout, "w");
    write_tree(fout);
    compress_file(fin, fout);
    fclose(fin);
    fclose(fout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13ee <main+0x19e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <strlen@plt>
add    $0x14,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcpy@plt>
mov    -0x48(%rbp),%rdi
lea    0xd34(%rip),%rsi
call   1110 <strcat@plt>
mov    $0x0,%al
call   1170 <reset_histogram@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <build_histogram@plt>
mov    $0x0,%al
call   1140 <build_pool@plt>
mov    $0x0,%al
call   1150 <init_tree@plt>
mov    $0x0,%al
call   10d0 <build_tree@plt>
lea    0xd00(%rip),%rdi
lea    0xd07(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1120 <print_tree@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fclose@plt>
mov    $0x0,%al
call   1050 <init_itemlist@plt>
mov    $0x0,%al
call   10e0 <build_itemlist@plt>
mov    $0x0,%al
call   1030 <free_tree@plt>
mov    $0x0,%al
call   1090 <sort_itemlist@plt>
mov    $0x0,%al
call   10b0 <gen_itemencoding@plt>
mov    $0x0,%al
call   1100 <gen_tree2@plt>
lea    0xcbd(%rip),%rdi
lea    0xcb4(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1160 <print_tree2@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fclose@plt>
mov    $0x0,%al
call   1130 <build_valueencode@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc90(%rip),%rsi
call   10f0 <fopen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,-0x28(%rbp)
lea    0xc6b(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <write_tree@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <compress_file@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126d <main+0x1d>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     13c3 <main+0x173>
mov    %edi,%eax
mov    %rax,-0x38(%rbp)
mov    $0x1,%r12d
mov    %rsi,-0x30(%rbp)
nopw   0x0(%rax,%rax,1)
mov    (%rsi,%r12,8),%rdi
call   1080 <strlen@plt>
mov    %rsp,-0x40(%rbp)
add    $0x14,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x30(%rbp),%rax
mov    (%rax,%r12,8),%rsi
mov    %r15,%rdi
call   1060 <strcpy@plt>
mov    %r15,%rdi
lea    0xd45(%rip),%rsi
call   1110 <strcat@plt>
xor    %eax,%eax
call   1170 <reset_histogram@plt>
mov    -0x30(%rbp),%rax
mov    (%rax,%r12,8),%rdi
call   10a0 <build_histogram@plt>
xor    %eax,%eax
call   1140 <build_pool@plt>
xor    %eax,%eax
call   1150 <init_tree@plt>
xor    %eax,%eax
call   10d0 <build_tree@plt>
lea    0xd15(%rip),%rdi
lea    0xd1c(%rip),%r14
mov    %r14,%rsi
call   10f0 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1120 <print_tree@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
call   1050 <init_itemlist@plt>
xor    %eax,%eax
call   10e0 <build_itemlist@plt>
xor    %eax,%eax
call   1030 <free_tree@plt>
xor    %eax,%eax
call   1090 <sort_itemlist@plt>
xor    %eax,%eax
call   10b0 <gen_itemencoding@plt>
xor    %eax,%eax
call   1100 <gen_tree2@plt>
lea    0xcd2(%rip),%rdi
mov    %r14,%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1160 <print_tree2@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
call   1130 <build_valueencode@plt>
mov    -0x30(%rbp),%rax
mov    (%rax,%r12,8),%rdi
lea    0xcb0(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    %r14,%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10c0 <write_tree@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <compress_file@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rsp
add    $0x1,%r12
cmp    %r12,-0x38(%rbp)
jne    1280 <main+0x30>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".hfm\00"
@.str.1 = [14 x i8] c"testgraph.dot\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [15 x i8] c"testgraph2.dot\00"
@.str.4 = [2 x i8] c"r\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 i32*
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %12
12: ; preds = %78, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %81
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 20
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %10
%26 = alloca i8, i64 %24
store i64 %24, i64* %11
%27 = load i8**, i8*** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %26, i8* %31)
%33 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = call i32 (...) @reset_histogram()
%35 = load i8**, i8*** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @build_histogram(i8* %39)
%41 = call i32 (...) @build_pool()
%42 = call i32 (...) @init_tree()
%43 = call i32 (...) @build_tree()
%44 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %44, i32** %7
%45 = load i32*, i32** %7
%46 = call i32 @print_tree(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
%49 = call i32 (...) @init_itemlist()
%50 = call i32 (...) @build_itemlist()
%51 = call i32 (...) @free_tree()
%52 = call i32 (...) @sort_itemlist()
%53 = call i32 (...) @gen_itemencoding()
%54 = call i32 (...) @gen_tree2()
%55 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %55, i32** %7
%56 = load i32*, i32** %7
%57 = call i32 @print_tree2(i32* %56)
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = call i32 (...) @build_valueencode()
%61 = load i8**, i8*** %5
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %66, i32** %8
%67 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %67, i32** %9
%68 = load i32*, i32** %9
%69 = call i32 @write_tree(i32* %68)
%70 = load i32*, i32** %8
%71 = load i32*, i32** %9
%72 = call i32 @compress_file(i32* %70, i32* %71)
%73 = load i32*, i32** %8
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %9
%76 = call i32 @fclose(i32* %75)
%77 = load i8*, i8** %10
br label %78
78: ; preds = %16
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %12
81: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c".hfm\00"
@.str.1 = [14 x i8] c"testgraph.dot\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [15 x i8] c"testgraph2.dot\00"
@.str.4 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %46
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %44, %6 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 20
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = load i8*, i8** %8
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @reset_histogram()
%19 = load i8*, i8** %8
%20 = call i32 @build_histogram(i8* %19)
%21 = call i32 (...) @build_pool()
%22 = call i32 (...) @init_tree()
%23 = call i32 (...) @build_tree()
%24 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @print_tree(i32* %24)
%26 = call i32 @fclose(i32* %24)
%27 = call i32 (...) @init_itemlist()
%28 = call i32 (...) @build_itemlist()
%29 = call i32 (...) @free_tree()
%30 = call i32 (...) @sort_itemlist()
%31 = call i32 (...) @gen_itemencoding()
%32 = call i32 (...) @gen_tree2()
%33 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @print_tree2(i32* %33)
%35 = call i32 @fclose(i32* %33)
%36 = call i32 (...) @build_valueencode()
%37 = load i8*, i8** %8
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @write_tree(i32* %39)
%41 = call i32 @compress_file(i32* %38, i32* %39)
%42 = call i32 @fclose(i32* %38)
%43 = call i32 @fclose(i32* %39)
%44 = add nuw nsw i64 %7, 1
%45 = icmp eq i64 %44, %5
br i1 %45, label %46, label %6
46: ; preds = %6, %2
ret i32 0
}