; LLVM IR from Dragons-Lake/REI :: sources/REI/3rdParty/spirv_reflect (spirv_reflect)

; 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.SpvReflectShaderModule = type { i32, ptr, i32, i32, ptr, i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, [64 x %struct.SpvReflectDescriptorSet], i32, ptr, i32, ptr, i32, ptr, ptr }
%struct.SpvReflectDescriptorSet = type { i32, i32, ptr }
%struct.SpvReflectDescriptorBinding = type { i32, ptr, i32, i32, i32, i32, i32, %struct.SpvReflectImageTraits, %struct.SpvReflectBlockVariable, %struct.SpvReflectBindingArrayTraits, i32, i32, i32, ptr, ptr, %struct.anon }
%struct.SpvReflectImageTraits = type { i32, i32, i32, i32, i32, i32 }
%struct.SpvReflectBlockVariable = type { i32, ptr, i32, i32, i32, i32, i32, %struct.SpvReflectNumericTraits, %struct.SpvReflectArrayTraits, i32, i32, ptr, ptr }
%struct.SpvReflectNumericTraits = type { %struct.Scalar, %struct.Vector, %struct.Matrix }
%struct.Scalar = type { i32, i32 }
%struct.Vector = type { i32 }
%struct.Matrix = type { i32, i32, i32 }
%struct.SpvReflectArrayTraits = type { i32, [32 x i32], i32 }
%struct.SpvReflectBindingArrayTraits = type { i32, [32 x i32] }
%struct.anon = type { i32, i32 }

; 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: nounwind uwtable
define dso_local ptr @spvReflectGetDescriptorBinding(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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 !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store ptr null, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %52

15:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %47, %15
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i32 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 2, ptr %11, align 4
  br label %50

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %24, i32 0, i32 12
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %26, i64 %28
  store ptr %29, ptr %12, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %43

35:                                               ; preds = %23
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !25
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %35
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %42, ptr %9, align 8, !tbaa !5
  store i32 2, ptr %11, align 4
  br label %44

43:                                               ; preds = %35, %23
  store i32 0, ptr %11, align 4
  br label %44

44:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %45 = load i32, ptr %11, align 4
  switch i32 %45, label %50 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !9
  br label %16, !llvm.loop !26

50:                                               ; preds = %44, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51, %4
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %67

55:                                               ; preds = %52
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  br label %64

59:                                               ; preds = %55
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = icmp eq ptr %60, null
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, i32 5, i32 8
  br label %64

64:                                               ; preds = %59, %58
  %65 = phi i32 [ 0, %58 ], [ %63, %59 ]
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %52
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret ptr %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"SpvReflectShaderModule", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !10, i64 80, !7, i64 88, !10, i64 1112, !6, i64 1120, !10, i64 1128, !6, i64 1136, !10, i64 1144, !6, i64 1152, !6, i64 1160}
!13 = !{!12, !6, i64 72}
!14 = !{!15, !10, i64 16}
!15 = !{!"SpvReflectDescriptorBinding", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !16, i64 36, !17, i64 64, !23, i64 288, !10, i64 420, !10, i64 424, !10, i64 428, !6, i64 432, !6, i64 440, !24, i64 448}
!16 = !{!"SpvReflectImageTraits", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!17 = !{!"SpvReflectBlockVariable", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !18, i64 36, !22, i64 60, !10, i64 196, !10, i64 200, !6, i64 208, !6, i64 216}
!18 = !{!"SpvReflectNumericTraits", !19, i64 0, !20, i64 8, !21, i64 12}
!19 = !{!"Scalar", !10, i64 0, !10, i64 4}
!20 = !{!"Vector", !10, i64 0}
!21 = !{!"Matrix", !10, i64 0, !10, i64 4, !10, i64 8}
!22 = !{!"SpvReflectArrayTraits", !10, i64 0, !7, i64 4, !10, i64 132}
!23 = !{!"SpvReflectBindingArrayTraits", !10, i64 0, !7, i64 4}
!24 = !{!"", !10, i64 0, !10, i64 4}
!25 = !{!15, !10, i64 24}
!26 = distinct !{!26, !27}
!27 = !{!"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.SpvReflectDescriptorBinding = type { i32, ptr, i32, i32, i32, i32, i32, %struct.SpvReflectImageTraits, %struct.SpvReflectBlockVariable, %struct.SpvReflectBindingArrayTraits, i32, i32, i32, ptr, ptr, %struct.anon }
%struct.SpvReflectImageTraits = type { i32, i32, i32, i32, i32, i32 }
%struct.SpvReflectBlockVariable = type { i32, ptr, i32, i32, i32, i32, i32, %struct.SpvReflectNumericTraits, %struct.SpvReflectArrayTraits, i32, i32, ptr, ptr }
%struct.SpvReflectNumericTraits = type { %struct.Scalar, %struct.Vector, %struct.Matrix }
%struct.Scalar = type { i32, i32 }
%struct.Vector = type { i32 }
%struct.Matrix = type { i32, i32, i32 }
%struct.SpvReflectArrayTraits = type { i32, [32 x i32], i32 }
%struct.SpvReflectBindingArrayTraits = type { i32, [32 x i32] }
%struct.anon = type { i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @spvReflectGetDescriptorBinding(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not28 = icmp eq i32 %6, 0
  br i1 %.not28, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %wide.trip.count = zext i32 %6 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %18 ]
  %10 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %8, i64 %indvars.iv
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = icmp eq i32 %12, %1
  br i1 %13, label %14, label %18

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %10, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !23
  %17 = icmp eq i32 %16, %2
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %9, %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %9, !llvm.loop !24

.loopexit:                                        ; preds = %18, %14, %.preheader, %4
  %.3 = phi ptr [ null, %4 ], [ null, %.preheader ], [ null, %18 ], [ %10, %14 ]
  %.not20 = icmp eq ptr %3, null
  br i1 %.not20, label %22, label %19

19:                                               ; preds = %.loopexit
  %.not21 = icmp eq ptr %.3, null
  %20 = select i1 %.not, i32 5, i32 8
  %21 = select i1 %.not21, i32 %20, i32 0
  store i32 %21, ptr %3, align 4, !tbaa !26
  br label %22

22:                                               ; preds = %19, %.loopexit
  ret ptr %.3
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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, !7, i64 64}
!6 = !{!"SpvReflectShaderModule", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !10, i64 24, !7, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !7, i64 56, !7, i64 60, !7, i64 64, !10, i64 72, !7, i64 80, !8, i64 88, !7, i64 1112, !10, i64 1120, !7, i64 1128, !10, i64 1136, !7, i64 1144, !10, i64 1152, !10, i64 1160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 72}
!12 = !{!13, !7, i64 16}
!13 = !{!"SpvReflectDescriptorBinding", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !14, i64 36, !15, i64 64, !21, i64 288, !7, i64 420, !7, i64 424, !7, i64 428, !10, i64 432, !10, i64 440, !22, i64 448}
!14 = !{!"SpvReflectImageTraits", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!15 = !{!"SpvReflectBlockVariable", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !16, i64 36, !20, i64 60, !7, i64 196, !7, i64 200, !10, i64 208, !10, i64 216}
!16 = !{!"SpvReflectNumericTraits", !17, i64 0, !18, i64 8, !19, i64 12}
!17 = !{!"Scalar", !7, i64 0, !7, i64 4}
!18 = !{!"Vector", !7, i64 0}
!19 = !{!"Matrix", !7, i64 0, !7, i64 4, !7, i64 8}
!20 = !{!"SpvReflectArrayTraits", !7, i64 0, !8, i64 4, !7, i64 132}
!21 = !{!"SpvReflectBindingArrayTraits", !7, i64 0, !8, i64 4}
!22 = !{!"", !7, i64 0, !7, i64 4}
!23 = !{!13, !7, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!7, !7, i64 0}


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