// File: /workspace/github_cpp_makefile_star2_O1/comptotherescue[P]Fibonacci-Heap/keywordcounter.cpp
// Function: main
int main(int argc,char* argv[])
{
	//check if input file is present
	if (argc == 2)
	{
		map<string, Fib*> words;
		map<string, Fib*>::iterator itr;
		vector<pair<string, Fib*>> pairs;
		map<Fib*, string> heapmap;
		map<Fib*, string>::iterator itr2;
		bool l_bIsword = false;
		Fibops *Fibop = new Fibops();
		ofstream myfile;
		string strline, line, name;
		//output file
		myfile.open("output_file.txt");
		ifstream file(argv[1]);
		while (file)
		{
			l_bIsword = false;
			if (!getline(file, strline))
			{
				break;
			}
			istringstream line2(strline);
			while (line2)
			{

				if ((!getline(line2, line, ' ')))
				{
					break;
				}

				if (line[0] == '$')
				{
					name = line.substr(1, line.size() - 1);
					l_bIsword = true;
				}
				else if (l_bIsword)
				{
					int data = atoi(line.c_str());
					itr = words.find(name);
					if (itr == words.end())
					{
						Fib* q;

						q = Fibop->Insert(data);
						words.insert({ name,q });
						heapmap.insert({ q,name });
					}
					else
					{

						Fibop->IncreaseKey(itr->second, data);
					}
				}
				else if (line == "stop")
				{
					myfile.close();
					exit(1);
				}
				else
				{
					int h = atoi(line.c_str());


					for (int i = 0; i < h; i++)
					{   
						//Removes max from heap
						Fib* q = Fibop->RemoveMax();
						itr2 = heapmap.find(q);
						myfile << itr2->second;
						if (i != h - 1)
						{
							myfile << ",";
						}
						pairs.push_back(make_pair(itr2->second, itr2->first));
					}
					for (int j = 0; j < pairs.size(); j++)
					{
						words.erase(pairs[j].first);
						heapmap.erase(pairs[j].second);
						Fib* temp = Fibop->Insert(pairs[j].second->m_iData);
						words.insert({ pairs[j].first,temp });
						heapmap.insert({ temp,pairs[j].first });
					}
					pairs.clear();
					myfile << "\n";
				}
			}

		}
	}
	else
	{
		cout << "Invalid parameters";
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x698, %rsp            # imm = 0x698
cmpl $0x2, %edi
jne 0x25c3
movq %rsi, %r14
leaq -0x130(%rbp), %rcx
xorl %eax, %eax
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rax, -0x60(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
leaq -0xe0(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movl $0x8, %edi
callq 0x2160
movq %rax, %r15
movq $0x0, (%rax)
leaq -0x4b8(%rbp), %rdi
callq 0x2260
leaq -0xf8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xa8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x88(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1b2d(%rip), %rsi      # 0x4004
leaq -0x4b8(%rbp), %rdi
movl $0x10, %edx
callq 0x2040
movq 0x8(%r14), %rsi
leaq -0x6c0(%rbp), %rdi
movl $0x8, %edx
callq 0x2290
movq -0x6c0(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x6a0(%rbp,%rax)
je 0x25ef
leaq -0x6c0(%rbp), %rdi
callq 0x2060
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x253a
callq 0x2140
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2552
callq 0x2140
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x256a
callq 0x2140
movq 0x3a57(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x4b0(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x4b8(%rbp,%rcx)
callq 0x2120
leaq -0x3c0(%rbp), %rdi
callq 0x2090
leaq -0xe8(%rbp), %rdi
callq 0x344e
leaq -0x70(%rbp), %rdi
callq 0x305a
leaq -0x138(%rbp), %rdi
callq 0x34b8
jmp 0x25db
movq 0x3a0e(%rip), %rdi      # 0x5fd8
leaq 0x1a4c(%rip), %rsi      # 0x401d
movl $0x12, %edx
callq 0x2190
xorl %eax, %eax
addq $0x698, %rsp            # imm = 0x698
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%rax,%rbp), %rdi
addq $-0x6c0, %rdi           # imm = 0xF940
leaq -0x2b8(%rbp), %rbx
leaq -0xb8(%rbp), %r14
leaq -0x50(%rbp), %r12
movq %r15, -0x78(%rbp)
movl $0xa, %esi
callq 0x2150
movsbl %al, %edx
leaq -0x6c0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x22a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2516
movq %rbx, %rdi
leaq -0x108(%rbp), %rsi
movl $0x8, %edx
callq 0x2250
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x298(%rbp,%rax)
je 0x26ab
movq %rbx, %rdi
movq 0x395b(%rip), %rsi      # 0x5fd0
callq 0x21e0
leaq -0x240(%rbp), %rdi
callq 0x2090
movq -0x6c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x6c0, %rdi           # imm = 0xF940
testb $0x5, 0x20(%rdi)
je 0x2610
jmp 0x2516
movl $0x0, -0x54(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x20, %edx
callq 0x22a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x266b
movq -0xb8(%rbp), %rdi
cmpb $0x24, (%rdi)
jne 0x2721
movq -0xb0(%rbp), %rcx
decq %rcx
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x2170
leaq -0x98(%rbp), %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2717
callq 0x2140
movb $0x1, %al
movl %eax, -0x54(%rbp)
jmp 0x2a04
testb $0x1, -0x54(%rbp)
je 0x2774
callq 0x2220
movl %eax, %r14d
leaq -0x138(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3522
leaq -0x130(%rbp), %rcx
cmpq %rcx, %rax
je 0x2a22
movq 0x40(%rax), %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x2c66
leaq -0x2b8(%rbp), %rbx
leaq -0xb8(%rbp), %r14
jmp 0x2a04
movq %r14, %rdi
leaq 0x1896(%rip), %rsi      # 0x4014
callq 0x2080
testl %eax, %eax
je 0x2ad4
movq -0xb8(%rbp), %rdi
callq 0x2220
testl %eax, %eax
jle 0x287b
movl %eax, %r14d
leal -0x1(%r14), %ebx
xorl %r13d, %r13d
movq -0x78(%rbp), %rdi
callq 0x2d06
movq -0xd8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
testq %rdx, %rdx
je 0x27da
xorl %esi, %esi
cmpq %rax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
jmp 0x27c0
leaq -0xe0(%rbp), %rdx
movq %rdx, %r12
cmpq %rdx, %rcx
je 0x27f4
cmpq 0x20(%rcx), %rax
cmovbq %rdx, %rcx
movq %rcx, %r12
movq 0x28(%r12), %rsi
movq 0x30(%r12), %rdx
leaq -0x4b8(%rbp), %rdi
callq 0x2190
cmpl %ebx, %r13d
je 0x2827
movl $0x1, %edx
leaq -0x4b8(%rbp), %rdi
leaq 0x17f7(%rip), %rsi      # 0x4019
callq 0x2190
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x28(%r12), %rsi
movq 0x30(%r12), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x30b6
movq 0x20(%r12), %rax
movq %rax, -0x30(%rbp)
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x3914
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x286f
callq 0x2140
incl %r13d
cmpl %r14d, %r13d
jne 0x27a9
movq -0x70(%rbp), %r14
movq -0x68(%rbp), %r12
cmpq %r14, %r12
je 0x29b0
xorl %ebx, %ebx
xorl %r13d, %r13d
addq %rbx, %r14
leaq -0x138(%rbp), %rdi
movq %r14, %rsi
callq 0x3bda
leaq -0x50(%rbp), %r12
leaq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x3c8c
movq -0x70(%rbp), %rax
leaq (%rax,%rbx), %rsi
addq $0x20, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x3db8
leaq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x3e3a
movq -0x70(%rbp), %rax
movq 0x20(%rax,%rbx), %rax
movl 0x4(%rax), %esi
movq -0x78(%rbp), %rdi
callq 0x2bf4
movq %rax, %r14
movq -0x70(%rbp), %rax
leaq -0x40(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq (%rax,%rbx), %rsi
movq 0x8(%rax,%rbx), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x30b6
movq %r14, -0x30(%rbp)
leaq -0x138(%rbp), %rdi
movq %r12, %rsi
callq 0x35c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x293a
callq 0x2140
movq -0x70(%rbp), %rax
movq %r14, -0x50(%rbp)
leaq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq (%rax,%rbx), %rsi
movq 0x8(%rax,%rbx), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x30b6
leaq -0xe8(%rbp), %rdi
movq %r12, %rsi
callq 0x3794
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2980
callq 0x2140
incq %r13
movq -0x70(%rbp), %r14
movq -0x68(%rbp), %r12
movq %r12, %rax
subq %r14, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %rbx
cmpq %r13, %rax
ja 0x2891
cmpq %r14, %r12
je 0x29d6
movq %r14, %rbx
movq (%rbx), %rdi
addq $0x10, %rbx
cmpq %rbx, %rdi
je 0x29c9
callq 0x2140
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x29b8
movq %r14, -0x68(%rbp)
movl $0x1, %edx
leaq -0x4b8(%rbp), %rdi
leaq 0x1632(%rip), %rsi      # 0x401b
callq 0x2190
movq -0x78(%rbp), %r15
leaq -0x2b8(%rbp), %rbx
leaq -0xb8(%rbp), %r14
leaq -0x50(%rbp), %r12
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x298(%rbp,%rax)
je 0x26b2
jmp 0x266b
movq %r15, %rdi
movl %r14d, %esi
callq 0x2bf4
movq %rax, %r14
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x30b6
movq %r14, -0x30(%rbp)
leaq -0x138(%rbp), %rdi
movq %r12, %rsi
callq 0x35c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2a76
callq 0x2140
movq %r14, -0x50(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x30b6
leaq -0xe8(%rbp), %rdi
movq %r12, %rsi
callq 0x3794
leaq -0x2b8(%rbp), %rbx
leaq -0xb8(%rbp), %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2a04
callq 0x2140
jmp 0x2a04
leaq -0x4b8(%rbp), %rdi
callq 0x21d0
movl $0x1, %edi
callq 0x21b0
jmp 0x2aec
movq %rax, %rbx
jmp 0x2b77
jmp 0x2af6
movq %rax, %rbx
jmp 0x2bcb
jmp 0x2b1f
jmp 0x2b49
jmp 0x2b2e
jmp 0x2b49
jmp 0x2b49
jmp 0x2b49
jmp 0x2b10
jmp 0x2b49
jmp 0x2b49
movq %rax, %rbx
jmp 0x2b6b
jmp 0x2b49
jmp 0x2b49
jmp 0x2b2e
jmp 0x2b49
jmp 0x2b49
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
jmp 0x2b39
jmp 0x2b49
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2b4c
callq 0x2140
jmp 0x2b4c
jmp 0x2b49
jmp 0x2b49
movq %rax, %rbx
movq 0x347d(%rip), %rsi      # 0x5fd0
leaq -0x2b8(%rbp), %rdi
callq 0x21e0
leaq -0x240(%rbp), %rdi
callq 0x2090
leaq -0x6c0(%rbp), %rdi
callq 0x2060
leaq -0x88(%rbp), %rax
movq -0x98(%rbp), %rdi
cmpq %rax, %rdi
je 0x2b8f
callq 0x2140
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2ba7
callq 0x2140
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x2bbf
callq 0x2140
leaq -0x4b8(%rbp), %rdi
callq 0x2200
leaq -0xe8(%rbp), %rdi
callq 0x344e
leaq -0x70(%rbp), %rdi
callq 0x305a
leaq -0x138(%rbp), %rdi
callq 0x34b8
movq %rbx, %rdi
callq 0x2270