#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 */
int /*<<< orphan*/ cp_3d(double *, double *);
int /*<<< orphan*/ diff_3d(double *, double *, double *);
double inner_3d(double *, double *);
int /*<<< orphan*/ scale_3d(double *, double *, double);
int /*<<< orphan*/ sum_3d(double *, double *, double *);
void p_ls_closest_approach(double p0[3], double a0[3], double b0[3],
                           double c0[3]) {
  double c[3];
  double r;
  diff_3d(p0, b0, a0);
  if (p0[0] == 0 && p0[1] == 0 && p0[2] == 0) {
    cp_3d(p0, a0);
  } else {
    diff_3d(c, c0, a0);
    r = inner_3d(p0, c) / inner_3d(p0, p0);
    if (r < 0)
      cp_3d(p0, a0);
    else if (r > 1)
      cp_3d(p0, b0);
    else {
      scale_3d(p0, p0, r);
      sum_3d(p0, p0, a0);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<p_ls_closest_approach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <diff_3d@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <p_ls_closest_approach+0x8e>
jp     11de <p_ls_closest_approach+0x8e>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <p_ls_closest_approach+0x8e>
jp     11de <p_ls_closest_approach+0x8e>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <p_ls_closest_approach+0x8e>
jp     11de <p_ls_closest_approach+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <cp_3d@plt>
jmp    1295 <p_ls_closest_approach+0x145>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <diff_3d@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <inner_3d@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <inner_3d@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    123f <p_ls_closest_approach+0xef>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <cp_3d@plt>
jmp    1290 <p_ls_closest_approach+0x140>
movsd  -0x48(%rbp),%xmm0
movsd  0xdb4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1268 <p_ls_closest_approach+0x118>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <cp_3d@plt>
jmp    128b <p_ls_closest_approach+0x13b>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
call   1030 <scale_3d@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <sum_3d@plt>
jmp    1290 <p_ls_closest_approach+0x140>
jmp    1295 <p_ls_closest_approach+0x145>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_ls_closest_approach>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %r14,%rdx
call   1070 <diff_3d@plt>
movsd  (%rbx),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ba <p_ls_closest_approach+0x6a>
jp     11ba <p_ls_closest_approach+0x6a>
movsd  0x8(%rbx),%xmm0
ucomisd %xmm1,%xmm0
jne    11ba <p_ls_closest_approach+0x6a>
jp     11ba <p_ls_closest_approach+0x6a>
movsd  0x10(%rbx),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ba <p_ls_closest_approach+0x6a>
jp     11ba <p_ls_closest_approach+0x6a>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <cp_3d@plt>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <diff_3d@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <inner_3d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1060 <inner_3d@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    120e <p_ls_closest_approach+0xbe>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <cp_3d@plt>
jmp    123e <p_ls_closest_approach+0xee>
ucomisd 0xdea(%rip),%xmm0
jbe    1225 <p_ls_closest_approach+0xd5>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <cp_3d@plt>
jmp    123e <p_ls_closest_approach+0xee>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <scale_3d@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <sum_3d@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @p_ls_closest_approach(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [3 x double]
%10 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%11 = load double*, double** %5
%12 = load double*, double** %7
%13 = load double*, double** %6
%14 = call i32 @diff_3d(double* %11, double* %12, double* %13)
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %33
19: ; preds = %4
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load double*, double** %5
%31 = load double*, double** %6
%32 = call i32 @cp_3d(double* %30, double* %31)
br label %69
33: ; preds = %24, %19, %4
%34 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%35 = load double*, double** %8
%36 = load double*, double** %6
%37 = call i32 @diff_3d(double* %34, double* %35, double* %36)
%38 = load double*, double** %5
%39 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%40 = call double @inner_3d(double* %38, double* %39)
%41 = load double*, double** %5
%42 = load double*, double** %5
%43 = call double @inner_3d(double* %41, double* %42)
%44 = fdiv double %40, %43
store double %44, double* %10
%45 = load double, double* %10
%46 = fcmp olt double %45, 0.000000e+00
br i1 %46, label %47, label %51
47: ; preds = %33
%48 = load double*, double** %5
%49 = load double*, double** %6
%50 = call i32 @cp_3d(double* %48, double* %49)
br label %68
51: ; preds = %33
%52 = load double, double* %10
%53 = fcmp ogt double %52, 1.000000e+00
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load double*, double** %5
%56 = load double*, double** %7
%57 = call i32 @cp_3d(double* %55, double* %56)
br label %67
58: ; preds = %51
%59 = load double*, double** %5
%60 = load double*, double** %5
%61 = load double, double* %10
%62 = call i32 @scale_3d(double* %59, double* %60, double %61)
%63 = load double*, double** %5
%64 = load double*, double** %5
%65 = load double*, double** %6
%66 = call i32 @sum_3d(double* %63, double* %64, double* %65)
br label %67
67: ; preds = %58, %54
br label %68
68: ; preds = %67, %47
br label %69
69: ; preds = %68, %29
ret void
}

LLVM IR (-O2):
define void @p_ls_closest_approach(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca [3 x double]
%6 = bitcast [3 x double]* %5 to i8*
%7 = tail call i32 @diff_3d(double* %0, double* %2, double* %1)
%8 = load double, double* %0
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %20
10: ; preds = %4
%11 = getelementptr inbounds double, double* %0, i64 1
%12 = load double, double* %11
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = getelementptr inbounds double, double* %0, i64 2
%16 = load double, double* %15
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @cp_3d(double* %0, double* %1)
br label %36
20: ; preds = %14, %10, %4
%21 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%22 = call i32 @diff_3d(double* %21, double* %3, double* %1)
%23 = call double @inner_3d(double* %0, double* %21)
%24 = call double @inner_3d(double* %0, double* %0)
%25 = fdiv double %23, %24
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @cp_3d(double* %0, double* %1)
br label %36
29: ; preds = %20
%30 = fcmp ogt double %25, 1.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = call i32 @cp_3d(double* %0, double* %2)
br label %36
33: ; preds = %29
%34 = call i32 @scale_3d(double* %0, double* %0, double %25)
%35 = call i32 @sum_3d(double* %0, double* %0, double* %1)
br label %36
36: ; preds = %27, %33, %31, %18
ret void
}