; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (set_null_c_string_array)

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

@STRING_MISSING_VALUE = external global ptr, align 8
@.str = external hidden unnamed_addr constant [84 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @set_null_c_string_array_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %31, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %34

14:                                               ; preds = %9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %22 = icmp ne ptr %20, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  call void @FerMem_Free(ptr noundef %25, ptr noundef @.str, i32 noundef 54)
  br label %26

26:                                               ; preds = %23, %18, %14
  %27 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %27, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds ptr, ptr %29, i64 1
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !11

34:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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 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 = distinct !{!11, !12}
!12 = !{!"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"

@STRING_MISSING_VALUE = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [84 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @set_null_c_string_array_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !9
  %.pre = load ptr, ptr @STRING_MISSING_VALUE, align 8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %10
  %6 = phi i32 [ %11, %10 ], [ %3, %.lr.ph.preheader ]
  %7 = phi ptr [ %12, %10 ], [ %.pre, %.lr.ph.preheader ]
  %.012 = phi i32 [ %14, %10 ], [ 0, %.lr.ph.preheader ]
  %.0811 = phi ptr [ %13, %10 ], [ %5, %.lr.ph.preheader ]
  %8 = load ptr, ptr %.0811, align 8, !tbaa !9
  %.not = icmp eq ptr %8, null
  %.not10 = icmp eq ptr %8, %7
  %or.cond = select i1 %.not, i1 true, i1 %.not10
  br i1 %or.cond, label %10, label %9

9:                                                ; preds = %.lr.ph
  tail call void @FerMem_Free(ptr noundef nonnull %8, ptr noundef nonnull @.str, i32 noundef 54) #2
  %.pre13 = load ptr, ptr @STRING_MISSING_VALUE, align 8
  %.pre14 = load i32, ptr %1, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %.lr.ph
  %11 = phi i32 [ %.pre14, %9 ], [ %6, %.lr.ph ]
  %12 = phi ptr [ %.pre13, %9 ], [ %7, %.lr.ph ]
  store ptr %12, ptr %.0811, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %.0811, i64 8
  %14 = add nuw nsw i32 %.012, 1
  %15 = icmp slt i32 %14, %11
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %10, %2
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass