// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
movq %rdi, %rbx
movq 0x178(%rsi), %rdi
testq %rdi, %rdi
je 0x11f10
callq 0x1700a
movq 0x1a0(%r13), %r15
movq 0x1c0(%r13), %r14
cmpq %r15, %r14
je 0x11fb1
movq %rbx, -0x40(%rbp)
leaq 0x190(%r13), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r12
andq $0x0, 0x10(%r12)
movaps %xmm0, (%r12)
movq 0x1b0(%r13), %rbx
movq %r13, -0x48(%rbp)
movq 0x1b8(%r13), %rax
movq %rax, -0x30(%rbp)
pushq $0x2
popq %r13
cmpq %r14, %r15
je 0x11f97
movq (%r15), %rsi
movq %r12, %rdi
movl %r13d, %edx
callq 0x16d24
addq $0x8, %r15
cmpq %rbx, %r15
jne 0x11f62
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r15
addq $0x8, %rax
movq %rax, -0x30(%rbp)
leaq 0x200(%r15), %rbx
jmp 0x11f62
movq -0x38(%rbp), %rdi
callq 0x13574
leaq -0x70(%rbp), %rdi
callq 0xd2dc
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rbx
cmpl $0x4, 0xcc(%r13)
jne 0x12043
cmpl $0x0, 0xe8(%r13)
je 0x12043
leaq 0xe0(%r13), %rsi
movl $0x20128, %r15d         # imm = 0x20128
addq 0x18(%rbx), %r15
leaq -0x70(%rbp), %r12
pushq $-0x1
popq %rdx
movq %r12, %rdi
callq 0xd636
movq %r15, %rdi
movq %r12, %rsi
callq 0x14a7e
movq %rax, %r15
leaq -0x70(%rbp), %rdi
callq 0xa130
movq 0x18(%rbx), %rdi
leaq 0x20130(%rdi), %rax
cmpq %rax, %r15
je 0x12043
movl $0x20158, %r12d         # imm = 0x20158
addq %r12, %rdi
callq 0xd764
movl $0x20128, %edi          # imm = 0x20128
addq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x162f4
addq 0x18(%rbx), %r12
movq %r12, %rdi
callq 0xa220
movq %r13, %rdi
callq 0xa84c
cmpb $0x1, 0xf0(%r13)
jne 0x120e8
cmpb $0x1, 0xf1(%r13)
jne 0x120a5
cmpl $0x2, 0xcc(%r13)
movq 0x120(%r13), %rdi
jne 0x120e3
testq %rdi, %rdi
je 0x120f7
cmpl $-0x1, (%rdi)
je 0x1209c
addq $0x18, %rdi
leaq 0x757e(%rip), %rsi      # 0x19603
callq 0xb93e
pushq $-0x1
popq %rsi
movq %rax, %rdi
callq 0xb9b2
movq 0x120(%r13), %rdi
andl $0x0, 0xcc(%rdi)
jmp 0x120d4
movq 0x120(%r13), %rax
testq %rax, %rax
je 0x120e8
movq 0xe0(%rax), %rsi
movl 0xe8(%rax), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x12c96
movq 0x120(%r13), %rdi
testq %rdi, %rdi
je 0x120e8
callq 0xa84c
andq $0x0, 0x120(%r13)
jmp 0x120e8
testq %rdi, %rdi
jne 0x12126
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %r14
leaq 0x7557(%rip), %rsi      # 0x19660
leaq 0x70e6(%rip), %rdx      # 0x191f6
leaq 0x7553(%rip), %r8       # 0x1966a
movq %rax, %rdi
movl $0x3d4, %ecx            # imm = 0x3D4
callq 0xe15c
jmp 0x12153
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %r14
leaq 0x7556(%rip), %rsi      # 0x1968e
leaq 0x70b7(%rip), %rdx      # 0x191f6
leaq 0x7524(%rip), %r8       # 0x1966a
movq %rax, %rdi
movl $0x3d7, %ecx            # imm = 0x3D7
callq 0xe15c
leaq 0xdbbe(%rip), %rsi      # 0x1fd18
leaq -0x3c4b(%rip), %rdx     # 0xe516
movq %r14, %rdi
callq 0xa450
jmp 0x1216b
movq %rax, %rbx
movq %r14, %rdi
callq 0xa200
jmp 0x12192
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0xa130
jmp 0x12192
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0xd2dc
movq %rbx, %rdi
callq 0xa470