#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*/ computeNormal2EdgeOfTriangle(float const *, float const *,
                                                float const *, float *);
float magnitudeVector(float *);
void computeGradientOfBarycentricTriangle(const float *v0, const float *v1,
                                          const float *v2, float *grad) {
  float v0v1[3], norm2edge[3];
  float base;
  computeNormal2EdgeOfTriangle(v0, v1, v2, norm2edge);
  v0v1[0] = v1[0] - v0[0];
  v0v1[1] = v1[1] - v0[1];
  v0v1[2] = v1[2] - v0[2];
  base = magnitudeVector(v0v1);
  grad[0] = 0.5 * base * norm2edge[0];
  grad[1] = 0.5 * base * norm2edge[1];
  grad[2] = 0.5 * base * norm2edge[2];
}


x86 assembly (clang, -O0):
<computeGradientOfBarycentricTriangle>:
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    -0x18(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <computeNormal2EdgeOfTriangle@plt>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
subss  0x4(%rax),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subss  0x8(%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <magnitudeVector@plt>
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x38(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe23(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x34(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdf4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeGradientOfBarycentricTriangle>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rcx
call   1030 <computeNormal2EdgeOfTriangle@plt>
movss  (%rbx),%xmm0
subss  (%r15),%xmm0
movss  %xmm0,0x14(%rsp)
movss  0x4(%rbx),%xmm0
subss  0x4(%r15),%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x8(%rbx),%xmm0
subss  0x8(%r15),%xmm0
movss  %xmm0,0x1c(%rsp)
lea    0x14(%rsp),%rdi
call   1040 <magnitudeVector@plt>
cvtss2sd %xmm0,%xmm0
mulsd  0xe7d(%rip),%xmm0
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%r14)
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%r14)
movss  0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @computeGradientOfBarycentricTriangle(float* %0, float* %1, float* %2, float* %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca [3 x float]
%10 = alloca [3 x float]
%11 = alloca float
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
%12 = load float*, float** %5
%13 = load float*, float** %6
%14 = load float*, float** %7
%15 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%16 = call i32 @computeNormal2EdgeOfTriangle(float* %12, float* %13, float* %14, float* %15)
%17 = load float*, float** %6
%18 = getelementptr inbounds float, float* %17, i64 0
%19 = load float, float* %18
%20 = load float*, float** %5
%21 = getelementptr inbounds float, float* %20, i64 0
%22 = load float, float* %21
%23 = fsub float %19, %22
%24 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
store float %23, float* %24
%25 = load float*, float** %6
%26 = getelementptr inbounds float, float* %25, i64 1
%27 = load float, float* %26
%28 = load float*, float** %5
%29 = getelementptr inbounds float, float* %28, i64 1
%30 = load float, float* %29
%31 = fsub float %27, %30
%32 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 1
store float %31, float* %32
%33 = load float*, float** %6
%34 = getelementptr inbounds float, float* %33, i64 2
%35 = load float, float* %34
%36 = load float*, float** %5
%37 = getelementptr inbounds float, float* %36, i64 2
%38 = load float, float* %37
%39 = fsub float %35, %38
%40 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 2
store float %39, float* %40
%41 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%42 = call float @magnitudeVector(float* %41)
store float %42, float* %11
%43 = load float, float* %11
%44 = fpext float %43 to double
%45 = fmul double 5.000000e-01, %44
%46 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = fmul double %45, %48
%50 = fptrunc double %49 to float
%51 = load float*, float** %8
%52 = getelementptr inbounds float, float* %51, i64 0
store float %50, float* %52
%53 = load float, float* %11
%54 = fpext float %53 to double
%55 = fmul double 5.000000e-01, %54
%56 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%57 = load float, float* %56
%58 = fpext float %57 to double
%59 = fmul double %55, %58
%60 = fptrunc double %59 to float
%61 = load float*, float** %8
%62 = getelementptr inbounds float, float* %61, i64 1
store float %60, float* %62
%63 = load float, float* %11
%64 = fpext float %63 to double
%65 = fmul double 5.000000e-01, %64
%66 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
%67 = load float, float* %66
%68 = fpext float %67 to double
%69 = fmul double %65, %68
%70 = fptrunc double %69 to float
%71 = load float*, float** %8
%72 = getelementptr inbounds float, float* %71, i64 2
store float %70, float* %72
ret void
}

LLVM IR (-O2):
define void @computeGradientOfBarycentricTriangle(float* %0, float* %1, float* %2, float* nocapture writeonly %3) {
%5 = alloca [3 x float]
%6 = alloca [3 x float]
%7 = bitcast [3 x float]* %5 to i8*
%8 = bitcast [3 x float]* %6 to i8*
%9 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%10 = call i32 @computeNormal2EdgeOfTriangle(float* %0, float* %1, float* %2, float* %9)
%11 = load float, float* %1
%12 = load float, float* %0
%13 = fsub float %11, %12
%14 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 0
store float %13, float* %14
%15 = getelementptr inbounds float, float* %1, i64 1
%16 = load float, float* %15
%17 = getelementptr inbounds float, float* %0, i64 1
%18 = load float, float* %17
%19 = fsub float %16, %18
%20 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 1
store float %19, float* %20
%21 = getelementptr inbounds float, float* %1, i64 2
%22 = load float, float* %21
%23 = getelementptr inbounds float, float* %0, i64 2
%24 = load float, float* %23
%25 = fsub float %22, %24
%26 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 2
store float %25, float* %26
%27 = call float @magnitudeVector(float* %14)
%28 = fpext float %27 to double
%29 = fmul double %28, 5.000000e-01
%30 = load float, float* %9
%31 = fpext float %30 to double
%32 = fmul double %29, %31
%33 = fptrunc double %32 to float
store float %33, float* %3
%34 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%35 = load float, float* %34
%36 = fpext float %35 to double
%37 = fmul double %29, %36
%38 = fptrunc double %37 to float
%39 = getelementptr inbounds float, float* %3, i64 1
store float %38, float* %39
%40 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%41 = load float, float* %40
%42 = fpext float %41 to double
%43 = fmul double %29, %42
%44 = fptrunc double %43 to float
%45 = getelementptr inbounds float, float* %3, i64 2
store float %44, float* %45
ret void
}