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

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

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc = external hidden unnamed_addr constant [92 x i8], align 1

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca [32 x i32], align 16
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store i32 %3, ptr %9, align 4, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8
  %15 = getelementptr inbounds %"struct.libspirv::Bytecode::Iterator", ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %"struct.libspirv::MutableBytecode::Iterator", ptr %14, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds %"class.libspirv::Bytecode", ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = icmp eq i32 %16, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %5
  br label %25

23:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 698, ptr noundef @__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc) #4
  unreachable

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24, %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 128, ptr %12) #5
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 128, i1 false)
  %26 = load i32, ptr %8, align 4, !tbaa !11
  %27 = getelementptr inbounds [32 x i32], ptr %12, i64 0, i64 0
  store i32 %26, ptr %27, align 16, !tbaa !11
  %28 = load i32, ptr %9, align 4, !tbaa !11
  %29 = getelementptr inbounds [32 x i32], ptr %12, i64 0, i64 1
  store i32 %28, ptr %29, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %56, %25
  %31 = load i32, ptr %13, align 4, !tbaa !11
  %32 = icmp slt i32 %31, 116
  br i1 %32, label %33, label %40

33:                                               ; preds = %30
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load i32, ptr %13, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !20
  %39 = icmp ne i8 %38, 0
  br label %40

40:                                               ; preds = %33, %30
  %41 = phi i1 [ false, %30 ], [ %39, %33 ]
  br i1 %41, label %43, label %42

42:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %59

43:                                               ; preds = %40
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !20
  %49 = getelementptr inbounds [32 x i32], ptr %12, i64 0, i64 0
  %50 = load i32, ptr %13, align 4, !tbaa !11
  %51 = add nsw i32 %50, 8
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  store i8 %48, ptr %53, align 1, !tbaa !20
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = add i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %43
  %57 = load i32, ptr %13, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %13, align 4, !tbaa !11
  br label %30, !llvm.loop !21

59:                                               ; preds = %42
  %60 = load i32, ptr %11, align 4, !tbaa !11
  %61 = add i32 %60, 1
  %62 = add i32 %61, 3
  %63 = udiv i32 %62, 4
  %64 = add i32 2, %63
  store i32 %64, ptr %11, align 4, !tbaa !11
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = getelementptr inbounds [32 x i32], ptr %12, i64 0, i64 0
  %67 = load i32, ptr %11, align 4, !tbaa !11
  %68 = zext i32 %67 to i64
  call void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEPKjm(ptr noundef nonnull align 8 dereferenceable(24) %14, i32 noundef %65, ptr noundef %66, i64 noundef %68)
  call void @llvm.lifetime.end.p0(i64 128, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { noreturn nounwind "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 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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"_ZTSN3spv2OpE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTSN8libspirv8Bytecode8IteratorE", !6, i64 0, !12, i64 8}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTSN8libspirv15MutableBytecode8IteratorE", !14, i64 0, !6, i64 16}
!17 = !{!18, !12, i64 16}
!18 = !{!"_ZTSN8libspirv8BytecodeE", !6, i64 0, !19, i64 8, !12, i64 16}
!19 = !{!"long", !7, i64 0}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc = external hidden unnamed_addr constant [92 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #3 align 2 {
  %6 = alloca [32 x i32], align 16
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp eq i32 %8, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 698, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjjPKc) #4
  unreachable

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %6, i8 0, i64 128, i1 false)
  store i32 %2, ptr %6, align 16, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %3, ptr %16, align 4, !tbaa !16
  %invariant.gep = getelementptr inbounds i8, ptr %6, i64 8
  br label %17

17:                                               ; preds = %33, %15
  %indvars.iv = phi i64 [ 0, %15 ], [ %indvars.iv.next.3, %33 ]
  %18 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !17
  %.not = icmp eq i8 %19, 0
  br i1 %.not, label %.critedge.split.loop.exit20, label %24

.critedge.split.loop.exit20:                      ; preds = %30, %27, %24, %17
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %17 ], [ %indvars.iv.next, %24 ], [ %indvars.iv.next.1, %27 ], [ %indvars.iv.next.2, %30 ]
  %indvars19.le = trunc i64 %indvars.iv.lcssa to i32
  %20 = add i32 %indvars19.le, 4
  %21 = lshr i32 %20, 2
  %22 = add nuw nsw i32 %21, 2
  %23 = zext nneg i32 %22 to i64
  br label %.critedge

.critedge:                                        ; preds = %33, %.critedge.split.loop.exit20
  %.013.lcssa = phi i64 [ %23, %.critedge.split.loop.exit20 ], [ 32, %33 ]
  call void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEPKjm(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, ptr noundef nonnull %6, i64 noundef %.013.lcssa)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #5
  ret void

24:                                               ; preds = %17
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv
  store i8 %19, ptr %gep, align 4, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next
  %26 = load i8, ptr %25, align 1, !tbaa !17
  %.not.1 = icmp eq i8 %26, 0
  br i1 %.not.1, label %.critedge.split.loop.exit20, label %27

27:                                               ; preds = %24
  %gep.1 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next
  store i8 %26, ptr %gep.1, align 1, !tbaa !17
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %28 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.1
  %29 = load i8, ptr %28, align 1, !tbaa !17
  %.not.2 = icmp eq i8 %29, 0
  br i1 %.not.2, label %.critedge.split.loop.exit20, label %30

30:                                               ; preds = %27
  %gep.2 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next.1
  store i8 %29, ptr %gep.2, align 2, !tbaa !17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %31 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.2
  %32 = load i8, ptr %31, align 1, !tbaa !17
  %.not.3 = icmp eq i8 %32, 0
  br i1 %.not.3, label %.critedge.split.loop.exit20, label %33

33:                                               ; preds = %30
  %gep.3 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next.2
  store i8 %32, ptr %gep.3, align 1, !tbaa !17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 116
  br i1 %exitcond.not.3, label %.critedge, label %17, !llvm.loop !18
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { noreturn nounwind "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 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 = { noreturn nounwind }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"_ZTSN8libspirv8Bytecode8IteratorE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"_ZTSN8libspirv15MutableBytecode8IteratorE", !6, i64 0, !7, i64 16}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTSN8libspirv8BytecodeE", !7, i64 0, !15, i64 8, !10, i64 16}
!15 = !{!"long", !8, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass