// File: /workspace/github_c_makefile_star2_O2/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
testq %rdi, %rdi
je 0x1e33
movq %rdi, %rbx
movq 0x98(%rdi), %r15
testq %r15, %r15
je 0x1de7
leaq 0x1f(%r15), %r14
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpq $0x10, %r13
je 0x1d69
movq 0x10(%rbx,%r13,8), %rax
testq %rax, %rax
je 0x1d64
movq 0x38(%rax), %rdi
callq *0x30(%rax)
bswapq %rax
movq %rax, (%r14)
addq $0x8, %r14
incl %r12d
incq %r13
jmp 0x1d40
cmpl 0xa4(%rbx), %r12d
jne 0x1e52
callq 0x15e4
movq %xmm0, %rax
bswapq %rax
leaq 0x17(%r15), %r14
movq %rax, 0x17(%r15)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10d0
movl %eax, %edi
leal 0x8(,%r12,8), %edx
movq %r14, %rsi
callq 0x10d0
bswapl %eax
movl %eax, 0xb(%r15)
movl 0xb0(%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1160
testq %rax, %rax
js 0x1df7
movl 0xb0(%rbx), %edi
movq 0x98(%rbx), %rsi
movq 0xa8(%rbx), %rdx
callq 0x1b85
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leal (%rcx,%rcx,2), %eax
jmp 0x1dfa
movq %rbx, %rdi
callq 0x1727
testl %eax, %eax
je 0x1e04
pushq $0x4
jmp 0x1df9
pushq $0x3
popq %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x98(%rbx), %r15
testq %r15, %r15
jne 0x1d36
leaq 0x33e0(%rip), %rdi      # 0x51fb
leaq 0x32e3(%rip), %rsi      # 0x5105
leaq 0x339f(%rip), %rcx      # 0x51c8
movl $0x1c2, %edx            # imm = 0x1C2
callq 0x1180
leaq 0x330c(%rip), %rdi      # 0x5146
leaq 0x32c4(%rip), %rsi      # 0x5105
leaq 0x3380(%rip), %rcx      # 0x51c8
movl $0x1b6, %edx            # imm = 0x1B6
callq 0x1180
leaq 0x33ae(%rip), %rdi      # 0x5207
leaq 0x32a5(%rip), %rsi      # 0x5105
leaq 0x3361(%rip), %rcx      # 0x51c8
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x1180
nopl (%rax)