// File: ADAPTLab[P]MuDBSCAN/vectorc.cpp
// Function: vector_resize_internal(vectorc*, int)
void vector_resize_internal(vectorc* v, int capacity)
{

    // #ifdef DEBUG_ON
    //     printf("vector_resize: %d to %d\n", v->capacity, capacity);
    // #endif
    int i;
    double* doubleItems = NULL;
    int* intItems = NULL;
    Group* groupItems = NULL;
    BCell* bcellItems = NULL;

    switch (v->type)
    {
        case DOUBLE:
            doubleItems = (double*) realloc(v->doubleItems, sizeof(double)*capacity);
            // assert(doubleItems != NULL);
            if(doubleItems)
            {
                v->intItems = NULL;
                v->groupItems = NULL;
                v->bcellItems = NULL;
                v->doubleItems = doubleItems;
                v->capacity = capacity;
            }
            break;

        case INTEGER:
            intItems = (int*) realloc(v->intItems, sizeof(int) * capacity);
            // assert(intItems != NULL);
            // fprintf(stderr, "Old: %p\t New: %p\n", v->intItems, intItems);
            if (intItems) 
            {
                v->doubleItems = NULL;
                v->groupItems = NULL;
                v->bcellItems = NULL;
                v->intItems = intItems;
                v->capacity = capacity;

            }
            break;

        case GROUP:
            groupItems = (Group*) realloc(v->groupItems, sizeof(Group) * capacity);
            // assert(groupItems != NULL);
            if (groupItems) 
            {
                v->doubleItems = NULL;
                v->intItems = NULL;
                v->bcellItems = NULL;
                v->groupItems = groupItems;
                v->capacity = capacity;
            }
            break;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x34(%rbp)
testl %eax, %eax
je 0xa619
jmp 0xa59f
movl -0x34(%rbp), %eax
subl $0x1, %eax
je 0xa674
jmp 0xa5ad
movl -0x34(%rbp), %eax
subl $0x2, %eax
jne 0xa6ce
jmp 0xa5bb
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x3, %rsi
callq 0x9b80
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xa614
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xa6ce
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x2, %rsi
callq 0x9b80
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xa672
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xa6ce
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x3, %rsi
callq 0x9b80
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa6cc
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xa6ce
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)