#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*/ crossProd(double *, double *, double *);
int /*<<< orphan*/ diffVt(double *, double *, double *);
double dotProd(double *, double *);
double vecMag(double *);
int isPntInTri(double t_xyz[3][3], double t_normal[3], double p_xyz[3],
               double tol) {
  double cross_p[3];
  double d;
  int side;
  int status;
  double cross_p_sqnorm;
  double dnbr;
  double dtol;
  double t_vec[3];
  double t_vec_norm;
  double tp_vec[3];
  double tp_vec_sqnorm;
  status = 1;
  for (side = 0; side < 3; side++) {
    diffVt(t_xyz[(side + 1) % 3], t_xyz[side], t_vec);
    crossProd(t_normal, t_vec, cross_p);
    cross_p_sqnorm = dotProd(cross_p, cross_p);
    diffVt(p_xyz, t_xyz[side], tp_vec);
    d = dotProd(cross_p, tp_vec);
    dnbr = d * d;
    dtol = tol * tol * cross_p_sqnorm;
    if (dnbr < dtol) {
      t_vec_norm = vecMag(t_vec);
      dtol = t_vec_norm + tol;
      dtol *= dtol;
      tp_vec_sqnorm = dotProd(tp_vec, tp_vec);
      if (tp_vec_sqnorm > dtol) {
        status = 0;
        break;
      }
      diffVt(p_xyz, t_xyz[(side + 1) % 3], tp_vec);
      tp_vec_sqnorm = dotProd(tp_vec, tp_vec);
      if (tp_vec_sqnorm > dtol) {
        status = 0;
        break;
      }
      continue;
    }
    if (d > 0.0) {
    } else if (d < 0.0) {
      status = 0;
      break;
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<isPntInTri>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x50(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jge    1356 <isPntInTri+0x216>
mov    -0x8(%rbp),%rdi
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x4c(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
lea    -0x80(%rbp),%rdx
call   1030 <diffVt@plt>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <crossProd@plt>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <dotProd@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x4c(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
lea    -0xa0(%rbp),%rdx
call   1030 <diffVt@plt>
lea    -0x40(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <dotProd@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    130d <isPntInTri+0x1cd>
lea    -0x80(%rbp),%rdi
call   1040 <vecMag@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <dotProd@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
ucomisd -0x68(%rbp),%xmm0
jbe    12a2 <isPntInTri+0x162>
movl   $0x0,-0x50(%rbp)
jmp    1356 <isPntInTri+0x216>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
lea    -0xa0(%rbp),%rdx
call   1030 <diffVt@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <dotProd@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
ucomisd -0x68(%rbp),%xmm0
jbe    1308 <isPntInTri+0x1c8>
movl   $0x0,-0x50(%rbp)
jmp    1356 <isPntInTri+0x216>
jmp    1348 <isPntInTri+0x208>
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1324 <isPntInTri+0x1e4>
jmp    1343 <isPntInTri+0x203>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    133e <isPntInTri+0x1fe>
movl   $0x0,-0x50(%rbp)
jmp    1356 <isPntInTri+0x216>
jmp    1343 <isPntInTri+0x203>
jmp    1348 <isPntInTri+0x208>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    116a <isPntInTri+0x2a>
mov    -0x50(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPntInTri>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    $0x1,%r14d
xor    %r12d,%r12d
lea    0x40(%rsp),%rbx
lea    0x60(%rsp),%r13
jmp    11b5 <isPntInTri+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     12bb <isPntInTri+0x17b>
add    $0x18,%r12
add    $0x1,%r14
cmp    $0x48,%r12
lea    0x40(%rsp),%rbx
je     12b3 <isPntInTri+0x173>
mov    %r14,%rax
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
shl    $0x2,%rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,8),%rax
mov    %r12,%rcx
sub    %rax,%rcx
mov    0x28(%rsp),%rax
lea    (%rax,%rcx,1),%rdi
add    $0x18,%rdi
lea    (%rax,%r12,1),%rbp
mov    %rdi,0x38(%rsp)
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <diffVt@plt>
mov    0x30(%rsp),%rdi
mov    %rbx,%rsi
lea    0x80(%rsp),%r15
mov    %r15,%rdx
call   1050 <crossProd@plt>
mov    %r15,%rdi
mov    %r15,%rsi
call   1060 <dotProd@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1030 <diffVt@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <dotProd@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jbe    1190 <isPntInTri+0x50>
mov    %rbx,%rdi
call   1040 <vecMag@plt>
addsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
mov    %r13,%rsi
call   1060 <dotProd@plt>
xor    %r15d,%r15d
ucomisd 0x8(%rsp),%xmm0
ja     12be <isPntInTri+0x17e>
mov    0x10(%rsp),%rdi
mov    0x38(%rsp),%rsi
mov    %r13,%rdx
call   1030 <diffVt@plt>
mov    %r13,%rdi
mov    %r13,%rsi
call   1060 <dotProd@plt>
ucomisd 0x8(%rsp),%xmm0
jbe    119e <isPntInTri+0x5e>
jmp    12be <isPntInTri+0x17e>
mov    $0x1,%r15d
jmp    12be <isPntInTri+0x17e>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isPntInTri([3 x double]* %0, double* %1, double* %2, double %3) {
%5 = alloca [3 x double]*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca [3 x double]
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca [3 x double]
%17 = alloca double
%18 = alloca [3 x double]
%19 = alloca double
store [3 x double]* %0, [3 x double]** %5
store double* %1, double** %6
store double* %2, double** %7
store double %3, double* %8
store i32 1, i32* %12
store i32 0, i32* %11
br label %20
20: ; preds = %112, %4
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %115
23: ; preds = %20
%24 = load [3 x double]*, [3 x double]** %5
%25 = load i32, i32* %11
%26 = add nsw i32 %25, 1
%27 = srem i32 %26, 3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 %28
%30 = getelementptr inbounds [3 x double], [3 x double]* %29, i64 0, i64 0
%31 = load [3 x double]*, [3 x double]** %5
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [3 x double], [3 x double]* %31, i64 %33
%35 = getelementptr inbounds [3 x double], [3 x double]* %34, i64 0, i64 0
%36 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
%37 = call i32 @diffVt(double* %30, double* %35, double* %36)
%38 = load double*, double** %6
%39 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
%40 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%41 = call i32 @crossProd(double* %38, double* %39, double* %40)
%42 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%43 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%44 = call double @dotProd(double* %42, double* %43)
store double %44, double* %13
%45 = load double*, double** %7
%46 = load [3 x double]*, [3 x double]** %5
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [3 x double], [3 x double]* %46, i64 %48
%50 = getelementptr inbounds [3 x double], [3 x double]* %49, i64 0, i64 0
%51 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%52 = call i32 @diffVt(double* %45, double* %50, double* %51)
%53 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%54 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%55 = call double @dotProd(double* %53, double* %54)
store double %55, double* %10
%56 = load double, double* %10
%57 = load double, double* %10
%58 = fmul double %56, %57
store double %58, double* %14
%59 = load double, double* %8
%60 = load double, double* %8
%61 = fmul double %59, %60
%62 = load double, double* %13
%63 = fmul double %61, %62
store double %63, double* %15
%64 = load double, double* %14
%65 = load double, double* %15
%66 = fcmp olt double %64, %65
br i1 %66, label %67, label %102
67: ; preds = %23
%68 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
%69 = call double @vecMag(double* %68)
store double %69, double* %17
%70 = load double, double* %17
%71 = load double, double* %8
%72 = fadd double %70, %71
store double %72, double* %15
%73 = load double, double* %15
%74 = load double, double* %15
%75 = fmul double %74, %73
store double %75, double* %15
%76 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%77 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%78 = call double @dotProd(double* %76, double* %77)
store double %78, double* %19
%79 = load double, double* %19
%80 = load double, double* %15
%81 = fcmp ogt double %79, %80
br i1 %81, label %82, label %83
82: ; preds = %67
store i32 0, i32* %12
br label %115
83: ; preds = %67
%84 = load double*, double** %7
%85 = load [3 x double]*, [3 x double]** %5
%86 = load i32, i32* %11
%87 = add nsw i32 %86, 1
%88 = srem i32 %87, 3
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [3 x double], [3 x double]* %85, i64 %89
%91 = getelementptr inbounds [3 x double], [3 x double]* %90, i64 0, i64 0
%92 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%93 = call i32 @diffVt(double* %84, double* %91, double* %92)
%94 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%95 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%96 = call double @dotProd(double* %94, double* %95)
store double %96, double* %19
%97 = load double, double* %19
%98 = load double, double* %15
%99 = fcmp ogt double %97, %98
br i1 %99, label %100, label %101
100: ; preds = %83
store i32 0, i32* %12
br label %115
101: ; preds = %83
br label %112
102: ; preds = %23
%103 = load double, double* %10
%104 = fcmp ogt double %103, 0.000000e+00
br i1 %104, label %105, label %106
105: ; preds = %102
br label %111
106: ; preds = %102
%107 = load double, double* %10
%108 = fcmp olt double %107, 0.000000e+00
br i1 %108, label %109, label %110
109: ; preds = %106
store i32 0, i32* %12
br label %115
110: ; preds = %106
br label %111
111: ; preds = %110, %105
br label %112
112: ; preds = %111, %101
%113 = load i32, i32* %11
%114 = add nsw i32 %113, 1
store i32 %114, i32* %11
br label %20
115: ; preds = %109, %100, %82, %20
%116 = load i32, i32* %12
ret i32 %116
}

LLVM IR (-O2):
define i32 @isPntInTri([3 x double]* %0, double* %1, double* %2, double %3) {
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = alloca [3 x double]
%8 = bitcast [3 x double]* %5 to i8*
%9 = bitcast [3 x double]* %6 to i8*
%10 = bitcast [3 x double]* %7 to i8*
%11 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%12 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%13 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%14 = fmul double %3, %3
br label %15
15: ; preds = %4, %43
%16 = phi i64 [ 0, %4 ], [ %17, %43 ]
%17 = add nuw nsw i64 %16, 1
%18 = trunc i64 %17 to i8
%19 = urem i8 %18, 3
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 %20, i64 0
%22 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 %16, i64 0
%23 = call i32 @diffVt(double* %21, double* %22, double* %11)
%24 = call i32 @crossProd(double* %1, double* %11, double* %12)
%25 = call double @dotProd(double* %12, double* %12)
%26 = call i32 @diffVt(double* %2, double* %22, double* %13)
%27 = call double @dotProd(double* %12, double* %13)
%28 = fmul double %27, %27
%29 = fmul double %14, %25
%30 = fcmp olt double %28, %29
br i1 %30, label %31, label %41
31: ; preds = %15
%32 = call double @vecMag(double* %11)
%33 = fadd double %32, %3
%34 = fmul double %33, %33
%35 = call double @dotProd(double* %13, double* %13)
%36 = fcmp ogt double %35, %34
br i1 %36, label %45, label %37
37: ; preds = %31
%38 = call i32 @diffVt(double* %2, double* %21, double* %13)
%39 = call double @dotProd(double* %13, double* %13)
%40 = fcmp ogt double %39, %34
br i1 %40, label %45, label %43
41: ; preds = %15
%42 = fcmp olt double %27, 0.000000e+00
br i1 %42, label %45, label %43
43: ; preds = %41, %37
%44 = icmp eq i64 %17, 3
br i1 %44, label %45, label %15
45: ; preds = %41, %37, %31, %43
%46 = phi i32 [ 1, %43 ], [ 0, %31 ], [ 0, %37 ], [ 0, %41 ]
ret i32 %46
}