; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

16:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %57

17:                                               ; preds = %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cgltf_accessor, ptr %18, i32 0, i32 7
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %26

22:                                               ; preds = %17
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = mul i64 %24, 4
  call void @llvm.memset.p0.i64(ptr align 4 %23, i8 0, i64 %25, i1 false)
  store i32 1, ptr %5, align 4
  br label %57

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cgltf_accessor, ptr %27, i32 0, i32 7
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = call ptr @cgltf_buffer_view_data(ptr noundef %29)
  store ptr %30, ptr %10, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %56

34:                                               ; preds = %26
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.cgltf_accessor, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cgltf_accessor, ptr %38, i32 0, i32 6
  %40 = load i64, ptr %39, align 8, !tbaa !20
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = mul i64 %40, %41
  %43 = add i64 %37, %42
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 %43
  store ptr %45, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.cgltf_accessor, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 8, !tbaa !21
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cgltf_accessor, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 8, !tbaa !22
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = call noundef i32 @_ZL23cgltf_element_read_uintPKh10cgltf_type20cgltf_component_typePjm(ptr noundef %46, i32 noundef %49, i32 noundef %52, ptr noundef %53, i64 noundef %54)
  store i32 %55, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %56

56:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %57

57:                                               ; preds = %56, %22, %16
  %58 = load i32, ptr %5, align 4
  ret i32 %58
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL23cgltf_element_read_uintPKh10cgltf_type20cgltf_component_typePjm(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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, !15, i64 16}
!22 = !{!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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = shl i64 %3, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 %12, i1 false)
  br label %29

13:                                               ; preds = %7
  %14 = tail call ptr @cgltf_buffer_view_data(ptr noundef nonnull %9)
  %15 = icmp eq ptr %14, null
  br i1 %15, label %29, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = mul i64 %20, %1
  %22 = getelementptr i8, ptr %14, i64 %18
  %23 = getelementptr i8, ptr %22, i64 %21
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = tail call noundef i32 @_ZL23cgltf_element_read_uintPKh10cgltf_type20cgltf_component_typePjm(ptr noundef %23, i32 noundef %25, i32 noundef %27, ptr noundef %2, i64 noundef %3)
  br label %29

29:                                               ; preds = %16, %13, %4, %11
  %.1 = phi i32 [ 1, %11 ], [ 0, %4 ], [ %28, %16 ], [ 0, %13 ]
  ret i32 %.1
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL23cgltf_element_read_uintPKh10cgltf_type20cgltf_component_typePjm(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !12, i64 16}
!20 = !{!6, !10, i64 8}


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