; 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.SpvReflectInterfaceVariable = type { i32, ptr, i32, i32, ptr, i32, i32, %struct.SpvReflectNumericTraits, %struct.SpvReflectArrayTraits, i32, ptr, i32, ptr, %struct.anon.0 }
%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.anon.0 = type { 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 @spvReflectGetInputVariableByLocation(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 8, ptr %17, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %16, %13
  store ptr null, ptr %4, align 8
  br label %66

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %49

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

23:                                               ; preds = %45, %22
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %25, i32 0, i32 15
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SpvReflectShaderModule, ptr %31, i32 0, i32 16
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %33, i64 %35
  store ptr %36, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %30
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %43, ptr %8, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %42, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = add i32 %46, 1
  store i32 %47, ptr %9, align 4, !tbaa !9
  br label %23, !llvm.loop !22

48:                                               ; preds = %29
  br label %49

49:                                               ; preds = %48, %19
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %64

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

55:                                               ; preds = %52
  br label %61

56:                                               ; preds = %52
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, i32 5, i32 8
  br label %61

61:                                               ; preds = %56, %55
  %62 = phi i32 [ 0, %55 ], [ %60, %56 ]
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %62, ptr %63, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %61, %49
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %65, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %66

66:                                               ; preds = %64, %18
  %67 = load ptr, ptr %4, align 8
  ret ptr %67
}

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 1112}
!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 1120}
!14 = !{!15, !10, i64 16}
!15 = !{!"SpvReflectInterfaceVariable", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !10, i64 36, !16, i64 40, !20, i64 64, !10, i64 200, !6, i64 208, !10, i64 216, !6, i64 224, !21, i64 232}
!16 = !{!"SpvReflectNumericTraits", !17, i64 0, !18, i64 8, !19, i64 12}
!17 = !{!"Scalar", !10, i64 0, !10, i64 4}
!18 = !{!"Vector", !10, i64 0}
!19 = !{!"Matrix", !10, i64 0, !10, i64 4, !10, i64 8}
!20 = !{!"SpvReflectArrayTraits", !10, i64 0, !7, i64 4, !10, i64 132}
!21 = !{!"", !10, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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.SpvReflectInterfaceVariable = type { i32, ptr, i32, i32, ptr, i32, i32, %struct.SpvReflectNumericTraits, %struct.SpvReflectArrayTraits, i32, ptr, i32, ptr, %struct.anon.0 }
%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.anon.0 = type { i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @spvReflectGetInputVariableByLocation(ptr noundef readonly %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, -1
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %36, label %.sink.split

6:                                                ; preds = %3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %0, i64 1120
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %wide.trip.count = zext i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %11 = icmp ult i32 %8, 4
  br i1 %11, 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 %12

12:                                               ; preds = %12, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %12 ]
  %.01826 = phi ptr [ null, %.lr.ph.new ], [ %spec.select.3, %12 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %12 ]
  %13 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %10, i64 %indvars.iv
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = icmp eq i32 %15, %1
  %spec.select = select i1 %16, ptr %13, ptr %.01826
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %10, i64 %indvars.iv.next
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = icmp eq i32 %19, %1
  %spec.select.1 = select i1 %20, ptr %17, ptr %spec.select
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %21 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %10, i64 %indvars.iv.next.1
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load i32, ptr %22, align 8, !tbaa !12
  %24 = icmp eq i32 %23, %1
  %spec.select.2 = select i1 %24, ptr %21, ptr %spec.select.1
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %25 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %10, i64 %indvars.iv.next.2
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = icmp eq i32 %27, %1
  %spec.select.3 = select i1 %28, ptr %25, 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 %12, !llvm.loop !20

.loopexit.loopexit.unr-lcssa:                     ; preds = %12, %.lr.ph
  %spec.select.lcssa.ph = phi ptr [ poison, %.lr.ph ], [ %spec.select.3, %12 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %12 ]
  %.01826.unr = phi ptr [ null, %.lr.ph ], [ %spec.select.3, %12 ]
  %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 ]
  %.01826.epil = phi ptr [ %spec.select.epil, %.epil.preheader ], [ %.01826.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %29 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %10, i64 %indvars.iv.epil
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !12
  %32 = icmp eq i32 %31, %1
  %spec.select.epil = select i1 %32, ptr %29, ptr %.01826.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 !22

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %6
  %.2 = phi ptr [ null, %6 ], [ null, %.preheader ], [ %spec.select.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %36, label %33

33:                                               ; preds = %.loopexit
  %.not24 = icmp eq ptr %.2, null
  %34 = select i1 %.not, i32 5, i32 8
  %35 = select i1 %.not24, i32 %34, i32 0
  br label %.sink.split

.sink.split:                                      ; preds = %5, %33
  %.sink = phi i32 [ %35, %33 ], [ 8, %5 ]
  %.0.ph = phi ptr [ %.2, %33 ], [ null, %5 ]
  store i32 %.sink, ptr %2, align 4, !tbaa !24
  br label %36

36:                                               ; preds = %.sink.split, %.loopexit, %5
  %.0 = phi ptr [ null, %5 ], [ %.2, %.loopexit ], [ %.0.ph, %.sink.split ]
  ret ptr %.0
}

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 1112}
!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 1120}
!12 = !{!13, !7, i64 16}
!13 = !{!"SpvReflectInterfaceVariable", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !10, i64 24, !7, i64 32, !7, i64 36, !14, i64 40, !18, i64 64, !7, i64 200, !10, i64 208, !7, i64 216, !10, i64 224, !19, i64 232}
!14 = !{!"SpvReflectNumericTraits", !15, i64 0, !16, i64 8, !17, i64 12}
!15 = !{!"Scalar", !7, i64 0, !7, i64 4}
!16 = !{!"Vector", !7, i64 0}
!17 = !{!"Matrix", !7, i64 0, !7, i64 4, !7, i64 8}
!18 = !{!"SpvReflectArrayTraits", !7, i64 0, !8, i64 4, !7, i64 132}
!19 = !{!"", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}
!24 = !{!7, !7, i64 0}


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