#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 */
struct lnode {
  int dummy;
};
struct kpnode {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ displist(struct lnode *);
int /*<<< orphan*/ disptree(struct kpnode *);
int /*<<< orphan*/ encode();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct lnode *mklist(int);
struct kpnode *mktree(struct lnode *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ remlnode(struct lnode **);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd1, fd2;
  struct lnode *clist;
  struct kpnode *tree;
  if (argc < 1) {
    fprintf(stderr, "Error: not enough arguments.\n");
    return 1;
  }
  if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Error: cannot open file.\n");
    return 1;
  }
  if ((clist = mklist(fd1)) == 0) {
    fprintf(stderr, "Error while compiling frequencies.\n");
    return 1;
  }
  displist(clist);
  tree = mktree(clist);
  disptree(tree);
  encode();
  remlnode(&clist);
  close(fd1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11d1 <main+0x41>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1214 <main+0x84>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0xf9>
mov    -0x14(%rbp),%edi
call   1090 <mklist@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124b <main+0xbb>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0xf9>
mov    -0x20(%rbp),%rdi
call   1070 <displist@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <mktree@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <disptree@plt>
mov    $0x0,%al
call   1030 <encode@plt>
lea    -0x20(%rbp),%rdi
call   1040 <remlnode@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    11f4 <main+0x64>
mov    0x8(%rsi),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
test   %eax,%eax
js     1206 <main+0x76>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <mklist@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1218 <main+0x88>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <displist@plt>
mov    %rbp,%rdi
call   10a0 <mktree@plt>
mov    %rax,%rdi
call   1050 <disptree@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <encode@plt>
mov    %rsp,%rdi
call   1040 <remlnode@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1232 <main+0xa2>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
jmp    1228 <main+0x98>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
jmp    1228 <main+0x98>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.lnode = type { i32 }
%struct.kpnode = type { i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Error: not enough arguments.\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Error: cannot open file.\0A\00"
@.str.2 = [36 x i8] c"Error while compiling frequencies.\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 %struct.lnode*
%9 = alloca %struct.kpnode*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %43
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %43
25: ; preds = %15
%26 = load i32, i32* %6
%27 = call %struct.lnode* @mklist(i32 %26)
store %struct.lnode* %27, %struct.lnode** %8
%28 = icmp eq %struct.lnode* %27, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %43
32: ; preds = %25
%33 = load %struct.lnode*, %struct.lnode** %8
%34 = call i32 @displist(%struct.lnode* %33)
%35 = load %struct.lnode*, %struct.lnode** %8
%36 = call %struct.kpnode* @mktree(%struct.lnode* %35)
store %struct.kpnode* %36, %struct.kpnode** %9
%37 = load %struct.kpnode*, %struct.kpnode** %9
%38 = call i32 @disptree(%struct.kpnode* %37)
%39 = call i32 (...) @encode()
%40 = call i32 @remlnode(%struct.lnode** %8)
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %32, %29, %22, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.lnode = type { i32 }
%struct.kpnode = type { i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Error: not enough arguments.\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Error: cannot open file.\0A\00"
@.str.2 = [36 x i8] c"Error while compiling frequencies.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.lnode*
%4 = bitcast %struct.lnode** %3 to i8*
%5 = icmp slt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %31
18: ; preds = %9
%19 = tail call %struct.lnode* @mklist(i32 %13)
store %struct.lnode* %19, %struct.lnode** %3
%20 = icmp eq %struct.lnode* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %31
24: ; preds = %18
%25 = tail call i32 @displist(%struct.lnode* %19)
%26 = tail call %struct.kpnode* @mktree(%struct.lnode* %19)
%27 = tail call i32 @disptree(%struct.kpnode* %26)
%28 = tail call i32 (...) @encode()
%29 = call i32 @remlnode(%struct.lnode** %3)
%30 = call i32 @close(i32 %13)
br label %31
31: ; preds = %24, %21, %15, %6
%32 = phi i32 [ 1, %6 ], [ 1, %15 ], [ 1, %21 ], [ 0, %24 ]
ret i32 %32
}