; LLVM IR from lionsoul2014/friso :: src (friso_string)

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

%struct.string_split_entry = type { ptr, i32, ptr, i32, i32 }

; 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: nounwind uwtable
define dso_local ptr @string_split_next(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.string_split_entry, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.string_split_entry, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp uge i32 %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %103

19:                                               ; preds = %2
  br label %20

20:                                               ; preds = %99, %19
  br label %21

21:                                               ; preds = %20
  store i32 1, ptr %7, align 4, !tbaa !13
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %64, %21
  %23 = load i32, ptr %6, align 4, !tbaa !13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.string_split_entry, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = icmp ult i32 %23, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.string_split_entry, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !13
  %33 = add i32 %31, %32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.string_split_entry, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = icmp ult i32 %33, %36
  br label %38

38:                                               ; preds = %28, %22
  %39 = phi i1 [ false, %22 ], [ %37, %28 ]
  br i1 %39, label %40, label %67

40:                                               ; preds = %38
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.string_split_entry, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.string_split_entry, ptr %44, i32 0, i32 4
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !13
  %48 = add i32 %46, %47
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %43, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !16
  %52 = sext i8 %51 to i32
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.string_split_entry, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = load i32, ptr %6, align 4, !tbaa !13
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !16
  %60 = sext i8 %59 to i32
  %61 = icmp ne i32 %52, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %40
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %67

63:                                               ; preds = %40
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %6, align 4, !tbaa !13
  %66 = add i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !13
  br label %22, !llvm.loop !18

67:                                               ; preds = %62, %38
  %68 = load i32, ptr %7, align 4, !tbaa !13
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %70, label %78

70:                                               ; preds = %67
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.string_split_entry, ptr %71, i32 0, i32 3
  %73 = load i32, ptr %72, align 8, !tbaa !14
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.string_split_entry, ptr %74, i32 0, i32 4
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = add i32 %76, %73
  store i32 %77, ptr %75, align 4, !tbaa !9
  br label %100

78:                                               ; preds = %67
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.string_split_entry, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.string_split_entry, ptr %82, i32 0, i32 4
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = add i32 %84, 1
  store i32 %85, ptr %83, align 4, !tbaa !9
  %86 = zext i32 %84 to i64
  %87 = getelementptr inbounds i8, ptr %81, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !16
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i32 1
  store ptr %90, ptr %8, align 8, !tbaa !5
  store i8 %88, ptr %89, align 1, !tbaa !16
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.string_split_entry, ptr %91, i32 0, i32 4
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.string_split_entry, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 8, !tbaa !12
  %97 = icmp uge i32 %93, %96
  br i1 %97, label %98, label %99

98:                                               ; preds = %78
  br label %100

99:                                               ; preds = %78
  br label %20

100:                                              ; preds = %98, %70
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %101, align 1, !tbaa !16
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %102, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %103

103:                                              ; preds = %100, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %104 = load ptr, ptr %3, align 8
  ret ptr %104
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !11, i64 28}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 24}
!15 = !{!10, !6, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @string_split_next(ptr nocapture noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %.not = icmp ult i32 %4, %6
  br i1 %.not, label %.preheader, label %34

.preheader:                                       ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %9

9:                                                ; preds = %.preheader, %.critedge
  %10 = phi i32 [ %33, %.critedge ], [ %6, %.preheader ]
  %11 = phi i32 [ %32, %.critedge ], [ %4, %.preheader ]
  %.0 = phi ptr [ %31, %.critedge ], [ %1, %.preheader ]
  %12 = load i32, ptr %7, align 8, !tbaa !12
  %.not44 = icmp eq i32 %12, 0
  br i1 %.not44, label %.critedge30, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %13 = tail call i32 @llvm.usub.sat.i32(i32 %10, i32 %11)
  %wide.trip.count = zext i32 %13 to i64
  %wide.trip.count54 = zext i32 %12 to i64
  br label %15

14:                                               ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next, %wide.trip.count54
  br i1 %exitcond55.not, label %.critedge30, label %15, !llvm.loop !13

15:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond.not, label %.critedge30, label %16

16:                                               ; preds = %15
  %17 = trunc nuw i64 %indvars.iv to i32
  %18 = add i32 %11, %17
  %19 = load ptr, ptr %0, align 8, !tbaa !15
  %20 = zext i32 %18 to i64
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !16
  %23 = load ptr, ptr %8, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %23, i64 %indvars.iv
  %25 = load i8, ptr %24, align 1, !tbaa !16
  %.not28 = icmp eq i8 %22, %25
  br i1 %.not28, label %14, label %.critedge

.critedge30:                                      ; preds = %9, %15, %14
  %26 = add i32 %11, %12
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %.loopexit

.critedge:                                        ; preds = %16
  %27 = add i32 %11, 1
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = zext i32 %11 to i64
  %29 = getelementptr inbounds i8, ptr %19, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %.0, i64 1
  store i8 %30, ptr %.0, align 1, !tbaa !16
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 8, !tbaa !11
  %.not29 = icmp ult i32 %32, %33
  br i1 %.not29, label %9, label %.loopexit

.loopexit:                                        ; preds = %.critedge, %.critedge30
  %.1 = phi ptr [ %.0, %.critedge30 ], [ %31, %.critedge ]
  store i8 0, ptr %.1, align 1, !tbaa !16
  br label %34

34:                                               ; preds = %2, %.loopexit
  %.026 = phi ptr [ %.1, %.loopexit ], [ null, %2 ]
  ret ptr %.026
}

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

attributes #0 = { 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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable 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, !10, i64 28}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 0}
!16 = !{!8, !8, i64 0}
!17 = !{!6, !7, i64 16}


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