// File: renzibei[P]TSProxy/proxyserver.cpp
// Function: eraseHostFromFdSets(int, fd_set&, fd_set&, int&, int&, int&)
void eraseHostFromFdSets(int hostFd, fd_set &readSet, fd_set &writeSet, int &max_read_sd, int &max_write_sd, int &max_all_sd) {
    
    if (FD_ISSET(hostFd, &writeSet)) {
        close(hostFd);
        FD_CLR(hostFd, &writeSet);
        if (hostFd == max_write_sd) {
            while (FD_ISSET(max_write_sd, &writeSet) == 0 && max_write_sd > 0)
                max_write_sd -= 1;
        }
    }
    else {
        LogHelper::log(Warn, "hostFd :%d not in writeSet");
    }
    if (FD_ISSET(hostFd, &readSet)) {
        FD_CLR(hostFd, &readSet);
        if (hostFd == max_read_sd) {
            while (FD_ISSET(max_read_sd, &readSet) == 0)
                max_read_sd -= 1;
        }
    }
    else {
        LogHelper::log(Warn, "hostFd: %d not in readSet");
    }
    
    max_all_sd = std::max(max_read_sd, max_write_sd);
}

// Assembly:
subq $0x98, %rsp
movl %edi, 0x94(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x70(%rsp)
movq %r9, 0x68(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x58(%rsp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x60(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x60(%rsp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3a9b
movl 0x94(%rsp), %edi
callq 0x23a0
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
xorq $-0x1, %rax
movq %rax, 0x48(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x48(%rsp), %rdx
movl %eax, %ecx
movq 0x50(%rsp), %rax
movslq %ecx, %rcx
andq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl 0x94(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x3a99
jmp 0x3a03
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x30(%rsp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x38(%rsp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x47(%rsp)
jne 0x3a7c
movq 0x70(%rsp), %rax
cmpl $0x0, (%rax)
setg %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x3a86
jmp 0x3a97
movq 0x70(%rsp), %rax
movl (%rax), %ecx
subl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3a03
jmp 0x3a99
jmp 0x3aae
movl $0x1, %edi
leaq 0xcb01(%rip), %rsi      # 0x105a8
movb $0x0, %al
callq 0x28f0
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x28(%rsp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3be8
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
xorq $-0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x94(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x10(%rsp), %rdx
movl %eax, %ecx
movq 0x18(%rsp), %rax
movslq %ecx, %rcx
andq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl 0x94(%rsp), %eax
movq 0x78(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x3be6
jmp 0x3b74
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq 0x78(%rsp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq (%rsp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x78(%rsp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x8(%rsp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3be4
movq 0x78(%rsp), %rax
movl (%rax), %ecx
subl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3b74
jmp 0x3be6
jmp 0x3bfb
movl $0x1, %edi
leaq 0xc9cf(%rip), %rsi      # 0x105c3
movb $0x0, %al
callq 0x28f0
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x57c0
movl (%rax), %ecx
movq 0x68(%rsp), %rax
movl %ecx, (%rax)
addq $0x98, %rsp
retq
nopl (%rax,%rax)