// File: niksram[P]Cache-Mapping-Simulator/cache_mapper.cpp
// Function: cache_mock::loader(long)
long int cache_mock::loader(long int address)
{
    if (address >= mem_size || address < 0)
        return -1;
    long int block = address / block_size;
    long int set = block % no_sets;
    long int tag = address / (block_size * no_sets);
    for (long int i = 0; i < set_size; i++) // Hit Case!!!
    {
        if (container[set * set_size + i][1] == tag)
        {
            if (lru)
                container[set * set_size + i][3] = container[find_hierarchy_max(set)][3] + 1;
            return 1;
        }
    }
    //miss case
    long int min_heir = find_hierarchy_min(set);
    container[min_heir][1] = tag;
    container[min_heir][2] = 0;
    container[min_heir][3] = container[find_hierarchy_max(set)][3] + 1;
    for (int i = 4; i < container[0].size(); i++)
    {
        container[min_heir][i] = block * block_size + i - 4;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq -0x18(%rbp), %rax
cmpq 0x10(%rcx), %rax
jge 0x1e6c
cmpq $0x0, -0x18(%rbp)
jge 0x1e79
movq $-0x1, -0x8(%rbp)
jmp 0x20ef
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
cqto
idivq 0x18(%rcx)
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cqto
idivq 0x28(%rcx)
movq %rdx, %rax
movq -0x50(%rbp), %rdx
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rdx), %rcx
imulq 0x28(%rdx), %rcx
cqto
idivq %rcx
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rax
cmpq 0x20(%rcx), %rax
jge 0x1fa2
movq -0x50(%rbp), %rax
movq %rax, %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
imulq 0x20(%rax), %rsi
addq -0x38(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x1, %esi
callq 0x2af0
movq (%rax), %rax
cmpq -0x30(%rbp), %rax
jne 0x1f8f
movq -0x50(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x1f82
movq -0x50(%rbp), %rdi
movq %rdi, %rax
addq $0x38, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rsi
callq 0x2100
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x3, %esi
callq 0x2af0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq (%rcx), %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movq %rax, %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
imulq 0x20(%rax), %rsi
addq -0x38(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x3, %esi
callq 0x2af0
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x20ef
jmp 0x1f91
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1ebe
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x21d0
movq -0x50(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
addq $0x38, %rdi
movq -0x40(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x1, %esi
callq 0x2af0
movq -0x78(%rbp), %rcx
movq -0x50(%rbp), %rdi
movq %rcx, (%rax)
addq $0x38, %rdi
movq -0x40(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x2, %esi
callq 0x2af0
movq -0x50(%rbp), %rdi
movq $0x0, (%rax)
movq %rdi, %rax
addq $0x38, %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rsi
callq 0x2100
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x3, %esi
callq 0x2af0
movq -0x50(%rbp), %rdi
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
addq $0x38, %rdi
movq -0x40(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movl $0x3, %esi
callq 0x2af0
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movl $0x4, -0x44(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x44(%rbp), %rax
movq %rax, -0x80(%rbp)
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2ab0
movq %rax, %rdi
callq 0x2ad0
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x20e7
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rax
imulq 0x18(%rdi), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
subq $0x4, %rax
movq %rax, -0x88(%rbp)
addq $0x38, %rdi
movq -0x40(%rbp), %rsi
callq 0x2ab0
movq %rax, %rdi
movslq -0x44(%rbp), %rsi
callq 0x2af0
movq -0x88(%rbp), %rcx
movq %rcx, (%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x206d
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)