// File: /workspace/github_c_makefile_star2_O1/WojciechMula[P]pyahocorasick/src/Automaton.c
// Function: automaton_add_word
static PyObject*
automaton_add_word(PyObject* self, PyObject* args) {
#define automaton ((Automaton*)self)
    // argument
    PyObject* py_value = NULL;
    struct Input input;

    Py_ssize_t integer = 0;
    TrieNode* node;
    bool new_word;

    if (!prepare_input_from_tuple(self, args, 0, &input)) {
        return NULL;
    }

    switch (automaton->store) {
        case STORE_ANY:
            py_value = F(PyTuple_GetItem)(args, 1);
            if (not py_value) {
                PyErr_SetString(PyExc_ValueError, "A value object is required as second argument.");
                goto py_exception;
            }
            break;

        case STORE_INTS:
            py_value = F(PyTuple_GetItem)(args, 1);
            if (py_value) {
                if (F(PyNumber_Check)(py_value)) {
                    integer = F(PyNumber_AsSsize_t)(py_value, PyExc_ValueError);
                    if (integer == -1 and PyErr_Occurred())
                        goto py_exception;
                }
                else {
                    PyErr_SetString(PyExc_TypeError, "An integer value is required as second argument.");
                    goto py_exception;
                }
            }
            else {
                // default
                PyErr_Clear();
                integer = automaton->count + 1;
            }
            break;

        case STORE_LENGTH:
            integer = input.wordlen;
            break;

        default:
            PyErr_SetString(PyExc_SystemError, "Invalid value for this key: see documentation for supported values.");
            goto py_exception;
    }

    node = NULL;
    new_word = false;

    if (input.wordlen > 0) {
        node = trie_add_word(automaton, input.word, input.wordlen, &new_word);

        if (node == NULL) {
            PyErr_NoMemory();
            goto py_exception;
        }
    }

    destroy_input(&input);

    if (node) {
        switch (automaton->store) {
            case STORE_ANY:
                if (not new_word and node->eow)
                    // replace
                    Py_DECREF(node->output.object);

                Py_INCREF(py_value);
                node->output.object = py_value;
                break;

            default:
                node->output.integer = integer;
        } // switch

        if (new_word) {
            automaton->version += 1; // change version only when new word appeared
            if (input.wordlen > automaton->longest_word)
                automaton->longest_word = (int)input.wordlen;

            Py_RETURN_TRUE;
        }
        else {
            Py_RETURN_FALSE;
        }
    }

    Py_RETURN_FALSE;

py_exception:
    destroy_input(&input);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
xorl %r15d, %r15d
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x639b
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x471d
testb %al, %al
je 0x6398
movl 0x14(%rbx), %eax
cmpl $0xa, %eax
je 0x60d4
cmpl $0x14, %eax
je 0x60cd
cmpl $0x1e, %eax
jne 0x611a
movl $0x1, %esi
movq %r14, %rdi
callq 0x3140
testq %rax, %rax
je 0x62bb
movq %rax, %r14
xorl %r15d, %r15d
jmp 0x613f
movq 0x28(%rsp), %r15
jmp 0x613c
movl $0x1, %esi
movq %r14, %rdi
callq 0x3140
testq %rax, %rax
je 0x6130
movq %rax, %r14
movq %rax, %rdi
callq 0x32e0
testl %eax, %eax
je 0x62ce
movq 0x9e88(%rip), %rax      # 0xff88
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3060
cmpq $-0x1, %rax
je 0x63ad
movq %rax, %r15
jmp 0x613f
movq 0x9e4f(%rip), %rax      # 0xff70
movq (%rax), %rdi
leaq 0x5523(%rip), %rsi      # 0xb64e
jmp 0x62df
callq 0x3190
movslq 0x1c(%rbx), %r15
incq %r15
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
movq %rbx, (%rsp)
movq %r15, 0x20(%rsp)
jle 0x62a8
movq 0x30(%rsp), %r13
cmpl $0x0, 0x10(%rbx)
jne 0x6198
cmpq $0x0, 0x28(%rbx)
jne 0x63cd
movl $0x20, %edi
callq 0x3370
testq %rax, %rax
je 0x6306
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rcx, 0xd(%rax)
movq %rax, 0x28(%rbx)
movq %r14, 0x8(%rsp)
movq 0x28(%rbx), %r12
xorl %eax, %eax
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
movq %r13, 0x18(%rsp)
movl (%r13,%rax,4), %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x57b7
movb $0x1, %r14b
testq %rax, %rax
je 0x61ce
movq %rax, %r12
jmp 0x6285
movl $0x20, %edi
callq 0x3370
testq %rax, %rax
je 0x6228
movq %rax, %r13
xorl %eax, %eax
movq %rax, 0x18(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq %rax, 0xd(%r13)
testq %r12, %r12
je 0x63c3
movq 0x18(%r12), %rdi
movl 0x10(%r12), %r15d
testq %r15, %r15
je 0x6239
leaq (,%r15,4), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
cmpl %ebp, (%rdi,%rcx)
je 0x622d
addq $0xc, %rcx
cmpq %rcx, %rax
jne 0x6218
jmp 0x6239
xorl %r14d, %r14d
jmp 0x6280
cmpq $0x0, 0x4(%rdi,%rcx)
jne 0x63c8
movslq %r15d, %rax
leaq (%rax,%rax,2), %rax
leaq 0xc(,%rax,4), %rsi
callq 0x3150
testq %rax, %rax
je 0x6270
movq %rax, 0x18(%r12)
movslq %r15d, %rcx
leaq (%rcx,%rcx,2), %rcx
movl %ebp, (%rax,%rcx,4)
movq %r13, 0x4(%rax,%rcx,4)
incl 0x10(%r12)
movq %r13, %r12
jmp 0x627b
movq %r13, %rdi
callq 0x3070
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r13
testb %r14b, %r14b
je 0x62af
incl %ebx
movq %rbx, %rax
cmpq %rbx, %r15
ja 0x61af
cmpb $0x0, 0x14(%r12)
je 0x62e9
xorl %ebx, %ebx
movq (%rsp), %rax
jmp 0x62f8
xorl %ebx, %ebx
xorl %r12d, %r12d
jmp 0x6314
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
jmp 0x630f
movq 0x9cc6(%rip), %rax      # 0xff88
movq (%rax), %rdi
leaq 0x5322(%rip), %rsi      # 0xb5ee
jmp 0x62df
movq 0x9cbb(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x533e(%rip), %rsi      # 0xb61d
callq 0x3120
jmp 0x638e
movb $0x1, 0x14(%r12)
movq (%rsp), %rax
incl 0x1c(%rax)
movb $0x1, %bl
movq 0x8(%rsp), %r14
movl $0x1, 0x10(%rax)
jmp 0x630f
movq %rax, 0x28(%rbx)
xorl %ebx, %ebx
xorl %r12d, %r12d
testq %r12, %r12
je 0x6389
leaq 0x28(%rsp), %rdi
callq 0x4a2c
testq %r12, %r12
je 0x637d
movq (%rsp), %rax
cmpl $0x1e, 0x14(%rax)
jne 0x634f
testb %bl, %bl
jne 0x6347
cmpb $0x0, 0x14(%r12)
je 0x6347
movq (%r12), %rdi
decq (%rdi)
jne 0x6347
callq 0x30d0
incq (%r14)
movq %r14, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, (%r12)
testb %bl, %bl
je 0x637d
movq (%rsp), %rdx
incl 0x30(%rdx)
movq 0x28(%rsp), %rax
movslq 0x20(%rdx), %rcx
cmpq %rcx, %rax
jle 0x6374
movl %eax, 0x20(%rdx)
movq 0x9c4d(%rip), %r15      # 0xffc8
jmp 0x6384
movq 0x9c24(%rip), %r15      # 0xffa8
incq (%r15)
jmp 0x639b
callq 0x30e0
leaq 0x28(%rsp), %rdi
callq 0x4a2c
xorl %r15d, %r15d
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31f0
testq %rax, %rax
jne 0x638e
movq $-0x1, %r15
jmp 0x613f
callq 0x41ea
callq 0x41a6
callq 0x4164