// File: /workspace/github_cpp_makefile_star2_O1/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 0x1b88
movq 0x3c7d(%rip), %rbx      # 0x4fd0
leaq 0x1cc2(%rip), %rsi      # 0x301c
movl $0xd, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3c4b(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3c37(%rip), %rbx      # 0x4fd0
leaq 0x1c8a(%rip), %rsi      # 0x302a
movl $0x38, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3c05(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3bf1(%rip), %rbx      # 0x4fd0
leaq 0x1c7d(%rip), %rsi      # 0x3063
movl $0x46, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3bbf(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3bbb(%rip), %rdi      # 0x4fe0
leaq -0x38(%rbp), %rsi
callq 0x1100
movq 0x3b9b(%rip), %rbx      # 0x4fd0
leaq 0x1c6e(%rip), %rsi      # 0x30aa
movl $0x52, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3b69(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3b65(%rip), %rdi      # 0x4fe0
leaq -0x58(%rbp), %rsi
callq 0x1100
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x1100
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x1100
cmpq $0x1, -0x38(%rbp)
je 0x14f9
movq 0x3b26(%rip), %rbx      # 0x4fd0
leaq 0x1c4c(%rip), %rsi      # 0x30fd
movl $0x43, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3af4(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3af0(%rip), %rdi      # 0x4fe0
leaq -0x40(%rbp), %rsi
callq 0x1100
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
je 0x153e
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
movq $0x0, (%rsp)
leaq -0xb0(%rbp), %rdi
callq 0x1948
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1bba
jmp 0x15cf
movq 0x3a8b(%rip), %rbx      # 0x4fd0
leaq 0x1bf5(%rip), %rsi      # 0x3141
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3a59(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3a55(%rip), %rdi      # 0x4fe0
leaq -0x60(%rbp), %rsi
callq 0x1100
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 0x1948
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1bba
leaq -0xb0(%rbp), %rdi
callq 0x1c02
movq 0x39ee(%rip), %rbx      # 0x4fd0
leaq 0x1b76(%rip), %rsi      # 0x315f
movl $0x47, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x39bc(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x39a8(%rip), %rbx      # 0x4fd0
leaq 0x1b78(%rip), %rsi      # 0x31a7
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3976(%rip), %r14      # 0x4fd0
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movl $0x1, %ebx
movq 0x396a(%rip), %r12      # 0x4fe0
leaq -0xb0(%rbp), %r13
leaq 0x1980(%rip), %r15      # 0x3004
testl %ebx, %ebx
je 0x18aa
movl $0x5, %edx
movq %r14, %rdi
leaq 0x1b48(%rip), %rsi      # 0x31e3
callq 0x1110
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq %r12, %rdi
movq %r13, %rsi
callq 0x1090
movl -0xb0(%rbp), %eax
cmpq $0x5, %rax
ja 0x17b0
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
leaq -0x100(%rbp), %rdi
callq 0x1c2a
jmp 0x1802
movl $0x12, %ebx
leaq -0x100(%rbp), %rdi
callq 0x19ca
leaq 0x1af4(%rip), %rsi      # 0x3208
jmp 0x17f7
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1100
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x1fe2
xorl %ebx, %ebx
testq %rax, %rax
sete %bl
leaq 0x1aa5(%rip), %rsi      # 0x31e9
leaq 0x1aa2(%rip), %rax      # 0x31ed
cmoveq %rax, %rsi
addq $0x3, %rbx
jmp 0x17f7
movl $0x1, %ebx
leaq -0x100(%rbp), %rdi
callq 0x21f0
jmp 0x182e
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1100
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x1d44
testl %eax, %eax
je 0x185a
cmpl $0x1, %eax
jne 0x1868
movl $0x3, %edx
leaq 0x1a42(%rip), %rsi      # 0x31e9
jmp 0x1874
xorl %ebx, %ebx
jmp 0x182e
movl $0x47, %edx
movq %r14, %rdi
leaq 0x19a0(%rip), %rsi      # 0x315f
callq 0x1110
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movl $0x3b, %ebx
movq %rax, %rdi
callq 0x10a0
leaq 0x19b0(%rip), %rsi      # 0x31a7
movq %r14, %rdi
movq %rbx, %rdx
callq 0x1110
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x10a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
jmp 0x1684
movl $0x4, %edx
leaq 0x1987(%rip), %rsi      # 0x31ed
jmp 0x1874
movl $0x15, %edx
leaq 0x197e(%rip), %rsi      # 0x31f2
movq %r14, %rdi
callq 0x1110
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x10a0
jmp 0x182e
movq 0x371f(%rip), %rbx      # 0x4fd0
leaq 0x1963(%rip), %rsi      # 0x321b
movl $0x16, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x36ed(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq -0x100(%rbp), %rdi
callq 0x1c02
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1914
jmp 0x192f
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x1c02
jmp 0x1932
jmp 0x192f
jmp 0x192f
jmp 0x192f
jmp 0x192f
jmp 0x192f
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x1c02
movq %rbx, %rdi
callq 0x1180
nop