// File: 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
movq %rsp, %rbp
subq $0x560, %rsp            # imm = 0x560
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3130
leaq -0x328(%rbp), %rdi
callq 0x3130
jmp 0x35a1
leaq -0x358(%rbp), %rdi
callq 0x32d0
leaq -0x378(%rbp), %rdi
callq 0x32d0
leaq -0x488(%rbp), %rdi
callq 0x32c0
leaq -0x490(%rbp), %rdi
callq 0x32c0
callq 0x3070
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x36af
movl -0x488(%rbp), %edi
xorl %esi, %esi
callq 0x31d0
movl -0x484(%rbp), %edi
callq 0x33a0
jmp 0x35fc
movl -0x48c(%rbp), %edi
movl $0x1, %esi
callq 0x31d0
movl -0x490(%rbp), %edi
callq 0x33a0
jmp 0x3619
leaq 0x29e4(%rip), %rdi      # 0x6004
leaq 0x29e6(%rip), %rsi      # 0x600d
leaq 0x29e4(%rip), %rdx      # 0x6012
leaq 0x29ea(%rip), %rcx      # 0x601f
leaq 0x29ed(%rip), %r8       # 0x6029
xorl %eax, %eax
movl %eax, %r9d
callq 0x3090
movq 0x59a3(%rip), %rdi      # 0x8ff0
leaq 0x29d8(%rip), %rsi      # 0x602c
callq 0x3200
movq %rax, -0x4d8(%rbp)
jmp 0x3662
movq -0x4d8(%rbp), %rdi
movq 0x5950(%rip), %rsi      # 0x8fc0
callq 0x3230
jmp 0x3677
movl $0x1, %edi
callq 0x3290
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x330(%rbp)
movl %eax, -0x334(%rbp)
jmp 0x39dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x330(%rbp)
movl %eax, -0x334(%rbp)
jmp 0x39b8
movl -0x488(%rbp), %edi
callq 0x33a0
jmp 0x36bc
movl -0x48c(%rbp), %edi
callq 0x33a0
jmp 0x36c9
leaq -0x190(%rbp), %rax
movq %rax, -0x4e8(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movsd %xmm0, -0x4e0(%rbp)
jmp 0x36ee
movsd -0x4e0(%rbp), %xmm0
movq -0x4e8(%rbp), %rdi
callq 0x3390
movq %rax, -0x4f0(%rbp)
jmp 0x370b
movq -0x4f0(%rbp), %rdi
leaq 0x2ac4(%rip), %rsi      # 0x61dd
callq 0x3200
movq %rax, -0x4f8(%rbp)
jmp 0x3727
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movsd %xmm0, -0x500(%rbp)
jmp 0x373e
movsd -0x500(%rbp), %xmm0
movq -0x4f8(%rbp), %rdi
callq 0x3390
movq %rax, -0x508(%rbp)
jmp 0x375b
movq -0x508(%rbp), %rdi
leaq 0x2a74(%rip), %rsi      # 0x61dd
callq 0x3200
movq %rax, -0x510(%rbp)
jmp 0x3777
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movsd %xmm0, -0x518(%rbp)
jmp 0x378e
movsd -0x518(%rbp), %xmm0
movq -0x510(%rbp), %rdi
callq 0x3390
movq %rax, -0x520(%rbp)
jmp 0x37ab
movq -0x520(%rbp), %rdi
leaq 0x2a24(%rip), %rsi      # 0x61dd
callq 0x3200
movq %rax, -0x528(%rbp)
jmp 0x37c7
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movsd %xmm0, -0x530(%rbp)
jmp 0x37de
movsd -0x530(%rbp), %xmm0
movq -0x528(%rbp), %rdi
callq 0x3390
movq %rax, -0x538(%rbp)
jmp 0x37fb
movq -0x538(%rbp), %rdi
movq 0x57b7(%rip), %rsi      # 0x8fc0
callq 0x3230
jmp 0x3810
movl -0x484(%rbp), %eax
movl %eax, -0x53c(%rbp)
leaq -0x4b0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x31f0
jmp 0x3831
leaq -0x4b0(%rbp), %rdi
callq 0x30e0
movq %rax, -0x548(%rbp)
leaq -0x4d0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x31f0
jmp 0x3859
leaq -0x4d0(%rbp), %rdi
callq 0x3300
movl -0x53c(%rbp), %edi
movq -0x548(%rbp), %rsi
movq %rax, %rdx
callq 0x30b0
jmp 0x387c
leaq -0x4d0(%rbp), %rdi
callq 0x3110
leaq -0x4b0(%rbp), %rdi
callq 0x3110
movl -0x484(%rbp), %edi
callq 0x33a0
jmp 0x38a1
movl -0x490(%rbp), %edi
leaq -0x480(%rbp), %rsi
movl $0xff, %edx
callq 0x32e0
jmp 0x38ba
movl -0x490(%rbp), %edi
callq 0x33a0
jmp 0x38c7
leaq -0x318(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0x3200
jmp 0x38dc
leaq -0x328(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x32b0
movq %rax, -0x550(%rbp)
jmp 0x38f8
movq -0x550(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0x32b0
movq %rax, -0x558(%rbp)
jmp 0x3914
movq -0x558(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x3190
jmp 0x3929
movsd -0x380(%rbp), %xmm0
movsd %xmm0, -0x560(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x3110
leaq -0x358(%rbp), %rdi
callq 0x3110
leaq -0x328(%rbp), %rdi
callq 0x3150
leaq -0x1a0(%rbp), %rdi
callq 0x3150
movsd -0x560(%rbp), %xmm0
addq $0x560, %rsp            # imm = 0x560
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x330(%rbp)
movl %eax, -0x334(%rbp)
jmp 0x39ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x330(%rbp)
movl %eax, -0x334(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x3110
leaq -0x4b0(%rbp), %rdi
callq 0x3110
leaq -0x378(%rbp), %rdi
callq 0x3110
leaq -0x358(%rbp), %rdi
callq 0x3110
leaq -0x328(%rbp), %rdi
callq 0x3150
leaq -0x1a0(%rbp), %rdi
callq 0x3150
movq -0x330(%rbp), %rdi
callq 0x3350
nopw %cs:(%rax,%rax)
nop