// File: /workspace/github_cpp_makefile_star2_O3/DivyanshuSaxena[P]green-vrp/Vehicle.cpp
// Function: Vehicle::addCustomerCS(int, int)
void Vehicle::addCustomerCS(int customerId, int chargingStation) {
    Node cs;
    cs.id = chargingStation;
    time_type timeToCS = travelTimes.at(this->currentNodeId).at(chargingStation);
    double travelCostCS = travelCosts.at(this->currentNodeId).at(chargingStation);
    cs.arrival_time = this->route.at(this->route.size()-2).departure_time + timeToCS;
    cs.departure_time = cs.arrival_time + chargingTimeCS;
    this->currentNodeId = chargingStation;
    auto it = this->route.end();
    this->route.insert(--it, cs);
    
    Node node;
    node.id = customerId;
    Customer customer = customers.at(customerId);
    time_type timeTaken = travelTimes.at(this->currentNodeId).at(customer.id);
    double travelCost = travelCosts.at(this->currentNodeId).at(customer.id);
    node.arrival_time = this->route.at(this->route.size()-2).departure_time + timeTaken;
    node.departure_time = node.arrival_time + serviceTime;
    this->currentNodeId = customer.id;
    it = this->route.end();
    this->route.insert(--it, node);

    // Update costs
    this->travellingCost += (travelCost + travelCostCS);
    double waitCost = (customer.timeWindowStarts > node.arrival_time) ? (customer.timeWindowStarts - node.arrival_time)*waiting_factor : 0; 
    this->waitingCost += waitCost;
    this->chargingCost += chargingCostStation;
    updateTotalCost();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x30(%rsp)
movslq 0x70(%rdi), %rax
leaq 0x6537(%rip), %r12      # 0x91c8
movq (%r12), %r9
movq 0x8(%r12), %rcx
subq %r9, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r15, %rcx
cmpq %rax, %rcx
jbe 0x2f58
movl %esi, %ebp
movq %rdi, %rbx
leaq (%rax,%rax,2), %r8
movslq %edx, %rsi
movq (%r9,%r8,8), %rdi
movq 0x8(%r9,%r8,8), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
cmpq %rsi, %rcx
jbe 0x2f70
leaq 0x64b4(%rip), %r13      # 0x9198
movq (%r13), %r10
movq 0x8(%r13), %rcx
subq %r10, %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
cmpq %rax, %rcx
jbe 0x2f58
movq (%r10,%r8,8), %r9
movq 0x8(%r10,%r8,8), %rax
subq %r9, %rax
sarq $0x3, %rax
cmpq %rsi, %rax
jbe 0x2f79
movq 0x8(%rbx), %r10
movq 0x10(%rbx), %rax
movq %rax, %rcx
subq %r10, %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
leaq -0x2(%rcx), %r8
cmpq $0x1, %rcx
jbe 0x2f85
movsd (%rdi,%rsi,8), %xmm0
movsd (%r9,%rsi,8), %xmm1
movaps %xmm1, (%rsp)
leaq (%r8,%r8,2), %rcx
addsd 0x10(%r10,%rcx,8), %xmm0
leaq 0x30(%rsp), %rcx
movsd %xmm0, 0x8(%rcx)
leaq 0x6530(%rip), %rsi      # 0x9298
addsd (%rsi), %xmm0
leaq 0x8(%rbx), %r14
movsd %xmm0, 0x10(%rcx)
movl %edx, 0x70(%rbx)
addq $-0x18, %rax
movq %r14, %rdi
movq %rax, %rsi
movq %rcx, %rdx
callq 0x3556
movl %ebp, 0x18(%rsp)
movslq %ebp, %rsi
leaq 0x6460(%rip), %rax      # 0x91f8
movq (%rax), %rdi
movq 0x8(%rax), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x2f4f
movslq 0x70(%rbx), %rax
movq (%r12), %r10
movq 0x8(%r12), %rdx
subq %r10, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
cmpq %rax, %rdx
jbe 0x2f64
imulq $0x38, %rsi, %r8
movl (%rdi,%r8), %ecx
movslq %ecx, %rsi
leaq (%rax,%rax,2), %rcx
movq (%r10,%rcx,8), %r9
movq 0x8(%r10,%rcx,8), %rdx
subq %r9, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x2f4f
movq (%r13), %r11
movq 0x8(%r13), %rdx
subq %r11, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
cmpq %rax, %rdx
jbe 0x2f64
movq (%r11,%rcx,8), %r10
movq 0x8(%r11,%rcx,8), %rdx
subq %r10, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x2f4f
movq 0x8(%rbx), %r11
movq 0x10(%rbx), %rax
movq %rax, %rdx
subq %r11, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
leaq -0x2(%rdx), %rcx
cmpq $0x1, %rdx
jbe 0x2f99
movsd (%r9,%rsi,8), %xmm0
leaq (%rcx,%rcx,2), %rcx
addsd 0x10(%r11,%rcx,8), %xmm0
movsd 0x28(%rdi,%r8), %xmm1
movsd %xmm1, 0x10(%rsp)
movapd (%rsp), %xmm1
addsd (%r10,%rsi,8), %xmm1
movapd %xmm1, (%rsp)
leaq 0x18(%rsp), %r15
movsd %xmm0, 0x8(%r15)
leaq 0x62c1(%rip), %rcx      # 0x9160
addsd (%rcx), %xmm0
movsd %xmm0, 0x10(%r15)
movl %esi, 0x70(%rbx)
addq $-0x18, %rax
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x3556
movsd 0x8(%r15), %xmm0
movsd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
leaq 0x63cf(%rip), %rax      # 0x92a8
cvtsi2sdl (%rax), %xmm2
mulsd %xmm1, %xmm2
cmpltsd %xmm3, %xmm0
andpd %xmm2, %xmm0
addsd 0x38(%rbx), %xmm0
movsd %xmm0, 0x38(%rbx)
leaq 0x63b5(%rip), %rax      # 0x92b0
movupd 0x28(%rbx), %xmm2
movsd (%rax), %xmm1
unpcklpd (%rsp), %xmm1           # xmm1 = xmm1[0],mem[0]
addpd %xmm2, %xmm1
movupd %xmm1, 0x28(%rbx)
cmpl $0x1, (%rbx)
jne 0x2f20
leaq 0x633a(%rip), %rax      # 0x9258
jmp 0x2f27
leaq 0x6339(%rip), %rax      # 0x9260
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm0, %xmm2
addsd %xmm1, %xmm2
addsd (%rax), %xmm2
movsd %xmm2, 0x20(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30ee(%rip), %rdi      # 0x6044
jmp 0x2f92
leaq 0x30e5(%rip), %rdi      # 0x6044
movq %rax, %rsi
jmp 0x2f8f
leaq 0x30d9(%rip), %rdi      # 0x6044
movq %rax, %rsi
jmp 0x2f92
leaq 0x30cd(%rip), %rdi      # 0x6044
jmp 0x2f8f
leaq 0x30c4(%rip), %rdi      # 0x6044
movq %rax, %rdx
jmp 0x2f92
leaq 0x30b8(%rip), %rdi      # 0x6044
movq %r8, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x21e0
leaq 0x30a4(%rip), %rdi      # 0x6044
movq %rcx, %rsi
jmp 0x2f92
nop