#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 triangle_area(double *, double *, double *);
int winding_triangle(double *A, double *B, double *C, double *X) {
  double v1 = triangle_area(A, B, X);
  double v2 = triangle_area(B, C, X);
  double v3 = triangle_area(C, A, X);
  int r = 0;
  if (v1 >= 0 && v2 >= 0 && v3 >= 0)
    r = 1;
  if (v1 < 0 && v2 < 0 && v3 < 0)
    r = -1;
  return r;
}


x86 assembly (clang, -O0):
<winding_triangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <triangle_area@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <triangle_area@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <triangle_area@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ae <winding_triangle+0x9e>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ae <winding_triangle+0x9e>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ae <winding_triangle+0x9e>
movl   $0x1,-0x3c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11df <winding_triangle+0xcf>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11df <winding_triangle+0xcf>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11df <winding_triangle+0xcf>
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<winding_triangle>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdx
call   1030 <triangle_area@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <triangle_area@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <triangle_area@plt>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
setae  %al
movsd  0x8(%rsp),%xmm3
ucomisd %xmm1,%xmm3
setae  %cl
and    %al,%cl
ucomisd %xmm1,%xmm0
setae  %al
and    %cl,%al
movzbl %al,%ecx
ucomisd %xmm0,%xmm1
mov    $0xffffffff,%eax
cmovbe %ecx,%eax
ucomisd %xmm3,%xmm1
cmovbe %ecx,%eax
ucomisd %xmm2,%xmm1
cmovbe %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @winding_triangle(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 i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%13 = load double*, double** %5
%14 = load double*, double** %6
%15 = load double*, double** %8
%16 = call double @triangle_area(double* %13, double* %14, double* %15)
store double %16, double* %9
%17 = load double*, double** %6
%18 = load double*, double** %7
%19 = load double*, double** %8
%20 = call double @triangle_area(double* %17, double* %18, double* %19)
store double %20, double* %10
%21 = load double*, double** %7
%22 = load double*, double** %5
%23 = load double*, double** %8
%24 = call double @triangle_area(double* %21, double* %22, double* %23)
store double %24, double* %11
store i32 0, i32* %12
%25 = load double, double* %9
%26 = fcmp oge double %25, 0.000000e+00
br i1 %26, label %27, label %34
27: ; preds = %4
%28 = load double, double* %10
%29 = fcmp oge double %28, 0.000000e+00
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load double, double* %11
%32 = fcmp oge double %31, 0.000000e+00
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* %12
br label %34
34: ; preds = %33, %30, %27, %4
%35 = load double, double* %9
%36 = fcmp olt double %35, 0.000000e+00
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load double, double* %10
%39 = fcmp olt double %38, 0.000000e+00
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load double, double* %11
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 -1, i32* %12
br label %44
44: ; preds = %43, %40, %37, %34
%45 = load i32, i32* %12
ret i32 %45
}

LLVM IR (-O2):
define i32 @winding_triangle(double* %0, double* %1, double* %2, double* %3) {
%5 = tail call double @triangle_area(double* %0, double* %1, double* %3)
%6 = tail call double @triangle_area(double* %1, double* %2, double* %3)
%7 = tail call double @triangle_area(double* %2, double* %0, double* %3)
%8 = fcmp oge double %5, 0.000000e+00
%9 = fcmp oge double %6, 0.000000e+00
%10 = select i1 %8, i1 %9, i1 false
%11 = fcmp oge double %7, 0.000000e+00
%12 = select i1 %10, i1 %11, i1 false
%13 = zext i1 %12 to i32
%14 = fcmp olt double %5, 0.000000e+00
%15 = fcmp olt double %6, 0.000000e+00
%16 = select i1 %14, i1 %15, i1 false
%17 = fcmp olt double %7, 0.000000e+00
%18 = select i1 %16, i1 %17, i1 false
%19 = select i1 %18, i32 -1, i32 %13
ret i32 %19
}