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

; 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.ScalarField = type { i32, i32, i32, double, double, double, double, double, double, double, double, i8, [7 x i8], %class.Array3d, %class.Array3d.0, %class.Array3d, %class.Array3d.0, i8, %"class.vmath::vec3" }
%class.Array3d = type <{ i32, i32, i32, [4 x i8], ptr, i8, [3 x i8], float, i32, [4 x i8] }>
%class.Array3d.0 = type { i32, i32, i32, ptr, i8, i8, i32 }
%"class.vmath::vec3" = type { float, float, float }

; 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 @_ZN11ScalarField16applyWeightFieldEv(ptr noundef nonnull align 8 dereferenceable(248) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  %10 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 17
  %11 = load i8, ptr %10, align 8, !tbaa !9, !range !18, !noundef !19
  %12 = trunc i8 %11 to i1
  br i1 %12, label %14, label %13

13:                                               ; preds = %1
  br label %69

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !20
  br label %15

15:                                               ; preds = %66, %14
  %16 = load i32, ptr %3, align 4, !tbaa !20
  %17 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !21
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %69

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !20
  br label %22

22:                                               ; preds = %62, %21
  %23 = load i32, ptr %5, align 4, !tbaa !20
  %24 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !22
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !20
  br label %29

29:                                               ; preds = %58, %28
  %30 = load i32, ptr %6, align 4, !tbaa !20
  %31 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !23
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %36 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 15
  %37 = load i32, ptr %6, align 4, !tbaa !20
  %38 = load i32, ptr %5, align 4, !tbaa !20
  %39 = load i32, ptr %3, align 4, !tbaa !20
  %40 = call noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36) %36, i32 noundef %37, i32 noundef %38, i32 noundef %39)
  store float %40, ptr %7, align 4, !tbaa !24
  %41 = load float, ptr %7, align 4, !tbaa !24
  %42 = fpext float %41 to double
  %43 = fcmp ogt double %42, 0.000000e+00
  br i1 %43, label %44, label %57

44:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %45 = getelementptr inbounds %class.ScalarField, ptr %9, i32 0, i32 13
  %46 = load i32, ptr %6, align 4, !tbaa !20
  %47 = load i32, ptr %5, align 4, !tbaa !20
  %48 = load i32, ptr %3, align 4, !tbaa !20
  %49 = call noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36) %45, i32 noundef %46, i32 noundef %47, i32 noundef %48)
  %50 = load float, ptr %7, align 4, !tbaa !24
  %51 = fdiv float %49, %50
  store float %51, ptr %8, align 4, !tbaa !24
  %52 = load i32, ptr %6, align 4, !tbaa !20
  %53 = load i32, ptr %5, align 4, !tbaa !20
  %54 = load i32, ptr %3, align 4, !tbaa !20
  %55 = load float, ptr %8, align 4, !tbaa !24
  %56 = fpext float %55 to double
  call void @_ZN11ScalarField19setScalarFieldValueEiiid(ptr noundef nonnull align 8 dereferenceable(248) %9, i32 noundef %52, i32 noundef %53, i32 noundef %54, double noundef %56)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %57

57:                                               ; preds = %44, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %6, align 4, !tbaa !20
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %6, align 4, !tbaa !20
  br label %29, !llvm.loop !25

61:                                               ; preds = %34
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %5, align 4, !tbaa !20
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !20
  br label %22, !llvm.loop !27

65:                                               ; preds = %27
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %3, align 4, !tbaa !20
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %3, align 4, !tbaa !20
  br label %15, !llvm.loop !28

