// File: /workspace/github_c_makefile_star2_O1/xapi-project[P]rrd-client-lib/librrd.c
// Function: initialise
static int
initialise(RRD_PLUGIN * plugin)
{

    RRD_HEADER     *header;
    uint32_t        size_meta;
    uint32_t        size_total;
    int64_t        *p64;
    int32_t        *p32;

    assert(plugin);
    assert(plugin->meta == NULL);
    assert(plugin->buf == NULL);
    assert(plugin->n <= RRD_MAX_SOURCES);

    plugin->meta = json_for_plugin(plugin);
    size_meta = json_serialization_size_pretty(plugin->meta);
    assert(size_meta < RRD_MAX_JSON);   /* just a safeguard */

    size_total = 0;
    size_total += sizeof(RRD_HEADER);
    size_total += RRD_MAX_SOURCES * sizeof(int64_t);
    size_total += sizeof(uint32_t);
    size_total += RRD_MAX_JSON;

    plugin->buf_size = size_total;
    plugin->buf = calloc(1, size_total);
    if (!plugin->buf) {
        /*
         * fatal
         */
        plugin->buf_size = 0;
        return -1;
    }
    /*
     * all values need to be in network byte order
     */
    header = (RRD_HEADER *) plugin->buf;
    memcpy(&header->rrd_magic, MAGIC, MAGIC_SIZE);
    header->rrd_checksum_value = htonl(0x01234567);
    header->rrd_header_datasources = htonl(plugin->n);
    header->rrd_timestamp = htonll(bits_of_double(get_timestamp()));
    if (header->rrd_timestamp == -1) {
        free(plugin->buf);
        plugin->buf_size = 0;
        plugin->buf = NULL;
        return -1;
    }
    p64 = (int64_t *) (plugin->buf + sizeof(RRD_HEADER));
    for (size_t i = 0; i < plugin->n; i++) {
        *p64++ = htonll(0x0011223344556677);
    }
    p32 = (int32_t *) p64;
    *p32++ = htonl(size_meta);
    json_serialize_to_buffer_pretty(plugin->meta, (char *)p32, size_meta);

    uint32_t        crc;
    crc = crc32(0L, Z_NULL, 0);
    crc = crc32(crc, (unsigned char *)p32, size_meta);
    header->rrd_checksum_meta = htonl(crc);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
cmpq $0x0, 0x90(%rdi)
jne 0x2b9b
cmpq $0x0, 0x98(%rdi)
jne 0x2bba
movq %rdi, 0x8(%rsp)
cmpl $0x11, 0xa4(%rdi)
jae 0x2bd9
callq 0x3e18
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x3a55
movq %rax, %r14
callq 0x3e18
movq %rax, %r12
movq %rax, %rdi
callq 0x3a55
movq %rax, 0x18(%rsp)
leaq 0x4a29(%rip), %rsi      # 0x727e
movq %r14, %rdi
movq %r12, %rdx
callq 0x534f
leaq 0x20(%rsp), %rbx
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
movq 0x10(%r12,%r13,8), %r15
testq %r15, %r15
je 0x2a16
callq 0x3e18
movq %rax, %rbp
movq %rax, %rdi
callq 0x3a55
movq %rax, %r14
movq 0x8(%r15), %rdx
movq %rax, %rdi
leaq 0x49ee(%rip), %rsi      # 0x728a
callq 0x53fe
movq 0x18(%r15), %rdx
movq %r14, %rdi
leaq 0x49e7(%rip), %rsi      # 0x7296
callq 0x53fe
movq 0x20(%r15), %rdx
movq %r14, %rdi
leaq 0x49da(%rip), %rsi      # 0x729c
callq 0x53fe
movq 0x28(%r15), %rdx
movq %r14, %rdi
leaq 0x49cb(%rip), %rsi      # 0x72a0
callq 0x53fe
cmpl $0x0, 0x44(%r15)
leaq 0x49c6(%rip), %rdx      # 0x72ac
leaq 0x49c4(%rip), %rax      # 0x72b1
cmoveq %rax, %rdx
movq %r14, %rdi
leaq 0x49a9(%rip), %rsi      # 0x72a4
callq 0x53fe
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movl 0x40(%r15), %eax
cmpl $0x2, %eax
je 0x2977
cmpl $0x1, %eax
je 0x2962
testl %eax, %eax
jne 0x2b96
movb $0x0, 0x24(%rsp)
movl $0x74736f68, 0x20(%rsp) # imm = 0x74736F68
movq %rbx, %rdx
jmp 0x2999
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x4947(%rip), %rdx      # 0x72bc
jmp 0x298a
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x4938(%rip), %rdx      # 0x72c2
xorl %eax, %eax
callq 0x2150
movq %rbx, %rdx
movq 0x8(%rsp), %r12
movq %r14, %rdi
leaq 0x4925(%rip), %rsi      # 0x72c8
callq 0x53fe
movl 0x4c(%r15), %eax
leaq 0x491b(%rip), %rdx      # 0x72ce
cmpl $0x1, %eax
je 0x29c7
testl %eax, %eax
jne 0x2b96
leaq 0x490d(%rip), %rdx      # 0x72d4
movq %r14, %rdi
leaq 0x4909(%rip), %rsi      # 0x72da
callq 0x53fe
movl 0x48(%r15), %eax
cmpq $0x3, %rax
jae 0x2b96
leaq 0x4931(%rip), %rcx      # 0x731c
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq %r14, %rdi
leaq 0x48e4(%rip), %rsi      # 0x72e0
callq 0x53fe
movq 0x10(%r12,%r13,8), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
callq 0x534f
incq %r13
cmpq $0x10, %r13
jne 0x286d
movq 0x10(%rsp), %rdi
movq %rdi, 0x90(%r12)
callq 0x4d41
movq %rax, %r14
cmpl $0x8000, %r14d          # imm = 0x8000
jae 0x2bf8
movq $0x80a3, 0xa8(%r12) # imm = 0x80A3
movl $0x1, %edi
movl $0x80a3, %esi           # imm = 0x80A3
callq 0x21e0
movq %rax, 0x98(%r12)
testq %rax, %rax
je 0x2b57
movq %rax, %r15
movabsq $0x52554f5341544144, %rax # imm = 0x52554F5341544144
movq %rax, (%r15)
movabsq $0x6745230153454352, %rax # imm = 0x6745230153454352
movq %rax, 0x7(%r15)
movl 0xa4(%r12), %eax
bswapl %eax
movl %eax, 0x13(%r15)
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x2170
cvtsi2sdq (%r12), %xmm0
cvtsi2sdq 0x8(%r12), %xmm1
divsd 0x4614(%rip), %xmm1     # 0x70d8
addsd %xmm0, %xmm1
movq %xmm1, %rax
cmpq $-0x1, %rax
bswapq %rax
movq %rax, 0x17(%r15)
movq 0x98(%rbx), %r12
je 0x2b65
addq $0x1f, %r12
movl 0xa4(%rbx), %eax
testq %rax, %rax
je 0x2b0b
movabsq $0x7766554433221100, %rcx # imm = 0x7766554433221100
movq %rcx, (%r12)
addq $0x8, %r12
decq %rax
jne 0x2afe
movl %r14d, %eax
bswapl %eax
movl %eax, (%r12)
addq $0x4, %r12
movq 0x8(%rsp), %rax
movq 0x90(%rax), %rdi
movl %r14d, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
movq %r12, %rsi
callq 0x4d70
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20d0
movl %eax, %edi
movq %r12, %rsi
movl %r14d, %edx
callq 0x20d0
bswapl %eax
movl %eax, 0xf(%r15)
jmp 0x2b82
movq $0x0, 0xa8(%r12)
jmp 0x2b7d
movq %r12, %rdi
callq 0x2030
xorl %eax, %eax
movq %rax, 0xa8(%rbx)
movq %rax, 0x98(%rbx)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2040
leaq 0x4671(%rip), %rdi      # 0x7213
leaq 0x453c(%rip), %rsi      # 0x70e5
leaq 0x4646(%rip), %rcx      # 0x71f6
movl $0x103, %edx            # imm = 0x103
callq 0x2180
leaq 0x4667(%rip), %rdi      # 0x7228
leaq 0x451d(%rip), %rsi      # 0x70e5
leaq 0x4627(%rip), %rcx      # 0x71f6
movl $0x104, %edx            # imm = 0x104
callq 0x2180
leaq 0x465c(%rip), %rdi      # 0x723c
leaq 0x44fe(%rip), %rsi      # 0x70e5
leaq 0x4608(%rip), %rcx      # 0x71f6
movl $0x105, %edx            # imm = 0x105
callq 0x2180
leaq 0x465a(%rip), %rdi      # 0x7259
leaq 0x44df(%rip), %rsi      # 0x70e5
leaq 0x45e9(%rip), %rcx      # 0x71f6
movl $0x109, %edx            # imm = 0x109
callq 0x2180