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

/* Variables and functions */
char EOF;
char getc(int /*<<< orphan*/);
int /*<<< orphan*/ huffmanTree(char *, int);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char *argv[]) {
  char ch;
  char str[40960];
  int i = 0;
  while ((ch = getc(stdin)) != EOF) {
    str[i++] = ch;
  }
  int size = strlen(str);
  huffmanTree(str, size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xa024(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e72(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     119b <main+0x6b>
mov    -0x11(%rbp),%cl
mov    -0xa024(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa024(%rbp)
cltq
mov    %cl,-0xa020(%rbp,%rax,1)
jmp    1153 <main+0x23>
lea    -0xa020(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xa028(%rbp)
lea    -0xa020(%rbp),%rdi
mov    -0xa028(%rbp),%esi
call   1040 <huffmanTree@plt>
xor    %eax,%eax
add    $0xa030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa000,%rsp
mov    0x2ea5(%rip),%r14
mov    (%r14),%edi
call   1050 <getc@plt>
mov    0x2e8e(%rip),%r15
cmp    (%r15),%al
je     1173 <main+0x43>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rbx)
mov    (%r14),%edi
call   1050 <getc@plt>
add    $0x1,%rbx
cmp    (%r15),%al
jne    1160 <main+0x30>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <huffmanTree@plt>
xor    %eax,%eax
add    $0xa000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca [40960 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %10
10: ; preds = %17, %2
%11 = load i32, i32* @stdin
%12 = call signext i8 @getc(i32 %11)
store i8 %12, i8* %6
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i8, i8* %6
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [40960 x i8], [40960 x i8]* %7, i64 0, i64 %21
store i8 %18, i8* %22
br label %10
23: ; preds = %10
%24 = getelementptr inbounds [40960 x i8], [40960 x i8]* %7, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %9
%26 = getelementptr inbounds [40960 x i8], [40960 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 @huffmanTree(i8* %26, i32 %27)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [40960 x i8]
%4 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = tail call signext i8 @getc(i32 %5)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %18, label %9
9: ; preds = %2, %9
%10 = phi i64 [ %12, %9 ], [ 0, %2 ]
%11 = phi i8 [ %15, %9 ], [ %6, %2 ]
%12 = add nuw i64 %10, 1
%13 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 %10
store i8 %11, i8* %13
%14 = load i32, i32* @stdin
%15 = tail call signext i8 @getc(i32 %14)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %9
18: ; preds = %9, %2
%19 = call i32 @strlen(i8* %4)
%20 = call i32 @huffmanTree(i8* %4, i32 %19)
ret i32 0
}