; LLVM IR from mesbahamin/star-sim :: src (barnes_hut)

; 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.QuadTreeNode = type { ptr, ptr, ptr, ptr, ptr }
%struct.Cell = type { float, float, float, float, float, float, float, float, float, ptr }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cell_contains_star(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cell_is_empty(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @quad_tree_node_is_leaf(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @node_is_sufficiently_far(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @quad_tree_calc_force_on_star(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %7, %2
  br label %71

11:                                               ; preds = %7
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call zeroext i1 @quad_tree_node_is_leaf(ptr noundef %12)
  br i1 %13, label %14, label %32

14:                                               ; preds = %11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.QuadTreeNode, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call zeroext i1 @cell_is_empty(ptr noundef %17)
  br i1 %18, label %32, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.QuadTreeNode, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call zeroext i1 @cell_contains_star(ptr noundef %22, ptr noundef %23)
  br i1 %24, label %32, label %25

25:                                               ; preds = %19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.QuadTreeNode, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.Cell, ptr %28, i32 0, i32 9
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  call void @star_attract(ptr noundef %30, ptr noundef %31)
  br label %71

32:                                               ; preds = %19, %14, %11
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call zeroext i1 @node_is_sufficiently_far(ptr noundef %33, ptr noundef %34)
  br i1 %35, label %36, label %53

36:                                               ; preds = %32
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.QuadTreeNode, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Cell, ptr %40, i32 0, i32 4
  %42 = load float, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.QuadTreeNode, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.Cell, ptr %45, i32 0, i32 5
  %47 = load float, ptr %46, align 4, !tbaa !15
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.QuadTreeNode, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.Cell, ptr %50, i32 0, i32 6
  %52 = load float, ptr %51, align 8, !tbaa !16
  call void @star_attract_to_mass(ptr noundef %37, float noundef %42, float noundef %47, float noundef %52)
  br label %70

53:                                               ; preds = %32
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.QuadTreeNode, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @quad_tree_calc_force_on_star(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.QuadTreeNode, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  call void @quad_tree_calc_force_on_star(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.QuadTreeNode, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  call void @quad_tree_calc_force_on_star(ptr noundef %64, ptr noundef %65)
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.QuadTreeNode, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  call void @quad_tree_calc_force_on_star(ptr noundef %68, ptr noundef %69)
  br label %70

70:                                               ; preds = %53, %36
  br label %71

71:                                               ; preds = %70, %25, %10
  ret void
}

declare void @star_attract(ptr noundef, ptr noundef) #1

declare void @star_attract_to_mass(ptr noundef, float noundef, float noundef, float noundef) #1

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

!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 = !{!"QuadTreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!12, !6, i64 40}
!12 = !{!"Cell", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !6, i64 40}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !13, i64 16}
!15 = !{!12, !13, i64 20}
!16 = !{!12, !13, i64 24}
!17 = !{!10, !6, i64 8}
!18 = !{!10, !6, i64 16}
!19 = !{!10, !6, i64 24}
!20 = !{!10, !6, i64 32}


; 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
declare dso_local zeroext i1 @cell_contains_star(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cell_is_empty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @quad_tree_node_is_leaf(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @node_is_sufficiently_far(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @quad_tree_calc_force_on_star(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %1, null
  %4 = icmp ne ptr %0, null
  %or.cond27 = and i1 %3, %4
  br i1 %or.cond27, label %.lr.ph.split, label %.loopexit

.lr.ph.split:                                     ; preds = %2, %tailrecurse
  %.tr28 = phi ptr [ %31, %tailrecurse ], [ %0, %2 ]
  %5 = tail call zeroext i1 @quad_tree_node_is_leaf(ptr noundef nonnull %.tr28)
  br i1 %5, label %6, label %15

6:                                                ; preds = %.lr.ph.split
  %7 = load ptr, ptr %.tr28, align 8, !tbaa !5
  %8 = tail call zeroext i1 @cell_is_empty(ptr noundef %7)
  br i1 %8, label %15, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr %.tr28, align 8, !tbaa !5
  %11 = tail call zeroext i1 @cell_contains_star(ptr noundef %10, ptr noundef nonnull %1)
  br i1 %11, label %15, label %.split

.split:                                           ; preds = %9
  %12 = load ptr, ptr %.tr28, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  tail call void @star_attract(ptr noundef %14, ptr noundef nonnull %1) #2
  br label %.loopexit

15:                                               ; preds = %9, %6, %.lr.ph.split
  %16 = tail call zeroext i1 @node_is_sufficiently_far(ptr noundef nonnull %.tr28, ptr noundef nonnull %1)
  br i1 %16, label %.split30, label %tailrecurse

.split30:                                         ; preds = %15
  %17 = load ptr, ptr %.tr28, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load float, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %17, i64 20
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %17, i64 24
  %23 = load float, ptr %22, align 8, !tbaa !15
  tail call void @star_attract_to_mass(ptr noundef nonnull %1, float noundef %19, float noundef %21, float noundef %23) #2
  br label %.loopexit

tailrecurse:                                      ; preds = %15
  %24 = getelementptr inbounds i8, ptr %.tr28, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  tail call void @quad_tree_calc_force_on_star(ptr noundef %25, ptr noundef nonnull %1)
  %26 = getelementptr inbounds i8, ptr %.tr28, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  tail call void @quad_tree_calc_force_on_star(ptr noundef %27, ptr noundef nonnull %1)
  %28 = getelementptr inbounds i8, ptr %.tr28, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  tail call void @quad_tree_calc_force_on_star(ptr noundef %29, ptr noundef nonnull %1)
  %30 = getelementptr inbounds i8, ptr %.tr28, i64 32
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %.not = icmp eq ptr %31, null
  br i1 %.not, label %.loopexit, label %.lr.ph.split

.loopexit:                                        ; preds = %tailrecurse, %2, %.split30, %.split
  ret void
}

declare void @star_attract(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @star_attract_to_mass(ptr noundef, float noundef, float noundef, float noundef) local_unnamed_addr #1

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 = { "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, !7, i64 0}
!6 = !{!"QuadTreeNode", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 40}
!11 = !{!"Cell", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !7, i64 40}
!12 = !{!"float", !8, i64 0}
!13 = !{!11, !12, i64 16}
!14 = !{!11, !12, i64 20}
!15 = !{!11, !12, i64 24}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 24}
!19 = !{!6, !7, i64 32}


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