; LLVM IR from Try/Tempest :: Engine/gapi/spirv (shaderanalyzer)

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

%class.ShaderAnalyzer = type <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [768 x i32], [768 x i32], [4 x i8], %"class.std::unordered_map", ptr, %"class.libspirv::MutableBytecode", %"class.std::unordered_map.13", %"class.std::unordered_map.27", %"class.std::unordered_map.41", %"class.std::unordered_map.55", %"class.std::unordered_map.69", i32, [4 x i8] }>
%"class.std::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%"class.libspirv::MutableBytecode" = type { %"class.libspirv::Bytecode.base", %"class.std::vector.8" }
%"class.libspirv::Bytecode.base" = type <{ ptr, i64, i32 }>
%"class.std::vector.8" = type { %"struct.std::_Vector_base.9" }
%"struct.std::_Vector_base.9" = type { %"struct.std::_Vector_base<libspirv::Bytecode::OpCode, std::allocator<libspirv::Bytecode::OpCode>>::_Vector_impl" }
%"struct.std::_Vector_base<libspirv::Bytecode::OpCode, std::allocator<libspirv::Bytecode::OpCode>>::_Vector_impl" = type { %"struct.std::_Vector_base<libspirv::Bytecode::OpCode, std::allocator<libspirv::Bytecode::OpCode>>::_Vector_impl_data" }
%"struct.std::_Vector_base<libspirv::Bytecode::OpCode, std::allocator<libspirv::Bytecode::OpCode>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::unordered_map.13" = type { %"class.std::_Hashtable.14" }
%"class.std::_Hashtable.14" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"class.std::unordered_map.27" = type { %"class.std::_Hashtable.28" }
%"class.std::_Hashtable.28" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"class.std::unordered_map.41" = type { %"class.std::_Hashtable.42" }
%"class.std::_Hashtable.42" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"class.std::unordered_map.55" = type { %"class.std::_Hashtable.56" }
%"class.std::_Hashtable.56" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"class.std::unordered_map.69" = type { %"class.std::_Hashtable.70" }
%"class.std::_Hashtable.70" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", 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: mustprogress nounwind uwtable
define dso_local void @_ZN14ShaderAnalyzer24markIndexAsThreadRelatedEjjNS_10AccessBitsE(ptr noundef nonnull align 8 dereferenceable(6596) %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i16 %3, ptr %8, align 2, !tbaa !11
  %14 = load ptr, ptr %5, align 8
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %51

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 14
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds [768 x i32], ptr %19, i64 0, i64 0
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds [768 x i32], ptr %21, i64 0, i64 0
  %23 = getelementptr inbounds i32, ptr %22, i64 768
  store ptr %23, ptr %11, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %47, %17
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp ne ptr %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %50

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %30, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 257
  br i1 %33, label %40, label %34

34:                                               ; preds = %29
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 24
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = icmp eq i32 %36, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %34, %29
  %41 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 24
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !9
  br label %46

44:                                               ; preds = %34
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 256, ptr %45, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %44, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %48, i32 1
  store ptr %49, ptr %10, align 8, !tbaa !5
  br label %24

50:                                               ; preds = %28
  br label %72

51:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %52 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 14
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds [768 x i32], ptr %52, i64 0, i64 %54
  store ptr %55, ptr %13, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 257
  br i1 %58, label %65, label %59

59:                                               ; preds = %51
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 24
  %63 = load i32, ptr %62, align 8, !tbaa !13
  %64 = icmp eq i32 %61, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %59, %51
  %66 = getelementptr inbounds %class.ShaderAnalyzer, ptr %14, i32 0, i32 24
  %67 = load i32, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %67, ptr %68, align 4, !tbaa !9
  br label %71

69:                                               ; preds = %59
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 256, ptr %70, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %69, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %72

72:                                               ; preds = %71, %50
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN14ShaderAnalyzer10AccessBitsE", !7, i64 0}
!13 = !{!14, !10, i64 6592}
!14 = !{!"_ZTS14ShaderAnalyzer", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 52, !7, i64 3124, !15, i64 6200, !6, i64 6256, !21, i64 6264, !27, i64 6312, !29, i64 6368, !31, i64 6424, !33, i64 6480, !35, i64 6536, !10, i64 6592}
!15 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer7VaryingESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !16, i64 0}
!16 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer7VaryingEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!19 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !20, i64 0, !17, i64 8}
!20 = !{!"float", !7, i64 0}
!21 = !{!"_ZTSN8libspirv15MutableBytecodeE", !22, i64 0, !23, i64 24}
!22 = !{!"_ZTSN8libspirv8BytecodeE", !6, i64 0, !17, i64 8, !10, i64 16}
!23 = !{!"_ZTSSt6vectorIN8libspirv8Bytecode6OpCodeESaIS2_EE", !24, i64 0}
!24 = !{!"_ZTSSt12_Vector_baseIN8libspirv8Bytecode6OpCodeESaIS2_EE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIN8libspirv8Bytecode6OpCodeESaIS2_EE12_Vector_implE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIN8libspirv8Bytecode6OpCodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!27 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer3RegESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !28, i64 0}
!28 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer3RegEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!29 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer4TypeESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !30, i64 0}
!30 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer4TypeEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!31 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer3VarESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !32, i64 0}
!32 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer3VarEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!33 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer8FunctionESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !34, i64 0}
!34 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer8FunctionEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!35 = !{!"_ZTSSt13unordered_mapIjN14ShaderAnalyzer3CFGESt4hashIjESt8equal_toIjESaISt4pairIKjS1_EEE", !36, i64 0}
!36 = !{!"_ZTSSt10_HashtableIjSt4pairIKjN14ShaderAnalyzer3CFGEESaIS4_ENSt8__detail10_Select1stESt8equal_toIjESt4hashIjENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_rehash_policyENS6_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN14ShaderAnalyzer24markIndexAsThreadRelatedEjjNS_10AccessBitsE(ptr nocapture noundef nonnull align 8 dereferenceable(6596) %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3) local_unnamed_addr #0 align 2 {
  %5 = icmp eq i32 %1, -1
  br i1 %5, label %.preheader, label %16

.preheader:                                       ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 6592
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 4
  br label %7

7:                                                ; preds = %7, %.preheader
  %.0.idx26 = phi i64 [ 3124, %.preheader ], [ %.0.add.1, %7 ]
  %.0.ptr = getelementptr inbounds i8, ptr %0, i64 %.0.idx26
  %8 = load i32, ptr %.0.ptr, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 257
  %10 = load i32, ptr %6, align 8
  %11 = icmp eq i32 %8, %10
  %or.cond = select i1 %9, i1 true, i1 %11
  %storemerge20 = select i1 %or.cond, i32 %10, i32 256
  store i32 %storemerge20, ptr %.0.ptr, align 4, !tbaa !5
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %.0.idx26
  %12 = load i32, ptr %gep, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 257
  %14 = load i32, ptr %6, align 8
  %15 = icmp eq i32 %12, %14
  %or.cond.1 = select i1 %13, i1 true, i1 %15
  %storemerge20.1 = select i1 %or.cond.1, i32 %14, i32 256
  store i32 %storemerge20.1, ptr %gep, align 4, !tbaa !5
  %.0.add.1 = add nuw nsw i64 %.0.idx26, 8
  %.not.1 = icmp eq i64 %.0.add.1, 6196
  br i1 %.not.1, label %.loopexit, label %7

16:                                               ; preds = %4
  %17 = getelementptr inbounds i8, ptr %0, i64 3124
  %18 = zext i32 %1 to i64
  %19 = getelementptr inbounds [768 x i32], ptr %17, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 257
  %22 = getelementptr inbounds i8, ptr %0, i64 6592
  %23 = load i32, ptr %22, align 8
  %24 = icmp eq i32 %20, %23
  %or.cond25 = select i1 %21, i1 true, i1 %24
  %storemerge = select i1 %or.cond25, i32 %23, i32 256
  store i32 %storemerge, ptr %19, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %7, %16
  ret void
}

attributes #0 = { mustprogress 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass