; LLVM IR from simon-zerisenay/42_Push_Swap :: libft (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: nounwind uwtable
define dso_local ptr @ft_split(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 ptr, align 8
  %7 = alloca i32, align 4
  %8 = 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !10
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %87

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = call i32 @count_strings(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) #4
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %12
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %87

23:                                               ; preds = %12
  br label %24

24:                                               ; preds = %80, %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %81

29:                                               ; preds = %24
  br label %30

30:                                               ; preds = %44, %29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %30
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = load i8, ptr %5, align 1, !tbaa !9
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %38, %40
  br label %42

42:                                               ; preds = %35, %30
  %43 = phi i1 [ false, %30 ], [ %41, %35 ]
  br i1 %43, label %44, label %47

44:                                               ; preds = %42
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %4, align 8, !tbaa !5
  br label %30, !llvm.loop !12

47:                                               ; preds = %42
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %62

52:                                               ; preds = %47
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load i8, ptr %5, align 1, !tbaa !9
  %55 = call ptr @ft_word(ptr noundef %53, i8 noundef signext %54)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !10
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %56, i64 %58
  store ptr %55, ptr %59, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !10
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !10
  br label %62

62:                                               ; preds = %52, %47
  br label %63

63:                                               ; preds = %77, %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !9
  %66 = sext i8 %65 to i32
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %75

68:                                               ; preds = %63
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %71 = sext i8 %70 to i32
  %72 = load i8, ptr %5, align 1, !tbaa !9
  %73 = sext i8 %72 to i32
  %74 = icmp ne i32 %71, %73
  br label %75

75:                                               ; preds = %68, %63
  %76 = phi i1 [ false, %63 ], [ %74, %68 ]
  br i1 %76, label %77, label %80

77:                                               ; preds = %75
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i32 1
  store ptr %79, ptr %4, align 8, !tbaa !5
  br label %63, !llvm.loop !14

80:                                               ; preds = %75
  br label %24, !llvm.loop !15

81:                                               ; preds = %24
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !10
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds ptr, ptr %82, i64 %84
  store ptr null, ptr %85, align 8, !tbaa !5
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %86, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %87

87:                                               ; preds = %81, %22, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %88 = load ptr, ptr %3, align 8
  ret ptr %88
}

; 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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @ft_word(ptr noundef, i8 noundef signext) #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 = { 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 = !{!"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: nounwind uwtable
define dso_local noalias noundef ptr @ft_split(ptr noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %24, label %3

3:                                                ; preds = %2
  %4 = tail call i32 @count_strings(ptr noundef nonnull %0, i8 noundef signext %1)
  %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) #2
  %.not30 = icmp eq ptr %8, null
  br i1 %.not30, label %24, label %.critedge2thread-pre-split

.critedge2thread-pre-split:                       ; preds = %3
  %.pr = load i8, ptr %0, align 1, !tbaa !5
  %.not3138 = icmp eq i8 %.pr, 0
  br i1 %.not3138, label %.critedge2._crit_edge, label %.preheader

.critedge2.loopexit:                              ; preds = %19
  br i1 %.not34, label %.critedge2._crit_edge.loopexit, label %.preheader, !llvm.loop !8

.preheader:                                       ; preds = %.critedge2thread-pre-split, %.critedge2.loopexit
  %.040 = phi i32 [ %.1, %.critedge2.loopexit ], [ 0, %.critedge2thread-pre-split ]
  %.02539 = phi ptr [ %.2, %.critedge2.loopexit ], [ %0, %.critedge2thread-pre-split ]
  br label %9

9:                                                ; preds = %9, %.preheader
  %.126 = phi ptr [ %12, %9 ], [ %.02539, %.preheader ]
  %10 = load i8, ptr %.126, align 1, !tbaa !5
  %.not32 = icmp ne i8 %10, 0
  %11 = icmp eq i8 %10, %1
  %or.cond = and i1 %.not32, %11
  %12 = getelementptr inbounds i8, ptr %.126, i64 1
  br i1 %or.cond, label %9, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %9
  %.not33 = icmp eq i8 %10, 0
  br i1 %.not33, label %18, label %13

13:                                               ; preds = %.critedge
  %14 = tail call ptr @ft_word(ptr noundef nonnull %.126, i8 noundef signext %1)
  %15 = sext i32 %.040 to i64
  %16 = getelementptr inbounds ptr, ptr %8, i64 %15
  store ptr %14, ptr %16, align 8, !tbaa !11
  %17 = add nsw i32 %.040, 1
  br label %18

18:                                               ; preds = %13, %.critedge
  %.1 = phi i32 [ %17, %13 ], [ %.040, %.critedge ]
  br label %19

19:                                               ; preds = %19, %18
  %.2 = phi ptr [ %.126, %18 ], [ %21, %19 ]
  %20 = load i8, ptr %.2, align 1, !tbaa !5
  %.not34 = icmp eq i8 %20, 0
  %.not35 = icmp eq i8 %20, %1
  %or.cond36 = or i1 %.not34, %.not35
  %21 = getelementptr inbounds i8, ptr %.2, i64 1
  br i1 %or.cond36, label %.critedge2.loopexit, label %19, !llvm.loop !13

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

.critedge2._crit_edge:                            ; preds = %.critedge2._crit_edge.loopexit, %.critedge2thread-pre-split
  %.0.lcssa = phi i64 [ 0, %.critedge2thread-pre-split ], [ %22, %.critedge2._crit_edge.loopexit ]
  %23 = getelementptr inbounds ptr, ptr %8, i64 %.0.lcssa
  store ptr null, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %3, %2, %.critedge2._crit_edge
  %.024 = phi ptr [ %8, %.critedge2._crit_edge ], [ null, %2 ], [ null, %3 ]
  ret ptr %.024
}

; 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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @ft_word(ptr noundef, i8 noundef signext) 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 = { 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 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = distinct !{!13, !9}


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