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

; 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.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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

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

18:                                               ; preds = %100, %1
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %103

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %23 = load i32, ptr %5, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = add i64 %25, 1
  %27 = urem i64 %24, %26
  store i64 %27, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = mul i64 3, %29
  %31 = add i64 %30, 0
  %32 = getelementptr inbounds i32, ptr %28, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !11
  store i32 %33, ptr %8, align 4, !tbaa !11
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = mul i64 3, %35
  %37 = add i64 %36, 0
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = mul i64 3, %41
  %43 = add i64 %42, 0
  %44 = getelementptr inbounds i32, ptr %40, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !11
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = mul i64 3, %47
  %49 = add i64 %48, 0
  %50 = getelementptr inbounds i32, ptr %46, i64 %49
  store i32 %45, ptr %50, align 4, !tbaa !11
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = mul i64 3, %52
  %54 = add i64 %53, 1
  %55 = getelementptr inbounds i32, ptr %51, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !11
  store i32 %56, ptr %8, align 4, !tbaa !11
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = mul i64 3, %58
  %60 = add i64 %59, 1
  %61 = getelementptr inbounds i32, ptr %57, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !11
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i64, ptr %7, align 8, !tbaa !9
  %65 = mul i64 3, %64
  %66 = add i64 %65, 1
  %67 = getelementptr inbounds i32, ptr %63, i64 %66
  store i32 %62, ptr %67, align 4, !tbaa !11
  %68 = load i32, ptr %8, align 4, !tbaa !11
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = mul i64 3, %70
  %72 = add i64 %71, 1
  %73 = getelementptr inbounds i32, ptr %69, i64 %72
  store i32 %68, ptr %73, align 4, !tbaa !11
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load i64, ptr %7, align 8, !tbaa !9
  %76 = mul i64 3, %75
  %77 = add i64 %76, 2
  %78 = getelementptr inbounds i32, ptr %74, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !11
  store i32 %79, ptr %8, align 4, !tbaa !11
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load i64, ptr %6, align 8, !tbaa !9
  %82 = mul i64 3, %81
  %83 = add i64 %82, 2
  %84 = getelementptr inbounds i32, ptr %80, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !11
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i64, ptr %7, align 8, !tbaa !9
  %88 = mul i64 3, %87
  %89 = add i64 %88, 2
  %90 = getelementptr inbounds i32, ptr %86, i64 %89
  store i32 %85, ptr %90, align 4, !tbaa !11
  %91 = load i32, ptr %8, align 4, !tbaa !11
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = load i64, ptr %6, align 8, !tbaa !9
  %94 = mul i64 3, %93
  %95 = add i64 %94, 2
  %96 = getelementptr inbounds i32, ptr %92, i64 %95
  store i32 %91, ptr %96, align 4, !tbaa !11
  %97 = load i32, ptr %5, align 4, !tbaa !11
  %98 = mul i32 %97, 1664525
  %99 = add i32 %98, 1013904223
  store i32 %99, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %100

100:                                              ; preds = %22
  %101 = load i64, ptr %6, align 8, !tbaa !9
  %102 = add i64 %101, -1
  store i64 %102, ptr %6, align 8, !tbaa !9
  br label %18, !llvm.loop !13

103:                                              ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = { 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 = distinct !{!13, !14}
!14 = !{!"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"

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z16optRandomShuffleR4Mesh(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = tail call noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #1
  %4 = udiv i64 %3, 3
  %5 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIjSaIjEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef 0) #1
  %.03436 = add nsw i64 %4, -1
  %.not37 = icmp eq i64 %.03436, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.03440 = phi i64 [ %.034, %.lr.ph ], [ %.03436, %1 ]
  %.039 = phi i32 [ %21, %.lr.ph ], [ 0, %1 ]
  %.034.in38 = phi i64 [ %.03440, %.lr.ph ], [ %4, %1 ]
  %6 = zext i32 %.039 to i64
  %7 = urem i64 %6, %.034.in38
  %.idx = mul nuw nsw i64 %7, 12
  %8 = getelementptr inbounds i8, ptr %5, i64 %.idx
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.idx35 = mul i64 %.03440, 12
  %10 = getelementptr inbounds i8, ptr %5, i64 %.idx35
  %11 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %11, ptr %8, align 4, !tbaa !5
  store i32 %9, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr i8, ptr %10, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr i8, ptr %10, i64 8
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !5
  %20 = mul i32 %.039, 1664525
  %21 = add i32 %20, 1013904223
  %.034 = add i64 %.03440, -1
  %.not = icmp eq i64 %.034, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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