; LLVM IR from doyubkim/fluid-engine-dev :: src/jet (collocated_vector_grid2)

; 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::Size2" = type { i64, i64 }
%"class.jet::CollocatedVectorGrid2" = type { %"class.jet::VectorGrid2", %"class.jet::Array", %"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::Vector" = type { double, double }
%"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<jet::Vector<double, 2>, std::allocator<jet::Vector<double, 2>>>::_Vector_impl" }
%"struct.std::_Vector_base<jet::Vector<double, 2>, std::allocator<jet::Vector<double, 2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<jet::Vector<double, 2>, std::allocator<jet::Vector<double, 2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<jet::Vector<double, 2>, std::allocator<jet::Vector<double, 2>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"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(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3jet21CollocatedVectorGrid221divergenceAtDataPointEmm(ptr noundef nonnull align 8 dereferenceable(240) %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 %"class.jet::Size2", align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = 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
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %14 = getelementptr inbounds %"class.jet::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  call void @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr dead_on_unwind writable sret(%"class.jet::Size2") align 8 %7, ptr noundef nonnull align 8 dereferenceable(40) %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %15 = getelementptr inbounds i8, ptr %13, i64 8
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = getelementptr inbounds %"class.jet::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %3
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = sub i64 %21, 1
  br label %25

23:                                               ; preds = %3
  %24 = load i64, ptr %5, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %23, %20
  %26 = phi i64 [ %22, %20 ], [ %24, %23 ]
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %17, i64 noundef %26, i64 noundef %27)
  %29 = getelementptr inbounds %"class.jet::Vector", ptr %28, i32 0, i32 0
  %30 = load double, ptr %29, align 8, !tbaa !11
  store double %30, ptr %9, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %31 = getelementptr inbounds %"class.jet::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = add i64 %32, 1
  %34 = getelementptr inbounds %"class.jet::Size2", ptr %7, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = icmp ult i64 %33, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %25
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = add i64 %38, 1
  br label %42

40:                                               ; preds = %25
  %41 = load i64, ptr %5, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %40, %37
  %43 = phi i64 [ %39, %37 ], [ %41, %40 ]
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %31, i64 noundef %43, i64 noundef %44)
  %46 = getelementptr inbounds %"class.jet::Vector", ptr %45, i32 0, i32 0
  %47 = load double, ptr %46, align 8, !tbaa !11
  store double %47, ptr %10, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %48 = getelementptr inbounds %"class.jet::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %49 = load i64, ptr %5, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = icmp ugt i64 %50, 0
  br i1 %51, label %52, label %55

52:                                               ; preds = %42
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = sub i64 %53, 1
  br label %57

55:                                               ; preds = %42
  %56 = load i64, ptr %6, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %55, %52
  %58 = phi i64 [ %54, %52 ], [ %56, %55 ]
  %59 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %48, i64 noundef %49, i64 noundef %58)
  %60 = getelementptr inbounds %"class.jet::Vector", ptr %59, i32 0, i32 1
  %61 = load double, ptr %60, align 8, !tbaa !17
  store double %61, ptr %11, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %62 = getelementptr inbounds %"class.jet::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %63 = load i64, ptr %5, align 8, !tbaa !9
  %64 = load i64, ptr %6, align 8, !tbaa !9
  %65 = add i64 %64, 1
  %66 = getelementptr inbounds %"class.jet::Size2", ptr %7, i32 0, i32 1
  %67 = load i64, ptr %66, align 8, !tbaa !18
  %68 = icmp ult i64 %65, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %57
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = add i64 %70, 1
  br label %74

72:                                               ; preds = %57
  %73 = load i64, ptr %6, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %72, %69
  %75 = phi i64 [ %71, %69 ], [ %73, %72 ]
  %76 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %62, i64 noundef %63, i64 noundef %75)
  %77 = getelementptr inbounds %"class.jet::Vector", ptr %76, i32 0, i32 1
  %78 = load double, ptr %77, align 8, !tbaa !17
  store double %78, ptr %12, align 8, !tbaa !14
  %79 = load double, ptr %10, align 8, !tbaa !14
  %80 = load double, ptr %9, align 8, !tbaa !14
  %81 = fsub double %79, %80
  %82 = fmul double 5.000000e-01, %81
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %"class.jet::Vector", ptr %83, i32 0, i32 0
  %85 = load double, ptr %84, align 8, !tbaa !11
  %86 = fdiv double %82, %85
  %87 = load double, ptr %12, align 8, !tbaa !14
  %88 = load double, ptr %11, align 8, !tbaa !14
  %89 = fsub double %87, %88
  %90 = fmul double 5.000000e-01, %89
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %"class.jet::Vector", ptr %91, i32 0, i32 1
  %93 = load double, ptr %92, align 8, !tbaa !17
  %94 = fdiv double %90, %93
  %95 = fadd double %86, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  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 16, ptr %7) #4
  ret double %95
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr dead_on_unwind noalias writable sret(%"class.jet::Size2") align 8, ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

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, !13, i64 0}
!12 = !{!"_ZTSN3jet6VectorIdLm2EEE", !13, i64 0, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN3jet5Size2E", !10, i64 0, !10, i64 8}
!17 = !{!12, !13, i64 8}
!18 = !{!16, !10, 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"

%"class.jet::Size2" = type { i64, i64 }

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

; Function Attrs: mustprogress 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(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3jet21CollocatedVectorGrid221divergenceAtDataPointEmm(ptr noundef nonnull align 8 dereferenceable(240) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %"class.jet::Size2", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  call void @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr dead_on_unwind nonnull writable sret(%"class.jet::Size2") align 8 %4, ptr noundef nonnull align 8 dereferenceable(40) %5)
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %6)
  %8 = call i64 @llvm.usub.sat.i64(i64 %1, i64 1)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %5, i64 noundef %8, i64 noundef %2)
  %10 = load <2 x double>, ptr %9, align 8
  %11 = add i64 %1, 1
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = icmp ult i64 %11, %12
  %14 = select i1 %13, i64 %11, i64 %1
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %5, i64 noundef %14, i64 noundef %2)
  %16 = load <2 x double>, ptr %15, align 8
  %17 = call i64 @llvm.usub.sat.i64(i64 %2, i64 1)
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %5, i64 noundef %1, i64 noundef %17)
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load double, ptr %19, align 8, !tbaa !10
  %21 = add i64 %2, 1
  %22 = getelementptr inbounds i8, ptr %4, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = icmp ult i64 %21, %23
  %25 = select i1 %24, i64 %21, i64 %2
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %5, i64 noundef %1, i64 noundef %25)
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load double, ptr %27, align 8, !tbaa !10
  %29 = insertelement <2 x double> %16, double %28, i64 1
  %30 = insertelement <2 x double> %10, double %20, i64 1
  %31 = fsub <2 x double> %29, %30
  %32 = fmul <2 x double> %31, <double 5.000000e-01, double 5.000000e-01>
  %33 = load <2 x double>, ptr %7, align 8, !tbaa !14
  %34 = fdiv <2 x double> %32, %33
  %shift = shufflevector <2 x double> %34, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %35 = fadd <2 x double> %34, %shift
  %36 = extractelement <2 x double> %35, i64 0
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  ret double %36
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr dead_on_unwind noalias writable sret(%"class.jet::Size2") align 8, ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #4

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"_ZTSN3jet5Size2E", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 8}
!11 = !{!"_ZTSN3jet6VectorIdLm2EEE", !12, i64 0, !12, i64 8}
!12 = !{!"double", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!12, !12, i64 0}


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