// File: /workspace/github_c_makefile_star2_O3/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 0x3565
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 0x35d7
xorl %r13d, %r13d
cmpl $0x1e, (%rbx)
jne 0x35d7
movq 0x28(%rbx), %rdi
movq (%r14), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3220
testq %rax, %rax
je 0x3627
movq %rax, %r15
movq 0x8(%rax), %rax
cmpq 0xc9cd(%rip), %rax      # 0xff80
jne 0x3634
movq 0xc9c4(%rip), %rax      # 0xff80
testb $0x8, 0xab(%rax)
je 0x366b
movq 0x10(%r15), %rax
movq %rax, (%r12)
movl 0x10(%r14), %eax
jmp 0x35da
xorl %r15d, %r15d
testl %eax, %eax
je 0x35f0
movq 0x18(%r14), %rsi
movl %eax, %eax
imulq $0xc, %rax, %rdx
movq %rbx, %rdi
callq 0x4cd1
testq %r15, %r15
je 0x361f
movq 0x8(%r15), %rax
testb $0x8, 0xab(%rax)
je 0x364c
leaq 0x20(%r15), %rsi
movq 0x10(%r15), %rdx
movq %rbx, %rdi
callq 0x4cd1
decq (%r15)
jne 0x361f
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 0xc955(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x5fa2(%rip), %rsi      # 0x95e7
callq 0x3120
jmp 0x3627
leaq 0x5fb8(%rip), %rdi      # 0x960b
leaq 0x5fc6(%rip), %rsi      # 0x9620
leaq 0x5fe6(%rip), %rcx      # 0x9647
movl $0x83, %edx
callq 0x3130
leaq 0x5f99(%rip), %rdi      # 0x960b
leaq 0x5fa7(%rip), %rsi      # 0x9620
leaq 0x5fc7(%rip), %rcx      # 0x9647
pushq $0x77
popq %rdx
callq 0x3130