// File: /workspace/github_c_makefile_star2_O0/WojciechMula[P]pyahocorasick/src/utils.c
// Function: _read_sequence__from_tuple
static bool
__read_sequence__from_tuple(PyObject* obj, TRIE_LETTER_TYPE** word, Py_ssize_t* wordlen) {
    Py_ssize_t i;
    Py_ssize_t size = PyTuple_GET_SIZE(obj);
    TRIE_LETTER_TYPE* tmpword;

    tmpword = (TRIE_LETTER_TYPE*)memory_alloc(size * TRIE_LETTER_SIZE);
    if (UNLIKELY(tmpword == NULL)) {
        PyErr_NoMemory();
        return false;
    }

    for (i=0; i < size; i++) {
        Py_ssize_t value = F(PyNumber_AsSsize_t)(F(PyTuple_GetItem)(obj, i), PyExc_ValueError);
        if (value == -1 && PyErr_Occurred()) {
            PyErr_Format(PyExc_ValueError, "item #%zd is not a number", i);
            memory_free(tmpword);
            return false;
        }


        // TODO: both min and max values should be configured
#if TRIE_LETTER_SIZE == 4
    #define MAX_VAL 4294967295l
#else
    #define MAX_VAL 65535ul
#endif
        if (value < 0 || value > MAX_VAL) {
            PyErr_Format(PyExc_ValueError, "item #%zd: value %zd outside range [%d..%lu]", i, value, 0, MAX_VAL);
            memory_free(tmpword);
            return false;
        }

        tmpword[i] = (TRIE_LETTER_TYPE)value;
    }

    *word = tmpword;
    *wordlen = size;

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x4000000, %esi        # imm = 0x4000000
callq 0x4450
cmpl $0x0, %eax
je 0x586d
jmp 0x588c
leaq 0x6bf1(%rip), %rdi      # 0xc465
leaq 0x6b1d(%rip), %rsi      # 0xc398
movl $0xf1, %edx
leaq 0x6bf1(%rip), %rcx      # 0xc478
callq 0x3130
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3450
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x58cc
callq 0x30e0
movb $0x0, -0x1(%rbp)
jmp 0x59cb
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x59b1
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3140
movq %rax, %rdi
movq 0xc68f(%rip), %rax      # 0x11f88
movq (%rax), %rsi
callq 0x3060
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
jne 0x5945
callq 0x31f0
cmpq $0x0, %rax
je 0x5945
movq 0xc66a(%rip), %rax      # 0x11f88
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x6b95(%rip), %rsi      # 0xc4c1
movb $0x0, %al
callq 0x3300
movq -0x38(%rbp), %rdi
callq 0x34b0
movb $0x0, -0x1(%rbp)
jmp 0x59cb
cmpq $0x0, -0x40(%rbp)
jl 0x5957
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x40(%rbp)
jle 0x598f
movq 0xc62a(%rip), %rax      # 0x11f88
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq 0x6b6b(%rip), %rsi      # 0xc4db
xorl %r8d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movb $0x0, %al
callq 0x3300
movq -0x38(%rbp), %rdi
callq 0x34b0
movb $0x0, -0x1(%rbp)
jmp 0x59cb
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x58d4
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)