// File: /workspace/github_cpp_makefile_star2_O3/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 0x1f4e
movq %rsi, %r8
cmpq %rsi, 0x10(%rdi)
jle 0x1f4e
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 0x1e2d
movq %r9, %rdx
imulq %rsi, %rdx
movq 0x38(%rdi), %r8
leaq (%rdx,%rdx,2), %r10
leaq (%r8,%r10,8), %r11
movq %r9, %rbx
movq (%r11), %r10
cmpq %rax, 0x8(%r10)
je 0x1e9e
addq $0x18, %r11
decq %rbx
jne 0x1dd0
testq %r9, %r9
jle 0x1e34
movq 0x38(%rdi), %r8
movq %r9, %r10
imulq %rsi, %r10
leaq (%r10,%r10,2), %r10
leaq (%r8,%r10,8), %r10
movq %rdx, %rbx
movq (%r10), %r11
movq 0x18(%r11), %r14
leaq (%rbx,%rbx,2), %r11
movq (%r8,%r11,8), %r15
movq %rdx, %r11
cmpq 0x18(%r15), %r14
jl 0x1e1c
movq %rbx, %r11
incq %rdx
addq $0x18, %r10
movq %r11, %rbx
decq %r9
jne 0x1e01
jmp 0x1e3b
imulq %rsi, %r9
movq %r9, %rdx
movq 0x38(%rdi), %r8
movq %rdx, %r11
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 0x1efc
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 0x1e8d
movq %r11, %r10
incq %rax
addq $0x18, %rsi
movq %r10, %r11
decq %r9
jne 0x1e72
jmp 0x1eff
movl $0x1, %eax
cmpq $0x0, 0x30(%rdi)
je 0x1f48
imulq %r9, %rsi
leaq (%rsi,%rsi,2), %rcx
leaq (%r8,%rcx,8), %rcx
movq %rdx, %rdi
movq (%rcx), %rsi
movq 0x18(%rsi), %r11
leaq (%rdi,%rdi,2), %rsi
movq (%r8,%rsi,8), %rbx
movq %rdx, %rsi
cmpq 0x18(%rbx), %r11
jg 0x1ed8
movq %rdi, %rsi
incq %rdx
addq $0x18, %rcx
movq %rsi, %rdi
decq %r9
jne 0x1ebd
leaq (%rsi,%rsi,2), %rcx
movq (%r8,%rcx,8), %rcx
movq 0x18(%rcx), %rcx
incq %rcx
movq %rcx, 0x18(%r10)
jmp 0x1f48
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 0x1f46
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 0x1f2c
jmp 0x1f48
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop