; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src/epa.ll (ZN8geometry3epa15addNewTrianglesERNS_5types3epa9epaMesh_tEi)

; 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.geometry::types::epa::epaMesh_t" = type { %"class.geometry::mesh::TriangleGraphMesh", [384 x %"struct.geometry::types::minkowskiDiffVertex_t"], i32 }
%"class.geometry::mesh::TriangleGraphMesh" = type { i32, [128 x %"struct.geometry::types::leanNeighborTriangle_t"] }
%"struct.geometry::types::leanNeighborTriangle_t" = type { [3 x i32], [3 x i32] }
%"struct.geometry::types::minkowskiDiffVertex_t" = type { i32, i32, %class.Vector3, %class.Vector3, %class.Vector3 }
%class.Vector3 = type { [3 x float] }

@_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE = external constant [3 x [2 x i32]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj128EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(3076)) #1 align 2

; 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 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8geometry3epa15addNewTrianglesERNS_5types3epa9epaMesh_tEi(ptr noundef nonnull align 4 dereferenceable(19976) %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.geometry::types::epa::epaMesh_t", ptr %13, i32 0, i32 0
  %15 = call noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj128EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(3076) %14)
  store i32 %15, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %84, %2
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %8, align 4
  br label %87

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %78, %21
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp ult i32 %23, 3
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 5, ptr %8, align 4
  br label %81

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.geometry::types::epa::epaMesh_t", ptr %27, i32 0, i32 0
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %28, i32 noundef %29)
  %31 = getelementptr inbounds %"struct.geometry::types::leanNeighborTriangle_t", ptr %30, i32 0, i32 1
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [3 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %77

37:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds [3 x [2 x i32]], ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 0, i64 %39
  %41 = getelementptr inbounds [2 x i32], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %41, align 8, !tbaa !9
  store i32 %42, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [3 x [2 x i32]], ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 0, i64 %44
  %46 = getelementptr inbounds [2 x i32], ptr %45, i64 0, i64 1
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.geometry::types::epa::epaMesh_t", ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.geometry::types::epa::epaMesh_t", ptr %50, i32 0, i32 0
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %51, i32 noundef %52)
  %54 = getelementptr inbounds %"struct.geometry::types::leanNeighborTriangle_t", ptr %53, i32 0, i32 0
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [3 x i32], ptr %54, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.geometry::types::epa::epaMesh_t", ptr %59, i32 0, i32 0
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %60, i32 noundef %61)
  %63 = getelementptr inbounds %"struct.geometry::types::leanNeighborTriangle_t", ptr %62, i32 0, i32 0
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [3 x i32], ptr %63, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076) %49, i32 noundef %58, i32 noundef %67, i32 noundef %68)
  store i32 %69, ptr %12, align 4, !tbaa !9
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %37
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %74

73:                                               ; preds = %37
  store i32 0, ptr %8, align 4
  br label %74

74:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %75 = load i32, ptr %8, align 4
  switch i32 %75, label %81 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %26
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = add i32 %79, 1
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %22, !llvm.loop !11

81:                                               ; preds = %74, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %82 = load i32, ptr %8, align 4
  switch i32 %82, label %87 [
    i32 5, label %83
  ]

83:                                               ; preds = %81
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !13

87:                                               ; preds = %81, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %88 = load i32, ptr %8, align 4
  switch i32 %88, label %90 [
    i32 2, label %89
  ]

89:                                               ; preds = %87
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %90

90:                                               ; preds = %89, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %91 = load i32, ptr %3, align 4
  ret i32 %91
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076), i32 noundef, i32 noundef, i32 noundef) #2 align 2

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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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"

@_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE = external local_unnamed_addr constant [3 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj128EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(3076)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8geometry3epa15addNewTrianglesERNS_5types3epa9epaMesh_tEi(ptr noundef nonnull align 4 dereferenceable(19976) %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj128EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(3076) %0)
  %.not32.not = icmp eq i32 %3, 0
  br i1 %.not32.not, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %4 = load i32, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, align 16
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 4), align 4
  %6 = zext i32 %4 to i64
  %7 = zext i32 %5 to i64
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 8), align 8
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 12), align 4
  %10 = zext i32 %8 to i64
  %11 = zext i32 %9 to i64
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 16), align 16
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN8geometry4mesh17TriangleGraphBase9edgeVertsE, i64 20), align 4
  %14 = zext i32 %12 to i64
  %15 = zext i32 %13 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %.02533 = phi i32 [ %57, %.critedge ], [ 0, %.preheader.preheader ]
  %16 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %17 = getelementptr inbounds i8, ptr %16, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %29

20:                                               ; preds = %.preheader
  %21 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %22 = getelementptr inbounds [3 x i32], ptr %21, i64 0, i64 %6
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %25 = getelementptr inbounds [3 x i32], ptr %24, i64 0, i64 %7
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %23, i32 noundef %26, i32 noundef %1)
  %28 = icmp sgt i32 %27, -1
  br i1 %28, label %29, label %.loopexit

29:                                               ; preds = %.preheader, %20
  %30 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  %35 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %36 = getelementptr inbounds [3 x i32], ptr %35, i64 0, i64 %10
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %39 = getelementptr inbounds [3 x i32], ptr %38, i64 0, i64 %11
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %37, i32 noundef %40, i32 noundef %1)
  %42 = icmp sgt i32 %41, -1
  br i1 %42, label %43, label %.loopexit

43:                                               ; preds = %34, %29
  %44 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %45 = getelementptr inbounds i8, ptr %44, i64 20
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp eq i32 %46, -1
  br i1 %47, label %48, label %.critedge

48:                                               ; preds = %43
  %49 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %50 = getelementptr inbounds [3 x i32], ptr %49, i64 0, i64 %14
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj128EEixEj(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %.02533)
  %53 = getelementptr inbounds [3 x i32], ptr %52, i64 0, i64 %15
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076) %0, i32 noundef %51, i32 noundef %54, i32 noundef %1)
  %56 = icmp sgt i32 %55, -1
  br i1 %56, label %.critedge, label %.loopexit

.critedge:                                        ; preds = %48, %43
  %57 = add nuw i32 %.02533, 1
  %exitcond.not = icmp eq i32 %57, %3
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !9

.loopexit:                                        ; preds = %.critedge, %20, %34, %48, %2
  %spec.select = phi i32 [ 1, %2 ], [ 1, %.critedge ], [ -1, %20 ], [ -1, %34 ], [ -1, %48 ]
  ret i32 %spec.select
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj128EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(3076), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass