// File: /workspace/github_c_makefile_star2_O3/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 0x2b51
cmpq $0x0, 0x98(%rdi)
jne 0x2b70
movq %rdi, 0x8(%rsp)
cmpl $0x11, 0xa4(%rdi)
jae 0x2b8f
callq 0x3d03
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x3945
movq %rax, %r14
callq 0x3d03
movq %rax, %r12
movq %rax, %rdi
callq 0x3945
movq %rax, 0x18(%rsp)
leaq 0x4a93(%rip), %rsi      # 0x729e
movq %r14, %rdi
movq %r12, %rdx
callq 0x5125
leaq 0x20(%rsp), %rbx
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
movq 0x10(%r12,%r13,8), %r15
testq %r15, %r15
je 0x29cc
callq 0x3d03
movq %rax, %rbp
movq %rax, %rdi
callq 0x3945
movq %rax, %r14
movq 0x8(%r15), %rdx
movq %rax, %rdi
leaq 0x4a58(%rip), %rsi      # 0x72aa
callq 0x51d4
movq 0x18(%r15), %rdx
movq %r14, %rdi
leaq 0x4a51(%rip), %rsi      # 0x72b6
callq 0x51d4
movq 0x20(%r15), %rdx
movq %r14, %rdi
leaq 0x4a44(%rip), %rsi      # 0x72bc
callq 0x51d4
movq 0x28(%r15), %rdx
movq %r14, %rdi
leaq 0x4a35(%rip), %rsi      # 0x72c0
callq 0x51d4
cmpl $0x0, 0x44(%r15)
leaq 0x4a30(%rip), %rdx      # 0x72cc
leaq 0x4a2e(%rip), %rax      # 0x72d1
cmoveq %rax, %rdx
movq %r14, %rdi
leaq 0x4a13(%rip), %rsi      # 0x72c4
callq 0x51d4
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 0x292d
cmpl $0x1, %eax
je 0x2918
testl %eax, %eax
jne 0x2b4c
movb $0x0, 0x24(%rsp)
movl $0x74736f68, 0x20(%rsp) # imm = 0x74736F68
movq %rbx, %rdx
jmp 0x294f
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x49b1(%rip), %rdx      # 0x72dc
jmp 0x2940
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x49a2(%rip), %rdx      # 0x72e2
xorl %eax, %eax
callq 0x2150
movq %rbx, %rdx
movq 0x8(%rsp), %r12
movq %r14, %rdi
leaq 0x498f(%rip), %rsi      # 0x72e8
callq 0x51d4
movl 0x4c(%r15), %eax
leaq 0x4985(%rip), %rdx      # 0x72ee
cmpl $0x1, %eax
je 0x297d
testl %eax, %eax
jne 0x2b4c
leaq 0x4977(%rip), %rdx      # 0x72f4
movq %r14, %rdi
leaq 0x4973(%rip), %rsi      # 0x72fa
callq 0x51d4
movl 0x48(%r15), %eax
cmpq $0x3, %rax
jae 0x2b4c
leaq 0x497b(%rip), %rcx      # 0x731c
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq %r14, %rdi
leaq 0x494e(%rip), %rsi      # 0x7300
callq 0x51d4
movq 0x10(%r12,%r13,8), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
callq 0x5125
incq %r13
cmpq $0x10, %r13
jne 0x2823
movq 0x10(%rsp), %rdi
movq %rdi, 0x90(%r12)
callq 0x4b88
movq %rax, %r14
cmpl $0x8000, %r14d          # imm = 0x8000
jae 0x2bae
movq $0x80a3, 0xa8(%r12) # imm = 0x80A3
movl $0x1, %edi
movl $0x80a3, %esi           # imm = 0x80A3
callq 0x21d0
movq %rax, 0x98(%r12)
testq %rax, %rax
je 0x2b0d
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 0x467e(%rip), %xmm1     # 0x70f8
addsd %xmm0, %xmm1
movq %xmm1, %rax
cmpq $-0x1, %rax
bswapq %rax
movq %rax, 0x17(%r15)
movq 0x98(%rbx), %r12
je 0x2b1b
addq $0x1f, %r12
movl 0xa4(%rbx), %eax
testq %rax, %rax
je 0x2ac1
movabsq $0x7766554433221100, %rcx # imm = 0x7766554433221100
movq %rcx, (%r12)
addq $0x8, %r12
decq %rax
jne 0x2ab4
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 0x4bb7
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 0x2b38
movq $0x0, 0xa8(%r12)
jmp 0x2b33
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 0x46db(%rip), %rdi      # 0x7233
leaq 0x45a6(%rip), %rsi      # 0x7105
leaq 0x46b0(%rip), %rcx      # 0x7216
movl $0x103, %edx            # imm = 0x103
callq 0x2180
leaq 0x46d1(%rip), %rdi      # 0x7248
leaq 0x4587(%rip), %rsi      # 0x7105
leaq 0x4691(%rip), %rcx      # 0x7216
movl $0x104, %edx            # imm = 0x104
callq 0x2180
leaq 0x46c6(%rip), %rdi      # 0x725c
leaq 0x4568(%rip), %rsi      # 0x7105
leaq 0x4672(%rip), %rcx      # 0x7216
movl $0x105, %edx            # imm = 0x105
callq 0x2180
leaq 0x46c4(%rip), %rdi      # 0x7279
leaq 0x4549(%rip), %rsi      # 0x7105
leaq 0x4653(%rip), %rcx      # 0x7216
movl $0x109, %edx            # imm = 0x109
callq 0x2180