// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rdi, %rbx
movsd 0x320a(%rip), %xmm1     # 0x6020
xorl %r13d, %r13d
pushq $-0x1
popq %r12
leaq 0x63a4(%rip), %r14      # 0x91c8
movl %r12d, %r15d
movl %r12d, 0x3c(%rsp)
movl %r13d, %esi
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x2, %rax
cmpq %rsi, %rax
movapd %xmm1, 0x40(%rsp)
jbe 0x302c
movq %r14, %rdi
callq 0x31b2
movslq (%rax), %rsi
leaq 0x6385(%rip), %rdi      # 0x91e0
callq 0x30bc
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movq 0x30(%rax), %rcx
movq %rcx, 0x80(%rsp)
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movupd (%rax), %xmm0
movups 0x10(%rax), %xmm1
movupd 0x20(%rax), %xmm2
movupd %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2636
testb %al, %al
je 0x2fba
movdqu (%rbx), %xmm0
movupd 0x58(%rsp), %xmm1
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
pcmpeqd 0x313d(%rip), %xmm0     # 0x6010
leaq 0x6336(%rip), %rax      # 0x9210
movq (%rax), %xmm2
punpcklqdq %xmm2, %xmm2    # xmm2 = xmm2[0,0]
leaq 0x632f(%rip), %rax      # 0x9218
movq (%rax), %xmm3
punpcklqdq %xmm3, %xmm3    # xmm3 = xmm3[0,0]
pand %xmm0, %xmm2
pandn %xmm3, %xmm0
por %xmm2, %xmm0
movupd 0x40(%rbx), %xmm2
addpd %xmm1, %xmm2
cmplepd %xmm0, %xmm2
movmskpd %xmm2, %eax
cmpl $0x3, %eax
jne 0x2fc2
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 0x26fe
testb %al, %al
jne 0x307c
leaq 0x50(%rsp), %rdi
callq 0x31d4
movl %eax, %ebp
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 %ebp, %esi
callq 0x281a
ucomisd 0x308a(%rip), %xmm0     # 0x6028
jne 0x2fa2
jnp 0x2fba
movapd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3024
xorl %r15d, %r15d
movl %ebp, 0x3c(%rsp)
movl %r13d, %r12d
jmp 0x3020
movapd 0x40(%rsp), %xmm1
jmp 0x3024
movslq 0x50(%rsp), %rsi
leaq 0x61b2(%rip), %rdi      # 0x9180
callq 0x30f8
movq %rax, %rdi
xorl %esi, %esi
callq 0x3116
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm3
cmpltpd %xmm3, %xmm1
movapd %xmm0, %xmm2
movsd 0x3028(%rip), %xmm4     # 0x6028
cmpneqpd %xmm4, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
pushq $0x1
popq %rax
cmovnel %eax, %r15d
cmovnel %r13d, %r12d
jne 0x3020
movapd %xmm3, %xmm0
movapd %xmm0, %xmm1
incl %r13d
jmp 0x2e2c
ucomisd 0x2ff4(%rip), %xmm1     # 0x6028
jne 0x3038
jnp 0x3059
movq %rbx, %rdi
movl %r12d, %esi
testl %r15d, %r15d
je 0x304a
callq 0x2c44
jmp 0x3053
movl 0x3c(%rsp), %edx
callq 0x2a44
movapd 0x40(%rsp), %xmm1
cmpneqsd 0x2fc6(%rip), %xmm1     # 0x6028
movq %xmm1, %rax
andl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5f4d(%rip), %rdi      # 0x8fd0
leaq 0x2fa6(%rip), %rsi      # 0x6030
callq 0x2130
xorl %edi, %edi
callq 0x2170