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

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

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

20:                                               ; preds = %17
  store i32 5, ptr %5, align 4
  br label %69

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call ptr @spvReflectGetEntryPoint(ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 8, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

28:                                               ; preds = %21
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %62

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp ne i32 %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  store i32 7, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

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

40:                                               ; preds = %58, %39
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = icmp ult i32 %41, %43
  br i1 %44, label %46, label %45

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

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

58:                                               ; preds = %46
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %12, align 4, !tbaa !9
  br label %40, !llvm.loop !15

61:                                               ; preds = %45
  br label %67

62:                                               ; preds = %28
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.SpvReflectEntryPoint, ptr %63, i32 0, i32 6
  %65 = load i32, ptr %64, align 8, !tbaa !11
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %62, %61
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %67, %38, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %69

69:                                               ; preds = %68, %20, %16
  %70 = load i32, ptr %5, align 4
  ret i32 %70
}

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 32}
!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 40}
!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.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 range(i32 0, 9) i32 @spvReflectEnumerateEntryPointOutputVariables(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %2, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %.loopexit, label %7

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

10:                                               ; preds = %7
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %40, label %11

11:                                               ; preds = %10
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %8, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %.not23 = icmp eq i32 %12, %14
  br i1 %.not23, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %11
  %.not25 = icmp eq i32 %12, 0
  br i1 %.not25, label %.loopexit, label %.lr.ph

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

vector.memcheck:                                  ; preds = %.lr.ph
  %16 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %3, i64 %16
  %scevgep27 = getelementptr i8, ptr %8, i64 48
  %bound0 = icmp ugt ptr %scevgep27, %3
  %bound1 = icmp ult ptr %15, %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
  %17 = load ptr, ptr %15, align 8, !tbaa !13, !alias.scope !14
  %broadcast.splatinsert29 = insertelement <2 x ptr> poison, ptr %17, i64 0
  %broadcast.splat30 = shufflevector <2 x ptr> %broadcast.splatinsert29, <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>
  %18 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, <2 x ptr> %broadcast.splat30, <2 x i64> %vec.ind
  %19 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, <2 x ptr> %broadcast.splat30, <2 x i64> %step.add
  %20 = getelementptr inbounds ptr, ptr %3, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store <2 x ptr> %18, ptr %20, align 8, !tbaa !17, !alias.scope !18, !noalias !14
  store <2 x ptr> %19, ptr %21, align 8, !tbaa !17, !alias.scope !18, !noalias !14
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !20

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 ]
  %23 = load ptr, ptr %15, align 8, !tbaa !13
  %24 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %23, i64 %indvars.iv.prol
  %25 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv.prol
  store ptr %24, ptr %25, align 8, !tbaa !17
  %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 !24

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 ]
  %26 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %27 = icmp ugt i64 %26, -4
  br i1 %27, 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 ]
  %28 = load ptr, ptr %15, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %28, i64 %indvars.iv
  %30 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv
  store ptr %29, ptr %30, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load ptr, ptr %15, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %31, i64 %indvars.iv.next
  %33 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv.next
  store ptr %32, ptr %33, align 8, !tbaa !17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %34 = load ptr, ptr %15, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %34, i64 %indvars.iv.next.1
  %36 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv.next.1
  store ptr %35, ptr %36, align 8, !tbaa !17
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %37 = load ptr, ptr %15, align 8, !tbaa !13
  %38 = getelementptr inbounds %struct.SpvReflectInterfaceVariable, ptr %37, i64 %indvars.iv.next.2
  %39 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv.next.2
  store ptr %38, ptr %39, align 8, !tbaa !17
  %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 !26

40:                                               ; preds = %10
  %41 = getelementptr inbounds i8, ptr %8, i64 32
  %42 = load i32, ptr %41, align 8, !tbaa !9
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader, %7, %11, %40, %4
  %.1 = phi i32 [ 5, %4 ], [ 8, %7 ], [ 7, %11 ], [ 0, %40 ], [ 0, %.preheader ], [ 0, %middle.block ], [ 0, %scalar.ph ], [ 0, %scalar.ph.prol.loopexit ]
  ret i32 %.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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"SpvReflectEntryPoint", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !11, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56, !6, i64 64, !11, i64 72, !6, i64 80, !11, i64 88, !12, i64 96, !6, i64 108, !6, i64 112}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"LocalSize", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!10, !11, i64 40}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!11, !11, i64 0}
!18 = !{!19}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.unroll.disable"}
!26 = distinct !{!26, !21, !22}


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