// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movl %ecx, 0xc(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x36590
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r15, 0x40(%rsp)
movq %r15, %rsi
callq 0x86cd2
leaq 0x20(%rsp), %rdi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
callq 0x5310
movq 0x8(%rax), %r13
movq (%r15), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x843b9
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x843d3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
testq %r13, %r13
je 0x843fe
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x20(%rsp), %rcx
cmpq %rbp, %rcx
je 0x8463f
movq %rcx, (%rbx)
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x84646
leaq 0x90(%rsp), %rdi
callq 0x86d84
movq 0x40(%rsp), %rax
leaq 0x20(%rax), %r15
leaq 0xc0(%rax), %r13
addq $0xf0, %rax
movq %rax, 0x18(%rsp)
leaq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movl $0xa0, %ebp
movq %r15, 0x48(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x86dfa
cmpb $0x1, (%rax)
jne 0x84477
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x86e76
movq 0x8(%rax), %rdx
xorl %r12d, %r12d
cmpq 0x8(%r14), %rdx
jne 0x844d7
testq %rdx, %rdx
je 0x84477
movq (%r14), %rsi
movq (%rax), %rdi
callq 0x5280
testl %eax, %eax
jne 0x844d7
cmpb $0x0, 0xc(%rsp)
je 0x84491
movq %r15, %rdi
leaq 0x14d11(%rip), %rsi     # 0x99199
callq 0x50c0
testl %eax, %eax
je 0x844f6
movq %r13, %rdi
movq %r15, %rsi
callq 0x86dfa
movb $0x1, (%rax)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x86e76
movq %rax, %rdi
movq %r14, %rsi
callq 0x5150
movq 0x10(%rsp), %rax
movq %rax, (%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movl $0x1, %r12d
movq %rbx, %rdi
callq 0x36590
cmpl $0x3, %r12d
je 0x844e6
testl %r12d, %r12d
jne 0x845f2
addq $0x20, %r15
addq $-0x20, %rbp
jne 0x84439
jmp 0x844fe
movl $0x3, %r12d
jmp 0x844d7
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 0x10(%rsp), %rcx
movq %rcx, (%rbx)
movq 0x48(%rsp), %rcx
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x36590
cmpb $0x0, 0xc(%rsp)
je 0x84588
leaq 0x14c38(%rip), %rsi     # 0x99199
movq %rbx, %rdi
callq 0x50c0
testl %eax, %eax
jne 0x84588
movq 0x8(%rbx), %rdx
leaq 0x147b8(%rip), %rcx     # 0x98d30
movl $0x3, %r8d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5370
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x36590
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
leaq 0x50(%rsp), %rsi
callq *0x28(%rax)
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x845cc
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5260
movq %r13, %rdi
movq %rbx, %rsi
callq 0x86dfa
movb $0x1, (%rax)
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x86e76
movq %rax, %rdi
movq %r14, %rsi
callq 0x5150
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x84613
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x30(%rsp), %rbp
je 0x84662
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x84662
movups (%rbp), %xmm0
movups %xmm0, (%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %rbp, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x84679
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5260
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x846d5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x846d5
jmp 0x846f1
jmp 0x846cd
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x84701
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x84701
movq %rax, %r14
jmp 0x84701
movq %rax, %r14
movq (%rbx), %rdi
cmpq 0x10(%rsp), %rdi
je 0x846f4
movq 0x10(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x5260
jmp 0x846f4
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x86ef2
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x8471d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5260
movq %r14, %rdi
callq 0x53d0
nop