; 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 @testArrayListGetLastIndex(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 @arrayListGetLastIndex(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 373, ptr noundef null, i32 noundef -83386157, i32 noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 @arrayListGetLastIndex(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 376, 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 48) #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 = %54, %1
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = icmp slt i32 %22, 6
  br i1 %23, label %25, label %24

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

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
  %39 = call noalias ptr @malloc(i64 noundef 4) #6
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !12
  %42 = add nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %40, i64 %43
  store ptr %39, ptr %44, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !12
  %46 = add nsw i32 %45, 1
  %47 = mul nsw i32 %46, 10
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !12
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %48, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  store i32 %47, ptr %53, align 4, !tbaa !12
  br label %54

54:                                               ; preds = %25
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = add nsw i32 %55, 2
  store i32 %56, ptr %5, align 4, !tbaa !12
  br label %21, !llvm.loop !13

57:                                               ; preds = %24
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @arrayListAddAll(ptr noundef %58, ptr noundef %59, i32 noundef 6)
  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 %60

60:                                               ; preds = %73, %57
  %61 = load i32, ptr %7, align 4, !tbaa !12
  %62 = icmp slt i32 %61, 6
  br i1 %62, label %64, label %63

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

64:                                               ; preds = %60
  %65 = load i32, ptr %7, align 4, !tbaa !12
  %66 = add nsw i32 %65, 1
  %67 = mul nsw i32 %66, 10
  store i32 %67, ptr %6, align 4, !tbaa !12
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !12
  %70 = add nsw i32 %69, 1
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = call i32 @arrayListGetLastIndex(ptr noundef %71, ptr noundef %6)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %68, ptr noundef @.str, i32 noundef 395, ptr noundef null, i32 noundef %70, i32 noundef %72)
  br label %73

73:                                               ; preds = %64
  %74 = load i32, ptr %7, align 4, !tbaa !12
  %75 = add nsw i32 %74, 2
  store i32 %75, ptr %7, align 4, !tbaa !12
  br label %60, !llvm.loop !15

76:                                               ; preds = %63
  store i32 100, ptr %6, align 4, !tbaa !12
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = call i32 @arrayListGetLastIndex(ptr noundef %78, ptr noundef %6)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %77, ptr noundef @.str, i32 noundef 399, ptr noundef null, i32 noundef -1, i32 noundef %79)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %80) #5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyArrayList(ptr noundef %81)
  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 @arrayListGetLastIndex(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 @testArrayListGetLastIndex(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 @arrayListGetLastIndex(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 373, ptr noundef null, i32 noundef -83386157, i32 noundef %6) #5
  %7 = tail call i32 @arrayListGetLastIndex(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 376, ptr noundef null, i32 noundef -83384987, i32 noundef %9) #5
  %10 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #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 10, 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 30, 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
  %20 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #6
  %21 = getelementptr inbounds i8, ptr %10, i64 40
  store ptr %20, ptr %21, align 8, !tbaa !5
  store i32 50, ptr %20, align 4, !tbaa !12
  tail call void @arrayListAddAll(ptr noundef %3, ptr noundef nonnull %10, i32 noundef 6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 10, ptr %2, align 4, !tbaa !12
  %22 = call i32 @arrayListGetLastIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 395, ptr noundef null, i32 noundef 1, i32 noundef %22) #5
  store i32 30, ptr %2, align 4, !tbaa !12
  %23 = call i32 @arrayListGetLastIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 395, ptr noundef null, i32 noundef 3, i32 noundef %23) #5
  store i32 50, ptr %2, align 4, !tbaa !12
  %24 = call i32 @arrayListGetLastIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 395, ptr noundef null, i32 noundef 5, i32 noundef %24) #5
  store i32 100, ptr %2, align 4, !tbaa !12
  %25 = call i32 @arrayListGetLastIndex(ptr noundef %3, ptr noundef nonnull %2) #5
  call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 399, 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 @arrayListGetLastIndex(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