; LLVM IR from ronan-kerviche/glip-lib :: GLIP-Lib/src/Core (HdlTextureTools)

; 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.Glip::CoreGL::HdlTextureFormatDescriptor" = type { i32, i32, i32, i32, i32, [4 x i32], [4 x i32], [4 x i32], i8, i8, i8 }

@_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList24textureFormatDescriptorsE = external dso_local constant [125 x %"struct.Glip::CoreGL::HdlTextureFormatDescriptor"], align 16
@_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i = external hidden global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEv() #0 align 2 {
  %1 = load i32, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 0
  br i1 %2, label %3, label %16

3:                                                ; preds = %0
  store i32 0, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %12, %3
  %5 = load i32, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [125 x %"struct.Glip::CoreGL::HdlTextureFormatDescriptor"], ptr @_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList24textureFormatDescriptorsE, i64 0, i64 %6
  %8 = getelementptr inbounds %"struct.Glip::CoreGL::HdlTextureFormatDescriptor", ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %4
  br label %12

12:                                               ; preds = %11
  %13 = load i32, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  br label %4, !llvm.loop !12

15:                                               ; preds = %4
  br label %16

16:                                               ; preds = %15, %0
  %17 = load i32, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  ret i32 %17
}

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

!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 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN4Glip6CoreGL26HdlTextureFormatDescriptorE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !7, i64 20, !7, i64 36, !7, i64 52, !11, i64 68, !11, i64 69, !11, i64 70}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%"struct.Glip::CoreGL::HdlTextureFormatDescriptor" = type { i32, i32, i32, i32, i32, [4 x i32], [4 x i32], [4 x i32], i8, i8, i8 }

@_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList24textureFormatDescriptorsE = external dso_local local_unnamed_addr constant [125 x %"struct.Glip::CoreGL::HdlTextureFormatDescriptor"], align 16
@_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEv() local_unnamed_addr #0 align 2 {
  %1 = load i32, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 0
  br i1 %2, label %.preheader, label %6

.preheader:                                       ; preds = %0, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %0 ]
  %3 = getelementptr inbounds [125 x %"struct.Glip::CoreGL::HdlTextureFormatDescriptor"], ptr @_ZN4Glip6CoreGL31HdlTextureFormatDescriptorsList24textureFormatDescriptorsE, i64 0, i64 %indvars.iv
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %.not = icmp eq i32 %4, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %.preheader
  %5 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %5, ptr @_ZZN4Glip6CoreGL31HdlTextureFormatDescriptorsList17getNumDescriptorsEvE1i, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %.loopexit, %0
  %7 = phi i32 [ %5, %.loopexit ], [ %1, %0 ]
  ret i32 %7
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN4Glip6CoreGL26HdlTextureFormatDescriptorE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !7, i64 20, !7, i64 36, !7, i64 52, !11, i64 68, !11, i64 69, !11, i64 70}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SimplifyCFGPass