// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0x3140
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x95f1
callq 0x3190
movl $0x0, -0x4(%rbp)
jmp 0x97b1
movq -0x38(%rbp), %rdi
callq 0x3350
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x9611
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movq -0x38(%rbp), %rdi
movq 0x89b4(%rip), %rax      # 0x11fd0
movq (%rax), %rsi
callq 0x3060
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x3a90
movq -0x30(%rbp), %rax
cmpq $-0x1, (%rax)
jne 0x9658
callq 0x31f0
cmpq $0x0, %rax
je 0x9658
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x9674
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq -0x20(%rbp), %rax
jl 0x968e
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jl 0x96ba
movq 0x893b(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq 0x51d0(%rip), %rsi      # 0xe877
movb $0x0, %al
callq 0x3300
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movq -0x10(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x3140
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x96e3
callq 0x3190
movl $0x0, -0x4(%rbp)
jmp 0x97b1
movq -0x38(%rbp), %rdi
callq 0x3350
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x9703
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movq -0x38(%rbp), %rdi
movq 0x88c2(%rip), %rax      # 0x11fd0
movq (%rax), %rsi
callq 0x3060
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x3a90
movq 0x10(%rbp), %rax
cmpq $-0x1, (%rax)
jne 0x9747
callq 0x31f0
cmpq $0x0, %rax
je 0x9747
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x9767
movq -0x28(%rbp), %rcx
subq $0x1, %rcx
movq 0x10(%rbp), %rax
addq (%rax), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x20(%rbp), %rax
jl 0x9781
movq 0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jle 0x97aa
movq 0x8848(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq 0x50ff(%rip), %rsi      # 0xe899
movb $0x0, %al
callq 0x3300
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97b1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)