; 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.testCharArrContainsChar.sentence = external hidden unnamed_addr constant [19 x i8], align 16
@__const.testCharArrContainsChar.sentence2 = external hidden unnamed_addr constant [10 x i8], align 1

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: 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @testCharArrContainsChar(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca [19 x i8], align 16
  %4 = alloca ptr, align 8
  %5 = alloca [10 x i8], align 1
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = call i32 @charArrContainsChar(ptr noundef null, i8 noundef signext 0)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ErrorTestStruct, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %8, ptr noundef @.str, i32 noundef 253, ptr noundef null, i32 noundef -83386157, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 19, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.testCharArrContainsChar.sentence, i64 19, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %12 = getelementptr inbounds [19 x i8], ptr %3, i64 0, i64 0
  store ptr %12, ptr %4, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %18, %1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !12
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds [19 x i8], ptr %3, i64 0, i64 0
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i32 1
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %21, align 1, !tbaa !12
  %24 = call i32 @charArrContainsChar(ptr noundef %20, i8 noundef signext %23)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %19, ptr noundef @.str, i32 noundef 259, ptr noundef null, i32 noundef 1, i32 noundef %24)
  br label %13, !llvm.loop !13

25:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 10, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 @__const.testCharArrContainsChar.sentence2, i64 10, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = getelementptr inbounds [10 x i8], ptr %5, i64 0, i64 0
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %32, %25
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !12
  %30 = sext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %39

32:                                               ; preds = %27
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds [19 x i8], ptr %3, i64 0, i64 0
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load i8, ptr %35, align 1, !tbaa !12
  %38 = call i32 @charArrContainsChar(ptr noundef %34, i8 noundef signext %37)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %33, ptr noundef @.str, i32 noundef 265, ptr noundef null, i32 noundef 0, i32 noundef %38)
  br label %27, !llvm.loop !15

39:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 10, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 19, ptr %3) #4
  ret void
}

declare i32 @charArrContainsChar(ptr noundef, i8 noundef signext) #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 = { nocallback nofree 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 }

!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 = !{!7, !7, 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.testCharArrContainsChar.sentence = external hidden unnamed_addr constant [19 x i8], align 16
@__const.testCharArrContainsChar.sentence2 = external hidden unnamed_addr constant [10 x i8], align 1

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 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @testCharArrContainsChar(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca [19 x i8], align 16
  %3 = tail call i32 @charArrContainsChar(ptr noundef null, i8 noundef signext 0) #4
  %4 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 253, ptr noundef null, i32 noundef -83386157, i32 noundef %5) #4
  call void @llvm.lifetime.start.p0(i64 19, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(19) %2, ptr noundef nonnull align 16 dereferenceable(19) @__const.testCharArrContainsChar.sentence, i64 19, i1 false)
  %6 = load i8, ptr %2, align 16, !tbaa !12
  %.not9 = icmp eq i8 %6, 0
  br i1 %.not9, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %1
  %7 = load i8, ptr @__const.testCharArrContainsChar.sentence2, align 1, !tbaa !12
  %.not811 = icmp eq i8 %7, 0
  br i1 %.not811, label %._crit_edge, label %.lr.ph13

.lr.ph:                                           ; preds = %1, %.lr.ph
  %8 = phi i8 [ %11, %.lr.ph ], [ %6, %1 ]
  %.0710 = phi ptr [ %9, %.lr.ph ], [ %2, %1 ]
  %9 = getelementptr inbounds i8, ptr %.0710, i64 1
  %10 = call i32 @charArrContainsChar(ptr noundef nonnull %2, i8 noundef signext %8) #4
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 259, ptr noundef null, i32 noundef 1, i32 noundef %10) #4
  %11 = load i8, ptr %9, align 1, !tbaa !12
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !13

.lr.ph13:                                         ; preds = %.preheader, %.lr.ph13
  %12 = phi i8 [ %15, %.lr.ph13 ], [ %7, %.preheader ]
  %.012 = phi ptr [ %13, %.lr.ph13 ], [ @__const.testCharArrContainsChar.sentence2, %.preheader ]
  %13 = getelementptr inbounds i8, ptr %.012, i64 1
  %14 = call i32 @charArrContainsChar(ptr noundef nonnull %2, i8 noundef signext %12) #4
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 265, ptr noundef null, i32 noundef 0, i32 noundef %14) #4
  %15 = load i8, ptr %13, align 1, !tbaa !12
  %.not8 = icmp eq i8 %15, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph13, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph13, %.preheader
  call void @llvm.lifetime.end.p0(i64 19, ptr nonnull %2) #4
  ret void
}

declare i32 @charArrContainsChar(ptr noundef, i8 noundef signext) 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 nocallback nofree 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 }

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


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