; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Algorithms/ArraysAlg/Sources (CharArrayAlg)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

declare ptr @vectorInitialization(i32 noundef, ptr noundef, ptr noundef) #3

declare void @destroyString(ptr noundef) #3

declare void @vectorAdd(ptr noundef, ptr noundef) #3

declare ptr @stringInitialization(i32 noundef) #3

declare i32 @stringGetLength(ptr noundef) #3

declare ptr @vectorGet(ptr noundef, i32 noundef) #3

declare i32 @vectorGetLength(ptr noundef) #3

declare void @stringAppendChar(ptr noundef, i8 noundef signext) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @charArrContainsChar(ptr noundef, i8 noundef signext) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @charArrSplitS(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str, ptr noundef @.str.7, ptr noundef @.str.30) #5
  call void @exit(i32 noundef -83386157) #6
  unreachable

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.4, ptr noundef @.str.31, ptr noundef @.str.30) #5
  call void @exit(i32 noundef -83384987) #6
  unreachable

17:                                               ; preds = %11
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %19 = call ptr @vectorInitialization(i32 noundef 5, ptr noundef @destroyString, ptr noundef @stringCompareS)
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call ptr @stringInitialization(i32 noundef 5)
  call void @vectorAdd(ptr noundef %20, ptr noundef %21)
  br label %22

22:                                               ; preds = %53, %18
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %56

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = call i32 @charArrContainsChar(ptr noundef %28, i8 noundef signext %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %45

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @vectorGetLength(ptr noundef %35)
  %37 = sub nsw i32 %36, 1
  %38 = call ptr @vectorGet(ptr noundef %34, i32 noundef %37)
  %39 = call i32 @stringGetLength(ptr noundef %38)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %33
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call ptr @stringInitialization(i32 noundef 5)
  call void @vectorAdd(ptr noundef %42, ptr noundef %43)
  br label %44

44:                                               ; preds = %41, %33
  br label %53

45:                                               ; preds = %27
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i32 @vectorGetLength(ptr noundef %47)
  %49 = sub nsw i32 %48, 1
  %50 = call ptr @vectorGet(ptr noundef %46, i32 noundef %49)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !9
  call void @stringAppendChar(ptr noundef %50, i8 noundef signext %52)
  br label %53

53:                                               ; preds = %45, %44
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %3, align 8, !tbaa !5
  br label %22, !llvm.loop !10

56:                                               ; preds = %22
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = call i32 @vectorGetLength(ptr noundef %58)
  %60 = sub nsw i32 %59, 1
  %61 = call ptr @vectorGet(ptr noundef %57, i32 noundef %60)
  %62 = call i32 @stringGetLength(ptr noundef %61)
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %69

64:                                               ; preds = %56
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = call i32 @vectorGetLength(ptr noundef %66)
  %68 = sub nsw i32 %67, 1
  call void @vectorRemoveAtIndex(ptr noundef %65, i32 noundef %68)
  br label %69

69:                                               ; preds = %64, %56
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %70
}

declare i32 @stringCompareS(ptr noundef, ptr noundef) #3

declare void @vectorRemoveAtIndex(ptr noundef, i32 noundef) #3

attributes #0 = { nounwind "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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

declare ptr @vectorInitialization(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @destroyString(ptr noundef) #2

declare void @vectorAdd(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @stringInitialization(i32 noundef) local_unnamed_addr #2

declare i32 @stringGetLength(ptr noundef) local_unnamed_addr #2

declare ptr @vectorGet(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @vectorGetLength(ptr noundef) local_unnamed_addr #2

declare void @stringAppendChar(ptr noundef, i8 noundef signext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @charArrContainsChar(ptr noundef, i8 noundef signext) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @charArrSplitS(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.30) #4
  tail call void @exit(i32 noundef -83386157) #5
  unreachable

7:                                                ; preds = %2
  %8 = icmp eq ptr %1, null
  br i1 %8, label %9, label %12

9:                                                ; preds = %7
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.31, ptr noundef nonnull @.str.30) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

12:                                               ; preds = %7
  %13 = tail call ptr @vectorInitialization(i32 noundef 5, ptr noundef nonnull @destroyString, ptr noundef nonnull @stringCompareS) #6
  %14 = tail call ptr @stringInitialization(i32 noundef 5) #6
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %14) #6
  %15 = load i8, ptr %0, align 1, !tbaa !9
  %.not22 = icmp eq i8 %15, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %27
  %16 = phi i8 [ %29, %27 ], [ %15, %12 ]
  %.023 = phi ptr [ %28, %27 ], [ %0, %12 ]
  %17 = tail call i32 @charArrContainsChar(ptr noundef nonnull %1, i8 noundef signext %16)
  %.not20 = icmp eq i32 %17, 0
  %18 = tail call i32 @vectorGetLength(ptr noundef %13) #6
  %19 = add nsw i32 %18, -1
  %20 = tail call ptr @vectorGet(ptr noundef %13, i32 noundef %19) #6
  br i1 %.not20, label %25, label %21

21:                                               ; preds = %.lr.ph
  %22 = tail call i32 @stringGetLength(ptr noundef %20) #6
  %.not21 = icmp eq i32 %22, 0
  br i1 %.not21, label %27, label %23

23:                                               ; preds = %21
  %24 = tail call ptr @stringInitialization(i32 noundef 5) #6
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %24) #6
  br label %27

25:                                               ; preds = %.lr.ph
  %26 = load i8, ptr %.023, align 1, !tbaa !9
  tail call void @stringAppendChar(ptr noundef %20, i8 noundef signext %26) #6
  br label %27

27:                                               ; preds = %21, %23, %25
  %28 = getelementptr inbounds i8, ptr %.023, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %.not = icmp eq i8 %29, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %27, %12
  %30 = tail call i32 @vectorGetLength(ptr noundef %13) #6
  %31 = add nsw i32 %30, -1
  %32 = tail call ptr @vectorGet(ptr noundef %13, i32 noundef %31) #6
  %33 = tail call i32 @stringGetLength(ptr noundef %32) #6
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %._crit_edge
  %36 = tail call i32 @vectorGetLength(ptr noundef %13) #6
  %37 = add nsw i32 %36, -1
  tail call void @vectorRemoveAtIndex(ptr noundef %13, i32 noundef %37) #6
  br label %38

38:                                               ; preds = %35, %._crit_edge
  ret ptr %13
}

declare i32 @stringCompareS(ptr noundef, ptr noundef) #2

declare void @vectorRemoveAtIndex(ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind "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 = { noreturn nounwind "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 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 #4 = { cold nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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