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

; 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.Brick = type <{ float, i8, [3 x i8] }>
%struct.GridIndex = type { i32, i32, i32 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN7Array3dI5BrickEclE9GridIndex(ptr noundef nonnull align 8 dereferenceable(40), i64, i32) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN14FluidBrickGrid23_isBrickMassInBrickGridER15GridIndexVectorR7Array3dI5BrickE(ptr noundef nonnull align 8 dereferenceable(353) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(40) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.Brick, align 4
  %11 = alloca %struct.GridIndex, align 4
  %12 = alloca { i64, i32 }, align 8
  %13 = alloca { i64, i32 }, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %38, %3
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %18)
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  store i32 2, ptr %9, align 4
  br label %41

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = call { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40) %24, i32 noundef %25)
  store { i64, i32 } %26, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %12, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %11, i64 12, i1 false)
  %27 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %28 = load i64, ptr %27, align 4
  %29 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %30 = load i32, ptr %29, align 4
  %31 = call i64 @_ZN7Array3dI5BrickEclE9GridIndex(ptr noundef nonnull align 8 dereferenceable(40) %23, i64 %28, i32 %30)
  %32 = trunc i64 %31 to i40
  store i40 %32, ptr %10, align 4
  %33 = getelementptr inbounds %struct.Brick, ptr %10, i32 0, i32 1
  %34 = load i8, ptr %33, align 4, !tbaa !13, !range !16, !noundef !17
  %35 = trunc i8 %34 to i1
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br i1 %35, label %36, label %37

36:                                               ; preds = %22
  store i8 1, ptr %7, align 1, !tbaa !9
  store i32 2, ptr %9, align 4
  br label %41

37:                                               ; preds = %22
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = add i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !11
  br label %15, !llvm.loop !18

41:                                               ; preds = %36, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %42

42:                                               ; preds = %41
  %43 = load i8, ptr %7, align 1, !tbaa !9, !range !16, !noundef !17
  %44 = trunc i8 %43 to i1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  ret i1 %44
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

declare { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #4

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint mustprogress 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 #4 = { "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 #5 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 4}
!14 = !{!"_ZTS5Brick", !15, i64 0, !10, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 i64 @_ZN7Array3dI5BrickEclE9GridIndex(ptr noundef nonnull align 8 dereferenceable(40), i64, i32) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN14FluidBrickGrid23_isBrickMassInBrickGridER15GridIndexVectorR7Array3dI5BrickE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(353) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(40) %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %.not17 = icmp eq i64 %4, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %6 = add i32 %.01214, 1
  %7 = zext i32 %6 to i64
  %8 = tail call noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %9 = icmp ugt i64 %8, %7
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !5

.lr.ph:                                           ; preds = %3, %5
  %.01214 = phi i32 [ %6, %5 ], [ 0, %3 ]
  %10 = tail call { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.01214)
  %.fca.0.extract = extractvalue { i64, i32 } %10, 0
  %.fca.1.extract = extractvalue { i64, i32 } %10, 1
  %11 = tail call i64 @_ZN7Array3dI5BrickEclE9GridIndex(ptr noundef nonnull align 8 dereferenceable(40) %2, i64 %.fca.0.extract, i32 %.fca.1.extract)
  %12 = and i64 %11, 4294967296
  %.not.not = icmp ne i64 %12, 0
  br i1 %.not.not, label %._crit_edge, label %5

._crit_edge:                                      ; preds = %5, %.lr.ph, %3
  %.lcssa = phi i1 [ false, %3 ], [ %.not.not, %.lr.ph ], [ %.not.not, %5 ]
  ret i1 %.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

declare { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #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 = { inlinehint mustprogress 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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