// File: /workspace/github_c_makefile_star2_O0/WojciechMula[P]pyahocorasick/src/custompickle/load/module_automaton_load.c
// Function: automaton_load_node
static bool
automaton_load_node(LoadBuffer* input) {

    PyObject* bytes; // XXX: it might be reused (i.e. be part of input)
    PyObject* object;
    TrieNode* original;
    TrieNode* node;
    size_t size;
    int ret;

    // 1. get original address of upcoming node
    ret = loadbuffer_loadinto(input, &original, TrieNode*);
    if (UNLIKELY(!ret)) {
        return false;
    }

    // 2. load node data
    node = (TrieNode*)memory_alloc(sizeof(TrieNode));
    if (UNLIKELY(node == NULL)) {
        PyErr_NoMemory();
        return false;
    }

    ret = loadbuffer_load(input, (char*)node, PICKLE_TRIENODE_SIZE);
    if (UNLIKELY(!ret)) {
        memory_free(node);
        return false;
    }

    node->next = NULL;

    // 3. load next pointers
    if (node->n > 0) {
        size = sizeof(Pair) * node->n;
        node->next = (Pair*)memory_alloc(size);
        if (UNLIKELY(node->next == NULL)) {
            PyErr_NoMemory();
            goto exception;
        }

        ret = loadbuffer_load(input, (char*)(node->next), size);
        if (UNLIKELY(!ret)) {
            goto exception;
        }
    }

    // 4. load custom python object
    if (node->eow && input->store == STORE_ANY) {
        size = (size_t)(node->output.integer);
        bytes = F(PyBytes_FromStringAndSize)(NULL, size);
        if (UNLIKELY(bytes == NULL)) {
            goto exception;
        }

        ret = loadbuffer_load(input, PyBytes_AS_STRING(bytes), size);
        if (UNLIKELY(!ret)) {
            Py_DECREF(bytes);
            goto exception;
        }

        object = F(PyObject_CallFunction)(input->deserializer, "O", bytes);
        if (UNLIKELY(object == NULL)) {
            Py_DECREF(bytes);
            goto exception;
        }

        node->output.object = object;
        Py_DECREF(bytes);
    }

    input->lookup[input->size].original = original;
    input->lookup[input->size].current  = node;
    input->size += 1;

    return true;

exception:
    memory_safefree(node->next);
    memory_free(node);

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x8, %edx
callq 0x4bb0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5ec0
movb $0x0, -0x1(%rbp)
jmp 0x614e
movl $0x20, %edi
callq 0x3450
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5ef1
callq 0x30e0
movb $0x0, -0x1(%rbp)
jmp 0x614e
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x18, %edx
callq 0x4bb0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5f2e
movq -0x30(%rbp), %rdi
callq 0x34b0
movb $0x0, -0x1(%rbp)
jmp 0x614e
movq -0x30(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jbe 0x5fbf
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0xc, %rax, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3450
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5f8a
callq 0x30e0
jmp 0x6134
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x4bb0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5fbd
jmp 0x6134
jmp 0x5fbf
movq -0x30(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x0, %eax
je 0x60e1
movq -0x10(%rbp), %rax
cmpl $0x1e, 0x10(%rax)
jne 0x60e1
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x30c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x6014
jmp 0x6134
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x4450
cmpl $0x0, %eax
je 0x6035
jmp 0x6054
leaq 0x65fb(%rip), %rdi      # 0xc637
leaq 0x669c(%rip), %rsi      # 0xc6df
movl $0x9c, %edx
leaq 0x66be(%rip), %rcx      # 0xc70d
callq 0x3130
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
movq -0x38(%rbp), %rdx
callq 0x4bb0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x6090
movq -0x18(%rbp), %rdi
callq 0x3a90
jmp 0x6134
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x8d03(%rip), %rsi      # 0xeda5
movb $0x0, %al
callq 0x30f0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x60cd
movq -0x18(%rbp), %rdi
callq 0x3a90
jmp 0x6134
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x3a90
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x20(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x20(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x614e
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x34d0
movq -0x30(%rbp), %rdi
callq 0x34b0
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)