// File: Manca[P]algorithms1/./assignment4.hpp
// Function: assignment4::testCase1()
void testCase1()
    {
        Graph g;
        g[1] = {4};
        g[2] = {8};
        g[3] = {6};
        g[4] = {7};
        g[5] = {2};
        g[6] = {9};
        g[7] = {1};
        g[8] = {5, 6};
        g[9] = {3, 7};
        
        Graph gRev;
        gRev[1] = {7};
        gRev[2] = {5};
        gRev[3] = {9};
        gRev[4] = {1};
        gRev[5] = {8};
        gRev[6] = {3, 8};
        gRev[7] = {4, 9};
        gRev[8] = {2};
        gRev[9] = {6};
        
        // initialize global var
        _seen       = seenList(g.size() + 1, 0);        // initialize with zeros
        _times      = timesList(g.size() + 1, 0);       // initialize with zeros
        _leaders    = leadersList(g.size() + 1, 0);     // initialize with zeros
        
        // First step: Calculate finishing times on transpose Graph gRev
        DFSLoop(gRev);
        
        // Second step: Construct a new graph (or update original)
        // with vertices updated according to their finishing times
        Graph newGraph = constructNewGraph(g, _times);
        
        // Third step: DFS over the new graph (updated original) and compute leaders
        DFSLoop(newGraph);

        // Forth step: Sort leaders in order to compute number of nodes in each SCC
        sort(begin(_leaders), end(_leaders));
        std::vector<SCC> SCCs;
        
        int el = _leaders[1];
        int elCnt = 1;
        for (size_t i = 2; i < _leaders.size(); i++)
        {
            if (_leaders[i] == el)
                elCnt++;
            else
            {
                SCC scc;
                scc.leader = el;
                scc.numNodes = elCnt;
                SCCs.push_back(scc);

                el = _leaders[i];
                elCnt = 1;
            }
        }
        // last SCC
        SCC scc;
        scc.leader = el;
        scc.numNodes = elCnt;
        SCCs.push_back(scc);
        
        // there are 3 SCCs in the given graph
        assert((int)SCCs.size() == 3);
        for (SCC sccc : SCCs)
        {
            cout << "SCC with leader " << sccc.leader << " has " << sccc.numNodes << " nodes." << endl;
        }
        
    }

