#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 */
scalar_t__ _dot(double *, double *, int);
double c_distance_to_line(double *, double *, double *);
double c_in_truncated_cylinder(double *point, double *center_1,
                               double *center_2, double *normal_cap_1,
                               double *normal_cap_2, double radius) {
  double c_1p[3];
  double c_2p[3];
  int i;
  double dst_to_centerline;
  for (i = 0; i < 3; i++) {
    c_1p[i] = point[i] - center_1[i];
  }
  if (_dot(normal_cap_1, c_1p, 3) < 0) {
    return -1;
  }
  for (i = 0; i < 3; i++) {
    c_2p[i] = point[i] - center_2[i];
  }
  if (_dot(normal_cap_2, c_2p, 3) < 0) {
    return -1;
  }
  dst_to_centerline = c_distance_to_line(point, center_1, center_2);
  if (dst_to_centerline > radius) {
    return -1;
  }
  return dst_to_centerline;
}


x86 assembly (clang, -O0):
<c_in_truncated_cylinder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x3,-0x74(%rbp)
jge    1187 <c_in_truncated_cylinder+0x67>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x74(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movslq -0x74(%rbp),%rax
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    114b <c_in_truncated_cylinder+0x2b>
mov    -0x28(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x3,%edx
call   1030 <_dot@plt>
cmp    $0x0,%rax
jge    11b5 <c_in_truncated_cylinder+0x95>
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1268 <c_in_truncated_cylinder+0x148>
movl   $0x0,-0x74(%rbp)
cmpl   $0x3,-0x74(%rbp)
jge    11f8 <c_in_truncated_cylinder+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x74(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movslq -0x74(%rbp),%rax
movsd  %xmm0,-0x70(%rbp,%rax,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11bc <c_in_truncated_cylinder+0x9c>
mov    -0x30(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x3,%edx
call   1030 <_dot@plt>
cmp    $0x0,%rax
jge    1226 <c_in_truncated_cylinder+0x106>
movsd  0xde4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1268 <c_in_truncated_cylinder+0x148>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <c_distance_to_line@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    125e <c_in_truncated_cylinder+0x13e>
movsd  0xdac(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1268 <c_in_truncated_cylinder+0x148>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_in_truncated_cylinder>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
movaps %xmm0,(%rsp)
mov    %r8,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movupd (%rdi),%xmm0
movupd (%rsi),%xmm1
subpd  %xmm1,%xmm0
movapd %xmm0,0x30(%rsp)
movsd  0x10(%rdi),%xmm0
subsd  0x10(%rsi),%xmm0
movsd  %xmm0,0x40(%rsp)
lea    0x30(%rsp),%rsi
mov    %rcx,%rdi
mov    $0x3,%edx
call   1030 <_dot@plt>
movsd  0xe89(%rip),%xmm0
test   %rax,%rax
js     11ef <c_in_truncated_cylinder+0xcf>
movupd (%rbx),%xmm0
movupd (%r14),%xmm1
subpd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0x10(%rbx),%xmm0
subsd  0x10(%r14),%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x10(%rsp),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1030 <_dot@plt>
movsd  0xe46(%rip),%xmm0
test   %rax,%rax
js     11ef <c_in_truncated_cylinder+0xcf>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <c_distance_to_line@plt>
movapd (%rsp),%xmm2
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm1
andnpd %xmm0,%xmm1
movsd  0xe19(%rip),%xmm0
andpd  %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @c_in_truncated_cylinder(double* %0, double* %1, double* %2, double* %3, double* %4, double %5) {
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca [3 x double]
%15 = alloca [3 x double]
%16 = alloca i32
%17 = alloca double
store double* %0, double** %8
store double* %1, double** %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store double %5, double* %13
store i32 0, i32* %16
br label %18
18: ; preds = %36, %6
%19 = load i32, i32* %16
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load double*, double** %8
%23 = load i32, i32* %16
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %9
%28 = load i32, i32* %16
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fsub double %26, %31
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %34
store double %32, double* %35
br label %36
36: ; preds = %21
%37 = load i32, i32* %16
%38 = add nsw i32 %37, 1
store i32 %38, i32* %16
br label %18
39: ; preds = %18
%40 = load double*, double** %11
%41 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
%42 = call i64 @_dot(double* %40, double* %41, i32 3)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store double -1.000000e+00, double* %7
br label %84
45: ; preds = %39
store i32 0, i32* %16
br label %46
46: ; preds = %64, %45
%47 = load i32, i32* %16
%48 = icmp slt i32 %47, 3
br i1 %48, label %49, label %67
49: ; preds = %46
%50 = load double*, double** %8
%51 = load i32, i32* %16
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %10
%56 = load i32, i32* %16
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = fsub double %54, %59
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 %62
store double %60, double* %63
br label %64
64: ; preds = %49
%65 = load i32, i32* %16
%66 = add nsw i32 %65, 1
store i32 %66, i32* %16
br label %46
67: ; preds = %46
%68 = load double*, double** %12
%69 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%70 = call i64 @_dot(double* %68, double* %69, i32 3)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %67
store double -1.000000e+00, double* %7
br label %84
73: ; preds = %67
%74 = load double*, double** %8
%75 = load double*, double** %9
%76 = load double*, double** %10
%77 = call double @c_distance_to_line(double* %74, double* %75, double* %76)
store double %77, double* %17
%78 = load double, double* %17
%79 = load double, double* %13
%80 = fcmp ogt double %78, %79
br i1 %80, label %81, label %82
81: ; preds = %73
store double -1.000000e+00, double* %7
br label %84
82: ; preds = %73
%83 = load double, double* %17
store double %83, double* %7
br label %84
84: ; preds = %82, %81, %72, %44
%85 = load double, double* %7
ret double %85
}

LLVM IR (-O2):
define double @c_in_truncated_cylinder(double* %0, double* %1, double* %2, double* %3, double* %4, double %5) {
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = bitcast [3 x double]* %7 to i8*
%10 = bitcast [3 x double]* %8 to i8*
%11 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%12 = bitcast double* %0 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = bitcast double* %1 to <2 x double>*
%15 = load <2 x double>, <2 x double>* %14
%16 = fsub <2 x double> %13, %15
%17 = bitcast [3 x double]* %7 to <2 x double>*
store <2 x double> %16, <2 x double>* %17
%18 = getelementptr inbounds double, double* %0, i64 2
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 2
%21 = load double, double* %20
%22 = fsub double %19, %21
%23 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
store double %22, double* %23
%24 = call i64 @_dot(double* %3, double* %11, i32 3)
%25 = icmp slt i64 %24, 0
br i1 %25, label %45, label %26
26: ; preds = %6
%27 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%28 = bitcast double* %0 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = bitcast double* %2 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = fsub <2 x double> %29, %31
%33 = bitcast [3 x double]* %8 to <2 x double>*
store <2 x double> %32, <2 x double>* %33
%34 = load double, double* %18
%35 = getelementptr inbounds double, double* %2, i64 2
%36 = load double, double* %35
%37 = fsub double %34, %36
%38 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
store double %37, double* %38
%39 = call i64 @_dot(double* %4, double* %27, i32 3)
%40 = icmp slt i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %26
%42 = call double @c_distance_to_line(double* %0, double* %1, double* %2)
%43 = fcmp ogt double %42, %5
%44 = select i1 %43, double -1.000000e+00, double %42
br label %45
45: ; preds = %41, %26, %6
%46 = phi double [ -1.000000e+00, %6 ], [ -1.000000e+00, %26 ], [ %44, %41 ]
ret double %46
}