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

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

; 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 noundef i64 @_Z11count_nodesPK6aiNodeS1_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = 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) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %7, %8
  br i1 %9, label %10, label %15

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.aiNode, ptr %11, i32 0, i32 5
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = zext i32 %13 to i64
  store i64 %14, ptr %5, align 8, !tbaa !15
  br label %28

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.aiNode, ptr %16, i32 0, i32 5
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp ugt i32 %18, 1
  br i1 %19, label %20, label %26

20:                                               ; preds = %15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.aiNode, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = add i32 %23, 1
  %25 = zext i32 %24 to i64
  store i64 %25, ptr %5, align 8, !tbaa !15
  br label %27

26:                                               ; preds = %15
  store i64 1, ptr %5, align 8, !tbaa !15
  br label %27

27:                                               ; preds = %26, %20
  br label %28

28:                                               ; preds = %27, %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %48, %28
  %30 = load i64, ptr %6, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.aiNode, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = zext i32 %33 to i64
  %35 = icmp ult i64 %30, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %51

37:                                               ; preds = %29
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.aiNode, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load i64, ptr %6, align 8, !tbaa !15
  %42 = getelementptr inbounds ptr, ptr %40, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = call noundef i64 @_Z11count_nodesPK6aiNodeS1_(ptr noundef %43, ptr noundef %44)
  %46 = load i64, ptr %5, align 8, !tbaa !15
  %47 = add i64 %46, %45
  store i64 %47, ptr %5, align 8, !tbaa !15
  br label %48

48:                                               ; preds = %37
  %49 = load i64, ptr %6, align 8, !tbaa !15
  %50 = add i64 %49, 1
  store i64 %50, ptr %6, align 8, !tbaa !15
  br label %29, !llvm.loop !19

51:                                               ; preds = %36
  %52 = load i64, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %52
}

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 = { 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, !12, i64 1120}
!10 = !{!"_ZTS6aiNode", !11, i64 0, !13, i64 1028, !6, i64 1096, !12, i64 1104, !6, i64 1112, !12, i64 1120, !6, i64 1128, !6, i64 1136}
!11 = !{!"_ZTS8aiString", !12, i64 0, !7, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS12aiMatrix4x4tIfE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !14, i64 48, !14, i64 52, !14, i64 56, !14, i64 60}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !12, i64 1104}
!18 = !{!10, !6, i64 1112}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z11count_nodesPK6aiNodeS1_(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, %1
  %4 = getelementptr inbounds i8, ptr %0, i64 1120
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp ugt i32 %5, 1
  %7 = add i32 %5, 1
  %spec.select = select i1 %6, i32 %7, i32 1
  %.012.shrunk = select i1 %3, i32 %5, i32 %spec.select
  %.012 = zext i32 %.012.shrunk to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 1104
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = zext i32 %9 to i64
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 1112
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  br label %13

._crit_edge:                                      ; preds = %13, %2
  %.1.lcssa = phi i64 [ %.012, %2 ], [ %17, %13 ]
  ret i64 %.1.lcssa

13:                                               ; preds = %.lr.ph, %13
  %.017 = phi i64 [ 0, %.lr.ph ], [ %18, %13 ]
  %.116 = phi i64 [ %.012, %.lr.ph ], [ %17, %13 ]
  %14 = getelementptr inbounds ptr, ptr %12, i64 %.017
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = tail call noundef i64 @_Z11count_nodesPK6aiNodeS1_(ptr noundef %15, ptr noundef %1)
  %17 = add i64 %16, %.116
  %18 = add nuw nsw i64 %.017, 1
  %exitcond.not = icmp eq i64 %18, %10
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !17
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, 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, !8, i64 1120}
!6 = !{!"_ZTS6aiNode", !7, i64 0, !11, i64 1028, !13, i64 1096, !8, i64 1104, !13, i64 1112, !8, i64 1120, !13, i64 1128, !13, i64 1136}
!7 = !{!"_ZTS8aiString", !8, i64 0, !9, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS12aiMatrix4x4tIfE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60}
!12 = !{!"float", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!6, !8, i64 1104}
!15 = !{!6, !13, i64 1112}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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