// File: /workspace/github_cpp_makefile_star2_O1/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:
movq $-0x1, %rax
testq %rsi, %rsi
js 0x1f31
movq %rsi, %r8
cmpq %rsi, 0x10(%rdi)
jle 0x1f31
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
movq 0x18(%rdi), %r10
movq 0x20(%rdi), %r9
movq %r8, %rax
cqto
idivq %r10
movq %rax, %rcx
movq 0x28(%rdi), %r11
cqto
idivq %r11
movq %rdx, %rsi
imulq %r10, %r11
movq %r8, %rax
cqto
idivq %r11
testq %r9, %r9
jle 0x1dc2
movq %r9, %r8
imulq %rsi, %r8
movq 0x38(%rdi), %rdx
leaq (%r8,%r8,2), %r10
leaq (%rdx,%r10,8), %r11
movq %r9, %rbx
movq (%r11), %r10
cmpq %rax, 0x8(%r10)
je 0x1e18
addq $0x18, %r11
decq %rbx
jne 0x1db0
movq 0x20(%rdi), %r8
movq %r8, %rdx
imulq %rsi, %rdx
testq %r8, %r8
jle 0x1e79
movq 0x38(%rdi), %r9
movq %r8, %r10
imulq %rsi, %r10
leaq (%r10,%r10,2), %r10
leaq (%r9,%r10,8), %r10
movq %rdx, %rbx
movq (%r10), %r11
movq 0x18(%r11), %r14
leaq (%rbx,%rbx,2), %r11
movq (%r9,%r11,8), %r15
movq %rdx, %r11
cmpq 0x18(%r15), %r14
jl 0x1e07
movq %rbx, %r11
incq %rdx
addq $0x18, %r10
movq %r11, %rbx
decq %r8
jne 0x1dec
jmp 0x1e7c
movl $0x1, %eax
cmpq $0x0, 0x30(%rdi)
je 0x1f2b
imulq %r9, %rsi
leaq (%rsi,%rsi,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movq %r8, %rdi
movq (%rcx), %rsi
movq 0x18(%rsi), %r11
leaq (%rdi,%rdi,2), %rsi
movq (%rdx,%rsi,8), %rbx
movq %r8, %rsi
cmpq 0x18(%rbx), %r11
jg 0x1e52
movq %rdi, %rsi
incq %r8
addq $0x18, %rcx
movq %rsi, %rdi
decq %r9
jne 0x1e37
leaq (%rsi,%rsi,2), %rcx
movq (%rdx,%rcx,8), %rcx
movq 0x18(%rcx), %rcx
incq %rcx
movq %rcx, 0x18(%r10)
jmp 0x1f2b
movq %rdx, %r11
movq 0x38(%rdi), %r8
leaq (%r11,%r11,2), %rdx
movq (%r8,%rdx,8), %rdx
movq %rax, 0x8(%rdx)
movq $0x0, 0x10(%rdx)
movq 0x20(%rdi), %r9
movq %r9, %rax
imulq %rsi, %rax
testq %r9, %r9
jle 0x1edf
imulq %r9, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
movq %rax, %r11
movq (%rsi), %r10
movq 0x18(%r10), %rbx
leaq (%r11,%r11,2), %r10
movq (%r8,%r10,8), %r14
movq %rax, %r10
cmpq 0x18(%r14), %rbx
jg 0x1ece
movq %r11, %r10
incq %rax
addq $0x18, %rsi
movq %r10, %r11
decq %r9
jne 0x1eb3
jmp 0x1ee2
movq %rax, %r10
leaq (%r10,%r10,2), %rax
movq (%r8,%rax,8), %rax
movq 0x18(%rax), %rax
incq %rax
movq %rax, 0x18(%rdx)
movq 0x8(%r8), %rsi
subq (%r8), %rsi
sarq $0x3, %rsi
cmpq $0x5, %rsi
jb 0x1f29
addq $-0x4, %rsi
xorl %eax, %eax
xorl %r8d, %r8d
movq 0x18(%rdi), %r9
imulq %rcx, %r9
addq %r8, %r9
movq %r9, 0x20(%rdx,%r8,8)
incq %r8
cmpq %r8, %rsi
jne 0x1f0f
jmp 0x1f2b
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq