// File: momohatt[P]seccampDB/database.cpp
// Function: DataBase::get_lock(Transaction*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, BaseOp)
bool DataBase::get_lock(Transaction* tx, Key key, BaseOp locktype) {
    if (table.count(key) <= 0) {
        UNREACHABLE;
        return false;
    }

    if (vexists(tx->lock_set, key)) {
        return ((locktype == Write && table[key].nlock == -1) ||
                (locktype == Read && table[key].nlock > 0));
    }

    if (locktype == Write) {
        if (table[key].nlock != 0)
            return false;
        table[key].nlock = -1;
        tx->lock_set.push_back(key);
        return true;
    }

    if (table[key].nlock < 0)
        return false;

    table[key].nlock++;
    tx->lock_set.push_back(key);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdx, -0x88(%rbp)
movq %rsi, %rax
movq -0x88(%rbp), %rsi
movq %rsi, -0x80(%rbp)
movq %rdi, -0x10(%rbp)
movq %rax, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x9410
cmpq $0x0, %rax
ja 0x5cef
movq 0x26307(%rip), %rax     # 0x2bfd0
movq (%rax), %rdi
leaq 0x16815(%rip), %rsi     # 0x1c4e8
leaq 0x1687a(%rip), %rdx     # 0x1c554
movl $0x13d, %ecx            # imm = 0x13D
movb $0x0, %al
callq 0x3470
movb $0x0, -0x1(%rbp)
jmp 0x5e6c
movq -0x18(%rbp), %rsi
addq $0x30, %rsi
leaq -0x40(%rbp), %rdi
callq 0xa1c0
movq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3150
jmp 0x5d0f
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xa330
movb %al, -0x89(%rbp)
jmp 0x5d24
leaq -0x60(%rbp), %rdi
callq 0x35f8
leaq -0x40(%rbp), %rdi
callq 0x41e0
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x5d45
jmp 0x5dde
cmpl $0x1, -0x24(%rbp)
jne 0x5d69
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
movq %rax, %rcx
movb $0x1, %al
cmpl $-0x1, 0x4(%rcx)
movb %al, -0x8a(%rbp)
je 0x5d9d
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x8b(%rbp)
jne 0x5d91
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
cmpl $0x0, 0x4(%rax)
setg %al
movb %al, -0x8b(%rbp)
movb -0x8b(%rbp), %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5e6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x5dd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x35f8
leaq -0x40(%rbp), %rdi
callq 0x41e0
jmp 0x5e7a
cmpl $0x1, -0x24(%rbp)
jne 0x5e28
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
cmpl $0x0, 0x4(%rax)
je 0x5dfd
movb $0x0, -0x1(%rbp)
jmp 0x5e6c
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
movq -0x80(%rbp), %rsi
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0x9470
movb $0x1, -0x1(%rbp)
jmp 0x5e6c
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
cmpl $0x0, 0x4(%rax)
jge 0x5e41
movb $0x0, -0x1(%rbp)
jmp 0x5e6c
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x96d0
movq -0x80(%rbp), %rsi
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0x9470
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3540
nopw %cs:(%rax,%rax)