// File: /workspace/github_c_makefile_star2_O3/WojciechMula[P]pyahocorasick/src/utils.c
// Function: pymod_parse_start_end
static int
pymod_parse_start_end(
    PyObject* args,
    int idx_start, int idx_end,
    const Py_ssize_t min, const Py_ssize_t max,
    Py_ssize_t* Start, Py_ssize_t* End
) {
    PyObject* obj;
#define start (*Start)
#define end (*End)

    start   = min;
    end     = max;

    // first argument
    obj = F(PyTuple_GetItem)(args, idx_start);
    if (obj == NULL) {
        PyErr_Clear();
        return 0;
    }

    obj = F(PyNumber_Index)(obj);
    if (obj == NULL)
        return -1;

    start = F(PyNumber_AsSsize_t)(obj, PyExc_IndexError);
    Py_DECREF(obj);
    if (start == -1 and PyErr_Occurred())
        return -1;

    if (start < 0)
        start = max + start;

    if (start < min or start >= max) {
        PyErr_Format(PyExc_IndexError, "start index not in range %zd..%zd", min, max);
        return -1;
    }

    // second argument
    obj = F(PyTuple_GetItem)(args, idx_end);
    if (obj == NULL) {
        PyErr_Clear();
        return 0;
    }

    obj = F(PyNumber_Index)(obj);
    if (obj == NULL)
        return -1;

    end = F(PyNumber_AsSsize_t)(obj, PyExc_IndexError);
    Py_DECREF(obj);
    if (end == -1 and PyErr_Occurred())
        return -1;

    if (end < 0)
        end = max - 1 + end;

    if (end < min or end > max) {
        PyErr_Format(PyExc_IndexError, "end index not in range %zd..%zd", min, max);
        return -1;
    }

    return 0;

#undef start
#undef end
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %r13
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %ebp
movq %rdi, %r15
movq 0x40(%rsp), %rax
movq %rcx, (%r9)
movq %r8, (%rax)
movl %esi, %esi
callq 0x3140
testq %rax, %rax
je 0x7646
movl %ebp, 0x4(%rsp)
movq %rax, %rdi
callq 0x3350
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x767e
movq %rax, %r12
movq 0x8a6c(%rip), %rax      # 0xffd0
movq (%rax), %rsi
movq %r12, %rdi
callq 0x3060
movq %rax, (%r13)
decq (%r12)
jne 0x7581
movq %r12, %rdi
callq 0x30d0
movq (%r13), %rax
cmpq $-0x1, %rax
je 0x7674
testq %rax, %rax
jns 0x759b
addq %rbx, %rax
movq %rax, (%r13)
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setl %al
testb %al, %cl
je 0x764f
movl 0x4(%rsp), %esi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x7646
movq %rax, %rdi
callq 0x3350
testq %rax, %rax
je 0x767e
movq %rax, %r15
movq 0x89f1(%rip), %rax      # 0xffd0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x3060
movq 0x40(%rsp), %r12
movq %rax, (%r12)
decq (%r15)
jne 0x7600
movq %r15, %rdi
callq 0x30d0
movq (%r12), %rax
cmpq $-0x1, %rax
je 0x7698
testq %rax, %rax
jns 0x7621
addq %rbx, %rax
decq %rax
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setle %al
xorl %ebp, %ebp
testb %al, %cl
jne 0x767e
movq 0x8996(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x41ef(%rip), %rsi      # 0xb833
jmp 0x7660
callq 0x3190
xorl %ebp, %ebp
jmp 0x767e
movq 0x897a(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x41b1(%rip), %rsi      # 0xb811
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3300
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x767e
callq 0x31f0
testq %rax, %rax
je 0x768f
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rax
jmp 0x758f
callq 0x31f0
testq %rax, %rax
jne 0x767e
movq 0x40(%rsp), %rax
movq (%rax), %rax
jmp 0x760e