// File: /workspace/github_cpp_makefile_star2_O3/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 0x11a20
callq 0x16a90
movq 0x1a0(%rbx), %r14
movq 0x1c0(%rbx), %r13
cmpq %r14, %r13
je 0x11ab7
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 0x167b2
addq $0x8, %r14
cmpq %rbx, %r14
jne 0x11a98
movq 0x8(%r15), %r14
addq $0x8, %r15
leaq 0x200(%r14), %rbx
cmpq %r13, %r14
jne 0x11a70
movq -0x58(%rbp), %rdi
callq 0x13432
leaq -0x50(%rbp), %rdi
callq 0xc194
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r12
cmpl $0x4, 0xcc(%rbx)
jne 0x11b6e
cmpl $0x0, 0xe8(%rbx)
je 0x11b6e
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 0xc49c
movq %r15, %rdi
movq %r12, %rsi
callq 0x1446a
movq %rax, %r15
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11b1e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x8320
movq %r14, %r12
movq 0x18(%r14), %rdi
leaq 0x20130(%rdi), %rax
cmpq %rax, %r15
je 0x11b6e
addq $0x20158, %rdi          # imm = 0x20158
callq 0x83f0
testl %eax, %eax
jne 0x11c27
movl $0x20128, %edi          # imm = 0x20128
addq 0x18(%r12), %rdi
movq %r15, %rsi
callq 0x15bf8
movl $0x20158, %edi          # imm = 0x20158
addq 0x18(%r12), %rdi
callq 0x8240
movq %rbx, %rdi
callq 0x898c
cmpb $0x1, 0xf0(%rbx)
jne 0x11c18
cmpb $0x1, 0xf1(%rbx)
jne 0x11bd2
cmpl $0x2, 0xcc(%rbx)
movq 0x120(%rbx), %rdi
jne 0x11c13
testq %rdi, %rdi
je 0x11c2e
cmpl $-0x1, (%rdi)
je 0x11bc6
addq $0x18, %rdi
leaq 0x6a52(%rip), %rsi      # 0x185ff
callq 0x9ec6
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x9f3a
movq 0x120(%rbx), %rdi
movl $0x0, 0xcc(%rdi)
jmp 0x11c01
movq 0x120(%rbx), %rax
testq %rax, %rax
je 0x11c18
movq 0xe0(%rax), %rsi
movl 0xe8(%rax), %edx
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x12ada
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x11c18
callq 0x898c
movq $0x0, 0x120(%rbx)
jmp 0x11c18
testq %rdi, %rdi
jne 0x11c5f
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 0x6a1a(%rip), %rsi      # 0x1865c
leaq 0x65a9(%rip), %rdx      # 0x181f2
leaq 0x6a16(%rip), %r8       # 0x18666
movq %rax, %rdi
movl $0x3d4, %ecx            # imm = 0x3D4
callq 0xcd04
jmp 0x11c8e
movl $0x30, %edi
callq 0x8170
movq %rax, %r14
leaq 0x6a17(%rip), %rsi      # 0x1868a
leaq 0x6578(%rip), %rdx      # 0x181f2
leaq 0x69e5(%rip), %r8       # 0x18666
movq %rax, %rdi
movl $0x3d7, %ecx            # imm = 0x3D7
callq 0xcd04
leaq 0xc083(%rip), %rsi      # 0x1dd18
leaq -0x498c(%rip), %rdx     # 0xd310
movq %r14, %rdi
callq 0x8480
jmp 0x11ca6
movq %rax, %rbx
movq %r14, %rdi
callq 0x8220
jmp 0x11cdd
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11cdd
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x8320
jmp 0x11cdd
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xc194
movq %rbx, %rdi
callq 0x84a0
nop