// File: raemarks[P]SuffixTree/src/main.cpp
// Function: main
int main(int argc, char *argv[])
{
	//TODO: append $ to input string!
	//suffixtree::SuffixTree tree = new suffixtree::SuffixTree(params);

	if (argc < 3) {
		printf("Error, not enough arguments.\n");
		printf("Usage: '%s <input fasta file> {<alphabet>}'\n", argv[0]);
		return 1;
	}

	std::ifstream in(argv[1], std::ifstream::in);
	if (!in.good()) {
		printf("Error: file '%s' not valid.\n", argv[1]);
		return 2;
	}

	std::string name, input;
	ReadInputFasta(in, input, name);

	/*
	std::cout << "Name: " << name << std::endl;
	std::cout << "Input: " << input << std::endl;
	*/

	suffixtree::Tree *t = new suffixtree::Tree(input, "$ACGT");

	t->Build();
	//t->EnumerateNodesDFS();
	t->PrintTreeInfo();
	t->PrintLongestRepeatSeqInfo();
	//t->EnumerateBWT();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x47fe
leaq 0x9c9(%rip), %rdi       # 0x519f
movb $0x0, %al
callq 0x2030
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x9d2(%rip), %rdi       # 0x51bd
movb $0x0, %al
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0x49b4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x2310
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x22c0
movb %al, -0x293(%rbp)
jmp 0x4837
movb -0x293(%rbp), %al
testb $0x1, %al
jne 0x4888
jmp 0x4843
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x998(%rip), %rdi       # 0x51ea
xorl %eax, %eax
callq 0x2030
jmp 0x485b
movl $0x2, -0x4(%rbp)
movl $0x1, -0x228(%rbp)
jmp 0x49a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x4a48
leaq -0x248(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x2260
leaq -0x268(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x2260
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
leaq -0x218(%rbp), %rdi
callq 0x4190
jmp 0x48ca
movl $0x80, %edi
callq 0x2190
movq %rax, -0x2b0(%rbp)
jmp 0x48dd
movb $0x1, -0x292(%rbp)
leaq -0x291(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x22f0
movq -0x2b8(%rbp), %rdx
leaq 0x902(%rip), %rsi       # 0x5207
leaq -0x290(%rbp), %rdi
callq 0x4440
jmp 0x4913
movq -0x2b0(%rbp), %rdi
leaq -0x268(%rbp), %rsi
leaq -0x290(%rbp), %rdx
callq 0x2510
jmp 0x492f
movb $0x0, -0x292(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x20f0
leaq -0x291(%rbp), %rdi
callq 0x21d0
movq -0x2b0(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rdi
callq 0x2750
jmp 0x496a
movq -0x270(%rbp), %rdi
callq 0x3680
jmp 0x4978
movq -0x270(%rbp), %rdi
callq 0x3730
jmp 0x4986
leaq -0x268(%rbp), %rdi
callq 0x20f0
leaq -0x248(%rbp), %rdi
callq 0x20f0
movl $0x0, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x2050
movl -0x4(%rbp), %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x4a30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x4a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x20f0
leaq -0x291(%rbp), %rdi
callq 0x21d0
testb $0x1, -0x292(%rbp)
jne 0x4a1d
jmp 0x4a2e
movq -0x2b0(%rbp), %rdi
movl $0x80, %esi
callq 0x21a0
jmp 0x4a30
leaq -0x268(%rbp), %rdi
callq 0x20f0
leaq -0x248(%rbp), %rdi
callq 0x20f0
leaq -0x218(%rbp), %rdi
callq 0x2050
movq -0x220(%rbp), %rdi
callq 0x22e0