// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
leaq -0x40(%rbp), %rcx
callq 0x39e0
testb $0x1, %al
jne 0x74d4
movq $0x0, -0x8(%rbp)
jmp 0x7703
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x58(%rbp)
subl $0xa, %eax
je 0x753a
jmp 0x74e5
movl -0x58(%rbp), %eax
subl $0x14, %eax
je 0x75c5
jmp 0x74f3
movl -0x58(%rbp), %eax
subl $0x1e, %eax
jne 0x75cf
jmp 0x7501
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x3140
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x7535
movq 0xaa67(%rip), %rax      # 0x11f88
movq (%rax), %rdi
leaq 0x711d(%rip), %rsi      # 0xe648
callq 0x3120
jmp 0x76f2
jmp 0x75ea
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x3140
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x75ae
movq -0x20(%rbp), %rdi
callq 0x32e0
cmpl $0x0, %eax
je 0x7591
movq -0x20(%rbp), %rdi
movq 0xaa1c(%rip), %rax      # 0x11f88
movq (%rax), %rsi
callq 0x3060
movq %rax, -0x48(%rbp)
cmpq $-0x1, -0x48(%rbp)
jne 0x758f
callq 0x31f0
cmpq $0x0, %rax
je 0x758f
jmp 0x76f2
jmp 0x75ac
movq 0xa9f8(%rip), %rax      # 0x11f90
movq (%rax), %rdi
leaq 0x70d5(%rip), %rsi      # 0xe677
callq 0x3120
jmp 0x76f2
jmp 0x75c3
callq 0x3190
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x48(%rbp)
jmp 0x75ea
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x75ea
movq 0xa99a(%rip), %rax      # 0x11f70
movq (%rax), %rdi
leaq 0x70c8(%rip), %rsi      # 0xe6a8
callq 0x3120
jmp 0x76f2
movq $0x0, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
cmpq $0x0, -0x40(%rbp)
jle 0x7629
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x51(%rbp), %rcx
callq 0x8bf0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x7627
callq 0x30e0
jmp 0x76f2
jmp 0x7629
leaq -0x40(%rbp), %rdi
callq 0x3a40
cmpq $0x0, -0x50(%rbp)
je 0x76e0
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x1e, %eax
jne 0x7680
jmp 0x764b
testb $0x1, -0x51(%rbp)
jne 0x766a
movq -0x50(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x0, %eax
je 0x766a
movq -0x50(%rbp), %rax
movq (%rax), %rdi
callq 0x3a90
movq -0x20(%rbp), %rdi
callq 0x5820
movq -0x20(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
jmp 0x768b
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
testb $0x1, -0x51(%rbp)
je 0x76ce
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
jle 0x76bc
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq 0xa905(%rip), %rdi      # 0x11fc8
callq 0x4a30
movq %rax, -0x8(%rbp)
jmp 0x7703
movq 0xa8d3(%rip), %rdi      # 0x11fa8
callq 0x4a30
movq %rax, -0x8(%rbp)
jmp 0x7703
movq 0xa8c1(%rip), %rdi      # 0x11fa8
callq 0x4a30
movq %rax, -0x8(%rbp)
jmp 0x7703
leaq -0x40(%rbp), %rdi
callq 0x3a40
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)