; 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 i32 @spvReflectEnumerateDescriptorBindings(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 5, ptr %4, align 4
  br label %57

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

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

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %51

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %23, i32 0, i32 11
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp ne i32 %22, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %20
  store i32 7, ptr %4, align 4
  br label %57

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

29:                                               ; preds = %47, %28
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp ult i32 %30, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %50

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %36, i32 0, i32 12
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %38, i64 %40
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  store ptr %42, ptr %46, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %47

47:                                               ; preds = %35
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !14

50:                                               ; preds = %34
  br label %56

51:                                               ; preds = %17
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %52, i32 0, i32 11
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %54, ptr %55, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %51, %50
  store i32 0, ptr %4, align 4
  br label %57

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

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 = distinct !{!14, !15}
!15 = !{!"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(argmem: readwrite) uwtable
define dso_local range(i32 0, 8) i32 @spvReflectEnumerateDescriptorBindings(ptr noundef readonly %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %.loopexit, label %6

6:                                                ; preds = %3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %36, label %7

7:                                                ; preds = %6
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %.not19 = icmp eq i32 %8, %10
  br i1 %.not19, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %7
  %.not21 = icmp eq i32 %8, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  %wide.trip.count = zext i32 %8 to i64
  %min.iters.check = icmp ult i32 %8, 10
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %12 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %2, i64 %12
  %scevgep23 = getelementptr i8, ptr %0, i64 80
  %bound0 = icmp ugt ptr %scevgep23, %2
  %bound1 = icmp ult ptr %11, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 4294967292
  %13 = load ptr, ptr %11, align 8, !tbaa !12, !alias.scope !13
  %broadcast.splatinsert25 = insertelement <2 x ptr> poison, ptr %13, i64 0
  %broadcast.splat26 = shufflevector <2 x ptr> %broadcast.splatinsert25, <2 x ptr> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %14 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, <2 x ptr> %broadcast.splat26, <2 x i64> %vec.ind
  %15 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, <2 x ptr> %broadcast.splat26, <2 x i64> %step.add
  %16 = getelementptr inbounds ptr, ptr %2, i64 %index
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  store <2 x ptr> %14, ptr %16, align 8, !tbaa !16, !alias.scope !17, !noalias !13
  store <2 x ptr> %15, ptr %17, align 8, !tbaa !16, !alias.scope !17, !noalias !13
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %19 = load ptr, ptr %11, align 8, !tbaa !12
  %20 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %19, i64 %indvars.iv.prol
  %21 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv.prol
  store ptr %20, ptr %21, align 8, !tbaa !16
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !23

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %22 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %24 = load ptr, ptr %11, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %24, i64 %indvars.iv
  %26 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  store ptr %25, ptr %26, align 8, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = load ptr, ptr %11, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %27, i64 %indvars.iv.next
  %29 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv.next
  store ptr %28, ptr %29, align 8, !tbaa !16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %30 = load ptr, ptr %11, align 8, !tbaa !12
  %31 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %30, i64 %indvars.iv.next.1
  %32 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv.next.1
  store ptr %31, ptr %32, align 8, !tbaa !16
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %33 = load ptr, ptr %11, align 8, !tbaa !12
  %34 = getelementptr inbounds %struct.SpvReflectDescriptorBinding, ptr %33, i64 %indvars.iv.next.2
  %35 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv.next.2
  store ptr %34, ptr %35, align 8, !tbaa !16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !25

36:                                               ; preds = %6
  %37 = getelementptr inbounds i8, ptr %0, i64 64
  %38 = load i32, ptr %37, align 8, !tbaa !9
  store i32 %38, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader, %36, %7, %3
  %.0 = phi i32 [ 5, %3 ], [ 7, %7 ], [ 0, %36 ], [ 0, %.preheader ], [ 0, %middle.block ], [ 0, %scalar.ph ], [ 0, %scalar.ph.prol.loopexit ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 64}
!10 = !{!"SpvReflectShaderModule", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 20, !11, i64 24, !6, i64 32, !6, i64 36, !11, i64 40, !11, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !11, i64 72, !6, i64 80, !7, i64 88, !6, i64 1112, !11, i64 1120, !6, i64 1128, !11, i64 1136, !6, i64 1144, !11, i64 1152, !11, i64 1160}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 72}
!13 = !{!14}
!14 = distinct !{!14, !15}
!15 = distinct !{!15, !"LVerDomain"}
!16 = !{!11, !11, i64 0}
!17 = !{!18}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.unroll.disable"}
!25 = distinct !{!25, !20, !21}


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