// File: /workspace/github_c_makefile_star2_O1/WojciechMula[P]pyahocorasick/src/Automaton.c
// Function: automaton_find_all
static PyObject*
automaton_find_all(PyObject* self, PyObject* args) {
#define automaton ((Automaton*)self)

    struct Input input;
    Py_ssize_t start;
    Py_ssize_t end;
    PyObject* callback;
    PyObject* callback_ret;

    Py_ssize_t i;
    TrieNode* state;
    TrieNode* tmp;

    if (automaton->kind != AHOCORASICK)
        Py_RETURN_NONE;

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

    // arg 2
    callback = F(PyTuple_GetItem)(args, 1);
    if (callback == NULL) {
        destroy_input(&input);
        return NULL;
    }
    else
    if (not F(PyCallable_Check)(callback)) {
        PyErr_SetString(PyExc_TypeError, "The callback argument must be a callable such as a function.");
        destroy_input(&input);
        return NULL;
    }

    // parse start/end
    if (pymod_parse_start_end(args, 2, 3, 0, input.wordlen, &start, &end)) {
        destroy_input(&input);
        return NULL;
    }

    state = automaton->root;
    for (i=start; i < end; i++) {
        state = tmp = ahocorasick_next(state, automaton->root, input.word[i]);

        // return output
        while (tmp) {
            if (tmp->eow) {
                if (automaton->store == STORE_ANY)
                    callback_ret = F(PyObject_CallFunction)(callback, "iO", i, tmp->output.object);
                else
                    callback_ret = F(PyObject_CallFunction)(callback, "ii", i, tmp->output.integer);

                if (callback_ret == NULL) {
                    destroy_input(&input);
                    return NULL;
                } else
                    Py_DECREF(callback_ret);
            }

            tmp = tmp->fail;
        }
    }
#undef automaton

    destroy_input(&input);
    Py_RETURN_NONE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x2, 0x10(%rdi)
jne 0x6b03
movq %rsi, %r15
movq %rdi, %rbx
xorl %r14d, %r14d
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x6b32
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x471d
testb %al, %al
je 0x6b2f
movl $0x1, %esi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x6b25
movq %rax, %r14
movq %rax, %rdi
callq 0x32a0
testl %eax, %eax
je 0x6b0f
movq 0x28(%rsp), %r8
leaq 0x18(%rsp), %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %r9
movq %r15, %rdi
movl $0x2, %esi
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x75a1
testl %eax, %eax
jne 0x6b25
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %r15
jge 0x6af9
movq 0x28(%rbx), %r12
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x4e5a(%rip), %r13      # 0xb8de
movq 0x28(%rbx), %rsi
movq 0x8(%rsp), %rax
movl (%rax,%r15,4), %edx
movq %r12, %rdi
callq 0x773d
movq %rax, %r12
testq %rax, %rax
je 0x6aef
movq %r12, %rbp
cmpb $0x0, 0x14(%rbp)
je 0x6ae6
cmpl $0x1e, 0x14(%rbx)
jne 0x6ac0
movq (%rbp), %rcx
movq %r14, %rdi
leaq 0x54d1(%rip), %rsi      # 0xbf8f
jmp 0x6aca
movq (%rbp), %rcx
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x30f0
testq %rax, %rax
je 0x6b25
decq (%rax)
jne 0x6ae6
movq %rax, %rdi
callq 0x30d0
movq 0x8(%rbp), %rbp
testq %rbp, %rbp
jne 0x6aa4
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x6a84
leaq 0x28(%rsp), %rdi
callq 0x4a2c
movq 0x94b6(%rip), %r14      # 0xffc0
incq (%r14)
jmp 0x6b32
movq 0x947a(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x4ca4(%rip), %rsi      # 0xb7c4
callq 0x3120
leaq 0x28(%rsp), %rdi
callq 0x4a2c
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq