; LLVM IR from mvr/jiggle :: src (Quadtree)

; 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.jgVector2 = type { float, float }
%struct.jgQuadtree = type { %struct.jgVector2, ptr, ptr, ptr, ptr, ptr }
%struct.jgList = type { ptr, i32, i32 }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @jgListGet(ptr noundef, i32 noundef) #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: 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 void @jgQuadtreeEachCandidate(ptr noundef %0, <2 x float> %1, ptr noundef %2) #3 {
  %4 = alloca %struct.jgVector2, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.jgVector2, align 4
  store <2 x float> %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.jgQuadtree, ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call ptr @jgListGet(ptr noundef %12, i32 noundef 0)
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %26, %3
  %15 = load i32, ptr %8, align 4, !tbaa !13
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.jgQuadtree, ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.jgList, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp slt i32 %15, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %34

23:                                               ; preds = %14
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  call void %24(ptr noundef %25)
  br label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %8, align 4, !tbaa !13
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %8, align 4, !tbaa !13
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.jgQuadtree, ptr %29, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !13
  %33 = call ptr @jgListGet(ptr noundef %31, i32 noundef %32)
  store ptr %33, ptr %7, align 8, !tbaa !5
  br label %14, !llvm.loop !17

34:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.jgQuadtree, ptr %35, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 8 %36, i64 8, i1 false), !tbaa.struct !19
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.jgQuadtree, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %59

41:                                               ; preds = %34
  %42 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %43 = load float, ptr %42, align 4, !tbaa !22
  %44 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 0
  %45 = load float, ptr %44, align 4, !tbaa !22
  %46 = fcmp ole float %43, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %41
  %48 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %49 = load float, ptr %48, align 4, !tbaa !23
  %50 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 1
  %51 = load float, ptr %50, align 4, !tbaa !23
  %52 = fcmp ole float %49, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %47
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.jgQuadtree, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load <2 x float>, ptr %4, align 4
  call void @jgQuadtreeEachCandidate(ptr noundef %56, <2 x float> %58, ptr noundef %57)
  br label %59

59:                                               ; preds = %53, %47, %41, %34
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.jgQuadtree, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %82

64:                                               ; preds = %59
  %65 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %66 = load float, ptr %65, align 4, !tbaa !22
  %67 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 0
  %68 = load float, ptr %67, align 4, !tbaa !22
  %69 = fcmp ole float %66, %68
  br i1 %69, label %70, label %82

70:                                               ; preds = %64
  %71 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %72 = load float, ptr %71, align 4, !tbaa !23
  %73 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 1
  %74 = load float, ptr %73, align 4, !tbaa !23
  %75 = fcmp oge float %72, %74
  br i1 %75, label %76, label %82

76:                                               ; preds = %70
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.jgQuadtree, ptr %77, i32 0, i32 4
  %79 = load ptr, ptr %78, align 8, !tbaa !24
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load <2 x float>, ptr %4, align 4
  call void @jgQuadtreeEachCandidate(ptr noundef %79, <2 x float> %81, ptr noundef %80)
  br label %82

82:                                               ; preds = %76, %70, %64, %59
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.jgQuadtree, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !25
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %105

87:                                               ; preds = %82
  %88 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %89 = load float, ptr %88, align 4, !tbaa !22
  %90 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 0
  %91 = load float, ptr %90, align 4, !tbaa !22
  %92 = fcmp oge float %89, %91
  br i1 %92, label %93, label %105

93:                                               ; preds = %87
  %94 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %95 = load float, ptr %94, align 4, !tbaa !23
  %96 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 1
  %97 = load float, ptr %96, align 4, !tbaa !23
  %98 = fcmp ole float %95, %97
  br i1 %98, label %99, label %105

99:                                               ; preds = %93
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.jgQuadtree, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !25
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load <2 x float>, ptr %4, align 4
  call void @jgQuadtreeEachCandidate(ptr noundef %102, <2 x float> %104, ptr noundef %103)
  br label %105

105:                                              ; preds = %99, %93, %87, %82
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.jgQuadtree, ptr %106, i32 0, i32 3
  %108 = load ptr, ptr %107, align 8, !tbaa !26
  %109 = icmp ne ptr %108, null
  br i1 %109, label %110, label %128

110:                                              ; preds = %105
  %111 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %112 = load float, ptr %111, align 4, !tbaa !22
  %113 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 0
  %114 = load float, ptr %113, align 4, !tbaa !22
  %115 = fcmp oge float %112, %114
  br i1 %115, label %116, label %128

116:                                              ; preds = %110
  %117 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %118 = load float, ptr %117, align 4, !tbaa !23
  %119 = getelementptr inbounds %struct.jgVector2, ptr %9, i32 0, i32 1
  %120 = load float, ptr %119, align 4, !tbaa !23
  %121 = fcmp oge float %118, %120
  br i1 %121, label %122, label %128

122:                                              ; preds = %116
  %123 = load ptr, ptr %5, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.jgQuadtree, ptr %123, i32 0, i32 3
  %125 = load ptr, ptr %124, align 8, !tbaa !26
  %126 = load ptr, ptr %6, align 8, !tbaa !5
  %127 = load <2 x float>, ptr %4, align 4
  call void @jgQuadtreeEachCandidate(ptr noundef %125, <2 x float> %127, ptr noundef %126)
  br label %128

128:                                              ; preds = %122, %116, %110, %105
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint nounwind uwtable "min-legal-vector-width"="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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"jgQuadtree", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"jgVector2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 8}
!16 = !{!"jgList", !6, i64 0, !14, i64 8, !14, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i64 0, i64 4, !20, i64 4, i64 4, !20}
!20 = !{!12, !12, i64 0}
!21 = !{!10, !6, i64 16}
!22 = !{!11, !12, i64 0}
!23 = !{!11, !12, i64 4}
!24 = !{!10, !6, i64 32}
!25 = !{!10, !6, i64 8}
!26 = !{!10, !6, i64 24}


; 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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @jgListGet(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @jgQuadtreeEachCandidate(ptr nocapture noundef readonly %0, <2 x float> %1, ptr noundef %2) local_unnamed_addr #1 {
  %.sroa.026.0.vec.extract = extractelement <2 x float> %1, i64 0
  %.sroa.026.4.vec.extract = extractelement <2 x float> %1, i64 1
  br label %tailrecurse

tailrecurse:                                      ; preds = %33, %3
  %.tr = phi ptr [ %0, %3 ], [ %35, %33 ]
  %4 = getelementptr inbounds i8, ptr %.tr, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call ptr @jgListGet(ptr noundef %5, i32 noundef 0)
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %tailrecurse
  %.sroa.0.0.copyload = load float, ptr %.tr, align 8, !tbaa !15
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %.tr, i64 4
  %.sroa.7.0.copyload = load float, ptr %.sroa.7.0..sroa_idx, align 4, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %.tr, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %.not = icmp eq ptr %12, null
  %13 = fcmp ugt float %.sroa.026.0.vec.extract, %.sroa.0.0.copyload
  %or.cond = select i1 %.not, i1 true, i1 %13
  %14 = fcmp ugt float %.sroa.026.4.vec.extract, %.sroa.7.0.copyload
  %or.cond51 = select i1 %or.cond, i1 true, i1 %14
  br i1 %or.cond51, label %23, label %22

.lr.ph:                                           ; preds = %tailrecurse, %.lr.ph
  %.061 = phi ptr [ %17, %.lr.ph ], [ %6, %tailrecurse ]
  %.04360 = phi i32 [ %15, %.lr.ph ], [ 0, %tailrecurse ]
  tail call void %2(ptr noundef %.061) #2
  %15 = add nuw nsw i32 %.04360, 1
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = tail call ptr @jgListGet(ptr noundef %16, i32 noundef %15)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = icmp slt i32 %15, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !17

22:                                               ; preds = %._crit_edge
  tail call void @jgQuadtreeEachCandidate(ptr noundef nonnull %12, <2 x float> %1, ptr noundef %2)
  br label %23

23:                                               ; preds = %22, %._crit_edge
  %24 = getelementptr inbounds i8, ptr %.tr, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  %.not48 = icmp eq ptr %25, null
  %or.cond52 = select i1 %.not48, i1 true, i1 %13
  %26 = fcmp ult float %.sroa.026.4.vec.extract, %.sroa.7.0.copyload
  %or.cond53 = select i1 %or.cond52, i1 true, i1 %26
  br i1 %or.cond53, label %28, label %27

27:                                               ; preds = %23
  tail call void @jgQuadtreeEachCandidate(ptr noundef nonnull %25, <2 x float> %1, ptr noundef %2)
  br label %28

28:                                               ; preds = %27, %23
  %29 = getelementptr inbounds i8, ptr %.tr, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %.not49 = icmp eq ptr %30, null
  %31 = fcmp ult float %.sroa.026.0.vec.extract, %.sroa.0.0.copyload
  %or.cond54 = select i1 %.not49, i1 true, i1 %31
  %or.cond55 = select i1 %or.cond54, i1 true, i1 %14
  br i1 %or.cond55, label %33, label %32

32:                                               ; preds = %28
  tail call void @jgQuadtreeEachCandidate(ptr noundef nonnull %30, <2 x float> %1, ptr noundef %2)
  br label %33

33:                                               ; preds = %32, %28
  %34 = getelementptr inbounds i8, ptr %.tr, i64 24
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  %.not50 = icmp eq ptr %35, null
  %or.cond56 = select i1 %.not50, i1 true, i1 %31
  %or.cond57 = select i1 %or.cond56, i1 true, i1 %26
  br i1 %or.cond57, label %36, label %tailrecurse

36:                                               ; preds = %33
  ret void
}

attributes #0 = { inlinehint nounwind uwtable "min-legal-vector-width"="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 = { 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, !11, i64 40}
!6 = !{!"jgQuadtree", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!7 = !{!"jgVector2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"jgList", !11, i64 0, !14, i64 8, !14, i64 12}
!14 = !{!"int", !9, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !11, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !11, i64 32}
!20 = !{!6, !11, i64 8}
!21 = !{!6, !11, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass