; LLVM IR from nde-jesu/Doom_Nukem :: libft/srcs/string (ft_strsplit)

; 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 ptr @ft_strsplit(ptr noundef %0, i8 noundef signext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %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 i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i32 0, ptr %6, align 4, !tbaa !10
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %21

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = call i32 @ft_wordcount(ptr noundef %13, i8 noundef signext %14)
  %16 = add nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = mul i64 8, %17
  %19 = call noalias ptr @malloc(i64 noundef %18) #5
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %12, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

22:                                               ; preds = %12
  store i32 0, ptr %7, align 4, !tbaa !10
  br label %23

23:                                               ; preds = %87, %22
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !10
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %88

31:                                               ; preds = %23
  br label %32

32:                                               ; preds = %52, %31
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !10
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %50

40:                                               ; preds = %32
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !10
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = load i8, ptr %5, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %46, %48
  br label %50

50:                                               ; preds = %40, %32
  %51 = phi i1 [ false, %32 ], [ %49, %40 ]
  br i1 %51, label %52, label %55

52:                                               ; preds = %50
  %53 = load i32, ptr %6, align 4, !tbaa !10
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !10
  br label %32, !llvm.loop !12

55:                                               ; preds = %50
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !10
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %87

63:                                               ; preds = %55
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !10
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !10
  %68 = load i8, ptr %5, align 1, !tbaa !9
  %69 = call i32 @ft_wordlength(ptr noundef %66, i32 noundef %67, i8 noundef signext %68)
  %70 = sext i32 %69 to i64
  %71 = call ptr @ft_strsub(ptr noundef %64, i32 noundef %65, i64 noundef %70)
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !10
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %7, align 4, !tbaa !10
  %75 = sext i32 %73 to i64
  %76 = getelementptr inbounds ptr, ptr %72, i64 %75
  store ptr %71, ptr %76, align 8, !tbaa !5
  %77 = icmp ne ptr %71, null
  br i1 %77, label %80, label %78

78:                                               ; preds = %63
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free_split(ptr noundef %79)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

80:                                               ; preds = %63
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i32, ptr %6, align 4, !tbaa !10
  %83 = load i8, ptr %5, align 1, !tbaa !9
  %84 = call i32 @ft_wordlength(ptr noundef %81, i32 noundef %82, i8 noundef signext %83)
  %85 = load i32, ptr %6, align 4, !tbaa !10
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %6, align 4, !tbaa !10
  br label %87

87:                                               ; preds = %80, %55
  br label %23, !llvm.loop !14

88:                                               ; preds = %23
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load i32, ptr %7, align 4, !tbaa !10
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds ptr, ptr %89, i64 %91
  store ptr null, ptr %92, align 8, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %93, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

94:                                               ; preds = %88, %78, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %95 = load ptr, ptr %3, align 8
  ret ptr %95
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @ft_wordcount(ptr noundef, i8 noundef signext) #3

declare ptr @ft_strsub(ptr noundef, i32 noundef, i64 noundef) #3

declare i32 @ft_wordlength(ptr noundef, i32 noundef, i8 noundef signext) #3

; Function Attrs: nounwind uwtable
declare hidden void @free_split(ptr noundef) #0

; 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 allocsize(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 = { "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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: nounwind uwtable
define dso_local noundef ptr @ft_strsplit(ptr noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %33, label %3

3:                                                ; preds = %2
  %4 = tail call i32 @ft_wordcount(ptr noundef nonnull %0, i8 noundef signext %1) #3
  %5 = add nsw i32 %4, 1
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 3
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #4
  %.not34 = icmp eq ptr %8, null
  br i1 %.not34, label %33, label %.preheader39

.preheader39:                                     ; preds = %3
  %9 = load i8, ptr %0, align 1, !tbaa !5
  %.not3541 = icmp eq i8 %9, 0
  br i1 %.not3541, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader39, %27
  %.02843 = phi i32 [ %.1, %27 ], [ 0, %.preheader39 ]
  %.02942 = phi i32 [ %.2, %27 ], [ 0, %.preheader39 ]
  %10 = sext i32 %.02942 to i64
  br label %11

11:                                               ; preds = %11, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %11 ], [ %10, %.preheader ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not36 = icmp ne i8 %13, 0
  %14 = icmp eq i8 %13, %1
  %or.cond = and i1 %.not36, %14
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  br i1 %or.cond, label %11, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %11
  %15 = trunc nsw i64 %indvars.iv to i32
  %.not37 = icmp eq i8 %13, 0
  br i1 %.not37, label %27, label %16

16:                                               ; preds = %.critedge
  %17 = tail call i32 @ft_wordlength(ptr noundef nonnull %0, i32 noundef %15, i8 noundef signext %1) #3
  %18 = sext i32 %17 to i64
  %19 = tail call ptr @ft_strsub(ptr noundef nonnull %0, i32 noundef %15, i64 noundef %18) #3
  %20 = sext i32 %.02843 to i64
  %21 = getelementptr inbounds ptr, ptr %8, i64 %20
  store ptr %19, ptr %21, align 8, !tbaa !10
  %.not38 = icmp eq ptr %19, null
  br i1 %.not38, label %22, label %23

22:                                               ; preds = %16
  tail call void @free_split(ptr noundef nonnull %8)
  br label %33

23:                                               ; preds = %16
  %24 = add nsw i32 %.02843, 1
  %25 = tail call i32 @ft_wordlength(ptr noundef nonnull %0, i32 noundef %15, i8 noundef signext %1) #3
  %26 = add nsw i32 %25, %15
  br label %27

27:                                               ; preds = %23, %.critedge
  %.2 = phi i32 [ %26, %23 ], [ %15, %.critedge ]
  %.1 = phi i32 [ %24, %23 ], [ %.02843, %.critedge ]
  %28 = sext i32 %.2 to i64
  %29 = getelementptr inbounds i8, ptr %0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %.not35 = icmp eq i8 %30, 0
  br i1 %.not35, label %._crit_edge.loopexit, label %.preheader, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %27
  %31 = sext i32 %.1 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader39
  %.028.lcssa = phi i64 [ 0, %.preheader39 ], [ %31, %._crit_edge.loopexit ]
  %32 = getelementptr inbounds ptr, ptr %8, i64 %.028.lcssa
  store ptr null, ptr %32, align 8, !tbaa !10
  br label %33

33:                                               ; preds = %2, %3, %._crit_edge, %22
  %.0 = phi ptr [ null, %22 ], [ %8, %._crit_edge ], [ null, %3 ], [ null, %2 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare i32 @ft_wordcount(ptr noundef, i8 noundef signext) local_unnamed_addr #2

declare ptr @ft_strsub(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @ft_wordlength(ptr noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @free_split(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 allocsize(0) }

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


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