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

; 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__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc = external hidden unnamed_addr constant [82 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 @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca [32 x i32], align 16
  %11 = alloca i32, align 4
  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 !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = getelementptr inbounds %"struct.libspirv::Bytecode::Iterator", ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %"struct.libspirv::MutableBytecode::Iterator", ptr %12, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds %"class.libspirv::Bytecode", ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !17
  %19 = icmp eq i32 %14, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  br label %23

21:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 685, ptr noundef @__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc) #4
  unreachable

22:                                               ; No predecessors!
  br label %23

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

26:                                               ; preds = %52, %23
  %27 = load i32, ptr %11, align 4, !tbaa !11
  %28 = icmp slt i32 %27, 120
  br i1 %28, label %29, label %36

29:                                               ; preds = %26
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !20
  %35 = icmp ne i8 %34, 0
  br label %36

36:                                               ; preds = %29, %26
  %37 = phi i1 [ false, %26 ], [ %35, %29 ]
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %55

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

52:                                               ; preds = %39
  %53 = load i32, ptr %11, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %11, align 4, !tbaa !11
  br label %26, !llvm.loop !21

55:                                               ; preds = %38
  %56 = load i32, ptr %9, align 4, !tbaa !11
  %57 = add i32 %56, 1
  %58 = add i32 %57, 3
  %59 = udiv i32 %58, 4
  %60 = add i32 1, %59
  store i32 %60, ptr %9, align 4, !tbaa !11
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = getelementptr inbounds [32 x i32], ptr %10, i64 0, i64 0
  %63 = load i32, ptr %9, align 4, !tbaa !11
  %64 = zext i32 %63 to i64
  call void @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEPKjm(ptr noundef nonnull align 8 dereferenceable(24) %12, i32 noundef %61, ptr noundef %62, i64 noundef %64)
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #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__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc = external hidden unnamed_addr constant [82 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 @_ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #3 align 2 {
  %5 = alloca [32 x i32], align 16
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %7, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 685, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8libspirv15MutableBytecode8Iterator6insertEN3spv2OpEjPKc) #4
  unreachable

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

15:                                               ; preds = %31, %14
  %indvars.iv = phi i64 [ 0, %14 ], [ %indvars.iv.next.3, %31 ]
  %16 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !17
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %.critedge.split.loop.exit19, label %22

.critedge.split.loop.exit19:                      ; preds = %28, %25, %22, %15
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %15 ], [ %indvars.iv.next, %22 ], [ %indvars.iv.next.1, %25 ], [ %indvars.iv.next.2, %28 ]
  %indvars18.le = trunc i64 %indvars.iv.lcssa to i32
  %18 = add i32 %indvars18.le, 4
  %19 = lshr i32 %18, 2
  %20 = add nuw nsw i32 %19, 1
  %21 = zext nneg i32 %20 to i64
  br label %.critedge

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

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

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

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

31:                                               ; preds = %28
  %gep.3 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next.2
  store i8 %30, 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, 120
  br i1 %exitcond.not.3, label %.critedge, label %15, !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