; 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
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@__const.testGenerateCharPointerP.words = external hidden unnamed_addr constant [5 x [20 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

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

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

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

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %42

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %21 = load i32, ptr %4, align 4, !tbaa !12
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5 x [20 x i8]], ptr %3, i64 0, i64 %22
  %24 = getelementptr inbounds [20 x i8], ptr %23, i64 0, i64 0
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [5 x [20 x i8]], ptr %3, i64 0, i64 %26
  %28 = getelementptr inbounds [20 x i8], ptr %27, i64 0, i64 0
  %29 = call i64 @strlen(ptr noundef %28) #7
  %30 = trunc i64 %29 to i32
  %31 = call ptr @generateCharPointerP(ptr noundef %24, i32 noundef %30)
  store ptr %31, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5 x [20 x i8]], ptr %3, i64 0, i64 %35
  %37 = getelementptr inbounds [20 x i8], ptr %36, i64 0, i64 0
  call void @CuAssertStrEquals_LineMsg(ptr noundef %32, ptr noundef @.str, i32 noundef 390, ptr noundef null, ptr noundef %33, ptr noundef %37)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %38) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %39

39:                                               ; preds = %20
  %40 = load i32, ptr %4, align 4, !tbaa !12
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !12
  br label %16, !llvm.loop !13

42:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 100, ptr %3) #6
  ret void
}

declare ptr @generateCharPointerP(ptr noundef, i32 noundef) #0

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

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 "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 #6 = { nounwind }
attributes #7 = { 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"}


; 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
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@__const.testGenerateCharPointerP.words = external hidden unnamed_addr constant [5 x [20 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

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

; Function Attrs: nounwind uwtable
define dso_local void @testGenerateCharPointerP(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca [5 x [20 x i8]], align 16
  %3 = tail call ptr @generateCharPointerP(ptr noundef null, i32 noundef 0) #6
  %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 380, ptr noundef null, i32 noundef -83386157, i32 noundef %5) #6
  %6 = tail call ptr @generateCharPointerP(ptr noundef nonnull @.str.1, i32 noundef -1) #6
  %7 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 383, ptr noundef null, i32 noundef -83384987, i32 noundef %8) #6
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %2, ptr noundef nonnull align 16 dereferenceable(100) @__const.testGenerateCharPointerP.words, i64 100, i1 false)
  %9 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %10 = trunc i64 %9 to i32
  %11 = call ptr @generateCharPointerP(ptr noundef nonnull %2, i32 noundef %10) #6
  call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 390, ptr noundef null, ptr noundef %11, ptr noundef nonnull %2) #6
  call void @free(ptr noundef %11) #6
  %12 = getelementptr inbounds i8, ptr %2, i64 20
  %13 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %12) #7
  %14 = trunc i64 %13 to i32
  %15 = call ptr @generateCharPointerP(ptr noundef nonnull %12, i32 noundef %14) #6
  call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 390, ptr noundef null, ptr noundef %15, ptr noundef nonnull %12) #6
  call void @free(ptr noundef %15) #6
  %16 = getelementptr inbounds i8, ptr %2, i64 40
  %17 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %16) #7
  %18 = trunc i64 %17 to i32
  %19 = call ptr @generateCharPointerP(ptr noundef nonnull %16, i32 noundef %18) #6
  call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 390, ptr noundef null, ptr noundef %19, ptr noundef nonnull %16) #6
  call void @free(ptr noundef %19) #6
  %20 = getelementptr inbounds i8, ptr %2, i64 60
  %21 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %20) #7
  %22 = trunc i64 %21 to i32
  %23 = call ptr @generateCharPointerP(ptr noundef nonnull %20, i32 noundef %22) #6
  call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 390, ptr noundef null, ptr noundef %23, ptr noundef nonnull %20) #6
  call void @free(ptr noundef %23) #6
  %24 = getelementptr inbounds i8, ptr %2, i64 80
  %25 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %24) #7
  %26 = trunc i64 %25 to i32
  %27 = call ptr @generateCharPointerP(ptr noundef nonnull %24, i32 noundef %26) #6
  call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 390, ptr noundef null, ptr noundef %27, ptr noundef nonnull %24) #6
  call void @free(ptr noundef %27) #6
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %2) #6
  ret void
}

declare ptr @generateCharPointerP(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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 = { 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 #6 = { nounwind }
attributes #7 = { 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass