; LLVM IR from yangfengzzz/Arche-webgpu :: vox.geometry (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"

%"struct.vox::Size2" = type { i64, i64 }
%"class.vox::CollocatedVectorGrid2" = type { %"class.vox::VectorGrid2", %"class.vox::Array", %"class.vox::LinearArraySampler", %"class.std::function" }
%"class.vox::VectorGrid2" = type { %"class.vox::VectorField2", %"class.vox::Grid2" }
%"class.vox::VectorField2" = type { %"class.vox::Field2" }
%"class.vox::Field2" = type { ptr }
%"class.vox::Grid2" = type { ptr, %"struct.vox::Size2", %"struct.vox::Vector", %"struct.vox::Point", %"struct.vox::BoundingBox" }
%"struct.vox::Vector" = type { double, double }
%"struct.vox::Point" = type { double, double }
%"struct.vox::BoundingBox" = type { %"struct.vox::Point", %"struct.vox::Point" }
%"class.vox::Array" = type { %"struct.vox::Size2", %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<vox::Vector<double, 2>, std::allocator<vox::Vector<double, 2>>>::_Vector_impl" }
%"struct.std::_Vector_base<vox::Vector<double, 2>, std::allocator<vox::Vector<double, 2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<vox::Vector<double, 2>, std::allocator<vox::Vector<double, 2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<vox::Vector<double, 2>, std::allocator<vox::Vector<double, 2>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.vox::LinearArraySampler" = type { %"struct.vox::Vector", %"struct.vox::Vector", %"struct.vox::Point", %"class.vox::ConstArrayAccessor" }
%"class.vox::ConstArrayAccessor" = type { %"struct.vox::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 @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3vox21CollocatedVectorGrid221divergenceAtDataPointEmm(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 %"struct.vox::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.vox::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %15 = call { i64, i64 } @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %14)
  %16 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %17 = extractvalue { i64, i64 } %15, 0
  store i64 %17, ptr %16, align 8
  %18 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %19 = extractvalue { i64, i64 } %15, 1
  store i64 %19, ptr %18, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %20)
  store ptr %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %22 = getelementptr inbounds %"class.vox::CollocatedVectorGrid2", ptr %13, i32 0, i32 1
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = icmp ugt i64 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %3
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = sub i64 %26, 1
  br label %30

28:                                               ; preds = %3
  %29 = load i64, ptr %5, align 8, !tbaa !9
  br label %30

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

42:                                               ; preds = %30
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = add i64 %43, 1
  br label %47

45:                                               ; preds = %30
  %46 = load i64, ptr %5, align 8, !tbaa !9
  br label %47

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

57:                                               ; preds = %47
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = sub i64 %58, 1
  br label %62

60:                                               ; preds = %47
  %61 = load i64, ptr %6, align 8, !tbaa !9
  br label %62

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

74:                                               ; preds = %62
  %75 = load i64, ptr %6, align 8, !tbaa !9
  %76 = add i64 %75, 1
  br label %79

77:                                               ; preds = %62
  %78 = load i64, ptr %6, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %77, %74
  %80 = phi i64 [ %76, %74 ], [ %78, %77 ]
  %81 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %67, i64 noundef %68, i64 noundef %80)
  %82 = getelementptr inbounds %"struct.vox::Vector", ptr %81, i32 0, i32 1
  %83 = load double, ptr %82, align 8, !tbaa !17
  store double %83, ptr %12, align 8, !tbaa !14
  %84 = load double, ptr %10, align 8, !tbaa !14
  %85 = load double, ptr %9, align 8, !tbaa !14
  %86 = fsub double %84, %85
  %87 = fmul double 5.000000e-01, %86
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %"struct.vox::Vector", ptr %88, i32 0, i32 0
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = fdiv double %87, %90
  %92 = load double, ptr %12, align 8, !tbaa !14
  %93 = load double, ptr %11, align 8, !tbaa !14
  %94 = fsub double %92, %93
  %95 = fmul double 5.000000e-01, %94
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %"struct.vox::Vector", ptr %96, i32 0, i32 1
  %98 = load double, ptr %97, align 8, !tbaa !17
  %99 = fdiv double %95, %98
  %100 = fadd double %91, %99
  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 %100
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5Grid211gridSpacingEv(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 = !{!"_ZTSN3vox6VectorIdLm2EEE", !13, i64 0, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN3vox5Size2E", !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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(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 @_ZNK3vox21CollocatedVectorGrid221divergenceAtDataPointEmm(ptr noundef nonnull align 8 dereferenceable(240) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = tail call { i64, i64 } @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %6 = extractvalue { i64, i64 } %5, 0
  %7 = extractvalue { i64, i64 } %5, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5Grid211gridSpacingEv(ptr noundef nonnull align 8 dereferenceable(88) %8)
  %10 = tail call i64 @llvm.usub.sat.i64(i64 %1, i64 1)
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %4, i64 noundef %10, i64 noundef %2)
  %12 = load <2 x double>, ptr %11, align 8
  %13 = add i64 %1, 1
  %14 = icmp ult i64 %13, %6
  %15 = select i1 %14, i64 %13, i64 %1
  %16 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %4, i64 noundef %15, i64 noundef %2)
  %17 = load <2 x double>, ptr %16, align 8
  %18 = tail call i64 @llvm.usub.sat.i64(i64 %2, i64 1)
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %4, i64 noundef %1, i64 noundef %18)
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = add i64 %2, 1
  %23 = icmp ult i64 %22, %7
  %24 = select i1 %23, i64 %22, i64 %2
  %25 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %4, i64 noundef %1, i64 noundef %24)
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = insertelement <2 x double> %17, double %27, i64 1
  %29 = insertelement <2 x double> %12, double %21, i64 1
  %30 = fsub <2 x double> %28, %29
  %31 = fmul <2 x double> %30, <double 5.000000e-01, double 5.000000e-01>
  %32 = load <2 x double>, ptr %9, align 8, !tbaa !10
  %33 = fdiv <2 x double> %31, %32
  %shift = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %34 = fadd <2 x double> %33, %shift
  %35 = extractelement <2 x double> %34, i64 0
  ret double %35
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZNK3vox5ArrayINS_6VectorIdLm2EEELm2EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

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

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

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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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