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

; 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 ptr @_Z17get_node_for_meshjP6aiNode(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %10

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

17:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %33

18:                                               ; preds = %10
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.aiNode, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load i64, ptr %6, align 8, !tbaa !11
  %23 = getelementptr inbounds i32, ptr %21, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %18
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %28, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %33

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %6, align 8, !tbaa !11
  %32 = add i64 %31, 1
  store i64 %32, ptr %6, align 8, !tbaa !11
  br label %10, !llvm.loop !19

33:                                               ; preds = %27, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %34 = load i32, ptr %7, align 4
  switch i32 %34, label %69 [
    i32 2, label %35
    i32 1, label %67
  ]

35:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %61, %35
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.aiNode, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !21
  %41 = zext i32 %40 to i64
  %42 = icmp ult i64 %37, %41
  br i1 %42, label %44, label %43

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

44:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.aiNode, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !22
  %49 = load i64, ptr %8, align 8, !tbaa !11
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = call noundef ptr @_Z17get_node_for_meshjP6aiNode(i32 noundef %45, ptr noundef %51)
  store ptr %52, ptr %9, align 8, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !9
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %57

55:                                               ; preds = %44
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %58

57:                                               ; preds = %44
  store i32 0, ptr %7, align 4
  br label %58

58:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %59 = load i32, ptr %7, align 4
  switch i32 %59, label %64 [
    i32 0, label %60
  ]

60:                                               ; preds = %58
  br label %61

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

64:                                               ; preds = %58, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %65 = load i32, ptr %7, align 4
  switch i32 %65, label %69 [
    i32 5, label %66
    i32 1, label %67
  ]

66:                                               ; preds = %64
  store ptr null, ptr %3, align 8
  br label %67

67:                                               ; preds = %66, %64, %33
  %68 = load ptr, ptr %3, align 8
  ret ptr %68

69:                                               ; preds = %64, %33
  unreachable
}

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


; 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 ptr @_Z17get_node_for_meshjP6aiNode(i32 noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 1120
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = zext i32 %4 to i64
  %.not36 = icmp eq i32 %4, 0
  br i1 %.not36, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 1128
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  br label %15

8:                                                ; preds = %15
  %9 = add nuw nsw i64 %.02230, 1
  %exitcond.not = icmp eq i64 %9, %5
  br i1 %exitcond.not, label %.preheader, label %15, !llvm.loop !15

.preheader:                                       ; preds = %8, %2
  %10 = getelementptr inbounds i8, ptr %1, i64 1104
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = zext i32 %11 to i64
  %.not2831.not = icmp eq i32 %11, 0
  br i1 %.not2831.not, label %.thread, label %.lr.ph33

.lr.ph33:                                         ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %1, i64 1112
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  br label %21

15:                                               ; preds = %.lr.ph, %8
  %.02230 = phi i64 [ 0, %.lr.ph ], [ %9, %8 ]
  %16 = getelementptr inbounds i32, ptr %7, i64 %.02230
  %17 = load i32, ptr %16, align 4, !tbaa !19
  %18 = icmp eq i32 %17, %0
  br i1 %18, label %.thread, label %8

19:                                               ; preds = %21
  %20 = add nuw nsw i64 %.01832, 1
  %exitcond38.not = icmp eq i64 %20, %12
  br i1 %exitcond38.not, label %.thread, label %21, !llvm.loop !20

21:                                               ; preds = %.lr.ph33, %19
  %.01832 = phi i64 [ 0, %.lr.ph33 ], [ %20, %19 ]
  %22 = getelementptr inbounds ptr, ptr %14, i64 %.01832
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = tail call noundef ptr @_Z17get_node_for_meshjP6aiNode(i32 noundef %0, ptr noundef %23)
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %19, label %.thread

.thread:                                          ; preds = %15, %19, %21, %.preheader
  %.4 = phi ptr [ null, %.preheader ], [ null, %19 ], [ %24, %21 ], [ %1, %15 ]
  ret ptr %.4
}

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, !13, i64 1128}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !8, i64 1104}
!18 = !{!6, !13, i64 1112}
!19 = !{!8, !8, i64 0}
!20 = distinct !{!20, !16}
!21 = !{!13, !13, i64 0}


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