// File: /workspace/github_c_makefile_star2_O0/WojciechMula[P]pyahocorasick/src/Automaton.c
// Function: automaton_items_create
static PyObject*
automaton_items_create(PyObject* self, PyObject* args, const ItemsType type) {
#define automaton ((Automaton*)self)
    PyObject* arg1 = NULL;
    PyObject* arg2 = NULL;
    PyObject* arg3 = NULL;
    TRIE_LETTER_TYPE* word = NULL;
    TRIE_LETTER_TYPE* tmp = NULL;
    Py_ssize_t wordlen = 0;

    TRIE_LETTER_TYPE wildcard;
    bool use_wildcard = false;
    PatternMatchType matchtype = MATCH_AT_LEAST_PREFIX;

    AutomatonItemsIter* iter;

    bool word_is_copy = false;
    bool tmp_is_copy = false;

    // arg 1: prefix/prefix pattern
    if (args)
        arg1 = F(PyTuple_GetItem)(args, 0);
    else
        arg1 = NULL;

    if (arg1) {
        arg1 = pymod_get_string(arg1, &word, &wordlen, &word_is_copy);
        if (arg1 == NULL)
            goto error;
    }
    else {
        PyErr_Clear();
        word = NULL;
        wordlen = 0;
    }

    // arg 2: wildcard
    if (args)
        arg2 = F(PyTuple_GetItem)(args, 1);
    else
        arg2 = NULL;

    if (arg2) {
        Py_ssize_t len = 0;

        arg2 = pymod_get_string(arg2, &tmp, &len, &tmp_is_copy);
        if (arg2 == NULL) {
            goto error;
        } else {
            if (len == 1) {
                wildcard = tmp[0];
                use_wildcard = true;
            }
            else {
                PyErr_SetString(PyExc_ValueError, "Wildcard must be a single character.");
                goto error;
            }
        }
    }
    else {
        PyErr_Clear();
        wildcard = 0;
        use_wildcard = false;
    }

    // arg3: matchtype
    matchtype = MATCH_AT_LEAST_PREFIX;
    if (args) {
        arg3 = F(PyTuple_GetItem)(args, 2);
        if (arg3) {
            Py_ssize_t val = F(PyNumber_AsSsize_t)(arg3, PyExc_OverflowError);
            if (val == -1 and PyErr_Occurred())
                goto error;

            switch ((PatternMatchType)val) {
                case MATCH_AT_LEAST_PREFIX:
                case MATCH_AT_MOST_PREFIX:
                case MATCH_EXACT_LENGTH:
                    matchtype = (PatternMatchType)val;
                    break;

                default:
                    PyErr_SetString(PyExc_ValueError,
                        "The optional how third argument must be one of: "
                        "MATCH_EXACT_LENGTH, MATCH_AT_LEAST_PREFIX or MATCH_AT_LEAST_PREFIX"
                    );
                    goto error;
            }
        }
        else {
            PyErr_Clear();
            if (use_wildcard)
                matchtype = MATCH_EXACT_LENGTH;
            else
                matchtype = MATCH_AT_LEAST_PREFIX;
        }
    }

    //
    iter = (AutomatonItemsIter*)automaton_items_iter_new(
                    automaton,
                    word,
                    wordlen,
                    use_wildcard,
                    wildcard,
                    matchtype);

    maybe_decref(word_is_copy, arg1)
    maybe_decref(tmp_is_copy, arg2)
    maybe_free(word_is_copy, word)
    maybe_free(tmp_is_copy, tmp)

    if (iter) {
        iter->type = type;
        return (PyObject*)iter;
    }
    else
        return NULL;


error:
    maybe_decref(word_is_copy, arg1)
    maybe_decref(tmp_is_copy, arg2)
    maybe_free(word_is_copy, word)
    maybe_free(tmp_is_copy, tmp)
    return NULL;
#undef automaton
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x0, -0x55(%rbp)
movl $0x2, -0x5c(%rbp)
movb $0x0, -0x69(%rbp)
movb $0x0, -0x6a(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6a53
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3140
movq %rax, -0x28(%rbp)
jmp 0x6a5b
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6a89
movq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x69(%rbp), %rcx
callq 0x35d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6a87
jmp 0x6c76
jmp 0x6a9e
callq 0x3190
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6ab9
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x3140
movq %rax, -0x30(%rbp)
jmp 0x6ac1
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6b2a
movq $0x0, -0x78(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x6a(%rbp), %rcx
callq 0x35d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6af5
jmp 0x6c76
cmpq $0x1, -0x78(%rbp)
jne 0x6b0b
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movb $0x1, -0x55(%rbp)
jmp 0x6b26
movq 0xb476(%rip), %rax      # 0x11f88
movq (%rax), %rdi
leaq 0x5fe5(%rip), %rsi      # 0xcb01
callq 0x3120
jmp 0x6c76
jmp 0x6b28
jmp 0x6b3a
callq 0x3190
movl $0x0, -0x54(%rbp)
movb $0x0, -0x55(%rbp)
movl $0x2, -0x5c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6be2
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x3140
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x6bc3
movq -0x38(%rbp), %rdi
movq 0xb448(%rip), %rax      # 0x11fb8
movq (%rax), %rsi
callq 0x3060
movq %rax, -0x80(%rbp)
cmpq $-0x1, -0x80(%rbp)
jne 0x6b93
callq 0x31f0
cmpq $0x0, %rax
je 0x6b93
jmp 0x6c76
movl -0x80(%rbp), %eax
subl $0x2, %eax
ja 0x6ba6
jmp 0x6b9d
movq -0x80(%rbp), %rax
movl %eax, -0x5c(%rbp)
jmp 0x6bc1
movq 0xb3db(%rip), %rax      # 0x11f88
movq (%rax), %rdi
leaq 0x5f6f(%rip), %rsi      # 0xcb26
callq 0x3120
jmp 0x6c76
jmp 0x6be0
callq 0x3190
testb $0x1, -0x55(%rbp)
je 0x6bd7
movl $0x0, -0x5c(%rbp)
jmp 0x6bde
movl $0x2, -0x5c(%rbp)
jmp 0x6be0
jmp 0x6be2
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
movb -0x55(%rbp), %al
movl -0x54(%rbp), %r8d
movl -0x5c(%rbp), %r9d
andb $0x1, %al
movzbl %al, %ecx
callq 0x6ce0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6c1d
testb $0x1, -0x69(%rbp)
jne 0x6c1d
movq -0x28(%rbp), %rdi
callq 0x3a90
cmpq $0x0, -0x30(%rbp)
je 0x6c33
testb $0x1, -0x6a(%rbp)
jne 0x6c33
movq -0x30(%rbp), %rdi
callq 0x3a90
testb $0x1, -0x69(%rbp)
je 0x6c42
movq -0x40(%rbp), %rdi
callq 0x34b0
testb $0x1, -0x6a(%rbp)
je 0x6c51
movq -0x48(%rbp), %rdi
callq 0x34b0
cmpq $0x0, -0x68(%rbp)
je 0x6c6c
movl -0x1c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6cc8
movq $0x0, -0x8(%rbp)
jmp 0x6cc8
cmpq $0x0, -0x28(%rbp)
je 0x6c8c
testb $0x1, -0x69(%rbp)
jne 0x6c8c
movq -0x28(%rbp), %rdi
callq 0x3a90
cmpq $0x0, -0x30(%rbp)
je 0x6ca2
testb $0x1, -0x6a(%rbp)
jne 0x6ca2
movq -0x30(%rbp), %rdi
callq 0x3a90
testb $0x1, -0x69(%rbp)
je 0x6cb1
movq -0x40(%rbp), %rdi
callq 0x34b0
testb $0x1, -0x6a(%rbp)
je 0x6cc0
movq -0x48(%rbp), %rdi
callq 0x34b0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)