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

; 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.MACVelocityField = type <{ float, i32, i32, i32, double, %class.Array3d, %class.Array3d, %class.Array3d, i32, [4 x i8] }>
%class.Array3d = type <{ i32, i32, i32, [4 x i8], ptr, i8, [3 x i8], float, i32, [4 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
declare dso_local noundef float @_ZN16MACVelocityField44evaluateVelocityMagnitudeSquaredAtCellCenterEiii(ptr noundef nonnull align 8 dereferenceable(148), i32 noundef, i32 noundef, i32 noundef) #1 align 2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN16MACVelocityField32evaluateMaximumVelocityMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(148) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %48, %1
  %12 = load i32, ptr %4, align 4, !tbaa !11
  %13 = getelementptr inbounds %class.MACVelocityField, ptr %10, i32 0, i32 3
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %51

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

18:                                               ; preds = %44, %17
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = getelementptr inbounds %class.MACVelocityField, ptr %10, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !18
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

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

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

25:                                               ; preds = %40, %24
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = getelementptr inbounds %class.MACVelocityField, ptr %10, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %43

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load i32, ptr %7, align 4, !tbaa !11
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = load i32, ptr %4, align 4, !tbaa !11
  %35 = call noundef float @_ZN16MACVelocityField44evaluateVelocityMagnitudeSquaredAtCellCenterEiii(ptr noundef nonnull align 8 dereferenceable(148) %10, i32 noundef %32, i32 noundef %33, i32 noundef %34)
  %36 = fpext float %35 to double
  store double %36, ptr %8, align 8, !tbaa !9
  %37 = load double, ptr %3, align 8, !tbaa !9
  %38 = load double, ptr %8, align 8, !tbaa !9
  %39 = call double @llvm.maxnum.f64(double %37, double %38)
  store double %39, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %40

40:                                               ; preds = %31
  %41 = load i32, ptr %7, align 4, !tbaa !11
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %7, align 4, !tbaa !11
  br label %25, !llvm.loop !20

43:                                               ; preds = %30
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !11
  br label %18, !llvm.loop !22

47:                                               ; preds = %23
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %4, align 4, !tbaa !11
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !11
  br label %11, !llvm.loop !23

51:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %52 = load double, ptr %3, align 8, !tbaa !9
  store double %52, ptr %9, align 8, !tbaa !9
  %53 = load double, ptr %3, align 8, !tbaa !9
  %54 = fcmp ogt double %53, 0.000000e+00
  br i1 %54, label %55, label %58

55:                                               ; preds = %51
  %56 = load double, ptr %3, align 8, !tbaa !9
  %57 = call double @sqrt(double noundef %56) #4
  store double %57, ptr %9, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %55, %51
  %59 = load double, ptr %9, align 8, !tbaa !9
  %60 = fptrunc double %59 to float
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret float %60
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maxnum.f64(double, double) #3

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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ 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 12}
!14 = !{!"_ZTS16MACVelocityField", !15, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !10, i64 16, !16, i64 24, !16, i64 64, !16, i64 104, !12, i64 144}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTS7Array3dIfE", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !17, i64 24, !15, i64 28, !12, i64 32}
!17 = !{!"bool", !7, i64 0}
!18 = !{!14, !12, i64 8}
!19 = !{!14, !12, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = distinct !{!23, !21}


; 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
declare dso_local noundef float @_ZN16MACVelocityField44evaluateVelocityMagnitudeSquaredAtCellCenterEiii(ptr noundef nonnull align 8 dereferenceable(148), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN16MACVelocityField32evaluateMaximumVelocityMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(148) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader19.lr.ph, label %._crit_edge29.thread

.preheader19.lr.ph:                               ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %5, align 8, !tbaa !15
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader19, label %._crit_edge29.thread

.preheader19:                                     ; preds = %.preheader19.lr.ph, %._crit_edge24
  %9 = phi i32 [ %19, %._crit_edge24 ], [ %3, %.preheader19.lr.ph ]
  %10 = phi i32 [ %20, %._crit_edge24 ], [ %7, %.preheader19.lr.ph ]
  %11 = phi i32 [ %21, %._crit_edge24 ], [ %7, %.preheader19.lr.ph ]
  %.01528 = phi double [ %.1.lcssa, %._crit_edge24 ], [ 0.000000e+00, %.preheader19.lr.ph ]
  %.01826 = phi i32 [ %22, %._crit_edge24 ], [ 0, %.preheader19.lr.ph ]
  %12 = icmp sgt i32 %11, 0
  %13 = load i32, ptr %6, align 4
  %14 = icmp sgt i32 %13, 0
  %or.cond = select i1 %12, i1 %14, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge24

._crit_edge29:                                    ; preds = %._crit_edge24
  %15 = fcmp ogt double %.1.lcssa, 0.000000e+00
  br i1 %15, label %34, label %._crit_edge29.thread

.preheader:                                       ; preds = %.preheader19, %._crit_edge
  %16 = phi i32 [ %24, %._crit_edge ], [ %10, %.preheader19 ]
  %17 = phi i32 [ %25, %._crit_edge ], [ %13, %.preheader19 ]
  %.123 = phi double [ %.2.lcssa, %._crit_edge ], [ %.01528, %.preheader19 ]
  %.01722 = phi i32 [ %26, %._crit_edge ], [ 0, %.preheader19 ]
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

._crit_edge24.loopexit:                           ; preds = %._crit_edge
  %.pre34 = load i32, ptr %2, align 4, !tbaa !5
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit, %.preheader19
  %19 = phi i32 [ %9, %.preheader19 ], [ %.pre34, %._crit_edge24.loopexit ]
  %20 = phi i32 [ %10, %.preheader19 ], [ %24, %._crit_edge24.loopexit ]
  %21 = phi i32 [ %11, %.preheader19 ], [ %24, %._crit_edge24.loopexit ]
  %.1.lcssa = phi double [ %.01528, %.preheader19 ], [ %.2.lcssa, %._crit_edge24.loopexit ]
  %22 = add nuw nsw i32 %.01826, 1
  %23 = icmp slt i32 %22, %19
  br i1 %23, label %.preheader19, label %._crit_edge29, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %5, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %24 = phi i32 [ %16, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %25 = phi i32 [ %17, %.preheader ], [ %32, %._crit_edge.loopexit ]
  %.2.lcssa = phi double [ %.123, %.preheader ], [ %30, %._crit_edge.loopexit ]
  %26 = add nuw nsw i32 %.01722, 1
  %27 = icmp slt i32 %26, %24
  br i1 %27, label %.preheader, label %._crit_edge24.loopexit, !llvm.loop !19

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.221 = phi double [ %30, %.lr.ph ], [ %.123, %.preheader ]
  %.01620 = phi i32 [ %31, %.lr.ph ], [ 0, %.preheader ]
  %28 = tail call noundef float @_ZN16MACVelocityField44evaluateVelocityMagnitudeSquaredAtCellCenterEiii(ptr noundef nonnull align 8 dereferenceable(148) %0, i32 noundef %.01620, i32 noundef %.01722, i32 noundef %.01826)
  %29 = fpext float %28 to double
  %30 = tail call double @llvm.maxnum.f64(double %.221, double %29)
  %31 = add nuw nsw i32 %.01620, 1
  %32 = load i32, ptr %6, align 4, !tbaa !20
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

34:                                               ; preds = %._crit_edge29
  %35 = tail call double @sqrt(double noundef %.1.lcssa) #3
  br label %._crit_edge29.thread

._crit_edge29.thread:                             ; preds = %.preheader19.lr.ph, %1, %34, %._crit_edge29
  %.0 = phi double [ %35, %34 ], [ %.1.lcssa, %._crit_edge29 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %.preheader19.lr.ph ]
  %36 = fptrunc double %.0 to float
  ret float %36
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maxnum.f64(double, double) #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" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 12}
!6 = !{!"_ZTS16MACVelocityField", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !11, i64 16, !12, i64 24, !12, i64 64, !12, i64 104, !10, i64 144}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_ZTS7Array3dIfE", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !14, i64 24, !7, i64 28, !10, i64 32}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !10, i64 8}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.unswitch.partial.disable"}
!19 = distinct !{!19, !17, !18}
!20 = !{!6, !10, i64 4}
!21 = distinct !{!21, !17}


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