// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b0d6
movl 0x272c(%rcx,%rdx,4), %edi
xorl %esi, %esi
cmpl $0x2, %edi
jb 0x2b0d0
xorl %esi, %esi
sarl %edi
incl %esi
cmpl $0x1, %edi
ja 0x2b0c7
movl %esi, 0x20(%rsp,%rdx,4)
subl %esi, %eax
incq %rdx
cmpq $0x5, %rdx
jne 0x2b0b1
movl 0x2738(%rcx), %edx
movl $0x0, %ecx
cmpl $0x2, %edx
jb 0x2b0fa
xorl %ecx, %ecx
sarl %edx
incl %ecx
cmpl $0x1, %edx
ja 0x2b0f1
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
movq 0x18(%rsp), %rax
movq (%rax), %rax
leaq 0xc(%rsp), %r13
xorl %ecx, %ecx
movl %ecx, %ecx
movl 0x20(%rsp,%rcx,4), %esi
xorl %edx, %edx
movl %edx, (%rax,%rcx,4)
movl %edx, 0xc(%rsp)
movl %esi, 0x14(%rsp)
testl %esi, %esi
je 0x2b1e3
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b314
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b37a
movq (%rax), %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b314
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b37a
cmpq 0x8(%rax), %rbx
je 0x2b1b8
xorl %ebp, %ebp
movl (%rbx), %eax
btq %rax, %r14
setb %al
xorb %al, %bpl
addq $0x4, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b314
movq %rax, %rdi
movq %r13, %rsi
callq 0x2b37a
cmpq 0x8(%rax), %rbx
jne 0x2b183
movzbl %bpl, %edx
andl $0x1, %edx
jmp 0x2b1ba
xorl %edx, %edx
movb 0xc(%rsp), %cl
shll %cl, %edx
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %rax
movq (%rax), %rax
orl %edx, (%rax,%rcx,4)
movl 0xc(%rsp), %ecx
incl %ecx
movl %ecx, 0xc(%rsp)
cmpl 0x14(%rsp), %ecx
jb 0x2b14c
movl 0x10(%rsp), %ecx
incl %ecx
movl %ecx, 0x10(%rsp)
cmpl $0x5, %ecx
jb 0x2b131
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop