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

@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.detect_collisions_quadtree = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @detect_collisions_quadtree(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = call ptr @make_quadtree(ptr noundef null, double noundef 2.500000e-01, double noundef 2.500000e-01, float noundef 5.000000e-01, i8 noundef zeroext 0)
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %24, %2
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CollisionWorld, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i32 %9, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %8
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CollisionWorld, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  call void @insert_line(ptr noundef %22, ptr noundef %23)
  br label %24

24:                                               ; preds = %15
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = add i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !14

27:                                               ; preds = %14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.CollisionWorld, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call zeroext i16 @count_lines(ptr noundef %31)
  %33 = zext i16 %32 to i32
  %34 = icmp eq i32 %30, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  br label %37

36:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 202, ptr noundef @__PRETTY_FUNCTION__.detect_collisions_quadtree) #5
  unreachable

37:                                               ; preds = %35
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @detect_collisions(ptr noundef %38, ptr noundef %39)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.IntersectionEventList, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CollisionWorld, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !18
  %46 = add i32 %45, %42
  store i32 %46, ptr %44, align 8, !tbaa !18
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  call void @destroy_quadtree(ptr noundef %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare ptr @make_quadtree(ptr noundef, double noundef, double noundef, float noundef, i8 noundef zeroext) #3

declare void @insert_line(ptr noundef, ptr noundef) #3

declare zeroext i16 @count_lines(ptr noundef) #3

declare void @detect_collisions(ptr noundef, ptr noundef) #3

declare void @destroy_quadtree(ptr noundef) #3

attributes #0 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"CollisionWorld", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 16}
!17 = !{!"IntersectionEventList", !6, i64 0, !6, i64 8, !10, i64 16}
!18 = !{!12, !10, i64 16}


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

@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.detect_collisions_quadtree = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @detect_collisions_quadtree(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @make_quadtree(ptr noundef null, double noundef 2.500000e-01, double noundef 2.500000e-01, float noundef 5.000000e-01, i8 noundef zeroext 0) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.lcssa = phi i32 [ 0, %2 ], [ %12, %.lr.ph ]
  %6 = tail call zeroext i16 @count_lines(ptr noundef %3) #3
  %7 = zext i16 %6 to i32
  %8 = icmp eq i32 %.lcssa, %7
  br i1 %8, label %16, label %15

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  tail call void @insert_line(ptr noundef %11, ptr noundef %3) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %4, align 8, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !13

15:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 202, ptr noundef nonnull @__PRETTY_FUNCTION__.detect_collisions_quadtree) #4
  unreachable

16:                                               ; preds = %._crit_edge
  tail call void @detect_collisions(ptr noundef %3, ptr noundef %1) #3
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = add i32 %20, %18
  store i32 %21, ptr %19, align 8, !tbaa !17
  tail call void @destroy_quadtree(ptr noundef %3) #3
  ret void
}

declare ptr @make_quadtree(ptr noundef, double noundef, double noundef, float noundef, i8 noundef zeroext) local_unnamed_addr #2

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

declare zeroext i16 @count_lines(ptr noundef) local_unnamed_addr #2

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

declare void @destroy_quadtree(ptr noundef) local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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"="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 }
attributes #4 = { noreturn 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, !10, i64 8}
!6 = !{!"CollisionWorld", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 16}
!16 = !{!"IntersectionEventList", !7, i64 0, !7, i64 8, !10, i64 16}
!17 = !{!6, !10, i64 16}


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