69:                                               ; preds = %20, %13
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36), i32 noundef, i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11ScalarField19setScalarFieldValueEiiid(ptr noundef nonnull align 8 dereferenceable(248), 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, !13, i64 232}
!10 = !{!"_ZTS11ScalarField", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !13, i64 80, !14, i64 88, !16, i64 128, !14, i64 160, !16, i64 200, !13, i64 232, !17, i64 236}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS7Array3dIfE", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !13, i64 24, !15, i64 28, !11, i64 32}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTS7Array3dIbE", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !13, i64 24, !13, i64 25, !11, i64 28}
!17 = !{!"_ZTSN5vmath4vec3E", !15, i64 0, !15, i64 4, !15, i64 8}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!11, !11, i64 0}
!21 = !{!10, !11, i64 8}
!22 = !{!10, !11, i64 4}
!23 = !{!10, !11, i64 0}
!24 = !{!15, !15, 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 @_ZN11ScalarField16applyWeightFieldEv(ptr noundef nonnull align 8 dereferenceable(248) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 232
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !17, !noundef !18
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %.preheader21, label %.loopexit

.preheader21:                                     ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !19
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader20.lr.ph, label %.loopexit

.preheader20.lr.ph:                               ; preds = %.preheader21
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = getelementptr inbounds i8, ptr %0, i64 160
  %10 = getelementptr inbounds i8, ptr %0, i64 88
  %11 = load i32, ptr %8, align 4, !tbaa !20
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader20, label %.loopexit

.preheader20:                                     ; preds = %.preheader20.lr.ph, %._crit_edge24
  %13 = phi i32 [ %22, %._crit_edge24 ], [ %6, %.preheader20.lr.ph ]
  %14 = phi i32 [ %23, %._crit_edge24 ], [ %11, %.preheader20.lr.ph ]
  %15 = phi i32 [ %24, %._crit_edge24 ], [ %11, %.preheader20.lr.ph ]
  %.025 = phi i32 [ %25, %._crit_edge24 ], [ 0, %.preheader20.lr.ph ]
  %16 = icmp sgt i32 %15, 0
  %17 = load i32, ptr %0, align 8
  %18 = icmp sgt i32 %17, 0
  %or.cond = select i1 %16, i1 %18, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge24

.preheader:                                       ; preds = %.preheader20, %._crit_edge
  %19 = phi i32 [ %27, %._crit_edge ], [ %14, %.preheader20 ]
  %20 = phi i32 [ %28, %._crit_edge ], [ %17, %.preheader20 ]
  %.01923 = phi i32 [ %29, %._crit_edge ], [ 0, %.preheader20 ]
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

._crit_edge24.loopexit:                           ; preds = %._crit_edge
  %.pre29 = load i32, ptr %5, align 8, !tbaa !19
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit, %.preheader20
  %22 = phi i32 [ %.pre29, %._crit_edge24.loopexit ], [ %13, %.preheader20 ]
  %23 = phi i32 [ %27, %._crit_edge24.loopexit ], [ %14, %.preheader20 ]
  %24 = phi i32 [ %27, %._crit_edge24.loopexit ], [ %15, %.preheader20 ]
  %25 = add nuw nsw i32 %.025, 1
  %26 = icmp slt i32 %25, %22
  br i1 %26, label %.preheader20, label %.loopexit, !llvm.loop !21

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %27 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %19, %.preheader ]
  %28 = phi i32 [ %39, %._crit_edge.loopexit ], [ %20, %.preheader ]
  %29 = add nuw nsw i32 %.01923, 1
  %30 = icmp slt i32 %29, %27
  br i1 %30, label %.preheader, label %._crit_edge24.loopexit, !llvm.loop !24

.lr.ph:                                           ; preds = %.preheader, %37
  %.01822 = phi i32 [ %38, %37 ], [ 0, %.preheader ]
  %31 = tail call noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36) %9, i32 noundef %.01822, i32 noundef %.01923, i32 noundef %.025)
  %32 = fcmp ogt float %31, 0.000000e+00
  br i1 %32, label %33, label %37

33:                                               ; preds = %.lr.ph
  %34 = tail call noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36) %10, i32 noundef %.01822, i32 noundef %.01923, i32 noundef %.025)
  %35 = fdiv float %34, %31
  %36 = fpext float %35 to double
  tail call void @_ZN11ScalarField19setScalarFieldValueEiiid(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %.01822, i32 noundef %.01923, i32 noundef %.025, double noundef %36)
  br label %37

37:                                               ; preds = %33, %.lr.ph
  %38 = add nuw nsw i32 %.01822, 1
  %39 = load i32, ptr %0, align 8, !tbaa !25
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !26

.loopexit:                                        ; preds = %._crit_edge24, %.preheader20.lr.ph, %.preheader21, %1
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN7Array3dIfEclEiii(ptr noundef nonnull align 8 dereferenceable(36), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11ScalarField19setScalarFieldValueEiiid(ptr noundef nonnull align 8 dereferenceable(248), 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, !11, i64 232}
!6 = !{!"_ZTS11ScalarField", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !11, i64 80, !12, i64 88, !15, i64 128, !12, i64 160, !15, i64 200, !11, i64 232, !16, i64 236}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTS7Array3dIfE", !7, i64 0, !7, i64 4, !7, i64 8, !13, i64 16, !11, i64 24, !14, i64 28, !7, i64 32}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!"_ZTS7Array3dIbE", !7, i64 0, !7, i64 4, !7, i64 8, !13, i64 16, !11, i64 24, !11, i64 25, !7, i64 28}
!16 = !{!"_ZTSN5vmath4vec3E", !14, i64 0, !14, i64 4, !14, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !7, i64 8}
!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass