; LLVM IR from zeux/meshoptimizer :: gltf/material.ll (Z13mergeTexturesP10cgltf_dataRSt6vectorI11TextureInfoSaIS2_EE)

; 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.TextureInfo = type { i8, i32 }
%struct.cgltf_data = type { i32, ptr, %struct.cgltf_asset, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, ptr, i64, ptr, i64, %struct.cgltf_extras, i64, ptr, ptr, i64, ptr, i64, ptr, i64, ptr, i64, %struct.cgltf_memory_options, %struct.cgltf_file_options }
%struct.cgltf_asset = type { ptr, ptr, ptr, ptr, %struct.cgltf_extras, i64, ptr }
%struct.cgltf_extras = type { i64, i64, ptr }
%struct.cgltf_memory_options = type { ptr, ptr, ptr }
%struct.cgltf_file_options = type { ptr, ptr, ptr }
%struct.cgltf_texture = type { ptr, ptr, ptr, i32, ptr, i32, ptr, %struct.cgltf_extras, i64, 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 uwtable
define dso_local void @_Z13mergeTexturesP10cgltf_dataRSt6vectorI11TextureInfoSaIS2_EE(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %81, %2
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i64 @_ZNKSt6vectorI11TextureInfoSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #3
  %14 = icmp ult i64 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %84

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %18) #3
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TextureInfo, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 4, !tbaa !11, !range !15, !noundef !16
  %23 = trunc i8 %22 to i1
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  store i32 4, ptr %7, align 4
  br label %78

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %61, %25
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %7, align 4
  br label %64

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %32, i64 noundef %33) #3
  %35 = getelementptr inbounds %struct.TextureInfo, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 4, !tbaa !11, !range !15, !noundef !16
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %60

38:                                               ; preds = %31
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cgltf_data, ptr %39, i32 0, i32 15
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.cgltf_texture, ptr %41, i64 %42
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cgltf_data, ptr %44, i32 0, i32 15
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.cgltf_texture, ptr %46, i64 %47
  %49 = call noundef zeroext i1 @_ZL16areTexturesEqualRK13cgltf_textureS1_(ptr noundef nonnull align 8 dereferenceable(96) %43, ptr noundef nonnull align 8 dereferenceable(96) %48)
  br i1 %49, label %50, label %60

50:                                               ; preds = %38
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TextureInfo, ptr %51, i32 0, i32 0
  store i8 0, ptr %52, align 4, !tbaa !11
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %53, i64 noundef %54) #3
  %56 = getelementptr inbounds %struct.TextureInfo, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !24
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TextureInfo, ptr %58, i32 0, i32 1
  store i32 %57, ptr %59, align 4, !tbaa !24
  store i32 5, ptr %7, align 4
  br label %64

60:                                               ; preds = %38, %31
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %9, align 8, !tbaa !9
  br label %26, !llvm.loop !25

64:                                               ; preds = %50, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TextureInfo, ptr %66, i32 0, i32 0
  %68 = load i8, ptr %67, align 4, !tbaa !11, !range !15, !noundef !16
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %77

70:                                               ; preds = %65
  %71 = load i64, ptr %5, align 8, !tbaa !9
  %72 = trunc i64 %71 to i32
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TextureInfo, ptr %73, i32 0, i32 1
  store i32 %72, ptr %74, align 4, !tbaa !24
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = add i64 %75, 1
  store i64 %76, ptr %5, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %70, %65
  store i32 0, ptr %7, align 4
  br label %78

78:                                               ; preds = %77, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %79 = load i32, ptr %7, align 4
  switch i32 %79, label %85 [
    i32 0, label %80
    i32 4, label %81
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80, %78
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = add i64 %82, 1
  store i64 %83, ptr %6, align 8, !tbaa !9
  br label %10, !llvm.loop !27

84:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void

85:                                               ; preds = %78
  unreachable
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL16areTexturesEqualRK13cgltf_textureS1_(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef nonnull align 8 dereferenceable(96)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !13, i64 0}
!12 = !{!"_ZTS11TextureInfo", !13, i64 0, !14, i64 4}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !6, i64 184}
!18 = !{!"_ZTS10cgltf_data", !19, i64 0, !6, i64 8, !20, i64 16, !6, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !6, i64 120, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !10, i64 192, !6, i64 200, !10, i64 208, !6, i64 216, !10, i64 224, !6, i64 232, !10, i64 240, !6, i64 248, !10, i64 256, !6, i64 264, !10, i64 272, !6, i64 280, !10, i64 288, !6, i64 296, !6, i64 304, !10, i64 312, !6, i64 320, !10, i64 328, !21, i64 336, !10, i64 360, !6, i64 368, !6, i64 376, !10, i64 384, !6, i64 392, !10, i64 400, !6, i64 408, !10, i64 416, !6, i64 424, !10, i64 432, !22, i64 440, !23, i64 464}
!19 = !{!"_ZTS15cgltf_file_type", !7, i64 0}
!20 = !{!"_ZTS11cgltf_asset", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !21, i64 32, !10, i64 56, !6, i64 64}
!21 = !{!"_ZTS12cgltf_extras", !10, i64 0, !10, i64 8, !6, i64 16}
!22 = !{!"_ZTS20cgltf_memory_options", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!"_ZTS18cgltf_file_options", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!12, !14, i64 4}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


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

