#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*/ diffVt(double *, double *, double *);
int intersect(double **, double *, double **);
scalar_t__ vecEqual(double *, double *);
double vecMag(double *);
double length(double x[4][3], double u[]) {
  int nint;
  double tmp[3], he;
  double points[4][3];
  nint = intersect(x, u, points);
  if (nint > 1) {
    if (vecEqual(points[0], points[1])) {
      if (vecEqual(points[0], points[2])) {
        diffVt(points[0], points[3], tmp);
      } else {
        diffVt(points[0], points[2], tmp);
      }
    } else {
      diffVt(points[0], points[1], tmp);
    }
  } else {
    diffVt(points[0], points[1], tmp);
  }
  he = vecMag(tmp);
  return he;
}


x86 assembly (clang, -O0):
<length>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
call   1060 <intersect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1216 <length+0xd6>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x18,%rsi
call   1050 <vecEqual@plt>
cmp    $0x0,%rax
je     11f6 <length+0xb6>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x30,%rsi
call   1050 <vecEqual@plt>
cmp    $0x0,%rax
je     11d6 <length+0x96>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x48,%rsi
lea    -0x30(%rbp),%rdx
call   1030 <diffVt@plt>
jmp    11f1 <length+0xb1>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x30,%rsi
lea    -0x30(%rbp),%rdx
call   1030 <diffVt@plt>
jmp    1211 <length+0xd1>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x18,%rsi
lea    -0x30(%rbp),%rdx
call   1030 <diffVt@plt>
jmp    1231 <length+0xf1>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
add    $0x18,%rsi
lea    -0x30(%rbp),%rdx
call   1030 <diffVt@plt>
lea    -0x30(%rbp),%rdi
call   1040 <vecMag@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<length>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsp,%rdx
call   1060 <intersect@plt>
lea    0x18(%rsp),%rbx
cmp    $0x2,%eax
jl     1185 <length+0x45>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <vecEqual@plt>
test   %rax,%rax
je     1185 <length+0x45>
lea    0x30(%rsp),%r14
mov    %rsp,%rdi
mov    %r14,%rsi
call   1050 <vecEqual@plt>
test   %rax,%rax
lea    0x48(%rsp),%rbx
cmove  %r14,%rbx
mov    %rsp,%rdi
lea    0x60(%rsp),%r14
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <diffVt@plt>
mov    %r14,%rdi
call   1040 <vecMag@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @length([3 x double]* %0, double* %1) {
%3 = alloca [3 x double]*
%4 = alloca double*
%5 = alloca i32
%6 = alloca [3 x double]
%7 = alloca double
%8 = alloca [4 x [3 x double]]
store [3 x double]* %0, [3 x double]** %3
store double* %1, double** %4
%9 = load [3 x double]*, [3 x double]** %3
%10 = bitcast [3 x double]* %9 to double**
%11 = load double*, double** %4
%12 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%13 = bitcast [3 x double]* %12 to double**
%14 = call i32 @intersect(double** %10, double* %11, double** %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %54
17: ; preds = %2
%18 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%19 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%20 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 1
%21 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%22 = call i64 @vecEqual(double* %19, double* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %46
24: ; preds = %17
%25 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%26 = getelementptr inbounds [3 x double], [3 x double]* %25, i64 0, i64 0
%27 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 2
%28 = getelementptr inbounds [3 x double], [3 x double]* %27, i64 0, i64 0
%29 = call i64 @vecEqual(double* %26, double* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %24
%32 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%33 = getelementptr inbounds [3 x double], [3 x double]* %32, i64 0, i64 0
%34 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 3
%35 = getelementptr inbounds [3 x double], [3 x double]* %34, i64 0, i64 0
%36 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%37 = call i32 @diffVt(double* %33, double* %35, double* %36)
br label %45
38: ; preds = %24
%39 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%40 = getelementptr inbounds [3 x double], [3 x double]* %39, i64 0, i64 0
%41 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 2
%42 = getelementptr inbounds [3 x double], [3 x double]* %41, i64 0, i64 0
%43 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%44 = call i32 @diffVt(double* %40, double* %42, double* %43)
br label %45
45: ; preds = %38, %31
br label %53
46: ; preds = %17
%47 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%48 = getelementptr inbounds [3 x double], [3 x double]* %47, i64 0, i64 0
%49 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 1
%50 = getelementptr inbounds [3 x double], [3 x double]* %49, i64 0, i64 0
%51 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%52 = call i32 @diffVt(double* %48, double* %50, double* %51)
br label %53
53: ; preds = %46, %45
br label %61
54: ; preds = %2
%55 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 0
%56 = getelementptr inbounds [3 x double], [3 x double]* %55, i64 0, i64 0
%57 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %8, i64 0, i64 1
%58 = getelementptr inbounds [3 x double], [3 x double]* %57, i64 0, i64 0
%59 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%60 = call i32 @diffVt(double* %56, double* %58, double* %59)
br label %61
61: ; preds = %54, %53
%62 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%63 = call double @vecMag(double* %62)
store double %63, double* %7
%64 = load double, double* %7
ret double %64
}

LLVM IR (-O2):
define double @length([3 x double]* %0, double* %1) {
%3 = alloca [3 x double]
%4 = alloca [4 x [3 x double]]
%5 = bitcast [3 x double]* %3 to i8*
%6 = bitcast [4 x [3 x double]]* %4 to i8*
%7 = bitcast [3 x double]* %0 to double**
%8 = bitcast [4 x [3 x double]]* %4 to double**
%9 = call i32 @intersect(double** %7, double* %1, double** %8)
%10 = icmp sgt i32 %9, 1
%11 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %4, i64 0, i64 0, i64 0
%12 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %4, i64 0, i64 1, i64 0
br i1 %10, label %13, label %22
13: ; preds = %2
%14 = call i64 @vecEqual(double* %11, double* %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %4, i64 0, i64 2, i64 0
%18 = call i64 @vecEqual(double* %11, double* %17)
%19 = icmp eq i64 %18, 0
%20 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %4, i64 0, i64 3, i64 0
%21 = select i1 %19, double* %17, double* %20
br label %22
22: ; preds = %16, %2, %13
%23 = phi double* [ %12, %13 ], [ %12, %2 ], [ %21, %16 ]
%24 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%25 = call i32 @diffVt(double* %11, double* %23, double* %24)
%26 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%27 = call double @vecMag(double* %26)
ret double %27
}