// File: /workspace/github_cpp_makefile_star2_O3/sighingnow[P]compile-pascal/pl0_allocator.cpp
// Function: SimpleAllocator::alloc(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
string SimpleAllocator::alloc(std::string name, bool is_ref) {
    string res;
    if ((res = exist(name)).length() != 0) {
        return res;
    }
    LOC loc;
    for (auto && r: regs) {
        if (!used[r] || record[r] == name) {
            if (is_ref && r == "ebx") {
                continue; // don't map ebx to a variable with reference type.
            }
            used[r] = true;
            this->record[r] = name;
            return r; // found free register, or this variable already mapped to register.
        }
    }
    std::string r = regs[this->random()];
    if (is_ref && r == "ebx") {
        r = "ecx";  // don't map ebx to a variable with reference type.
    }
    this->spill(r);
    this->used[r] = true;
    this->record[r] = name;
    return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r13
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x351dc
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r15, 0x10(%rsp)
movq %r15, %rsi
callq 0x812a8
leaq 0x18(%rsp), %rdi
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x5310
movq 0x8(%rax), %r12
movq (%r15), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x7eac2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7ead9
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
testq %r12, %r12
je 0x7eb0b
leaq 0x10(%r13), %rax
movq %rax, (%r13)
movq 0x18(%rsp), %rcx
leaq 0x28(%rsp), %rdx
cmpq %rdx, %rcx
je 0x7eca9
movq %rcx, (%r13)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r13)
jmp 0x7ecaf
movq %r13, (%rsp)
leaq 0x80(%rsp), %rdi
callq 0x81346
movq 0x10(%rsp), %rax
leaq 0x20(%rax), %r15
leaq 0xc0(%rax), %r13
addq $0xf0, %rax
movq %rax, 0x8(%rsp)
movl $0xa0, %ebx
leaq 0x14656(%rip), %r12     # 0x93199
movq %r15, 0x38(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x813bc
cmpb $0x1, (%rax)
jne 0x7eb83
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x81438
movq 0x8(%rax), %rdx
cmpq 0x8(%r14), %rdx
jne 0x7eb9f
testq %rdx, %rdx
je 0x7eb83
movq (%r14), %rsi
movq (%rax), %rdi
callq 0x5280
testl %eax, %eax
jne 0x7eb9f
testb %bpl, %bpl
je 0x7ecbd
movq %r15, %rdi
movq %r12, %rsi
callq 0x50c0
testl %eax, %eax
jne 0x7ecbd
addq $0x20, %r15
addq $-0x20, %rbx
jne 0x7eb48
xorl %edi, %edi
callq 0x5210
movl %eax, %edi
callq 0x5230
callq 0x50a0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
cltq
shlq $0x5, %rax
movq (%rsp), %rdi
leaq 0x10(%rdi), %r15
movq %r15, (%rdi)
movq 0x38(%rsp), %rcx
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
addq %rsi, %rdx
callq 0x351dc
testb %bpl, %bpl
movq 0x10(%rsp), %r12
je 0x7ec38
leaq 0x1458a(%rip), %rsi     # 0x93199
movq (%rsp), %rdi
callq 0x50c0
testl %eax, %eax
jne 0x7ec38
movq (%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x14105(%rip), %rcx     # 0x92d30
movl $0x3, %r8d
xorl %esi, %esi
callq 0x5370
leaq 0x50(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x351dc
movq (%r12), %rax
leaq 0x40(%rsp), %rsi
movq %r12, %rdi
callq *0x28(%rax)
movq 0x40(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7ec7f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5260
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x813bc
movb $0x1, (%rax)
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
callq 0x81438
movq %rax, %rdi
movq %r14, %rsi
callq 0x5150
jmp 0x7ecfd
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%r13)
jmp 0x7ed63
movq %r13, %rdi
movq %r15, %rsi
callq 0x813bc
movb $0x1, (%rax)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x81438
movq %rax, %rdi
movq %r14, %rsi
callq 0x5150
movq (%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
callq 0x351dc
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ed1e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
movq (%rsp), %r13
je 0x7ed47
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7ed63
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5260
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7ed9b
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x7ed9b
jmp 0x7edd7
jmp 0x7edd2
movq %rax, %r14
movq (%rsp), %rax
movq (%rax), %rdi
cmpq %r15, %rdi
je 0x7edda
movq (%r15), %rsi
incq %rsi
callq 0x5260
jmp 0x7edda
jmp 0x7edd7
movq %rax, %r14
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7ede7
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x7ede7
movq %rax, %r14
jmp 0x7ede7
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x814b4
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7ee03
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5260
movq %r14, %rdi
callq 0x53d0
nop