; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/Tests/DataStructuresTests/ListsTest/ArrayListTest (ArrayListTest)

; 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 [154 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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 uwtable
declare dso_local i32 @compareIntPointersALT(ptr noundef, ptr noundef) #2

declare ptr @arrayListInitialization(i32 noundef, ptr noundef, ptr noundef) #3

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

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

declare void @destroyArrayList(ptr noundef) #3

declare void @arrayListAddAll(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @testArrayListGetIndex(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %8 = call ptr @arrayListInitialization(i32 noundef 1, ptr noundef @free, ptr noundef @compareIntPointersALT)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = call i32 @arrayListGetIndex(ptr noundef null, 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 338, ptr noundef null, i32 noundef -83386157, i32 noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 @arrayListGetIndex(ptr noundef %14, ptr noundef null)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ErrorTestStruct, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %16, ptr noundef @.str, i32 noundef 341, ptr noundef null, i32 noundef -83384987, i32 noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %20 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %20, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %21

21:                                               ; preds = %39, %1
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = icmp slt i32 %22, 5
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %21
  %26 = call noalias ptr @malloc(i64 noundef 4) #6
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  store ptr %26, ptr %30, align 8, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !12
  %32 = add nsw i32 %31, 1
  %33 = mul nsw i32 %32, 10
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  store i32 %33, ptr %38, align 4, !tbaa !12
  br label %39

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

42:                                               ; preds = %24
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @arrayListAddAll(ptr noundef %43, ptr noundef %44, i32 noundef 5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %57, %42
  %46 = load i32, ptr %7, align 4, !tbaa !12
  %47 = icmp slt i32 %46, 5
  br i1 %47, label %49, label %48

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

49:                                               ; preds = %45
  %50 = load i32, ptr %7, align 4, !tbaa !12
  %51 = add nsw i32 %50, 1
  %52 = mul nsw i32 %51, 10
  store i32 %52, ptr %6, align 4, !tbaa !12
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !12
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call i32 @arrayListGetIndex(ptr noundef %55, ptr noundef %6)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %53, ptr noundef @.str, i32 noundef 356, ptr noundef null, i32 noundef %54, i32 noundef %56)
  br label %57

57:                                               ; preds = %49
  %58 = load i32, ptr %7, align 4, !tbaa !12
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !12
  br label %45, !llvm.loop !15

60:                                               ; preds = %48
  store i32 60, ptr %6, align 4, !tbaa !12
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = call i32 @arrayListGetIndex(ptr noundef %62, ptr noundef %6)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %61, ptr noundef @.str, i32 noundef 360, ptr noundef null, i32 noundef -1, i32 noundef %63)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %64) #5
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyArrayList(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

declare i32 @arrayListGetIndex(ptr noundef, ptr noundef) #3

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 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: nounwind uwtable
declare dso_local i32 @compareIntPointersALT(ptr noundef, ptr noundef) #2

declare ptr @arrayListInitialization(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

declare void @destroyArrayList(ptr noundef) local_unnamed_addr #3

declare void @arrayListAddAll(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @testArrayListGetIndex(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca i32, align 4
  %3 = tail call ptr @arrayListInitialization(i32 noundef 1, ptr noundef nonnull @free, ptr noundef nonnull @compareIntPointersALT) #5
  %4 = tail call i32 @arrayListGetIndex(ptr noundef null, 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 338, ptr noundef null, i32 noundef -83386157, i32 noundef %6) #5
  %7 = tail call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef null) #5
  %8 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %9 = load i32, ptr %8, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 341, ptr noundef null, i32 noundef -83384987, i32 noundef %9) #5
  %10 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #6
  %11 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  store ptr %11, ptr %10, align 8, !tbaa !5
  store i32 10, ptr %11, align 4, !tbaa !12
  %12 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  %13 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !5
  store i32 20, ptr %12, align 4, !tbaa !12
  %14 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  %15 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %14, ptr %15, align 8, !tbaa !5
  store i32 30, ptr %14, align 4, !tbaa !12
  %16 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  %17 = getelementptr inbounds i8, ptr %10, i64 24
  store ptr %16, ptr %17, align 8, !tbaa !5
  store i32 40, ptr %16, align 4, !tbaa !12
  %18 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  %19 = getelementptr inbounds i8, ptr %10, i64 32
  store ptr %18, ptr %19, align 8, !tbaa !5
  store i32 50, ptr %18, align 4, !tbaa !12
  tail call void @arrayListAddAll(ptr noundef %3, ptr noundef nonnull %10, i32 noundef 5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 10, ptr %2, align 4, !tbaa !12
  %20 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 356, ptr noundef null, i32 noundef 0, i32 noundef %20) #5
  store i32 20, ptr %2, align 4, !tbaa !12
  %21 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 356, ptr noundef null, i32 noundef 1, i32 noundef %21) #5
  store i32 30, ptr %2, align 4, !tbaa !12
  %22 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 356, ptr noundef null, i32 noundef 2, i32 noundef %22) #5
  store i32 40, ptr %2, align 4, !tbaa !12
  %23 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 356, ptr noundef null, i32 noundef 3, i32 noundef %23) #5
  store i32 50, ptr %2, align 4, !tbaa !12
  %24 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 356, ptr noundef null, i32 noundef 4, i32 noundef %24) #5
  store i32 60, ptr %2, align 4, !tbaa !12
  %25 = call i32 @arrayListGetIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 360, ptr noundef null, i32 noundef -1, i32 noundef %25) #5
  call void @free(ptr noundef %10) #5
  call void @destroyArrayList(ptr noundef %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  ret void
}

declare i32 @arrayListGetIndex(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { 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 #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, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}


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