// File: 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
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x198(%rbp)
movsd 0x7a7e(%rip), %xmm0     # 0xb010
movsd %xmm0, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq %rax, -0x1a0(%rbp)
leaq 0xdc6c(%rip), %rdi      # 0x11230
callq 0x3e20
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x389d
movl -0x28(%rbp), %eax
movl %eax, %esi
leaq 0xdc48(%rip), %rdi      # 0x11230
callq 0x3e40
movslq (%rax), %rsi
leaq 0xdc51(%rip), %rdi      # 0x11248
callq 0x3a20
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
movl $0x38, %edx
callq 0x2150
leaq -0x98(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x38, %edx
callq 0x2150
movq -0x198(%rbp), %rdi
movq -0x68(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups -0x98(%rbp), %xmm0
movups -0x88(%rbp), %xmm1
movups -0x78(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2850
testb $0x1, %al
jne 0x365f
jmp 0x388d
leaq -0xd0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x38, %edx
callq 0x2150
movq -0x198(%rbp), %rdi
movq -0xa0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups -0xd0(%rbp), %xmm0
movups -0xc0(%rbp), %xmm1
movups -0xb0(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2a40
testb $0x1, %al
jne 0x36b7
jmp 0x37eb
leaq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x38, %edx
callq 0x2150
movq -0x198(%rbp), %rdi
movq -0xd8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups -0x108(%rbp), %xmm0
movups -0xf8(%rbp), %xmm1
movups -0xe8(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2980
testb $0x1, %al
jne 0x37cc
leaq -0x60(%rbp), %rdi
callq 0x3e80
movl %eax, -0x10c(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x38, %edx
callq 0x2150
movq -0x198(%rbp), %rdi
movl -0x10c(%rbp), %esi
movq -0x120(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups -0x150(%rbp), %xmm0
movups -0x140(%rbp), %xmm1
movups -0x130(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2b80
movsd %xmm0, -0x118(%rbp)
movsd -0x118(%rbp), %xmm0
movsd 0x788e(%rip), %xmm1     # 0xb018
ucomisd %xmm1, %xmm0
jne 0x3794
jp 0x3794
jmp 0x37ca
movsd -0x118(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x37ca
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x10c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
jmp 0x37e6
movq 0xd7fd(%rip), %rdi      # 0x10fd0
leaq 0x7846(%rip), %rsi      # 0xb020
callq 0x2180
xorl %edi, %edi
callq 0x2200
jmp 0x388b
leaq -0x190(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x38, %edx
callq 0x2150
movq -0x198(%rbp), %rdi
movq -0x160(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups -0x190(%rbp), %xmm0
movups -0x180(%rbp), %xmm1
movups -0x170(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2c70
movsd %xmm0, -0x158(%rbp)
movsd -0x158(%rbp), %xmm0
movsd 0x77c6(%rip), %xmm1     # 0xb018
ucomisd %xmm1, %xmm0
jne 0x385c
jp 0x385c
jmp 0x3889
movsd -0x158(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3889
movsd -0x158(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x1, -0x24(%rbp)
jmp 0x388b
jmp 0x388d
jmp 0x388f
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x35b3
movsd -0x18(%rbp), %xmm0
movsd 0x776e(%rip), %xmm1     # 0xb018
ucomisd %xmm1, %xmm0
jne 0x38b8
jp 0x38b8
movb $0x0, -0x1(%rbp)
jmp 0x38e5
cmpl $0x0, -0x24(%rbp)
jne 0x38d2
movq -0x198(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x2f00
jmp 0x38e1
movq -0x198(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x3250
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)