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

; 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::Size3" = type { i64, i64, i64 }
%"class.std::function.0" = 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.std::function.35" = type { %"class.std::_Function_base", ptr }
%class.anon = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3jet17triangleMeshToSdfERKNS_13TriangleMesh3EPNS_11ScalarGrid3Ej(ptr noundef nonnull align 8 dereferenceable(560) %0, ptr noundef %1, i32 noundef %2) #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %"class.jet::Size3", align 8
  %8 = alloca i32, align 4
  %9 = alloca %"class.std::function.0", align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"class.std::function.35", align 8
  %13 = alloca %class.anon, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds ptr, ptr %15, i64 6
  %17 = load ptr, ptr %16, align 8
  call void %17(ptr dead_on_unwind writable sret(%"class.jet::Size3") align 8 %7, ptr noundef nonnull align 8 dereferenceable(320) %14)
  %18 = getelementptr inbounds %"class.jet::Size3", ptr %7, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds %"class.jet::Size3", ptr %7, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = mul i64 %19, %21
  %23 = getelementptr inbounds %"class.jet::Size3", ptr %7, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = mul i64 %22, %24
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %3
  store i32 1, ptr %8, align 4
  br label %39

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNK3jet11ScalarGrid312dataPositionEv(ptr dead_on_unwind writable sret(%"class.std::function.0") align 8 %9, ptr noundef nonnull align 8 dereferenceable(320) %29)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZNK3jet13TriangleMesh317updateQueryEngineEv(ptr noundef nonnull align 8 dereferenceable(560) %30)
          to label %31 unwind label %42

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #4
  %33 = getelementptr inbounds %class.anon, ptr %13, i32 0, i32 0
  store ptr %9, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.anon, ptr %13, i32 0, i32 1
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %35, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.anon, ptr %13, i32 0, i32 2
  store ptr %5, ptr %36, align 8, !tbaa !5
  invoke void @"_ZNSt8functionIFvmmmEEC2IZN3jet17triangleMeshToSdfERKNS3_13TriangleMesh3EPNS3_11ScalarGrid3EjE3$_0vEEOT_"(ptr noundef nonnull align 8 dereferenceable(32) %12, ptr noundef nonnull align 8 dereferenceable(24) %13)
          to label %37 unwind label %46

37:                                               ; preds = %31
  invoke void @_ZNK3jet11ScalarGrid329parallelForEachDataPointIndexERKSt8functionIFvmmmEE(ptr noundef nonnull align 8 dereferenceable(320) %32, ptr noundef nonnull align 8 dereferenceable(32) %12)
          to label %38 unwind label %50

38:                                               ; preds = %37
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %12) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  store i32 0, ptr %8, align 4
  br label %39

39:                                               ; preds = %38, %27
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  %40 = load i32, ptr %8, align 4
  switch i32 %40, label %61 [
    i32 0, label %41
    i32 1, label %41
  ]

41:                                               ; preds = %39, %39
  ret void

42:                                               ; preds = %28
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %10, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %11, align 4
  br label %55

46:                                               ; preds = %31
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %10, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %11, align 4
  br label %54

50:                                               ; preds = %37
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %10, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %11, align 4
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %12) #4
  br label %54

54:                                               ; preds = %50, %46
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  br label %55

55:                                               ; preds = %54, %42
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %10, align 8
  %58 = load i32, ptr %11, align 4
  %59 = insertvalue { ptr, i32 } poison, ptr %57, 0
  %60 = insertvalue { ptr, i32 } %59, i32 %58, 1
  resume { ptr, i32 } %60

61:                                               ; preds = %39
  unreachable
}

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

declare void @_ZNK3jet11ScalarGrid312dataPositionEv(ptr dead_on_unwind writable sret(%"class.std::function.0") align 8, ptr noundef nonnull align 8 dereferenceable(320)) #2

declare void @_ZNK3jet13TriangleMesh317updateQueryEngineEv(ptr noundef nonnull align 8 dereferenceable(560)) #2

declare i32 @__gxx_personality_v0(...)

declare void @_ZNK3jet11ScalarGrid329parallelForEachDataPointIndexERKSt8functionIFvmmmEE(ptr noundef nonnull align 8 dereferenceable(320), ptr noundef nonnull align 8 dereferenceable(32)) #2

; Function Attrs: mustprogress uwtable
declare hidden void @"_ZNSt8functionIFvmmmEEC2IZN3jet17triangleMeshToSdfERKNS3_13TriangleMesh3EPNS3_11ScalarGrid3EjE3$_0vEEOT_"(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN3jet5Size3E", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!14, !15, i64 16}


; 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::Size3" = type { i64, i64, i64 }
%"class.std::function.0" = 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.std::function.35" = type { %"class.std::_Function_base", ptr }
%class.anon = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3jet17triangleMeshToSdfERKNS_13TriangleMesh3EPNS_11ScalarGrid3Ej(ptr noundef nonnull align 8 dereferenceable(560) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca %"class.jet::Size3", align 8
  %6 = alloca %"class.std::function.0", align 8
  %7 = alloca %"class.std::function.35", align 8
  %8 = alloca %class.anon, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  %9 = load ptr, ptr %1, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 48
  %11 = load ptr, ptr %10, align 8
  call void %11(ptr dead_on_unwind nonnull writable sret(%"class.jet::Size3") align 8 %5, ptr noundef nonnull align 8 dereferenceable(320) %1)
  %12 = load i64, ptr %5, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = mul i64 %14, %12
  %16 = getelementptr inbounds i8, ptr %5, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = mul i64 %15, %17
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  call void @_ZNK3jet11ScalarGrid312dataPositionEv(ptr dead_on_unwind nonnull writable sret(%"class.std::function.0") align 8 %6, ptr noundef nonnull align 8 dereferenceable(320) %1)
  invoke void @_ZNK3jet13TriangleMesh317updateQueryEngineEv(ptr noundef nonnull align 8 dereferenceable(560) %0)
          to label %21 unwind label %27

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #4
  store ptr %6, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %0, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %4, ptr %23, align 8, !tbaa !5
  invoke void @"_ZNSt8functionIFvmmmEEC2IZN3jet17triangleMeshToSdfERKNS3_13TriangleMesh3EPNS3_11ScalarGrid3EjE3$_0vEEOT_"(ptr noundef nonnull align 8 dereferenceable(32) %7, ptr noundef nonnull align 8 dereferenceable(24) %8)
          to label %24 unwind label %29

24:                                               ; preds = %21
  invoke void @_ZNK3jet11ScalarGrid329parallelForEachDataPointIndexERKSt8functionIFvmmmEE(ptr noundef nonnull align 8 dereferenceable(320) %1, ptr noundef nonnull align 8 dereferenceable(32) %7)
          to label %25 unwind label %31

25:                                               ; preds = %24
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  br label %26

26:                                               ; preds = %3, %25
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  ret void

27:                                               ; preds = %20
  %28 = landingpad { ptr, i32 }
          cleanup
  br label %34

29:                                               ; preds = %21
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %33

31:                                               ; preds = %24
  %32 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  br label %33

33:                                               ; preds = %31, %29
  %.pn = phi { ptr, i32 } [ %32, %31 ], [ %30, %29 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  br label %34

34:                                               ; preds = %33, %27
  %.pn.pn = phi { ptr, i32 } [ %.pn, %33 ], [ %28, %27 ]
  call void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  resume { ptr, i32 } %.pn.pn
}

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

declare void @_ZNK3jet11ScalarGrid312dataPositionEv(ptr dead_on_unwind writable sret(%"class.std::function.0") align 8, ptr noundef nonnull align 8 dereferenceable(320)) local_unnamed_addr #2

declare void @_ZNK3jet13TriangleMesh317updateQueryEngineEv(ptr noundef nonnull align 8 dereferenceable(560)) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @_ZNK3jet11ScalarGrid329parallelForEachDataPointIndexERKSt8functionIFvmmmEE(ptr noundef nonnull align 8 dereferenceable(320), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden void @"_ZNSt8functionIFvmmmEEC2IZN3jet17triangleMeshToSdfERKNS3_13TriangleMesh3EPNS3_11ScalarGrid3EjE3$_0vEEOT_"(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt14_Function_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN3jet5Size3E", !13, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !13, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass