#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 cross_2d(double *, double *);
int /*<<< orphan*/ diff_2d(double *, double *, double *);
int p_inside_tri(double *tri0, double *tri1, double *tri2, double *p) {
  double c1, c2, c3;
  double x0[2], x1[2], x2[2];
  diff_2d(x0, tri0, p);
  diff_2d(x1, tri1, p);
  diff_2d(x2, tri2, p);
  c1 = cross_2d(x0, x1);
  c2 = cross_2d(x1, x2);
  c3 = cross_2d(x2, x0);
  return ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0));
}


x86 assembly (clang, -O0):
<p_inside_tri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <diff_2d@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <diff_2d@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <diff_2d@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <cross_2d@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <cross_2d@plt>
movsd  %xmm0,-0x30(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <cross_2d@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11df <p_inside_tri+0xbf>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11df <p_inside_tri+0xbf>
movsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x71(%rbp)
ja     1219 <p_inside_tri+0xf9>
xor    %eax,%eax
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
mov    %al,-0x72(%rbp)
jbe    1213 <p_inside_tri+0xf3>
xor    %eax,%eax
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
mov    %al,-0x72(%rbp)
jbe    1213 <p_inside_tri+0xf3>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
seta   %al
mov    %al,-0x72(%rbp)
mov    -0x72(%rbp),%al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_inside_tri>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    %rcx,%rdx
call   1040 <diff_2d@plt>
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <diff_2d@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <diff_2d@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <cross_2d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <cross_2d@plt>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <cross_2d@plt>
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm3
jbe    11c5 <p_inside_tri+0xa5>
ucomisd %xmm1,%xmm4
jbe    11c5 <p_inside_tri+0xa5>
mov    $0x1,%eax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
ja     11e0 <p_inside_tri+0xc0>
xor    %eax,%eax
ucomisd %xmm3,%xmm1
jbe    11e0 <p_inside_tri+0xc0>
xorpd  %xmm1,%xmm1
ucomisd %xmm4,%xmm1
jbe    11e0 <p_inside_tri+0xc0>
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @p_inside_tri(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca [2 x double]
%13 = alloca [2 x double]
%14 = alloca [2 x double]
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%15 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%16 = load double*, double** %5
%17 = load double*, double** %8
%18 = call i32 @diff_2d(double* %15, double* %16, double* %17)
%19 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%20 = load double*, double** %6
%21 = load double*, double** %8
%22 = call i32 @diff_2d(double* %19, double* %20, double* %21)
%23 = getelementptr inbounds [2 x double], [2 x double]* %14, i64 0, i64 0
%24 = load double*, double** %7
%25 = load double*, double** %8
%26 = call i32 @diff_2d(double* %23, double* %24, double* %25)
%27 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%28 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%29 = call double @cross_2d(double* %27, double* %28)
store double %29, double* %9
%30 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%31 = getelementptr inbounds [2 x double], [2 x double]* %14, i64 0, i64 0
%32 = call double @cross_2d(double* %30, double* %31)
store double %32, double* %10
%33 = getelementptr inbounds [2 x double], [2 x double]* %14, i64 0, i64 0
%34 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%35 = call double @cross_2d(double* %33, double* %34)
store double %35, double* %11
%36 = load double, double* %9
%37 = fcmp ogt double %36, 0.000000e+00
br i1 %37, label %38, label %44
38: ; preds = %4
%39 = load double, double* %10
%40 = fcmp ogt double %39, 0.000000e+00
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load double, double* %11
%43 = fcmp ogt double %42, 0.000000e+00
br i1 %43, label %55, label %44
44: ; preds = %41, %38, %4
%45 = load double, double* %9
%46 = fcmp olt double %45, 0.000000e+00
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load double, double* %10
%49 = fcmp olt double %48, 0.000000e+00
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load double, double* %11
%52 = fcmp olt double %51, 0.000000e+00
br label %53
53: ; preds = %50, %47, %44
%54 = phi i1 [ false, %47 ], [ false, %44 ], [ %52, %50 ]
br label %55
55: ; preds = %53, %41
%56 = phi i1 [ true, %41 ], [ %54, %53 ]
%57 = zext i1 %56 to i32
ret i32 %57
}

LLVM IR (-O2):
define i32 @p_inside_tri(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca [2 x double]
%6 = alloca [2 x double]
%7 = alloca [2 x double]
%8 = bitcast [2 x double]* %5 to i8*
%9 = bitcast [2 x double]* %6 to i8*
%10 = bitcast [2 x double]* %7 to i8*
%11 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%12 = call i32 @diff_2d(double* %11, double* %0, double* %3)
%13 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%14 = call i32 @diff_2d(double* %13, double* %1, double* %3)
%15 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 0
%16 = call i32 @diff_2d(double* %15, double* %2, double* %3)
%17 = call double @cross_2d(double* %11, double* %13)
%18 = call double @cross_2d(double* %13, double* %15)
%19 = call double @cross_2d(double* %15, double* %11)
%20 = fcmp ogt double %17, 0.000000e+00
%21 = fcmp ogt double %18, 0.000000e+00
%22 = select i1 %20, i1 %21, i1 false
%23 = fcmp ogt double %19, 0.000000e+00
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %32, label %25
25: ; preds = %4
%26 = fcmp olt double %17, 0.000000e+00
%27 = fcmp olt double %18, 0.000000e+00
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = fcmp olt double %19, 0.000000e+00
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %25, %29, %4
%33 = phi i32 [ 1, %4 ], [ 0, %25 ], [ %31, %29 ]
ret i32 %33
}