// File: /workspace/github_cpp_makefile_star2_O3/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 0x1ba4
movq 0x3c5d(%rip), %rbx      # 0x4fd0
leaq 0x1ca2(%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 0x3c2b(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3c17(%rip), %rbx      # 0x4fd0
leaq 0x1c6a(%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 0x3be5(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3bd1(%rip), %rbx      # 0x4fd0
leaq 0x1c5d(%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 0x3b9f(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3b9b(%rip), %rdi      # 0x4fe0
leaq -0x38(%rbp), %rsi
callq 0x1100
movq 0x3b7b(%rip), %rbx      # 0x4fd0
leaq 0x1c4e(%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 0x3b49(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3b45(%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
movl $0x1, %esi
cmpq $0x1, -0x38(%rbp)
je 0x152b
movq 0x3b01(%rip), %rbx      # 0x4fd0
leaq 0x1c27(%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 0x3acf(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3acb(%rip), %rdi      # 0x4fe0
leaq -0x40(%rbp), %rsi
callq 0x1100
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
je 0x18a3
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
movq $0x0, (%rsp)
leaq -0xb0(%rbp), %rdi
callq 0x1970
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1bd6
leaq -0xb0(%rbp), %rdi
callq 0x1c1e
movq 0x3a5b(%rip), %rbx      # 0x4fd0
leaq 0x1be3(%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 0x3a29(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3a15(%rip), %rbx      # 0x4fd0
leaq 0x1be5(%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 0x39e3(%rip), %r14      # 0x4fd0
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movl $0x1, %ebx
movq 0x39d7(%rip), %r12      # 0x4fe0
leaq -0xb0(%rbp), %r13
leaq 0x19ed(%rip), %r15      # 0x3004
testl %ebx, %ebx
je 0x183d
movl $0x5, %edx
movq %r14, %rdi
leaq 0x1bb5(%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 0x1743
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
leaq -0x100(%rbp), %rdi
callq 0x1c46
jmp 0x1795
movl $0x12, %ebx
leaq -0x100(%rbp), %rdi
callq 0x19f4
leaq 0x1b61(%rip), %rsi      # 0x3208
jmp 0x178a
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1100
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x2000
xorl %ebx, %ebx
testq %rax, %rax
sete %bl
leaq 0x1b12(%rip), %rsi      # 0x31e9
leaq 0x1b0f(%rip), %rax      # 0x31ed
cmoveq %rax, %rsi
addq $0x3, %rbx
jmp 0x178a
movl $0x1, %ebx
leaq -0x100(%rbp), %rdi
callq 0x220a
jmp 0x17c1
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1100
movq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x1d64
testl %eax, %eax
je 0x17ed
cmpl $0x1, %eax
jne 0x17fb
movl $0x3, %edx
leaq 0x1aaf(%rip), %rsi      # 0x31e9
jmp 0x1807
xorl %ebx, %ebx
jmp 0x17c1
movl $0x47, %edx
movq %r14, %rdi
leaq 0x1a0d(%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 0x1a1d(%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 0x1617
movl $0x4, %edx
leaq 0x19f4(%rip), %rsi      # 0x31ed
jmp 0x1807
movl $0x15, %edx
leaq 0x19eb(%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 0x17c1
movq 0x378c(%rip), %rbx      # 0x4fd0
leaq 0x19d0(%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 0x375a(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq -0x100(%rbp), %rdi
callq 0x1c1e
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3726(%rip), %rbx      # 0x4fd0
leaq 0x1890(%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 0x36f4(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x36f0(%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 0x1970
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1bd6
jmp 0x1562
jmp 0x193d
jmp 0x1958
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x1c1e
jmp 0x195b
jmp 0x1958
jmp 0x1958
jmp 0x1958
jmp 0x1958
jmp 0x1958
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x1c1e
movq %rbx, %rdi
callq 0x1180
nop