; LLVM IR from NOAA-PMEL/Ferret :: fmt/src (tm_unblockify_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"

@.str = external hidden unnamed_addr constant [89 x i8], align 1

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

17:                                               ; preds = %86, %4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sdiv i32 %19, %20
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %89

23:                                               ; preds = %17
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %38, %23
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %36

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

36:                                               ; preds = %28, %24
  %37 = phi i1 [ false, %24 ], [ %35, %28 ]
  br i1 %37, label %38, label %41

38:                                               ; preds = %36
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !12

41:                                               ; preds = %36
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %42, ptr %11, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = sext i32 %43 to i64
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  store ptr %46, ptr %12, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = mul i64 1, %49
  %51 = call ptr @FerMem_Malloc(i64 noundef %50, ptr noundef @.str, i32 noundef 76)
  store ptr %51, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %41
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  call void @FerMem_Free(ptr noundef %57, ptr noundef @.str, i32 noundef 83)
  br label %58

58:                                               ; preds = %55, %41
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = getelementptr inbounds ptr, ptr %61, i64 1
  store ptr %62, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %74, %58
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %72

67:                                               ; preds = %63
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %70, 0
  br label %72

72:                                               ; preds = %67, %63
  %73 = phi i1 [ false, %63 ], [ %71, %67 ]
  br i1 %73, label %74, label %84

74:                                               ; preds = %72
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load i8, ptr %75, align 1, !tbaa !11
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 %76, ptr %77, align 1, !tbaa !11
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i32 1
  store ptr %79, ptr %13, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i32 1
  store ptr %81, ptr %11, align 8, !tbaa !5
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %10, align 4, !tbaa !9
  br label %63, !llvm.loop !14

84:                                               ; preds = %72
  %85 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %85, align 1, !tbaa !11
  br label %86

86:                                               ; preds = %84
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !15

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

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

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) #2

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) #2

; 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 = { "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/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"

@.str = external hidden unnamed_addr constant [89 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @tm_unblockify_ferret_strings(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sdiv i32 %2, %3
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %4
  %7 = sext i32 %3 to i64
  %8 = icmp sgt i32 %3, 0
  br i1 %8, label %.preheader.us.us.preheader, label %.preheader

.preheader.us.us.preheader:                       ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader, %.critedge2.us.us
  %.050.us.us = phi ptr [ %20, %.critedge2.us.us ], [ %0, %.preheader.us.us.preheader ]
  %.03149.us.us = phi ptr [ %14, %.critedge2.us.us ], [ %1, %.preheader.us.us.preheader ]
  %.03448.us.us = phi i32 [ %27, %.critedge2.us.us ], [ 0, %.preheader.us.us.preheader ]
  br label %9

9:                                                ; preds = %.preheader.us.us, %12
  %indvars.iv = phi i64 [ 0, %.preheader.us.us ], [ %indvars.iv.next, %12 ]
  %10 = getelementptr inbounds i8, ptr %.03149.us.us, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %.not.us.us = icmp eq i8 %11, 0
  br i1 %.not.us.us, label %.critedge.us.us.split.loop.exit, label %12

12:                                               ; preds = %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond68.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond68.not, label %.critedge.us.us, label %9, !llvm.loop !8

.critedge.us.us.split.loop.exit:                  ; preds = %9
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge.us.us

.critedge.us.us:                                  ; preds = %12, %.critedge.us.us.split.loop.exit
  %.033.lcssa.us.us = phi i32 [ %13, %.critedge.us.us.split.loop.exit ], [ %3, %12 ]
  %14 = getelementptr inbounds i8, ptr %.03149.us.us, i64 %7
  %15 = add nuw nsw i32 %.033.lcssa.us.us, 1
  %16 = zext nneg i32 %15 to i64
  %17 = tail call ptr @FerMem_Malloc(i64 noundef %16, ptr noundef nonnull @.str, i32 noundef 76) #2
  %18 = load ptr, ptr %.050.us.us, align 8, !tbaa !10
  %.not36.us.us = icmp eq ptr %18, null
  br i1 %.not36.us.us, label %.lr.ph44.us.us, label %19

19:                                               ; preds = %.critedge.us.us
  tail call void @FerMem_Free(ptr noundef nonnull %18, ptr noundef nonnull @.str, i32 noundef 83) #2
  br label %.lr.ph44.us.us

.lr.ph44.us.us:                                   ; preds = %19, %.critedge.us.us
  store ptr %17, ptr %.050.us.us, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %.050.us.us, i64 8
  br label %21

21:                                               ; preds = %23, %.lr.ph44.us.us
  %.03043.us.us = phi ptr [ %17, %.lr.ph44.us.us ], [ %24, %23 ]
  %.03242.us.us = phi ptr [ %.03149.us.us, %.lr.ph44.us.us ], [ %25, %23 ]
  %.141.us.us = phi i32 [ 0, %.lr.ph44.us.us ], [ %26, %23 ]
  %22 = load i8, ptr %.03242.us.us, align 1, !tbaa !5
  %.not37.us.us = icmp eq i8 %22, 0
  br i1 %.not37.us.us, label %.critedge2.us.us, label %23

23:                                               ; preds = %21
  store i8 %22, ptr %.03043.us.us, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.03043.us.us, i64 1
  %25 = getelementptr inbounds i8, ptr %.03242.us.us, i64 1
  %26 = add nuw nsw i32 %.141.us.us, 1
  %exitcond69.not = icmp eq i32 %26, %3
  br i1 %exitcond69.not, label %.critedge2.us.us, label %21, !llvm.loop !12

.critedge2.us.us:                                 ; preds = %21, %23
  %.030.lcssa.us.us = phi ptr [ %24, %23 ], [ %.03043.us.us, %21 ]
  store i8 0, ptr %.030.lcssa.us.us, align 1, !tbaa !5
  %27 = add nuw nsw i32 %.03448.us.us, 1
  %exitcond70.not = icmp eq i32 %27, %5
  br i1 %exitcond70.not, label %._crit_edge, label %.preheader.us.us, !llvm.loop !13

.preheader:                                       ; preds = %.preheader.lr.ph, %.critedge2
  %.050 = phi ptr [ %31, %.critedge2 ], [ %0, %.preheader.lr.ph ]
  %.03448 = phi i32 [ %32, %.critedge2 ], [ 0, %.preheader.lr.ph ]
  %28 = tail call ptr @FerMem_Malloc(i64 noundef 1, ptr noundef nonnull @.str, i32 noundef 76) #2
  %29 = load ptr, ptr %.050, align 8, !tbaa !10
  %.not36 = icmp eq ptr %29, null
  br i1 %.not36, label %.critedge2, label %30

30:                                               ; preds = %.preheader
  tail call void @FerMem_Free(ptr noundef nonnull %29, ptr noundef nonnull @.str, i32 noundef 83) #2
  br label %.critedge2

.critedge2:                                       ; preds = %30, %.preheader
  store ptr %28, ptr %.050, align 8, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %.050, i64 8
  store i8 0, ptr %28, align 1, !tbaa !5
  %32 = add nuw nsw i32 %.03448, 1
  %exitcond.not = icmp eq i32 %32, %5
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !13

._crit_edge:                                      ; preds = %.critedge2, %.critedge2.us.us, %4
  ret void
}

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = distinct !{!12, !9}
!13 = distinct !{!13, !9}


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