// Assembly:
subq $0x468, %rsp            # imm = 0x468
leaq 0x438(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x8760
movq 0x120(%rsp), %rdi
movl $0x4, 0x424(%rsp)
leaq 0x424(%rsp), %rax
movq %rax, 0x428(%rsp)
movq $0x1, 0x430(%rsp)
movl $0x1, 0x420(%rsp)
leaq 0x420(%rsp), %rsi
callq 0x8770
movq %rax, 0x128(%rsp)
jmp 0x35cd
movq 0x128(%rsp), %rdi
movq 0x428(%rsp), %rsi
movq 0x430(%rsp), %rdx
callq 0x8870
jmp 0x35ec
movl $0x8, 0x3fc(%rsp)
leaq 0x3fc(%rsp), %rax
movq %rax, 0x400(%rsp)
movq $0x1, 0x408(%rsp)
movl $0x2, 0x3f8(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x3f8(%rsp), %rsi
callq 0x8770
movq %rax, 0x118(%rsp)
jmp 0x363d
movq 0x118(%rsp), %rdi
movq 0x400(%rsp), %rsi
movq 0x408(%rsp), %rdx
callq 0x8870
jmp 0x365c
movl $0x6, 0x3e4(%rsp)
leaq 0x3e4(%rsp), %rax
movq %rax, 0x3e8(%rsp)
movq $0x1, 0x3f0(%rsp)
movl $0x3, 0x3e0(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x3e0(%rsp), %rsi
callq 0x8770
movq %rax, 0x110(%rsp)
jmp 0x36ad
movq 0x110(%rsp), %rdi
movq 0x3e8(%rsp), %rsi
movq 0x3f0(%rsp), %rdx
callq 0x8870
jmp 0x36cc
movl $0x7, 0x3cc(%rsp)
leaq 0x3cc(%rsp), %rax
movq %rax, 0x3d0(%rsp)
movq $0x1, 0x3d8(%rsp)
movl $0x4, 0x3c8(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x3c8(%rsp), %rsi
callq 0x8770
movq %rax, 0x108(%rsp)
jmp 0x371d
movq 0x108(%rsp), %rdi
movq 0x3d0(%rsp), %rsi
movq 0x3d8(%rsp), %rdx
callq 0x8870
jmp 0x373c
movl $0x2, 0x3b4(%rsp)
leaq 0x3b4(%rsp), %rax
movq %rax, 0x3b8(%rsp)
movq $0x1, 0x3c0(%rsp)
movl $0x5, 0x3b0(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0x8770
movq %rax, 0x100(%rsp)
jmp 0x378d
movq 0x100(%rsp), %rdi
movq 0x3b8(%rsp), %rsi
movq 0x3c0(%rsp), %rdx
callq 0x8870
jmp 0x37ac
movl $0x9, 0x39c(%rsp)
leaq 0x39c(%rsp), %rax
movq %rax, 0x3a0(%rsp)
movq $0x1, 0x3a8(%rsp)
movl $0x6, 0x398(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x398(%rsp), %rsi
callq 0x8770
movq %rax, 0xf8(%rsp)
jmp 0x37fd
movq 0xf8(%rsp), %rdi
movq 0x3a0(%rsp), %rsi
movq 0x3a8(%rsp), %rdx
callq 0x8870
jmp 0x381c
movl $0x1, 0x384(%rsp)
leaq 0x384(%rsp), %rax
movq %rax, 0x388(%rsp)
movq $0x1, 0x390(%rsp)
movl $0x7, 0x380(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x8770
movq %rax, 0xf0(%rsp)
jmp 0x386d
movq 0xf0(%rsp), %rdi
movq 0x388(%rsp), %rsi
movq 0x390(%rsp), %rdx
callq 0x8870
jmp 0x388c
movl $0x5, 0x368(%rsp)
movl $0x6, 0x36c(%rsp)
leaq 0x368(%rsp), %rax
movq %rax, 0x370(%rsp)
movq $0x2, 0x378(%rsp)
movl $0x8, 0x364(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x364(%rsp), %rsi
callq 0x8770
movq %rax, 0xe8(%rsp)
jmp 0x38e8
movq 0xe8(%rsp), %rdi
movq 0x370(%rsp), %rsi
movq 0x378(%rsp), %rdx
callq 0x8870
jmp 0x3907
movl $0x3, 0x348(%rsp)
movl $0x7, 0x34c(%rsp)
leaq 0x348(%rsp), %rax
movq %rax, 0x350(%rsp)
movq $0x2, 0x358(%rsp)
movl $0x9, 0x344(%rsp)
leaq 0x438(%rsp), %rdi
leaq 0x344(%rsp), %rsi
callq 0x8770
movq %rax, 0xe0(%rsp)
jmp 0x3963
movq 0xe0(%rsp), %rdi
movq 0x350(%rsp), %rsi
movq 0x358(%rsp), %rdx
callq 0x8870
jmp 0x3982
leaq 0x310(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x8760
movq 0xd0(%rsp), %rdi
movl $0x7, 0x2fc(%rsp)
leaq 0x2fc(%rsp), %rax
movq %rax, 0x300(%rsp)
movq $0x1, 0x308(%rsp)
movl $0x1, 0x2f8(%rsp)
leaq 0x2f8(%rsp), %rsi
callq 0x8770
movq %rax, 0xd8(%rsp)
jmp 0x39e8
movq 0xd8(%rsp), %rdi
movq 0x300(%rsp), %rsi
movq 0x308(%rsp), %rdx
callq 0x8870
jmp 0x3a07
movl $0x5, 0x2e4(%rsp)
leaq 0x2e4(%rsp), %rax
movq %rax, 0x2e8(%rsp)
movq $0x1, 0x2f0(%rsp)
movl $0x2, 0x2e0(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x8770
movq %rax, 0xc8(%rsp)
jmp 0x3a58
movq 0xc8(%rsp), %rdi
movq 0x2e8(%rsp), %rsi
movq 0x2f0(%rsp), %rdx
callq 0x8870
jmp 0x3a77
movl $0x9, 0x2cc(%rsp)
leaq 0x2cc(%rsp), %rax
movq %rax, 0x2d0(%rsp)
movq $0x1, 0x2d8(%rsp)
movl $0x3, 0x2c8(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x8770
movq %rax, 0xc0(%rsp)
jmp 0x3ac8
movq 0xc0(%rsp), %rdi
movq 0x2d0(%rsp), %rsi
movq 0x2d8(%rsp), %rdx
callq 0x8870
jmp 0x3ae7
movl $0x1, 0x2b4(%rsp)
leaq 0x2b4(%rsp), %rax
movq %rax, 0x2b8(%rsp)
movq $0x1, 0x2c0(%rsp)
movl $0x4, 0x2b0(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x8770
movq %rax, 0xb8(%rsp)
jmp 0x3b38
movq 0xb8(%rsp), %rdi
movq 0x2b8(%rsp), %rsi
movq 0x2c0(%rsp), %rdx
callq 0x8870
jmp 0x3b57
movl $0x8, 0x29c(%rsp)
leaq 0x29c(%rsp), %rax
movq %rax, 0x2a0(%rsp)
movq $0x1, 0x2a8(%rsp)
movl $0x5, 0x298(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0x8770
movq %rax, 0xb0(%rsp)
jmp 0x3ba8
movq 0xb0(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
callq 0x8870
jmp 0x3bc7
movl $0x3, 0x280(%rsp)
movl $0x8, 0x284(%rsp)
leaq 0x280(%rsp), %rax
movq %rax, 0x288(%rsp)
movq $0x2, 0x290(%rsp)
movl $0x6, 0x27c(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x27c(%rsp), %rsi
callq 0x8770
movq %rax, 0xa8(%rsp)
jmp 0x3c23
movq 0xa8(%rsp), %rdi
movq 0x288(%rsp), %rsi
movq 0x290(%rsp), %rdx
callq 0x8870
jmp 0x3c42
movl $0x4, 0x260(%rsp)
movl $0x9, 0x264(%rsp)
leaq 0x260(%rsp), %rax
movq %rax, 0x268(%rsp)
movq $0x2, 0x270(%rsp)
movl $0x7, 0x25c(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x25c(%rsp), %rsi
callq 0x8770
movq %rax, 0xa0(%rsp)
jmp 0x3c9e
movq 0xa0(%rsp), %rdi
movq 0x268(%rsp), %rsi
movq 0x270(%rsp), %rdx
callq 0x8870
jmp 0x3cbd
movl $0x2, 0x244(%rsp)
leaq 0x244(%rsp), %rax
movq %rax, 0x248(%rsp)
movq $0x1, 0x250(%rsp)
movl $0x8, 0x240(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x8770
movq %rax, 0x98(%rsp)
jmp 0x3d0e
movq 0x98(%rsp), %rdi
movq 0x248(%rsp), %rsi
movq 0x250(%rsp), %rdx
callq 0x8870
jmp 0x3d2d
movl $0x6, 0x22c(%rsp)
leaq 0x22c(%rsp), %rax
movq %rax, 0x230(%rsp)
movq $0x1, 0x238(%rsp)
movl $0x9, 0x228(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0x8770
movq %rax, 0x90(%rsp)
jmp 0x3d7e
movq 0x90(%rsp), %rdi
movq 0x230(%rsp), %rsi
movq 0x238(%rsp), %rdx
callq 0x8870
jmp 0x3d9d
leaq 0x438(%rsp), %rdi
callq 0x8690
incq %rax
movq %rax, 0x80(%rsp)
movl $0x0, 0x20c(%rsp)
leaq 0x20b(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x83d0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rcx
leaq 0x210(%rsp), %rdi
leaq 0x20c(%rsp), %rdx
callq 0x86a0
jmp 0x3dfc
leaq 0x20405(%rip), %rdi     # 0x24208
leaq 0x210(%rsp), %rsi
movq %rsi, 0x68(%rsp)
callq 0x8720
movq 0x68(%rsp), %rdi
callq 0x8300
leaq 0x20b(%rsp), %rdi
callq 0x8470
leaq 0x438(%rsp), %rdi
callq 0x8690
incq %rax
movq %rax, 0x70(%rsp)
movl $0x0, 0x1ec(%rsp)
leaq 0x1eb(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x83d0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rcx
leaq 0x1f0(%rsp), %rdi
leaq 0x1ec(%rsp), %rdx
callq 0x86a0
jmp 0x3e7f
leaq 0x2036a(%rip), %rdi     # 0x241f0
leaq 0x1f0(%rsp), %rsi
movq %rsi, 0x50(%rsp)
callq 0x8720
movq 0x50(%rsp), %rdi
callq 0x8300
leaq 0x1eb(%rsp), %rdi
callq 0x8470
leaq 0x438(%rsp), %rdi
callq 0x8690
incq %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x1cc(%rsp)
leaq 0x1cb(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x83d0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rcx
leaq 0x1d0(%rsp), %rdi
leaq 0x1cc(%rsp), %rdx
callq 0x86a0
jmp 0x3f02
leaq 0x20317(%rip), %rdi     # 0x24220
leaq 0x1d0(%rsp), %rsi
movq %rsi, 0x48(%rsp)
callq 0x8720
movq 0x48(%rsp), %rdi
callq 0x8300
leaq 0x1cb(%rsp), %rdi
callq 0x8470
leaq 0x310(%rsp), %rdi
callq 0x3160
jmp 0x3f41
leaq 0x202a8(%rip), %rdx     # 0x241f0
leaq 0x198(%rsp), %rdi
leaq 0x438(%rsp), %rsi
callq 0x3270
jmp 0x3f5f
leaq 0x198(%rsp), %rdi
callq 0x3160
jmp 0x3f6e
leaq 0x202ab(%rip), %rdi     # 0x24220
callq 0x8910
movq %rax, 0x40(%rsp)
jmp 0x3f81
movq 0x40(%rsp), %rax
movq %rax, 0x190(%rsp)
leaq 0x2028b(%rip), %rdi     # 0x24220
callq 0x8940
movq %rax, 0x38(%rsp)
jmp 0x3fa1
movq 0x38(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x190(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x88d0
jmp 0x3fc5
leaq 0x170(%rsp), %rdi
callq 0x8970
leaq 0x20247(%rip), %rdi     # 0x24220
movl $0x1, %esi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x16c(%rsp)
movl $0x1, 0x168(%rsp)
movq $0x2, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x20209(%rip), %rdi     # 0x24220
callq 0x7f90
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x41c1
movq 0x160(%rsp), %rsi
leaq 0x201e4(%rip), %rdi     # 0x24220
callq 0x84b0
movl (%rax), %eax
cmpl 0x16c(%rsp), %eax
jne 0x4123
movl 0x168(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x168(%rsp)
jmp 0x41a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
jmp 0x438e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
jmp 0x4381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
leaq 0x20b(%rsp), %rdi
callq 0x8470
jmp 0x4381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
leaq 0x1eb(%rsp), %rdi
callq 0x8470
jmp 0x4381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
leaq 0x1cb(%rsp), %rdi
callq 0x8470
jmp 0x4381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
jmp 0x4374
movl 0x16c(%rsp), %eax
movl %eax, 0x158(%rsp)
movl 0x168(%rsp), %eax
movl %eax, 0x15c(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x8980
jmp 0x4156
movq 0x160(%rsp), %rsi
leaq 0x200bb(%rip), %rdi     # 0x24220
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x16c(%rsp)
movl $0x1, 0x168(%rsp)
jmp 0x41a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x418(%rsp)
movl %eax, 0x414(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x8ae0
jmp 0x4374
jmp 0x41a8
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x4003
movl 0x16c(%rsp), %eax
movl %eax, 0x150(%rsp)
movl 0x168(%rsp), %eax
movl %eax, 0x154(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x8980
jmp 0x41f4
leaq 0x170(%rsp), %rdi
callq 0x89f0
cmpl $0x3, %eax
jne 0x4208
jmp 0x4227
leaq 0x15eb7(%rip), %rdi     # 0x1a0c6
leaq 0x15e11(%rip), %rsi     # 0x1a027
movl $0xd3, %edx
leaq 0x15eba(%rip), %rcx     # 0x1a0dc
callq 0x2140
leaq 0x170(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rdi
callq 0x8a10
movq %rax, 0x140(%rsp)
movq 0x148(%rsp), %rdi
callq 0x8a40
movq %rax, 0x138(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x8a70
testb $0x1, %al
jne 0x427f
jmp 0x4338
leaq 0x140(%rsp), %rdi
callq 0x8ab0
movq (%rax), %rax
movq %rax, 0x130(%rsp)
movq 0x1fd3a(%rip), %rdi     # 0x23fd8
leaq 0x15e55(%rip), %rsi     # 0x1a0fa
callq 0x21a0
movq %rax, 0x28(%rsp)
jmp 0x42b1
movq 0x28(%rsp), %rdi
movl 0x130(%rsp), %esi
callq 0x2320
movq %rax, 0x20(%rsp)
jmp 0x42c9
movq 0x20(%rsp), %rdi
leaq 0x15e36(%rip), %rsi     # 0x1a10b
callq 0x21a0
movq %rax, 0x18(%rsp)
jmp 0x42e1
movq 0x18(%rsp), %rdi
movl 0x134(%rsp), %esi
callq 0x2320
movq %rax, 0x10(%rsp)
jmp 0x42f9
movq 0x10(%rsp), %rdi
leaq 0x15e0c(%rip), %rsi     # 0x1a111
callq 0x21a0
movq %rax, 0x8(%rsp)
jmp 0x4311
movq 0x8(%rsp), %rdi
movq 0x1fcab(%rip), %rsi     # 0x23fc8
callq 0x21d0
jmp 0x4324
jmp 0x4326
leaq 0x140(%rsp), %rdi
callq 0x8ac0
jmp 0x4261
leaq 0x170(%rsp), %rdi
callq 0x8ae0
leaq 0x198(%rsp), %rdi
callq 0x8860
leaq 0x310(%rsp), %rdi
callq 0x8860
leaq 0x438(%rsp), %rdi
callq 0x8860
addq $0x468, %rsp            # imm = 0x468
retq
leaq 0x198(%rsp), %rdi
callq 0x8860
leaq 0x310(%rsp), %rdi
callq 0x8860
leaq 0x438(%rsp), %rdi
callq 0x8860
movq 0x418(%rsp), %rdi
callq 0x2330
nopl (%rax,%rax)