; LLVM IR from SourangshuGhosh/Fluid-Simulation-for-Computer-Graphics :: src/fluidbrickgrid.ll (ZN14FluidBrickGrid16_updateDensitiesEd)

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

%class.FluidBrickGrid = type <{ i32, i32, i32, [4 x i8], double, %class.AABB, %class.Array3d, %class.Array3d.0, [3 x %class.Array3d.0], i32, [4 x i8], %class.Array3d.0, i8, [3 x i8], i32, i32, float, float, float, i32, i32, i8, [7 x i8] }>
%class.AABB = type { %"class.vmath::vec3", double, double, double }
%"class.vmath::vec3" = type { float, float, float }
%class.Array3d = type <{ i32, i32, i32, [4 x i8], ptr, i8, [3 x i8], %"struct.FluidBrickGrid::DensityNode", i32, [4 x i8] }>
%"struct.FluidBrickGrid::DensityNode" = type { float, float, float }
%class.Array3d.0 = type { i32, i32, i32, ptr, i8, [3 x i8], %struct.Brick, i32 }
%struct.Brick = type <{ float, i8, [3 x i8] }>

; 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: mustprogress uwtable
define dso_local void @_ZN14FluidBrickGrid16_updateDensitiesEd(ptr noundef nonnull align 8 dereferenceable(353) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %43, %2
  %11 = load i32, ptr %5, align 4, !tbaa !11
  %12 = getelementptr inbounds %class.FluidBrickGrid, ptr %9, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %39, %16
  %18 = load i32, ptr %7, align 4, !tbaa !11
  %19 = getelementptr inbounds %class.FluidBrickGrid, ptr %9, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !23
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %35, %23
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = getelementptr inbounds %class.FluidBrickGrid, ptr %9, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !24
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %24
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = load i32, ptr %7, align 4, !tbaa !11
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZN14FluidBrickGrid14_updateDensityEiiid(ptr noundef nonnull align 8 dereferenceable(353) %9, i32 noundef %31, i32 noundef %32, i32 noundef %33, double noundef %34)
  br label %35

35:                                               ; preds = %30
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %8, align 4, !tbaa !11
  br label %24, !llvm.loop !25

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %7, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !11
  br label %17, !llvm.loop !27

42:                                               ; preds = %22
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %5, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %5, align 4, !tbaa !11
  br label %10, !llvm.loop !28

46:                                               ; preds = %15
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14FluidBrickGrid14_updateDensityEiiid(ptr noundef nonnull align 8 dereferenceable(353), i32 noundef, i32 noundef, i32 noundef, double noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTS14FluidBrickGrid", !12, i64 0, !12, i64 4, !12, i64 8, !10, i64 16, !15, i64 24, !18, i64 64, !21, i64 112, !7, i64 152, !12, i64 272, !21, i64 280, !19, i64 320, !12, i64 324, !12, i64 328, !17, i64 332, !17, i64 336, !17, i64 340, !12, i64 344, !12, i64 348, !19, i64 352}
!15 = !{!"_ZTS4AABB", !16, i64 0, !10, i64 16, !10, i64 24, !10, i64 32}
!16 = !{!"_ZTSN5vmath4vec3E", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !7, i64 0}
!18 = !{!"_ZTS7Array3dIN14FluidBrickGrid11DensityNodeEE", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !19, i64 24, !20, i64 28, !12, i64 40}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSN14FluidBrickGrid11DensityNodeE", !17, i64 0, !17, i64 4, !17, i64 8}
!21 = !{!"_ZTS7Array3dI5BrickE", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !19, i64 24, !22, i64 28, !12, i64 36}
!22 = !{!"_ZTS5Brick", !17, i64 0, !19, i64 4}
!23 = !{!14, !12, i64 4}
!24 = !{!14, !12, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}
!28 = distinct !{!28, !26}


; 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: mustprogress uwtable
define dso_local void @_ZN14FluidBrickGrid16_updateDensitiesEd(ptr noundef nonnull align 8 dereferenceable(353) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader12.lr.ph, label %._crit_edge18

.preheader12.lr.ph:                               ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !20
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader12, label %._crit_edge18

.preheader12:                                     ; preds = %.preheader12.lr.ph, %._crit_edge15
  %9 = phi i32 [ %18, %._crit_edge15 ], [ %4, %.preheader12.lr.ph ]
  %10 = phi i32 [ %19, %._crit_edge15 ], [ %7, %.preheader12.lr.ph ]
  %11 = phi i32 [ %20, %._crit_edge15 ], [ %7, %.preheader12.lr.ph ]
  %.01116 = phi i32 [ %21, %._crit_edge15 ], [ 0, %.preheader12.lr.ph ]
  %12 = icmp sgt i32 %11, 0
  %13 = load i32, ptr %0, align 8
  %14 = icmp sgt i32 %13, 0
  %or.cond = select i1 %12, i1 %14, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge15

._crit_edge18:                                    ; preds = %._crit_edge15, %.preheader12.lr.ph, %2
  ret void

.preheader:                                       ; preds = %.preheader12, %._crit_edge
  %15 = phi i32 [ %23, %._crit_edge ], [ %10, %.preheader12 ]
  %16 = phi i32 [ %24, %._crit_edge ], [ %13, %.preheader12 ]
  %.01014 = phi i32 [ %25, %._crit_edge ], [ 0, %.preheader12 ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge

._crit_edge15.loopexit:                           ; preds = %._crit_edge
  %.pre21 = load i32, ptr %3, align 8, !tbaa !5
  br label %._crit_edge15

._crit_edge15:                                    ; preds = %._crit_edge15.loopexit, %.preheader12
  %18 = phi i32 [ %.pre21, %._crit_edge15.loopexit ], [ %9, %.preheader12 ]
  %19 = phi i32 [ %23, %._crit_edge15.loopexit ], [ %10, %.preheader12 ]
  %20 = phi i32 [ %23, %._crit_edge15.loopexit ], [ %11, %.preheader12 ]
  %21 = add nuw nsw i32 %.01116, 1
  %22 = icmp slt i32 %21, %18
  br i1 %22, label %.preheader12, label %._crit_edge18, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %6, align 4, !tbaa !20
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %23 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %15, %.preheader ]
  %24 = phi i32 [ %28, %._crit_edge.loopexit ], [ %16, %.preheader ]
  %25 = add nuw nsw i32 %.01014, 1
  %26 = icmp slt i32 %25, %23
  br i1 %26, label %.preheader, label %._crit_edge15.loopexit, !llvm.loop !24

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.013 = phi i32 [ %27, %.lr.ph ], [ 0, %.preheader ]
  tail call void @_ZN14FluidBrickGrid14_updateDensityEiiid(ptr noundef nonnull align 8 dereferenceable(353) %0, i32 noundef %.013, i32 noundef %.01014, i32 noundef %.01116, double noundef %1)
  %27 = add nuw nsw i32 %.013, 1
  %28 = load i32, ptr %0, align 8, !tbaa !25
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !26
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14FluidBrickGrid14_updateDensityEiiid(ptr noundef nonnull align 8 dereferenceable(353), i32 noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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" }

!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 8}
!6 = !{!"_ZTS14FluidBrickGrid", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24, !14, i64 64, !18, i64 112, !8, i64 152, !7, i64 272, !18, i64 280, !16, i64 320, !7, i64 324, !7, i64 328, !13, i64 332, !13, i64 336, !13, i64 340, !7, i64 344, !7, i64 348, !16, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"_ZTS4AABB", !12, i64 0, !10, i64 16, !10, i64 24, !10, i64 32}
!12 = !{!"_ZTSN5vmath4vec3E", !13, i64 0, !13, i64 4, !13, i64 8}
!13 = !{!"float", !8, i64 0}
!14 = !{!"_ZTS7Array3dIN14FluidBrickGrid11DensityNodeEE", !7, i64 0, !7, i64 4, !7, i64 8, !15, i64 16, !16, i64 24, !17, i64 28, !7, i64 40}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"bool", !8, i64 0}
!17 = !{!"_ZTSN14FluidBrickGrid11DensityNodeE", !13, i64 0, !13, i64 4, !13, i64 8}
!18 = !{!"_ZTS7Array3dI5BrickE", !7, i64 0, !7, i64 4, !7, i64 8, !15, i64 16, !16, i64 24, !19, i64 28, !7, i64 36}
!19 = !{!"_ZTS5Brick", !13, i64 0, !16, i64 4}
!20 = !{!6, !7, i64 4}
!21 = distinct !{!21, !22, !23}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.unswitch.partial.disable"}
!24 = distinct !{!24, !22, !23}
!25 = !{!6, !7, i64 0}
!26 = distinct !{!26, !22}


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