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

; 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 [140 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8

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

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @intCopyFunArrAlgT(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @testFillArrC(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %7 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %19, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 10
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %12
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !11

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @fillArrC(ptr noundef null, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef null)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ErrorTestStruct, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !13
  call void @CuAssertIntEquals_LineMsg(ptr noundef %23, ptr noundef @.str, i32 noundef 451, ptr noundef null, i32 noundef -83386157, i32 noundef %26)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fillArrC(ptr noundef %27, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef null)
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ErrorTestStruct, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !13
  call void @CuAssertIntEquals_LineMsg(ptr noundef %28, ptr noundef @.str, i32 noundef 454, ptr noundef null, i32 noundef -83384987, i32 noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fillArrC(ptr noundef %32, ptr noundef %5, i32 noundef 0, i32 noundef 0, ptr noundef null)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ErrorTestStruct, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !13
  call void @CuAssertIntEquals_LineMsg(ptr noundef %33, ptr noundef @.str, i32 noundef 457, ptr noundef null, i32 noundef -83384987, i32 noundef %36)
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fillArrC(ptr noundef %37, ptr noundef %5, i32 noundef -1, i32 noundef 0, ptr noundef @intCopyFunArrAlgT)
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ErrorTestStruct, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !13
  call void @CuAssertIntEquals_LineMsg(ptr noundef %38, ptr noundef @.str, i32 noundef 460, ptr noundef null, i32 noundef -83384987, i32 noundef %41)
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fillArrC(ptr noundef %42, ptr noundef %5, i32 noundef 0, i32 noundef 0, ptr noundef @intCopyFunArrAlgT)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ErrorTestStruct, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !13
  call void @CuAssertIntEquals_LineMsg(ptr noundef %43, ptr noundef @.str, i32 noundef 463, ptr noundef null, i32 noundef -83384987, i32 noundef %46)
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fillArrC(ptr noundef %47, ptr noundef %5, i32 noundef 10, i32 noundef 4, ptr noundef @intCopyFunArrAlgT)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %59, %22
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = icmp slt i32 %49, 10
  br i1 %50, label %52, label %51

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

52:                                               ; preds = %48
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %53, ptr noundef @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %58)
  br label %59

59:                                               ; preds = %52
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !9
  br label %48, !llvm.loop !15

62:                                               ; preds = %51
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %63) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

declare void @fillArrC(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

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

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


; 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 [140 x i8], align 1
@ERROR_TEST = external dso_local local_unnamed_addr global ptr, align 8

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @intCopyFunArrAlgT(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @testFillArrC(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca i32, align 4
  %3 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = getelementptr inbounds i8, ptr %3, i64 12
  store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %3, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 16
  %8 = getelementptr inbounds i8, ptr %3, i64 20
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  %10 = getelementptr inbounds i8, ptr %3, i64 28
  store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, ptr %7, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 9, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %3, i64 36
  store i32 10, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  tail call void @fillArrC(ptr noundef null, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef null) #6
  %13 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !9
  %14 = load i32, ptr %13, align 4, !tbaa !11
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 451, ptr noundef null, i32 noundef -83386157, i32 noundef %14) #6
  tail call void @fillArrC(ptr noundef nonnull %3, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef null) #6
  %15 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !9
  %16 = load i32, ptr %15, align 4, !tbaa !11
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 454, ptr noundef null, i32 noundef -83384987, i32 noundef %16) #6
  call void @fillArrC(ptr noundef nonnull %3, ptr noundef nonnull %2, i32 noundef 0, i32 noundef 0, ptr noundef null) #6
  %17 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !9
  %18 = load i32, ptr %17, align 4, !tbaa !11
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 457, ptr noundef null, i32 noundef -83384987, i32 noundef %18) #6
  call void @fillArrC(ptr noundef nonnull %3, ptr noundef nonnull %2, i32 noundef -1, i32 noundef 0, ptr noundef nonnull @intCopyFunArrAlgT) #6
  %19 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !9
  %20 = load i32, ptr %19, align 4, !tbaa !11
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 460, ptr noundef null, i32 noundef -83384987, i32 noundef %20) #6
  call void @fillArrC(ptr noundef nonnull %3, ptr noundef nonnull %2, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @intCopyFunArrAlgT) #6
  %21 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !9
  %22 = load i32, ptr %21, align 4, !tbaa !11
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 463, ptr noundef null, i32 noundef -83384987, i32 noundef %22) #6
  call void @fillArrC(ptr noundef nonnull %3, ptr noundef nonnull %2, i32 noundef 10, i32 noundef 4, ptr noundef nonnull @intCopyFunArrAlgT) #6
  %23 = load i32, ptr %3, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %23) #6
  %24 = load i32, ptr %4, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %24) #6
  %25 = load i32, ptr %5, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %25) #6
  %26 = load i32, ptr %6, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %26) #6
  %27 = load i32, ptr %7, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %27) #6
  %28 = load i32, ptr %8, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %28) #6
  %29 = load i32, ptr %9, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %29) #6
  %30 = load i32, ptr %10, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %30) #6
  %31 = load i32, ptr %11, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %31) #6
  %32 = load i32, ptr %12, align 4, !tbaa !5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 469, ptr noundef null, i32 noundef 1, i32 noundef %32) #6
  call void @free(ptr noundef %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  ret void
}

declare void @fillArrC(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { 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 #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 allocsize(0) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"ErrorTestStruct", !6, i64 0}


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