; LLVM IR from zeux/meshoptimizer :: demo/main.ll (Z8hashMeshRK4Mesh)

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

%union.Triangle = type { [3 x %struct.Vertex] }
%struct.Vertex = type { float, float, float, float, float, float, float, float }
%struct.Mesh = type { %"class.std::vector", %"class.std::vector.0" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Vertex, std::allocator<Vertex>>::_Vector_impl" }
%"struct.std::_Vector_base<Vertex, std::allocator<Vertex>>::_Vector_impl" = type { %"struct.std::_Vector_base<Vertex, std::allocator<Vertex>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Vertex, std::allocator<Vertex>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZNKSt6vectorI6VertexSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z14rotateTriangleR8Triangle(ptr noundef nonnull align 4 dereferenceable(96)) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9hashRangePKcm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z8hashMeshRK4Mesh(ptr noundef nonnull align 8 dereferenceable(48) %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca %union.Triangle, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Mesh, ptr %11, i32 0, i32 1
  %13 = call noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #3
  %14 = udiv i64 %13, 3
  store i64 %14, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Mesh, ptr %15, i32 0, i32 0
  %17 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZNKSt6vectorI6VertexSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef 0) #3
  store ptr %17, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Mesh, ptr %18, i32 0, i32 1
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef 0) #3
  store ptr %20, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %68, %1
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %3, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %71

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 96, ptr %9) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = mul i64 %29, 3
  %31 = add i64 %30, 0
  %32 = getelementptr inbounds i32, ptr %28, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %struct.Vertex, ptr %27, i64 %34
  %36 = getelementptr inbounds [3 x %struct.Vertex], ptr %9, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %36, ptr align 4 %35, i64 32, i1 false), !tbaa.struct !13
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = mul i64 %39, 3
  %41 = add i64 %40, 1
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.Vertex, ptr %37, i64 %44
  %46 = getelementptr inbounds [3 x %struct.Vertex], ptr %9, i64 0, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %46, ptr align 4 %45, i64 32, i1 false), !tbaa.struct !13
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = mul i64 %49, 3
  %51 = add i64 %50, 2
  %52 = getelementptr inbounds i32, ptr %48, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds %struct.Vertex, ptr %47, i64 %54
  %56 = getelementptr inbounds [3 x %struct.Vertex], ptr %9, i64 0, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %56, ptr align 4 %55, i64 32, i1 false), !tbaa.struct !13
  %57 = call noundef zeroext i1 @_Z14rotateTriangleR8Triangle(ptr noundef nonnull align 4 dereferenceable(96) %9)
  br i1 %57, label %58, label %67

58:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %59 = getelementptr inbounds [96 x i8], ptr %9, i64 0, i64 0
  %60 = call noundef i32 @_Z9hashRangePKcm(ptr noundef %59, i64 noundef 96)
  store i32 %60, ptr %10, align 4, !tbaa !11
  %61 = load i32, ptr %10, align 4, !tbaa !11
  %62 = load i32, ptr %6, align 4, !tbaa !11
  %63 = xor i32 %62, %61
  store i32 %63, ptr %6, align 4, !tbaa !11
  %64 = load i32, ptr %10, align 4, !tbaa !11
  %65 = load i32, ptr %7, align 4, !tbaa !11
  %66 = add i32 %65, %64
  store i32 %66, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %67

67:                                               ; preds = %58, %26
  call void @llvm.lifetime.end.p0(i64 96, ptr %9) #3
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %8, align 8, !tbaa !9
  br label %21, !llvm.loop !16

71:                                               ; preds = %25
  %72 = load i32, ptr %6, align 4, !tbaa !11
  %73 = mul i32 %72, 1540483477
  %74 = load i32, ptr %7, align 4, !tbaa !11
  %75 = add i32 %73, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 %75
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 4, !14, i64 12, i64 4, !14, i64 16, i64 4, !14, i64 20, i64 4, !14, i64 24, i64 4, !14, i64 28, i64 4, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%union.Triangle = type { [3 x %struct.Vertex] }
%struct.Vertex = type { float, float, float, float, float, float, float, float }

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZNKSt6vectorI6VertexSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z14rotateTriangleR8Triangle(ptr noundef nonnull align 4 dereferenceable(96)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9hashRangePKcm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z8hashMeshRK4Mesh(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #2 {
  %2 = alloca %union.Triangle, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = tail call noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %5 = udiv i64 %4, 3
  %6 = tail call noundef nonnull align 4 dereferenceable(32) ptr @_ZNKSt6vectorI6VertexSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #3
  %7 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #3
  %.not = icmp ult i64 %4, 3
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %2, i64 32
  %9 = getelementptr inbounds i8, ptr %2, i64 64
  br label %13

._crit_edge.loopexit:                             ; preds = %31
  %10 = mul i32 %.1, 1540483477
  %11 = add i32 %10, %.122
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %12 = phi i32 [ 0, %1 ], [ %11, %._crit_edge.loopexit ]
  ret i32 %12

13:                                               ; preds = %.lr.ph, %31
  %.025 = phi i32 [ 0, %.lr.ph ], [ %.1, %31 ]
  %.02024 = phi i64 [ 0, %.lr.ph ], [ %32, %31 ]
  %.02123 = phi i32 [ 0, %.lr.ph ], [ %.122, %31 ]
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %2) #3
  %.idx = mul i64 %.02024, 12
  %14 = getelementptr inbounds i8, ptr %7, i64 %.idx
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %struct.Vertex, ptr %6, i64 %16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %2, ptr noundef nonnull align 4 dereferenceable(32) %17, i64 32, i1 false), !tbaa.struct !9
  %18 = getelementptr i8, ptr %14, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %struct.Vertex, ptr %6, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %8, ptr noundef nonnull align 4 dereferenceable(32) %21, i64 32, i1 false), !tbaa.struct !9
  %22 = getelementptr i8, ptr %14, i64 8
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.Vertex, ptr %6, i64 %24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %9, ptr noundef nonnull align 4 dereferenceable(32) %25, i64 32, i1 false), !tbaa.struct !9
  %26 = call noundef zeroext i1 @_Z14rotateTriangleR8Triangle(ptr noundef nonnull align 4 dereferenceable(96) %2)
  br i1 %26, label %27, label %31

27:                                               ; preds = %13
  %28 = call noundef i32 @_Z9hashRangePKcm(ptr noundef nonnull %2, i64 noundef 96)
  %29 = xor i32 %28, %.025
  %30 = add i32 %28, %.02123
  br label %31

31:                                               ; preds = %27, %13
  %.122 = phi i32 [ %30, %27 ], [ %.02123, %13 ]
  %.1 = phi i32 [ %29, %27 ], [ %.025, %13 ]
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %2) #3
  %32 = add nuw nsw i64 %.02024, 1
  %exitcond.not = icmp eq i64 %32, %5
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %13, !llvm.loop !12
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 12, i64 4, !10, i64 16, i64 4, !10, i64 20, i64 4, !10, i64 24, i64 4, !10, i64 28, i64 4, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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