; LLVM IR from Mithreindeir/VelocityRaptor :: VelocityRaptor/src (vrTriangulation)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vrTriangle = type { %struct.vrVec2, %struct.vrVec2, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @vrTrianglePoint(ptr noundef byval(%struct.vrTriangle) align 8 %0, <2 x float> %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca %struct.vrVec2, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.vrVec2, align 4
  %8 = alloca %struct.vrVec2, align 4
  %9 = alloca %struct.vrVec2, align 4
  %10 = alloca %struct.vrVec2, align 4
  %11 = alloca %struct.vrVec2, align 4
  %12 = alloca %struct.vrVec2, align 4
  %13 = alloca i32, align 4
  store <2 x float> %1, ptr %5, align 4
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 1
  %15 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 0
  %16 = load <2 x float>, ptr %14, align 8
  %17 = load <2 x float>, ptr %15, align 8
  %18 = call <2 x float> @vrSub(<2 x float> %16, <2 x float> %17)
  store <2 x float> %18, ptr %7, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 0
  %20 = load <2 x float>, ptr %5, align 4
  %21 = load <2 x float>, ptr %19, align 8
  %22 = call <2 x float> @vrSub(<2 x float> %20, <2 x float> %21)
  store <2 x float> %22, ptr %8, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %23 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 2
  %24 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 1
  %25 = load <2 x float>, ptr %23, align 8
  %26 = load <2 x float>, ptr %24, align 8
  %27 = call <2 x float> @vrSub(<2 x float> %25, <2 x float> %26)
  store <2 x float> %27, ptr %9, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 1
  %29 = load <2 x float>, ptr %5, align 4
  %30 = load <2 x float>, ptr %28, align 8
  %31 = call <2 x float> @vrSub(<2 x float> %29, <2 x float> %30)
  store <2 x float> %31, ptr %10, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %32 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 0
  %33 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 2
  %34 = load <2 x float>, ptr %32, align 8
  %35 = load <2 x float>, ptr %33, align 8
  %36 = call <2 x float> @vrSub(<2 x float> %34, <2 x float> %35)
  store <2 x float> %36, ptr %11, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %37 = getelementptr inbounds %struct.vrTriangle, ptr %0, i32 0, i32 2
  %38 = load <2 x float>, ptr %5, align 4
  %39 = load <2 x float>, ptr %37, align 8
  %40 = call <2 x float> @vrSub(<2 x float> %38, <2 x float> %39)
  store <2 x float> %40, ptr %12, align 4
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %60, label %43

43:                                               ; preds = %3
  %44 = load <2 x float>, ptr %7, align 4
  %45 = load <2 x float>, ptr %8, align 4
  %46 = call float @vrCross(<2 x float> %44, <2 x float> %45)
  %47 = fcmp olt float %46, 0.000000e+00
  br i1 %47, label %48, label %59

48:                                               ; preds = %43
  %49 = load <2 x float>, ptr %9, align 4
  %50 = load <2 x float>, ptr %10, align 4
  %51 = call float @vrCross(<2 x float> %49, <2 x float> %50)
  %52 = fcmp olt float %51, 0.000000e+00
  br i1 %52, label %53, label %59

53:                                               ; preds = %48
  %54 = load <2 x float>, ptr %11, align 4
  %55 = load <2 x float>, ptr %12, align 4
  %56 = call float @vrCross(<2 x float> %54, <2 x float> %55)
  %57 = fcmp olt float %56, 0.000000e+00
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %78

59:                                               ; preds = %53, %48, %43
  br label %77

60:                                               ; preds = %3
  %61 = load <2 x float>, ptr %7, align 4
  %62 = load <2 x float>, ptr %8, align 4
  %63 = call float @vrCross(<2 x float> %61, <2 x float> %62)
  %64 = fcmp ogt float %63, 0.000000e+00
  br i1 %64, label %65, label %76

65:                                               ; preds = %60
  %66 = load <2 x float>, ptr %9, align 4
  %67 = load <2 x float>, ptr %10, align 4
  %68 = call float @vrCross(<2 x float> %66, <2 x float> %67)
  %69 = fcmp ogt float %68, 0.000000e+00
  br i1 %69, label %70, label %76

70:                                               ; preds = %65
  %71 = load <2 x float>, ptr %11, align 4
  %72 = load <2 x float>, ptr %12, align 4
  %73 = call float @vrCross(<2 x float> %71, <2 x float> %72)
  %74 = fcmp ogt float %73, 0.000000e+00
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %78

76:                                               ; preds = %70, %65, %60
  br label %77

77:                                               ; preds = %76, %59
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %78

78:                                               ; preds = %77, %75, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

declare <2 x float> @vrSub(<2 x float>, <2 x float>) #2

declare float @vrCross(<2 x float>, <2 x float>) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vrTriangle = type { %struct.vrVec2, %struct.vrVec2, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @vrTrianglePoint(ptr nocapture noundef readonly byval(%struct.vrTriangle) align 8 %0, <2 x float> %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load <2 x float>, ptr %4, align 8
  %6 = load <2 x float>, ptr %0, align 8
  %7 = tail call <2 x float> @vrSub(<2 x float> %5, <2 x float> %6) #2
  %8 = tail call <2 x float> @vrSub(<2 x float> %1, <2 x float> %6) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load <2 x float>, ptr %9, align 8
  %11 = tail call <2 x float> @vrSub(<2 x float> %10, <2 x float> %5) #2
  %12 = tail call <2 x float> @vrSub(<2 x float> %1, <2 x float> %5) #2
  %13 = tail call <2 x float> @vrSub(<2 x float> %6, <2 x float> %10) #2
  %14 = tail call <2 x float> @vrSub(<2 x float> %1, <2 x float> %10) #2
  %.not = icmp eq i32 %2, 0
  %15 = tail call float @vrCross(<2 x float> %7, <2 x float> %8) #2
  br i1 %.not, label %16, label %24

16:                                               ; preds = %3
  %17 = fcmp olt float %15, 0.000000e+00
  br i1 %17, label %18, label %32

18:                                               ; preds = %16
  %19 = tail call float @vrCross(<2 x float> %11, <2 x float> %12) #2
  %20 = fcmp olt float %19, 0.000000e+00
  br i1 %20, label %21, label %32

21:                                               ; preds = %18
  %22 = tail call float @vrCross(<2 x float> %13, <2 x float> %14) #2
  %23 = fcmp olt float %22, 0.000000e+00
  br i1 %23, label %33, label %32

24:                                               ; preds = %3
  %25 = fcmp ogt float %15, 0.000000e+00
  br i1 %25, label %26, label %32

26:                                               ; preds = %24
  %27 = tail call float @vrCross(<2 x float> %11, <2 x float> %12) #2
  %28 = fcmp ogt float %27, 0.000000e+00
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = tail call float @vrCross(<2 x float> %13, <2 x float> %14) #2
  %31 = fcmp ogt float %30, 0.000000e+00
  br i1 %31, label %33, label %32

32:                                               ; preds = %24, %26, %29, %16, %18, %21
  br label %33

33:                                               ; preds = %29, %21, %32
  %.0 = phi i32 [ 0, %32 ], [ 1, %21 ], [ 1, %29 ]
  ret i32 %.0
}

declare <2 x float> @vrSub(<2 x float>, <2 x float>) local_unnamed_addr #1

declare float @vrCross(<2 x float>, <2 x float>) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="64" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass