; LLVM IR from doyubkim/fluid-engine-dev :: src/jet/face_centered_grid2.ll (ZNK3jet17FaceCenteredGrid222divergenceAtCellCenterEmm)

; 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.jet::FaceCenteredGrid2" = type { %"class.jet::VectorGrid2", %"class.jet::Array", %"class.jet::Array", %"class.jet::Vector", %"class.jet::Vector", %"class.jet::LinearArraySampler", %"class.jet::LinearArraySampler", %"class.std::function" }
%"class.jet::VectorGrid2" = type { %"class.jet::VectorField2", %"class.jet::Grid2" }
%"class.jet::VectorField2" = type { %"class.jet::Field2" }
%"class.jet::Field2" = type { ptr }
%"class.jet::Grid2" = type { %"class.jet::Serializable", %"class.jet::Size2", %"class.jet::Vector", %"class.jet::Vector", %"class.jet::BoundingBox" }
%"class.jet::Serializable" = type { ptr }
%"class.jet::Size2" = type { i64, i64 }
%"class.jet::BoundingBox" = type { %"class.jet::Vector", %"class.jet::Vector" }
%"class.jet::Array" = type { %"class.jet::Size2", %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.jet::Vector" = type { double, double }
%"class.jet::LinearArraySampler" = type { %"class.jet::Vector", %"class.jet::Vector", %"class.jet::Vector", %"class.jet::ConstArrayAccessor" }
%"class.jet::ConstArrayAccessor" = type { %"class.jet::Size2", ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }

; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3jet17FaceCenteredGrid222divergenceAtCellCenterEmm(ptr noundef nonnull align 8 dereferenceable(384) %0, i64 noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %15 = getelementptr inbounds %"class.jet::FaceCenteredGrid2", ptr %12, i32 0, i32 1
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %15, i64 noundef %16, i64 noundef %17)
  %19 = load double, ptr %18, align 8, !tbaa !11
  store double %19, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = getelementptr inbounds %"class.jet::FaceCenteredGrid2", ptr %12, i32 0, i32 1
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = add i64 %21, 1
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %20, i64 noundef %22, i64 noundef %23)
  %25 = load double, ptr %24, align 8, !tbaa !11
  store double %25, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %26 = getelementptr inbounds %"class.jet::FaceCenteredGrid2", ptr %12, i32 0, i32 2
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %26, i64 noundef %27, i64 noundef %28)
  %30 = load double, ptr %29, align 8, !tbaa !11
  store double %30, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %31 = getelementptr inbounds %"class.jet::FaceCenteredGrid2", ptr %12, i32 0, i32 2
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = add i64 %33, 1
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %31, i64 noundef %32, i64 noundef %34)
  %36 = load double, ptr %35, align 8, !tbaa !11
  store double %36, ptr %11, align 8, !tbaa !11
  %37 = load double, ptr %9, align 8, !tbaa !11
  %38 = load double, ptr %8, align 8, !tbaa !11
  %39 = fsub double %37, %38
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.jet::Vector", ptr %40, i32 0, i32 0
  %42 = load double, ptr %41, align 8, !tbaa !13
  %43 = fdiv double %39, %42
  %44 = load double, ptr %11, align 8, !tbaa !11
  %45 = load double, ptr %10, align 8, !tbaa !11
  %46 = fsub double %44, %45
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.jet::Vector", ptr %47, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !15
  %50 = fdiv double %46, %49
  %51 = fadd double %43, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %51
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { "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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN3jet6VectorIdLm2EEE", !12, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 8}


; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3jet17FaceCenteredGrid222divergenceAtCellCenterEmm(ptr noundef nonnull align 8 dereferenceable(384) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %4)
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %6, i64 noundef %1, i64 noundef %2)
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = add i64 %1, 1
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %6, i64 noundef %9, i64 noundef %2)
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 136
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %12, i64 noundef %1, i64 noundef %2)
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = add i64 %2, 1
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %12, i64 noundef %1, i64 noundef %15)
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = insertelement <2 x double> poison, double %11, i64 0
  %19 = insertelement <2 x double> %18, double %17, i64 1
  %20 = insertelement <2 x double> poison, double %8, i64 0
  %21 = insertelement <2 x double> %20, double %14, i64 1
  %22 = fsub <2 x double> %19, %21
  %23 = load <2 x double>, ptr %5, align 8, !tbaa !5
  %24 = fdiv <2 x double> %22, %23
  %shift = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %25 = fadd <2 x double> %24, %shift
  %26 = extractelement <2 x double> %25, i64 0
  ret double %26
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #2

attributes #0 = { 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 #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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass,VectorCombinePass