#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*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, char *);
int getopt(int, char **, char *);
int huffman_decode_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int huffman_encode_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *optarg;
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char compress = 1;
  int opt;
  const char *file_in = NULL, *file_out = NULL;
  FILE *in = stdin;
  FILE *out = stdout;
  if (argc == 1) {
    usage(stderr);
    return 1;
  }
  while ((opt = getopt(argc, argv, "i:o:cdhvm")) != -1) {
    switch (opt) {
    case 'i':
      file_in = optarg;
      break;
    case 'o':
      file_out = optarg;
      break;
    case 'c':
      compress = 1;
      break;
    case 'd':
      compress = 0;
      break;
    case 'h':
      usage(stdout);
      return 0;
    default:
      usage(stderr);
      return 1;
    }
  }
  if (file_in) {
    in = fopen(file_in, "rb");
    if (!in) {
      fprintf(stderr, "Can't open input file '%s': %s\n", file_in,
              strerror(errno));
      return 1;
    }
  }
  if (file_out) {
    out = fopen(file_out, "wb");
    if (!out) {
      fprintf(stderr, "Can't open output file '%s': %s\n", file_out,
              strerror(errno));
      return 1;
    }
  }
  return compress ? huffman_encode_file(in, out) : huffman_decode_file(in, out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11db <main+0x6b>
mov    0x2e09(%rip),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x24f>
jmp    11e0 <main+0x70>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe46(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     129b <main+0x12b>
mov    -0x18(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0xc,%eax
ja     127b <main+0x10b>
mov    -0x40(%rbp),%rax
lea    0xde1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dc9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1296 <main+0x126>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1296 <main+0x126>
movb   $0x1,-0x11(%rbp)
jmp    1296 <main+0x126>
movb   $0x0,-0x11(%rbp)
jmp    1296 <main+0x126>
mov    0x2d59(%rip),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bf <main+0x24f>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x24f>
jmp    11e0 <main+0x70>
cmpq   $0x0,-0x20(%rbp)
je     1311 <main+0x1a1>
mov    -0x20(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    130c <main+0x19c>
mov    0x2d04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd46(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x24f>
jmp    1311 <main+0x1a1>
cmpq   $0x0,-0x28(%rbp)
je     1387 <main+0x217>
mov    -0x28(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1382 <main+0x212>
mov    0x2c8e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xcf3(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x24f>
jmp    1387 <main+0x217>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     13a9 <main+0x239>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <huffman_encode_file@plt>
mov    %eax,-0x64(%rbp)
jmp    13b9 <main+0x249>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <huffman_decode_file@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%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    $0x1,%edi
je     128f <main+0x11f>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    $0x1,%al
mov    %eax,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0xe5e(%rip),%r14
mov    0x2e33(%rip),%r15
lea    0xe34(%rip),%r12
xor    %r13d,%r13d
jmp    11e3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x6f,%eax
je     11e0 <main+0x70>
lea    -0x63(%rax),%ecx
cmp    $0x6,%ecx
ja     1222 <main+0xb2>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0x1,%al
mov    %eax,0xc(%rsp)
jmp    11e3 <main+0x73>
movl   $0x0,0xc(%rsp)
jmp    11e3 <main+0x73>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
jmp    11e3 <main+0x73>
cmp    $0xffffffff,%eax
jne    128f <main+0x11f>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
mov    0x20(%rsp),%rbx
je     124d <main+0xdd>
lea    0xde9(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12c5 <main+0x155>
test   %r13,%r13
mov    0x18(%rsp),%rsi
je     1272 <main+0x102>
lea    0xdeb(%rip),%rsi
mov    %r13,%rdi
call   1070 <fopen@plt>
mov    %rax,%rsi
test   %rax,%rax
je     1302 <main+0x192>
cmpb   $0x0,0xc(%rsp)
je     12ec <main+0x17c>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <huffman_encode_file@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d07(%rip),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
xor    %eax,%eax
jmp    12a3 <main+0x133>
mov    0x2d04(%rip),%rax
mov    (%rax),%rbx
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd45(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
jmp    1327 <main+0x1b7>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <huffman_decode_file@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%rbx
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd2b(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
jmp    129e <main+0x12e>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@.str = [10 x i8] c"i:o:cdhvm\00"
@optarg = global i8* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [32 x i8] c"Can't open input file '%s': %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [33 x i8] c"Can't open output file '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 1, i8* %6
store i8* null, i8** %8
store i8* null, i8** %9
%12 = load i32*, i32** @stdin
store i32* %12, i32** %10
%13 = load i32*, i32** @stdout
store i32* %13, i32** %11
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32*, i32** @stderr
%18 = call i32 @usage(i32* %17)
store i32 1, i32* %3
br label %84
19: ; preds = %2
br label %20
20: ; preds = %39, %19
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %7
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = load i32, i32* %7
switch i32 %26, label %36 [
i32 105, label %27
i32 111, label %29
i32 99, label %31
i32 100, label %32
i32 104, label %33
]
27: ; preds = %25
%28 = load i8*, i8** @optarg
store i8* %28, i8** %8
br label %39
29: ; preds = %25
%30 = load i8*, i8** @optarg
store i8* %30, i8** %9
br label %39
31: ; preds = %25
store i8 1, i8* %6
br label %39
32: ; preds = %25
store i8 0, i8* %6
br label %39
33: ; preds = %25
%34 = load i32*, i32** @stdout
%35 = call i32 @usage(i32* %34)
store i32 0, i32* %3
br label %84
36: ; preds = %25
%37 = load i32*, i32** @stderr
%38 = call i32 @usage(i32* %37)
store i32 1, i32* %3
br label %84
39: ; preds = %32, %31, %29, %27
br label %20
40: ; preds = %20
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i8*, i8** %8
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %45, i32** %10
%46 = load i32*, i32** %10
%47 = icmp ne i32* %46, null
br i1 %47, label %54, label %48
48: ; preds = %43
%49 = load i32*, i32** @stderr
%50 = load i8*, i8** %8
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %52)
store i32 1, i32* %3
br label %84
54: ; preds = %43
br label %55
55: ; preds = %54, %40
%56 = load i8*, i8** %9
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %70
58: ; preds = %55
%59 = load i8*, i8** %9
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %60, i32** %11
%61 = load i32*, i32** %11
%62 = icmp ne i32* %61, null
br i1 %62, label %69, label %63
63: ; preds = %58
%64 = load i32*, i32** @stderr
%65 = load i8*, i8** %9
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 @fprintf(i32* %64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %65, i8* %67)
store i32 1, i32* %3
br label %84
69: ; preds = %58
br label %70
70: ; preds = %69, %55
%71 = load i8, i8* %6
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %70
%75 = load i32*, i32** %10
%76 = load i32*, i32** %11
%77 = call i32 @huffman_encode_file(i32* %75, i32* %76)
br label %82
78: ; preds = %70
%79 = load i32*, i32** %10
%80 = load i32*, i32** %11
%81 = call i32 @huffman_decode_file(i32* %79, i32* %80)
br label %82
82: ; preds = %78, %74
%83 = phi i32 [ %77, %74 ], [ %81, %78 ]
store i32 %83, i32* %3
br label %84
84: ; preds = %82, %63, %48, %36, %33, %16
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@.str = [10 x i8] c"i:o:cdhvm\00"
@optarg = global i8* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [32 x i8] c"Can't open input file '%s': %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [33 x i8] c"Can't open output file '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32*, i32** @stdin
%4 = load i32*, i32** @stdout
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32*, i32** @stderr
%8 = tail call i32 @usage(i32* %7)
br label %60
9: ; preds = %18, %21
%10 = phi i8* [ %22, %21 ], [ %20, %18 ]
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %29 [
i32 -1, label %32
i32 105, label %16
i32 111, label %21
i32 99, label %24
i32 100, label %23
i32 104, label %26
]
12: ; preds = %2, %24
%13 = phi i8 [ %25, %24 ], [ 1, %2 ]
%14 = phi i8* [ %19, %24 ], [ null, %2 ]
%15 = phi i8* [ %10, %24 ], [ null, %2 ]
br label %18
16: ; preds = %9
%17 = load i8*, i8** @optarg
br label %18
18: ; preds = %12, %16
%19 = phi i8* [ %14, %12 ], [ %17, %16 ]
%20 = phi i8* [ %15, %12 ], [ %10, %16 ]
br label %9
21: ; preds = %9
%22 = load i8*, i8** @optarg
br label %9
23: ; preds = %9
br label %24
24: ; preds = %9, %23
%25 = phi i8 [ 0, %23 ], [ 1, %9 ]
br label %12
26: ; preds = %9
%27 = load i32*, i32** @stdout
%28 = tail call i32 @usage(i32* %27)
br label %60
29: ; preds = %9
%30 = load i32*, i32** @stderr
%31 = tail call i32 @usage(i32* %30)
br label %60
32: ; preds = %9
%33 = icmp eq i8* %19, null
br i1 %33, label %42, label %34
34: ; preds = %32
%35 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32*, i32** @stderr
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %40)
br label %60
42: ; preds = %34, %32
%43 = phi i32* [ %35, %34 ], [ %3, %32 ]
%44 = icmp eq i8* %10, null
br i1 %44, label %53, label %45
45: ; preds = %42
%46 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i32*, i32** @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %51)
br label %60
53: ; preds = %45, %42
%54 = phi i32* [ %46, %45 ], [ %4, %42 ]
%55 = icmp eq i8 %13, 0
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = tail call i32 @huffman_encode_file(i32* %43, i32* %54)
br label %60
58: ; preds = %53
%59 = tail call i32 @huffman_decode_file(i32* %43, i32* %54)
br label %60
60: ; preds = %56, %58, %48, %37, %29, %26, %6
%61 = phi i32 [ 1, %6 ], [ 1, %29 ], [ 0, %26 ], [ 1, %48 ], [ 1, %37 ], [ %57, %56 ], [ %59, %58 ]
ret i32 %61
}