#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 fabs(double);
double *malloc(int);
double *toBarycentric(double *t_vtx1, double *t_vtx2, double *t_vtx3,
                      double *point) {
  double *out = malloc(3 * sizeof(double));
  double v1x = t_vtx3[0] - t_vtx1[0];
  double v1y = t_vtx2[0] - t_vtx1[0];
  double v1z = t_vtx1[0] - point[0];
  double v2x = t_vtx3[1] - t_vtx1[1];
  double v2y = t_vtx2[1] - t_vtx1[1];
  double v2z = t_vtx1[1] - point[1];
  double a = (v1y * v2z - v1z * v2y);
  double b = (v1z * v2x - v1x * v2z);
  double c = (v1x * v2y - v1y * v2x);
  if (fabs(c) < 1) {
    out[0] = -1;
    out[1] = -1;
    out[2] = -1;
  } else {
    out[0] = (1 - (a + b) / c);
    out[1] = (b / c);
    out[2] = (a / c);
  }
  return out;
}


x86 assembly (clang, -O0):
<toBarycentric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
call   1030 <fabs@plt>
cmp    $0x1,%eax
jge    12bc <toBarycentric+0x19c>
mov    -0x28(%rbp),%rax
movsd  0xd77(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xd67(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x28(%rbp),%rax
movsd  0xd56(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
jmp    1305 <toBarycentric+0x1e5>
movsd  -0x60(%rbp),%xmm1
addsd  -0x68(%rbp),%xmm1
divsd  -0x70(%rbp),%xmm1
movsd  0xd2d(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x68(%rbp),%xmm0
divsd  -0x70(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x60(%rbp),%xmm0
divsd  -0x70(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x28(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toBarycentric>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movsd  (%r12),%xmm3
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
subsd  %xmm0,%xmm3
movsd  (%r15),%xmm2
unpcklpd %xmm0,%xmm2
movhpd 0x0(%r13),%xmm0
subpd  %xmm2,%xmm0
movsd  0x8(%r13),%xmm4
subsd  %xmm1,%xmm4
movsd  0x8(%r12),%xmm2
unpcklpd %xmm1,%xmm2
movhpd 0x8(%r15),%xmm1
subpd  %xmm1,%xmm2
movapd %xmm0,0x40(%rsp)
unpckhpd %xmm0,%xmm0
movapd %xmm2,0x10(%rsp)
mulsd  %xmm2,%xmm0
movapd %xmm3,0x30(%rsp)
movapd %xmm4,(%rsp)
mulsd  %xmm4,%xmm3
subsd  %xmm0,%xmm3
movapd %xmm3,0x20(%rsp)
movapd %xmm3,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    121e <toBarycentric+0xfe>
movapd 0x40(%rsp),%xmm2
movapd 0x30(%rsp),%xmm0
unpcklpd %xmm2,%xmm0
movapd 0x10(%rsp),%xmm1
mulpd  %xmm1,%xmm2
shufpd $0x1,(%rsp),%xmm1
mulpd  %xmm0,%xmm1
subpd  %xmm1,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
movapd 0x20(%rsp),%xmm3
divsd  %xmm3,%xmm0
movsd  0xdf5(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
unpcklpd %xmm3,%xmm3
divpd  %xmm3,%xmm2
jmp    1233 <toBarycentric+0x113>
movabs $0xbff0000000000000,%rax
mov    %rax,(%r14)
movapd 0xddd(%rip),%xmm2
movupd %xmm2,0x8(%r14)
mov    %r14,%rax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @toBarycentric(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 double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%19 = call double* @malloc(i32 24)
store double* %19, double** %9
%20 = load double*, double** %7
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = fsub double %22, %25
store double %26, double* %10
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = fsub double %29, %32
store double %33, double* %11
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = load double*, double** %8
%38 = getelementptr inbounds double, double* %37, i64 0
%39 = load double, double* %38
%40 = fsub double %36, %39
store double %40, double* %12
%41 = load double*, double** %7
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i64 1
%46 = load double, double* %45
%47 = fsub double %43, %46
store double %47, double* %13
%48 = load double*, double** %6
%49 = getelementptr inbounds double, double* %48, i64 1
%50 = load double, double* %49
%51 = load double*, double** %5
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double, double* %52
%54 = fsub double %50, %53
store double %54, double* %14
%55 = load double*, double** %5
%56 = getelementptr inbounds double, double* %55, i64 1
%57 = load double, double* %56
%58 = load double*, double** %8
%59 = getelementptr inbounds double, double* %58, i64 1
%60 = load double, double* %59
%61 = fsub double %57, %60
store double %61, double* %15
%62 = load double, double* %11
%63 = load double, double* %15
%64 = load double, double* %12
%65 = load double, double* %14
%66 = fmul double %64, %65
%67 = fneg double %66
%68 = call double @llvm.fmuladd.f64(double %62, double %63, double %67)
store double %68, double* %16
%69 = load double, double* %12
%70 = load double, double* %13
%71 = load double, double* %10
%72 = load double, double* %15
%73 = fmul double %71, %72
%74 = fneg double %73
%75 = call double @llvm.fmuladd.f64(double %69, double %70, double %74)
store double %75, double* %17
%76 = load double, double* %10
%77 = load double, double* %14
%78 = load double, double* %11
%79 = load double, double* %13
%80 = fmul double %78, %79
%81 = fneg double %80
%82 = call double @llvm.fmuladd.f64(double %76, double %77, double %81)
store double %82, double* %18
%83 = load double, double* %18
%84 = call i32 @fabs(double %83)
%85 = icmp slt i32 %84, 1
br i1 %85, label %86, label %93
86: ; preds = %4
%87 = load double*, double** %9
%88 = getelementptr inbounds double, double* %87, i64 0
store double -1.000000e+00, double* %88
%89 = load double*, double** %9
%90 = getelementptr inbounds double, double* %89, i64 1
store double -1.000000e+00, double* %90
%91 = load double*, double** %9
%92 = getelementptr inbounds double, double* %91, i64 2
store double -1.000000e+00, double* %92
br label %112
93: ; preds = %4
%94 = load double, double* %16
%95 = load double, double* %17
%96 = fadd double %94, %95
%97 = load double, double* %18
%98 = fdiv double %96, %97
%99 = fsub double 1.000000e+00, %98
%100 = load double*, double** %9
%101 = getelementptr inbounds double, double* %100, i64 0
store double %99, double* %101
%102 = load double, double* %17
%103 = load double, double* %18
%104 = fdiv double %102, %103
%105 = load double*, double** %9
%106 = getelementptr inbounds double, double* %105, i64 1
store double %104, double* %106
%107 = load double, double* %16
%108 = load double, double* %18
%109 = fdiv double %107, %108
%110 = load double*, double** %9
%111 = getelementptr inbounds double, double* %110, i64 2
store double %109, double* %111
br label %112
112: ; preds = %93, %86
%113 = load double*, double** %9
ret double* %113
}

LLVM IR (-O2):
define noalias double* @toBarycentric(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = tail call double* @malloc(i32 24)
%6 = load double, double* %2
%7 = load double, double* %0
%8 = fsub double %6, %7
%9 = load double, double* %1
%10 = load double, double* %3
%11 = insertelement <2 x double> poison, double %7, i64 0
%12 = insertelement <2 x double> %11, double %9, i64 1
%13 = insertelement <2 x double> poison, double %10, i64 0
%14 = insertelement <2 x double> %13, double %7, i64 1
%15 = fsub <2 x double> %12, %14
%16 = getelementptr inbounds double, double* %2, i64 1
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %0, i64 1
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 1
%21 = load double, double* %20
%22 = fsub double %21, %19
%23 = getelementptr inbounds double, double* %3, i64 1
%24 = load double, double* %23
%25 = insertelement <2 x double> poison, double %17, i64 0
%26 = insertelement <2 x double> %25, double %19, i64 1
%27 = insertelement <2 x double> poison, double %19, i64 0
%28 = insertelement <2 x double> %27, double %24, i64 1
%29 = fsub <2 x double> %26, %28
%30 = insertelement <2 x double> poison, double %8, i64 0
%31 = shufflevector <2 x double> %30, <2 x double> %15, <2 x i32> <i32 0, i32 2>
%32 = fneg <2 x double> %31
%33 = extractelement <2 x double> %29, i64 1
%34 = insertelement <2 x double> poison, double %33, i64 0
%35 = insertelement <2 x double> %34, double %22, i64 1
%36 = fmul <2 x double> %35, %32
%37 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %15, <2 x double> %29, <2 x double> %36)
%38 = extractelement <2 x double> %15, i64 1
%39 = fneg double %38
%40 = extractelement <2 x double> %29, i64 0
%41 = fmul double %40, %39
%42 = tail call double @llvm.fmuladd.f64(double %8, double %22, double %41)
%43 = tail call i32 @fabs(double %42)
%44 = icmp slt i32 %43, 1
br i1 %44, label %45, label %46
45: ; preds = %4
store double -1.000000e+00, double* %5
br label %55
46: ; preds = %4
%47 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%48 = fadd <2 x double> %47, %37
%49 = extractelement <2 x double> %48, i64 0
%50 = fdiv double %49, %42
%51 = fsub double 1.000000e+00, %50
store double %51, double* %5
%52 = insertelement <2 x double> poison, double %42, i64 0
%53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> zeroinitializer
%54 = fdiv <2 x double> %37, %53
br label %55
55: ; preds = %46, %45
%56 = phi <2 x double> [ <double -1.000000e+00, double -1.000000e+00>, %45 ], [ %54, %46 ]
%57 = getelementptr inbounds double, double* %5, i64 1
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> %56, <2 x double>* %58
ret double* %5
}