// File: /workspace/github_c_makefile_star2_O2/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
movq %rdx, %rdi
movq %r14, %rsi
callq 0x3e7c
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x3db7
movq %rax, %r12
cmpl $0x1e, (%rbx)
je 0x4aff
movq (%r14), %rax
movq %rax, (%r12)
movl 0x10(%r14), %eax
movl %eax, 0x10(%r12)
movb 0x14(%r14), %cl
movb %cl, 0x14(%r12)
movq 0x8(%r14), %rdx
movq %rdx, 0x8(%r12)
testb %cl, %cl
je 0x4b6d
xorl %r13d, %r13d
cmpl $0x1e, (%rbx)
jne 0x4b6d
movq 0x28(%rbx), %rdi
movq (%r14), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3220
testq %rax, %rax
je 0x4bb8
movq %rax, %r15
movq 0x8(%rax), %rax
cmpq 0x9437(%rip), %rax      # 0xdf80
jne 0x4bc5
movq 0x942e(%rip), %rax      # 0xdf80
testb $0x8, 0xab(%rax)
je 0x4bfc
movq 0x10(%r15), %rax
movq %rax, (%r12)
movl 0x10(%r14), %eax
jmp 0x4b70
xorl %r15d, %r15d
testl %eax, %eax
je 0x4b86
movq 0x18(%r14), %rsi
movl %eax, %eax
imulq $0xc, %rax, %rdx
movq %rbx, %rdi
callq 0x3dfe
testq %r15, %r15
je 0x4bb0
movq 0x8(%r15), %rax
testb $0x8, 0xab(%rax)
je 0x4bdd
leaq 0x20(%r15), %rsi
movq 0x10(%r15), %rdx
movq %rbx, %rdi
callq 0x3dfe
movq %r15, %rdi
callq 0x37d5
incq 0x30(%rbx)
pushq $0x1
popq %r13
movl %r13d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x93c4(%rip), %rax      # 0xdf90
movq (%rax), %rdi
leaq 0x3a01(%rip), %rsi      # 0x85d7
callq 0x3120
jmp 0x4bb8
leaq 0x3a17(%rip), %rdi      # 0x85fb
leaq 0x3a25(%rip), %rsi      # 0x8610
leaq 0x3a45(%rip), %rcx      # 0x8637
movl $0x83, %edx
callq 0x3130
leaq 0x39f8(%rip), %rdi      # 0x85fb
leaq 0x3a06(%rip), %rsi      # 0x8610
leaq 0x3a26(%rip), %rcx      # 0x8637
pushq $0x77
popq %rdx
callq 0x3130