; LLVM IR from yettabaa/FdF :: libft_fdf (ft_split)

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @nb_w(ptr noundef, i8 noundef signext) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @len_split(ptr noundef, i8 noundef signext) #2

; Function Attrs: nounwind uwtable
declare hidden void @free_s(ptr noundef, i32 noundef) #2

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

13:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %111

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i8, ptr %6, align 1, !tbaa !9
  %17 = call i32 @nb_w(ptr noundef %15, i8 noundef signext %16)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !10
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = mul i64 8, %22
  %24 = call noalias ptr @malloc(i64 noundef %23) #5
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %14
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %111

28:                                               ; preds = %14
  store i32 0, ptr %8, align 4, !tbaa !10
  br label %29

29:                                               ; preds = %104, %28
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %33, label %105

33:                                               ; preds = %29
  br label %34

34:                                               ; preds = %48, %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = load i8, ptr %6, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %37, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %34
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br label %46

46:                                               ; preds = %41, %34
  %47 = phi i1 [ false, %34 ], [ %45, %41 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %34, !llvm.loop !12

51:                                               ; preds = %46
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i8, ptr %52, align 1, !tbaa !9
  %54 = sext i8 %53 to i32
  %55 = load i8, ptr %6, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %54, %56
  br i1 %57, label %58, label %104

58:                                               ; preds = %51
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %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 %104

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

80:                                               ; preds = %63
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !10
  call void @free_s(ptr noundef %81, i32 noundef %82)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %111

83:                                               ; preds = %63
  %84 = load i32, ptr %8, align 4, !tbaa !10
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !10
  br label %86

86:                                               ; preds = %100, %83
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load i8, ptr %87, align 1, !tbaa !9
  %89 = sext i8 %88 to i32
  %90 = load i8, ptr %6, align 1, !tbaa !9
  %91 = sext i8 %90 to i32
  %92 = icmp ne i32 %89, %91
  br i1 %92, label %93, label %98

93:                                               ; preds = %86
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load i8, ptr %94, align 1, !tbaa !9
  %96 = sext i8 %95 to i32
  %97 = icmp ne i32 %96, 0
  br label %98

98:                                               ; preds = %93, %86
  %99 = phi i1 [ false, %86 ], [ %97, %93 ]
  br i1 %99, label %100, label %103

100:                                              ; preds = %98
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i32 1
  store ptr %102, ptr %5, align 8, !tbaa !5
  br label %86, !llvm.loop !14

103:                                              ; preds = %98
  br label %104

104:                                              ; preds = %103, %58, %51
  br label %29, !llvm.loop !15

105:                                              ; preds = %29
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = load i32, ptr %8, align 4, !tbaa !10
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds ptr, ptr %106, i64 %108
  store ptr null, ptr %109, align 8, !tbaa !5
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %110, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %111

111:                                              ; preds = %105, %80, %27, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %112 = load ptr, ptr %4, align 8
  ret ptr %112
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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}
!15 = distinct !{!15, !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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @nb_w(ptr noundef, i8 noundef signext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @len_split(ptr noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @free_s(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ft_split_count(ptr noundef %0, i8 noundef signext %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %28, label %4

4:                                                ; preds = %3
  %5 = tail call i32 @nb_w(ptr noundef nonnull %0, i8 noundef signext %1)
  store i32 %5, ptr %2, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #3
  %.not42 = icmp eq ptr %9, null
  br i1 %.not42, label %28, label %.preheader52

.preheader52:                                     ; preds = %4
  %10 = load i8, ptr %0, align 1, !tbaa !9
  %.not4354 = icmp eq i8 %10, 0
  br i1 %.not4354, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader52, %.critedge2
  %.03356 = phi i32 [ %.1, %.critedge2 ], [ 0, %.preheader52 ]
  %.03455 = phi ptr [ %.3, %.critedge2 ], [ %0, %.preheader52 ]
  br label %11

11:                                               ; preds = %11, %.preheader
  %.135 = phi ptr [ %14, %11 ], [ %.03455, %.preheader ]
  %12 = load i8, ptr %.135, align 1, !tbaa !9
  %13 = icmp ne i8 %12, %1
  %.not44 = icmp eq i8 %12, 0
  %or.cond = or i1 %13, %.not44
  %14 = getelementptr inbounds i8, ptr %.135, i64 1
  br i1 %or.cond, label %.critedge, label %11, !llvm.loop !10

.critedge:                                        ; preds = %11
  %.not45 = icmp eq i8 %12, %1
  %or.cond50 = or i1 %.not45, %.not44
  br i1 %or.cond50, label %.critedge2, label %15

15:                                               ; preds = %.critedge
  %16 = tail call i32 @len_split(ptr noundef nonnull %.135, i8 noundef signext %1)
  %17 = sext i32 %16 to i64
  %18 = tail call ptr @ft_substr(ptr noundef nonnull %.135, i32 noundef 0, i64 noundef %17) #4
  %19 = sext i32 %.03356 to i64
  %20 = getelementptr inbounds ptr, ptr %9, i64 %19
  store ptr %18, ptr %20, align 8, !tbaa !12
  %.not47 = icmp eq ptr %18, null
  br i1 %.not47, label %21, label %.preheader60

21:                                               ; preds = %15
  tail call void @free_s(ptr noundef nonnull %9, i32 noundef %.03356)
  br label %28

.preheader60:                                     ; preds = %15, %.preheader60
  %.2 = phi ptr [ %23, %.preheader60 ], [ %.135, %15 ]
  %22 = load i8, ptr %.2, align 1, !tbaa !9
  %.not48 = icmp eq i8 %22, %1
  %.not49 = icmp eq i8 %22, 0
  %or.cond51 = or i1 %.not48, %.not49
  %23 = getelementptr inbounds i8, ptr %.2, i64 1
  br i1 %or.cond51, label %.critedge2.loopexit, label %.preheader60, !llvm.loop !14

.critedge2.loopexit:                              ; preds = %.preheader60
  %24 = add nsw i32 %.03356, 1
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.critedge
  %25 = phi i8 [ %12, %.critedge ], [ %22, %.critedge2.loopexit ]
  %.3 = phi ptr [ %.135, %.critedge ], [ %.2, %.critedge2.loopexit ]
  %.1 = phi i32 [ %.03356, %.critedge ], [ %24, %.critedge2.loopexit ]
  %.not43 = icmp eq i8 %25, 0
  br i1 %.not43, label %._crit_edge.loopexit, label %.preheader, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.critedge2
  %26 = sext i32 %.1 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader52
  %.033.lcssa = phi i64 [ 0, %.preheader52 ], [ %26, %._crit_edge.loopexit ]
  %27 = getelementptr inbounds ptr, ptr %9, i64 %.033.lcssa
  store ptr null, ptr %27, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %4, %3, %._crit_edge, %21
  %.0 = phi ptr [ null, %21 ], [ %9, %._crit_edge ], [ null, %3 ], [ null, %4 ]
  ret ptr %.0
}

attributes #0 = { 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 #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 = { "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 allocsize(0) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}


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