// File: /workspace/github_cpp_makefile_star2_O2/qian-jiahong[P]uvncrep017-ws/repeater.cpp
// Function: connectionRemover(int, _repeaterInfo*, int)
static void connectionRemover(int connectionFrom, repeaterInfo *rI, int index)
{
    bool fRemove;
    char removalReason[MY_TMP_BUF_LEN];
    
    fRemove = false;
    strlcpy(removalReason, "", MY_TMP_BUF_LEN);

     
    if (isExistingConnectionInactive(rI -> active, (rI -> code != 0))) {
        if (isConnectionTooOld(rI -> timeStamp)) {
            //Existing connection has been idle for too long, remove
            fRemove = true;
            snprintf(removalReason, MY_TMP_BUF_LEN, "%s", "idle connection too old");
        }
        else if (isPeerDisconnected(rI -> socket, connectionFrom)) {
            //Peer has closed the connection before another peer appeared, remove
            fRemove = true;
            snprintf(removalReason, MY_TMP_BUF_LEN, "%s", "peer has disconnected");
        }

        if (fRemove) {
            //Send VIEWER_DISCONNECT / SERVER_DISCONNECT to event interface
            if (useEventInterface) {
                repeaterEvent event;
                connectionEvent connEv;
                            
                event.eventNum = (connectionFrom == CONNECTION_FROM_VIEWER) ? VIEWER_DISCONNECT : SERVER_DISCONNECT;
                event.timeStamp = time(NULL);
                event.repeaterProcessId = getpid();

                connEv.tableIndex = index;
                connEv.code = rI -> code;
                connEv.connMode = (rI -> code < 0) ? CONN_MODE1 : CONN_MODE2;
                connEv.peerIp = rI -> peerIp;
                memcpy(event.extraInfo, &connEv, sizeof(connectionEvent));
                
                if (false == sendRepeaterEvent(event)) {
                    debug(LEVEL_1, "connectionRemover(): Warning, event fifo is full\n");
                }
            }

            //Remove & close connection 
            close(rI -> socket);
            debug(LEVEL_1, "connectionRemover(): Removing %s %ld at index %d (%s)\n", 
                (connectionFrom == CONNECTION_FROM_VIEWER) ? "viewer" : "server",
                rI -> code, 
                index,
                removalReason);
            
            if (connectionFrom == CONNECTION_FROM_VIEWER)
                removeViewerList(rI -> code);
            else
                removeServerList(rI -> code);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movl %edx, %ebp
movq %rsi, %r14
movl %edi, %ebx
leaq 0x36b9(%rip), %rsi      # 0x85da
leaq 0x80(%rsp), %rdi
movl $0xff, %edx
callq 0x553a
cmpq $0x0, 0x8(%r14)
je 0x507c
cmpb $0x0, 0x28(%r14)
jne 0x507c
movq 0x10(%r14), %rdi
callq 0x2a7a
testb %al, %al
je 0x4f79
movups 0x3d7a(%rip), %xmm0     # 0x8cd7
movaps %xmm0, 0x80(%rsp)
movabsq $0x646c6f206f6f74, %rax # imm = 0x646C6F206F6F74
movq %rax, 0x90(%rsp)
jmp 0x4faa
movl (%r14), %edi
callq 0x2a9b
testb %al, %al
je 0x507c
movups 0x3d5f(%rip), %xmm0     # 0x8cef
movaps %xmm0, 0x80(%rsp)
movabsq $0x64657463656e6e, %rax # imm = 0x64657463656E6E
movq %rax, 0x8e(%rsp)
leaq 0x10313(%rip), %rax     # 0x152c4
cmpb $0x1, (%rax)
jne 0x502a
xorl %eax, %eax
cmpl $0x1, %ebx
setne %al
leal 0x1(,%rax,2), %r12d
xorl %edi, %edi
callq 0x21c0
movq %rax, %r15
callq 0x22f0
movq 0x8(%r14), %rcx
movups 0x18(%r14), %xmm0
leaq 0x188(%rsp), %rsi
movups %xmm0, 0x28(%rsi)
movl %r12d, (%rsi)
movq %r15, 0x8(%rsi)
movl %eax, 0x10(%rsi)
movl %ebp, 0x14(%rsi)
movq %rcx, 0x1c(%rsi)
shrq $0x3f, %rcx
pushq $0x2
popq %rax
subl %ecx, %eax
movl %eax, 0x24(%rsi)
pushq $0xf
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x6478
testb %al, %al
jne 0x502a
leaq 0x3ce5(%rip), %rsi      # 0x8d05
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x247c
movl (%r14), %edi
callq 0x2370
cmpl $0x1, %ebx
leaq 0x3699(%rip), %rax      # 0x86d5
leaq 0x43d1(%rip), %rdx      # 0x9414
cmoveq %rax, %rdx
movq 0x8(%r14), %rcx
leaq 0x3ce5(%rip), %rsi      # 0x8d37
pushq $0x1
popq %rdi
leaq 0x80(%rsp), %r9
movl %ebp, %r8d
xorl %eax, %eax
callq 0x247c
movq 0x8(%r14), %rdi
cmpl $0x1, %ebx
jne 0x5077
callq 0x508c
jmp 0x507c
callq 0x50ef
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq