; LLVM IR from zeux/meshoptimizer :: gltf (parselib)

; 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.cgltf_primitive = type { i32, ptr, ptr, ptr, i64, ptr, i64, %struct.cgltf_extras, i32, %struct.cgltf_draco_mesh_compression, ptr, i64, i64, ptr }
%struct.cgltf_extras = type { i64, i64, ptr }
%struct.cgltf_draco_mesh_compression = type { ptr, ptr, i64 }
%struct.cgltf_attribute = type { ptr, i32, i32, 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 nounwind uwtable
define dso_local ptr @cgltf_find_accessor(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %43, %3
  %12 = load i64, ptr %8, align 8, !tbaa !13
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.cgltf_primitive, ptr %13, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = icmp ult i64 %12, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 2, ptr %9, align 4
  br label %46

18:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.cgltf_primitive, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load i64, ptr %8, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.cgltf_attribute, ptr %21, i64 %22
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.cgltf_attribute, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !21
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %39

29:                                               ; preds = %18
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cgltf_attribute, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !23
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %29
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cgltf_attribute, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !24
  store ptr %38, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %40

39:                                               ; preds = %29, %18
  store i32 0, ptr %9, align 4
  br label %40

40:                                               ; preds = %39, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %41 = load i32, ptr %9, align 4
  switch i32 %41, label %46 [
    i32 0, label %42
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %8, align 8, !tbaa !13
  %45 = add i64 %44, 1
  store i64 %45, ptr %8, align 8, !tbaa !13
  br label %11, !llvm.loop !25

46:                                               ; preds = %40, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %47 = load i32, ptr %9, align 4
  switch i32 %47, label %51 [
    i32 2, label %48
    i32 1, label %49
  ]

48:                                               ; preds = %46
  store ptr null, ptr %4, align 8
  br label %49

49:                                               ; preds = %48, %46
  %50 = load ptr, ptr %4, align 8
  ret ptr %50

51:                                               ; preds = %46
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"_ZTS20cgltf_attribute_type", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !14, i64 32}
!16 = !{!"_ZTS15cgltf_primitive", !17, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 40, !14, i64 48, !18, i64 56, !12, i64 80, !19, i64 88, !6, i64 112, !14, i64 120, !14, i64 128, !6, i64 136}
!17 = !{!"_ZTS20cgltf_primitive_type", !7, i64 0}
!18 = !{!"_ZTS12cgltf_extras", !14, i64 0, !14, i64 8, !6, i64 16}
!19 = !{!"_ZTS28cgltf_draco_mesh_compression", !6, i64 0, !6, i64 8, !14, i64 16}
!20 = !{!16, !6, i64 24}
!21 = !{!22, !10, i64 8}
!22 = !{!"_ZTS15cgltf_attribute", !6, i64 0, !10, i64 8, !12, i64 12, !6, i64 16}
!23 = !{!22, !12, i64 12}
!24 = !{!22, !6, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"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.cgltf_attribute = type { ptr, i32, i32, ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @cgltf_find_accessor(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not18.not = icmp eq i64 %5, 0
  br i1 %.not18.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  br label %8

8:                                                ; preds = %.lr.ph, %20
  %.01419 = phi i64 [ 0, %.lr.ph ], [ %21, %20 ]
  %9 = getelementptr inbounds %struct.cgltf_attribute, ptr %7, i64 %.01419
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !16
  %12 = icmp eq i32 %11, %1
  br i1 %12, label %13, label %20

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %9, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !19
  %16 = icmp eq i32 %15, %2
  br i1 %16, label %17, label %20

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %9, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  br label %.loopexit

20:                                               ; preds = %13, %8
  %21 = add nuw i64 %.01419, 1
  %exitcond.not = icmp eq i64 %21, %5
  br i1 %exitcond.not, label %.loopexit, label %8, !llvm.loop !21

.loopexit:                                        ; preds = %20, %3, %17
  %spec.select = phi ptr [ %19, %17 ], [ null, %3 ], [ null, %20 ]
  ret ptr %spec.select
}

attributes #0 = { mustprogress nofree norecurse 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, !11, i64 32}
!6 = !{!"_ZTS15cgltf_primitive", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !10, i64 40, !11, i64 48, !12, i64 56, !13, i64 80, !14, i64 88, !10, i64 112, !11, i64 120, !11, i64 128, !10, i64 136}
!7 = !{!"_ZTS20cgltf_primitive_type", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_ZTS12cgltf_extras", !11, i64 0, !11, i64 8, !10, i64 16}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_ZTS28cgltf_draco_mesh_compression", !10, i64 0, !10, i64 8, !11, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!17, !18, i64 8}
!17 = !{!"_ZTS15cgltf_attribute", !10, i64 0, !18, i64 8, !13, i64 12, !10, i64 16}
!18 = !{!"_ZTS20cgltf_attribute_type", !8, i64 0}
!19 = !{!17, !13, i64 12}
!20 = !{!17, !10, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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