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

; 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 }>
%"class.std::initializer_list" = type { ptr, i64 }
%"struct.libspirv::Bytecode::OpCode" = type { i16, i16 }

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN8libspirv15MutableBytecode13fetchAddBoundEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpESt16initializer_listIjE(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, ptr, i64) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8libspirv15MutableBytecode14OpTypeFunctionERNS0_8IteratorEj(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"struct.libspirv::MutableBytecode::Iterator", align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"class.std::initializer_list", align 8
  %13 = alloca [2 x i32], align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @_ZN8libspirv15MutableBytecode5beginEv(ptr dead_on_unwind writable sret(%"struct.libspirv::MutableBytecode::Iterator") align 8 %8, ptr noundef nonnull align 8 dereferenceable(48) %14)
  br label %15

15:                                               ; preds = %44, %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call noundef zeroext i1 @_ZN8libspirvneERKNS_8Bytecode8IteratorES3_(ptr noundef nonnull align 8 dereferenceable(12) %8, ptr noundef nonnull align 8 dereferenceable(12) %16)
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %9, align 4
  br label %45

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %8)
  store ptr %20, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %21)
  %23 = icmp eq i32 %22, 33
  br i1 %23, label %24, label %40

24:                                               ; preds = %19
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %25, i16 noundef zeroext 2)
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %24
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.libspirv::Bytecode::OpCode", ptr %31, i32 0, i32 1
  %33 = load i16, ptr %32, align 2, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %37, i16 noundef zeroext 1)
  %39 = load i32, ptr %38, align 4, !tbaa !9
  store i32 %39, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %41

40:                                               ; preds = %30, %24, %19
  store i32 0, ptr %9, align 4
  br label %41

41:                                               ; preds = %40, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %42 = load i32, ptr %9, align 4
  switch i32 %42, label %45 [
    i32 0, label %43
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43
  call void @_ZN8libspirv8Bytecode8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(12) %8)
  br label %15, !llvm.loop !14

45:                                               ; preds = %41, %18
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  %46 = load i32, ptr %9, align 4
  switch i32 %46, label %62 [
    i32 2, label %47
    i32 1, label %60
  ]

47:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %48 = call noundef i32 @_ZN8libspirv15MutableBytecode13fetchAddBoundEv(ptr noundef nonnull align 8 dereferenceable(48) %14)
  store i32 %48, ptr %11, align 4, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %50 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %50, ptr %13, align 4, !tbaa !9
  %51 = getelementptr inbounds i32, ptr %13, i64 1
  %52 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %52, ptr %51, align 4, !tbaa !9
  %53 = getelementptr inbounds %"class.std::initializer_list", ptr %12, i32 0, i32 0
  store ptr %13, ptr %53, align 8, !tbaa !16
  %54 = getelementptr inbounds %"class.std::initializer_list", ptr %12, i32 0, i32 1
  store i64 2, ptr %54, align 8, !tbaa !19
  %55 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8
  %57 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 1
  %58 = load i64, ptr %57, align 8
  call void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpESt16initializer_listIjE(ptr noundef nonnull align 8 dereferenceable(24) %49, i32 noundef 33, ptr %56, i64 %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  %59 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %59, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %60

60:                                               ; preds = %47, %45
  %61 = load i32, ptr %4, align 4
  ret i32 %61

62:                                               ; preds = %45
  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 = !{!12, !13, i64 2}
!12 = !{!"_ZTSN8libspirv8Bytecode6OpCodeE", !13, i64 0, !13, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTSSt16initializer_listIjE", !6, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!17, !18, i64 8}


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN8libspirv15MutableBytecode13fetchAddBoundEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpESt16initializer_listIjE(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, ptr, i64) local_unnamed_addr #2 align 2

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

.lr.ph:                                           ; preds = %3, %17
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(12) %4)
  %8 = call noundef i32 @_ZNK8libspirv8Bytecode6OpCode2opEv(ptr noundef nonnull align 4 dereferenceable(4) %7)
  %9 = icmp eq i32 %8, 33
  br i1 %9, label %10, label %17

10:                                               ; preds = %.lr.ph
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %7, i16 noundef zeroext 2)
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, %2
  %14 = getelementptr inbounds i8, ptr %7, i64 2
  %15 = load i16, ptr %14, align 2
  %16 = icmp eq i16 %15, 3
  %or.cond = select i1 %13, i1 %16, i1 false
  br i1 %or.cond, label %19, label %17

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

19:                                               ; preds = %10
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK8libspirv8Bytecode6OpCodeixEt(ptr noundef nonnull align 4 dereferenceable(4) %7, i16 noundef zeroext 1)
  %21 = load i32, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  br label %24

._crit_edge:                                      ; preds = %17, %3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  %22 = call noundef i32 @_ZN8libspirv15MutableBytecode13fetchAddBoundEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i32 %22, ptr %5, align 4, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %2, ptr %23, align 4, !tbaa !5
  call void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpESt16initializer_listIjE(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef 33, ptr nonnull %5, i64 2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %24

24:                                               ; preds = %19, %._crit_edge
  %.3 = phi i32 [ %21, %19 ], [ %22, %._crit_edge ]
  ret i32 %.3
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass