// File: /workspace/github_c_makefile_star2_O2/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, %r13
xorl %r15d, %r15d
leaq 0x28(%rsp), %rcx
xorl %edx, %edx
callq 0x376f
testb %al, %al
je 0x5eda
movl 0x14(%r13), %eax
cmpl $0xa, %eax
je 0x5ca8
cmpl $0x14, %eax
je 0x5c9b
cmpl $0x1e, %eax
jne 0x5cec
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x3140
testq %rax, %rax
je 0x5e95
movq %rax, %r14
xorl %ebp, %ebp
jmp 0x5d11
movq 0x28(%rsp), %r15
xorl %r14d, %r14d
movq %r15, %rbp
jmp 0x5d16
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x3140
testq %rax, %rax
je 0x5d02
movq %rax, %r14
movq %rax, %rdi
callq 0x32e0
testl %eax, %eax
je 0x5eb7
movq 0x82b6(%rip), %rax      # 0xdf88
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3060
cmpq $-0x1, %rax
je 0x5eec
movq %rax, %rbp
jmp 0x5d11
movq 0x827d(%rip), %rax      # 0xdf70
movq (%rax), %rdi
leaq 0x4951(%rip), %rsi      # 0xa64e
jmp 0x5ec8
callq 0x3190
movslq 0x1c(%r13), %rbp
incq %rbp
xorl %r14d, %r14d
movq 0x28(%rsp), %r15
testq %r15, %r15
jle 0x5d46
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x10(%r13)
movq 0x28(%r13), %r12
movq %r13, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
je 0x5d50
movq 0x8(%rsp), %r14
jmp 0x5d73
xorl %ebx, %ebx
xorl %r12d, %r12d
jmp 0x5e31
testq %r12, %r12
jne 0x5f6f
callq 0x6ea6
movq %rax, %r12
movq %rax, 0x28(%r13)
testq %rax, %rax
movq 0x8(%rsp), %r14
je 0x5eb0
xorl %ebx, %ebx
movl %ebx, %ebx
cmpq %rbx, %r15
jbe 0x5e05
movl (%r14,%rbx,4), %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x4d53
movq %rax, %r13
testq %rax, %rax
jne 0x5dfb
callq 0x6ea6
testq %rax, %rax
je 0x5eb0
testq %r12, %r12
je 0x5f2c
movq %rax, %r13
movq %r12, %rdi
movl %ebp, %esi
callq 0x4d53
testq %rax, %rax
jne 0x5efe
movslq 0x10(%r12), %rax
movq 0x18(%r12), %rdi
imulq $0xc, %rax, %r14
leaq 0xc(%r14), %rsi
callq 0x3150
testq %rax, %rax
je 0x5ea8
movq %rax, 0x18(%r12)
movl %ebp, (%rax,%r14)
movq %r13, 0x4(%rax,%r14)
incl 0x10(%r12)
movq 0x8(%rsp), %r14
incl %ebx
movq %r13, %r12
jmp 0x5d75
cmpb $0x0, 0x14(%r12)
sete %bl
movq 0x20(%rsp), %r13
jne 0x5e1f
movb $0x1, 0x14(%r12)
incl 0x1c(%r13)
movl $0x1, 0x10(%r13)
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbp
leaq 0x28(%rsp), %rdi
callq 0x37ab
testq %r12, %r12
je 0x5e89
cmpl $0x1e, 0x14(%r13)
jne 0x5e62
testb %bl, %bl
jne 0x5e5c
cmpb $0x0, 0x14(%r12)
je 0x5e5c
movq (%r12), %rdi
callq 0x37d5
incq (%r14)
movq %r14, %rbp
movq %rbp, (%r12)
testb %bl, %bl
je 0x5e89
incl 0x30(%r13)
movq 0x28(%rsp), %rax
movslq 0x20(%r13), %rcx
cmpq %rcx, %rax
jle 0x5e80
movl %eax, 0x20(%r13)
movq 0x8141(%rip), %r15      # 0xdfc8
jmp 0x5e90
movq 0x8118(%rip), %r15      # 0xdfa8
incq (%r15)
jmp 0x5eda
movq 0x80ec(%rip), %rax      # 0xdf88
movq (%rax), %rdi
leaq 0x4748(%rip), %rsi      # 0xa5ee
jmp 0x5ec8
movq %r13, %rdi
callq 0x3070
callq 0x30e0
jmp 0x5ecd
movq 0x80d2(%rip), %rax      # 0xdf90
movq (%rax), %rdi
leaq 0x4755(%rip), %rsi      # 0xa61d
callq 0x3120
leaq 0x28(%rsp), %rdi
callq 0x37ab
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 0x5ecd
pushq $-0x1
popq %rbp
jmp 0x5d11
movq 0x80f3(%rip), %rbx      # 0xdff8
movq (%rbx), %rdi
leaq 0x2121(%rip), %rsi      # 0x8030
leaq 0x269a(%rip), %rdx      # 0x85b0
leaq 0x479b(%rip), %rcx      # 0xa6b8
leaq 0x47ac(%rip), %r9       # 0xa6d0
movl $0x84, %r8d
jmp 0x5f58
movq 0x80c5(%rip), %rbx      # 0xdff8
movq (%rbx), %rdi
leaq 0x20f3(%rip), %rsi      # 0x8030
leaq 0x266c(%rip), %rdx      # 0x85b0
leaq 0x476d(%rip), %rcx      # 0xa6b8
leaq 0x4d9d(%rip), %r9       # 0xacef
movl $0x82, %r8d
xorl %eax, %eax
callq 0x31b0
movq (%rbx), %rdi
callq 0x3230
pushq $0x1
popq %rdi
callq 0x3310
movq 0x8082(%rip), %rbx      # 0xdff8
movq (%rbx), %rdi
leaq 0x20b0(%rip), %rsi      # 0x8030
leaq 0x2607(%rip), %rdx      # 0x858e
leaq 0x4704(%rip), %rcx      # 0xa692
leaq 0x470b(%rip), %r9       # 0xa6a0
pushq $0x16
popq %r8
jmp 0x5f58