; LLVM IR from Try/Tempest :: Engine/libspirv/libspirv.ll (ZNK8libspirv8Bytecode10findOpTypeEj)

; 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.libspirv::Bytecode::Iterator" = type <{ ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode3endEv(ptr noundef nonnull align 8 dereferenceable(20)) #0 align 2

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(12)) #3

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4), i16 noundef zeroext) #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20), i8 noundef zeroext) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_8IteratorENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20), ptr, i32, i8 noundef zeroext) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode10findOpTypeEj(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %7 = alloca { ptr, i32 }, align 8
  %8 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %9 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %10 = alloca { ptr, i32 }, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca { ptr, i32 }, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %15 = call { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20) %14, i8 noundef zeroext 9)
  store { ptr, i32 } %15, ptr %7, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %7, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !11
  %16 = getelementptr inbounds { ptr, i32 }, ptr %9, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8
  %18 = getelementptr inbounds { ptr, i32 }, ptr %9, i32 0, i32 1
  %19 = load i32, ptr %18, align 8
  %20 = call { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_8IteratorENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20) %14, ptr %17, i32 %19, i8 noundef zeroext 10)
  store { ptr, i32 } %20, ptr %10, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !11
  br label %21

21:                                               ; preds = %40, %2
  %22 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef nonnull align 8 dereferenceable(12) %8)
  br i1 %22, label %23, label %41

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %3)
  store ptr %24, ptr %11, align 8, !tbaa !5
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %25)
  switch i32 %26, label %35 [
    i32 19, label %27
    i32 20, label %27
    i32 21, label %27
    i32 22, label %27
    i32 23, label %27
    i32 24, label %27
    i32 25, label %27
    i32 26, label %27
    i32 27, label %27
    i32 28, label %27
    i32 29, label %27
    i32 30, label %27
    i32 31, label %27
    i32 32, label %27
    i32 33, label %27
    i32 34, label %27
    i32 35, label %27
    i32 36, label %27
    i32 37, label %27
    i32 38, label %27
    i32 39, label %27
  ]

27:                                               ; preds = %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %28, i16 noundef zeroext 1)
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 1, ptr %12, align 4
  br label %37

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34, %23
  br label %36

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

37:                                               ; preds = %36, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %38 = load i32, ptr %12, align 4
  switch i32 %38, label %43 [
    i32 0, label %39
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %3)
  br label %21, !llvm.loop !12

41:                                               ; preds = %21
  %42 = call { ptr, i32 } @_ZNK8libspirv8Bytecode3endEv(ptr noundef nonnull align 8 dereferenceable(20) %14)
  store { ptr, i32 } %42, ptr %13, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %13, i64 12, i1 false)
  store i32 1, ptr %12, align 4
  br label %43

43:                                               ; preds = %41, %37
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %44 = load { ptr, i32 }, ptr %3, align 8
  ret { ptr, i32 } %44
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !5, i64 8, i64 4, !9}
!12 = distinct !{!12, !13}
!13 = !{!"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.libspirv::Bytecode::Iterator" = type <{ ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode3endEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4), i16 noundef zeroext) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20), i8 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_8IteratorENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20), ptr, i32, i8 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local { ptr, i32 } @_ZNK8libspirv8Bytecode10findOpTypeEj(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %4 = alloca %"struct.libspirv::Bytecode::Iterator", align 8
  %5 = tail call { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20) %0, i8 noundef zeroext 9)
  %.fca.0.extract8 = extractvalue { ptr, i32 } %5, 0
  %.fca.1.extract9 = extractvalue { ptr, i32 } %5, 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %6 = tail call { ptr, i32 } @_ZNK8libspirv8Bytecode11findSectionENS0_8IteratorENS0_7SectionE(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr %.fca.0.extract8, i32 %.fca.1.extract9, i8 noundef zeroext 10)
  %.fca.0.extract2 = extractvalue { ptr, i32 } %6, 0
  %.fca.1.extract3 = extractvalue { ptr, i32 } %6, 1
  store ptr %.fca.0.extract2, ptr %4, align 8
  %.sroa.25.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %.fca.1.extract3, ptr %.sroa.25.0..sroa_idx, align 8
  store ptr %.fca.0.extract8, ptr %3, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %.fca.1.extract9, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  %7 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef nonnull align 8 dereferenceable(12) %4)
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.critedge
  %8 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %3)
  %9 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %8)
  %.off = add i32 %9, -19
  %switch = icmp ult i32 %.off, 21
  br i1 %switch, label %10, label %.critedge

10:                                               ; preds = %.lr.ph
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %8, i16 noundef zeroext 1)
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, %1
  br i1 %13, label %.loopexit.loopexit, label %.critedge

.critedge:                                        ; preds = %.lr.ph, %10
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %3)
  %14 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef nonnull align 8 dereferenceable(12) %4)
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %2
  %15 = call { ptr, i32 } @_ZNK8libspirv8Bytecode3endEv(ptr noundef nonnull align 8 dereferenceable(20) %0)
  %.fca.0.extract = extractvalue { ptr, i32 } %15, 0
  %.fca.1.extract = extractvalue { ptr, i32 } %15, 1
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %10
  %.fca.0.load.pre = load ptr, ptr %3, align 8
  %.fca.1.load.pre = load i32, ptr %.sroa.5.0..sroa_idx, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %._crit_edge
  %.fca.1.load = phi i32 [ %.fca.1.load.pre, %.loopexit.loopexit ], [ %.fca.1.extract, %._crit_edge ]
  %.fca.0.load = phi ptr [ %.fca.0.load.pre, %.loopexit.loopexit ], [ %.fca.0.extract, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  %.fca.0.insert = insertvalue { ptr, i32 } poison, ptr %.fca.0.load, 0
  %.fca.1.insert = insertvalue { ptr, i32 } %.fca.0.insert, i32 %.fca.1.load, 1
  ret { ptr, i32 } %.fca.1.insert
}

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass