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

; 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 @str_dncase_sub_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !9
  br label %24

21:                                               ; preds = %4
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %21, %18
  %25 = phi i32 [ %20, %18 ], [ %23, %21 ]
  store i32 %25, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %49, %24
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %52

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %31 = call ptr @__ctype_tolower_loc() #4
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %32, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  store i32 %41, ptr %11, align 4, !tbaa !9
  %42 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %42, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !11
  br label %49

49:                                               ; preds = %30
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !9
  br label %26, !llvm.loop !12

52:                                               ; preds = %26
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = icmp sgt i32 %54, %56
  br i1 %57, label %58, label %75

58:                                               ; preds = %52
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i32, ptr %59, align 4, !tbaa !9
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %71, %58
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = icmp slt i32 %62, %64
  br i1 %65, label %66, label %74

66:                                               ; preds = %61
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  store i8 32, ptr %70, align 1, !tbaa !11
  br label %71

71:                                               ; preds = %66
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %10, align 4, !tbaa !9
  br label %61, !llvm.loop !14

74:                                               ; preds = %61
  br label %75

75:                                               ; preds = %74, %52
  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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() #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 = { nounwind willreturn memory(none) "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 }
attributes #4 = { nounwind willreturn memory(none) }

!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}


; 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 nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @str_dncase_sub_(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %. = tail call i32 @llvm.smin.i32(i32 %5, i32 %6)
  %7 = icmp sgt i32 %., 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %8 = tail call ptr @__ctype_tolower_loc() #3
  %wide.trip.count = zext nneg i32 %. to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %9 = icmp ult i32 %., 4
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %10

10:                                               ; preds = %10, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %10 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %10 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i64
  %15 = getelementptr inbounds i32, ptr %11, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = trunc i32 %16 to i8
  %18 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  store i8 %17, ptr %18, align 1, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv.next
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i64
  %23 = getelementptr inbounds i32, ptr %19, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  store i8 %25, ptr %26, align 1, !tbaa !11
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv.next.1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i64
  %31 = getelementptr inbounds i32, ptr %27, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = trunc i32 %32 to i8
  %34 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  store i8 %33, ptr %34, align 1, !tbaa !11
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv.next.2
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i64
  %39 = getelementptr inbounds i32, ptr %35, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = trunc i32 %40 to i8
  %42 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  store i8 %41, ptr %42, align 1, !tbaa !11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %10, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %10, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %10 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv.epil
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i64
  %47 = getelementptr inbounds i32, ptr %43, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = trunc i32 %48 to i8
  %50 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.epil
  store i8 %49, ptr %50, align 1, !tbaa !11
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.epil.preheader, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.epil.preheader, %._crit_edge.loopexit.unr-lcssa
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %.pre30 = load i32, ptr %3, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %51 = phi i32 [ %.pre30, %._crit_edge.loopexit ], [ %6, %4 ]
  %52 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %5, %4 ]
  %53 = icmp sgt i32 %52, %51
  br i1 %53, label %.lr.ph25.preheader, label %.loopexit

.lr.ph25.preheader:                               ; preds = %._crit_edge
  %54 = sext i32 %51 to i64
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %.lr.ph25
  %indvars.iv27 = phi i64 [ %54, %.lr.ph25.preheader ], [ %indvars.iv.next28, %.lr.ph25 ]
  %55 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv27
  store i8 32, ptr %55, align 1, !tbaa !11
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, 1
  %56 = load i32, ptr %1, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = icmp slt i64 %indvars.iv.next28, %57
  br i1 %58, label %.lr.ph25, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph25, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { nofree nosync nounwind memory(read, argmem: 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !13}


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