%struct.cgltf_texture = type { ptr, ptr, ptr, i32, ptr, i32, ptr, %struct.cgltf_extras, i64, ptr }
%struct.cgltf_extras = type { i64, i64, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13mergeTexturesP10cgltf_dataRSt6vectorI11TextureInfoSaIS2_EE(ptr nocapture noundef readonly %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZNKSt6vectorI11TextureInfoSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #1
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 184
  br label %5

._crit_edge:                                      ; preds = %29, %2
  ret void

5:                                                ; preds = %.lr.ph30, %29
  %.02229 = phi i32 [ 0, %.lr.ph30 ], [ %.2, %29 ]
  %.02326 = phi i64 [ 0, %.lr.ph30 ], [ %30, %29 ]
  %6 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.02326) #1
  %7 = load i8, ptr %6, align 4, !tbaa !5, !range !11, !noundef !12
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %.preheader, label %29

.preheader:                                       ; preds = %5
  %.not31 = icmp eq i64 %.02326, 0
  br i1 %.not31, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %22
  %.025 = phi i64 [ %23, %22 ], [ 0, %.preheader ]
  %9 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.025) #1
  %10 = load i8, ptr %9, align 4, !tbaa !5, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %22

12:                                               ; preds = %.lr.ph
  %13 = load ptr, ptr %4, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.cgltf_texture, ptr %13, i64 %.02326
  %15 = getelementptr inbounds %struct.cgltf_texture, ptr %13, i64 %.025
  %16 = tail call noundef zeroext i1 @_ZL16areTexturesEqualRK13cgltf_textureS1_(ptr noundef nonnull align 8 dereferenceable(96) %14, ptr noundef nonnull align 8 dereferenceable(96) %15)
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  store i8 0, ptr %6, align 4, !tbaa !5
  %18 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorI11TextureInfoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.025) #1
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %20, ptr %21, align 4, !tbaa !22
  br label %.loopexit

22:                                               ; preds = %.lr.ph, %12
  %23 = add nuw i64 %.025, 1
  %exitcond.not = icmp eq i64 %23, %.02326
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %22, %.preheader, %17
  %24 = load i8, ptr %6, align 4, !tbaa !5, !range !11, !noundef !12
  %25 = trunc nuw i8 %24 to i1
  br i1 %25, label %26, label %29

26:                                               ; preds = %.loopexit
  %27 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %.02229, ptr %27, align 4, !tbaa !22
  %28 = add i32 %.02229, 1
  br label %29

29:                                               ; preds = %.loopexit, %26, %5
  %.2 = phi i32 [ %.02229, %5 ], [ %28, %26 ], [ %.02229, %.loopexit ]
  %30 = add nuw i64 %.02326, 1
  %31 = tail call noundef i64 @_ZNKSt6vectorI11TextureInfoSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #1
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %5, label %._crit_edge, !llvm.loop !25
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL16areTexturesEqualRK13cgltf_textureS1_(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0

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, !7, i64 0}
!6 = !{!"_ZTS11TextureInfo", !7, i64 0, !10, i64 4}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !16, i64 184}
!14 = !{!"_ZTS10cgltf_data", !15, i64 0, !16, i64 8, !17, i64 16, !16, i64 88, !19, i64 96, !16, i64 104, !19, i64 112, !16, i64 120, !19, i64 128, !16, i64 136, !19, i64 144, !16, i64 152, !19, i64 160, !16, i64 168, !19, i64 176, !16, i64 184, !19, i64 192, !16, i64 200, !19, i64 208, !16, i64 216, !19, i64 224, !16, i64 232, !19, i64 240, !16, i64 248, !19, i64 256, !16, i64 264, !19, i64 272, !16, i64 280, !19, i64 288, !16, i64 296, !16, i64 304, !19, i64 312, !16, i64 320, !19, i64 328, !18, i64 336, !19, i64 360, !16, i64 368, !16, i64 376, !19, i64 384, !16, i64 392, !19, i64 400, !16, i64 408, !19, i64 416, !16, i64 424, !19, i64 432, !20, i64 440, !21, i64 464}
!15 = !{!"_ZTS15cgltf_file_type", !8, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTS11cgltf_asset", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !18, i64 32, !19, i64 56, !16, i64 64}
!18 = !{!"_ZTS12cgltf_extras", !19, i64 0, !19, i64 8, !16, i64 16}
!19 = !{!"long", !8, i64 0}
!20 = !{!"_ZTS20cgltf_memory_options", !16, i64 0, !16, i64 8, !16, i64 16}
!21 = !{!"_ZTS18cgltf_file_options", !16, i64 0, !16, i64 8, !16, i64 16}
!22 = !{!6, !10, i64 4}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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