; 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 }

; 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 @spvReflectGetDescriptorSet(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %38

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

13:                                               ; preds = %34, %12
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %15, i32 0, i32 13
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %21, i32 0, i32 14
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %22, i64 0, i64 %24
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SpvReflectDescriptorSet, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %20
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %32, ptr %7, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !15

37:                                               ; preds = %19
  br label %38

38:                                               ; preds = %37, %3
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %53

41:                                               ; preds = %38
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  br label %50

45:                                               ; preds = %41
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  %48 = zext i1 %47 to i64
  %49 = select i1 %47, i32 5, i32 8
  br label %50

50:                                               ; preds = %45, %44
  %51 = phi i32 [ 0, %44 ], [ %49, %45 ]
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %50, %38
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %54
}

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 80}
!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 = !{!14, !10, i64 0}
!14 = !{!"SpvReflectDescriptorSet", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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.SpvReflectDescriptorSet = type { i32, i32, ptr }

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

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

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %0, i64 88
  %wide.trip.count = zext i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %7 = icmp ult i32 %5, 4
  br i1 %7, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %8

8:                                                ; preds = %8, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %8 ]
  %.019 = phi ptr [ null, %.lr.ph.new ], [ %spec.select.3, %8 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %8 ]
  %9 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %6, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, %1
  %spec.select = select i1 %11, ptr %9, ptr %.019
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %6, i64 0, i64 %indvars.iv.next
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, %1
  %spec.select.1 = select i1 %14, ptr %12, ptr %spec.select
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %15 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %6, i64 0, i64 %indvars.iv.next.1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i32 %16, %1
  %spec.select.2 = select i1 %17, ptr %15, ptr %spec.select.1
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %18 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %6, i64 0, i64 %indvars.iv.next.2
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, %1
  %spec.select.3 = select i1 %20, ptr %18, ptr %spec.select.2
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %8, !llvm.loop !13

.loopexit.loopexit.unr-lcssa:                     ; preds = %8, %.lr.ph
  %spec.select.lcssa.ph = phi ptr [ poison, %.lr.ph ], [ %spec.select.3, %8 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %8 ]
  %.019.unr = phi ptr [ null, %.lr.ph ], [ %spec.select.3, %8 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %.019.epil = phi ptr [ %spec.select.epil, %.epil.preheader ], [ %.019.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %21 = getelementptr inbounds [64 x %struct.SpvReflectDescriptorSet], ptr %6, i64 0, i64 %indvars.iv.epil
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %22, %1
  %spec.select.epil = select i1 %23, ptr %21, ptr %.019.epil
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.epil.preheader, !llvm.loop !15

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %3
  %.2 = phi ptr [ null, %3 ], [ null, %.preheader ], [ %spec.select.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, label %27, label %24

24:                                               ; preds = %.loopexit
  %.not17 = icmp eq ptr %.2, null
  %25 = select i1 %.not, i32 5, i32 8
  %26 = select i1 %.not17, i32 %25, i32 0
  store i32 %26, ptr %2, align 4, !tbaa !17
  br label %27

27:                                               ; preds = %24, %.loopexit
  ret ptr %.2
}

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, !7, i64 80}
!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 = !{!12, !7, i64 0}
!12 = !{!"SpvReflectDescriptorSet", !7, i64 0, !7, i64 4, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = !{!7, !7, i64 0}


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