// File: /workspace/github_c_makefile_star2_O3/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 0x6562
movslq %eax, %rdx
movq 0x88(%rbx), %rsi
imulq $0x38, %rdx, %rdx
cmpq $0x0, 0x18(%rsi,%rdx)
jne 0x6562
incl %eax
movl %eax, 0x98(%rbx)
xorl %ebp, %ebp
cmpl %ecx, %eax
jge 0x6650
cltq
imulq $0x38, %rax, %r14
addq 0x88(%rbx), %r14
movl (%rbx), %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
jle 0x65e5
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x6d48(%rip), %rdx      # 0xd2e0
addq %rcx, 0x50(%rdx)
movq 0x18(%r14), %rcx
testq %rcx, %rcx
je 0x65d1
movq 0x10(%r14), %rdx
addq $0x10, %rdx
decq %rcx
movl %eax, %esi
subl -0x8(%rdx), %eax
jl 0x65cb
movq %rcx, 0x18(%r14)
movq %rdx, 0x10(%r14)
addq $0x10, %rdx
movl %eax, %esi
addq $-0x1, %rcx
jb 0x65b0
movl %esi, %eax
testl %esi, %esi
jle 0x65de
movq 0x10(%r14), %rcx
movl %eax, %eax
addq %rax, (%rcx)
subq %rax, 0x8(%rcx)
movl $0x1, %ebp
jmp 0x6650
cmpl $-0x1, %eax
jne 0x661e
callq 0x2040
cmpl $0xb, (%rax)
jne 0x661e
movl $0x2, %ebp
movq %rbx, %rdi
movl $0x2, %esi
callq 0x64bd
testl %eax, %eax
jne 0x6650
leaq 0x6c77(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jle 0x663e
callq 0x25f2
jmp 0x663e
leaq 0x6c63(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jg 0x6657
cmpl $0x0, 0xbc(%rbx)
je 0x663e
movq %rbx, %rdi
movl $0x1, %esi
jmp 0x6646
movq %rbx, %rdi
movl $0x5, %esi
callq 0x4189
movl $0x3, %ebp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x25d6
jmp 0x662b