// File: /workspace/github_c_makefile_star2_O2/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, %ebp
andq $0x0, 0x18(%rsp)
movq %rsi, %rbx
andq $0x0, 0x28(%rsp)
movq %rdi, %r15
andq $0x0, 0x20(%rsp)
xorl %eax, %eax
movb %al, 0x7(%rsp)
movb %al, 0x6(%rsp)
testq %rsi, %rsi
je 0x55a7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x55bd
leaq 0x18(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x7(%rsp), %rcx
movq %rax, %rdi
callq 0x35db
movq %rax, %r13
testq %rax, %rax
jne 0x55d1
jmp 0x57f4
callq 0x3190
andq $0x0, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
xorl %r13d, %r13d
jmp 0x5629
callq 0x3190
andq $0x0, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
xorl %r13d, %r13d
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3140
testq %rax, %rax
je 0x5629
leaq 0x40(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x28(%rsp), %rsi
leaq 0x6(%rsp), %rcx
movq %rax, %rdi
callq 0x35db
movq %rax, %r14
testq %rax, %rax
je 0x57cc
cmpq $0x1, 0x40(%rsp)
jne 0x57b6
movq 0x28(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movl (%rcx), %eax
movl %eax, 0x14(%rsp)
movb $0x1, %r12b
jmp 0x564a
callq 0x3190
movq $0x0, 0x38(%rsp)
testq %rbx, %rbx
je 0x5691
xorl %r12d, %r12d
movl $0x0, 0x14(%rsp)
xorl %r14d, %r14d
movq %r13, 0x8(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x3140
testq %rax, %rax
je 0x56b1
movq 0x8952(%rip), %rcx      # 0xdfb8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x3060
cmpq $-0x1, %rax
je 0x578f
movq %rax, %r13
cmpl $0x3, %r13d
jae 0x5799
movq %r15, %rbx
movl %ebp, 0x10(%rsp)
jmp 0x56c9
movq %r15, %rbx
movq %r13, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
pushq $0x2
popq %r13
xorl %r12d, %r12d
movl $0x0, 0x14(%rsp)
xorl %r14d, %r14d
jmp 0x56c9
movq %r15, %rbx
movl %ebp, 0x10(%rsp)
callq 0x3190
movl %r12d, %eax
xorb $0x1, %al
movzbl %al, %r13d
addl %r13d, %r13d
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x9009(%rip), %rdi      # 0xe6e8
callq 0x32b0
testq %rax, %rax
je 0x5860
movq %rax, %rbp
movq %rbx, 0x10(%rax)
movl 0x30(%rbx), %eax
movl %eax, 0x18(%rbp)
andq $0x0, 0x20(%rbp)
andl $0x0, 0x40(%rbp)
andq $0x0, 0x48(%rbp)
andq $0x0, 0x58(%rbp)
movb %r12b, 0x60(%rbp)
movl 0x14(%rsp), %eax
movl %eax, 0x64(%rbp)
movl %r13d, 0x68(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbp)
incq (%rbx)
movq %rbx, %r12
movl 0x20(%rbx), %eax
leal 0x4(,%rax,4), %eax
movslq %eax, %rdi
callq 0x3370
movq %rax, 0x48(%rbp)
testq %rax, %rax
je 0x5853
testq %r15, %r15
je 0x581f
movq 0x30(%rsp), %rax
leaq (,%rax,4), %r13
movq %r13, %rdi
callq 0x3370
movq %rax, 0x58(%rbp)
testq %rax, %rax
je 0x5853
movq 0x30(%rsp), %rcx
movq %rcx, 0x50(%rbp)
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x31e0
jmp 0x5824
callq 0x31f0
testq %rax, %rax
jne 0x57af
movq 0x87e8(%rip), %rax      # 0xdf88
movq (%rax), %rdi
leaq 0x3322(%rip), %rsi      # 0x8acc
callq 0x3120
movq 0x8(%rsp), %r13
jmp 0x57cc
movq 0x87cb(%rip), %rax      # 0xdf88
movq (%rax), %rdi
leaq 0x32e0(%rip), %rsi      # 0x8aa7
callq 0x3120
testq %r13, %r13
je 0x57e0
cmpb $0x0, 0x7(%rsp)
jne 0x57e0
movq %r13, %rdi
callq 0x37d5
testq %r14, %r14
je 0x57f4
cmpb $0x0, 0x6(%rsp)
jne 0x57f4
movq %r14, %rdi
callq 0x37d5
cmpb $0x1, 0x7(%rsp)
jne 0x5805
movq 0x18(%rsp), %rdi
callq 0x3070
cmpb $0x1, 0x6(%rsp)
jne 0x58c8
movq 0x28(%rsp), %rdi
callq 0x3070
jmp 0x58c8
andq $0x0, 0x50(%rbp)
pushq $0x20
popq %rdi
callq 0x37fa
testq %rax, %rax
je 0x5853
movq 0x28(%r12), %rcx
movq %rcx, 0x8(%rax)
andq $0x0, 0x18(%rax)
movq %rbp, %rcx
addq $0x30, %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x5869
movq %rdx, (%rax)
jmp 0x586d
movq %rbp, %rdi
callq 0x37d5
callq 0x30e0
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
jmp 0x5875
movq %rax, 0x38(%rbp)
movq 0x8(%rsp), %rdi
movq %rax, (%rcx)
testq %rdi, %rdi
je 0x5886
cmpb $0x0, 0x7(%rsp)
jne 0x5886
callq 0x37d5
testq %r14, %r14
je 0x589a
cmpb $0x0, 0x6(%rsp)
jne 0x589a
movq %r14, %rdi
callq 0x37d5
cmpb $0x1, 0x7(%rsp)
jne 0x58a9
movq %r15, %rdi
callq 0x3070
cmpb $0x1, 0x6(%rsp)
jne 0x58ba
movq 0x38(%rsp), %rdi
callq 0x3070
testq %rbp, %rbp
je 0x58c8
movl 0x10(%rsp), %eax
movl %eax, 0x40(%rbp)
jmp 0x58ca
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq