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

; 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::MutableBytecode::Iterator" = type { %"struct.libspirv::Bytecode::Iterator.base", ptr }
%"struct.libspirv::Bytecode::Iterator.base" = type <{ ptr, i32 }>

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

; 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)) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 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) #1 align 2

; 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
declare dso_local void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode5beginEv(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8libspirv15MutableBytecode12findFunctionEj(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.libspirv::MutableBytecode::Iterator", align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i32 %2, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @_ZN8libspirv15MutableBytecode5beginEv(ptr dead_on_unwind writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %9)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #3
  call void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %6, ptr noundef nonnull align 8 dereferenceable(48) %9)
  br label %10

10:                                               ; preds = %39, %3
  %11 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(12) %6)
  br i1 %11, label %13, label %12

12:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %40

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %15)
  %17 = icmp ne i32 %16, 54
  br i1 %17, label %24, label %18

18:                                               ; preds = %13
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %19, i16 noundef zeroext 2)
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp ne i32 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18, %13
  store i32 4, ptr %7, align 4
  br label %37

25:                                               ; preds = %18
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %27 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %26)
  %28 = icmp eq i32 %27, 248
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  br label %30

30:                                               ; preds = %29, %25
  br label %31

31:                                               ; preds = %35, %30
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %33 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %32)
  %34 = icmp eq i32 %33, 59
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  br label %31, !llvm.loop !11

36:                                               ; preds = %31
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %36, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %38 = load i32, ptr %7, align 4
  switch i32 %38, label %40 [
    i32 4, label %39
  ]

39:                                               ; preds = %37
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  br label %10, !llvm.loop !13

40:                                               ; preds = %37, %12
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #3
  %41 = load i32, ptr %7, align 4
  switch i32 %41, label %44 [
    i32 2, label %42
    i32 1, label %43
  ]

42:                                               ; preds = %40
  call void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %9)
  br label %43

43:                                               ; preds = %42, %40
  ret void

44:                                               ; preds = %40
  unreachable
}

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 = { 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 = { 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"}
!13 = distinct !{!13, !12}


; 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::MutableBytecode::Iterator" = type { %"struct.libspirv::Bytecode::Iterator.base", ptr }
%"struct.libspirv::Bytecode::Iterator.base" = type <{ ptr, i32 }>

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

; 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 #1

; 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 #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 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 #1 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode5beginEv(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8libspirv15MutableBytecode12findFunctionEj(ptr dead_on_unwind noalias writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i32 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %"struct.libspirv::MutableBytecode::Iterator", align 8
  tail call void @_ZN8libspirv15MutableBytecode5beginEv(ptr dead_on_unwind writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %1)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind nonnull writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %4, ptr noundef nonnull align 8 dereferenceable(48) %1)
  %5 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(12) %4)
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %23
  %6 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %7 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %6)
  %.not = icmp eq i32 %7, 54
  br i1 %.not, label %8, label %23

8:                                                ; preds = %.lr.ph
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %6, i16 noundef zeroext 2)
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not5 = icmp eq i32 %10, %2
  br i1 %.not5, label %11, label %23

11:                                               ; preds = %8
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %12 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %13 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %12)
  %14 = icmp eq i32 %13, 248
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  br label %16

16:                                               ; preds = %15, %11
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %18 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %17)
  %19 = icmp eq i32 %18, 59
  br i1 %19, label %.lr.ph13, label %._crit_edge14

.lr.ph13:                                         ; preds = %16, %.lr.ph13
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  %21 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %20)
  %22 = icmp eq i32 %21, 59
  br i1 %22, label %.lr.ph13, label %._crit_edge14, !llvm.loop !9

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

._crit_edge14:                                    ; preds = %.lr.ph13, %16
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  br label %25

._crit_edge:                                      ; preds = %23, %3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN8libspirv15MutableBytecode3endEv(ptr dead_on_unwind nonnull writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %1)
  br label %25

25:                                               ; preds = %._crit_edge14, %._crit_edge
  ret void
}

attributes #0 = { mustprogress 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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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