// File: 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
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdx, -0x128(%rbp)
movq %rdi, -0x140(%rbp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5490
movq -0x128(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x5150
jmp 0xd86bc
movq -0x130(%rbp), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0xda8d0
jmp 0xd86d2
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5420
movq %rax, %rdi
callq 0x54e0
movq %rax, -0x148(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5200
leaq -0x80(%rbp), %rdi
callq 0x5200
movq -0x148(%rbp), %rax
cmpq $0x0, %rax
je 0xd8763
movq -0x140(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x51e0
movl $0x1, -0x90(%rbp)
jmp 0xd8adb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xd8af4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5200
jmp 0xd8af4
leaq -0xd8(%rbp), %rdi
callq 0xda9d0
jmp 0xd8771
movq -0x130(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rax
cmpq -0xf0(%rbp), %rax
je 0xd8920
movq -0x130(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq %rax, -0xf8(%rbp)
addq $0xc0, %rdi
movq -0xf8(%rbp), %rsi
callq 0xdaa70
movq %rax, -0x150(%rbp)
jmp 0xd87ea
movq -0x150(%rbp), %rax
testb $0x1, (%rax)
je 0xd8835
movq -0x130(%rbp), %rdi
addq $0xf0, %rdi
movq -0xf8(%rbp), %rsi
callq 0xdab50
movq %rax, -0x158(%rbp)
jmp 0xd8819
movq -0x128(%rbp), %rsi
movq -0x158(%rbp), %rdi
callq 0x19db0
testb $0x1, %al
jne 0xd8835
jmp 0xd8907
testb $0x1, -0x19(%rbp)
je 0xd887e
movq -0xf8(%rbp), %rdi
leaq 0x19078(%rip), %rsi     # 0xf18c1
callq 0x2a580
movb %al, -0x159(%rbp)
jmp 0xd8856
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0xd8862
jmp 0xd887e
jmp 0xd8909
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xd8acd
movq -0x130(%rbp), %rdi
addq $0xc0, %rdi
movq -0xf8(%rbp), %rsi
callq 0xdaa70
movq %rax, -0x168(%rbp)
jmp 0xd88a1
movq -0x130(%rbp), %rdi
movq -0x168(%rbp), %rax
movb $0x1, (%rax)
addq $0xf0, %rdi
movq -0xf8(%rbp), %rsi
callq 0xdab50
movq %rax, -0x170(%rbp)
jmp 0xd88ce
movq -0x128(%rbp), %rsi
movq -0x170(%rbp), %rdi
callq 0x5050
jmp 0xd88e3
movq -0x140(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x5150
jmp 0xd88f8
movl $0x1, -0x90(%rbp)
jmp 0xd8abf
jmp 0xd8909
movq -0xe8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xe8(%rbp)
jmp 0xd87a5
movq -0x130(%rbp), %rdi
movb $0x0, -0xf9(%rbp)
movq %rdi, %rax
addq $0x20, %rax
movq %rax, -0x180(%rbp)
callq 0xdac30
movl %eax, -0x174(%rbp)
jmp 0xd8949
movq -0x140(%rbp), %rdi
movq -0x180(%rbp), %rsi
movl -0x174(%rbp), %eax
cltq
shlq $0x5, %rax
addq %rax, %rsi
callq 0x5150
jmp 0xd896d
testb $0x1, -0x19(%rbp)
je 0xd89c8
movq -0x140(%rbp), %rdi
leaq 0x18f40(%rip), %rsi     # 0xf18c1
callq 0x2a580
movb %al, -0x181(%rbp)
jmp 0xd898e
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0xd899a
jmp 0xd89c8
movq -0x140(%rbp), %rdi
leaq 0x18ab0(%rip), %rsi     # 0xf1458
callq 0x5480
jmp 0xd89af
jmp 0xd89c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xd8ab1
movq -0x140(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x5150
jmp 0xd89dd
movq -0x130(%rbp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq -0x120(%rbp), %rsi
callq *%rax
jmp 0xd89f6
leaq -0x120(%rbp), %rdi
callq 0x5200
movq -0x130(%rbp), %rdi
movq -0x140(%rbp), %rsi
addq $0xc0, %rdi
callq 0xdaa70
movq %rax, -0x190(%rbp)
jmp 0xd8a25
movq -0x140(%rbp), %rsi
movq -0x130(%rbp), %rdi
movq -0x190(%rbp), %rax
movb $0x1, (%rax)
addq $0xf0, %rdi
callq 0xdab50
movq %rax, -0x198(%rbp)
jmp 0xd8a52
movq -0x128(%rbp), %rsi
movq -0x198(%rbp), %rdi
callq 0x5050
jmp 0xd8a67
movb $0x1, -0xf9(%rbp)
movl $0x1, -0x90(%rbp)
testb $0x1, -0xf9(%rbp)
jne 0xd8aaf
jmp 0xd8aa3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x5200
jmp 0xd8ab1
movq -0x140(%rbp), %rdi
callq 0x5200
jmp 0xd8abf
movq -0x140(%rbp), %rdi
callq 0x5200
jmp 0xd8acd
leaq -0xd8(%rbp), %rdi
callq 0xdac70
jmp 0xd8adb
leaq -0xd8(%rbp), %rdi
callq 0xdac70
jmp 0xd8af4
leaq -0x40(%rbp), %rdi
callq 0x5200
movq -0x138(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x5200
movq -0x88(%rbp), %rdi
callq 0x55b0
nopl (%rax)