// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdx, %rbx
movq %rsi, %r14
leaq 0x228(%rsp), %rdi
callq 0x20e0
leaq 0xa0(%rsp), %rdi
callq 0x20e0
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x21d0
movq %rsp, %rdi
callq 0x21d0
callq 0x2060
movl (%r15), %edi
testl %eax, %eax
je 0x25df
callq 0x2260
movl 0x4(%rsp), %edi
callq 0x2260
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
leaq 0x238(%rsp), %rdi
callq 0x2220
leaq 0x1d9a(%rip), %rsi      # 0x4207
movq %rax, %rdi
callq 0x2180
movq %rax, %r15
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq %r15, %rdi
callq 0x2220
leaq 0x1d77(%rip), %rsi      # 0x4207
movq %rax, %rdi
callq 0x2180
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
callq 0x2220
leaq 0x1d54(%rip), %rsi      # 0x4207
movq %rax, %rdi
callq 0x2180
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movq %r14, %rdi
callq 0x2220
movq %rax, %rdi
callq 0x20c0
movl 0xc(%rsp), %ebx
leaq 0x240(%rsp), %r14
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x2210
movq 0x40(%rsp), %r15
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2210
movq 0x28(%rsp), %rdx
movl %ebx, %edi
movq %r15, %rsi
callq 0x2080
leaq 0x20(%rsp), %rdi
callq 0x20b0
leaq 0x40(%rsp), %rdi
callq 0x20b0
movl 0xc(%rsp), %edi
callq 0x2260
movl (%rsp), %edi
leaq 0x3b0(%rsp), %rsi
movl $0xff, %edx
callq 0x21f0
movl (%rsp), %edi
callq 0x2260
leaq 0xb0(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0x2180
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x21c0
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x20b0
leaq 0x80(%rsp), %rdi
callq 0x20b0
leaq 0xa0(%rsp), %rdi
callq 0x2100
leaq 0x228(%rsp), %rdi
callq 0x2100
movsd 0x10(%rsp), %xmm0
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbx
popq %r14
popq %r15
retq
xorl %esi, %esi
callq 0x2160
movl 0xc(%rsp), %edi
callq 0x2260
movl 0x4(%rsp), %edi
pushq $0x1
popq %rsi
callq 0x2160
movl (%rsp), %edi
callq 0x2260
leaq 0x19fa(%rip), %rdi      # 0x4004
leaq 0x19fc(%rip), %rsi      # 0x400d
leaq 0x19fa(%rip), %rdx      # 0x4012
leaq 0x1a00(%rip), %rcx      # 0x401f
leaq 0x1a03(%rip), %r8       # 0x4029
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x2070
movq 0x39b9(%rip), %rdi      # 0x5ff0
leaq 0x19ee(%rip), %rsi      # 0x402c
callq 0x2180
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x21b0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20b0
jmp 0x2665
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x20b0
jmp 0x267b
jmp 0x2678
movq %rax, %rbx
jmp 0x269f
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x20b0
leaq 0x80(%rsp), %rdi
callq 0x20b0
leaq 0xa0(%rsp), %rdi
callq 0x2100
leaq 0x228(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2230