; LLVM IR from NOAA-PMEL/Ferret :: fmt/src (tm_blockify_ferret_strings)

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

; Function Attrs: nounwind uwtable
define dso_local void @tm_blockify_ferret_strings(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %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 ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  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
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %23, %4
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !11
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !12

26:                                               ; preds = %14
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %27, ptr %13, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %28, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %65, %26
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sdiv i32 %31, %32
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %35, label %68

35:                                               ; preds = %29
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %36, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store ptr %42, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds ptr, ptr %43, i64 1
  store ptr %44, ptr %13, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %56, %35
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = icmp ult ptr %46, %47
  br i1 %48, label %49, label %54

49:                                               ; preds = %45
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = sext i8 %51 to i32
  %53 = icmp ne i32 %52, 0
  br label %54

54:                                               ; preds = %49, %45
  %55 = phi i1 [ false, %45 ], [ %53, %49 ]
  br i1 %55, label %56, label %64

56:                                               ; preds = %54
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !11
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %58, ptr %59, align 1, !tbaa !11
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 1
  store ptr %61, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i32 1
  store ptr %63, ptr %12, align 8, !tbaa !5
  br label %45, !llvm.loop !14

64:                                               ; preds = %54
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !9
  br label %29, !llvm.loop !15

68:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @tm_blockify_ferret_strings(ptr nocapture noundef readonly %0, ptr noundef writeonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %4
  %6 = zext nneg i32 %2 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %1, i8 0, i64 %6, i1 false), !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.preheader, %4
  %7 = sdiv i32 %2, %3
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph35, label %._crit_edge

.lr.ph35:                                         ; preds = %.preheader
  %9 = sext i32 %3 to i64
  %10 = icmp sgt i32 %3, 0
  %xtraiter = and i32 %7, 1
  %11 = icmp eq i32 %7, 1
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph35.new

.lr.ph35.new:                                     ; preds = %.lr.ph35
  %unroll_iter = and i32 %7, 2147483646
  br label %12

12:                                               ; preds = %.critedge.1, %.lr.ph35.new
  %.034 = phi ptr [ %0, %.lr.ph35.new ], [ %22, %.critedge.1 ]
  %.02333 = phi ptr [ %1, %.lr.ph35.new ], [ %21, %.critedge.1 ]
  %niter = phi i32 [ 0, %.lr.ph35.new ], [ %niter.next.1, %.critedge.1 ]
  %13 = getelementptr inbounds i8, ptr %.02333, i64 %9
  %14 = getelementptr inbounds i8, ptr %.034, i64 8
  br i1 %10, label %.lr.ph30.preheader, label %.critedge

.lr.ph30.preheader:                               ; preds = %12
  %15 = load ptr, ptr %.034, align 8, !tbaa !8
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %17
  %.02229 = phi ptr [ %19, %17 ], [ %15, %.lr.ph30.preheader ]
  %.02428 = phi ptr [ %18, %17 ], [ %.02333, %.lr.ph30.preheader ]
  %16 = load i8, ptr %.02229, align 1, !tbaa !5
  %.not = icmp eq i8 %16, 0
  br i1 %.not, label %.critedge, label %17

17:                                               ; preds = %.lr.ph30
  store i8 %16, ptr %.02428, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.02428, i64 1
  %19 = getelementptr inbounds i8, ptr %.02229, i64 1
  %20 = icmp ult ptr %18, %13
  br i1 %20, label %.lr.ph30, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %17, %.lr.ph30, %12
  %21 = getelementptr inbounds i8, ptr %13, i64 %9
  %22 = getelementptr inbounds i8, ptr %.034, i64 16
  br i1 %10, label %.lr.ph30.preheader.1, label %.critedge.1

.lr.ph30.preheader.1:                             ; preds = %.critedge
  %23 = load ptr, ptr %14, align 8, !tbaa !8
  br label %.lr.ph30.1

.lr.ph30.1:                                       ; preds = %25, %.lr.ph30.preheader.1
  %.02229.1 = phi ptr [ %27, %25 ], [ %23, %.lr.ph30.preheader.1 ]
  %.02428.1 = phi ptr [ %26, %25 ], [ %13, %.lr.ph30.preheader.1 ]
  %24 = load i8, ptr %.02229.1, align 1, !tbaa !5
  %.not.1 = icmp eq i8 %24, 0
  br i1 %.not.1, label %.critedge.1, label %25

25:                                               ; preds = %.lr.ph30.1
  store i8 %24, ptr %.02428.1, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.02428.1, i64 1
  %27 = getelementptr inbounds i8, ptr %.02229.1, i64 1
  %28 = icmp ult ptr %26, %21
  br i1 %28, label %.lr.ph30.1, label %.critedge.1, !llvm.loop !10

.critedge.1:                                      ; preds = %.lr.ph30.1, %25, %.critedge
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %12, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.critedge.1, %.lr.ph35
  %.034.unr = phi ptr [ %0, %.lr.ph35 ], [ %22, %.critedge.1 ]
  %.02333.unr = phi ptr [ %1, %.lr.ph35 ], [ %21, %.critedge.1 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %29 = getelementptr inbounds i8, ptr %.02333.unr, i64 %9
  br i1 %10, label %.lr.ph30.preheader.epil, label %._crit_edge

.lr.ph30.preheader.epil:                          ; preds = %.epil.preheader
  %30 = load ptr, ptr %.034.unr, align 8, !tbaa !8
  br label %.lr.ph30.epil

.lr.ph30.epil:                                    ; preds = %32, %.lr.ph30.preheader.epil
  %.02229.epil = phi ptr [ %34, %32 ], [ %30, %.lr.ph30.preheader.epil ]
  %.02428.epil = phi ptr [ %33, %32 ], [ %.02333.unr, %.lr.ph30.preheader.epil ]
  %31 = load i8, ptr %.02229.epil, align 1, !tbaa !5
  %.not.epil = icmp eq i8 %31, 0
  br i1 %.not.epil, label %._crit_edge, label %32

32:                                               ; preds = %.lr.ph30.epil
  store i8 %31, ptr %.02428.epil, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.02428.epil, i64 1
  %34 = getelementptr inbounds i8, ptr %.02229.epil, i64 1
  %35 = icmp ult ptr %33, %29
  br i1 %35, label %.lr.ph30.epil, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph30.epil, %32, %.epil.preheader, %.preheader
  ret void
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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: write) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass