// File: /workspace/github_c_makefile_star2_O2/seojangho[P]clee/simclist.c
// Function: list_delete_range
int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend) {
    struct list_entry_s *lastvalid, *tmp, *tmp2;
    unsigned int i;
    int movedx;
    unsigned int numdel, midposafter;

    if (l->iter_active || posend < posstart || posend >= l->numels) return -1;

    tmp = list_findpos(l, posstart);    /* first el to be deleted */
    lastvalid = tmp->prev;              /* last valid element */

    numdel = posend - posstart + 1;
    midposafter = (l->numels-1-numdel)/2;

    midposafter = midposafter < posstart ? midposafter : midposafter+numdel;
    movedx = midposafter - (l->numels-1)/2;

    if (movedx > 0) { /* move right */
        for (i = 0; i < (unsigned int)movedx; l->mid = l->mid->next, i++);
    } else {    /* move left */
        movedx = -movedx;
        for (i = 0; i < (unsigned int)movedx; l->mid = l->mid->prev, i++);
    }

    assert(posstart == 0 || lastvalid != l->head_sentinel);
    i = posstart;
    if (l->attrs.copy_data) {
        /* also free element data */
        for (; i <= posend; i++) {
            tmp2 = tmp;
            tmp = tmp->next;
            if (tmp2->data != NULL) free(tmp2->data);
            if (l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS) {
                l->spareels[l->spareelsnum++] = tmp2;
            } else {
                free(tmp2);
            }
        }
    } else {
        /* only free containers */
        for (; i <= posend; i++) {
            tmp2 = tmp;
            tmp = tmp->next;
            if (l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS) {
                l->spareels[l->spareelsnum++] = tmp2;
            } else {
                free(tmp2);
            }
        }
    }
    assert(i == posend+1 && (posend != l->numels || tmp == l->tail_sentinel));

    lastvalid->next = tmp;
    tmp->prev = lastvalid;

    l->numels -= posend - posstart + 1;

    assert(list_repOk(l));

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r12d
pushq $-0x1
popq %rax
subl %esi, %r12d
jb 0x433f
movq %rdi, %rbx
cmpl $0x0, 0x2c(%rdi)
jne 0x433f
movl %edx, %ebp
movl 0x18(%rbx), %r15d
cmpl %edx, %r15d
jbe 0x433f
movl %esi, %r14d
movq %rbx, %rdi
callq 0x3fd8
movq %r15, %rcx
movq %rax, %r15
incl %r12d
movq %rcx, 0x10(%rsp)
decl %ecx
movl %ecx, %eax
subl %r12d, %eax
shrl %eax
xorl %edx, %edx
cmpl %r14d, %eax
cmovael %r12d, %edx
shrl %ecx
subl %ecx, %eax
addl %edx, %eax
testl %eax, %eax
jle 0x42a3
leaq 0x10(%rbx), %rcx
movq %rcx, %rdx
movq (%rdx), %rdx
subl $0x1, %eax
jb 0x42a9
addq $0x8, %rdx
jmp 0x4287
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rbx)
incl %eax
testl %eax, %eax
jne 0x4295
jmp 0x42ac
movq %rdx, (%rcx)
movq 0x10(%r15), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x58(%rbx)
je 0x4320
cmpl %ebp, %r14d
ja 0x4325
movq (%r15), %rdi
movq 0x8(%r15), %r13
callq 0x3030
movl 0x28(%rbx), %eax
cmpq $0x4, %rax
ja 0x42e5
movq 0x20(%rbx), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x28(%rbx)
movq %r15, (%rcx,%rax,8)
jmp 0x42ed
movq %r15, %rdi
callq 0x3030
incl %r14d
movq %r13, %r15
jmp 0x42bb
movq 0x8(%r15), %r13
movl 0x28(%rbx), %eax
cmpq $0x4, %rax
ja 0x4312
movq 0x20(%rbx), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x28(%rbx)
movq %r15, (%rcx,%rax,8)
jmp 0x431a
movq %r15, %rdi
callq 0x3030
incl %r14d
movq %r13, %r15
cmpl %ebp, %r14d
jbe 0x42f5
movq 0x8(%rsp), %rax
movq %r15, 0x8(%rax)
movq %rax, 0x10(%r15)
movq 0x10(%rsp), %rax
subl %r12d, %eax
movl %eax, 0x18(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq