// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movl %edx, %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %esi, %r12d
jb 0x4611
movq %rdi, %rbx
cmpl $0x0, 0x2c(%rdi)
jne 0x4611
movl %edx, %ebp
movl 0x18(%rbx), %ecx
cmpl %edx, %ecx
jbe 0x4611
movl %esi, %r14d
leal 0x1(%r14), %eax
cvtsi2ss %eax, %xmm0
movl %ecx, %edx
cvtsi2ss %rdx, %xmm1
divss %xmm1, %xmm0
movss 0x28d6(%rip), %xmm1     # 0x6ddc
ucomiss %xmm0, %xmm1
jae 0x4533
movss 0x28cd(%rip), %xmm1     # 0x6de0
ucomiss %xmm0, %xmm1
jbe 0x4620
leal -0x1(%rcx), %eax
shrl %eax
incl %eax
movq %rbx, %r15
movq 0x10(%r15), %r15
decl %eax
cmpl %r14d, %eax
jg 0x4526
jmp 0x4543
movq (%rbx), %r15
testl %r14d, %r14d
js 0x4543
movq 0x8(%r15), %r15
decl %eax
jne 0x453b
incl %r12d
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 0x4570
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rcx
decl %eax
jne 0x4566
jmp 0x457e
je 0x4582
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %rcx
incl %eax
jne 0x4576
movq %rcx, 0x10(%rbx)
movq 0x10(%r15), %rax
movq %rax, (%rsp)
cmpl $0x0, 0x58(%rbx)
je 0x45cf
movq (%r15), %rdi
movq 0x8(%r15), %r13
testq %rdi, %rdi
je 0x45a1
callq 0x3030
movl 0x28(%rbx), %eax
cmpq $0x4, %rax
ja 0x45ba
movq 0x20(%rbx), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x28(%rbx)
movq %r15, (%rcx,%rax,8)
jmp 0x45c2
movq %r15, %rdi
callq 0x3030
incl %r14d
movq %r13, %r15
cmpl %ebp, %r14d
jbe 0x4590
jmp 0x45ff
movq 0x8(%r15), %r13
movl 0x28(%rbx), %eax
cmpq $0x4, %rax
ja 0x45ec
movq 0x20(%rbx), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x28(%rbx)
movq %r15, (%rcx,%rax,8)
jmp 0x45f4
movq %r15, %rdi
callq 0x3030
incl %r14d
movq %r13, %r15
cmpl %ebp, %r14d
jbe 0x45cf
movq (%rsp), %rax
movq %r13, 0x8(%rax)
movq %rax, 0x10(%r13)
subl %r12d, 0x18(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movss 0x27bc(%rip), %xmm1     # 0x6de4
ucomiss %xmm0, %xmm1
jae 0x464c
movq 0x8(%rbx), %r15
cmpl %r14d, %ecx
jle 0x4543
movl %ecx, %eax
decl %eax
movq 0x10(%r15), %r15
cmpl %r14d, %eax
jg 0x463c
jmp 0x4543
leal -0x1(%rcx), %edx
shrl %edx
movq 0x10(%rbx), %r15
movl %r14d, %eax
subl %edx, %eax
jle 0x4543
movq 0x8(%r15), %r15
decl %eax
jne 0x4660
jmp 0x4543