// File: /workspace/github_c_makefile_star2_O1/xapi-project[P]rrd-client-lib/librrd.c
// Function: rrd_sample
int
rrd_sample(RRD_PLUGIN * plugin, time_t(*t) (time_t *))
{
    assert(plugin);
    int             n = 0;
    int64_t        *p;
    RRD_HEADER     *header;

    if (plugin->buf == NULL) {
        int             rc;
        rc = initialise(plugin);
        if (rc != 0) {
            return RRD_ERROR;
        }
    }
    assert(plugin->buf);
    header = (RRD_HEADER *) plugin->buf;

    /*
     * sample n sources and write values to buffer
     */
    p = (int64_t *) (plugin->buf + sizeof(RRD_HEADER));
    for (size_t i = 0; i < RRD_MAX_SOURCES; i++) {
        void *userdata;
        if (plugin->sources[i] == NULL)
            continue;
        userdata = plugin->sources[i]->userdata;

        rrd_value_t     v = plugin->sources[i]->sample(userdata);
        *p++ = htonll((uint64_t) v.int64);
        n++;
    }
    /*
     * must have sampled exactly n data sources
     */
    assert(n == plugin->n);

    /*
     * update timestamp, calculate crc
     */

    header->rrd_timestamp = htonll(bits_of_double(get_timestamp()));
    uint32_t        crc = crc32(0L, Z_NULL, 0);
    crc = crc32(crc,
                (unsigned char *)&header->rrd_timestamp,
                (n + 1) * sizeof(int64_t));
    header->rrd_checksum_value = htonl(crc);

    /*
     * reset file pointer, write out buffer
     */
    if (lseek(plugin->file, 0, SEEK_SET) < 0) {
        return RRD_FILE_ERROR;
    }
    if (write_exact(plugin->file, plugin->buf, plugin->buf_size) != 0) {
        return RRD_FILE_ERROR;
    }
    return RRD_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
testq %rdi, %rdi
je 0x2fc0
movq %rdi, %rbx
cmpq $0x0, 0x98(%rdi)
je 0x2f95
movq 0x98(%rbx), %r15
testq %r15, %r15
je 0x2fdf
leaq 0x1f(%r15), %r14
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%rbx,%r13,8), %rax
testq %rax, %rax
je 0x2eef
movq 0x38(%rax), %rdi
callq *0x30(%rax)
bswapq %rax
movq %rax, (%r14)
addq $0x8, %r14
incl %r12d
incq %r13
cmpq $0x10, %r13
jne 0x2ed1
cmpl 0xa4(%rbx), %r12d
jne 0x2ffe
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
cvtsi2sdq (%r14), %xmm0
cvtsi2sdq 0x8(%r14), %xmm1
divsd 0x41b3(%rip), %xmm1     # 0x70d8
addsd %xmm0, %xmm1
movq %xmm1, %rax
bswapq %rax
leaq 0x17(%r15), %r14
movq %rax, 0x17(%r15)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20d0
movl %eax, %edi
leal 0x8(,%r12,8), %edx
movq %r14, %rsi
callq 0x20d0
bswapl %eax
movl %eax, 0xb(%r15)
movl 0xb0(%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2160
testq %rax, %rax
js 0x2fad
movl 0xb0(%rbx), %edi
movq 0x98(%rbx), %rsi
movq 0xa8(%rbx), %rdx
callq 0x2c17
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leal (%rcx,%rcx,2), %eax
jmp 0x2fb2
movq %rbx, %rdi
callq 0x27e5
movl %eax, %ecx
movl $0x4, %eax
testl %ecx, %ecx
jne 0x2fb2
jmp 0x2eb7
movl $0x3, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x415f(%rip), %rdi      # 0x7126
leaq 0x4117(%rip), %rsi      # 0x70e5
leaq 0x41d3(%rip), %rcx      # 0x71a8
movl $0x1b6, %edx            # imm = 0x1B6
callq 0x2180
leaq 0x41f5(%rip), %rdi      # 0x71db
leaq 0x40f8(%rip), %rsi      # 0x70e5
leaq 0x41b4(%rip), %rcx      # 0x71a8
movl $0x1c2, %edx            # imm = 0x1C2
callq 0x2180
leaq 0x41e2(%rip), %rdi      # 0x71e7
leaq 0x40d9(%rip), %rsi      # 0x70e5
leaq 0x4195(%rip), %rcx      # 0x71a8
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x2180
nopl (%rax)