// File: /workspace/github_c_makefile_star2_O1/WojciechMula[P]pyahocorasick/src/custompickle/save/automaton_save.c
// Function: automaton_save_node
static int
automaton_save_node(TrieNode* node, const int depth, void* extra) {

    SaveBuffer* output;
    TrieNode* dump;
    PyObject* bytes;

    output = (SaveBuffer*)extra;

    // 1. save actual address of node
    savebuffer_store_pointer(output, (void*)node);

    // 2. obtain buffer
    dump = (TrieNode*)savebuffer_acquire(output, PICKLE_TRIENODE_SIZE);

    if (output->store != STORE_ANY)
        dump->output.integer = node->output.integer;

    dump->n         = node->n;
    dump->eow       = node->eow;
    dump->fail      = node->fail;

    // 3. pickle python value associated with word
    if (node->eow && output->store == STORE_ANY) {
        bytes = F(PyObject_CallFunctionObjArgs)(output->serializer, node->output.object, NULL);
        if (UNLIKELY(bytes == NULL)) {
            return 0;
        }

        if (UNLIKELY(!F(PyBytes_CheckExact)(bytes))) {
            PyErr_SetString(PyExc_TypeError, "serializer must return bytes object");
            return 0;
        }

        // store the size of buffer in trie node [which is not saved yet in the file]
        *(size_t*)(&dump->output.integer) = PyBytes_GET_SIZE(bytes);
    } else {
        bytes = NULL;
    }

    // 4. save array of pointers
    if (node->n > 0) {
        savebuffer_store(output, (const char*)node->next, node->n * sizeof(Pair));
    }

    // 5. save pickled data, if any
    if (bytes) {
        savebuffer_store(output, PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes));
        Py_DECREF(bytes);
    }

    output->nodes_count += 1;

    return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rdi, %r14
pushq $0x8
popq %rsi
movq %rdx, %rdi
callq 0x3390
movq %r14, (%rax)
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x3390
movq %rax, %r12
cmpl $0x1e, (%rbx)
je 0x3551
movq (%r14), %rax
movq %rax, (%r12)
movl 0x10(%r14), %eax
movl %eax, 0x10(%r12)
movb 0x14(%r14), %al
movb %al, 0x14(%r12)
movq 0x8(%r14), %rax
movq %rax, 0x8(%r12)
cmpb $0x0, 0x14(%r14)
je 0x35b7
xorl %r13d, %r13d
cmpl $0x1e, (%rbx)
jne 0x35b7
movq 0x28(%rbx), %rdi
movq (%r14), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3220
testq %rax, %rax
je 0x360a
movq %rax, %r15
movq 0x8(%rax), %rax
cmpq 0xc9e2(%rip), %rax      # 0xff80
jne 0x3617
testb $0x8, 0xab(%rax)
je 0x364e
movq 0x10(%r15), %rax
movq %rax, (%r12)
jmp 0x35ba
xorl %r15d, %r15d
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x35d3
movq 0x18(%r14), %rsi
imulq $0xc, %rax, %rdx
movq %rbx, %rdi
callq 0x4e28
testq %r15, %r15
je 0x3602
movq 0x8(%r15), %rax
testb $0x8, 0xab(%rax)
je 0x362f
leaq 0x20(%r15), %rsi
movq 0x10(%r15), %rdx
movq %rbx, %rdi
callq 0x4e28
decq (%r15)
jne 0x3602
movq %r15, %rdi
callq 0x30d0
incq 0x30(%rbx)
pushq $0x1
popq %r13
movl %r13d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xc972(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x5faf(%rip), %rsi      # 0x95d7
callq 0x3120
jmp 0x360a
leaq 0x5fc5(%rip), %rdi      # 0x95fb
leaq 0x5fd3(%rip), %rsi      # 0x9610
leaq 0x5ff3(%rip), %rcx      # 0x9637
movl $0x83, %edx
callq 0x3130
leaq 0x5fa6(%rip), %rdi      # 0x95fb
leaq 0x5fb4(%rip), %rsi      # 0x9610
leaq 0x5fd4(%rip), %rcx      # 0x9637
pushq $0x77
popq %rdx
callq 0x3130