// File: /workspace/github_cpp_makefile_star2_O3/ADAPTLab[P]MuDBSCAN/vectorc.cpp
// Function: vector_resize(vectorc*, int, void*)
void vector_resize(vectorc* v, int capacity, void* val)
{
    int i;

    double* doubleItems;
    int* intItems;
    Group* groupItems;

    double d;
    int j;
    Group g; 
    switch (v->type)
    {
        case DOUBLE:
            doubleItems = (double*)realloc(v->doubleItems, sizeof(double)*capacity);
            // assert(doubleItems != NULL);

            if(v->total >= capacity)
            {
                v->total = capacity;
                v->capacity = capacity;
            }            
            if(doubleItems)
            {
                v->intItems = NULL;
                v->groupItems = NULL;
                v->doubleItems = doubleItems;
                v->capacity = capacity;

                for(i=v->total;i<capacity;i++){
                    d = *((double*)val);
                    v->doubleItems[i] = d;
                }
                v->total = v->capacity;
            }
            break;

        case INTEGER:
            intItems = (int*)realloc(v->intItems, sizeof(int) * capacity);
            // assert(intItems != NULL);

            if(v->total >= capacity)
            {
                v->total = capacity;
                v->capacity = capacity;
            }
            if (intItems) 
            {
                v->doubleItems = NULL;
                v->groupItems = NULL;
                v->intItems = intItems;
                v->capacity = capacity;
                for(i=v->total;i<capacity;i++)
                {
                    j = *((int*)val);
                    v->intItems[i] = d;
                }
                v->total = v->capacity;
            }
            break;

        case GROUP:
            groupItems = (Group*)realloc(v->groupItems, sizeof(Group) * capacity);
            // assert(groupItems != NULL);

            g = *((Group*)val);
            if(v->total >= capacity)
            {
                v->total = capacity;
                v->capacity = capacity;
            }
            if (groupItems) 
            {
                v->doubleItems = NULL;
                v->intItems = NULL;
                v->groupItems = groupItems;
                v->capacity = capacity;
                for(i=v->total;i<capacity;i++)
                {
                    g = ((Group)val);
                    v->groupItems[i] = g;
                }
                v->total = v->capacity;
            }
            break;

        // default:
        //     fprintf(stderr, "Vector doesn't have a type\n");
        //     exit(-1);
        //     break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movl 0x28(%rdi), %eax
testl %eax, %eax
je 0x3b3c
movq %rdx, %r15
cmpl $0x1, %eax
je 0x3ae6
cmpl $0x2, %eax
jne 0x3b76
movq 0x10(%r14), %rdi
movslq %ebx, %r12
leaq (,%r12,8), %rsi
callq 0x34a0
movl 0x24(%r14), %edx
cmpl %ebx, %edx
jl 0x3aa8
movl %ebx, 0x24(%r14)
movl %ebx, 0x20(%r14)
movl %ebx, %edx
testq %rax, %rax
je 0x3b76
leaq 0x24(%r14), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq %rax, 0x10(%r14)
movl %ebx, 0x20(%r14)
cmpl %ebx, %edx
jge 0x3b74
movsd (%r15), %xmm0
movslq %edx, %rdx
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %r12
jne 0x3ad4
jmp 0x3b74
movq (%r14), %rdi
movslq %ebx, %r12
leaq (,%r12,8), %rsi
callq 0x34a0
movl 0x24(%r14), %edx
cmpl %r12d, %edx
jl 0x3b0c
movl %ebx, 0x24(%r14)
movl %ebx, 0x20(%r14)
movl %ebx, %edx
testq %rax, %rax
je 0x3b76
leaq 0x24(%r14), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq %rax, (%r14)
movl %ebx, 0x20(%r14)
cmpl %ebx, %edx
jge 0x3b74
movslq %edx, %rax
movq (%r14), %rdx
movq %r15, (%rdx,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x3b2b
jmp 0x3b74
movq 0x8(%r14), %rdi
movslq %ebx, %rsi
shlq $0x2, %rsi
callq 0x34a0
cmpl %ebx, 0x24(%r14)
jl 0x3b5a
movl %ebx, 0x24(%r14)
movl %ebx, 0x20(%r14)
testq %rax, %rax
je 0x3b76
leaq 0x24(%r14), %rcx
xorl %edx, %edx
movq %rdx, 0x10(%r14)
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movl %ebx, 0x20(%r14)
movl %ebx, (%rcx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq