; 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_accessor = type { ptr, i32, i32, i32, i64, i64, i64, ptr, i32, [16 x float], i32, [16 x float], i32, %struct.cgltf_accessor_sparse, %struct.cgltf_extras, i64, ptr }
%struct.cgltf_accessor_sparse = type { i64, ptr, i64, i32, ptr, i64 }
%struct.cgltf_extras = type { i64, i64, 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
declare dso_local ptr @cgltf_buffer_view_data(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL26cgltf_component_read_indexPKv20cgltf_component_type(ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @cgltf_accessor_read_index(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.cgltf_accessor, ptr %8, i32 0, i32 12
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %45

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.cgltf_accessor, ptr %14, i32 0, i32 7
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  store i64 0, ptr %3, align 8
  br label %45

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cgltf_accessor, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = call ptr @cgltf_buffer_view_data(ptr noundef %22)
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

27:                                               ; preds = %19
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cgltf_accessor, ptr %28, i32 0, i32 4
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cgltf_accessor, ptr %31, i32 0, i32 6
  %33 = load i64, ptr %32, align 8, !tbaa !20
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = mul i64 %33, %34
  %36 = add i64 %30, %35
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 %36
  store ptr %38, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.cgltf_accessor, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !21
  %43 = call noundef i64 @_ZL26cgltf_component_read_indexPKv20cgltf_component_type(ptr noundef %39, i32 noundef %42)
  store i64 %43, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

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

45:                                               ; preds = %44, %18, %12
  %46 = load i64, ptr %3, align 8
  ret i64 %46
}

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 = { 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, !14, i64 192}
!12 = !{!"_ZTS14cgltf_accessor", !6, i64 0, !13, i64 8, !14, i64 12, !15, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !6, i64 48, !14, i64 56, !7, i64 60, !14, i64 124, !7, i64 128, !14, i64 192, !16, i64 200, !17, i64 248, !10, i64 272, !6, i64 280}
!13 = !{!"_ZTS20cgltf_component_type", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS10cgltf_type", !7, i64 0}
!16 = !{!"_ZTS21cgltf_accessor_sparse", !10, i64 0, !6, i64 8, !10, i64 16, !13, i64 24, !6, i64 32, !10, i64 40}
!17 = !{!"_ZTS12cgltf_extras", !10, i64 0, !10, i64 8, !6, i64 16}
!18 = !{!12, !6, i64 48}
!19 = !{!12, !10, i64 24}
!20 = !{!12, !10, i64 40}
!21 = !{!12, !13, i64 8}


; 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 nounwind uwtable
declare dso_local ptr @cgltf_buffer_view_data(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL26cgltf_component_read_indexPKv20cgltf_component_type(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @cgltf_accessor_read_index(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %23

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %8 = icmp eq ptr %7, null
  br i1 %8, label %23, label %9

9:                                                ; preds = %5
  %10 = tail call ptr @cgltf_buffer_view_data(ptr noundef nonnull %7)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %23, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load i64, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load i64, ptr %15, align 8, !tbaa !18
  %17 = mul i64 %16, %1
  %18 = getelementptr i8, ptr %10, i64 %14
  %19 = getelementptr i8, ptr %18, i64 %17
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = tail call noundef i64 @_ZL26cgltf_component_read_indexPKv20cgltf_component_type(ptr noundef %19, i32 noundef %21)
  br label %23

23:                                               ; preds = %12, %9, %5, %2
  %.1 = phi i64 [ 0, %2 ], [ 0, %5 ], [ %22, %12 ], [ 0, %9 ]
  ret i64 %.1
}

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, !11, i64 192}
!6 = !{!"_ZTS14cgltf_accessor", !7, i64 0, !10, i64 8, !11, i64 12, !12, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !7, i64 48, !11, i64 56, !8, i64 60, !11, i64 124, !8, i64 128, !11, i64 192, !14, i64 200, !15, i64 248, !13, i64 272, !7, i64 280}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS20cgltf_component_type", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_ZTS10cgltf_type", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"_ZTS21cgltf_accessor_sparse", !13, i64 0, !7, i64 8, !13, i64 16, !10, i64 24, !7, i64 32, !13, i64 40}
!15 = !{!"_ZTS12cgltf_extras", !13, i64 0, !13, i64 8, !7, i64 16}
!16 = !{!6, !7, i64 48}
!17 = !{!6, !13, i64 24}
!18 = !{!6, !13, i64 40}
!19 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass