// File: 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
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0xa3d3
jmp 0xa2f7
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0xa48d
jmp 0xa305
movl -0x54(%rbp), %eax
subl $0x2, %eax
jne 0xa54c
jmp 0xa313
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x3, %rsi
callq 0x9b80
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
cmpl -0xc(%rbp), %eax
jl 0xa34c
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
cmpq $0x0, -0x28(%rbp)
je 0xa3ce
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa3c0
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa38a
movq -0x8(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0xa54c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x2, %rsi
callq 0x9b80
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
cmpl -0xc(%rbp), %eax
jl 0xa40c
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
cmpq $0x0, -0x30(%rbp)
je 0xa488
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa47a
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
cvttsd2si -0x40(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa44a
movq -0x8(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0xa54c
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x3, %rsi
callq 0x9b80
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
cmpl -0xc(%rbp), %eax
jl 0xa4d0
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
cmpq $0x0, -0x38(%rbp)
je 0xa54a
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa53c
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa50e
movq -0x8(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0xa54c
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)