; LLVM IR from Try/Tempest :: Engine/thirdparty/spirv_cross/spirv_cross.ll (ZN11spirv_cross8Compiler13register_readEjjb)

; 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.spirv_cross::IVariant" = type <{ ptr, %"class.spirv_cross::TypedID.162", [4 x i8] }>
%"class.spirv_cross::TypedID.162" = type { i32 }
%"struct.spirv_cross::SPIRExpression" = type <{ %"struct.spirv_cross::IVariant.base", %"class.spirv_cross::TypedID.162", %"class.std::__cxx11::basic_string", %"class.spirv_cross::TypedID.163", %"class.spirv_cross::TypedID.162", i8, i8, i8, i8, [4 x i8], %"class.spirv_cross::SmallVector.7", %"class.spirv_cross::SmallVector.7", %"class.spirv_cross::SmallVector.7", i32, [4 x i8] }>
%"struct.spirv_cross::IVariant.base" = type <{ ptr, %"class.spirv_cross::TypedID.162" }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.spirv_cross::TypedID.163" = type { i32 }
%"class.spirv_cross::SmallVector.7" = type { %"class.spirv_cross::VectorView.8", i64, %"class.spirv_cross::AlignedBuffer.9" }
%"class.spirv_cross::VectorView.8" = type { ptr, i64 }
%"class.spirv_cross::AlignedBuffer.9" = type { [32 x i8] }
%"struct.spirv_cross::SPIRVariable" = type { %"struct.spirv_cross::IVariant.base", %"class.spirv_cross::TypedID.163", i32, i32, %"class.spirv_cross::TypedID.162", %"class.spirv_cross::TypedID.164", %"class.spirv_cross::SmallVector.92", i8, i8, %"class.spirv_cross::TypedID.162", %"class.spirv_cross::SmallVector.7", i8, i8, i8, i8, i32, %"class.spirv_cross::TypedID.165", i8, i8, i8, ptr }
%"class.spirv_cross::TypedID.164" = type { i32 }
%"class.spirv_cross::SmallVector.92" = type { %"class.spirv_cross::VectorView.93", i64, %"class.spirv_cross::AlignedBuffer.94" }
%"class.spirv_cross::VectorView.93" = type { ptr, i64 }
%"class.spirv_cross::AlignedBuffer.94" = type { [32 x i8] }
%"class.spirv_cross::TypedID.165" = type { i32 }
%"struct.spirv_cross::SPIRFunction::Parameter" = type <{ %"class.spirv_cross::TypedID.163", %"class.spirv_cross::TypedID.162", i32, i32, i8, [3 x i8] }>

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN11spirv_cross8Compiler26maybe_get_backing_variableEj(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11spirv_cross7TypedIDILNS_5TypesE0EEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11spirv_cross8Compiler13register_readEjjb(ptr noundef nonnull align 8 dereferenceable(3176) %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = 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
  %11 = zext i1 %3 to i8
  store i8 %11, ptr %8, align 1, !tbaa !11
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = call noundef nonnull align 8 dereferenceable(236) ptr @_ZN11spirv_cross8Compiler3getINS_14SPIRExpressionEEERT_j(ptr noundef nonnull align 8 dereferenceable(3176) %12, i32 noundef %13)
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = call noundef ptr @_ZN11spirv_cross8Compiler26maybe_get_backing_variableEj(ptr noundef nonnull align 8 dereferenceable(3176) %12, i32 noundef %15)
  store ptr %16, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %52

19:                                               ; preds = %4
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.spirv_cross::IVariant", ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.spirv_cross::SPIRExpression", ptr %22, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 8 %21, i64 4, i1 false), !tbaa.struct !13
  %24 = load i8, ptr %8, align 1, !tbaa !11, !range !14, !noundef !15
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %36

26:                                               ; preds = %19
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.spirv_cross::IVariant", ptr %27, i32 0, i32 1
  %29 = call noundef i32 @_ZNK11spirv_cross7TypedIDILNS_5TypesE0EEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %28)
  %30 = call noundef zeroext i1 @_ZNK11spirv_cross8Compiler12is_immutableEj(ptr noundef nonnull align 8 dereferenceable(3176) %12, i32 noundef %29)
  br i1 %30, label %36, label %31

