// File: /workspace/github_cpp_makefile_star2_O3/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 0x5f9d(%rip), %r13      # 0x91e0
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x34f7
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
movsd 0x2dbf(%rip), %xmm1     # 0x6020
xorl %ecx, %ecx
leaq 0x5f8e(%rip), %r14      # 0x91f8
movl $0x1, %r15d
movl $0xffffffff, 0x48(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movapd %xmm1, 0x90(%rsp)
movslq (%rax,%rcx,4), %rsi
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x352e
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 0x2760
testb %al, %al
je 0x342f
leal -0x1(%r15), %ebp
movdqu (%rbx), %xmm0
movupd 0x58(%rsp), %xmm1
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
pcmpeqd 0x2cdb(%rip), %xmm0     # 0x6010
leaq 0x5eec(%rip), %rax      # 0x9228
movq (%rax), %xmm2
punpcklqdq %xmm2, %xmm2    # xmm2 = xmm2[0,0]
leaq 0x5ee5(%rip), %rax      # 0x9230
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 0x343d
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 0x2854
testb %al, %al
jne 0x353c
leaq 0x50(%rsp), %rdi
callq 0x3602
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 0x2968
ucomisd 0x2c26(%rip), %xmm0     # 0x6028
jne 0x3406
jnp 0x342f
movapd 0x90(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x34c0
movl $0x0, 0x48(%rsp)
movl %r12d, 0x4c(%rsp)
movl %ebp, 0x44(%rsp)
jmp 0x34bc
movapd 0x90(%rsp), %xmm1
jmp 0x34c0
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 0x2a14
movapd %xmm0, %xmm1
movapd 0x90(%rsp), %xmm4
cmpltpd %xmm4, %xmm1
movapd %xmm0, %xmm2
movsd 0x2b9c(%rip), %xmm3     # 0x6028
cmpneqpd %xmm3, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
movl $0x1, %eax
movl 0x48(%rsp), %ecx
cmovnel %eax, %ecx
movl %ecx, 0x48(%rsp)
movl 0x44(%rsp), %eax
cmovnel %ebp, %eax
movl %eax, 0x44(%rsp)
jne 0x34bc
movapd %xmm4, %xmm0
movapd %xmm0, %xmm1
movl %r15d, %ecx
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r15d
cmpq %rcx, %rdx
ja 0x3280
ucomisd 0x2b42(%rip), %xmm1     # 0x6028
jne 0x34ea
jnp 0x3508
cmpl $0x0, 0x48(%rsp)
je 0x351c
movl 0x44(%rsp), %esi
jmp 0x34fc
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x2fa6
movb $0x1, %al
jmp 0x350a
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl 0x44(%rsp), %esi
movl 0x4c(%rsp), %edx
callq 0x2c74
jmp 0x3504
leaq 0x2b0f(%rip), %rdi      # 0x6044
xorl %eax, %eax
callq 0x21e0
movq 0x5a8d(%rip), %rdi      # 0x8fd0
leaq 0x2ae6(%rip), %rsi      # 0x6030
callq 0x2140
xorl %edi, %edi
callq 0x2190