// File: /workspace/github_c_makefile_star2_O1/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 0x76e1
movl %ebp, 0x4(%rsp)
movq %rax, %rdi
callq 0x3350
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x771d
movq %rax, %r12
movq 0x89d7(%rip), %rax      # 0xffd0
movq (%rax), %rsi
movq %r12, %rdi
callq 0x3060
movq %rax, (%r13)
decq (%r12)
jne 0x7616
movq %r12, %rdi
callq 0x30d0
cmpq $-0x1, (%r13)
je 0x770f
movq (%r13), %rax
testq %rax, %rax
jns 0x7631
addq %rbx, %rax
movq %rax, (%r13)
movq (%r13), %rax
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setl %al
testb %al, %cl
je 0x76ea
movl 0x4(%rsp), %esi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x76e1
movq %rax, %rdi
callq 0x3350
testq %rax, %rax
je 0x771d
movq %rax, %r15
movq 0x8957(%rip), %rax      # 0xffd0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x3060
movq 0x40(%rsp), %r12
movq %rax, (%r12)
decq (%r15)
jne 0x769a
movq %r15, %rdi
callq 0x30d0
cmpq $-0x1, (%r12)
je 0x772e
movq (%r12), %rax
testq %rax, %rax
jns 0x76b8
addq %rbx, %rax
decq %rax
movq %rax, (%r12)
movq (%r12), %rax
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setle %al
xorl %ebp, %ebp
testb %al, %cl
jne 0x771d
movq 0x88fb(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x4144(%rip), %rsi      # 0xb823
jmp 0x76fb
callq 0x3190
xorl %ebp, %ebp
jmp 0x771d
movq 0x88df(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x4106(%rip), %rsi      # 0xb801
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3300
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x771d
callq 0x31f0
testq %rax, %rax
je 0x7621
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31f0
testq %rax, %rax
jne 0x771d
jmp 0x76a5