// File: /workspace/github_c_makefile_star2_O1/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
testb $0x10, 0xab(%rax)
jne 0x4896
movq 0xb710(%rip), %rax      # 0xff90
movq (%rax), %rdi
leaq 0x4bc1(%rip), %rsi      # 0x944b
callq 0x3120
xorl %ebx, %ebx
jmp 0x4969
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
testb $-0x80, 0x20(%rdi)
jne 0x48b0
movq %rbx, %rdi
callq 0x3040
movq 0x8(%rbx), %rax
testb $0x10, 0xab(%rax)
je 0x4978
movl 0x20(%rbx), %eax
testb %al, %al
jns 0x4981
movl %eax, %ecx
andl $0x1c, %ecx
cmpl $0x10, %ecx
jne 0x4902
testb $0x20, %al
jne 0x4936
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
jne 0x4944
leaq 0x4b3d(%rip), %rdi      # 0x9427
leaq 0x4ac7(%rip), %rsi      # 0x93b8
leaq 0x4acc(%rip), %rcx      # 0x93c4
movl $0x9d, %edx
callq 0x3130
movq %rbx, %rdi
callq 0x3110
movq %rax, (%r12)
movq 0x8(%rbx), %rax
testb $0x10, 0xab(%rax)
je 0x49a0
testb $-0x80, 0x20(%rbx)
je 0x49b2
movq 0x10(%rbx), %rax
movq %rax, (%r15)
movb $0x1, (%r14)
jmp 0x4969
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 0x49a9
testb $-0x80, 0x20(%rbx)
je 0x49d1
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 0x4a24(%rip), %rdi      # 0x93a3
jmp 0x4988
leaq 0x4a87(%rip), %rdi      # 0x940f
leaq 0x4a29(%rip), %rsi      # 0x93b8
leaq 0x4a2e(%rip), %rcx      # 0x93c4
movl $0x9c, %edx
callq 0x3130
leaq 0x49fc(%rip), %rdi      # 0x93a3
jmp 0x49b9
leaq 0x49f3(%rip), %rdi      # 0x93a3
jmp 0x49d8
leaq 0x4a56(%rip), %rdi      # 0x940f
leaq 0x49f8(%rip), %rsi      # 0x93b8
leaq 0x49fd(%rip), %rcx      # 0x93c4
movl $0xa5, %edx
callq 0x3130
leaq 0x4a37(%rip), %rdi      # 0x940f
leaq 0x49d9(%rip), %rsi      # 0x93b8
leaq 0x49de(%rip), %rcx      # 0x93c4
movl $0x9e, %edx
callq 0x3130