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

; 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::triangleMesh_t" = type { i32, i32, [1000 x %"struct.geometry::types::meshTriangle_t"], [500 x %class.Vector3] }
%"struct.geometry::types::meshTriangle_t" = type { [3 x i32], %class.Vector3 }
%class.Vector3 = type { [3 x float] }
%struct.data_triangleMesh_s = type { i32, [1000 x %struct.meshTriangle], i32, [500 x %struct.vector3] }
%struct.meshTriangle = type { [3 x i32], %struct.vector3 }
%struct.vector3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry10converters6to_podERK7Vector3P7vector3(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef) #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry10converters6to_podERKNS_5types14meshTriangle_tEP12meshTriangle(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef) #0

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

17:                                               ; preds = %35, %2
  %18 = load i32, ptr %5, align 4, !tbaa !16
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.geometry::types::triangleMesh_t", ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = icmp ult i32 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %38

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.geometry::types::triangleMesh_t", ptr %25, i32 0, i32 3
  %27 = load i32, ptr %5, align 4, !tbaa !16
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [500 x %class.Vector3], ptr %26, i64 0, i64 %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.data_triangleMesh_s, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %5, align 4, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [500 x %struct.vector3], ptr %31, i64 0, i64 %33
  call void @_ZN8geometry10converters6to_podERK7Vector3P7vector3(ptr noundef nonnull align 4 dereferenceable(12) %29, ptr noundef %34)
  br label %35

35:                                               ; preds = %24
  %36 = load i32, ptr %5, align 4, !tbaa !16
  %37 = add i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !16
  br label %17, !llvm.loop !17

38:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %39

39:                                               ; preds = %57, %38
  %40 = load i32, ptr %6, align 4, !tbaa !16
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.geometry::types::triangleMesh_t", ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = icmp ult i32 %40, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %60

46:                                               ; preds = %39
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.geometry::types::triangleMesh_t", ptr %47, i32 0, i32 2
  %49 = load i32, ptr %6, align 4, !tbaa !16
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [1000 x %"struct.geometry::types::meshTriangle_t"], ptr %48, i64 0, i64 %50
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.data_triangleMesh_s, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %6, align 4, !tbaa !16
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds [1000 x %struct.meshTriangle], ptr %53, i64 0, i64 %55
  call void @_ZN8geometry10converters6to_podERKNS_5types14meshTriangle_tEP12meshTriangle(ptr noundef nonnull align 4 dereferenceable(24) %51, ptr noundef %56)
  br label %57

57:                                               ; preds = %46
  %58 = load i32, ptr %6, align 4, !tbaa !16
  %59 = add i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !16
  br label %39, !llvm.loop !19

60:                                               ; preds = %45
  ret void
}

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 = { 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, !11, i64 0}
!10 = !{!"_ZTSN8geometry5types14triangleMesh_tE", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 24008}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTS19data_triangleMesh_s", !11, i64 0, !7, i64 4, !11, i64 24004, !7, i64 24008}
!14 = !{!10, !11, i64 4}
!15 = !{!13, !11, i64 24004}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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.Vector3 = type { [3 x float] }
%struct.vector3 = type { [3 x float] }
%"struct.geometry::types::meshTriangle_t" = type { [3 x i32], %class.Vector3 }
%struct.meshTriangle = type { [3 x i32], %struct.vector3 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry10converters6to_podERK7Vector3P7vector3(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry10converters6to_podERKNS_5types14meshTriangle_tEP12meshTriangle(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry10converters6to_podERKNS_5types14triangleMesh_tEP19data_triangleMesh_s(ptr noundef nonnull align 4 dereferenceable(30008) %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  store i32 %3, ptr %1, align 4, !tbaa !10
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %1, i64 24004
  store i32 %5, ptr %6, align 4, !tbaa !13
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 24008
  %8 = getelementptr inbounds i8, ptr %1, i64 24008
  br label %12

.preheader.loopexit:                              ; preds = %12
  %.pre = load i32, ptr %0, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %2
  %9 = phi i32 [ %.pre, %.preheader.loopexit ], [ %3, %2 ]
  %.not21 = icmp eq i32 %9, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph20

.lr.ph20:                                         ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  br label %18

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = getelementptr inbounds [500 x %class.Vector3], ptr %7, i64 0, i64 %indvars.iv
  %14 = getelementptr inbounds [500 x %struct.vector3], ptr %8, i64 0, i64 %indvars.iv
  tail call void @_ZN8geometry10converters6to_podERK7Vector3P7vector3(ptr noundef nonnull align 4 dereferenceable(12) %13, ptr noundef nonnull %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i32, ptr %4, align 4, !tbaa !12
  %16 = zext i32 %15 to i64
  %17 = icmp ult i64 %indvars.iv.next, %16
  br i1 %17, label %12, label %.preheader.loopexit, !llvm.loop !14

._crit_edge:                                      ; preds = %18, %.preheader
  ret void

18:                                               ; preds = %.lr.ph20, %18
  %indvars.iv23 = phi i64 [ 0, %.lr.ph20 ], [ %indvars.iv.next24, %18 ]
  %19 = getelementptr inbounds [1000 x %"struct.geometry::types::meshTriangle_t"], ptr %10, i64 0, i64 %indvars.iv23
  %20 = getelementptr inbounds [1000 x %struct.meshTriangle], ptr %11, i64 0, i64 %indvars.iv23
  tail call void @_ZN8geometry10converters6to_podERKNS_5types14meshTriangle_tEP12meshTriangle(ptr noundef nonnull align 4 dereferenceable(24) %19, ptr noundef nonnull %20)
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %21 = load i32, ptr %0, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = icmp ult i64 %indvars.iv.next24, %22
  br i1 %23, label %18, label %._crit_edge, !llvm.loop !16
}

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

!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 0}
!6 = !{!"_ZTSN8geometry5types14triangleMesh_tE", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 24008}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTS19data_triangleMesh_s", !7, i64 0, !8, i64 4, !7, i64 24004, !8, i64 24008}
!12 = !{!6, !7, i64 4}
!13 = !{!11, !7, i64 24004}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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