; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/Tests/AlgorithmsTests/CharArrayAlgTest (CharArrayAlgTest)

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

%struct.ErrorTestStruct = type { i32 }

@.str = external hidden unnamed_addr constant [146 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8
@__const.testCharIsAlphabetP.letters = external hidden unnamed_addr constant [53 x i8], align 16
@__const.testCharIsAlphabetP.notLetters = external hidden unnamed_addr constant [35 x i8], align 16

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local void @testCharIsAlphabetP(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca [53 x i8], align 16
  %4 = alloca [35 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = call i32 @isAlphabetP(ptr noundef null)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ErrorTestStruct, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %10, ptr noundef @.str, i32 noundef 435, ptr noundef null, i32 noundef -83386157, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 53, ptr %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.testCharIsAlphabetP.letters, i64 53, i1 false)
  call void @llvm.lifetime.start.p0(i64 35, ptr %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.testCharIsAlphabetP.notLetters, i64 35, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %14 = getelementptr inbounds [53 x i8], ptr %3, i64 0, i64 0
  %15 = call i64 @strlen(ptr noundef %14) #6
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %29, %1
  %18 = load i32, ptr %6, align 4, !tbaa !12
  %19 = load i32, ptr %5, align 4, !tbaa !12
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %32

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds [53 x i8], ptr %3, i64 0, i64 0
  %25 = load i32, ptr %6, align 4, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = call i32 @isAlphabetP(ptr noundef %27)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %23, ptr noundef @.str, i32 noundef 444, ptr noundef null, i32 noundef 1, i32 noundef %28)
  br label %29

29:                                               ; preds = %22
  %30 = load i32, ptr %6, align 4, !tbaa !12
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !12
  br label %17, !llvm.loop !13

32:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %33 = getelementptr inbounds [35 x i8], ptr %4, i64 0, i64 0
  %34 = call i64 @strlen(ptr noundef %33) #6
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %36

36:                                               ; preds = %48, %32
  %37 = load i32, ptr %8, align 4, !tbaa !12
  %38 = load i32, ptr %7, align 4, !tbaa !12
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds [35 x i8], ptr %4, i64 0, i64 0
  %44 = load i32, ptr %8, align 4, !tbaa !12
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = call i32 @isAlphabetP(ptr noundef %46)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %42, ptr noundef @.str, i32 noundef 449, ptr noundef null, i32 noundef 0, i32 noundef %47)
  br label %48

48:                                               ; preds = %41
  %49 = load i32, ptr %8, align 4, !tbaa !12
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %8, align 4, !tbaa !12
  br label %36, !llvm.loop !15

51:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 35, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 53, ptr %3) #5
  ret void
}

declare i32 @isAlphabetP(ptr noundef) #0

attributes #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 willreturn memory(read) "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 nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind willreturn memory(read) }

!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 = !{!10, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@.str = external hidden unnamed_addr constant [146 x i8], align 1
@ERROR_TEST = external dso_local local_unnamed_addr global ptr, align 8
@__const.testCharIsAlphabetP.letters = external hidden unnamed_addr constant [53 x i8], align 16
@__const.testCharIsAlphabetP.notLetters = external hidden unnamed_addr constant [35 x i8], align 16

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local void @testCharIsAlphabetP(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca [53 x i8], align 16
  %3 = alloca [35 x i8], align 16
  %4 = tail call i32 @isAlphabetP(ptr noundef null) #5
  %5 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 435, ptr noundef null, i32 noundef -83386157, i32 noundef %6) #5
  call void @llvm.lifetime.start.p0(i64 53, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(53) %2, ptr noundef nonnull align 16 dereferenceable(53) @__const.testCharIsAlphabetP.letters, i64 53, i1 false)
  call void @llvm.lifetime.start.p0(i64 35, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(35) %3, ptr noundef nonnull align 16 dereferenceable(35) @__const.testCharIsAlphabetP.notLetters, i64 35, i1 false)
  %7 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #6
  %8 = trunc i64 %7 to i32
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = and i64 %7, 2147483647
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %10 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #6
  %11 = trunc i64 %10 to i32
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph14.preheader, label %._crit_edge15

.lr.ph14.preheader:                               ; preds = %._crit_edge
  %wide.trip.count20 = and i64 %10, 2147483647
  br label %.lr.ph14

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %13 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %14 = call i32 @isAlphabetP(ptr noundef nonnull %13) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 444, ptr noundef null, i32 noundef 1, i32 noundef %14) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge15:                                    ; preds = %.lr.ph14, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 35, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 53, ptr nonnull %2) #5
  ret void

.lr.ph14:                                         ; preds = %.lr.ph14.preheader, %.lr.ph14
  %indvars.iv17 = phi i64 [ 0, %.lr.ph14.preheader ], [ %indvars.iv.next18, %.lr.ph14 ]
  %15 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv17
  %16 = call i32 @isAlphabetP(ptr noundef nonnull %15) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 449, ptr noundef null, i32 noundef 0, i32 noundef %16) #5
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %exitcond21.not = icmp eq i64 %indvars.iv.next18, %wide.trip.count20
  br i1 %exitcond21.not, label %._crit_edge15, label %.lr.ph14, !llvm.loop !14
}

declare i32 @isAlphabetP(ptr noundef) local_unnamed_addr #0

attributes #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind willreturn memory(read) }

!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 = !{!10, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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