// File: /workspace/github_cpp_makefile_star2_O1/DivyanshuSaxena[P]green-vrp/Vehicle.cpp
// Function: Vehicle::addChargingStationOrDepot()
bool Vehicle::addChargingStationOrDepot()
{
    double minCost = infinity;
    int minCustomerIndex = -1, minChargingStation = -1;
    int typeOfInsertion = -1; // 0 for charging station and 1 for depot
    for(unsigned i=0; i < customerPool.size(); i++)
    {
        Customer customer  = customers.at(customerPool.at(i));
        if(timingCondition(customer))
        {
            if (capacityCondition(customer))
            {
                if(!chargingCondition(customer))//if charging condition is not satisfied
                {
                    int chargingStation = customer.findNearestCS();
                    // Calculate Cost of insertion of customer and charging station
                    double currCost = costAddCustomerCS(customer, chargingStation);
                    if (currCost != -1 && currCost < minCost)
                    {
                        minCost = currCost;
                        minCustomerIndex = i;
                        minChargingStation = chargingStation;
                        typeOfInsertion = 0;
                    }
                }
                else{
                    cout<<"There is some Error";
                    std::exit(0);
                }
            }
            else
            {
                // Add depot and calculate cost
                double currCost = costAddCustomerDepot(customer);
                if (currCost != -1 && currCost < minCost)
                {                    
                    minCost = currCost;
                    minCustomerIndex = i;
                    typeOfInsertion = 1;
                }
            }
        }
    }
    if (minCost == -1) {
        return false;
    }
    // Add the suitable customer
    if (typeOfInsertion == 0) {
        addCustomerCS(minCustomerIndex, minChargingStation);
    } else {
        addCustomerDepot(minCustomerIndex);
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
leaq 0x5f15(%rip), %r13      # 0x91e0
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x3585
movl $0xffffffff, 0x48(%rsp) # imm = 0xFFFFFFFF
movsd 0x2d1f(%rip), %xmm1     # 0x6008
xorl %ecx, %ecx
leaq 0x5f06(%rip), %r15      # 0x91f8
movl $0x1, %ebp
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movapd %xmm1, 0x90(%rsp)
movslq (%rax,%rcx,4), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x35c1
imulq $0x38, %rsi, %rcx
movq 0x30(%rax,%rcx), %rdx
movq %rdx, 0x80(%rsp)
movups (%rax,%rcx), %xmm0
movups 0x10(%rax,%rcx), %xmm1
movups 0x20(%rax,%rcx), %xmm2
movaps %xmm2, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x30(%rax,%rcx), %rdx
movq %rdx, 0x30(%rsp)
movupd (%rax,%rcx), %xmm0
movups 0x10(%rax,%rcx), %xmm1
movupd 0x20(%rax,%rcx), %xmm2
movupd %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x278c
testb %al, %al
je 0x34b3
movl (%rbx), %eax
leaq 0x5e7e(%rip), %rcx      # 0x9228
movsd (%rcx), %xmm0
leaq 0x5e7b(%rip), %rcx      # 0x9230
movsd (%rcx), %xmm2
movapd %xmm0, %xmm1
cmpl $0x1, %eax
je 0x33c6
movapd %xmm2, %xmm1
cmpl $0x2, %eax
je 0x33cf
movapd %xmm2, %xmm0
leal -0x1(%rbp), %r14d
movsd 0x60(%rsp), %xmm2
addsd 0x48(%rbx), %xmm2
ucomisd %xmm2, %xmm1
jb 0x34c1
movsd 0x58(%rsp), %xmm1
addsd 0x40(%rbx), %xmm1
ucomisd %xmm1, %xmm0
jb 0x34c1
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movaps 0x70(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2880
testb %al, %al
jne 0x35cf
leaq 0x50(%rsp), %rdi
callq 0x3696
movl %eax, %r12d
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movapd 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
movupd %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2994
ucomisd 0x2b8b(%rip), %xmm0     # 0x6010
jne 0x3489
jnp 0x34b3
movapd 0x90(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3545
movl $0x0, 0x44(%rsp)
movl %r12d, 0x4c(%rsp)
movl %r14d, 0x48(%rsp)
jmp 0x3541
movapd 0x90(%rsp), %xmm1
jmp 0x3545
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movapd 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movaps 0x70(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x2a40
movapd %xmm0, %xmm1
movapd 0x90(%rsp), %xmm4
cmpltpd %xmm4, %xmm1
movapd %xmm0, %xmm2
movsd 0x2b00(%rip), %xmm3     # 0x6010
cmpneqpd %xmm3, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
movl $0x1, %eax
movl 0x44(%rsp), %ecx
cmovnel %eax, %ecx
movl %ecx, 0x44(%rsp)
movl 0x48(%rsp), %eax
cmovnel %r14d, %eax
movl %eax, 0x48(%rsp)
jne 0x3541
movapd %xmm4, %xmm0
movapd %xmm0, %xmm1
movl %ebp, %ecx
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x3307
cmpneqsd 0x2aa6(%rip), %xmm1     # 0x6010
movq %xmm1, %r15
andl $0x1, %r15d
cmpl $0x0, 0x44(%rsp)
sete %al
movl 0x48(%rsp), %esi
movl 0x4c(%rsp), %edx
jmp 0x3594
movb $0x1, %r15b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
testb %r15b, %r15b
je 0x35ac
movq %rbx, %rdi
testb %al, %al
je 0x35a7
callq 0x2ca8
jmp 0x35ac
callq 0x2ff4
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a64(%rip), %rdi      # 0x602c
xorl %eax, %eax
callq 0x21e0
movq 0x59fa(%rip), %rdi      # 0x8fd0
leaq 0x2a3b(%rip), %rsi      # 0x6018
callq 0x2140
xorl %edi, %edi
callq 0x2190
nop