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

; 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::Vector" = type { double, double }
%"class.jet::CustomImplicitSurface2" = type <{ %"class.jet::ImplicitSurface2.base", [7 x i8], %"class.std::function", %"class.jet::BoundingBox", double, double, i32, [4 x i8] }>
%"class.jet::ImplicitSurface2.base" = type { %"class.jet::Surface2.base" }
%"class.jet::Surface2.base" = type <{ ptr, %"class.jet::Transform2", i8 }>
%"class.jet::Transform2" = type { %"class.jet::Vector", double, double, double }
%"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 } }
%"class.jet::BoundingBox" = type { %"class.jet::Vector", %"class.jet::Vector" }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3jet22CustomImplicitSurface217closestPointLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(144) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca %"class.jet::Vector", align 8
  %11 = alloca %"class.jet::Vector", align 8
  %12 = alloca %"class.jet::Vector", align 8
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.jet::CustomImplicitSurface2", ptr %13, i32 0, i32 3
  %16 = getelementptr inbounds %"class.jet::BoundingBox", ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %"class.jet::CustomImplicitSurface2", ptr %13, i32 0, i32 3
  %18 = getelementptr inbounds %"class.jet::BoundingBox", ptr %17, i32 0, i32 1
  call void @_ZN3jet5clampIdEENS_6VectorIT_Lm2EEERKS3_S5_S5_(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef nonnull align 8 dereferenceable(16) %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %37, %3
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.jet::CustomImplicitSurface2", ptr %13, i32 0, i32 6
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp ult i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %8, align 4
  br label %40

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = call noundef double @_ZNK3jet22CustomImplicitSurface219signedDistanceLocalERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(144) %13, ptr noundef nonnull align 8 dereferenceable(16) %0)
  store double %26, ptr %9, align 8, !tbaa !22
  %27 = load double, ptr %9, align 8, !tbaa !22
  %28 = call double @llvm.fabs.f64(double %27)
  %29 = fcmp olt double %28, 0x3CB0000000000000
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  store i32 2, ptr %8, align 4
  br label %34

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  call void @_ZNK3jet22CustomImplicitSurface213gradientLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %10, ptr noundef nonnull align 8 dereferenceable(144) %13, ptr noundef nonnull align 8 dereferenceable(16) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #3
  %32 = load double, ptr %9, align 8, !tbaa !22
  call void @_ZN3jetmlIdEENS_6VectorIT_Lm2EEES2_RKS3_(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %12, double noundef %32, ptr noundef nonnull align 8 dereferenceable(16) %10)
  call void @_ZN3jetmiIdEENS_6VectorIT_Lm2EEERKS3_S5_(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %11, ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %12)
  %33 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3jet6VectorIdLm2EEaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  store i32 0, ptr %8, align 4
  br label %34

34:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %35 = load i32, ptr %8, align 4
  switch i32 %35, label %40 [
    i32 0, label %36
  ]

36:                                               ; preds = %34
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !9
  br label %19, !llvm.loop !23

40:                                               ; preds = %34, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %41

