// File: /workspace/github_cpp_makefile_star2_O1/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 0x3455(%rip), %rsi      # 0x85da
leaq 0x80(%rsp), %rdi
movl $0xff, %edx
callq 0x5844
cmpq $0x0, 0x8(%r14)
je 0x52f1
cmpb $0x0, 0x28(%r14)
jne 0x52f1
movq 0x10(%r14), %r15
xorl %edi, %edi
callq 0x21c0
subq %r15, %rax
cmpq $0x259, %rax            # imm = 0x259
jb 0x51e6
movups 0x3b0d(%rip), %xmm0     # 0x8cd7
movaps %xmm0, 0x80(%rsp)
movabsq $0x646c6f206f6f74, %rax # imm = 0x646C6F206F6F74
movq %rax, 0x90(%rsp)
jmp 0x5217
movl (%r14), %edi
callq 0x3ab4
testb %al, %al
je 0x52f1
movups 0x3af2(%rip), %xmm0     # 0x8cef
movaps %xmm0, 0x80(%rsp)
movabsq $0x64657463656e6e, %rax # imm = 0x64657463656E6E
movq %rax, 0x8e(%rsp)
leaq 0x100a6(%rip), %rax     # 0x152c4
cmpb $0x1, (%rax)
jne 0x529d
xorl %eax, %eax
cmpl $0x1, %ebx
setne %al
leal 0x1(,%rax,2), %r12d
xorl %edi, %edi
callq 0x21c0
movq %rax, %r15
callq 0x22e0
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
movl $0x2, %eax
subl %ecx, %eax
movl %eax, 0x24(%rsi)
movl $0xf, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x6849
testb %al, %al
jne 0x529d
leaq 0x3a74(%rip), %rsi      # 0x8d05
movl $0x1, %edi
xorl %eax, %eax
callq 0x355c
movl (%r14), %edi
callq 0x2360
cmpl $0x1, %ebx
leaq 0x3426(%rip), %rax      # 0x86d5
leaq 0x415e(%rip), %rdx      # 0x9414
cmoveq %rax, %rdx
movq 0x8(%r14), %rcx
leaq 0x3a72(%rip), %rsi      # 0x8d37
leaq 0x80(%rsp), %r9
movl $0x1, %edi
movl %ebp, %r8d
xorl %eax, %eax
callq 0x355c
movq 0x8(%r14), %rdi
cmpl $0x1, %ebx
jne 0x52ec
callq 0x5301
jmp 0x52f1
callq 0x536a
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq