// File: /workspace/github_c_makefile_star2_O0/zuocheng-liu[P]ae-memcached/src/connection.c
// Function: add_iov
int add_iov(conn *c, const void *buf, int len) {
    struct msghdr *m;
    int leftover;
    int limit_to_mtu;

    do {
        m = &c->msglist[c->msgused - 1];

        /*
         * Limit UDP packets, and the first payloads of TCP replies, to
         * UDP_MAX_PAYLOAD_SIZE bytes.
         */
        limit_to_mtu = c->udp || (1 == c->msgused);

        /* We may need to start a new msghdr if this one is full. */
        if (m->msg_iovlen == IOV_MAX ||
                (limit_to_mtu && c->msgbytes >= UDP_MAX_PAYLOAD_SIZE)) {
            add_msghdr(c);
            m = &c->msglist[c->msgused - 1];
        }

        if (ensure_iov_space(c))
            return -1;

        /* If the fragment is too big to fit in the datagram, split it up */
        if (limit_to_mtu && len + c->msgbytes > UDP_MAX_PAYLOAD_SIZE) {
            leftover = len + c->msgbytes - UDP_MAX_PAYLOAD_SIZE;
            len -= leftover;
        } else {
            leftover = 0;
        }

        m = &c->msglist[c->msgused - 1];
        m->msg_iov[m->msg_iovlen].iov_base = (void*) buf;
        m->msg_iov[m->msg_iovlen].iov_len = len;

        c->msgbytes += len;
        c->iovused++;
        m->msg_iovlen++;

        buf = ((char *)buf) + len;
        len = leftover;
    } while (leftover > 0);

    return 0;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rsp), %rcx
movl 0x94(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rcx
movb $0x1, %al
cmpl $0x0, 0xbc(%rcx)
movb %al, 0x7(%rsp)
jne 0x5116
movq 0x28(%rsp), %rcx
movl $0x1, %eax
cmpl 0x94(%rcx), %eax
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x400, 0x18(%rax)      # imm = 0x400
je 0x514a
cmpl $0x0, 0x8(%rsp)
je 0x517d
movq 0x28(%rsp), %rax
cmpl $0x578, 0x9c(%rax)      # imm = 0x578
jl 0x517d
movq 0x28(%rsp), %rdi
callq 0x52d0
movq 0x28(%rsp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rsp), %rcx
movl 0x94(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movb $0x0, %al
callq 0x6800
cmpl $0x0, %eax
je 0x519b
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x52bb
cmpl $0x0, 0x8(%rsp)
je 0x51e0
movl 0x1c(%rsp), %eax
movq 0x28(%rsp), %rcx
addl 0x9c(%rcx), %eax
cmpl $0x578, %eax            # imm = 0x578
jle 0x51e0
movl 0x1c(%rsp), %eax
movq 0x28(%rsp), %rcx
addl 0x9c(%rcx), %eax
subl $0x578, %eax            # imm = 0x578
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %ecx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x1c(%rsp)
jmp 0x51e8
movl $0x0, 0xc(%rsp)
movq 0x28(%rsp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rsp), %rcx
movl 0x94(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq 0x1c(%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl 0x1c(%rsp), %ecx
movq 0x28(%rsp), %rax
addl 0x9c(%rax), %ecx
movl %ecx, 0x9c(%rax)
movq 0x28(%rsp), %rax
movl 0x84(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x84(%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rax
movslq 0x1c(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0xc(%rsp)
jg 0x50c2
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)