// File: /workspace/github_c_makefile_star2_O2/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 0x66cc
movq %rsi, %r15
movq %rdi, %rbx
xorl %r14d, %r14d
leaq 0x28(%rsp), %rcx
xorl %edx, %edx
callq 0x376f
testb %al, %al
je 0x66d6
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x66b3
movq %rax, %r14
movq %rax, %rdi
callq 0x32a0
testl %eax, %eax
je 0x669d
movq 0x28(%rsp), %r8
leaq 0x18(%rsp), %rax
movq %rax, (%rsp)
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
leaq 0x20(%rsp), %r9
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x7161
testl %eax, %eax
jne 0x66b3
movq 0x28(%rbx), %r12
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x42bd(%rip), %rbp      # 0xa8de
movq %rax, 0x8(%rsp)
cmpq %rax, %r15
jge 0x66c2
movq 0x28(%rbx), %rsi
movq 0x10(%rsp), %rax
movl (%rax,%r15,4), %edx
movq %r12, %rdi
callq 0x72d8
movq %rax, %r12
movq %rax, %r13
testq %r13, %r13
je 0x6693
cmpb $0x0, 0x14(%r13)
je 0x668d
cmpl $0x1e, 0x14(%rbx)
jne 0x666c
movq (%r13), %rcx
movq %r14, %rdi
leaq 0x4925(%rip), %rsi      # 0xaf8f
jmp 0x6676
movq (%r13), %rcx
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x30f0
testq %rax, %rax
je 0x66b3
movq %rax, %rdi
callq 0x37d5
movq 0x8(%r13), %r13
jmp 0x664a
incq %r15
movq 0x8(%rsp), %rax
jmp 0x6626
movq 0x78ec(%rip), %rax      # 0xdf90
movq (%rax), %rdi
leaq 0x4116(%rip), %rsi      # 0xa7c4
callq 0x3120
leaq 0x28(%rsp), %rdi
callq 0x37ab
xorl %r14d, %r14d
jmp 0x66d6
leaq 0x28(%rsp), %rdi
callq 0x37ab
movq 0x78ed(%rip), %r14      # 0xdfc0
incq (%r14)
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq