// File: viniciu21[P]sortingAlgorithmsProject/src/main.cpp
// Function: main
int main()
{

	ofstream quickF, bubbleF;
	quickF.open("data/quick.txt");
	bubbleF.open("data/bubble.txt");

	std::random_device r;
	std::default_random_engine e1(r());
	std::uniform_int_distribution<int> uniform_dist(1, 100);

	int quickValues[100], bubbleValues[100];

	for (int i{50}; i < 10000; i += 50)
	{
		int listaBubble[i];
		int listaQuick[i];

		long double quickSortSum{0}, bubbleSortSum{0}, quickSortAverage, bubbleSortAverege;

		for (int k{0}; k < 100; k++)
		{
			for (int j{0}; j < i; j++)
			{
				listaBubble[j] = uniform_dist(e1);
				listaQuick[j] = uniform_dist(e1);
			}

			auto startChrono = chrono::steady_clock::now();

			bubbleSort(listaBubble, (sizeof(listaBubble) / sizeof(listaBubble[i]) - 1));

			auto endChrono = chrono::steady_clock::now();
			auto timeDifference = endChrono - startChrono;

			bubbleValues[k] = chrono::duration<long double, std::milli>(timeDifference).count();

			startChrono = chrono::steady_clock::now();

			quickSort(listaQuick, 0, (sizeof(listaQuick) / sizeof(listaQuick[0])));

			endChrono = chrono::steady_clock::now();
			timeDifference = endChrono - startChrono;

			quickValues[k] = chrono::duration<long double, std::milli>(timeDifference).count();
		}
		for (int z{0}; z < 100; z++)
		{
			quickSortSum += quickValues[z];
			bubbleSortSum += bubbleValues[z];
		}
		bubbleSortAverege = bubbleSortSum / 100;
		quickSortAverage = quickSortSum / 100;

		quickF << quickSortAverage << " "
					 << endl;
		bubbleF << bubbleSortAverege << " "
						<< endl;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c30, %rsp           # imm = 0x1C30
movl $0x0, -0x4(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x21e0
leaq -0x408(%rbp), %rdi
callq 0x21e0
jmp 0x23dc
leaq 0x1c29(%rip), %rsi      # 0x400c
leaq -0x208(%rbp), %rdi
movl $0x10, %edx
callq 0x2030
jmp 0x23f6
leaq 0x1c1e(%rip), %rsi      # 0x401b
leaq -0x408(%rbp), %rdi
movl $0x10, %edx
callq 0x2030
jmp 0x2410
leaq -0x17a0(%rbp), %rdi
callq 0x2990
jmp 0x241e
leaq -0x17a0(%rbp), %rdi
callq 0x2a30
movl %eax, -0x1bb0(%rbp)
jmp 0x2432
movl -0x1bb0(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x17a8(%rbp), %rdi
callq 0x2a50
jmp 0x244a
leaq -0x17b0(%rbp), %rdi
movl $0x1, %esi
movl $0x64, %edx
callq 0x2a80
jmp 0x2462
movl $0x32, -0x1ad4(%rbp)
cmpl $0x2710, -0x1ad4(%rbp)  # imm = 0x2710
jge 0x2930
movl -0x1ad4(%rbp), %eax
movq %rax, -0x1bd0(%rbp)
movq %rsp, %rcx
movq %rcx, -0x1ae0(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1bc8(%rbp)
movq %rcx, %rsp
movq %rax, -0x1ae8(%rbp)
movl -0x1ad4(%rbp), %eax
movq %rax, -0x1bc0(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1bb8(%rbp)
movq %rcx, %rsp
movq %rax, -0x1af0(%rbp)
fldz
fld %st(0)
fstpt -0x1b00(%rbp)
fstpt -0x1b10(%rbp)
movl $0x0, -0x1b34(%rbp)
cmpl $0x64, -0x1b34(%rbp)
jge 0x27c8
movl $0x0, -0x1b38(%rbp)
movl -0x1b38(%rbp), %eax
cmpl -0x1ad4(%rbp), %eax
jge 0x25f2
leaq -0x17b0(%rbp), %rdi
leaq -0x17a8(%rbp), %rsi
callq 0x2ab0
movl %eax, -0x1bd4(%rbp)
jmp 0x2544
movq -0x1bc8(%rbp), %rax
movl -0x1bd4(%rbp), %edx
movslq -0x1b38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
leaq -0x17b0(%rbp), %rdi
leaq -0x17a8(%rbp), %rsi
callq 0x2ab0
movl %eax, -0x1bd8(%rbp)
jmp 0x2576
movq -0x1bb8(%rbp), %rax
movl -0x1bd8(%rbp), %edx
movslq -0x1b38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1b38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b38(%rbp)
jmp 0x2517
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x410(%rbp)
movl %eax, -0x414(%rbp)
jmp 0x296f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x410(%rbp)
movl %eax, -0x414(%rbp)
jmp 0x2963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x410(%rbp)
movl %eax, -0x414(%rbp)
leaq -0x17a0(%rbp), %rdi
callq 0x2b80
jmp 0x2963
callq 0x2170
movq -0x1bc8(%rbp), %rdi
movq %rax, %rcx
movq -0x1bd0(%rbp), %rax
movq %rcx, -0x1b40(%rbp)
movl %eax, %esi
decl %esi
callq 0x33d0
jmp 0x261a
callq 0x2170
movq %rax, -0x1b48(%rbp)
leaq -0x1b48(%rbp), %rdi
leaq -0x1b40(%rbp), %rsi
callq 0x2ae0
movq %rax, -0x1be0(%rbp)
jmp 0x2642
movq -0x1be0(%rbp), %rax
movq %rax, -0x1b50(%rbp)
leaq -0x1b60(%rbp), %rdi
leaq -0x1b50(%rbp), %rsi
callq 0x2b30
jmp 0x2665
leaq -0x1b60(%rbp), %rdi
callq 0x2b70
fstpt -0x1bec(%rbp)
jmp 0x2679
fldt -0x1bec(%rbp)
fnstcw -0x1ba6(%rbp)
movzwl -0x1ba6(%rbp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, -0x1ba8(%rbp)
fldcw -0x1ba8(%rbp)
fistpl -0x1ba0(%rbp)
fldcw -0x1ba6(%rbp)
movl -0x1ba0(%rbp), %ecx
movslq -0x1b34(%rbp), %rax
movl %ecx, -0x1ad0(%rbp,%rax,4)
callq 0x2170
movq -0x1bb8(%rbp), %rdi
movq %rax, %rcx
movq -0x1bc0(%rbp), %rax
movq %rcx, -0x1b68(%rbp)
movq -0x1b68(%rbp), %rcx
movq %rcx, -0x1b40(%rbp)
movl %eax, %edx
xorl %esi, %esi
callq 0x3570
jmp 0x26f4
callq 0x2170
movq %rax, -0x1b70(%rbp)
movq -0x1b70(%rbp), %rax
movq %rax, -0x1b48(%rbp)
leaq -0x1b48(%rbp), %rdi
leaq -0x1b40(%rbp), %rsi
callq 0x2ae0
movq %rax, -0x1bf8(%rbp)
jmp 0x272a
movq -0x1bf8(%rbp), %rax
movq %rax, -0x1b78(%rbp)
movq -0x1b78(%rbp), %rax
movq %rax, -0x1b50(%rbp)
leaq -0x1b90(%rbp), %rdi
leaq -0x1b50(%rbp), %rsi
callq 0x2b30
jmp 0x275b
leaq -0x1b90(%rbp), %rdi
callq 0x2b70
fstpt -0x1c04(%rbp)
jmp 0x276f
fldt -0x1c04(%rbp)
fnstcw -0x1baa(%rbp)
movzwl -0x1baa(%rbp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, -0x1bac(%rbp)
fldcw -0x1bac(%rbp)
fistpl -0x1ba4(%rbp)
fldcw -0x1baa(%rbp)
movl -0x1ba4(%rbp), %ecx
movslq -0x1b34(%rbp), %rax
movl %ecx, -0x1940(%rbp,%rax,4)
movl -0x1b34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b34(%rbp)
jmp 0x2500
movl $0x0, -0x1b94(%rbp)
cmpl $0x64, -0x1b94(%rbp)
jge 0x283c
movslq -0x1b94(%rbp), %rax
movl -0x1940(%rbp,%rax,4), %eax
movl %eax, -0x1b9c(%rbp)
fildl -0x1b9c(%rbp)
fldt -0x1b00(%rbp)
faddp %st, %st(1)
fstpt -0x1b00(%rbp)
movslq -0x1b94(%rbp), %rax
movl -0x1ad0(%rbp,%rax,4), %eax
movl %eax, -0x1b98(%rbp)
fildl -0x1b98(%rbp)
fldt -0x1b10(%rbp)
faddp %st, %st(1)
fstpt -0x1b10(%rbp)
movl -0x1b94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b94(%rbp)
jmp 0x27d2
fldt -0x1b10(%rbp)
flds 0x17bc(%rip)            # 0x4004
fdivr %st, %st(1)
fxch %st(1)
fstpt -0x1b30(%rbp)
fldt -0x1b00(%rbp)
fdivp %st, %st(1)
fstpt -0x1b20(%rbp)
fldt -0x1b20(%rbp)
subq $0x10, %rsp
movq %rsp, %rax
fstpt (%rax)
leaq -0x208(%rbp), %rdi
callq 0x2150
addq $0x10, %rsp
movq %rax, -0x1c10(%rbp)
jmp 0x2888
movq -0x1c10(%rbp), %rdi
leaq 0x1795(%rip), %rsi      # 0x402b
callq 0x20f0
movq %rax, -0x1c18(%rbp)
jmp 0x28a4
movq -0x1c18(%rbp), %rdi
movq 0x371e(%rip), %rsi      # 0x5fd0
callq 0x2100
jmp 0x28b9
fldt -0x1b30(%rbp)
subq $0x10, %rsp
movq %rsp, %rax
fstpt (%rax)
leaq -0x408(%rbp), %rdi
callq 0x2150
addq $0x10, %rsp
movq %rax, -0x1c20(%rbp)
jmp 0x28e1
movq -0x1c20(%rbp), %rdi
leaq 0x173c(%rip), %rsi      # 0x402b
callq 0x20f0
movq %rax, -0x1c28(%rbp)
jmp 0x28fd
movq -0x1c28(%rbp), %rdi
movq 0x36c5(%rip), %rsi      # 0x5fd0
callq 0x2100
jmp 0x2912
movq -0x1ae0(%rbp), %rax
movq %rax, %rsp
movl -0x1ad4(%rbp), %eax
addl $0x32, %eax
movl %eax, -0x1ad4(%rbp)
jmp 0x246c
movl $0x0, -0x4(%rbp)
leaq -0x17a0(%rbp), %rdi
callq 0x2b80
leaq -0x408(%rbp), %rdi
callq 0x21a0
leaq -0x208(%rbp), %rdi
callq 0x21a0
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0x408(%rbp), %rdi
callq 0x21a0
leaq -0x208(%rbp), %rdi
callq 0x21a0
movq -0x410(%rbp), %rdi
callq 0x21f0
nopw (%rax,%rax)