; LLVM IR from zeux/meshoptimizer :: src (indexgenerator)

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

%class.meshopt_Allocator = type { [24 x ptr], i64 }
%"struct.meshopt::VertexStreamHasher" = type { ptr, i64 }
%struct.meshopt_Stream = type { ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti = external hidden unnamed_addr constant [137 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, 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: mustprogress nounwind uwtable
declare dso_local void @_ZN17meshopt_AllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(200)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @meshopt_generateShadowIndexBufferMulti(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #3 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca %class.meshopt_Allocator, align 8
  %15 = alloca %"struct.meshopt::VertexStreamHasher", align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  br label %23

21:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i32 noundef 426, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = urem i64 %24, 3
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  br label %30

28:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 427, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29, %27
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = icmp ugt i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = icmp ule i64 %34, 16
  br label %36

36:                                               ; preds = %33, %30
  %37 = phi i1 [ false, %30 ], [ %35, %33 ]
  br i1 %37, label %38, label %39

38:                                               ; preds = %36
  br label %41

39:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 428, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %82, %41
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %85

47:                                               ; preds = %42
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.meshopt_Stream, ptr %48, i64 %49
  %51 = getelementptr inbounds %struct.meshopt_Stream, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = icmp ugt i64 %52, 0
  br i1 %53, label %54, label %61

54:                                               ; preds = %47
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.meshopt_Stream, ptr %55, i64 %56
  %58 = getelementptr inbounds %struct.meshopt_Stream, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !11
  %60 = icmp ule i64 %59, 256
  br label %61

61:                                               ; preds = %54, %47
  %62 = phi i1 [ false, %47 ], [ %60, %54 ]
  br i1 %62, label %63, label %64

63:                                               ; preds = %61
  br label %66

64:                                               ; preds = %61
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 432, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

65:                                               ; No predecessors!
  br label %66

66:                                               ; preds = %65, %63
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.meshopt_Stream, ptr %67, i64 %68
  %70 = getelementptr inbounds %struct.meshopt_Stream, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.meshopt_Stream, ptr %72, i64 %73
  %75 = getelementptr inbounds %struct.meshopt_Stream, ptr %74, i32 0, i32 2
  %76 = load i64, ptr %75, align 8, !tbaa !13
  %77 = icmp ule i64 %71, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %66
  br label %81

79:                                               ; preds = %66
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 433, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

80:                                               ; No predecessors!
  br label %81

81:                                               ; preds = %80, %78
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %13, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %13, align 8, !tbaa !9
  br label %42, !llvm.loop !14

85:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 200, ptr %14) #5
  call void @_ZN17meshopt_AllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(200) %14)
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %86 = getelementptr inbounds %"struct.meshopt::VertexStreamHasher", ptr %15, i32 0, i32 0
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %87, ptr %86, align 8, !tbaa !16
  %88 = getelementptr inbounds %"struct.meshopt::VertexStreamHasher", ptr %15, i32 0, i32 1
  %89 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %89, ptr %88, align 8, !tbaa !18
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load i64, ptr %9, align 8, !tbaa !9
  %93 = load i64, ptr %10, align 8, !tbaa !9
  invoke void @_ZN7meshoptL20generateShadowBufferINS_18VertexStreamHasherEEEvPjPKjmmRKT_R17meshopt_Allocator(ptr noundef %90, ptr noundef %91, i64 noundef %92, i64 noundef %93, ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull align 8 dereferenceable(200) %14)
          to label %94 unwind label %95

94:                                               ; preds = %85
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %14) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %14) #5
  ret void

95:                                               ; preds = %85
  %96 = landingpad { ptr, i32 }
          cleanup
  %97 = extractvalue { ptr, i32 } %96, 0
  store ptr %97, ptr %16, align 8
  %98 = extractvalue { ptr, i32 } %96, 1
  store i32 %98, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %14) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %14) #5
  br label %99

99:                                               ; preds = %95
  %100 = load ptr, ptr %16, align 8
  %101 = load i32, ptr %17, align 4
  %102 = insertvalue { ptr, i32 } poison, ptr %100, 0
  %103 = insertvalue { ptr, i32 } %102, i32 %101, 1
  resume { ptr, i32 } %103
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7meshoptL20generateShadowBufferINS_18VertexStreamHasherEEEvPjPKjmmRKT_R17meshopt_Allocator(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(200)) #3

attributes #0 = { noreturn nounwind "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 = { 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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !10, i64 8}
!12 = !{!"_ZTS14meshopt_Stream", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTSN7meshopt18VertexStreamHasherE", !6, i64 0, !10, i64 8}
!18 = !{!17, !10, i64 8}


; 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.meshopt_Allocator = type { [24 x ptr], i64 }
%"struct.meshopt::VertexStreamHasher" = type { ptr, i64 }
%struct.meshopt_Stream = type { ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti = external hidden unnamed_addr constant [137 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN17meshopt_AllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(200)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @meshopt_generateShadowIndexBufferMulti(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %7 = alloca %class.meshopt_Allocator, align 8
  %8 = alloca %"struct.meshopt::VertexStreamHasher", align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %9, label %10

9:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i32 noundef 426, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

10:                                               ; preds = %6
  %11 = urem i64 %2, 3
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 427, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

14:                                               ; preds = %10
  %15 = add i64 %5, -1
  %16 = icmp ult i64 %15, 16
  br i1 %16, label %.lr.ph, label %17

17:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 428, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

18:                                               ; preds = %25
  %19 = add nuw i64 %.027, 1
  %exitcond.not = icmp eq i64 %19, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %18
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %7) #5
  call void @_ZN17meshopt_AllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(200) %7)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #5
  store ptr %4, ptr %8, align 8, !tbaa !7
  %20 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 %5, ptr %20, align 8, !tbaa !13
  invoke void @_ZN7meshoptL20generateShadowBufferINS_18VertexStreamHasherEEEvPjPKjmmRKT_R17meshopt_Allocator(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %3, ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(200) %7)
          to label %29 unwind label %30

.lr.ph:                                           ; preds = %14, %18
  %.027 = phi i64 [ %19, %18 ], [ 0, %14 ]
  %21 = getelementptr inbounds %struct.meshopt_Stream, ptr %4, i64 %.027
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = add i64 %23, -1
  %or.cond = icmp ult i64 %24, 256
  br i1 %or.cond, label %25, label %.critedge

.critedge:                                        ; preds = %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 432, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

25:                                               ; preds = %.lr.ph
  %26 = getelementptr inbounds i8, ptr %21, i64 16
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %.not26 = icmp ugt i64 %23, %27
  br i1 %.not26, label %28, label %18

28:                                               ; preds = %25
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 433, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateShadowIndexBufferMulti) #4
  unreachable

29:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %7) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %7) #5
  ret void

30:                                               ; preds = %._crit_edge
  %31 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %7) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %7) #5
  resume { ptr, i32 } %31
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7meshoptL20generateShadowBufferINS_18VertexStreamHasherEEEvPjPKjmmRKT_R17meshopt_Allocator(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(200)) local_unnamed_addr #3

attributes #0 = { noreturn nounwind "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 nocallback nofree nosync 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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"_ZTSN7meshopt18VertexStreamHasherE", !9, i64 0, !12, i64 8}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!8, !12, i64 8}
!14 = !{!15, !12, i64 8}
!15 = !{!"_ZTS14meshopt_Stream", !9, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!15, !12, i64 16}


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