; 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.SpvReflectEntryPoint = type { ptr, i32, i32, i32, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, %struct.LocalSize, i32, i32 }
%struct.LocalSize = type { i32, i32, i32 }
%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
declare dso_local ptr @spvReflectGetEntryPoint(ptr noundef, ptr noundef) #1

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

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call ptr @spvReflectGetEntryPoint(ptr noundef %18, ptr noundef %19)
  store ptr %20, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %17
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 8, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %26, %23
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %56

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

30:                                               ; preds = %52, %29
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %32, i32 0, i32 8
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = icmp ult i32 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %55

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %38, i32 0, i32 9
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct.SpvReflectDescriptorSet, ptr %40, i64 %42
  store ptr %43, ptr %14, align 8, !tbaa !5
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SpvReflectDescriptorSet, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !15
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %37
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %50, ptr %10, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %30, !llvm.loop !17

55:                                               ; preds = %36
  store i32 0, ptr %12, align 4
  br label %56

56:                                               ; preds = %55, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %57 = load i32, ptr %12, align 4
  switch i32 %57, label %76 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58, %4
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %74

62:                                               ; preds = %59
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %66

65:                                               ; preds = %62
  br label %71

66:                                               ; preds = %62
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = icmp eq ptr %67, null
  %69 = zext i1 %68 to i64
  %70 = select i1 %68, i32 5, i32 8
  br label %71

71:                                               ; preds = %66, %65
  %72 = phi i32 [ 0, %65 ], [ %70, %66 ]
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %71, %59
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %75, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %76

76:                                               ; preds = %74, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %77 = load ptr, ptr %5, align 8
  ret ptr %77
}

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 48}
!12 = !{!"SpvReflectEntryPoint", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !6, i64 88, !13, i64 96, !10, i64 108, !10, i64 112}
!13 = !{!"LocalSize", !10, i64 0, !10, i64 4, !10, i64 8}
!14 = !{!12, !6, i64 56}
!15 = !{!16, !10, i64 0}
!16 = !{!"SpvReflectDescriptorSet", !10, i64 0, !10, i64 4, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
declare dso_local ptr @spvReflectGetEntryPoint(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @spvReflectGetEntryPointDescriptorSet(ptr noundef %0, ptr 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 %5

5:                                                ; preds = %4
  %6 = tail call ptr @spvReflectGetEntryPoint(ptr noundef nonnull %0, ptr noundef %1)
  %.not28 = icmp eq ptr %6, null
  br i1 %.not28, label %12, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %6, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %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 %13

12:                                               ; preds = %5
  %.not27 = icmp eq ptr %3, null
  br i1 %.not27, label %.thread, label %.thread.sink.split

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

.loopexit.loopexit.unr-lcssa:                     ; preds = %13, %.lr.ph
  %spec.select.lcssa.ph = phi ptr [ poison, %.lr.ph ], [ %spec.select.3, %13 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %13 ]
  %.02232.unr = phi ptr [ null, %.lr.ph ], [ %spec.select.3, %13 ]
  %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 ]
  %.02232.epil = phi ptr [ %spec.select.epil, %.epil.preheader ], [ %.02232.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %26 = getelementptr inbounds %struct.SpvReflectDescriptorSet, ptr %10, i64 %indvars.iv.epil
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = icmp eq i32 %27, %2
  %spec.select.epil = select i1 %28, ptr %26, ptr %.02232.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 !17

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %4
  %.3 = phi ptr [ null, %4 ], [ null, %.preheader ], [ %spec.select.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %.not29 = icmp eq ptr %3, null
  br i1 %.not29, label %.thread, label %29

29:                                               ; preds = %.loopexit
  %.not30 = icmp eq ptr %.3, null
  %30 = select i1 %.not, i32 5, i32 8
  %31 = select i1 %.not30, i32 %30, i32 0
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %12, %29
  %.sink = phi i32 [ %31, %29 ], [ 8, %12 ]
  %.1.ph = phi ptr [ %.3, %29 ], [ null, %12 ]
  store i32 %.sink, ptr %3, align 4, !tbaa !19
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %12, %.loopexit
  %.1 = phi ptr [ %.3, %.loopexit ], [ null, %12 ], [ %.1.ph, %.thread.sink.split ]
  ret ptr %.1
}

attributes #0 = { 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" }

!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, !10, i64 48}
!6 = !{!"SpvReflectEntryPoint", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !7, i64 88, !11, i64 96, !10, i64 108, !10, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"LocalSize", !10, i64 0, !10, i64 4, !10, i64 8}
!12 = !{!6, !7, i64 56}
!13 = !{!14, !10, i64 0}
!14 = !{!"SpvReflectDescriptorSet", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = !{!10, !10, i64 0}


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