// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x47c0
movq -0x28(%rbp), %rdi
movl $0x18, %esi
callq 0x4650
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1e, (%rax)
je 0x5b11
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movb 0x14(%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x14(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x0, %eax
je 0x5c2a
movq -0x28(%rbp), %rax
cmpl $0x1e, (%rax)
jne 0x5c2a
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x3220
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5b9a
movl $0x0, -0x4(%rbp)
jmp 0x5d1c
movq -0x38(%rbp), %rdi
movq 0xc3db(%rip), %rsi      # 0x11f80
callq 0x5e50
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5be1
movq 0xc3ca(%rip), %rax      # 0x11f90
movq (%rax), %rdi
leaq 0x6a43(%rip), %rsi      # 0xc613
callq 0x3120
movl $0x0, -0x4(%rbp)
jmp 0x5d1c
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x4450
cmpl $0x0, %eax
je 0x5bfa
jmp 0x5c19
leaq 0x6a36(%rip), %rdi      # 0xc637
leaq 0x6a44(%rip), %rsi      # 0xc64c
movl $0x77, %edx
leaq 0x6a5f(%rip), %rcx      # 0xc673
callq 0x3130
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5c32
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jbe 0x5c58
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0xc, %rax, %rdx
callq 0x46f0
cmpq $0x0, -0x38(%rbp)
je 0x5d05
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x4450
cmpl $0x0, %eax
je 0x5c84
jmp 0x5ca3
leaq 0x69ac(%rip), %rdi      # 0xc637
leaq 0x69ba(%rip), %rsi      # 0xc64c
movl $0x83, %edx
leaq 0x69d5(%rip), %rcx      # 0xc673
callq 0x3130
movq -0x38(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x4450
cmpl $0x0, %eax
je 0x5cc8
jmp 0x5ce7
leaq 0x6968(%rip), %rdi      # 0xc637
leaq 0x6976(%rip), %rsi      # 0xc64c
movl $0x83, %edx
leaq 0x6991(%rip), %rcx      # 0xc673
callq 0x3130
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x46f0
movq -0x38(%rbp), %rdi
callq 0x3a90
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)