// File: 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
subq $0x8f0, %rsp            # imm = 0x8F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jne 0x2de6
leaq -0x40(%rbp), %rdi
callq 0x2e10
leaq -0x48(%rbp), %rdi
callq 0x2e30
leaq -0x60(%rbp), %rdi
callq 0x2e50
leaq -0x90(%rbp), %rdi
callq 0x2e70
leaq -0x98(%rbp), %rdi
callq 0x2e90
movb $0x0, -0x99(%rbp)
movl $0x8, %edi
callq 0x21b0
movq %rax, -0x818(%rbp)
jmp 0x24b0
movq -0x818(%rbp), %rdi
callq 0x2eb0
jmp 0x24be
movq -0x818(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x22b0
jmp 0x24da
leaq -0x2d8(%rbp), %rdi
callq 0x2220
leaq -0x2f8(%rbp), %rdi
callq 0x2220
leaq -0x318(%rbp), %rdi
callq 0x2220
leaq 0x6aff(%rip), %rsi      # 0x9004
leaq -0x2b8(%rbp), %rdi
movl $0x10, %edx
callq 0x2040
jmp 0x2518
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x520(%rbp), %rdi
movl $0x8, %edx
callq 0x22d0
jmp 0x2533
jmp 0x2535
movq -0x520(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x520(%rbp,%rax), %rdi
callq 0x2210
movb %al, -0x819(%rbp)
jmp 0x2555
movb -0x819(%rbp), %al
testb $0x1, %al
jne 0x2564
jmp 0x2d2e
movb $0x0, -0x99(%rbp)
leaq -0x520(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x2060
movq %rax, -0x828(%rbp)
jmp 0x2587
movq -0x828(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20e0
movb %al, -0x829(%rbp)
jmp 0x25a5
movb -0x829(%rbp), %al
testb $0x1, %al
jne 0x25b1
jmp 0x261e
jmp 0x2d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2dc6
movq -0x818(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x2190
jmp 0x2dc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2d96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2d8a
leaq -0x6a0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
movl $0x8, %edx
callq 0x22a0
jmp 0x2638
jmp 0x263a
movq -0x6a0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x6a0(%rbp,%rax), %rdi
callq 0x2210
movb %al, -0x82a(%rbp)
jmp 0x265a
movb -0x82a(%rbp), %al
testb $0x1, %al
jne 0x2669
jmp 0x2d0f
leaq -0x6a0(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
movl $0x20, %edx
callq 0x22e0
movq %rax, -0x838(%rbp)
jmp 0x268a
movq -0x838(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20e0
movb %al, -0x839(%rbp)
jmp 0x26a8
movb -0x839(%rbp), %al
testb $0x1, %al
jne 0x26b4
jmp 0x26d0
jmp 0x2d0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2d20
xorl %eax, %eax
movl %eax, %esi
leaq -0x2f8(%rbp), %rdi
callq 0x22f0
movq %rax, -0x848(%rbp)
jmp 0x26e9
movq -0x848(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0x2756
leaq -0x2f8(%rbp), %rdi
movq %rdi, -0x850(%rbp)
callq 0x2150
movq -0x850(%rbp), %rsi
movq %rax, %rcx
decq %rcx
leaq -0x6c0(%rbp), %rdi
movl $0x1, %edx
callq 0x21c0
jmp 0x272b
leaq -0x318(%rbp), %rdi
leaq -0x6c0(%rbp), %rsi
callq 0x2200
leaq -0x6c0(%rbp), %rdi
callq 0x2130
movb $0x1, -0x99(%rbp)
jmp 0x2d0a
testb $0x1, -0x99(%rbp)
je 0x2944
leaq -0x2f8(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2270
movl %eax, -0x6c4(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x2ed0
movq %rax, -0x858(%rbp)
jmp 0x2796
movq -0x858(%rbp), %rax
movq %rax, -0x6d0(%rbp)
movq -0x6d0(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2f30
movq %rax, -0x6d8(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x6d8(%rbp), %rsi
callq 0x2f00
testb $0x1, %al
jne 0x27d8
jmp 0x290e
movq -0xa8(%rbp), %rdi
movl -0x6c4(%rbp), %esi
callq 0x2f60
movq %rax, -0x860(%rbp)
jmp 0x27f3
movq -0x860(%rbp), %rax
movq %rax, -0x6e0(%rbp)
leaq -0x708(%rbp), %rdi
leaq -0x318(%rbp), %rsi
leaq -0x6e0(%rbp), %rdx
callq 0x30c0
jmp 0x281d
leaq -0x40(%rbp), %rdi
leaq -0x708(%rbp), %rsi
callq 0x3080
movb %dl, -0x869(%rbp)
movq %rax, -0x868(%rbp)
jmp 0x283c
movb -0x869(%rbp), %al
movq -0x868(%rbp), %rcx
movq %rcx, -0x718(%rbp)
movb %al, -0x710(%rbp)
leaq -0x708(%rbp), %rdi
callq 0x3100
leaq -0x740(%rbp), %rdi
leaq -0x6e0(%rbp), %rsi
leaq -0x318(%rbp), %rdx
callq 0x3160
jmp 0x287e
leaq -0x90(%rbp), %rdi
leaq -0x740(%rbp), %rsi
callq 0x3120
movb %dl, -0x879(%rbp)
movq %rax, -0x878(%rbp)
jmp 0x28a0
movb -0x879(%rbp), %al
movq -0x878(%rbp), %rcx
movq %rcx, -0x750(%rbp)
movb %al, -0x748(%rbp)
leaq -0x740(%rbp), %rdi
callq 0x31a0
jmp 0x293f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x708(%rbp), %rdi
callq 0x3100
jmp 0x2d20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x740(%rbp), %rdi
callq 0x31a0
jmp 0x2d20
movq -0xa8(%rbp), %rax
movq %rax, -0x888(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3350
movq -0x888(%rbp), %rdi
movq 0x20(%rax), %rsi
movl -0x6c4(%rbp), %edx
callq 0x31c0
jmp 0x293d
jmp 0x293f
jmp 0x2d08
leaq 0x66c9(%rip), %rsi      # 0x9014
leaq -0x2f8(%rbp), %rdi
callq 0x3370
movb %al, -0x889(%rbp)
jmp 0x295f
movb -0x889(%rbp), %al
testb $0x1, %al
jne 0x296b
jmp 0x2983
leaq -0x2b8(%rbp), %rdi
callq 0x2230
jmp 0x2979
movl $0x1, %edi
callq 0x21f0
leaq -0x2f8(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2270
movl %eax, -0x754(%rbp)
movl $0x0, -0x758(%rbp)
movl -0x758(%rbp), %eax
cmpl -0x754(%rbp), %eax
jge 0x2af6
movq -0xa8(%rbp), %rdi
callq 0x33a0
movq %rax, -0x898(%rbp)
jmp 0x29ce
movq -0x898(%rbp), %rax
movq %rax, -0x760(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x760(%rbp), %rsi
callq 0x3bf0
movq %rax, -0x8a0(%rbp)
jmp 0x29f8
movq -0x8a0(%rbp), %rax
movq %rax, -0x768(%rbp)
movq -0x768(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3c20
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x2b8(%rbp), %rdi
callq 0x2180
jmp 0x2a35
movl -0x758(%rbp), %eax
movl -0x754(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x2a5f
leaq 0x65ca(%rip), %rsi      # 0x9019
leaq -0x2b8(%rbp), %rdi
callq 0x21a0
jmp 0x2a5d
jmp 0x2a5f
leaq -0x98(%rbp), %rdi
movq %rdi, -0x8b0(%rbp)
callq 0x3c20
movq -0x8b0(%rbp), %rdi
addq $0x8, %rax
movq %rax, -0x8a8(%rbp)
callq 0x3c20
movq -0x8a8(%rbp), %rsi
movq %rax, %rdx
leaq -0x790(%rbp), %rdi
callq 0x3c70
jmp 0x2aa1
leaq -0x60(%rbp), %rdi
leaq -0x790(%rbp), %rsi
callq 0x3c40
jmp 0x2ab3
leaq -0x790(%rbp), %rdi
callq 0x3cb0
movl -0x758(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x758(%rbp)
jmp 0x29a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x790(%rbp), %rdi
callq 0x3cb0
jmp 0x2d20
movl $0x0, -0x794(%rbp)
movslq -0x794(%rbp), %rax
movq %rax, -0x8b8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3cd0
movq %rax, %rcx
movq -0x8b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2ce6
movslq -0x794(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3d00
jmp 0x2b48
movslq -0x794(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x90(%rbp), %rdi
callq 0x3d50
jmp 0x2b6d
movq -0xa8(%rbp), %rax
movq %rax, -0x8c8(%rbp)
movslq -0x794(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq -0x8c8(%rbp), %rdi
movq 0x20(%rax), %rax
movl 0x4(%rax), %esi
callq 0x2f60
movq %rax, -0x8c0(%rbp)
jmp 0x2ba7
movq -0x8c0(%rbp), %rax
movq %rax, -0x7a0(%rbp)
movslq -0x794(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq %rax, %rsi
leaq -0x7c8(%rbp), %rdi
leaq -0x7a0(%rbp), %rdx
callq 0x30c0
jmp 0x2bdd
leaq -0x40(%rbp), %rdi
leaq -0x7c8(%rbp), %rsi
callq 0x3080
movb %dl, -0x8d1(%rbp)
movq %rax, -0x8d0(%rbp)
jmp 0x2bfc
movb -0x8d1(%rbp), %al
movq -0x8d0(%rbp), %rcx
movq %rcx, -0x7d8(%rbp)
movb %al, -0x7d0(%rbp)
leaq -0x7c8(%rbp), %rdi
callq 0x3100
movslq -0x794(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq %rax, %rdx
leaq -0x800(%rbp), %rdi
leaq -0x7a0(%rbp), %rsi
callq 0x3160
jmp 0x2c4a
leaq -0x90(%rbp), %rdi
leaq -0x800(%rbp), %rsi
callq 0x3120
movb %dl, -0x8e1(%rbp)
movq %rax, -0x8e0(%rbp)
jmp 0x2c6c
movb -0x8e1(%rbp), %al
movq -0x8e0(%rbp), %rcx
movq %rcx, -0x810(%rbp)
movb %al, -0x808(%rbp)
leaq -0x800(%rbp), %rdi
callq 0x31a0
movl -0x794(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x794(%rbp)
jmp 0x2b00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x7c8(%rbp), %rdi
callq 0x3100
jmp 0x2d20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x800(%rbp), %rdi
callq 0x31a0
jmp 0x2d20
leaq -0x60(%rbp), %rdi
callq 0x3d80
leaq 0x6325(%rip), %rsi      # 0x901b
leaq -0x2b8(%rbp), %rdi
callq 0x21a0
jmp 0x2d04
jmp 0x2d06
jmp 0x2d08
jmp 0x2d0a
jmp 0x263a
leaq -0x6a0(%rbp), %rdi
callq 0x20f0
jmp 0x2535
leaq -0x6a0(%rbp), %rdi
callq 0x20f0
jmp 0x2d8a
leaq -0x520(%rbp), %rdi
callq 0x2070
leaq -0x318(%rbp), %rdi
callq 0x2130
leaq -0x2f8(%rbp), %rdi
callq 0x2130
leaq -0x2d8(%rbp), %rdi
callq 0x2130
leaq -0x2b8(%rbp), %rdi
callq 0x2250
leaq -0x90(%rbp), %rdi
callq 0x3da0
leaq -0x60(%rbp), %rdi
callq 0x3dc0
leaq -0x40(%rbp), %rdi
callq 0x3e20
jmp 0x2df9
leaq -0x520(%rbp), %rdi
callq 0x2070
leaq -0x318(%rbp), %rdi
callq 0x2130
leaq -0x2f8(%rbp), %rdi
callq 0x2130
leaq -0x2d8(%rbp), %rdi
callq 0x2130
leaq -0x2b8(%rbp), %rdi
callq 0x2250
leaq -0x90(%rbp), %rdi
callq 0x3da0
leaq -0x60(%rbp), %rdi
callq 0x3dc0
leaq -0x40(%rbp), %rdi
callq 0x3e20
jmp 0x2e04
movq 0xb1eb(%rip), %rdi      # 0xdfd8
leaq 0x6229(%rip), %rsi      # 0x901d
callq 0x21a0
xorl %eax, %eax
addq $0x8f0, %rsp            # imm = 0x8F0
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x22c0