// File: /workspace/github_c_makefile_star2_O3/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 0x6a44
movq %rsi, %r15
movq %rdi, %rbx
xorl %r14d, %r14d
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x6a73
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x45cd
testb %al, %al
je 0x6a70
movl $0x1, %esi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x6a66
movq %rax, %r14
movq %rax, %rdi
callq 0x32a0
testl %eax, %eax
je 0x6a50
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 0x750c
testl %eax, %eax
jne 0x6a66
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %r15
jge 0x6a3a
movq 0x28(%rbx), %r12
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x4f29(%rip), %r13      # 0xb8ee
movq 0x28(%rbx), %rsi
movq 0x8(%rsp), %rax
movl (%rax,%r15,4), %edx
movq %r12, %rdi
callq 0x76af
movq %rax, %r12
testq %rax, %rax
je 0x6a30
movq %r12, %rbp
cmpb $0x0, 0x14(%rbp)
je 0x6a27
cmpl $0x1e, 0x14(%rbx)
jne 0x6a01
movq (%rbp), %rcx
movq %r14, %rdi
leaq 0x55a0(%rip), %rsi      # 0xbf9f
jmp 0x6a0b
movq (%rbp), %rcx
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x30f0
testq %rax, %rax
je 0x6a66
decq (%rax)
jne 0x6a27
movq %rax, %rdi
callq 0x30d0
movq 0x8(%rbp), %rbp
testq %rbp, %rbp
jne 0x69e5
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x69c5
leaq 0x28(%rsp), %rdi
callq 0x48e4
movq 0x9575(%rip), %r14      # 0xffc0
incq (%r14)
jmp 0x6a73
movq 0x9539(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x4d73(%rip), %rsi      # 0xb7d4
callq 0x3120
leaq 0x28(%rsp), %rdi
callq 0x48e4
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq