// File: /workspace/github_c_makefile_star2_O2/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, %r12
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 0x7277
movq %rax, %rdi
callq 0x3350
movq %rax, %r13
pushq $-0x1
popq %rax
testq %r13, %r13
je 0x72ad
movq 0x6e1d(%rip), %rax      # 0xdfd0
movq (%rax), %rsi
movq %r13, %rdi
callq 0x3060
movq %rax, (%r12)
movq %r13, %rdi
callq 0x37d5
movq (%r12), %rax
cmpq $-0x1, %rax
movq 0x40(%rsp), %r13
je 0x72a0
testq %rax, %rax
jns 0x71e9
addq %rbx, %rax
movq %rax, (%r12)
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setl %al
testb %al, %cl
je 0x7280
movl %ebp, %esi
movq %r15, %rdi
callq 0x3140
testq %rax, %rax
je 0x7277
movq %rax, %rdi
callq 0x3350
testq %rax, %rax
je 0x72aa
movq %rax, %r15
movq 0x6da9(%rip), %r12      # 0xdfd0
movq (%r12), %rsi
movq %rax, %rdi
callq 0x3060
movq %rax, (%r13)
movq %r15, %rdi
callq 0x37d5
movq (%r13), %rax
cmpq $-0x1, %rax
je 0x72c5
testq %rax, %rax
jns 0x7258
addq %rbx, %rax
decq %rax
movq %rax, (%r13)
cmpq %r14, %rax
setge %cl
cmpq %rbx, %rax
setle %dl
xorl %eax, %eax
testb %dl, %cl
jne 0x72ad
movq (%r12), %rdi
leaq 0x35ae(%rip), %rsi      # 0xa823
jmp 0x7291
callq 0x3190
xorl %eax, %eax
jmp 0x72ad
movq 0x6d49(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
leaq 0x3570(%rip), %rsi      # 0xa801
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3300
jmp 0x72aa
callq 0x31f0
testq %rax, %rax
je 0x72bc
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rax
jmp 0x71dd
callq 0x31f0
testq %rax, %rax
jne 0x72aa
movq (%r13), %rax
jmp 0x7249