// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10(%rax)
je 0x8092
movq 0x9f3c(%rip), %rdi      # 0x11fc0
callq 0x4a30
movq %rax, -0x8(%rbp)
jmp 0x826e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
leaq -0x38(%rbp), %rcx
callq 0x39e0
testb $0x1, %al
jne 0x80b6
movq $0x0, -0x8(%rbp)
jmp 0x826e
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x3140
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x80e5
leaq -0x38(%rbp), %rdi
callq 0x3a40
movq $0x0, -0x8(%rbp)
jmp 0x826e
movq -0x50(%rbp), %rdi
callq 0x32a0
cmpl $0x0, %eax
jne 0x811f
movq 0x9e96(%rip), %rax      # 0x11f90
movq (%rax), %rdi
leaq 0x6736(%rip), %rsi      # 0xe83a
callq 0x3120
leaq -0x38(%rbp), %rdi
callq 0x3a40
movq $0x0, -0x8(%rbp)
jmp 0x826e
jmp 0x8121
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %r8
movl $0x2, %esi
movl $0x3, %edx
xorl %eax, %eax
movl %eax, %ecx
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x9590
cmpl $0x0, %eax
je 0x8163
leaq -0x38(%rbp), %rdi
callq 0x3a40
movq $0x0, -0x8(%rbp)
jmp 0x826e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x48(%rbp), %rax
jge 0x8255
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %edx
callq 0x97c0
movq %rax, -0x70(%rbp)
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x8242
movq -0x70(%rbp), %rax
cmpb $0x0, 0x14(%rax)
je 0x8231
movq -0x10(%rbp), %rax
cmpl $0x1e, 0x14(%rax)
jne 0x81eb
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x70(%rbp), %rax
movq (%rax), %rcx
leaq 0x6eb1(%rip), %rsi      # 0xf08f
movb $0x0, %al
callq 0x30f0
movq %rax, -0x58(%rbp)
jmp 0x820c
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x70(%rbp), %rax
movq (%rax), %rcx
leaq 0x6753(%rip), %rsi      # 0xe954
movb $0x0, %al
callq 0x30f0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x8226
leaq -0x38(%rbp), %rdi
callq 0x3a40
movq $0x0, -0x8(%rbp)
jmp 0x826e
movq -0x58(%rbp), %rdi
callq 0x3a90
jmp 0x8231
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x81a9
jmp 0x8244
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x8177
leaq -0x38(%rbp), %rdi
callq 0x3a40
movq 0x9d5b(%rip), %rdi      # 0x11fc0
callq 0x4a30
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)