#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 */
float dotproduct(float *, float *);
int /*<<< orphan*/ scaleaddvectors(float *, float *, float *, float);
int /*<<< orphan*/ subtractvectors(float *, float *, float *);
int lineintersectplane(float *intersectpoint, float *normal, float *scale,
                       float *startpoint, float *endpoint, float *point) {
  float vec[3], vec2[3];
  subtractvectors(vec, endpoint, point);
  if (dotproduct(vec, normal) > 0.0f)
    return (0);
  subtractvectors(vec, startpoint, point);
  if (dotproduct(vec, normal) < 0.0f)
    return (0);
  subtractvectors(vec, point, startpoint);
  *scale = dotproduct(vec, normal);
  subtractvectors(vec2, endpoint, startpoint);
  *scale /= dotproduct(vec2, normal);
  scaleaddvectors(intersectpoint, startpoint, vec2, *scale);
  return (1);
}


x86 assembly (clang, -O0):
<lineintersectplane>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0x44(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <subtractvectors@plt>
lea    -0x44(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dotproduct@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1186 <lineintersectplane+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1236 <lineintersectplane+0x106>
lea    -0x44(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <subtractvectors@plt>
lea    -0x44(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dotproduct@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    11bf <lineintersectplane+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    1236 <lineintersectplane+0x106>
lea    -0x44(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <subtractvectors@plt>
lea    -0x44(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dotproduct@plt>
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
lea    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <subtractvectors@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dotproduct@plt>
movaps %xmm0,%xmm1
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <scaleaddvectors@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lineintersectplane>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,(%rsp)
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r8,%rsi
mov    %r9,%rdx
call   1050 <subtractvectors@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dotproduct@plt>
xor    %r14d,%r14d
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
ja     1212 <lineintersectplane+0xe2>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <subtractvectors@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dotproduct@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     1212 <lineintersectplane+0xe2>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1050 <subtractvectors@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dotproduct@plt>
mov    (%rsp),%rbp
movss  %xmm0,0x0(%rbp)
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1050 <subtractvectors@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dotproduct@plt>
movss  0x0(%rbp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x0(%rbp)
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
movaps %xmm1,%xmm0
call   1040 <scaleaddvectors@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lineintersectplane(float* %0, float* %1, float* %2, float* %3, float* %4, float* %5) {
%7 = alloca i32
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca [3 x float]
%15 = alloca [3 x float]
store float* %0, float** %8
store float* %1, float** %9
store float* %2, float** %10
store float* %3, float** %11
store float* %4, float** %12
store float* %5, float** %13
%16 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%17 = load float*, float** %12
%18 = load float*, float** %13
%19 = call i32 @subtractvectors(float* %16, float* %17, float* %18)
%20 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%21 = load float*, float** %9
%22 = call float @dotproduct(float* %20, float* %21)
%23 = fcmp ogt float %22, 0.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %6
store i32 0, i32* %7
br label %60
25: ; preds = %6
%26 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%27 = load float*, float** %11
%28 = load float*, float** %13
%29 = call i32 @subtractvectors(float* %26, float* %27, float* %28)
%30 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%31 = load float*, float** %9
%32 = call float @dotproduct(float* %30, float* %31)
%33 = fcmp olt float %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %25
store i32 0, i32* %7
br label %60
35: ; preds = %25
%36 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%37 = load float*, float** %13
%38 = load float*, float** %11
%39 = call i32 @subtractvectors(float* %36, float* %37, float* %38)
%40 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%41 = load float*, float** %9
%42 = call float @dotproduct(float* %40, float* %41)
%43 = load float*, float** %10
store float %42, float* %43
%44 = getelementptr inbounds [3 x float], [3 x float]* %15, i64 0, i64 0
%45 = load float*, float** %12
%46 = load float*, float** %11
%47 = call i32 @subtractvectors(float* %44, float* %45, float* %46)
%48 = getelementptr inbounds [3 x float], [3 x float]* %15, i64 0, i64 0
%49 = load float*, float** %9
%50 = call float @dotproduct(float* %48, float* %49)
%51 = load float*, float** %10
%52 = load float, float* %51
%53 = fdiv float %52, %50
store float %53, float* %51
%54 = load float*, float** %8
%55 = load float*, float** %11
%56 = getelementptr inbounds [3 x float], [3 x float]* %15, i64 0, i64 0
%57 = load float*, float** %10
%58 = load float, float* %57
%59 = call i32 @scaleaddvectors(float* %54, float* %55, float* %56, float %58)
store i32 1, i32* %7
br label %60
60: ; preds = %35, %34, %24
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
define i32 @lineintersectplane(float* %0, float* %1, float* nocapture %2, float* %3, float* %4, float* %5) {
%7 = alloca [3 x float]
%8 = alloca [3 x float]
%9 = bitcast [3 x float]* %7 to i8*
%10 = bitcast [3 x float]* %8 to i8*
%11 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%12 = call i32 @subtractvectors(float* %11, float* %4, float* %5)
%13 = call float @dotproduct(float* %11, float* %1)
%14 = fcmp ogt float %13, 0.000000e+00
br i1 %14, label %28, label %15
15: ; preds = %6
%16 = call i32 @subtractvectors(float* %11, float* %3, float* %5)
%17 = call float @dotproduct(float* %11, float* %1)
%18 = fcmp olt float %17, 0.000000e+00
br i1 %18, label %28, label %19
19: ; preds = %15
%20 = call i32 @subtractvectors(float* %11, float* %5, float* %3)
%21 = call float @dotproduct(float* %11, float* %1)
store float %21, float* %2
%22 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 0
%23 = call i32 @subtractvectors(float* %22, float* %4, float* %3)
%24 = call float @dotproduct(float* %22, float* %1)
%25 = load float, float* %2
%26 = fdiv float %25, %24
store float %26, float* %2
%27 = call i32 @scaleaddvectors(float* %0, float* %3, float* %22, float %26)
br label %28
28: ; preds = %15, %6, %19
%29 = phi i32 [ 1, %19 ], [ 0, %6 ], [ 0, %15 ]
ret i32 %29
}