; 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.18 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [34 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

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

; Function Attrs: nounwind uwtable
define dso_local void @charArrRemoveCharacters(ptr noundef %0, ptr noundef %1) #3 {
  %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.18) #4
  call void @exit(i32 noundef -83386157) #5
  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.19, ptr noundef @.str.18) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

17:                                               ; preds = %11
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %47, %18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %48

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = call i32 @charArrContainsChar(ptr noundef %25, i8 noundef signext %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %44

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %37, %30
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %35, ptr %36, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %32
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %5, align 8, !tbaa !5
  %40 = load i8, ptr %38, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %32, label %43, !llvm.loop !10

43:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %47

44:                                               ; preds = %24
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %3, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %44, %43
  br label %19, !llvm.loop !12

48:                                               ; preds = %19
  ret void
}

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 = { 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 = { nounwind }
attributes #5 = { 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"}
!12 = distinct !{!12, !11}


; 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.18 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [34 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

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

; Function Attrs: nounwind uwtable
define dso_local void @charArrRemoveCharacters(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %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.18) #3
  tail call void @exit(i32 noundef -83386157) #4
  unreachable

7:                                                ; preds = %2
  %8 = icmp eq ptr %1, null
  br i1 %8, label %10, label %.preheader14

.preheader14:                                     ; preds = %7
  %9 = load i8, ptr %0, align 1, !tbaa !9
  %.not15 = icmp eq i8 %9, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

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

.lr.ph:                                           ; preds = %.preheader14, %.loopexit
  %13 = phi i8 [ %19, %.loopexit ], [ %9, %.preheader14 ]
  %.01016 = phi ptr [ %.1, %.loopexit ], [ %0, %.preheader14 ]
  %14 = tail call i32 @charArrContainsChar(ptr noundef nonnull %1, i8 noundef signext %13)
  %.not12 = icmp eq i32 %14, 0
  br i1 %.not12, label %17, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.preheader
  %.0 = phi ptr [ %15, %.preheader ], [ %.01016, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %.0, i64 1
  %16 = load i8, ptr %15, align 1, !tbaa !9
  store i8 %16, ptr %.0, align 1, !tbaa !9
  %.not13 = icmp eq i8 %16, 0
  br i1 %.not13, label %.loopexit, label %.preheader, !llvm.loop !10

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.01016, i64 1
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %17
  %.1 = phi ptr [ %18, %17 ], [ %.01016, %.preheader ]
  %19 = load i8, ptr %.1, align 1, !tbaa !9
  %.not = icmp eq i8 %19, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.loopexit, %.preheader14
  ret void
}

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 = { 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 = { cold nounwind }
attributes #4 = { 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"}
!12 = distinct !{!12, !11}


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