41:                                               ; preds = %40
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet5clampIdEENS_6VectorIT_Lm2EEERKS3_S5_S5_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK3jet22CustomImplicitSurface219signedDistanceLocalERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet22CustomImplicitSurface213gradientLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jetmiIdEENS_6VectorIT_Lm2EEERKS3_S5_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jetmlIdEENS_6VectorIT_Lm2EEES2_RKS3_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, double noundef, ptr noundef nonnull align 8 dereferenceable(16)) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3jet6VectorIdLm2EEaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 136}
!12 = !{!"_ZTSN3jet22CustomImplicitSurface2E", !13, i64 0, !19, i64 56, !21, i64 88, !17, i64 120, !17, i64 128, !10, i64 136}
!13 = !{!"_ZTSN3jet16ImplicitSurface2E", !14, i64 0}
!14 = !{!"_ZTSN3jet8Surface2E", !15, i64 8, !18, i64 48}
!15 = !{!"_ZTSN3jet10Transform2E", !16, i64 0, !17, i64 16, !17, i64 24, !17, i64 32}
!16 = !{!"_ZTSN3jet6VectorIdLm2EEE", !17, i64 0, !17, i64 8}
!17 = !{!"double", !7, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTSSt8functionIFdRKN3jet6VectorIdLm2EEEEE", !20, i64 0, !6, i64 24}
!20 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!21 = !{!"_ZTSN3jet11BoundingBoxIdLm2EEE", !16, i64 0, !16, i64 16}
!22 = !{!17, !17, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

%"class.jet::Vector" = type { double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3jet22CustomImplicitSurface217closestPointLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(144) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) unnamed_addr #0 align 2 {
  %4 = alloca %"class.jet::Vector", align 8
  %5 = alloca %"class.jet::Vector", align 8
  %6 = alloca %"class.jet::Vector", align 8
  %7 = getelementptr inbounds i8, ptr %1, i64 88
  %8 = getelementptr inbounds i8, ptr %1, i64 104
  tail call void @_ZN3jet5clampIdEENS_6VectorIT_Lm2EEERKS3_S5_S5_(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(16) %8)
  %9 = getelementptr inbounds i8, ptr %1, i64 136
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %14
  %.07 = phi i32 [ %16, %14 ], [ 0, %3 ]
  %11 = call noundef double @_ZNK3jet22CustomImplicitSurface219signedDistanceLocalERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(144) %1, ptr noundef nonnull align 8 dereferenceable(16) %0)
  %12 = call double @llvm.fabs.f64(double %11)
  %13 = fcmp uge double %12, 0x3CB0000000000000
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @_ZNK3jet22CustomImplicitSurface213gradientLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind nonnull writable sret(%"class.jet::Vector") align 8 %4, ptr noundef nonnull align 8 dereferenceable(144) %1, ptr noundef nonnull align 8 dereferenceable(16) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  call void @_ZN3jetmlIdEENS_6VectorIT_Lm2EEES2_RKS3_(ptr dead_on_unwind nonnull writable sret(%"class.jet::Vector") align 8 %6, double noundef %11, ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @_ZN3jetmiIdEENS_6VectorIT_Lm2EEERKS3_S5_(ptr dead_on_unwind nonnull writable sret(%"class.jet::Vector") align 8 %5, ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %6)
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3jet6VectorIdLm2EEaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %5)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  %16 = add nuw i32 %.07, 1
  %17 = load i32, ptr %9, align 8, !tbaa !5
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %.lr.ph, label %.critedge, !llvm.loop !20

.critedge:                                        ; preds = %14, %.lr.ph, %3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet5clampIdEENS_6VectorIT_Lm2EEERKS3_S5_S5_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK3jet22CustomImplicitSurface219signedDistanceLocalERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet22CustomImplicitSurface213gradientLocalERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jetmiIdEENS_6VectorIT_Lm2EEERKS3_S5_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jetmlIdEENS_6VectorIT_Lm2EEES2_RKS3_(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8, double noundef, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3jet6VectorIdLm2EEaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !19, i64 136}
!6 = !{!"_ZTSN3jet22CustomImplicitSurface2E", !7, i64 0, !15, i64 56, !18, i64 88, !11, i64 120, !11, i64 128, !19, i64 136}
!7 = !{!"_ZTSN3jet16ImplicitSurface2E", !8, i64 0}
!8 = !{!"_ZTSN3jet8Surface2E", !9, i64 8, !14, i64 48}
!9 = !{!"_ZTSN3jet10Transform2E", !10, i64 0, !11, i64 16, !11, i64 24, !11, i64 32}
!10 = !{!"_ZTSN3jet6VectorIdLm2EEE", !11, i64 0, !11, i64 8}
!11 = !{!"double", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"bool", !12, i64 0}
!15 = !{!"_ZTSSt8functionIFdRKN3jet6VectorIdLm2EEEEE", !16, i64 0, !17, i64 24}
!16 = !{!"_ZTSSt14_Function_base", !12, i64 0, !17, i64 16}
!17 = !{!"any pointer", !12, i64 0}
!18 = !{!"_ZTSN3jet11BoundingBoxIdLm2EEE", !10, i64 0, !10, i64 16}
!19 = !{!"int", !12, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass