// File: ttalvitie[P]traveling-santa/optimize.cpp
// Function: Path::finalize()
void finalize() {
        if(len(points) < 2 || points.front().child != -1 || points.back().child != -1) throw 0;
        Z wt = 0;
        for(int i = 0; i < len(points); ++i) {
            if(i != 0 && i != len(points) - 1 && points[i].child == -1) throw 0;
            wt += points[i].wt;
            points[i].leftWt = wt;
        }
        wt = 0;
        for(int i = len(points) - 1; i >= 0; --i) {
            wt += points[i].wt;
            points[i].rightWt = wt;
        }
        if(wt > FinalWtLimit) throw 0;
        cost = 0.0;
        for(int i = 1; i < len(points); ++i) {
            cost += sphereDist(points[i - 1].pos, points[i].pos);
        }
    }

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0xa0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8f80
cmpl $0x2, %eax
jl 0x9294
movq 0x50(%rsp), %rdi
callq 0x9f40
cmpl $-0x1, (%rax)
jne 0x9294
movq 0x50(%rsp), %rdi
callq 0x8f90
cmpl $-0x1, (%rax)
je 0x92b7
movl $0x4, %edi
callq 0x30d0
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x9d12(%rip), %rsi      # 0x12fc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33f0
movq $0x0, 0x98(%rsp)
movl $0x0, 0x94(%rsp)
movq 0x50(%rsp), %rdi
movl 0x94(%rsp), %eax
movl %eax, 0x4c(%rsp)
callq 0x8f80
movl %eax, %ecx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jge 0x93bb
cmpl $0x0, 0x94(%rsp)
je 0x9357
movq 0x50(%rsp), %rdi
movl 0x94(%rsp), %eax
movl %eax, 0x48(%rsp)
callq 0x8f80
movl %eax, %ecx
movl 0x48(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x9357
movq 0x50(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0x8fd0
cmpl $-0x1, (%rax)
jne 0x9357
movl $0x4, %edi
callq 0x30d0
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x9c72(%rip), %rsi      # 0x12fc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33f0
movq 0x50(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0x8fd0
movq 0x50(%rsp), %rdi
movq 0x20(%rax), %rax
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x40(%rsp)
movslq 0x94(%rsp), %rsi
callq 0x8fd0
movq 0x40(%rsp), %rcx
movq %rcx, 0x28(%rax)
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x92ce
movq 0x50(%rsp), %rdi
movq $0x0, 0x98(%rsp)
callq 0x8f80
subl $0x1, %eax
movl %eax, 0x90(%rsp)
cmpl $0x0, 0x90(%rsp)
jl 0x9446
movq 0x50(%rsp), %rdi
movslq 0x90(%rsp), %rsi
callq 0x8fd0
movq 0x50(%rsp), %rdi
movq 0x20(%rax), %rax
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x38(%rsp)
movslq 0x90(%rsp), %rsi
callq 0x8fd0
movq 0x38(%rsp), %rcx
movq %rcx, 0x30(%rax)
movl 0x90(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x93db
cmpq $0x989680, 0x98(%rsp) # imm = 0x989680
jle 0x9477
movl $0x4, %edi
callq 0x30d0
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x9b52(%rip), %rsi      # 0x12fc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33f0
movq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rax)
movl $0x1, 0x8c(%rsp)
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x34(%rsp)
callq 0x8f80
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x957b
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8fd0
movq 0x50(%rsp), %rdi
movq 0x8(%rax), %rcx
movq %rcx, 0x70(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x78(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x80(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0x8fd0
movq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x68(%rsp)
leaq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x3860
movq 0x50(%rsp), %rax
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x948f
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)