31:                                               ; preds = %26
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.spirv_cross::SPIRVariable", ptr %32, i32 0, i32 10
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.spirv_cross::IVariant", ptr %34, i32 0, i32 1
  call void @_ZN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EE9push_backERKS3_(ptr noundef nonnull align 8 dereferenceable(56) %33, ptr noundef nonnull align 4 dereferenceable(4) %35) #4
  br label %36

36:                                               ; preds = %31, %26, %19
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %51

39:                                               ; preds = %36
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.spirv_cross::SPIRVariable", ptr %40, i32 0, i32 20
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %51

44:                                               ; preds = %39
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.spirv_cross::SPIRVariable", ptr %45, i32 0, i32 20
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = getelementptr inbounds %"struct.spirv_cross::SPIRFunction::Parameter", ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 4, !tbaa !31
  %50 = add i32 %49, 1
  store i32 %50, ptr %48, align 4, !tbaa !31
  br label %51

51:                                               ; preds = %44, %39, %36
  br label %52

52:                                               ; preds = %51, %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(236) ptr @_ZN11spirv_cross8Compiler3getINS_14SPIRExpressionEEERT_j(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK11spirv_cross8Compiler12is_immutableEj(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EE9push_backERKS3_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { 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 #4 = { 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 = !{!"bool", !7, i64 0}
!13 = !{i64 0, i64 4, !9}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !6, i64 168}
!17 = !{!"_ZTSN11spirv_cross12SPIRVariableE", !18, i64 0, !20, i64 12, !21, i64 16, !10, i64 20, !19, i64 24, !22, i64 28, !23, i64 32, !12, i64 88, !12, i64 89, !19, i64 92, !27, i64 96, !12, i64 152, !12, i64 153, !12, i64 154, !12, i64 155, !10, i64 156, !30, i64 160, !12, i64 164, !12, i64 165, !12, i64 166, !6, i64 168}
!18 = !{!"_ZTSN11spirv_cross8IVariantE", !19, i64 8}
!19 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE0EEE", !10, i64 0}
!20 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE1EEE", !10, i64 0}
!21 = !{!"_ZTSN3spv12StorageClassE", !7, i64 0}
!22 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE2EEE", !10, i64 0}
!23 = !{!"_ZTSN11spirv_cross11SmallVectorIjLm8EEE", !24, i64 0, !25, i64 16, !26, i64 24}
!24 = !{!"_ZTSN11spirv_cross10VectorViewIjEE", !6, i64 0, !25, i64 8}
!25 = !{!"long", !7, i64 0}
!26 = !{!"_ZTSN11spirv_cross13AlignedBufferIjLm8EEE", !7, i64 0}
!27 = !{!"_ZTSN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EEE", !28, i64 0, !25, i64 16, !29, i64 24}
!28 = !{!"_ZTSN11spirv_cross10VectorViewINS_7TypedIDILNS_5TypesE0EEEEE", !6, i64 0, !25, i64 8}
!29 = !{!"_ZTSN11spirv_cross13AlignedBufferINS_7TypedIDILNS_5TypesE0EEELm8EEE", !7, i64 0}
!30 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE6EEE", !10, i64 0}
!31 = !{!32, !10, i64 8}
!32 = !{!"_ZTSN11spirv_cross12SPIRFunction9ParameterE", !20, i64 0, !19, i64 4, !10, i64 8, !10, i64 12, !12, i64 16}


; 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 uwtable
declare dso_local noundef ptr @_ZN11spirv_cross8Compiler26maybe_get_backing_variableEj(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11spirv_cross7TypedIDILNS_5TypesE0EEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11spirv_cross8Compiler13register_readEjjb(ptr noundef nonnull align 8 dereferenceable(3176) %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef nonnull align 8 dereferenceable(236) ptr @_ZN11spirv_cross8Compiler3getINS_14SPIRExpressionEEERT_j(ptr noundef nonnull align 8 dereferenceable(3176) %0, i32 noundef %1)
  %6 = tail call noundef ptr @_ZN11spirv_cross8Compiler26maybe_get_backing_variableEj(ptr noundef nonnull align 8 dereferenceable(3176) %0, i32 noundef %2)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %24, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = getelementptr inbounds i8, ptr %5, i64 52
  %10 = load i32, ptr %8, align 8, !tbaa !5
  store i32 %10, ptr %9, align 4, !tbaa !5
  br i1 %3, label %11, label %17

11:                                               ; preds = %7
  %12 = tail call noundef i32 @_ZNK11spirv_cross7TypedIDILNS_5TypesE0EEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %8)
  %13 = tail call noundef zeroext i1 @_ZNK11spirv_cross8Compiler12is_immutableEj(ptr noundef nonnull align 8 dereferenceable(3176) %0, i32 noundef %12)
  br i1 %13, label %17, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %6, i64 96
  %16 = getelementptr inbounds i8, ptr %5, i64 8
  tail call void @_ZN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EE9push_backERKS3_(ptr noundef nonnull align 8 dereferenceable(56) %15, ptr noundef nonnull align 4 dereferenceable(4) %16) #2
  br label %17

17:                                               ; preds = %7, %11, %14
  %18 = getelementptr inbounds i8, ptr %6, i64 168
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %.not13 = icmp eq ptr %19, null
  br i1 %.not13, label %24, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %19, i64 8
  %22 = load i32, ptr %21, align 4, !tbaa !26
  %23 = add i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !26
  br label %24

24:                                               ; preds = %17, %20, %4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(236) ptr @_ZN11spirv_cross8Compiler3getINS_14SPIRExpressionEEERT_j(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK11spirv_cross8Compiler12is_immutableEj(ptr noundef nonnull align 8 dereferenceable(3176), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EE9push_backERKS3_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !18, i64 168}
!10 = !{!"_ZTSN11spirv_cross12SPIRVariableE", !11, i64 0, !13, i64 12, !14, i64 16, !6, i64 20, !12, i64 24, !15, i64 28, !16, i64 32, !21, i64 88, !21, i64 89, !12, i64 92, !22, i64 96, !21, i64 152, !21, i64 153, !21, i64 154, !21, i64 155, !6, i64 156, !25, i64 160, !21, i64 164, !21, i64 165, !21, i64 166, !18, i64 168}
!11 = !{!"_ZTSN11spirv_cross8IVariantE", !12, i64 8}
!12 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE0EEE", !6, i64 0}
!13 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE1EEE", !6, i64 0}
!14 = !{!"_ZTSN3spv12StorageClassE", !7, i64 0}
!15 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE2EEE", !6, i64 0}
!16 = !{!"_ZTSN11spirv_cross11SmallVectorIjLm8EEE", !17, i64 0, !19, i64 16, !20, i64 24}
!17 = !{!"_ZTSN11spirv_cross10VectorViewIjEE", !18, i64 0, !19, i64 8}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTSN11spirv_cross13AlignedBufferIjLm8EEE", !7, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTSN11spirv_cross11SmallVectorINS_7TypedIDILNS_5TypesE0EEELm8EEE", !23, i64 0, !19, i64 16, !24, i64 24}
!23 = !{!"_ZTSN11spirv_cross10VectorViewINS_7TypedIDILNS_5TypesE0EEEEE", !18, i64 0, !19, i64 8}
!24 = !{!"_ZTSN11spirv_cross13AlignedBufferINS_7TypedIDILNS_5TypesE0EEELm8EEE", !7, i64 0}
!25 = !{!"_ZTSN11spirv_cross7TypedIDILNS_5TypesE6EEE", !6, i64 0}
!26 = !{!27, !6, i64 8}
!27 = !{!"_ZTSN11spirv_cross12SPIRFunction9ParameterE", !13, i64 0, !12, i64 4, !6, i64 8, !6, i64 12, !21, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass