// File: /workspace/github_c_makefile_star2_O1/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
movslq 0x98(%rdi), %rcx
movl 0x94(%rdi), %eax
cmpl %eax, %ecx
jge 0x65d8
movq 0x88(%rbx), %rdx
imulq $0x38, %rcx, %rsi
cmpq $0x0, 0x18(%rdx,%rsi)
jne 0x65d8
incl %ecx
movl %ecx, 0x98(%rbx)
movslq 0x98(%rbx), %rcx
xorl %ebp, %ebp
cmpl %eax, %ecx
jge 0x66d1
imulq $0x38, %rcx, %r14
addq 0x88(%rbx), %r14
movl (%rbx), %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
jle 0x664c
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x6ccd(%rip), %rdx      # 0xd2e0
addq %rcx, 0x50(%rdx)
movq 0x18(%r14), %rcx
testq %rcx, %rcx
je 0x66a5
movq 0x10(%r14), %rdx
addq $0x10, %rdx
decq %rcx
movl %eax, %esi
subl -0x8(%rdx), %eax
jl 0x66a7
movq %rcx, 0x18(%r14)
movq %rdx, 0x10(%r14)
addq $0x10, %rdx
movl %eax, %esi
addq $-0x1, %rcx
jb 0x662f
jmp 0x66a7
cmpl $-0x1, %eax
jne 0x6685
callq 0x2040
cmpl $0xb, (%rax)
jne 0x6685
movl $0x2, %ebp
movq %rbx, %rdi
movl $0x2, %esi
callq 0x6535
testl %eax, %eax
jne 0x66d1
leaq 0x6c10(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jle 0x66bf
callq 0x25f2
jmp 0x66bf
leaq 0x6bfc(%rip), %rax      # 0xd288
cmpl $0x0, 0x18(%rax)
jg 0x66d8
cmpl $0x0, 0xbc(%rbx)
je 0x66bf
movq %rbx, %rdi
movl $0x1, %esi
jmp 0x66c7
movl %eax, %esi
movl $0x1, %ebp
testl %esi, %esi
jle 0x66d1
movq 0x10(%r14), %rax
movl %esi, %ecx
addq %rcx, (%rax)
subq %rcx, 0x8(%rax)
jmp 0x66d1
movq %rbx, %rdi
movl $0x5, %esi
callq 0x41a2
movl $0x3, %ebp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x25d6
jmp 0x6692