// File: /workspace/github_cpp_makefile_star2_O2/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 $0x6a8, %rsp            # imm = 0x6A8
cmpl $0x2, %edi
jne 0x2815
movq %rsi, %r14
leaq -0xe8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
andq $0x0, -0x30(%rbp)
leaq -0x138(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
pushq $0x8
popq %rdi
callq 0x2160
movq %rax, %r15
andq $0x0, (%rax)
leaq -0x4c0(%rbp), %rdi
callq 0x2260
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq -0x88(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x1b6a(%rip), %rsi      # 0x4004
leaq -0x4c0(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x2040
movq 0x8(%r14), %rsi
leaq -0x6c8(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2280
leaq -0x70(%rbp), %r12
movq %r15, -0x78(%rbp)
movq -0x6c8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x6a8(%rbp,%rax)
jne 0x282a
leaq -0x6c8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x282a
leaq -0x2c0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x2250
xorl %ebx, %ebx
movq -0x2c0(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x2a0(%rbp,%rax)
jne 0x2804
leaq -0x2c0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
pushq $0x20
popq %rdx
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2804
movq -0x98(%rbp), %rdi
cmpb $0x24, (%rdi)
jne 0x25a1
movq -0x90(%rbp), %rcx
decq %rcx
movq %r12, %rdi
leaq -0x98(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x2170
leaq -0xc0(%rbp), %rdi
movq %r12, %rsi
callq 0x21b0
movq %r12, %rdi
callq 0x20c0
movb $0x1, %bl
jmp 0x251a
testb $0x1, %bl
je 0x25e7
callq 0x2220
movl %eax, %r14d
leaq -0xf0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x32fc
leaq -0xe8(%rbp), %rcx
cmpq %rcx, %rax
je 0x27a0
movq 0x40(%rax), %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x29e0
movb $0x1, %bl
jmp 0x251a
leaq -0x98(%rbp), %rdi
leaq 0x1a1f(%rip), %rsi      # 0x4014
callq 0x2a72
testb %al, %al
jne 0x289b
movq -0x98(%rbp), %rdi
callq 0x2220
movl %eax, %r14d
leal -0x1(%r14), %eax
movl %eax, -0x44(%rbp)
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
cmpl %r15d, %r14d
je 0x26af
movq -0x78(%rbp), %rdi
callq 0x2a82
movq %rax, -0xa0(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3796
movq %rax, %rbx
leaq 0x28(%rax), %r13
leaq -0x4c0(%rbp), %rdi
movq %r13, %rsi
callq 0x2130
cmpl %r15d, -0x44(%rbp)
je 0x267d
leaq -0x4c0(%rbp), %rdi
leaq 0x19a1(%rip), %rsi      # 0x4019
callq 0x2150
addq $0x20, %rbx
leaq -0x70(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x31b4
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x37f2
movq %r12, %rdi
callq 0x20c0
incl %r15d
jmp 0x2622
xorl %r12d, %r12d
xorl %r13d, %r13d
movq -0x78(%rbp), %r15
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %r13, %rax
jbe 0x2779
addq %r12, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x3a02
movq -0x40(%rbp), %rax
leaq (%rax,%r12), %rsi
addq $0x20, %rsi
leaq -0x140(%rbp), %rdi
callq 0x3be6
movq -0x40(%rbp), %rax
movq 0x20(%rax,%r12), %rax
movl 0x4(%rax), %esi
movq %r15, %rdi
callq 0x2974
movq %rax, %r14
movq -0x40(%rbp), %rsi
addq %r12, %rsi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x21d0
movq %r14, -0x50(%rbp)
leaq -0xf0(%rbp), %rdi
movq %rbx, %rsi
callq 0x339c
movq %rbx, %rdi
callq 0x20c0
movq -0x40(%rbp), %rsi
addq %r12, %rsi
movq %r14, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x21d0
leaq -0x140(%rbp), %rdi
movq %rbx, %rsi
callq 0x35e2
leaq -0x68(%rbp), %rdi
callq 0x20c0
incq %r13
addq $0x28, %r12
jmp 0x26b9
leaq -0x40(%rbp), %rdi
callq 0x2d14
xorl %ebx, %ebx
leaq -0x4c0(%rbp), %rdi
leaq 0x1889(%rip), %rsi      # 0x401b
callq 0x2150
leaq -0x70(%rbp), %r12
jmp 0x251a
movq %r15, %rdi
movl %r14d, %esi
callq 0x2974
movq %rax, %r14
movq %r12, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x21d0
movq %r14, -0x50(%rbp)
leaq -0xf0(%rbp), %rdi
movq %r12, %rsi
callq 0x339c
movq %r12, %rdi
callq 0x20c0
movq %r14, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x21d0
leaq -0x140(%rbp), %rdi
movq %r12, %rsi
callq 0x35e2
leaq -0x68(%rbp), %rdi
jmp 0x2595
leaq -0x2c0(%rbp), %rdi
callq 0x20d0
jmp 0x24c4
movq 0x47bc(%rip), %rdi      # 0x6fd8
leaq 0x17fa(%rip), %rsi      # 0x401d
callq 0x2150
jmp 0x2887
leaq -0x6c8(%rbp), %rdi
callq 0x2070
leaq -0xc0(%rbp), %rdi
callq 0x20c0
leaq -0x98(%rbp), %rdi
callq 0x20c0
leaq -0x110(%rbp), %rdi
callq 0x20c0
leaq -0x4c0(%rbp), %rdi
callq 0x2200
leaq -0x140(%rbp), %rdi
callq 0x31d2
leaq -0x40(%rbp), %rdi
callq 0x2d22
leaq -0xf0(%rbp), %rdi
callq 0x324a
xorl %eax, %eax
addq $0x6a8, %rsp            # imm = 0x6A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x4c0(%rbp), %rdi
callq 0x21e0
pushq $0x1
popq %rdi
callq 0x21a0
jmp 0x28b1
movq %rax, %rbx
jmp 0x291b
jmp 0x28b8
movq %rax, %rbx
jmp 0x294b
jmp 0x28c2
movq %rax, %rbx
jmp 0x290f
jmp 0x2900
jmp 0x28dd
jmp 0x2900
jmp 0x28ee
jmp 0x2900
jmp 0x2900
jmp 0x2900
jmp 0x2900
jmp 0x2900
jmp 0x2900
jmp 0x2900
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x28f5
jmp 0x28ee
jmp 0x2900
jmp 0x2900
jmp 0x2900
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20c0
jmp 0x2903
jmp 0x2900
jmp 0x2900
movq %rax, %rbx
leaq -0x2c0(%rbp), %rdi
callq 0x20d0
leaq -0x6c8(%rbp), %rdi
callq 0x2070
leaq -0xc0(%rbp), %rdi
callq 0x20c0
leaq -0x98(%rbp), %rdi
callq 0x20c0
leaq -0x110(%rbp), %rdi
callq 0x20c0
leaq -0x4c0(%rbp), %rdi
callq 0x2200
leaq -0x140(%rbp), %rdi
callq 0x31d2
leaq -0x40(%rbp), %rdi
callq 0x2d22
leaq -0xf0(%rbp), %rdi
callq 0x324a
movq %rbx, %rdi
callq 0x2270