// File: /workspace/github_c_makefile_star2_O2/WojciechMula[P]pyahocorasick/src/utils.c
// Function: pymod_get_string
static PyObject*
pymod_get_string(PyObject* obj, TRIE_LETTER_TYPE** word, Py_ssize_t* wordlen, bool* is_copy) {

#ifdef INPUT_KEEPS_COPY
    Py_ssize_t i;
    char* bytes;
#endif

#if defined PEP393_UNICODE
    if (F(PyUnicode_Check)(obj)) {
    PyUnicode_READY(obj);
    if (PyUnicode_KIND(obj) == PyUnicode_4BYTE_KIND) {
            *word = (TRIE_LETTER_TYPE*)(PyUnicode_4BYTE_DATA(obj));
            *wordlen = PyUnicode_GET_LENGTH(obj);
            *is_copy = false;
            Py_INCREF(obj);

        return obj;
    } else {
        *word = PyUnicode_AsUCS4Copy(obj);
        *wordlen = PyUnicode_GET_LENGTH(obj);
        *is_copy = true;
        // No INCREF - we have our copy
        return obj;
    }
    }
    else {
    PyErr_SetString(PyExc_TypeError, "string expected");
    return NULL;
    }
#elif defined PY3K
#   ifdef AHOCORASICK_UNICODE
        if (F(PyUnicode_Check)(obj)) {
            *word = (TRIE_LETTER_TYPE*)(PyUnicode_AS_UNICODE(obj));
            *wordlen = PyUnicode_GET_SIZE(obj);
            Py_INCREF(obj);
            return obj;
        }
        else {
            PyErr_SetString(PyExc_TypeError, "string expected");
            return NULL;
        }
#   else
#       ifndef INPUT_KEEPS_COPY
#           error "defines inconsistency"
#       endif
        if (F(PyBytes_Check)(obj)) {
            *wordlen = PyBytes_GET_SIZE(obj);
            *word    = (TRIE_LETTER_TYPE*)memory_alloc(*wordlen * TRIE_LETTER_SIZE);
            if (*word == NULL) {
                PyErr_NoMemory();
                return NULL;
            }

            bytes = PyBytes_AS_STRING(obj);
            for (i=0; i < *wordlen; i++) {
                (*word)[i] = bytes[i];
            }
            // Note: there is no INCREF
            return obj;
        }
        else {
            PyErr_SetString(PyExc_TypeError, "bytes expected");
            return NULL;
        }
#   endif
#else // PY_MAJOR_VERSION == 3
#       ifndef INPUT_KEEPS_COPY
#           error "defines inconsistency"
#       endif
    if (F(PyString_Check)(obj)) {
        *wordlen = PyString_GET_SIZE(obj);
        *word    = (TRIE_LETTER_TYPE*)memory_alloc(*wordlen * TRIE_LETTER_SIZE);
        if (*word == NULL) {
            PyErr_NoMemory();
            return NULL;
        }


        bytes = PyString_AS_STRING(obj);
        for (i=0; i < *wordlen; i++) {
            (*word)[i] = bytes[i];
        };

        Py_INCREF(obj);
        return obj;
    } else {
        PyErr_SetString(PyExc_TypeError, "string required");
        return NULL;
    }
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq 0x8(%rdi), %rax
movq 0xa8(%rax), %rax
btl $0x1c, %eax
jb 0x3611
movq 0xa995(%rip), %rax      # 0xdf90
movq (%rax), %rdi
leaq 0x4e46(%rip), %rsi      # 0x844b
callq 0x3120
xorl %ebx, %ebx
jmp 0x36e8
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
testb $-0x80, 0x20(%rdi)
jne 0x3636
movq %rbx, %rdi
callq 0x3040
movq 0x8(%rbx), %rax
movq 0xa8(%rax), %rax
btl $0x1c, %eax
jae 0x36f7
movl 0x20(%rbx), %eax
testb %al, %al
jns 0x3700
movl %eax, %ecx
andl $0x1c, %ecx
cmpl $0x10, %ecx
jne 0x3681
testb $0x20, %al
jne 0x36b5
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
jne 0x36c3
leaq 0x4dbe(%rip), %rdi      # 0x8427
leaq 0x4d48(%rip), %rsi      # 0x83b8
leaq 0x4d4d(%rip), %rcx      # 0x83c4
movl $0x9d, %edx
callq 0x3130
movq %rbx, %rdi
callq 0x3110
movq %rax, (%r12)
movq 0x8(%rbx), %rax
testb $0x10, 0xab(%rax)
je 0x371f
testb $-0x80, 0x20(%rbx)
je 0x3731
movq 0x10(%rbx), %rax
movq %rax, (%r15)
movb $0x1, (%r14)
jmp 0x36e8
leaq 0x30(%rbx), %rcx
leaq 0x48(%rbx), %rdx
testb $0x40, %al
cmoveq %rdx, %rcx
movq %rcx, (%r12)
movq 0x8(%rbx), %rax
testb $0x10, 0xab(%rax)
je 0x3728
testb $-0x80, 0x20(%rbx)
je 0x3750
movq 0x10(%rbx), %rax
movq %rax, (%r15)
movb $0x0, (%r14)
incq (%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x4ca5(%rip), %rdi      # 0x83a3
jmp 0x3707
leaq 0x4d08(%rip), %rdi      # 0x840f
leaq 0x4caa(%rip), %rsi      # 0x83b8
leaq 0x4caf(%rip), %rcx      # 0x83c4
movl $0x9c, %edx
callq 0x3130
leaq 0x4c7d(%rip), %rdi      # 0x83a3
jmp 0x3738
leaq 0x4c74(%rip), %rdi      # 0x83a3
jmp 0x3757
leaq 0x4cd7(%rip), %rdi      # 0x840f
leaq 0x4c79(%rip), %rsi      # 0x83b8
leaq 0x4c7e(%rip), %rcx      # 0x83c4
movl $0xa5, %edx
callq 0x3130
leaq 0x4cb8(%rip), %rdi      # 0x840f
leaq 0x4c5a(%rip), %rsi      # 0x83b8
leaq 0x4c5f(%rip), %rcx      # 0x83c4
movl $0x9e, %edx
callq 0x3130