// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/http_proxy.c
// Function: tcp_out
void tcp_out(conn_t * to)
{
    conn_t *from;
    int write_len;

    if (to->fd == -1)
        return;
    else if ((to - cts) & 1)
        from = to - 1;
    else
        from = to + 1;
    from->timer = to->timer = 0;

    write_len = write(to->fd, from->ready_data + from->sent_len, from->ready_data_len - from->sent_len);
    if (write_len == from->ready_data_len - from->sent_len) {
        //服务端的数据可能没全部写入到客户端
        if ((from - cts) & 1) {
            serverToClient(from);
            if (from->fd >= 0 && from->ready_data_len == 0) {
                ev.events = EPOLLIN | EPOLLET;
                ev.data.ptr = to;
                epoll_ctl(epollfd, EPOLL_CTL_MOD, to->fd, &ev);
            }
        } else {
            ev.events = EPOLLIN | EPOLLET;
            ev.data.ptr = to;
            epoll_ctl(epollfd, EPOLL_CTL_MOD, to->fd, &ev);
            free(from->ready_data);
            from->ready_data = NULL;
            from->ready_data_len = 0;
        }
    } else if (write_len > 0) {
        from->sent_len += write_len;
        ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
        ev.data.ptr = to;
        epoll_ctl(epollfd, EPOLL_CTL_MOD, to->fd, &ev);
    } else if (errno != EAGAIN) {
        close_connection(to);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x10(%rax)
jne 0x4a5b
jmp 0x4c42
movq -0x8(%rbp), %rax
leaq 0xaa0a(%rip), %rcx      # 0xf470
subq %rcx, %rax
movl $0x28, %ecx
cqto
idivq %rcx
andq $0x1, %rax
cmpq $0x0, %rax
je 0x4a8b
movq -0x8(%rbp), %rax
addq $-0x28, %rax
movq %rax, -0x10(%rbp)
jmp 0x4a97
movq -0x8(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x10(%rbp)
jmp 0x4a99
movq -0x8(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x1c(%rax), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x1c(%rcx), %eax
movslq %eax, %rdx
callq 0x20d0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x10(%rbp), %rdx
subl 0x1c(%rdx), %ecx
cmpl %ecx, %eax
jne 0x4bd9
movq -0x10(%rbp), %rax
leaq 0xa96b(%rip), %rcx      # 0xf470
subq %rcx, %rax
movl $0x28, %ecx
cqto
idivq %rcx
andq $0x1, %rax
cmpq $0x0, %rax
je 0x4b78
movq -0x10(%rbp), %rdi
callq 0x4540
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x4b76
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x4b76
leaq 0x1489c(%rip), %rax     # 0x193dc
movl $0x80000001, (%rax)     # imm = 0x80000001
movq -0x8(%rbp), %rcx
leaq 0x1488b(%rip), %rax     # 0x193dc
movq %rcx, 0x4(%rax)
leaq 0x14878(%rip), %rax     # 0x193d4
movl (%rax), %edi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x3, %esi
leaq 0x1486b(%rip), %rcx     # 0x193dc
callq 0x2240
jmp 0x4bd7
leaq 0x1485d(%rip), %rax     # 0x193dc
movl $0x80000001, (%rax)     # imm = 0x80000001
movq -0x8(%rbp), %rcx
leaq 0x1484c(%rip), %rax     # 0x193dc
movq %rcx, 0x4(%rax)
leaq 0x14839(%rip), %rax     # 0x193d4
movl (%rax), %edi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x3, %esi
leaq 0x1482c(%rip), %rcx     # 0x193dc
callq 0x2240
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
jmp 0x4c42
cmpl $0x0, -0x14(%rbp)
jle 0x4c2b
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
leaq 0x147e9(%rip), %rax     # 0x193dc
movl $0x80000005, (%rax)     # imm = 0x80000005
movq -0x8(%rbp), %rcx
leaq 0x147d8(%rip), %rax     # 0x193dc
movq %rcx, 0x4(%rax)
leaq 0x147c5(%rip), %rax     # 0x193d4
movl (%rax), %edi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x3, %esi
leaq 0x147b8(%rip), %rcx     # 0x193dc
callq 0x2240
jmp 0x4c40
callq 0x2050
cmpl $0xb, (%rax)
je 0x4c3e
movq -0x8(%rbp), %rdi
callq 0x3f20
jmp 0x4c40
jmp 0x4c42
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)