// File: /workspace/github_cpp_makefile_star2_O2/Manca[P]algorithms1/main.cpp
// Function: main
int main(int argc, const char * argv[]) {

    /*** Assignment 1 test cases ***/
    // TEST CASE 1:
    cout << "*** Assignment 1 - Test Case 1 ***" << endl;
    std::vector<int> vec{4, 5, 6, 1, 3};
    
    long long inversions = assignment1::Count(vec);
    
    cout << "Number of inversions is: " << inversions << endl;
    
    // TEST CASE 2:
    // load file
    cout << "*** Assignment 1 - Test Case 2 ***" << endl;
    std::ifstream inputFile("data/IntegerArray.txt", ios::in);
    std::vector<int> fileNumbers;

    // fill it in with numbers from the file
    if (inputFile.is_open())
    {
        int number;
        while (inputFile >> number)
        {
            fileNumbers.push_back(number);
        }
        inputFile.close();
        // do the work
        long long variations = assignment1::Count(fileNumbers);
        cout << "Total number of inversions is: " << variations << endl;
        assert(variations == 2407905288);
    }
    else
    {
        cout << "File cannot be opened!" << endl;
    }
    
    /*** Assignment 2 test cases ***/
    // TEST CASE 1:
    cout << endl << "*** Assignment 2 - Test Case 1 ***" << endl;
    ifstream as2File("data/QuickSort.txt", ios::in);
    vector<int> as2Input;
    
    if (as2File.is_open())
    {
        int number;
        while (as2File >> number)
        {
            as2Input.push_back(number);
        }
        as2File.close();
        
        // create three copies for each algorithm (input array is mutable)
        vector<int> as2Input1 = as2Input;
        vector<int> as2Input2 = as2Input;
        vector<int> as2Input3 = as2Input;
        
        // do the work
        assignment2::QuickSort(as2Input1, 0, (int)as2Input1.size(), 1);
        assignment2::QuickSort(as2Input2, 0, (int)as2Input2.size(), 2);
        assignment2::QuickSort(as2Input3, 0, (int)as2Input3.size(), 3);
        
        cout << "Number of comparisons for first pivot: " << assignment2::noCompFirst << endl;
        cout << "Number of comparisons for last pivot: " << assignment2::noCompLast << endl;
        cout << "Number of comparisons for median pivot: " << assignment2::noCompMedian << endl;
        
        assert(assignment2::noCompFirst == 162085);
        assert(assignment2::noCompLast == 164123);
        assert(assignment2::noCompMedian == 138382);
    }
    else
    {
        cout << "File cannot be opened!" << endl;
    }
    
    /*** Assignment 3 test cases ***/
    cout << endl << "*** Assignment 3 - Test Case 1 ***" << endl;
    assignment3::Graph graph("data/kargerMinCut.txt");
    for (int i = 0; i < 10; i++)
    {
        cout << "MinCut so far: " << graph.mincut() << endl;
    }
    
    // Min-Cut for this graph is 17, if we don't get exactly 17,
    // we might need to increase number of iterations above
    //assert(graph.mincut() == 17);
    
    /*** Assignment 4 test cases ***/
    cout << endl << "*** Assignment 4 - Test Case 1 ***" << endl;
    assignment4::testCase1();
    cout << "*** Assignment 4 - Test Case 2 ***" << endl;
    assignment4::testCase2();
    
    cout << "*** Assignment 4 - Main Test Case (disabled) ***" << endl;
    /**** Takes too much time... Enable when needed ****
    *
    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
    assignment4::computeSCC("data/SCC.txt");
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
    std::cout << "Total time assignment4 main case took to run: "
    << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
    << "ms.\n";
    *
    ****/
    
    /*** Assignment 5 test cases ***/
    cout << endl << "*** Assignment 5 - Test Case 1 ***" << endl;
    assignment5::loadGraphAndInit("data/dijkstraData.txt");
    assignment5::computeShortestPaths();
    
    /*** Assignment 6 test cases ***/
    // 6.1) 2-SUM Problem
    cout << endl << "*** Assignment 6 - Problem 1 ***" << endl;
    long long sums = assignment6::computeTargetSums("data/algo1-programming_prob-2sum.txt");
    cout << "Number of sums is: " << sums << endl;
    
    // 6.2) Median Maintenance
    cout << endl << "*** Assignment 6 - Problem 2 ***" << endl;
    int sumOfMedians = assignment6::computeSumOfMedians("data/Median.txt") % 10000;
    std::cout << "The sum of medians mod 10000 is: " << sumOfMedians << std::endl;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x500, %rsp            # imm = 0x500
movq 0x9706(%rip), %rdi      # 0xdfd8
leaq 0x4b03(%rip), %rsi      # 0x93dc
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movups 0x4f77(%rip), %xmm0     # 0x9864
leaq 0x2f0(%rsp), %rsi
movaps %xmm0, (%rsi)
movl $0x3, 0x10(%rsi)
leaq 0xd0(%rsp), %rbx
pushq $0x5
popq %rdx
leaq 0xe8(%rsp), %rcx
movq %rbx, %rdi
callq 0x5302
movq %rbx, %rdi
callq 0x265c
movq %rax, %rbx
movq 0x96ac(%rip), %rdi      # 0xdfd8
leaq 0x4acc(%rip), %rsi      # 0x93ff
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20b0
movq %rax, %rdi
callq 0x2100
movq 0x9686(%rip), %rdi      # 0xdfd8
leaq 0x4ac0(%rip), %rsi      # 0x9419
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x4acf(%rip), %rsi      # 0x943c
leaq 0x2f0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2300
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
leaq 0x368(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x49d7
leaq 0x2f0(%rsp), %rbx
leaq 0xe8(%rsp), %r14
leaq 0x50(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x49f4
movq %r15, %rdi
movq %r14, %rsi
callq 0x4ffc
jmp 0x49b1
movq 0x95fa(%rip), %rdi      # 0xdfd8
leaq 0x4acc(%rip), %rsi      # 0x94b1
callq 0x21d0
movq %rax, %rdi
callq 0x2100
jmp 0x4a42
leaq 0x2f0(%rsp), %rdi
callq 0x2060
leaq 0x50(%rsp), %rdi
callq 0x265c
movq %rax, %rbx
movq 0x95c3(%rip), %rdi      # 0xdfd8
leaq 0x4a36(%rip), %rsi      # 0x9452
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20b0
movq %rax, %rdi
callq 0x2100
movl $0x8f85b808, %eax       # imm = 0x8F85B808
cmpq %rax, %rbx
jne 0x4ec9
movq 0x958f(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x4a73(%rip), %rsi      # 0x94c8
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x4a7f(%rip), %rsi      # 0x94eb
leaq 0xe8(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2300
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x4ad3
leaq 0xe8(%rsp), %rbx
leaq 0x74(%rsp), %r14
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4af3
movq %r15, %rdi
movq %r14, %rsi
callq 0x4ffc
jmp 0x4aad
movq 0x94fe(%rip), %rdi      # 0xdfd8
leaq 0x49d0(%rip), %rsi      # 0x94b1
callq 0x21d0
movq %rax, %rdi
callq 0x2100
jmp 0x4c3e
leaq 0xe8(%rsp), %rdi
callq 0x2060
leaq 0x78(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5338
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x5338
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5338
leaq 0x78(%rsp), %rdi
movq 0x8(%rdi), %rdx
subq (%rdi), %rdx
shrq $0x2, %rdx
pushq $0x1
popq %rcx
xorl %esi, %esi
callq 0x284b
movq %rsp, %rdi
movq 0x8(%rdi), %rdx
subq (%rdi), %rdx
shrq $0x2, %rdx
pushq $0x2
popq %rcx
xorl %esi, %esi
callq 0x284b
leaq 0x38(%rsp), %rdi
movq 0x8(%rdi), %rdx
subq (%rdi), %rdx
shrq $0x2, %rdx
pushq $0x3
popq %rcx
xorl %esi, %esi
callq 0x284b
movq 0x945a(%rip), %rdi      # 0xdfd8
leaq 0x4979(%rip), %rsi      # 0x94fe
callq 0x21d0
movl 0x9624(%rip), %esi      # 0xe1b4
movq %rax, %rdi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
movq 0x9431(%rip), %rdi      # 0xdfd8
leaq 0x4978(%rip), %rsi      # 0x9526
callq 0x21d0
movl 0x95ff(%rip), %esi      # 0xe1b8
movq %rax, %rdi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
movq 0x9408(%rip), %rdi      # 0xdfd8
leaq 0x4976(%rip), %rsi      # 0x954d
callq 0x21d0
movl 0x95da(%rip), %esi      # 0xe1bc
movq %rax, %rdi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
cmpl $0x27925, 0x95b8(%rip)  # imm = 0x27925
jne 0x4ee2
cmpl $0x2811b, 0x95ac(%rip)  # imm = 0x2811B
jne 0x4efb
cmpl $0x21c8e, 0x95a0(%rip)  # imm = 0x21C8E
jne 0x4f14
leaq 0x38(%rsp), %rdi
callq 0x606a
movq %rsp, %rdi
callq 0x606a
leaq 0x78(%rsp), %rdi
callq 0x606a
movq 0x9393(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x498e(%rip), %rsi      # 0x95df
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x499a(%rip), %rsi      # 0x9602
leaq 0xb0(%rsp), %rdi
movq %rsp, %rdx
callq 0x20c0
leaq 0x78(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x5386
leaq 0xb0(%rsp), %rdi
callq 0x20e0
pushq $0xa
popq %rbp
movq 0x9337(%rip), %rbx      # 0xdfd8
leaq 0x4970(%rip), %r14      # 0x9618
leaq 0x78(%rsp), %r15
subl $0x1, %ebp
jb 0x4cdc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21d0
movq %rax, %r12
movq %r15, %rdi
callq 0x556a
movq %r12, %rdi
movl %eax, %esi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
jmp 0x4cad
movq 0x92f5(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x4939(%rip), %rsi      # 0x9628
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
callq 0x2b9d
movq 0x92cd(%rip), %rdi      # 0xdfd8
leaq 0x4939(%rip), %rsi      # 0x964b
callq 0x21d0
movq %rax, %rdi
callq 0x2100
callq 0x323c
movq 0x92ad(%rip), %rdi      # 0xdfd8
leaq 0x493c(%rip), %rsi      # 0x966e
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x9292(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x494d(%rip), %rsi      # 0x969f
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x4959(%rip), %rsi      # 0x96c2
movq %rsp, %rdi
leaq 0x38(%rsp), %rdx
callq 0x20c0
movq %rsp, %rdi
callq 0x3ef3
movq %rsp, %rdi
callq 0x20e0
callq 0x40de
movq 0x9246(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x493a(%rip), %rsi      # 0x96d8
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x4944(%rip), %rsi      # 0x96f9
movq %rsp, %rdi
leaq 0x38(%rsp), %rdx
callq 0x20c0
movq %rsp, %rdi
callq 0x436a
movl %eax, %ebx
movq %rsp, %rdi
callq 0x20e0
movq 0x91fd(%rip), %rdi      # 0xdfd8
leaq 0x493c(%rip), %rsi      # 0x971e
callq 0x21d0
movslq %ebx, %rsi
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
callq 0x2100
movq 0x91d7(%rip), %rdi      # 0xdfd8
callq 0x2100
leaq 0x4925(%rip), %rsi      # 0x9732
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq 0x492f(%rip), %rsi      # 0x9753
movq %rsp, %rdi
leaq 0x38(%rsp), %rdx
callq 0x20c0
movq %rsp, %rdi
callq 0x4673
movl %eax, %ebx
movq %rsp, %rdi
callq 0x20e0
movq 0x918e(%rip), %rdi      # 0xdfd8
leaq 0x4912(%rip), %rsi      # 0x9763
callq 0x21d0
movq %rax, %rdi
movl $0x2710, %ecx           # imm = 0x2710
movl %ebx, %eax
cltd
idivl %ecx
movl %edx, %esi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
leaq 0x78(%rsp), %rdi
callq 0x586e
leaq 0x20(%rsp), %rdi
callq 0x606a
leaq 0xe8(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x606a
leaq 0x2f0(%rsp), %rdi
callq 0x2080
leaq 0xd0(%rsp), %rdi
callq 0x606a
xorl %eax, %eax
addq $0x500, %rsp            # imm = 0x500
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45a2(%rip), %rdi      # 0x9472
leaq 0x45b4(%rip), %rsi      # 0x948b
leaq 0x45b6(%rip), %rcx      # 0x9494
pushq $0x32
jmp 0x4f2b
leaq 0x468d(%rip), %rdi      # 0x9576
leaq 0x459b(%rip), %rsi      # 0x948b
leaq 0x459d(%rip), %rcx      # 0x9494
pushq $0x56
jmp 0x4f2b
leaq 0x4697(%rip), %rdi      # 0x9599
leaq 0x4582(%rip), %rsi      # 0x948b
leaq 0x4584(%rip), %rcx      # 0x9494
pushq $0x57
jmp 0x4f2b
leaq 0x46a0(%rip), %rdi      # 0x95bb
leaq 0x4569(%rip), %rsi      # 0x948b
leaq 0x456b(%rip), %rcx      # 0x9494
pushq $0x58
popq %rdx
callq 0x2150
movq %rax, %rbx
jmp 0x4f85
movq %rax, %rbx
jmp 0x4f8d
jmp 0x4fa2
jmp 0x4fa2
jmp 0x4fa7
jmp 0x4f49
jmp 0x4fac
jmp 0x4f49
jmp 0x4fac
movq %rax, %rbx
movq %rsp, %rdi
callq 0x20e0
jmp 0x4faf
jmp 0x4fac
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x20e0
jmp 0x4fb9
jmp 0x4fa2
jmp 0x4fa7
jmp 0x4f9b
jmp 0x4fa7
jmp 0x4fac
jmp 0x4fa2
jmp 0x4fa7
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x606a
movq %rsp, %rdi
callq 0x606a
leaq 0x78(%rsp), %rdi
callq 0x606a
jmp 0x4fb9
jmp 0x4fac
movq %rax, %rbx
jmp 0x4fe7
jmp 0x4fac
movq %rax, %rbx
jmp 0x4fb9
movq %rax, %rbx
jmp 0x4fd0
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x586e
leaq 0x20(%rsp), %rdi
callq 0x606a
leaq 0xe8(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x606a
leaq 0x2f0(%rsp), %rdi
callq 0x2080
leaq 0xd0(%rsp), %rdi
callq 0x606a
movq %rbx, %rdi
callq 0x22f0