#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 */
scalar_t__ fabs(double const);
int /*<<< orphan*/ geom_cross3d(double const *, double *, double *);
int geom_norm2d(double const *);
double geom_norm3d(double const *);
void geom_maketriad3d(const double a[3], double b[3], double c[3]) {
  double alen = geom_norm3d(a);
  const double an[3] = {a[0] / alen, a[1] / alen, a[2] / alen};
  if (fabs(a[0]) > fabs(a[2])) {
    double invLen = 1. / geom_norm2d(&an[0]);
    b[0] = -an[1] * invLen;
    b[1] = an[0] * invLen;
    b[2] = 0;
  } else {
    double invLen = 1. / geom_norm2d(&an[1]);
    b[0] = 0;
    b[1] = an[2] * invLen;
    b[2] = -an[1] * invLen;
  }
  geom_cross3d(an, b, c);
}


x86 assembly (clang, -O0):
<geom_maketriad3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <geom_norm3d@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
call   1040 <fabs@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1040 <fabs@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jle    1234 <geom_maketriad3d+0xf4>
lea    -0x40(%rbp),%rdi
call   1050 <geom_norm2d@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe22(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
jmp    129e <geom_maketriad3d+0x15e>
lea    -0x40(%rbp),%rdi
add    $0x8,%rdi
call   1050 <geom_norm2d@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdb3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <geom_cross3d@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_maketriad3d>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <geom_norm3d@plt>
movupd (%rbx),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm1,%xmm3
divpd  %xmm2,%xmm3
movapd %xmm3,(%rsp)
movsd  0x10(%rbx),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
mov    %rax,%r12
movsd  0x10(%rbx),%xmm0
call   1040 <fabs@plt>
cmp    %rax,%r12
jle    11d9 <geom_maketriad3d+0x99>
mov    %rsp,%rdi
call   1050 <geom_norm2d@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xe4d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
xorpd  0xe4b(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
mulsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
jmp    1219 <geom_maketriad3d+0xd9>
lea    0x8(%rsp),%rdi
call   1050 <geom_norm2d@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe0e(%rip),%xmm2
divsd  %xmm0,%xmm2
movq   $0x0,(%r15)
movsd  0x10(%rsp),%xmm0
mulsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
xorpd  0xdfb(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm0,0x8(%r15)
movsd  %xmm1,0x10(%r15)
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <geom_cross3d@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @geom_maketriad3d(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca [3 x double]
%9 = alloca double
%10 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%11 = load double*, double** %4
%12 = call double @geom_norm3d(double* %11)
store double %12, double* %7
%13 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double, double* %7
%18 = fdiv double %16, %17
store double %18, double* %13
%19 = getelementptr inbounds double, double* %13, i64 1
%20 = load double*, double** %4
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = load double, double* %7
%24 = fdiv double %22, %23
store double %24, double* %19
%25 = getelementptr inbounds double, double* %19, i64 1
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double, double* %7
%30 = fdiv double %28, %29
store double %30, double* %25
%31 = load double*, double** %4
%32 = getelementptr inbounds double, double* %31, i64 0
%33 = load double, double* %32
%34 = call i64 @fabs(double %33)
%35 = load double*, double** %4
%36 = getelementptr inbounds double, double* %35, i64 2
%37 = load double, double* %36
%38 = call i64 @fabs(double %37)
%39 = icmp sgt i64 %34, %38
br i1 %39, label %40, label %60
40: ; preds = %3
%41 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%42 = call i32 @geom_norm2d(double* %41)
%43 = sitofp i32 %42 to double
%44 = fdiv double 1.000000e+00, %43
store double %44, double* %9
%45 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
%46 = load double, double* %45
%47 = fneg double %46
%48 = load double, double* %9
%49 = fmul double %47, %48
%50 = load double*, double** %5
%51 = getelementptr inbounds double, double* %50, i64 0
store double %49, double* %51
%52 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%53 = load double, double* %52
%54 = load double, double* %9
%55 = fmul double %53, %54
%56 = load double*, double** %5
%57 = getelementptr inbounds double, double* %56, i64 1
store double %55, double* %57
%58 = load double*, double** %5
%59 = getelementptr inbounds double, double* %58, i64 2
store double 0.000000e+00, double* %59
br label %80
60: ; preds = %3
%61 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
%62 = call i32 @geom_norm2d(double* %61)
%63 = sitofp i32 %62 to double
%64 = fdiv double 1.000000e+00, %63
store double %64, double* %10
%65 = load double*, double** %5
%66 = getelementptr inbounds double, double* %65, i64 0
store double 0.000000e+00, double* %66
%67 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
%68 = load double, double* %67
%69 = load double, double* %10
%70 = fmul double %68, %69
%71 = load double*, double** %5
%72 = getelementptr inbounds double, double* %71, i64 1
store double %70, double* %72
%73 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
%74 = load double, double* %73
%75 = fneg double %74
%76 = load double, double* %10
%77 = fmul double %75, %76
%78 = load double*, double** %5
%79 = getelementptr inbounds double, double* %78, i64 2
store double %77, double* %79
br label %80
80: ; preds = %60, %40
%81 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%82 = load double*, double** %5
%83 = load double*, double** %6
%84 = call i32 @geom_cross3d(double* %81, double* %82, double* %83)
ret void
}

LLVM IR (-O2):
define void @geom_maketriad3d(double* %0, double* %1, double* %2) {
%4 = alloca [3 x double]
%5 = tail call double @geom_norm3d(double* %0)
%6 = bitcast [3 x double]* %4 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%8 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%9 = bitcast double* %0 to <2 x double>*
%10 = load <2 x double>, <2 x double>* %9
%11 = insertelement <2 x double> poison, double %5, i64 0
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
%13 = fdiv <2 x double> %10, %12
%14 = bitcast [3 x double]* %4 to <2 x double>*
store <2 x double> %13, <2 x double>* %14
%15 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%16 = getelementptr inbounds double, double* %0, i64 2
%17 = load double, double* %16
%18 = fdiv double %17, %5
store double %18, double* %15
%19 = extractelement <2 x double> %10, i64 0
%20 = tail call i64 @fabs(double %19)
%21 = load double, double* %16
%22 = tail call i64 @fabs(double %21)
%23 = icmp sgt i64 %20, %22
br i1 %23, label %24, label %33
24: ; preds = %3
%25 = call i32 @geom_norm2d(double* %7)
%26 = sitofp i32 %25 to double
%27 = fdiv double 1.000000e+00, %26
%28 = load double, double* %8
%29 = fneg double %28
%30 = fmul double %27, %29
store double %30, double* %1
%31 = load double, double* %7
%32 = fmul double %27, %31
br label %42
33: ; preds = %3
%34 = call i32 @geom_norm2d(double* %8)
%35 = sitofp i32 %34 to double
%36 = fdiv double 1.000000e+00, %35
store double 0.000000e+00, double* %1
%37 = load double, double* %15
%38 = fmul double %37, %36
%39 = load double, double* %8
%40 = fneg double %39
%41 = fmul double %36, %40
br label %42
42: ; preds = %33, %24
%43 = phi double [ %32, %24 ], [ %38, %33 ]
%44 = phi double [ 0.000000e+00, %24 ], [ %41, %33 ]
%45 = getelementptr inbounds double, double* %1, i64 1
store double %43, double* %45
%46 = getelementptr inbounds double, double* %1, i64 2
store double %44, double* %46
%47 = call i32 @geom_cross3d(double* %7, double* %1, double* %2)
ret void
}