// File: /workspace/github_c_makefile_star2_O2/zuocheng-liu[P]ae-memcached/src/memcached.c
// Function: transmit
int transmit(conn *c) {
    int res;

    if (c->msgcurr < c->msgused &&
            c->msglist[c->msgcurr].msg_iovlen == 0) {
        /* Finished writing the current msg; advance to the next. */
        c->msgcurr++;
    }
    if (c->msgcurr < c->msgused) {
        struct msghdr *m = &c->msglist[c->msgcurr];
        res = sendmsg(c->sfd, m, 0);
        if (res > 0) {
            stats.bytes_written += res;

            /* We've written some of the data. Remove the completed
               iovec entries from the list of pending writes. */
            while (m->msg_iovlen > 0 && res >= (int)(m->msg_iov->iov_len)) {
                res -= m->msg_iov->iov_len;
                m->msg_iovlen--;
                m->msg_iov++;
            }

            /* Might have written just part of the last iovec entry;
               adjust it so the next write will do the rest. */
            if (res > 0) {
                m->msg_iov->iov_base += res;
                m->msg_iov->iov_len -= res;
            }
            return TRANSMIT_INCOMPLETE;
        }
        if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
            if (!update_event(c, AE_WRITABLE)) {
                LOG_INFO("Couldn't update event\n");
                conn_set_state(c, conn_closing);
                return TRANSMIT_HARD_ERROR;
            }
            return TRANSMIT_SOFT_ERROR;
        }
        /* if res==0 or res==-1 and error is not EAGAIN or EWOULDBLOCK,
           we have a real error, on which we close the connection */
        LOG_INFO("Failed to write, and not due to blocking\n");

        if (c->udp)
            conn_set_state(c, conn_read);
        else
            conn_set_state(c, conn_closing);
        return TRANSMIT_HARD_ERROR;
    } else {
        return TRANSMIT_COMPLETE;
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x94(%rdi), %ecx
movl 0x98(%rdi), %eax
cmpl %ecx, %eax
jge 0x5b75
movslq %eax, %rdx
movq 0x88(%rbx), %rsi
imulq $0x38, %rdx, %rdx
cmpq $0x0, 0x18(%rsi,%rdx)
jne 0x5b75
incl %eax
movl %eax, 0x98(%rbx)
xorl %ebp, %ebp
cmpl %ecx, %eax
jge 0x5c67
cltq
imulq $0x38, %rax, %r14
addq 0x88(%rbx), %r14
movl (%rbx), %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
jle 0x5bf4
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x7735(%rip), %rdx      # 0xd2e0
addq %rcx, 0x50(%rdx)
movq 0x18(%r14), %rcx
decq %rcx
cmpq $-0x1, %rcx
je 0x5bda
movq 0x10(%r14), %rsi
movl %eax, %edx
subl 0x8(%rsi), %edx
jl 0x5bda
movq %rcx, 0x18(%r14)
addq $0x10, %rsi
movq %rsi, 0x10(%r14)
decq %rcx
movl %edx, %eax
jmp 0x5bb6
pushq $0x1
popq %rbp
testl %eax, %eax
jle 0x5c67
movq 0x10(%r14), %rcx
movl %eax, %eax
addq %rax, (%rcx)
subq %rax, 0x8(%rcx)
jmp 0x5c67
cmpl $-0x1, %eax
jne 0x5c3f
callq 0x2040
cmpl $0xb, (%rax)
jne 0x5c3f
pushq $0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5abc
testl %eax, %eax
jne 0x5c67
leaq 0x766d(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jle 0x5c59
movq 0x73d0(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x2c6d(%rip), %rdi      # 0x889f
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2420
jmp 0x5c59
leaq 0x7642(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jg 0x5c6e
cmpl $0x0, 0xbc(%rbx)
je 0x5c59
pushq $0x1
jmp 0x5c5b
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x391f
pushq $0x3
popq %rbp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
movq 0x7383(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x2c37(%rip), %rdi      # 0x88b6
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x2420
jmp 0x5c4c