// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]ramulator/src/Memory.h
// Function: ramulator::Memory<ramulator::DDR3, ramulator::Controller>::apply_mapping(long, std::vector<int, std::allocator<int>>&)
void apply_mapping(long addr, std::vector<int>& addr_vec){
        int *sz = spec->org_entry.count;
        int addr_total_bits = sizeof(addr_vec)*8;
        int addr_bits [int(T::Level::MAX)];
        for (int i = 0 ; i < int(T::Level::MAX) ; i ++)
        {
            if ( i != int(T::Level::Row))
            {
                addr_bits[i] = calc_log2(sz[i]);
                addr_total_bits -= addr_bits[i];
            }
        }
        // Row address is an integer.
        addr_bits[int(T::Level::Row)] = min((int)sizeof(int)*8, max(addr_total_bits, calc_log2(sz[int(T::Level::Row)])));

        // printf("Address: %lx => ",addr);
        for (unsigned int lvl = 0; lvl < int(T::Level::MAX); lvl++)
        {
            unsigned int lvl_bits = addr_bits[lvl];
            addr_vec[lvl] = 0;
            for (unsigned int bitindex = 0 ; bitindex < lvl_bits ; bitindex++){
                bool bitvalue = false;
                for (MapSrcVector::iterator it = mapping_scheme[lvl][bitindex].begin() ;
                    it != mapping_scheme[lvl][bitindex].end(); it ++)
                {
                    bitvalue = bitvalue xor get_bit_at(addr, *it);
                }
                addr_vec[lvl] |= (bitvalue << bitindex);
            }
            // printf("%s: %x, ",T::level_str[lvl].c_str(),addr_vec[lvl]);
        }
        // printf("\n");
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0xc20(%rdi), %rcx
movl $0xc0, %eax
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x2aea4
movl 0x272c(%rcx,%rdx,4), %edi
xorl %esi, %esi
cmpl $0x2, %edi
jb 0x2ae9e
xorl %esi, %esi
sarl %edi
incl %esi
cmpl $0x1, %edi
ja 0x2ae95
movl %esi, 0x20(%rsp,%rdx,4)
subl %esi, %eax
incq %rdx
cmpq $0x5, %rdx
jne 0x2ae7f
movl 0x2738(%rcx), %edx
movl $0x0, %ecx
cmpl $0x2, %edx
jb 0x2aec8
xorl %ecx, %ecx
sarl %edx
incl %ecx
cmpl $0x1, %edx
ja 0x2aebf
cmpl %ecx, %eax
cmovgl %eax, %ecx
cmpl $0x20, %ecx
movl $0x20, %eax
cmovll %ecx, %eax
movl %eax, 0x2c(%rsp)
leaq 0x10(%rsp), %r12
movl $0x0, (%r12)
addq $0xb50, %r15            # imm = 0xB50
leaq 0xc(%rsp), %r13
xorl %eax, %eax
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %esi
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
movl %edx, (%rcx,%rax,4)
movl %edx, 0xc(%rsp)
movl %esi, 0x14(%rsp)
testl %esi, %esi
je 0x2afb1
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b0dc
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b140
movq (%rax), %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b0dc
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b140
cmpq 0x8(%rax), %rbx
je 0x2af86
xorl %ebp, %ebp
movl (%rbx), %eax
btq %rax, %r14
setb %al
xorb %al, %bpl
addq $0x4, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b0dc
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b140
cmpq 0x8(%rax), %rbx
jne 0x2af51
movzbl %bpl, %eax
andl $0x1, %eax
jmp 0x2af88
xorl %eax, %eax
movb 0xc(%rsp), %cl
shll %cl, %eax
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %rdx
movq (%rdx), %rdx
orl %eax, (%rdx,%rcx,4)
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl 0x14(%rsp), %eax
jb 0x2af1a
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl $0x5, %eax
jb 0x2aef7
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop