; LLVM IR from simonaertssen/MIT-6.172-Performance-Engineering-of-Software-Systems :: Project 2 - Collision Detection/screensaver (collision_world)

; 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.IntersectionEventList = type { ptr, ptr, i32 }
%struct.IntersectionEventNode = type { ptr, ptr, i32, ptr }

; 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 void @CollisionWorld_detectIntersection(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.IntersectionEventList, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  call void (ptr, ...) @IntersectionEventList_make(ptr dead_on_unwind writable sret(%struct.IntersectionEventList) align 8 %3)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @detect_collisions_quadtree(ptr noundef %8, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = getelementptr inbounds %struct.IntersectionEventList, ptr %3, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %40, %1
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %44

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.IntersectionEventNode, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  store ptr %18, ptr %6, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %29, %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %33

22:                                               ; preds = %19
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i32 @IntersectionEventNode_compareData(ptr noundef %23, ptr noundef %24)
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %27, %22
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.IntersectionEventNode, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  store ptr %32, ptr %6, align 8, !tbaa !5
  br label %19, !llvm.loop !14

33:                                               ; preds = %19
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = icmp ne ptr %34, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %33
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @IntersectionEventNode_swapData(ptr noundef %38, ptr noundef %39)
  br label %40

40:                                               ; preds = %37, %33
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IntersectionEventNode, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  store ptr %43, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %11, !llvm.loop !16

44:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %45 = getelementptr inbounds %struct.IntersectionEventList, ptr %3, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  store ptr %46, ptr %7, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %50, %44
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %64

50:                                               ; preds = %47
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IntersectionEventNode, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.IntersectionEventNode, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !18
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IntersectionEventNode, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 8, !tbaa !19
  call void @CollisionWorld_collisionSolver(ptr noundef %51, ptr noundef %54, ptr noundef %57, i32 noundef %60)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.IntersectionEventNode, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  store ptr %63, ptr %7, align 8, !tbaa !5
  br label %47, !llvm.loop !20

64:                                               ; preds = %47
  call void @IntersectionEventList_deleteNodes(ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  ret void
}

declare void @IntersectionEventList_make(ptr dead_on_unwind writable sret(%struct.IntersectionEventList) align 8, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @detect_collisions_quadtree(ptr noundef, ptr noundef) #1

declare i32 @IntersectionEventNode_compareData(ptr noundef, ptr noundef) #2

declare void @IntersectionEventNode_swapData(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @CollisionWorld_collisionSolver(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare void @IntersectionEventList_deleteNodes(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"IntersectionEventList", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"IntersectionEventNode", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!13, !6, i64 0}
!18 = !{!13, !6, i64 8}
!19 = !{!13, !11, i64 16}
!20 = distinct !{!20, !15}


; 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.IntersectionEventList = type { ptr, ptr, i32 }

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

; Function Attrs: mustprogress 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 @CollisionWorld_detectIntersection(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.IntersectionEventList, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void (ptr, ...) @IntersectionEventList_make(ptr dead_on_unwind nonnull writable sret(%struct.IntersectionEventList) align 8 %2) #3
  call void @detect_collisions_quadtree(ptr noundef %0, ptr noundef nonnull %2)
  %.02230 = load ptr, ptr %2, align 8, !tbaa !5
  %.not31 = icmp eq ptr %.02230, null
  br i1 %.not31, label %._crit_edge39, label %.lr.ph34

.preheader:                                       ; preds = %.lr.ph34, %8
  %.035.pre = load ptr, ptr %2, align 8, !tbaa !5
  %.not2336 = icmp eq ptr %.035.pre, null
  br i1 %.not2336, label %._crit_edge39, label %.lr.ph38

.lr.ph34:                                         ; preds = %1, %8
  %.02232 = phi ptr [ %.022.pr, %8 ], [ %.02230, %1 ]
  %3 = getelementptr inbounds i8, ptr %.02232, i64 24
  %.02026 = load ptr, ptr %3, align 8, !tbaa !5
  %.not2427 = icmp eq ptr %.02026, null
  br i1 %.not2427, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph34, %.lr.ph
  %.02029 = phi ptr [ %.020, %.lr.ph ], [ %.02026, %.lr.ph34 ]
  %.02128 = phi ptr [ %spec.select, %.lr.ph ], [ %.02232, %.lr.ph34 ]
  %4 = call i32 @IntersectionEventNode_compareData(ptr noundef nonnull %.02029, ptr noundef %.02128) #3
  %5 = icmp slt i32 %4, 0
  %spec.select = select i1 %5, ptr %.02029, ptr %.02128
  %6 = getelementptr inbounds i8, ptr %.02029, i64 24
  %.020 = load ptr, ptr %6, align 8, !tbaa !9
  %.not24 = icmp eq ptr %.020, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph
  %.not25 = icmp eq ptr %spec.select, %.02232
  br i1 %.not25, label %8, label %7

7:                                                ; preds = %._crit_edge
  call void @IntersectionEventNode_swapData(ptr noundef %spec.select, ptr noundef nonnull %.02232) #3
  br label %8

8:                                                ; preds = %7, %._crit_edge
  %.022.pr = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %.022.pr, null
  br i1 %.not, label %.preheader, label %.lr.ph34, !llvm.loop !14

.lr.ph38:                                         ; preds = %.preheader, %.lr.ph38
  %.037 = phi ptr [ %.0, %.lr.ph38 ], [ %.035.pre, %.preheader ]
  %9 = load ptr, ptr %.037, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %.037, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %.037, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !17
  call void @CollisionWorld_collisionSolver(ptr noundef %0, ptr noundef %9, ptr noundef %11, i32 noundef %13)
  %14 = getelementptr inbounds i8, ptr %.037, i64 24
  %.0 = load ptr, ptr %14, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.0, null
  br i1 %.not23, label %._crit_edge39, label %.lr.ph38, !llvm.loop !18

._crit_edge39:                                    ; preds = %.lr.ph38, %1, %.preheader
  call void @IntersectionEventList_deleteNodes(ptr noundef nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  ret void
}

declare void @IntersectionEventList_make(ptr dead_on_unwind writable sret(%struct.IntersectionEventList) align 8, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @detect_collisions_quadtree(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @IntersectionEventNode_compareData(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @IntersectionEventNode_swapData(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @CollisionWorld_collisionSolver(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @IntersectionEventList_deleteNodes(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"IntersectionEventNode", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !6, i64 8}
!17 = !{!10, !11, i64 16}
!18 = distinct !{!18, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass