// File: /workspace/github_cpp_makefile_star2_O2/niksram[P]Cache-Mapping-Simulator/client.cpp
// Function: main
int main()
{
    cache_mock Cacher;
    cout << "Cache-Mapper\n"
         << endl;
    cout << "Input only compatible values (such as power of 2s, etc)\n"
         << endl;
    long int d, c, m, b, s, l; // default meaning as in 'cache_mapper.cpp' constructor call;
    long int address;
    cout << "Enter 0 for Set-Associative, 1 for Direct-Map, 2 for Fully-Associative" << endl;
    cin >> d;
    cout << "Enter Cache-Size, Memory-Size, Block-Size in Bytes/Words (stick to one convention)" << endl;
    cin >> c >> m >> b;
    if (d != 1)
    {
        // There is no requirement of replacement techniques for direct mapped cache.
        cout << "Enter 1 for Least-Recently-Used, 0 for First-In-First-Out Hierarchy" << endl;
        cin >> l;
    }
    
    if (!d)
    {
        cout << "Enter X for X-way associative"<<endl;
        cin >> s;
        cache_mock temp(d, c, m, b, l, s);
        Cacher.cache_mock_copy(temp);
    }
    else
    {
        cache_mock temp(d, c, m, b, l);
        Cacher.cache_mock_copy(temp);
    }
    int flag = 1;
    int val;
    cout << "\n0 : Display\n1 : Load followed by address\n2 : Store followed by address" << endl;
    cout << "3 : Refresh dirty_bits\n4 : Clear cache main_frame\n5 : Exit\n" << endl;
    while (flag)
    {
        cout << "Input" << endl;
        cin >> val;
        switch (val)
        {
        case 0:
        {
            Cacher.container_display();
            cout << endl;
            break;
        }
        case 1:
        {
            cin >> address;
            int addressFlag = Cacher.loader(address);
            if (addressFlag == 1)
                cout << "Hit" << endl;
            else if(addressFlag == 0)
                cout << "Miss" << endl;
            else
            {
                cout << "Invalid address input" << endl;
            }
            
            break;
        }
        case 2:
        {
            cin >> address;
            if (Cacher.storer(address))
                cout << "Hit" << endl;
            else
                cout << "Miss" << endl;
            break;
        }
        case 3:
        {
            Cacher.refresh_dirty();
            break;
        }
        case 4:
        {
            Cacher.container_init();
            cout << "Cache was cleared!" << endl;
            break;
        }
        case 5:
        {
            flag--;
            break;
        }
        default:
        {
            cout << "\n0 : Display\n1 : Load followed by address\n2 : Store followed by address" << endl;
            cout << "3 : Refresh dirty_bits\n4 : Clear cache main_frame\n5 : Exit\n" << endl;   
        }
        }
        cout<<endl;
    }
    cout << "Simulation Terminated!" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
leaq -0x100(%rbp), %rdi
callq 0x1832
movq 0x4ccd(%rip), %rdi      # 0x5fd0
leaq 0x1d12(%rip), %rsi      # 0x301c
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4cb2(%rip), %rdi      # 0x5fd0
leaq 0x1d05(%rip), %rsi      # 0x302a
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4c97(%rip), %rdi      # 0x5fd0
leaq 0x1d23(%rip), %rsi      # 0x3063
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4c8c(%rip), %rdi      # 0x5fe0
leaq -0x38(%rbp), %rsi
callq 0x10f0
movq 0x4c6c(%rip), %rdi      # 0x5fd0
leaq 0x1d3f(%rip), %rsi      # 0x30aa
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4c61(%rip), %rdi      # 0x5fe0
leaq -0x58(%rbp), %rsi
callq 0x10f0
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x10f0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x10f0
cmpq $0x1, -0x38(%rbp)
jne 0x13ac
pushq $0x1
popq %rsi
jmp 0x13e4
movq 0x4c1d(%rip), %rdi      # 0x5fd0
leaq 0x1d43(%rip), %rsi      # 0x30fd
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4c12(%rip), %rdi      # 0x5fe0
leaq -0x40(%rbp), %rsi
callq 0x10f0
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
je 0x1604
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
andq $0x0, (%rsp)
leaq -0xb0(%rbp), %rdi
callq 0x16a8
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1866
leaq -0xb0(%rbp), %rdi
callq 0x18ae
movq 0x4ba5(%rip), %rdi      # 0x5fd0
leaq 0x1d2d(%rip), %rsi      # 0x315f
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x4b8a(%rip), %rbx      # 0x5fd0
leaq 0x1d5a(%rip), %rsi      # 0x31a7
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rdi
callq 0x1070
pushq $0x1
popq %r15
movq 0x4b78(%rip), %r12      # 0x5fe0
leaq -0xb0(%rbp), %r13
leaq 0x1b8e(%rip), %r14      # 0x3004
testl %r15d, %r15d
je 0x15c9
movq %rbx, %rdi
leaq 0x1d5a(%rip), %rsi      # 0x31e3
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq %r12, %rdi
movq %r13, %rsi
callq 0x1090
movl -0xb0(%rbp), %eax
cmpq $0x5, %rax
ja 0x158a
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
leaq -0x100(%rbp), %rdi
callq 0x18d2
movq %rbx, %rax
jmp 0x15b0
leaq -0x100(%rbp), %rdi
callq 0x1728
leaq 0x1d27(%rip), %rsi      # 0x3208
jmp 0x15a8
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x10f0
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x1ba6
leaq 0x1ce4(%rip), %rsi      # 0x31ed
testq %rax, %rax
je 0x15a8
leaq 0x1cd0(%rip), %rsi      # 0x31e9
jmp 0x15a8
leaq -0x100(%rbp), %rdi
callq 0x1cf4
pushq $0x1
popq %r15
jmp 0x15bc
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x10f0
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x19d0
leaq 0x1c97(%rip), %rsi      # 0x31ed
testl %eax, %eax
je 0x1561
leaq 0x1c91(%rip), %rsi      # 0x31f2
cmpl $0x1, %eax
leaq 0x1c7e(%rip), %rax      # 0x31e9
cmoveq %rax, %rsi
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rdi
callq 0x1070
pushq $0x1
popq %r15
jmp 0x15bc
xorl %r15d, %r15d
jmp 0x15bc
movq %rbx, %rdi
leaq 0x1bcb(%rip), %rsi      # 0x315f
callq 0x10c0
movq %rax, %rdi
callq 0x1070
leaq 0x1bff(%rip), %rsi      # 0x31a7
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rdi
callq 0x1070
pushq $0x1
popq %r15
movq %rbx, %rdi
callq 0x1070
jmp 0x1476
movq 0x4a00(%rip), %rdi      # 0x5fd0
leaq 0x1c44(%rip), %rsi      # 0x321b
callq 0x10c0
movq %rax, %rdi
callq 0x1070
leaq -0x100(%rbp), %rdi
callq 0x18ae
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x49c5(%rip), %rdi      # 0x5fd0
leaq 0x1b2f(%rip), %rsi      # 0x3141
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq 0x49ba(%rip), %rdi      # 0x5fe0
leaq -0x60(%rbp), %rsi
callq 0x10f0
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x60(%rbp), %rax
movq %rax, (%rsp)
leaq -0xb0(%rbp), %rdi
callq 0x16a8
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1866
jmp 0x1418
jmp 0x1673
jmp 0x168e
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x18ae
jmp 0x1691
jmp 0x168e
jmp 0x168e
jmp 0x168e
jmp 0x168e
jmp 0x168e
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x18ae
movq %rbx, %rdi
callq 0x1160
nopl (%rax)