; LLVM IR from alibaba/GCanvas :: core/src/gcanvas/GStrSeparator.ll (ZN7gcanvas13GStrSeparator17SepStrByCharArrayEPcPKcss)

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

%"class.gcanvas::GStrSeparator" = type { [480 x ptr] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef signext i16 @_ZN7gcanvas13GStrSeparator17SepStrByCharArrayEPcPKcss(ptr noundef nonnull align 8 dereferenceable(3840) %0, ptr noundef %1, ptr noundef %2, i16 noundef signext %3, i16 noundef signext %4) #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i16 %3, ptr %9, align 2, !tbaa !9
  store i16 %4, ptr %10, align 2, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  %16 = load i16, ptr %10, align 2, !tbaa !9
  %17 = sext i16 %16 to i32
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i16 50, ptr %10, align 2, !tbaa !9
  br label %20

20:                                               ; preds = %19, %5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #2
  store i16 0, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #2
  store i16 0, ptr %12, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  store i8 1, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %21, ptr %14, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %72, %20
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %75

26:                                               ; preds = %22
  store i16 0, ptr %12, align 2, !tbaa !9
  br label %27

27:                                               ; preds = %47, %26
  %28 = load i16, ptr %12, align 2, !tbaa !9
  %29 = sext i16 %28 to i32
  %30 = load i16, ptr %9, align 2, !tbaa !9
  %31 = sext i16 %30 to i32
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %33, label %50

33:                                               ; preds = %27
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = sext i8 %35 to i32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i16, ptr %12, align 2, !tbaa !9
  %39 = sext i16 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %36, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %33
  store i8 1, ptr %13, align 1, !tbaa !11
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  store i8 0, ptr %45, align 1, !tbaa !13
  br label %50

46:                                               ; preds = %33
  br label %47

47:                                               ; preds = %46
  %48 = load i16, ptr %12, align 2, !tbaa !9
  %49 = add i16 %48, 1
  store i16 %49, ptr %12, align 2, !tbaa !9
  br label %27, !llvm.loop !14

50:                                               ; preds = %44, %27
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !13
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %71

54:                                               ; preds = %50
  %55 = load i8, ptr %13, align 1, !tbaa !11, !range !16, !noundef !17
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %71

57:                                               ; preds = %54
  %58 = load i16, ptr %11, align 2, !tbaa !9
  %59 = sext i16 %58 to i32
  %60 = load i16, ptr %10, align 2, !tbaa !9
  %61 = sext i16 %60 to i32
  %62 = icmp slt i32 %59, %61
  br i1 %62, label %63, label %70

63:                                               ; preds = %57
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.gcanvas::GStrSeparator", ptr %15, i32 0, i32 0
  %66 = load i16, ptr %11, align 2, !tbaa !9
  %67 = add i16 %66, 1
  store i16 %67, ptr %11, align 2, !tbaa !9
  %68 = sext i16 %66 to i64
  %69 = getelementptr inbounds [480 x ptr], ptr %65, i64 0, i64 %68
  store ptr %64, ptr %69, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %63, %57
  store i8 0, ptr %13, align 1, !tbaa !11
  br label %71

71:                                               ; preds = %70, %54, %50
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 1
  store ptr %74, ptr %14, align 8, !tbaa !5
  br label %22, !llvm.loop !18

75:                                               ; preds = %22
  %76 = load i16, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #2
  ret i16 %76
}

; 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !15}


; 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: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef signext i16 @_ZN7gcanvas13GStrSeparator17SepStrByCharArrayEPcPKcss(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(3840) %0, ptr noundef %1, ptr nocapture noundef readonly %2, i16 noundef signext %3, i16 noundef signext %4) local_unnamed_addr #0 align 2 {
  %6 = icmp slt i16 %4, 0
  %spec.store.select = select i1 %6, i16 50, i16 %4
  %7 = load i8, ptr %1, align 1, !tbaa !5
  %.not27 = icmp eq i8 %7, 0
  br i1 %.not27, label %._crit_edge31, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %5
  %8 = icmp sgt i16 %3, 0
  br i1 %8, label %.preheader.us.preheader, label %.preheader.peel

.preheader.peel:                                  ; preds = %.preheader.lr.ph
  %.not43 = icmp eq i16 %spec.store.select, 0
  br i1 %.not43, label %10, label %9

9:                                                ; preds = %.preheader.peel
  store ptr %1, ptr %0, align 8, !tbaa !8
  br label %10

10:                                               ; preds = %9, %.preheader.peel
  %.222.peel = phi i16 [ 0, %.preheader.peel ], [ 1, %9 ]
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not.peel = icmp eq i8 %12, 0
  br i1 %.not.peel, label %._crit_edge31, label %.preheader

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %22
  %.pr.us = phi i8 [ %24, %22 ], [ %7, %.preheader.us.preheader ]
  %.030.us = phi ptr [ %23, %22 ], [ %1, %.preheader.us.preheader ]
  %.01829.us = phi i1 [ %21, %22 ], [ true, %.preheader.us.preheader ]
  %.02028.us = phi i16 [ %.222.us, %22 ], [ 0, %.preheader.us.preheader ]
  br label %18

13:                                               ; preds = %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %18, !llvm.loop !10

14:                                               ; preds = %._crit_edge.us
  %15 = add nsw i16 %.02028.us, 1
  %16 = sext i16 %.02028.us to i64
  %17 = getelementptr inbounds [480 x ptr], ptr %0, i64 0, i64 %16
  store ptr %.030.us, ptr %17, align 8, !tbaa !8
  br label %22

18:                                               ; preds = %.preheader.us, %13
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %13 ]
  %19 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = icmp eq i8 %.pr.us, %20
  br i1 %21, label %.thread.us, label %13

.thread.us:                                       ; preds = %18
  store i8 0, ptr %.030.us, align 1, !tbaa !5
  br label %22

22:                                               ; preds = %.thread.us, %14, %._crit_edge.us
  %.222.us = phi i16 [ %.02028.us, %._crit_edge.us ], [ %15, %14 ], [ %.02028.us, %.thread.us ]
  %23 = getelementptr inbounds i8, ptr %.030.us, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %.not.us = icmp eq i8 %24, 0
  br i1 %.not.us, label %._crit_edge31, label %.preheader.us, !llvm.loop !12

._crit_edge.us:                                   ; preds = %13
  %25 = icmp slt i16 %.02028.us, %spec.store.select
  %or.cond = select i1 %.01829.us, i1 %25, i1 false
  br i1 %or.cond, label %14, label %22

.preheader:                                       ; preds = %10, %.preheader
  %.030 = phi ptr [ %26, %.preheader ], [ %11, %10 ]
  %26 = getelementptr inbounds i8, ptr %.030, i64 1
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %.not = icmp eq i8 %27, 0
  br i1 %.not, label %._crit_edge31, label %.preheader, !llvm.loop !13

._crit_edge31:                                    ; preds = %10, %.preheader, %22, %5
  %.020.lcssa = phi i16 [ 0, %5 ], [ %.222.us, %22 ], [ %.222.peel, %.preheader ], [ %.222.peel, %10 ]
  ret i16 %.020.lcssa
}

attributes #0 = { mustprogress 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" }

!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++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11, !14}
!14 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: AggressiveInstCombinePass,BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass