; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src (quickhull)

; 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::mesh::quickhullMesh_t" = type { %"class.geometry::mesh::TriangleGraphMesh", i32, [500 x %"struct.geometry::types::minkowskiDiffVertex_t"] }
%"class.geometry::mesh::TriangleGraphMesh" = type { i32, [500 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: 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 i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj500EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(12004)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8geometry4mesh20addTrianglesToVertIdEiRNS0_15quickhullMesh_tE(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(34008) %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %82

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %"struct.geometry::mesh::quickhullMesh_t", ptr %16, i32 0, i32 0
  %18 = call noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj500EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(12004) %17)
  store i32 %18, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %78, %15
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %81

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

25:                                               ; preds = %74, %24
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = icmp ult i32 %26, 3
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %77

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %"struct.geometry::mesh::quickhullMesh_t", ptr %30, i32 0, i32 0
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %31, i32 noundef %32)
  %34 = getelementptr inbounds %"struct.geometry::types::leanNeighborTriangle_t", ptr %33, i32 0, i32 1
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [3 x i32], ptr %34, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %73

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

73:                                               ; preds = %40, %29
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = add i32 %75, 1
  store i32 %76, ptr %9, align 4, !tbaa !5
  br label %25, !llvm.loop !11

77:                                               ; preds = %28
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = add i32 %79, 1
  store i32 %80, ptr %7, align 4, !tbaa !5
  br label %19, !llvm.loop !13

81:                                               ; preds = %23
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %82

82:                                               ; preds = %81, %14
  %83 = load i32, ptr %3, align 4
  ret i32 %83
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 @_ZNK8geometry4mesh17TriangleGraphMeshILj500EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(12004)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj500EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(12004), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN8geometry4mesh20addTrianglesToVertIdEiRNS0_15quickhullMesh_tE(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(34008) %1) local_unnamed_addr #1 {
  %3 = icmp slt i32 %0, 0
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = tail call noundef i32 @_ZNK8geometry4mesh17TriangleGraphMeshILj500EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(12004) %1)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.loopexit, label %.preheader.preheader

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

.preheader:                                       ; preds = %.preheader.preheader, %56
  %.02024 = phi i32 [ %57, %56 ], [ 0, %.preheader.preheader ]
  %18 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %19 = getelementptr inbounds i8, ptr %18, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %30

22:                                               ; preds = %.preheader
  %23 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %24 = getelementptr inbounds [3 x i32], ptr %23, i64 0, i64 %8
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %27 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 %9
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj500EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %25, i32 noundef %28, i32 noundef %0)
  br label %30

30:                                               ; preds = %.preheader, %22
  %31 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, -1
  br i1 %34, label %35, label %43

35:                                               ; preds = %30
  %36 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %37 = getelementptr inbounds [3 x i32], ptr %36, i64 0, i64 %12
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %40 = getelementptr inbounds [3 x i32], ptr %39, i64 0, i64 %13
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj500EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %38, i32 noundef %41, i32 noundef %0)
  br label %43

43:                                               ; preds = %35, %30
  %44 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %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 %56

48:                                               ; preds = %43
  %49 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %50 = getelementptr inbounds [3 x i32], ptr %49, i64 0, i64 %16
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN8geometry4mesh17TriangleGraphMeshILj500EEixEj(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %.02024)
  %53 = getelementptr inbounds [3 x i32], ptr %52, i64 0, i64 %17
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = tail call noundef i32 @_ZN8geometry4mesh17TriangleGraphMeshILj500EE12add_triangleEiii(ptr noundef nonnull align 4 dereferenceable(12004) %1, i32 noundef %51, i32 noundef %54, i32 noundef %0)
  br label %56

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

.loopexit:                                        ; preds = %56, %4, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %4 ], [ 1, %56 ]
  ret i32 %.0
}

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