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

; 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.vrEdge = type { %struct.vrVec2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }
%struct.vrPolygonShape = type { ptr, i32, ptr, i32, %struct.vrVec2 }

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

declare <2 x float> @vrVect(float noundef, float noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @vrPolyBestEdge(ptr dead_on_unwind noalias writable sret(%struct.vrEdge) align 4 %0, ptr noundef byval(%struct.vrPolygonShape) align 8 %1, i32 noundef %2, <2 x float> %3) #3 {
  %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 %struct.vrVec2, align 4
  %14 = alloca %struct.vrVec2, align 4
  %15 = alloca %struct.vrVec2, align 4
  %16 = alloca i32, align 4
  store <2 x float> %3, ptr %5, align 4
  store i32 %2, ptr %6, align 4, !tbaa !5
  %17 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %26

20:                                               ; preds = %4
  call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 40, i1 false)
  %21 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 0
  %22 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 1
  %23 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 2
  %24 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 3
  %25 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 4
  br label %104

26:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %27 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.vrVec2, ptr %28, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %31, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %26
  %38 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.vrVec2, ptr %39, i64 %42
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %43, i64 8, i1 false), !tbaa.struct !15
  br label %48

44:                                               ; preds = %26
  %45 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = getelementptr inbounds %struct.vrVec2, ptr %46, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %47, i64 8, i1 false), !tbaa.struct !15
  br label %48

48:                                               ; preds = %44, %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = icmp sgt i32 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %48
  %52 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.vrVec2, ptr %53, i64 %56
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %57, i64 8, i1 false), !tbaa.struct !15
  br label %66

58:                                               ; preds = %48
  %59 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.vrPolygonShape, ptr %1, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.vrVec2, ptr %60, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %65, i64 8, i1 false), !tbaa.struct !15
  br label %66

66:                                               ; preds = %58, %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %67 = load <2 x float>, ptr %7, align 4
  %68 = load <2 x float>, ptr %8, align 4
  %69 = call <2 x float> @vrSub(<2 x float> %67, <2 x float> %68)
  store <2 x float> %69, ptr %10, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %70 = load <2 x float>, ptr %7, align 4
  %71 = load <2 x float>, ptr %9, align 4
  %72 = call <2 x float> @vrSub(<2 x float> %70, <2 x float> %71)
  store <2 x float> %72, ptr %11, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %73 = getelementptr inbounds %struct.vrVec2, ptr %11, i32 0, i32 0
  %74 = load float, ptr %73, align 4, !tbaa !17
  %75 = fneg float %74
  %76 = getelementptr inbounds %struct.vrVec2, ptr %11, i32 0, i32 1
  %77 = load float, ptr %76, align 4, !tbaa !18
  %78 = fneg float %77
  %79 = call <2 x float> @vrVect(float noundef %75, float noundef %78)
  store <2 x float> %79, ptr %13, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %80 = load <2 x float>, ptr %10, align 4
  %81 = call <2 x float> @vrNormalize(<2 x float> %80)
  store <2 x float> %81, ptr %14, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %14, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %82 = load <2 x float>, ptr %11, align 4
  %83 = call <2 x float> @vrNormalize(<2 x float> %82)
  store <2 x float> %83, ptr %15, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %15, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %84 = load <2 x float>, ptr %11, align 4
  %85 = load <2 x float>, ptr %5, align 4
  %86 = call float @vrDot(<2 x float> %84, <2 x float> %85)
  %87 = load <2 x float>, ptr %10, align 4
  %88 = load <2 x float>, ptr %5, align 4
  %89 = call float @vrDot(<2 x float> %87, <2 x float> %88)
  %90 = fcmp ole float %86, %89
  br i1 %90, label %91, label %97

91:                                               ; preds = %66
  %92 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %92, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !15
  %93 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %93, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !15
  %94 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %94, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !15
  %95 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %95, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !15
  %96 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %96, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !15
  store i32 1, ptr %16, align 4
  br label %103

97:                                               ; preds = %66
  %98 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %98, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !15
  %99 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %99, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !15
  %100 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %100, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !15
  %101 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %101, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !15
  %102 = getelementptr inbounds %struct.vrEdge, ptr %0, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %102, ptr align 4 %12, i64 8, i1 false), !tbaa.struct !15
  store i32 1, ptr %16, align 4
  br label %103

103:                                              ; preds = %97, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %104

104:                                              ; preds = %103, %20
  ret void
}

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

declare <2 x float> @vrNormalize(<2 x float>) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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"}
!9 = !{!10, !6, i64 8}
!10 = !{!"vrPolygonShape", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !12, i64 28}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"vrVec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{i64 0, i64 4, !16, i64 4, i64 4, !16}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !13, i64 0}
!18 = !{!12, !13, i64 4}


; 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.vrEdge = type { %struct.vrVec2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }
%struct.vrPolygonShape = type { ptr, i32, ptr, i32, %struct.vrVec2 }

declare <2 x float> @vrVect(float noundef, float noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @vrPolyBestEdge(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.vrEdge) align 4 %0, ptr nocapture noundef readonly byval(%struct.vrPolygonShape) align 8 %1, i32 noundef %2, <2 x float> %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i32, ptr %5, align 8
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %0, i8 0, i64 40, i1 false)
  br label %35

9:                                                ; preds = %4
  %10 = load ptr, ptr %1, align 8
  %11 = sext i32 %2 to i64
  %12 = getelementptr inbounds %struct.vrVec2, ptr %10, i64 %11
  %.sroa.017.0.copyload = load <2 x float>, ptr %12, align 4
  %13 = add nsw i32 %6, -1
  %14 = icmp sgt i32 %13, %2
  %15 = getelementptr i8, ptr %12, i64 8
  %.sroa.013.0.in = select i1 %14, ptr %15, ptr %10
  %.sroa.013.0 = load <2 x float>, ptr %.sroa.013.0.in, align 4
  %16 = icmp sgt i32 %2, 0
  %17 = zext nneg i32 %2 to i64
  %18 = sext i32 %6 to i64
  %.pn.v = select i1 %16, i64 %17, i64 %18
  %.pn = getelementptr %struct.vrVec2, ptr %10, i64 %.pn.v
  %.sroa.09.0.in = getelementptr i8, ptr %.pn, i64 -8
  %.sroa.09.0 = load <2 x float>, ptr %.sroa.09.0.in, align 4
  %19 = tail call <2 x float> @vrSub(<2 x float> %.sroa.017.0.copyload, <2 x float> %.sroa.013.0) #3
  %20 = tail call <2 x float> @vrSub(<2 x float> %.sroa.017.0.copyload, <2 x float> %.sroa.09.0) #3
  %.sroa.03.0.vec.extract = extractelement <2 x float> %20, i64 0
  %21 = fneg float %.sroa.03.0.vec.extract
  %.sroa.03.4.vec.extract = extractelement <2 x float> %20, i64 1
  %22 = fneg float %.sroa.03.4.vec.extract
  %23 = tail call <2 x float> @vrVect(float noundef %21, float noundef %22) #3
  %24 = tail call <2 x float> @vrNormalize(<2 x float> %19) #3
  %25 = tail call <2 x float> @vrNormalize(<2 x float> %20) #3
  %26 = tail call float @vrDot(<2 x float> %25, <2 x float> %3) #3
  %27 = tail call float @vrDot(<2 x float> %24, <2 x float> %3) #3
  %28 = fcmp ugt float %26, %27
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x float> %.sroa.017.0.copyload, ptr %29, align 4
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  %32 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %28, label %34, label %33

33:                                               ; preds = %9
  store <2 x float> %.sroa.09.0, ptr %30, align 4
  store <2 x float> %.sroa.017.0.copyload, ptr %0, align 4
  store <2 x float> %.sroa.09.0, ptr %31, align 4
  store <2 x float> %23, ptr %32, align 4
  br label %35

34:                                               ; preds = %9
  store <2 x float> %.sroa.013.0, ptr %30, align 4
  store <2 x float> %.sroa.013.0, ptr %0, align 4
  store <2 x float> %.sroa.017.0.copyload, ptr %31, align 4
  store <2 x float> %19, ptr %32, align 4
  br label %35

35:                                               ; preds = %33, %34, %8
  ret void
}

declare <2 x float> @vrNormalize(<2 x float>) local_unnamed_addr #0

declare float @vrDot(<2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { "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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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)"}


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