; LLVM IR from Overload-Technologies/Overload :: Dependencies/assimp/code/AssetLib/FBX/FBXExporter.ll (Z14count_texturesPK7aiScene)

; 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.aiScene = type { i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, ptr, %struct.aiString, i32, ptr, ptr }
%struct.aiString = type { i32, [1024 x i8] }

; 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z14count_texturesPK7aiScene(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %41, %1
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.aiScene, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %9, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.aiScene, ptr %17, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %19, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %37, %16
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = icmp ult i64 %24, 18
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %40

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = trunc i64 %29 to i32
  %31 = call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %28, i32 noundef %30)
  %32 = icmp ugt i32 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %27
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = add i64 %34, 1
  store i64 %35, ptr %3, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %33, %27
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %7, align 8, !tbaa !9
  br label %23, !llvm.loop !16

40:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %4, align 8, !tbaa !9
  br label %8, !llvm.loop !18

44:                                               ; preds = %15
  %45 = load i64, ptr %3, align 8, !tbaa !9
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 32}
!12 = !{!"_ZTS7aiScene", !13, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !13, i64 48, !6, i64 56, !13, i64 64, !6, i64 72, !13, i64 80, !6, i64 88, !13, i64 96, !6, i64 104, !6, i64 112, !14, i64 120, !13, i64 1148, !6, i64 1152, !6, i64 1160}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS8aiString", !13, i64 0, !7, i64 4}
!15 = !{!12, !6, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z14count_texturesPK7aiScene(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not16 = icmp eq i32 %3, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  br label %5

._crit_edge:                                      ; preds = %5, %1
  %.010.lcssa = phi i64 [ 0, %1 ], [ %spec.select.16, %5 ]
  ret i64 %.010.lcssa

5:                                                ; preds = %.lr.ph, %5
  %.01015 = phi i64 [ 0, %.lr.ph ], [ %spec.select.16, %5 ]
  %.01114 = phi i64 [ 0, %.lr.ph ], [ %43, %5 ]
  %6 = load ptr, ptr %4, align 8, !tbaa !12
  %7 = getelementptr inbounds ptr, ptr %6, i64 %.01114
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 1)
  %.not = icmp ne i32 %9, 0
  %10 = zext i1 %.not to i64
  %spec.select = add i64 %.01015, %10
  %11 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 2)
  %.not.1 = icmp ne i32 %11, 0
  %12 = zext i1 %.not.1 to i64
  %spec.select.1 = add i64 %spec.select, %12
  %13 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 3)
  %.not.2 = icmp ne i32 %13, 0
  %14 = zext i1 %.not.2 to i64
  %spec.select.2 = add i64 %spec.select.1, %14
  %15 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 4)
  %.not.3 = icmp ne i32 %15, 0
  %16 = zext i1 %.not.3 to i64
  %spec.select.3 = add i64 %spec.select.2, %16
  %17 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 5)
  %.not.4 = icmp ne i32 %17, 0
  %18 = zext i1 %.not.4 to i64
  %spec.select.4 = add i64 %spec.select.3, %18
  %19 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 6)
  %.not.5 = icmp ne i32 %19, 0
  %20 = zext i1 %.not.5 to i64
  %spec.select.5 = add i64 %spec.select.4, %20
  %21 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 7)
  %.not.6 = icmp ne i32 %21, 0
  %22 = zext i1 %.not.6 to i64
  %spec.select.6 = add i64 %spec.select.5, %22
  %23 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 8)
  %.not.7 = icmp ne i32 %23, 0
  %24 = zext i1 %.not.7 to i64
  %spec.select.7 = add i64 %spec.select.6, %24
  %25 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 9)
  %.not.8 = icmp ne i32 %25, 0
  %26 = zext i1 %.not.8 to i64
  %spec.select.8 = add i64 %spec.select.7, %26
  %27 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 10)
  %.not.9 = icmp ne i32 %27, 0
  %28 = zext i1 %.not.9 to i64
  %spec.select.9 = add i64 %spec.select.8, %28
  %29 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 11)
  %.not.10 = icmp ne i32 %29, 0
  %30 = zext i1 %.not.10 to i64
  %spec.select.10 = add i64 %spec.select.9, %30
  %31 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 12)
  %.not.11 = icmp ne i32 %31, 0
  %32 = zext i1 %.not.11 to i64
  %spec.select.11 = add i64 %spec.select.10, %32
  %33 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 13)
  %.not.12 = icmp ne i32 %33, 0
  %34 = zext i1 %.not.12 to i64
  %spec.select.12 = add i64 %spec.select.11, %34
  %35 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 14)
  %.not.13 = icmp ne i32 %35, 0
  %36 = zext i1 %.not.13 to i64
  %spec.select.13 = add i64 %spec.select.12, %36
  %37 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 15)
  %.not.14 = icmp ne i32 %37, 0
  %38 = zext i1 %.not.14 to i64
  %spec.select.14 = add i64 %spec.select.13, %38
  %39 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 16)
  %.not.15 = icmp ne i32 %39, 0
  %40 = zext i1 %.not.15 to i64
  %spec.select.15 = add i64 %spec.select.14, %40
  %41 = tail call noundef i32 @_ZNK10aiMaterial15GetTextureCountE13aiTextureType(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef 17)
  %.not.16 = icmp ne i32 %41, 0
  %42 = zext i1 %.not.16 to i64
  %spec.select.16 = add i64 %spec.select.15, %42
  %43 = add nuw nsw i64 %.01114, 1
  %44 = load i32, ptr %2, align 8, !tbaa !5
  %45 = zext i32 %44 to i64
  %46 = icmp ult i64 %43, %45
  br i1 %46, label %5, label %._crit_edge, !llvm.loop !14
}

attributes #0 = { inlinehint 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 = { 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" }

!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 32}
!6 = !{!"_ZTS7aiScene", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56, !7, i64 64, !10, i64 72, !7, i64 80, !10, i64 88, !7, i64 96, !10, i64 104, !10, i64 112, !11, i64 120, !7, i64 1148, !10, i64 1152, !10, i64 1160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS8aiString", !7, i64 0, !8, i64 4}
!12 = !{!6, !10, i64 40}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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