// File: UBOdin[P]jitd-cpp/src/rwlock.cpp
// Function: RWLock::writer_lock()
void RWLock::writer_lock()
{
  unique_lock<std::mutex> l(lock);
  if(readers.load() || writers.load()){
    write_waiters.fetch_add(1);
    do { write.wait(l); }
    while(readers.load() || writers.load());
    write_waiters.fetch_sub(1);
  }
  writers.store(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
movq %rsi, -0xd8(%rbp)
addq $0x10, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x5560
movq -0xd8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x5, -0x54(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl -0x54(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x56f0
movl %eax, -0xc4(%rbp)
jmp 0x4e32
movl -0xc4(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0xdc(%rbp)
decl %eax
subl $0x2, %eax
jb 0x4e68
jmp 0x4e4d
movl -0xdc(%rbp), %eax
subl $0x5, %eax
je 0x4e76
jmp 0x4e5a
movq -0xd0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x4e8c
movq -0xd0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x4e8c
movq -0xd0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x4e8c
movq %rax, %rdi
callq 0x56c0
cmpl $0x0, -0x5c(%rbp)
jne 0x4f30
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x68(%rbp)
movl $0x5, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl -0x6c(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x56f0
movl %eax, -0xe0(%rbp)
jmp 0x4ecc
movl -0xe0(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xec(%rbp)
decl %eax
subl $0x2, %eax
jb 0x4f02
jmp 0x4ee7
movl -0xec(%rbp), %eax
subl $0x5, %eax
je 0x4f10
jmp 0x4ef4
movq -0xe8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x4f26
movq -0xe8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x4f26
movq -0xe8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x4f26
movq %rax, %rdi
callq 0x56c0
cmpl $0x0, -0x74(%rbp)
je 0x523a
movq -0xd8(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movl $0x5, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x100(%rbp)
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %ecx
movl %ecx, -0x44(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0xf8(%rbp)
subl $0x4, %eax
ja 0x4f88
movq -0xf8(%rbp), %rax
leaq 0x1b0d5(%rip), %rcx     # 0x20054
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x100(%rbp), %rcx
movl -0x44(%rbp), %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x48(%rbp)
jmp 0x4fe5
movq -0x100(%rbp), %rcx
movl -0x44(%rbp), %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x48(%rbp)
jmp 0x4fe5
movq -0x100(%rbp), %rcx
movl -0x44(%rbp), %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x48(%rbp)
jmp 0x4fe5
movq -0x100(%rbp), %rcx
movl -0x44(%rbp), %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x48(%rbp)
jmp 0x4fe5
movq -0x100(%rbp), %rcx
movl -0x44(%rbp), %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x48(%rbp)
movq -0xd8(%rbp), %rdi
addq $0x68, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4090
movq -0xd8(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x5, -0x84(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x84(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x56f0
movl %eax, -0x104(%rbp)
jmp 0x5034
movl -0x104(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x114(%rbp)
decl %eax
subl $0x2, %eax
jb 0x5073
jmp 0x5055
movl -0x114(%rbp), %eax
subl $0x5, %eax
je 0x5084
jmp 0x5062
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x509d
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x509d
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x509d
movq %rax, %rdi
callq 0x56c0
movb $0x1, %al
cmpl $0x0, -0x8c(%rbp)
movb %al, -0x115(%rbp)
jne 0x516d
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x98(%rbp)
movl $0x5, -0x9c(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0x9c(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x56f0
movl %eax, -0x11c(%rbp)
jmp 0x50f4
movl -0x11c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x12c(%rbp)
decl %eax
subl $0x2, %eax
jb 0x5133
jmp 0x5115
movl -0x12c(%rbp), %eax
subl $0x5, %eax
je 0x5144
jmp 0x5122
movq -0x128(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x515d
movq -0x128(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x515d
movq -0x128(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x515d
movq %rax, %rdi
callq 0x56c0
cmpl $0x0, -0xa4(%rbp)
setne %al
movb %al, -0x115(%rbp)
movb -0x115(%rbp), %al
testb $0x1, %al
jne 0x4fe5
movq -0xd8(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x5, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0x28(%rbp), %eax
movl -0x24(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x138(%rbp)
subl $0x4, %eax
ja 0x51d3
movq -0x138(%rbp), %rax
leaq 0x1ae9e(%rip), %rcx     # 0x20068
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x140(%rbp), %rcx
movl -0x2c(%rbp), %eax
negl %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x30(%rbp)
jmp 0x523a
movq -0x140(%rbp), %rcx
movl -0x2c(%rbp), %eax
negl %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x30(%rbp)
jmp 0x523a
movq -0x140(%rbp), %rcx
movl -0x2c(%rbp), %eax
negl %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x30(%rbp)
jmp 0x523a
movq -0x140(%rbp), %rcx
movl -0x2c(%rbp), %eax
negl %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x30(%rbp)
jmp 0x523a
movq -0x140(%rbp), %rcx
movl -0x2c(%rbp), %eax
negl %eax
lock
xaddl %eax, (%rcx)
movl %eax, -0x30(%rbp)
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0xc(%rbp)
movl $0x5, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x10(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x56f0
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x144(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, -0x18(%rbp)
subl $0x3, %eax
je 0x52a3
jmp 0x5288
movl -0x144(%rbp), %eax
subl $0x5, %eax
je 0x52b1
jmp 0x5295
movq -0x150(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x52bd
movq -0x150(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x52bd
movq -0x150(%rbp), %rcx
movl -0x18(%rbp), %eax
xchgl %eax, (%rcx)
leaq -0xc0(%rbp), %rdi
callq 0x55a0
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)