// File: /workspace/github_c_makefile_star2_O2/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 0x1ab1
cmpq $0x0, 0x98(%rdi)
jne 0x1ad0
movq %rdi, 0x8(%rsp)
cmpl $0x11, 0xa4(%rdi)
jae 0x1aef
callq 0x2a87
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x26eb
movq %rax, %r14
callq 0x2a87
movq %rax, %r12
movq %rax, %rdi
callq 0x26eb
movq %rax, 0x18(%rsp)
leaq 0x3b07(%rip), %rsi      # 0x529e
movq %r14, %rdi
movq %r12, %rdx
callq 0x3bba
leaq 0x20(%rsp), %rbx
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
cmpq $0x10, %r13
je 0x196a
movq 0x10(%r12,%r13,8), %r15
testq %r15, %r15
je 0x1962
callq 0x2a87
movq %rax, %rbp
movq %rax, %rdi
callq 0x26eb
movq %rax, %r14
movq 0x8(%r15), %rdx
movq %rax, %rdi
leaq 0x3ac2(%rip), %rsi      # 0x52aa
callq 0x3c57
movq 0x18(%r15), %rdx
movq %r14, %rdi
leaq 0x3abb(%rip), %rsi      # 0x52b6
callq 0x3c57
movq 0x20(%r15), %rdx
movq %r14, %rdi
leaq 0x3aae(%rip), %rsi      # 0x52bc
callq 0x3c57
movq 0x28(%r15), %rdx
movq %r14, %rdi
leaq 0x3a9f(%rip), %rsi      # 0x52c0
callq 0x3c57
cmpl $0x0, 0x44(%r15)
leaq 0x3a9a(%rip), %rdx      # 0x52cc
leaq 0x3a98(%rip), %rax      # 0x52d1
cmoveq %rax, %rdx
movq %r14, %rdi
leaq 0x3a7d(%rip), %rsi      # 0x52c4
callq 0x3c57
pxor %xmm0, %xmm0
movdqa %xmm0, 0x90(%rsp)
movdqa %xmm0, 0x80(%rsp)
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm0, 0x60(%rsp)
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm0, 0x20(%rsp)
movl 0x40(%r15), %eax
cmpl $0x2, %eax
je 0x18c3
cmpl $0x1, %eax
je 0x18ae
testl %eax, %eax
jne 0x1aac
movb $0x0, 0x24(%rsp)
movl $0x74736f68, 0x20(%rsp) # imm = 0x74736F68
movq %rbx, %rdx
jmp 0x18e5
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x3a1b(%rip), %rdx      # 0x52dc
jmp 0x18d6
movq 0x10(%r15), %rcx
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x3a0c(%rip), %rdx      # 0x52e2
xorl %eax, %eax
callq 0x1150
movq %rbx, %rdx
movq 0x8(%rsp), %r12
movq %r14, %rdi
leaq 0x39f9(%rip), %rsi      # 0x52e8
callq 0x3c57
movl 0x4c(%r15), %eax
leaq 0x39ef(%rip), %rdx      # 0x52ee
cmpl $0x1, %eax
je 0x1913
testl %eax, %eax
jne 0x1aac
leaq 0x39e1(%rip), %rdx      # 0x52f4
movq %r14, %rdi
leaq 0x39dd(%rip), %rsi      # 0x52fa
callq 0x3c57
movl 0x48(%r15), %eax
cmpq $0x3, %rax
jae 0x1aac
leaq 0x3a05(%rip), %rcx      # 0x533c
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq %r14, %rdi
leaq 0x39b8(%rip), %rsi      # 0x5300
callq 0x3c57
movq 0x10(%r12,%r13,8), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
callq 0x3bba
incq %r13
jmp 0x17af
movq 0x10(%rsp), %rdi
movq %rdi, 0x90(%r12)
callq 0x3783
movq %rax, %r14
cmpl $0x8000, %r14d          # imm = 0x8000
jae 0x1b0e
movq $0x80a3, 0xa8(%r12) # imm = 0x80A3
pushq $0x1
popq %rdi
movl $0x80a3, %esi           # imm = 0x80A3
callq 0x11c0
movq %rax, 0x98(%r12)
testq %rax, %rax
je 0x1a72
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)
callq 0x15e4
movq %xmm0, %rax
cmpq $-0x1, %rax
bswapq %rax
movq %rax, 0x17(%r15)
movq %r12, %rbx
movq 0x98(%r12), %r12
je 0x1a7d
movl 0xa4(%rbx), %eax
addq $0x23, %r12
movabsq $0x7766554433221100, %rcx # imm = 0x7766554433221100
subq $0x1, %rax
jb 0x1a29
movq %rcx, -0x4(%r12)
addq $0x8, %r12
jmp 0x1a18
movl %r14d, %eax
bswapl %eax
movl %eax, -0x4(%r12)
movq 0x8(%rsp), %rax
movq 0x90(%rax), %rdi
movl %r14d, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
movq %r12, %rsi
callq 0x37b0
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10d0
movl %eax, %edi
movq %r12, %rsi
movl %r14d, %edx
callq 0x10d0
bswapl %eax
movl %eax, 0xf(%r15)
jmp 0x1a98
andq $0x0, 0xa8(%r12)
jmp 0x1a95
movq %r12, %rdi
callq 0x1030
andq $0x0, 0xa8(%rbx)
andq $0x0, 0x98(%rbx)
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040
leaq 0x377b(%rip), %rdi      # 0x5233
leaq 0x3646(%rip), %rsi      # 0x5105
leaq 0x3750(%rip), %rcx      # 0x5216
movl $0x103, %edx            # imm = 0x103
callq 0x1180
leaq 0x3771(%rip), %rdi      # 0x5248
leaq 0x3627(%rip), %rsi      # 0x5105
leaq 0x3731(%rip), %rcx      # 0x5216
movl $0x104, %edx            # imm = 0x104
callq 0x1180
leaq 0x3766(%rip), %rdi      # 0x525c
leaq 0x3608(%rip), %rsi      # 0x5105
leaq 0x3712(%rip), %rcx      # 0x5216
movl $0x105, %edx            # imm = 0x105
callq 0x1180
leaq 0x3764(%rip), %rdi      # 0x5279
leaq 0x35e9(%rip), %rsi      # 0x5105
leaq 0x36f3(%rip), %rcx      # 0x5216
movl $0x109, %edx            # imm = 0x109
callq 0x1180