#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double line_segment_dist_2d(int, int, double, int, double, double);
double point_distance_3d(double, double, double, double, double, double);
int sqrt(double);
double line_segment_dist_3d(double x1, double y1, double z1, double x2,
                            double y2, double z2, double x, double y,
                            double z) {
  double d1, d2, d3, xx, yy;
  d1 = point_distance_3d(x, y, z, x1, y1, z1);
  d2 = point_distance_3d(x, y, z, x2, y2, z2);
  d3 = point_distance_3d(x1, y1, z1, x2, y2, z2);
  xx = (d2 * d2 - d1 * d1 - d3 * d3) / (-2 * d3);
  yy = d1 * d1 - xx * xx;
  yy = yy < 0 ? 0. : sqrt(yy);
  return (line_segment_dist_2d(0., 0., d3, 0., xx, yy));
}


x86 assembly (clang, -O0):
<line_segment_dist_3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  0x10(%rbp),%xmm8
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  %xmm6,-0x38(%rbp)
movsd  %xmm7,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm4
movsd  -0x18(%rbp),%xmm5
call   1030 <point_distance_3d@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  0x10(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
call   1030 <point_distance_3d@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
call   1030 <point_distance_3d@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdbe(%rip),%xmm1
mulsd  -0x58(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    12a3 <line_segment_dist_3d+0x173>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    12b6 <line_segment_dist_3d+0x186>
movsd  -0x68(%rbp),%xmm0
call   1050 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1040 <line_segment_dist_2d@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line_segment_dist_3d>:
sub    $0x58,%rsp
movsd  %xmm7,0x8(%rsp)
movsd  %xmm6,0x30(%rsp)
movsd  %xmm5,0x10(%rsp)
movsd  %xmm4,0x20(%rsp)
movsd  %xmm3,0x18(%rsp)
movaps %xmm2,%xmm5
movsd  %xmm2,0x48(%rsp)
movaps %xmm1,%xmm4
movsd  %xmm1,0x40(%rsp)
movaps %xmm0,%xmm3
movsd  %xmm0,0x38(%rsp)
movsd  0x60(%rsp),%xmm2
movsd  %xmm2,0x28(%rsp)
movaps %xmm6,%xmm0
movaps %xmm7,%xmm1
call   1030 <point_distance_3d@plt>
movsd  %xmm0,0x50(%rsp)
movsd  0x30(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm4
movsd  0x10(%rsp),%xmm5
call   1030 <point_distance_3d@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
movsd  0x48(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm4
movsd  0x10(%rsp),%xmm5
call   1030 <point_distance_3d@plt>
movapd %xmm0,%xmm3
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm2
movsd  0x50(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm0
subsd  %xmm0,%xmm2
movapd %xmm3,%xmm0
mulsd  0xdee(%rip),%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
ja     124e <line_segment_dist_3d+0x11e>
movsd  %xmm3,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm3
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
xor    %edi,%edi
xor    %esi,%esi
movapd %xmm3,%xmm0
xor    %edx,%edx
movsd  0x8(%rsp),%xmm1
add    $0x58,%rsp
jmp    1040 <line_segment_dist_2d@plt>

LLVM IR (-O0):
define double @line_segment_dist_3d(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
store double %8, double* %18
%24 = load double, double* %16
%25 = load double, double* %17
%26 = load double, double* %18
%27 = load double, double* %10
%28 = load double, double* %11
%29 = load double, double* %12
%30 = call double @point_distance_3d(double %24, double %25, double %26, double %27, double %28, double %29)
store double %30, double* %19
%31 = load double, double* %16
%32 = load double, double* %17
%33 = load double, double* %18
%34 = load double, double* %13
%35 = load double, double* %14
%36 = load double, double* %15
%37 = call double @point_distance_3d(double %31, double %32, double %33, double %34, double %35, double %36)
store double %37, double* %20
%38 = load double, double* %10
%39 = load double, double* %11
%40 = load double, double* %12
%41 = load double, double* %13
%42 = load double, double* %14
%43 = load double, double* %15
%44 = call double @point_distance_3d(double %38, double %39, double %40, double %41, double %42, double %43)
store double %44, double* %21
%45 = load double, double* %20
%46 = load double, double* %20
%47 = load double, double* %19
%48 = load double, double* %19
%49 = fmul double %47, %48
%50 = fneg double %49
%51 = call double @llvm.fmuladd.f64(double %45, double %46, double %50)
%52 = load double, double* %21
%53 = load double, double* %21
%54 = fneg double %52
%55 = call double @llvm.fmuladd.f64(double %54, double %53, double %51)
%56 = load double, double* %21
%57 = fmul double -2.000000e+00, %56
%58 = fdiv double %55, %57
store double %58, double* %22
%59 = load double, double* %19
%60 = load double, double* %19
%61 = load double, double* %22
%62 = load double, double* %22
%63 = fmul double %61, %62
%64 = fneg double %63
%65 = call double @llvm.fmuladd.f64(double %59, double %60, double %64)
store double %65, double* %23
%66 = load double, double* %23
%67 = fcmp olt double %66, 0.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %9
br label %73
69: ; preds = %9
%70 = load double, double* %23
%71 = call i32 @sqrt(double %70)
%72 = sitofp i32 %71 to double
br label %73
73: ; preds = %69, %68
%74 = phi double [ 0.000000e+00, %68 ], [ %72, %69 ]
store double %74, double* %23
%75 = load double, double* %21
%76 = load double, double* %22
%77 = load double, double* %23
%78 = call double @line_segment_dist_2d(i32 0, i32 0, double %75, i32 0, double %76, double %77)
ret double %78
}

LLVM IR (-O2):
define double @line_segment_dist_3d(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = tail call double @point_distance_3d(double %6, double %7, double %8, double %0, double %1, double %2)
%11 = tail call double @point_distance_3d(double %6, double %7, double %8, double %3, double %4, double %5)
%12 = tail call double @point_distance_3d(double %0, double %1, double %2, double %3, double %4, double %5)
%13 = fneg double %10
%14 = fmul double %10, %13
%15 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %14)
%16 = fneg double %12
%17 = tail call double @llvm.fmuladd.f64(double %16, double %12, double %15)
%18 = fmul double %12, -2.000000e+00
%19 = fdiv double %17, %18
%20 = fneg double %19
%21 = fmul double %19, %20
%22 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %21)
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %27, label %24
24: ; preds = %9
%25 = tail call i32 @sqrt(double %22)
%26 = sitofp i32 %25 to double
br label %27
27: ; preds = %9, %24
%28 = phi double [ %26, %24 ], [ 0.000000e+00, %9 ]
%29 = tail call double @line_segment_dist_2d(i32 0, i32 0, double %12, i32 0, double %19, double %28)
ret double %29
}