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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

14:                                               ; preds = %3
  store i16 50, ptr %6, align 2, !tbaa !9
  br label %15

15:                                               ; preds = %14, %3
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  store i16 0, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 1, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %9, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %48, %15
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %51

21:                                               ; preds = %17
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = call i32 @isspace(i32 noundef %24) #4
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %21
  store i8 1, ptr %8, align 1, !tbaa !11
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %28, align 1, !tbaa !13
  br label %47

29:                                               ; preds = %21
  %30 = load i8, ptr %8, align 1, !tbaa !11, !range !14, !noundef !15
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %46

32:                                               ; preds = %29
  %33 = load i16, ptr %7, align 2, !tbaa !9
  %34 = sext i16 %33 to i32
  %35 = load i16, ptr %6, align 2, !tbaa !9
  %36 = sext i16 %35 to i32
  %37 = icmp slt i32 %34, %36
  br i1 %37, label %38, label %45

38:                                               ; preds = %32
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.gcanvas::GStrSeparator", ptr %10, i32 0, i32 0
  %41 = load i16, ptr %7, align 2, !tbaa !9
  %42 = add i16 %41, 1
  store i16 %42, ptr %7, align 2, !tbaa !9
  %43 = sext i16 %41 to i64
  %44 = getelementptr inbounds [480 x ptr], ptr %40, i64 0, i64 %43
  store ptr %39, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %38, %32
  store i8 0, ptr %8, align 1, !tbaa !11
  br label %46

46:                                               ; preds = %45, %29
  br label %47

47:                                               ; preds = %46, %27
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %17, !llvm.loop !16

51:                                               ; preds = %17
  %52 = load i16, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  ret i16 %52
}

; Function Attrs: inlinehint mustprogress nounwind willreturn memory(read) uwtable
declare i32 @isspace(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint mustprogress nounwind willreturn memory(read) 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nofree nounwind memory(readwrite, inaccessiblemem: read) uwtable
define dso_local noundef signext i16 @_ZN7gcanvas13GStrSeparator13SepStrBySpaceEPcs(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(3840) %0, ptr noundef %1, i16 noundef signext %2) local_unnamed_addr #0 align 2 {
  %4 = icmp slt i16 %2, 0
  %spec.store.select = select i1 %4, i16 50, i16 %2
  %5 = load i8, ptr %1, align 1, !tbaa !5
  %.not17 = icmp eq i8 %5, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %16
  %6 = phi i8 [ %18, %16 ], [ %5, %3 ]
  %.020 = phi ptr [ %17, %16 ], [ %1, %3 ]
  %.01219 = phi i1 [ %.not16, %16 ], [ true, %3 ]
  %.01318 = phi i16 [ %.2, %16 ], [ 0, %3 ]
  %7 = zext i8 %6 to i32
  %8 = tail call i32 @isspace(i32 noundef %7) #2
  %.not16 = icmp ne i32 %8, 0
  br i1 %.not16, label %9, label %10

9:                                                ; preds = %.lr.ph
  store i8 0, ptr %.020, align 1, !tbaa !5
  br label %16

10:                                               ; preds = %.lr.ph
  %11 = icmp slt i16 %.01318, %spec.store.select
  %or.cond = select i1 %.01219, i1 %11, i1 false
  br i1 %or.cond, label %12, label %16

12:                                               ; preds = %10
  %13 = add nsw i16 %.01318, 1
  %14 = sext i16 %.01318 to i64
  %15 = getelementptr inbounds [480 x ptr], ptr %0, i64 0, i64 %14
  store ptr %.020, ptr %15, align 8, !tbaa !8
  br label %16

16:                                               ; preds = %12, %9, %10
  %.2 = phi i16 [ %.01318, %9 ], [ %.01318, %10 ], [ %13, %12 ]
  %17 = getelementptr inbounds i8, ptr %.020, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %16, %3
  %.013.lcssa = phi i16 [ 0, %3 ], [ %.2, %16 ]
  ret i16 %.013.lcssa
}

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @isspace(i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind memory(readwrite, inaccessiblemem: read) 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #2 = { nounwind willreturn memory(read) }

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


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass