// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r13d
movq %rdi, %r12
xorl %r15d, %r15d
movq %r15, 0x20(%rsp)
movq %r15, 0x30(%rsp)
movq %r15, 0x18(%rsp)
movb %r15b, 0x3(%rsp)
movb %r15b, 0x2(%rsp)
testq %rsi, %rsi
je 0x593a
movq %rsi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x5986
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x3(%rsp), %rcx
movq %rax, %rdi
callq 0x4714
movq %rax, %r14
testq %rax, %rax
jne 0x5998
jmp 0x5c64
movl %r13d, 0x4(%rsp)
callq 0x3190
movq $0x0, 0x18(%rsp)
callq 0x3190
movl $0x2, %r13d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
jmp 0x5a7f
callq 0x3190
xorl %r14d, %r14d
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movl $0x1, %esi
movq %rbx, %rdi
callq 0x3140
movq %rax, %rbp
testq %rax, %rax
je 0x59f7
leaq 0x40(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x30(%rsp), %rsi
leaq 0x2(%rsp), %rcx
movq %rbp, %rdi
callq 0x4714
movq %rax, %r15
testq %rax, %rax
je 0x5c32
cmpq $0x1, 0x40(%rsp)
jne 0x5bf5
movq %r15, 0x8(%rsp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movl (%rcx), %r15d
jmp 0x5a11
callq 0x3190
movq $0x0, 0x28(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movl %r13d, 0x4(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x3140
testq %rax, %rax
je 0x5a52
movq 0xa589(%rip), %rcx      # 0xffb8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x3060
cmpq $-0x1, %rax
je 0x5c0d
movq %rax, %r13
cmpl $0x3, %r13d
jb 0x5a64
jmp 0x5c17
xorl %r13d, %r13d
testq %rbp, %rbp
sete %r13b
callq 0x3190
addl %r13d, %r13d
testq %rbp, %rbp
setne %bpl
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0xac62(%rip), %rdi      # 0x106e8
callq 0x32b0
testq %rax, %rax
je 0x5b38
movq %rax, %rbx
movq %r12, 0x10(%rax)
movl 0x30(%r12), %eax
movl %eax, 0x18(%rbx)
xorl %eax, %eax
movq %rax, 0x20(%rbx)
movl $0x0, 0x40(%rbx)
movq %rax, 0x48(%rbx)
movq %rax, 0x58(%rbx)
movb %bpl, 0x60(%rbx)
movl %r15d, 0x64(%rbx)
movl %r13d, 0x68(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
incq (%r12)
movq %r12, %rbp
movl 0x20(%r12), %eax
leal 0x4(,%rax,4), %eax
movslq %eax, %rdi
callq 0x3370
movq %rax, 0x48(%rbx)
testq %rax, %rax
movq 0x8(%rsp), %r15
movq 0x38(%rsp), %r12
je 0x5c9a
cmpq $0x0, 0x10(%rsp)
je 0x5b45
leaq (,%r12,4), %r13
movq %r13, %rdi
callq 0x3370
movq %rax, 0x58(%rbx)
testq %rax, %rax
je 0x5c9a
movq %r12, 0x50(%rbx)
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x31e0
jmp 0x5b4d
xorl %ebx, %ebx
movl 0x4(%rsp), %ebp
movq 0x8(%rsp), %r15
jmp 0x5b90
movq $0x0, 0x50(%rbx)
movl $0x20, %edi
callq 0x3370
testq %rax, %rax
je 0x5c9a
movq %rbx, %rcx
addq $0x30, %rcx
xorl %edx, %edx
movq %rdx, (%rax)
movq 0x28(%rbp), %rsi
movq %rsi, 0x8(%rax)
movq %rdx, 0x18(%rax)
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x5b85
movq %rdx, (%rax)
jmp 0x5b89
movq %rax, 0x38(%rbx)
movl 0x4(%rsp), %ebp
movq %rax, (%rcx)
testq %r14, %r14
je 0x5ba9
cmpb $0x0, 0x3(%rsp)
jne 0x5ba9
decq (%r14)
jne 0x5ba9
movq %r14, %rdi
callq 0x30d0
testq %r15, %r15
je 0x5bc2
cmpb $0x0, 0x2(%rsp)
jne 0x5bc2
decq (%r15)
jne 0x5bc2
movq %r15, %rdi
callq 0x30d0
cmpb $0x1, 0x3(%rsp)
jne 0x5bd3
movq 0x10(%rsp), %rdi
callq 0x3070
cmpb $0x1, 0x2(%rsp)
jne 0x5be4
movq 0x28(%rsp), %rdi
callq 0x3070
testq %rbx, %rbx
je 0x5c86
movl %ebp, 0x40(%rbx)
jmp 0x5c88
movq 0xa38c(%rip), %rax      # 0xff88
movq (%rax), %rdi
leaq 0x3eb1(%rip), %rsi      # 0x9ab7
callq 0x3120
jmp 0x5c32
callq 0x31f0
testq %rax, %rax
jne 0x5c2d
movq 0xa36a(%rip), %rax      # 0xff88
movq (%rax), %rdi
leaq 0x3eb4(%rip), %rsi      # 0x9adc
callq 0x3120
movq 0x8(%rsp), %r15
testq %r14, %r14
je 0x5c4b
cmpb $0x0, 0x3(%rsp)
jne 0x5c4b
decq (%r14)
jne 0x5c4b
movq %r14, %rdi
callq 0x30d0
testq %r15, %r15
je 0x5c64
cmpb $0x0, 0x2(%rsp)
jne 0x5c64
decq (%r15)
jne 0x5c64
movq %r15, %rdi
callq 0x30d0
cmpb $0x1, 0x3(%rsp)
jne 0x5c75
movq 0x20(%rsp), %rdi
callq 0x3070
cmpb $0x1, 0x2(%rsp)
jne 0x5c86
movq 0x30(%rsp), %rdi
callq 0x3070
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x3fa5
xorl %ebx, %ebx
movl 0x4(%rsp), %ebp
jmp 0x5b90