; 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::VertexHasher" = type { ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_generateVertexRemap = external hidden unnamed_addr constant [111 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local i64 @meshopt_generateVertexRemap(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5) #0 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca %class.meshopt_Allocator, align 8
  %14 = alloca %"struct.meshopt::VertexHasher", align 8
  %15 = alloca ptr, align 8
  %16 = 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 ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i64 %5, ptr %12, align 8, !tbaa !9
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %6
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = icmp eq i64 %20, %21
  br label %23

23:                                               ; preds = %19, %6
  %24 = phi i1 [ true, %6 ], [ %22, %19 ]
  br i1 %24, label %25, label %26

25:                                               ; preds = %23
  br label %28

26:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 313, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

27:                                               ; No predecessors!
  br label %28

28:                                               ; preds = %27, %25
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = urem i64 %32, 3
  %34 = icmp eq i64 %33, 0
  br label %35

35:                                               ; preds = %31, %28
  %36 = phi i1 [ true, %28 ], [ %34, %31 ]
  br i1 %36, label %37, label %38

37:                                               ; preds = %35
  br label %40

38:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 314, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

39:                                               ; No predecessors!
  br label %40

40:                                               ; preds = %39, %37
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = icmp ugt i64 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = icmp ule i64 %44, 256
  br label %46

46:                                               ; preds = %43, %40
  %47 = phi i1 [ false, %40 ], [ %45, %43 ]
  br i1 %47, label %48, label %49

48:                                               ; preds = %46
  br label %51

49:                                               ; preds = %46
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 315, ptr noundef @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

50:                                               ; No predecessors!
  br label %51

51:                                               ; preds = %50, %48
  call void @llvm.lifetime.start.p0(i64 200, ptr %13) #5
  call void @_ZN17meshopt_AllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(200) %13)
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #5
  %52 = getelementptr inbounds %"struct.meshopt::VertexHasher", ptr %14, i32 0, i32 0
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %53, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %"struct.meshopt::VertexHasher", ptr %14, i32 0, i32 1
  %55 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %55, ptr %54, align 8, !tbaa !13
  %56 = getelementptr inbounds %"struct.meshopt::VertexHasher", ptr %14, i32 0, i32 2
  %57 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %57, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = invoke noundef i64 @_ZN7meshoptL19generateVertexRemapINS_12VertexHasherEEEmPjPKjmmRKT_R17meshopt_Allocator(ptr noundef %58, ptr noundef %59, i64 noundef %60, i64 noundef %61, ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(200) %13)
          to label %63 unwind label %64

63:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %13) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %13) #5
  ret i64 %62

64:                                               ; preds = %51
  %65 = landingpad { ptr, i32 }
          cleanup
  %66 = extractvalue { ptr, i32 } %65, 0
  store ptr %66, ptr %15, align 8
  %67 = extractvalue { ptr, i32 } %65, 1
  store i32 %67, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #5
  call void @_ZN17meshopt_AllocatorD2Ev(ptr noundef nonnull align 8 dereferenceable(200) %13) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %13) #5
  br label %68

68:                                               ; preds = %64
  %69 = load ptr, ptr %15, align 8
  %70 = load i32, ptr %16, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

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

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

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

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN7meshoptL19generateVertexRemapINS_12VertexHasherEEEmPjPKjmmRKT_R17meshopt_Allocator(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(200)) #0

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) #2

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !6, i64 0}
!12 = !{!"_ZTSN7meshopt12VertexHasherE", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}


; 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::VertexHasher" = type { ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_generateVertexRemap = external hidden unnamed_addr constant [111 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

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

12:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 313, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

13:                                               ; preds = %6
  %14 = urem i64 %2, 3
  %15 = icmp ne i64 %14, 0
  %or.cond.not = and i1 %9, %15
  br i1 %or.cond.not, label %16, label %.critedge

16:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 314, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

.critedge:                                        ; preds = %13
  %17 = add i64 %5, -1
  %18 = icmp ult i64 %17, 256
  br i1 %18, label %20, label %19

19:                                               ; preds = %.critedge
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 315, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_generateVertexRemap) #4
  unreachable

20:                                               ; preds = %.critedge
  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 24, ptr nonnull %8) #5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 %5, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %8, i64 16
  store i64 %5, ptr %22, align 8, !tbaa !12
  %23 = invoke noundef i64 @_ZN7meshoptL19generateVertexRemapINS_12VertexHasherEEEmPjPKjmmRKT_R17meshopt_Allocator(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %4, ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef nonnull align 8 dereferenceable(200) %7)
          to label %24 unwind label %25

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 24, 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 i64 %23

25:                                               ; preds = %20
  %26 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 24, 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 } %26
}

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

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

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

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN7meshoptL19generateVertexRemapINS_12VertexHasherEEEmPjPKjmmRKT_R17meshopt_Allocator(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(200)) local_unnamed_addr #0

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) #2

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN7meshopt12VertexHasherE", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass