// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
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 -0x100(%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, %r14
movq $0x0, (%rax)
leaq -0x4b8(%rbp), %rdi
callq 0x2260
leaq -0xc8(%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(%rbx), %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 -0xd8(%rbp), %rdi
leaq -0xc8(%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 -0x108(%rbp), %rdi
callq 0x3444
leaq -0x70(%rbp), %rdi
callq 0x304e
leaq -0x138(%rbp), %rdi
callq 0x34ae
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), %r12
leaq -0xb8(%rbp), %r15
leaq -0x50(%rbp), %r13
movq %r14, -0x78(%rbp)
movl $0xa, %esi
callq 0x2150
movsbl %al, %edx
leaq -0x6c0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2516
movq %r12, %rdi
leaq -0xd8(%rbp), %rsi
movl $0x8, %edx
callq 0x2250
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x298(%rbp,%rax)
je 0x26ab
movq %r12, %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
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %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 0x2719
movq -0xb0(%rbp), %rcx
decq %rcx
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2170
leaq -0x98(%rbp), %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2712
callq 0x2140
movb $0x1, %bl
jmp 0x2a0f
testb $0x1, %bl
je 0x2766
callq 0x2220
movl %eax, %r15d
leaq -0x138(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3518
leaq -0x130(%rbp), %rcx
cmpq %rcx, %rax
je 0x2a2d
movq 0x40(%rax), %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x2c5c
movb $0x1, %bl
leaq -0xb8(%rbp), %r15
jmp 0x2a0f
movq %r15, %rdi
leaq 0x18a4(%rip), %rsi      # 0x4014
callq 0x2080
testl %eax, %eax
je 0x2aca
movq -0xb8(%rbp), %rdi
callq 0x2220
testl %eax, %eax
leaq -0x138(%rbp), %r12
jle 0x2890
movl %eax, %r15d
leal -0x1(%r15), %ebx
xorl %r14d, %r14d
movq -0x78(%rbp), %rdi
callq 0x2cf4
movq -0xf8(%rbp), %r8
leaq -0x100(%rbp), %rsi
movq %rsi, %r13
testq %r8, %r8
je 0x2807
movq %rsi, %rcx
movq %r8, %rdx
movq 0x20(%r8), %rdi
xorl %r8d, %r8d
cmpq %rax, %rdi
setb %r8b
movq %rdx, %rsi
cmovbq %rcx, %rsi
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x27c1
leaq -0x100(%rbp), %r8
movq %r8, %r13
cmpq %r8, %rsi
je 0x2807
cmpq %rax, %rdi
cmovbq %rcx, %rdx
cmpq 0x20(%rdx), %rax
cmovbq %r8, %rsi
movq %rsi, %r13
movq 0x28(%r13), %rsi
movq 0x30(%r13), %rdx
leaq -0x4b8(%rbp), %rdi
callq 0x2190
cmpl %ebx, %r14d
je 0x2838
movl $0x1, %edx
leaq -0x4b8(%rbp), %rdi
leaq 0x17e6(%rip), %rsi      # 0x4019
callq 0x2190
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x28(%r13), %rsi
movq 0x30(%r13), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
callq 0x30b4
movq 0x20(%r13), %rax
movq %rax, -0x30(%rbp)
leaq -0x70(%rbp), %rdi
movq %r12, %rsi
callq 0x38f6
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
leaq -0x138(%rbp), %r12
je 0x2884
callq 0x2140
incl %r14d
cmpl %r15d, %r14d
jne 0x27a2
movq -0x70(%rbp), %r15
movq -0x68(%rbp), %r13
cmpq %r15, %r13
je 0x29b9
xorl %ebx, %ebx
xorl %r14d, %r14d
addq %rbx, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x3bbc
leaq -0x50(%rbp), %r13
movq %r12, %rdi
movq %rax, %rsi
callq 0x3c78
movq -0x70(%rbp), %rax
leaq (%rax,%rbx), %rsi
addq $0x20, %rsi
leaq -0x108(%rbp), %rdi
callq 0x3da4
leaq -0x108(%rbp), %rdi
movq %rax, %rsi
callq 0x3e2c
movq -0x70(%rbp), %rax
movq 0x20(%rax,%rbx), %rax
movl 0x4(%rax), %esi
movq -0x78(%rbp), %rdi
callq 0x2bea
movq %rax, %r15
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 %r13, %rdi
callq 0x30b4
movq %r15, -0x30(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x35b6
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2943
callq 0x2140
movq -0x70(%rbp), %rax
movq %r15, -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 0x30b4
leaq -0x108(%rbp), %rdi
movq %r13, %rsi
callq 0x3780
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2989
callq 0x2140
incq %r14
movq -0x70(%rbp), %r15
movq -0x68(%rbp), %r13
movq %r13, %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %rbx
cmpq %r14, %rax
ja 0x28a6
cmpq %r15, %r13
movq -0x78(%rbp), %r14
leaq -0x2b8(%rbp), %r12
je 0x29ea
movq %r15, %rbx
movq (%rbx), %rdi
addq $0x10, %rbx
cmpq %rbx, %rdi
je 0x29dd
callq 0x2140
addq $0x18, %rbx
cmpq %r13, %rbx
jne 0x29cc
movq %r15, -0x68(%rbp)
movl $0x1, %edx
leaq -0x4b8(%rbp), %rdi
leaq 0x161e(%rip), %rsi      # 0x401b
callq 0x2190
xorl %ebx, %ebx
leaq -0xb8(%rbp), %r15
leaq -0x50(%rbp), %r13
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x298(%rbp,%rax)
je 0x26ad
jmp 0x266b
movq %r14, %rdi
movl %r15d, %esi
callq 0x2bea
movq %rax, %r15
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x30b4
movq %r15, -0x30(%rbp)
leaq -0x138(%rbp), %rdi
movq %r13, %rsi
callq 0x35b6
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2a81
callq 0x2140
movq %r15, -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 0x30b4
leaq -0x108(%rbp), %rdi
movq %r13, %rsi
callq 0x3780
leaq -0xb8(%rbp), %r15
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
jmp 0x2708
leaq -0x4b8(%rbp), %rdi
callq 0x21d0
movl $0x1, %edi
callq 0x21b0
jmp 0x2ae2
movq %rax, %rbx
jmp 0x2b6d
jmp 0x2aec
movq %rax, %rbx
jmp 0x2bc1
jmp 0x2b15
jmp 0x2b3f
jmp 0x2b24
jmp 0x2b3f
jmp 0x2b3f
jmp 0x2b3f
jmp 0x2b06
jmp 0x2b3f
jmp 0x2b3f
movq %rax, %rbx
jmp 0x2b61
jmp 0x2b3f
jmp 0x2b3f
jmp 0x2b24
jmp 0x2b3f
jmp 0x2b3f
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
jmp 0x2b2f
jmp 0x2b3f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2b42
callq 0x2140
jmp 0x2b42
jmp 0x2b3f
jmp 0x2b3f
movq %rax, %rbx
movq 0x3487(%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 0x2b85
callq 0x2140
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2b9d
callq 0x2140
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x2bb5
callq 0x2140
leaq -0x4b8(%rbp), %rdi
callq 0x2200
leaq -0x108(%rbp), %rdi
callq 0x3444
leaq -0x70(%rbp), %rdi
callq 0x304e
leaq -0x138(%rbp), %rdi
callq 0x34ae
movq %rbx, %rdi
callq 0x2270