// File: /workspace/github_cpp_makefile_star2_O1/skaringa[P]DistanceCalculation/GeodDistanceCalculator.cpp
// Function: GeodDistanceCalculator::distance(Point const&, Point const&) const
double GeodDistanceCalculator::distance(const Point & from, const Point & to) const
{
#ifndef _WIN32
	stringstream pin, pout;
	string s1, s2;
	double dist;
	char outbuf[256];
	int fdin[2], fdout[2];
	
	pipe(fdin);
	pipe(fdout);
	if (0 == fork()) {
		/* child */
		dup2(fdin[0], 0);
		close(fdin[1]);
		dup2(fdout[1], 1);
		close(fdout[0]);
		execlp("/usr/bin/geod", "geod", "+ellps=WGS84", "+units=km", "-I", (char *)NULL);
        cerr << "execlp geod failed" << endl;
        exit(1);
	}
	/* parent */
    close(fdin[0]);
    close(fdout[1]);
    
    pin << from.lat() << " " << from.lon() << " " << to.lat() << " " << to.lon() << endl;
    write(fdin[1], pin.str().c_str(), pin.str().length());
    close(fdin[1]);
    
    read(fdout[0], outbuf, 255);
    close(fdout[0]);

    pout << outbuf;
    pout >> s1 >> s2 >> dist;
    
    return dist;
#else
	return -1;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rdx, %r14
movq %rsi, %r15
leaq 0x228(%rsp), %rbx
movq %rbx, %rdi
callq 0x20f0
leaq 0xa0(%rsp), %rdi
callq 0x20f0
leaq 0x30(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x90(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x21d0
movq %rsp, %rdi
callq 0x21d0
callq 0x2070
movl (%r12), %edi
testl %eax, %eax
je 0x2695
callq 0x2260
movl 0x4(%rsp), %edi
callq 0x2260
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x238(%rsp), %rdi
callq 0x2210
movq %rax, %r12
leaq 0x1d1e(%rip), %rsi      # 0x4197
movl $0x1, %edx
movq %rax, %rdi
callq 0x21a0
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq %r12, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x1cf6(%rip), %rsi      # 0x4197
movl $0x1, %edx
movq %rax, %rdi
callq 0x21a0
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %r15, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x1cce(%rip), %rsi      # 0x4197
movl $0x1, %edx
movq %rax, %rdi
callq 0x21a0
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq %r15, %rdi
callq 0x2210
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movl 0xc(%rsp), %ebp
leaq 0x240(%rsp), %r14
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x2200
movq 0x60(%rsp), %r15
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x2200
movq 0x48(%rsp), %rdx
movl %ebp, %edi
movq %r15, %rsi
callq 0x20a0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2566
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2581
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2190
movl 0xc(%rsp), %edi
callq 0x2260
movl (%rsp), %edi
leaq 0x3b0(%rsp), %rsi
movl $0xff, %edx
callq 0x21e0
movl (%rsp), %edi
callq 0x2260
leaq 0xb0(%rsp), %r14
leaq 0x3b0(%rsp), %r15
movq %r15, %rdi
callq 0x20b0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x21a0
leaq 0xa0(%rsp), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x21c0
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x2628
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2644
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x396d(%rip), %r15      # 0x5fb8
movq %r14, %rdi
movq %r15, %rsi
callq 0x2110
movl $0x80, %r12d
addq %r12, %r14
movq %r14, %rdi
callq 0x2090
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2110
addq %r12, %rbx
movq %rbx, %rdi
callq 0x2090
movsd 0x10(%rsp), %xmm0
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
callq 0x2150
movl 0xc(%rsp), %edi
callq 0x2260
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x2150
movl (%rsp), %edi
callq 0x2260
leaq 0x1942(%rip), %rdi      # 0x4004
leaq 0x1944(%rip), %rsi      # 0x400d
leaq 0x1942(%rip), %rdx      # 0x4012
leaq 0x1948(%rip), %rcx      # 0x401f
leaq 0x194b(%rip), %r8       # 0x4029
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x2080
movq 0x3901(%rip), %rdi      # 0x5ff0
leaq 0x1936(%rip), %rsi      # 0x402c
movl $0x12, %edx
callq 0x21a0
movq 0x38e9(%rip), %rdi      # 0x5ff0
callq 0x20c0
movl $0x1, %edi
callq 0x21b0
movq %rax, %rbx
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2739
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2190
jmp 0x2739
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2760
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2190
jmp 0x2760
jmp 0x275d
movq %rax, %rbx
jmp 0x27ba
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x277d
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2799
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x3818(%rip), %rsi      # 0x5fb8
leaq 0xa0(%rsp), %rdi
callq 0x2110
leaq 0x120(%rsp), %rdi
callq 0x2090
movq 0x37f7(%rip), %rsi      # 0x5fb8
leaq 0x228(%rsp), %rdi
callq 0x2110
leaq 0x2a8(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2230
nop