; 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 uwtable
declare dso_local i32 @charArrAlgStrcmp(ptr noundef, ptr noundef) #0

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

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

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

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

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

declare void @destroyString(ptr noundef) #4

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

declare ptr @stringInitialization(i32 noundef) #4

declare i32 @stringGetLength(ptr noundef) #4

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

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

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

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

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

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

18:                                               ; preds = %12
  br label %19

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

22:                                               ; preds = %47, %19
  %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 %50

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 %43

33:                                               ; preds = %27
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @stringGetLength(ptr noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %42

37:                                               ; preds = %33
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call ptr @stringToCharArray(ptr noundef %39)
  call void @vectorAdd(ptr noundef %38, ptr noundef %40)
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  call void @clearString(ptr noundef %41)
  br label %42

42:                                               ; preds = %37, %33
  br label %47

43:                                               ; preds = %27
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !9
  call void @stringAppendChar(ptr noundef %44, i8 noundef signext %46)
  br label %47

47:                                               ; preds = %43, %42
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %3, align 8, !tbaa !5
  br label %22, !llvm.loop !10

50:                                               ; preds = %22
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call i32 @stringGetLength(ptr noundef %51)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %58

54:                                               ; preds = %50
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call ptr @stringToCharArray(ptr noundef %56)
  call void @vectorAdd(ptr noundef %55, ptr noundef %57)
  br label %58

58:                                               ; preds = %54, %50
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  call void @destroyString(ptr noundef %59)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %60
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare ptr @stringToCharArray(ptr noundef) #4

declare void @clearString(ptr noundef) #4

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 = { 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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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: nounwind uwtable
declare dso_local i32 @charArrAlgStrcmp(ptr noundef, ptr noundef) #0

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

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

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

declare void @destroyString(ptr noundef) local_unnamed_addr #3

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

declare ptr @stringInitialization(i32 noundef) local_unnamed_addr #3

declare i32 @stringGetLength(ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @charArrSplitC(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %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) #5
  tail call void @exit(i32 noundef -83386157) #6
  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) #5
  tail call void @exit(i32 noundef -83384987) #6
  unreachable

12:                                               ; preds = %7
  %13 = tail call ptr @vectorInitialization(i32 noundef 5, ptr noundef nonnull @free, ptr noundef nonnull @charArrAlgStrcmp) #7
  %14 = tail call ptr @stringInitialization(i32 noundef 10) #7
  %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, %24
  %16 = phi i8 [ %26, %24 ], [ %15, %12 ]
  %.023 = phi ptr [ %25, %24 ], [ %0, %12 ]
  %17 = tail call i32 @charArrContainsChar(ptr noundef nonnull %1, i8 noundef signext %16)
  %.not20 = icmp eq i32 %17, 0
  br i1 %.not20, label %22, label %18

18:                                               ; preds = %.lr.ph
  %19 = tail call i32 @stringGetLength(ptr noundef %14) #7
  %.not21 = icmp eq i32 %19, 0
  br i1 %.not21, label %24, label %20

20:                                               ; preds = %18
  %21 = tail call ptr @stringToCharArray(ptr noundef %14) #7
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %21) #7
  tail call void @clearString(ptr noundef %14) #7
  br label %24

22:                                               ; preds = %.lr.ph
  %23 = load i8, ptr %.023, align 1, !tbaa !9
  tail call void @stringAppendChar(ptr noundef %14, i8 noundef signext %23) #7
  br label %24

24:                                               ; preds = %18, %20, %22
  %25 = getelementptr inbounds i8, ptr %.023, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %24, %12
  %27 = tail call i32 @stringGetLength(ptr noundef %14) #7
  %.not19 = icmp eq i32 %27, 0
  br i1 %.not19, label %30, label %28

28:                                               ; preds = %._crit_edge
  %29 = tail call ptr @stringToCharArray(ptr noundef %14) #7
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %29) #7
  br label %30

30:                                               ; preds = %28, %._crit_edge
  tail call void @destroyString(ptr noundef %14) #7
  ret ptr %13
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) #4

declare ptr @stringToCharArray(ptr noundef) local_unnamed_addr #3

declare void @clearString(ptr noundef) local_unnamed_addr #3

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 = { 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 #2 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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