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

; 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 @detect_collisions_naive(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = 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 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

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

18:                                               ; preds = %12
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %75

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.CollisionWorld, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %68, %19
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.CollisionWorld, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp ult i32 %30, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %71

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.CollisionWorld, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call i32 @compareLines(ptr noundef %44, ptr noundef %45)
  %47 = icmp sge i32 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %49, ptr %10, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %51, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %52

52:                                               ; preds = %48, %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = call i32 @intersect(ptr noundef %53, ptr noundef %54)
  store i32 %55, ptr %11, align 4, !tbaa !9
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %67

58:                                               ; preds = %52
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !9
  call void @IntersectionEventList_appendNode(ptr noundef %59, ptr noundef %60, ptr noundef %61, i32 noundef %62)
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.CollisionWorld, ptr %63, i32 0, i32 3
  %65 = load i32, ptr %64, align 8, !tbaa !14
  %66 = add i32 %65, 1
  store i32 %66, ptr %64, align 8, !tbaa !14
  br label %67

67:                                               ; preds = %58, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = add i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !15

71:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = add i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !17

75:                                               ; preds = %18
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @compareLines(ptr noundef, ptr noundef) #2

declare i32 @intersect(ptr noundef, ptr noundef) #3

declare void @IntersectionEventList_appendNode(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

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 = { 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 #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 }

!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 = !{!12, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

; Function Attrs: nounwind uwtable
define dso_local void @detect_collisions_naive(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not32 = icmp eq i32 %4, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph31

.lr.ph31:                                         ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %8

.loopexit:                                        ; preds = %24, %8
  %.pre-phi = phi i64 [ %10, %8 ], [ %26, %24 ]
  %6 = phi i32 [ %9, %8 ], [ %25, %24 ]
  %7 = icmp ult i64 %indvars.iv.next37, %.pre-phi
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %7, label %8, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void

8:                                                ; preds = %.lr.ph31, %.loopexit
  %9 = phi i32 [ %4, %.lr.ph31 ], [ %6, %.loopexit ]
  %indvars.iv36 = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next37, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph31 ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %10 = zext i32 %9 to i64
  %11 = icmp ult i64 %indvars.iv.next37, %10
  br i1 %11, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %8
  %12 = load ptr, ptr %0, align 8, !tbaa !13
  %13 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv36
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %indvars.iv33 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next34, %24 ]
  %.02528 = phi ptr [ %14, %.lr.ph.preheader ], [ %spec.select, %24 ]
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv33
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = tail call i32 @compareLines(ptr noundef %.02528, ptr noundef %17)
  %19 = icmp sgt i32 %18, -1
  %spec.select = select i1 %19, ptr %17, ptr %.02528
  %spec.select27 = select i1 %19, ptr %.02528, ptr %17
  %20 = tail call i32 @intersect(ptr noundef %spec.select, ptr noundef %spec.select27) #3
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %24, label %21

21:                                               ; preds = %.lr.ph
  tail call void @IntersectionEventList_appendNode(ptr noundef %1, ptr noundef %spec.select, ptr noundef %spec.select27, i32 noundef %20) #3
  %22 = load i32, ptr %5, align 8, !tbaa !15
  %23 = add i32 %22, 1
  store i32 %23, ptr %5, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %21, %.lr.ph
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %25 = load i32, ptr %3, align 8, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next34, %26
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !16
}

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

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

declare void @IntersectionEventList_appendNode(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 = { 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 = { "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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 16}
!16 = distinct !{!16, !12}


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