; 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.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
declare dso_local ptr @spvReflectGetEntryPoint(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @spvReflectGetEntryPointInputVariableByLocation(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
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %23

17:                                               ; preds = %4
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 8, ptr %21, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %20, %17
  store ptr null, ptr %5, align 8
  br label %86

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store ptr null, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %68

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @spvReflectGetEntryPoint(ptr noundef %27, ptr noundef %28)
  store ptr %29, ptr %11, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %38

32:                                               ; preds = %26
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 8, ptr %36, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %35, %32
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %65

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

39:                                               ; preds = %61, %38
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %41, i32 0, i32 4
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = icmp ult i32 %40, %43
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %49, i64 %51
  store ptr %52, ptr %14, align 8, !tbaa !5
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = icmp eq i32 %55, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %46
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %59, ptr %10, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %58, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = add i32 %62, 1
  store i32 %63, ptr %13, align 4, !tbaa !9
  br label %39, !llvm.loop !23

64:                                               ; preds = %45
  store i32 0, ptr %12, align 4
  br label %65

65:                                               ; preds = %64, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %66 = load i32, ptr %12, align 4
  switch i32 %66, label %85 [
    i32 0, label %67
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67, %23
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %83

71:                                               ; preds = %68
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %75

74:                                               ; preds = %71
  br label %80

75:                                               ; preds = %71
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = icmp eq ptr %76, null
  %78 = zext i1 %77 to i64
  %79 = select i1 %77, i32 5, i32 8
  br label %80

80:                                               ; preds = %75, %74
  %81 = phi i32 [ 0, %74 ], [ %79, %75 ]
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %81, ptr %82, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %80, %68
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %84, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %85

85:                                               ; preds = %83, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %86

86:                                               ; preds = %85, %22
  %87 = load ptr, ptr %5, align 8
  ret ptr %87
}

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 20}
!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 24}
!15 = !{!16, !10, i64 16}
!16 = !{!"SpvReflectInterfaceVariable", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !10, i64 36, !17, i64 40, !21, i64 64, !10, i64 200, !6, i64 208, !10, i64 216, !6, i64 224, !22, i64 232}
!17 = !{!"SpvReflectNumericTraits", !18, i64 0, !19, i64 8, !20, i64 12}
!18 = !{!"Scalar", !10, i64 0, !10, i64 4}
!19 = !{!"Vector", !10, i64 0}
!20 = !{!"Matrix", !10, i64 0, !10, i64 4, !10, i64 8}
!21 = !{!"SpvReflectArrayTraits", !10, i64 0, !7, i64 4, !10, i64 132}
!22 = !{!"", !10, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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: nounwind uwtable
declare dso_local ptr @spvReflectGetEntryPoint(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @spvReflectGetEntryPointInputVariableByLocation(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %2, -1
  br i1 %5, label %6, label %7

6:                                                ; preds = %4
  %.not37 = icmp eq ptr %3, null
  br i1 %.not37, label %.thread, label %.thread.sink.split

7:                                                ; preds = %4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %8

8:                                                ; preds = %7
  %9 = tail call ptr @spvReflectGetEntryPoint(ptr noundef nonnull %0, ptr noundef %1)
  %.not34 = icmp eq ptr %9, null
  br i1 %.not34, label %15, label %.preheader

.preheader:                                       ; preds = %8
  %10 = getelementptr inbounds i8, ptr %9, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not41 = icmp eq i32 %11, 0
  br i1 %.not41, label %.loopexit, label %.lr.ph

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

15:                                               ; preds = %8
  %.not33 = icmp eq ptr %3, null
  br i1 %.not33, label %.thread, label %.thread.sink.split

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

.loopexit.loopexit.unr-lcssa:                     ; preds = %16, %.lr.ph
  %spec.select.lcssa.ph = phi ptr [ poison, %.lr.ph ], [ %spec.select.3, %16 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %16 ]
  %.02539.unr = phi ptr [ null, %.lr.ph ], [ %spec.select.3, %16 ]
  %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 ]
  %.02539.epil = phi ptr [ %spec.select.epil, %.epil.preheader ], [ %.02539.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %33 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %13, i64 %indvars.iv.epil
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = icmp eq i32 %35, %2
  %spec.select.epil = select i1 %36, ptr %33, ptr %.02539.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 !23

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

37:                                               ; preds = %.loopexit
  %.not36 = icmp eq ptr %.3, null
  %38 = select i1 %.not, i32 5, i32 8
  %39 = select i1 %.not36, i32 %38, i32 0
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %15, %6, %37
  %.sink = phi i32 [ %39, %37 ], [ 8, %6 ], [ 8, %15 ]
  %.2.ph = phi ptr [ %.3, %37 ], [ null, %6 ], [ null, %15 ]
  store i32 %.sink, ptr %3, align 4, !tbaa !25
  br label %.thread

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

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