// File: /workspace/github_c_makefile_star2_O3/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 0x474a
movq 0xb85c(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x4d1d(%rip), %rsi      # 0x945b
callq 0x3120
xorl %ebx, %ebx
jmp 0x4821
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
testb $-0x80, 0x20(%rdi)
jne 0x476f
movq %rbx, %rdi
callq 0x3040
movq 0x8(%rbx), %rax
movq 0xa8(%rax), %rax
btl $0x1c, %eax
jae 0x4830
movl 0x20(%rbx), %eax
testb %al, %al
jns 0x4839
movl %eax, %ecx
andl $0x1c, %ecx
cmpl $0x10, %ecx
jne 0x47ba
testb $0x20, %al
jne 0x47ee
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
jne 0x47fc
leaq 0x4c95(%rip), %rdi      # 0x9437
leaq 0x4c1f(%rip), %rsi      # 0x93c8
leaq 0x4c24(%rip), %rcx      # 0x93d4
movl $0x9d, %edx
callq 0x3130
movq %rbx, %rdi
callq 0x3110
movq %rax, (%r12)
movq 0x8(%rbx), %rax
testb $0x10, 0xab(%rax)
je 0x4858
testb $-0x80, 0x20(%rbx)
je 0x486a
movq 0x10(%rbx), %rax
movq %rax, (%r15)
movb $0x1, (%r14)
jmp 0x4821
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 0x4861
testb $-0x80, 0x20(%rbx)
je 0x4889
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 0x4b7c(%rip), %rdi      # 0x93b3
jmp 0x4840
leaq 0x4bdf(%rip), %rdi      # 0x941f
leaq 0x4b81(%rip), %rsi      # 0x93c8
leaq 0x4b86(%rip), %rcx      # 0x93d4
movl $0x9c, %edx
callq 0x3130
leaq 0x4b54(%rip), %rdi      # 0x93b3
jmp 0x4871
leaq 0x4b4b(%rip), %rdi      # 0x93b3
jmp 0x4890
leaq 0x4bae(%rip), %rdi      # 0x941f
leaq 0x4b50(%rip), %rsi      # 0x93c8
leaq 0x4b55(%rip), %rcx      # 0x93d4
movl $0xa5, %edx
callq 0x3130
leaq 0x4b8f(%rip), %rdi      # 0x941f
leaq 0x4b31(%rip), %rsi      # 0x93c8
leaq 0x4b36(%rip), %rcx      # 0x93d4
movl $0x9e, %edx
callq 0x3130