// File: /workspace/github_cpp_makefile_star2_O1/lega911[P]ijson/src/server.cpp
// Function: Loop::on_disconnect(Connect*)
void Loop::on_disconnect(Connect *conn) {
    if(conn->worker_item) conn->worker_item->pop();

    if(!conn->direct_message.empty()) {
        GC gc;
        for(auto const &it : conn->direct_message) {
            gc.add(it, GC::DirectMessage);
        }
        conn->direct_message.clear();
    }

    if(conn->status == Status::client_wait_result && !conn->id.empty()) {
        auto it = server->wait_response.find(conn->id.as_string());
        if(it != server->wait_response.end()) {
            server->wait_lock.lock();
            server->wait_response.erase(it);
            server->wait_lock.unlock();
            conn->unlink();
        }
    };
    if(!conn->fail_on_disconnect) return;
    if(conn->noid) {
        if(conn->status == Status::worker_wait_result) {
            if(!conn->client) THROW("No client");
            if(!conn->client->is_closed()) conn->client->send.status("503 Service Unavailable")->done(-1);
            conn->client->status = Status::net;
        } else if(conn->client) THROW("Client is linked to pending worker");
    } else if(conn->client) {
        worker_result(conn->client->id, NULL);
    }
    if(conn->client) {
        conn->client->unlink();
        conn->client = NULL;
    };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r12
movq 0x178(%rsi), %rdi
testq %rdi, %rdi
je 0x11b56
callq 0x16bbc
movq 0x1a0(%rbx), %r14
movq 0x1c0(%rbx), %r13
cmpq %r14, %r13
je 0x11bed
movq %r12, -0x60(%rbp)
leaq 0x190(%rbx), %rax
movq %rax, -0x58(%rbp)
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r12
movaps %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movq %rbx, %rax
movq 0x1b0(%rbx), %rbx
movq %rax, -0x68(%rbp)
movq 0x1b8(%rax), %r15
movq (%r14), %rsi
movq %r12, %rdi
movl $0x2, %edx
callq 0x168de
addq $0x8, %r14
cmpq %rbx, %r14
jne 0x11bce
movq 0x8(%r15), %r14
addq $0x8, %r15
leaq 0x200(%r14), %rbx
cmpq %r13, %r14
jne 0x11ba6
movq -0x58(%rbp), %rdi
callq 0x13576
leaq -0x50(%rbp), %rdi
callq 0xc13a
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r12
cmpl $0x4, 0xcc(%rbx)
jne 0x11ca4
cmpl $0x0, 0xe8(%rbx)
je 0x11ca4
leaq 0xe0(%rbx), %rsi
movl $0x20128, %r15d         # imm = 0x20128
movq %r12, %r14
addq 0x18(%r12), %r15
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xc468
movq %r15, %rdi
movq %r12, %rsi
callq 0x14586
movq %rax, %r15
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11c54
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x8320
movq %r14, %r12
movq 0x18(%r14), %rdi
leaq 0x20130(%rdi), %rax
cmpq %rax, %r15
je 0x11ca4
addq $0x20158, %rdi          # imm = 0x20158
callq 0x83f0
testl %eax, %eax
jne 0x11d5d
movl $0x20128, %edi          # imm = 0x20128
addq 0x18(%r12), %rdi
movq %r15, %rsi
callq 0x15d14
movl $0x20158, %edi          # imm = 0x20158
addq 0x18(%r12), %rdi
callq 0x8240
movq %rbx, %rdi
callq 0x898c
cmpb $0x1, 0xf0(%rbx)
jne 0x11d4e
cmpb $0x1, 0xf1(%rbx)
jne 0x11d08
cmpl $0x2, 0xcc(%rbx)
movq 0x120(%rbx), %rdi
jne 0x11d2d
testq %rdi, %rdi
je 0x11d64
cmpl $-0x1, (%rdi)
je 0x11cf5
addq $0x18, %rdi
leaq 0x691c(%rip), %rsi      # 0x185ff
callq 0x9ee0
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x9f54
movq 0x120(%rbx), %rax
movl $0x0, 0xcc(%rax)
jmp 0x11d32
movq 0x120(%rbx), %rax
testq %rax, %rax
je 0x11d32
movq 0xe0(%rax), %rsi
movl 0xe8(%rax), %edx
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x12c1e
jmp 0x11d32
testq %rdi, %rdi
jne 0x11d95
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x11d4e
callq 0x898c
movq $0x0, 0x120(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x81d0
movl $0x30, %edi
callq 0x8170
movq %rax, %r14
leaq 0x68e4(%rip), %rsi      # 0x1865c
leaq 0x6473(%rip), %rdx      # 0x181f2
leaq 0x68e0(%rip), %r8       # 0x18666
movq %rax, %rdi
movl $0x3d4, %ecx            # imm = 0x3D4
callq 0xcd04
jmp 0x11dc4
movl $0x30, %edi
callq 0x8170
movq %rax, %r14
leaq 0x68e1(%rip), %rsi      # 0x1868a
leaq 0x6442(%rip), %rdx      # 0x181f2
leaq 0x68af(%rip), %r8       # 0x18666
movq %rax, %rdi
movl $0x3d7, %ecx            # imm = 0x3D7
callq 0xcd04
leaq 0xbf4d(%rip), %rsi      # 0x1dd18
leaq -0x4ac2(%rip), %rdx     # 0xd310
movq %r14, %rdi
callq 0x8480
jmp 0x11ddc
movq %rax, %rbx
movq %r14, %rdi
callq 0x8220
jmp 0x11e13
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11e13
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x8320
jmp 0x11e13
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xc13a
movq %rbx, %rdi
callq 0x84a0
nop