; 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 }
%struct.ArrayList = type { ptr, i32, i32, ptr, ptr }

@.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

; Function Attrs: nounwind uwtable
define dso_local void @testArrayListAddAll(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
  call void @arrayListAddAll(ptr noundef null, ptr noundef null, i32 noundef 0)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ErrorTestStruct, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %9, ptr noundef @.str, i32 noundef 136, ptr noundef null, i32 noundef -83386157, i32 noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @arrayListAddAll(ptr noundef %13, ptr noundef null, i32 noundef 0)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ErrorTestStruct, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %14, ptr noundef @.str, i32 noundef 139, ptr noundef null, i32 noundef -83384987, i32 noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %18 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %18, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !12
  br label %19

19:                                               ; preds = %39, %1
  %20 = load i32, ptr %5, align 4, !tbaa !12
  %21 = icmp sle i32 %20, 3
  br i1 %21, label %23, label %22

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

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

39:                                               ; preds = %23
  %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 %19, !llvm.loop !13

42:                                               ; preds = %22
  %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 3)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ArrayList, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !15
  call void @CuAssertIntEquals_LineMsg(ptr noundef %45, ptr noundef @.str, i32 noundef 151, ptr noundef null, i32 noundef 3, i32 noundef %48)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ArrayList, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = sub nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 2, ptr %7, align 4, !tbaa !12
  br label %53

53:                                               ; preds = %77, %42
  %54 = load i32, ptr %6, align 4, !tbaa !12
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ArrayList, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = sub nsw i32 %57, 4
  %59 = icmp sgt i32 %54, %58
  br i1 %59, label %61, label %60

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

61:                                               ; preds = %53
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !12
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load i32, ptr %67, align 4, !tbaa !12
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ArrayList, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load i32, ptr %6, align 4, !tbaa !12
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds ptr, ptr %71, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4, !tbaa !12
  call void @CuAssertIntEquals_LineMsg(ptr noundef %62, ptr noundef @.str, i32 noundef 154, ptr noundef null, i32 noundef %68, i32 noundef %76)
  br label %77

77:                                               ; preds = %61
  %78 = load i32, ptr %6, align 4, !tbaa !12
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %6, align 4, !tbaa !12
  %80 = load i32, ptr %7, align 4, !tbaa !12
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %7, align 4, !tbaa !12
  br label %53, !llvm.loop !18

82:                                               ; preds = %60
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %83) #5
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyArrayList(ptr noundef %84)
  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 void @arrayListAddAll(ptr noundef, ptr noundef, i32 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 = !{!16, !11, i64 12}
!16 = !{!"ArrayList", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24}
!17 = !{!16, !6, i64 0}
!18 = distinct !{!18, !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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @compareIntPointersALT(ptr noundef, ptr noundef) #1

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

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

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

declare void @destroyArrayList(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @testArrayListAddAll(ptr noundef %0) local_unnamed_addr #1 {
.lr.ph.preheader:
  %1 = tail call ptr @arrayListInitialization(i32 noundef 1, ptr noundef nonnull @free, ptr noundef nonnull @compareIntPointersALT) #4
  tail call void @arrayListAddAll(ptr noundef null, ptr noundef null, i32 noundef 0) #4
  %2 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 136, ptr noundef null, i32 noundef -83386157, i32 noundef %3) #4
  tail call void @arrayListAddAll(ptr noundef %1, ptr noundef null, i32 noundef 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 139, ptr noundef null, i32 noundef -83384987, i32 noundef %5) #4
  %6 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  %7 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #5
  store ptr %7, ptr %6, align 8, !tbaa !5
  store i32 70, ptr %7, align 4, !tbaa !12
  %8 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #5
  %gep.1 = getelementptr i8, ptr %6, i64 8
  store ptr %8, ptr %gep.1, align 8, !tbaa !5
  store i32 80, ptr %8, align 4, !tbaa !12
  %9 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #5
  %gep.2 = getelementptr i8, ptr %6, i64 16
  store ptr %9, ptr %gep.2, align 8, !tbaa !5
  store i32 90, ptr %9, align 4, !tbaa !12
  tail call void @arrayListAddAll(ptr noundef %1, ptr noundef nonnull %6, i32 noundef 3) #4
  %10 = getelementptr inbounds i8, ptr %1, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !13
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 151, ptr noundef null, i32 noundef 3, i32 noundef %11) #4
  %12 = load i32, ptr %10, align 4, !tbaa !13
  %13 = sext i32 %12 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  tail call void @free(ptr noundef nonnull %6) #4
  tail call void @destroyArrayList(ptr noundef nonnull %1) #4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv31 = phi i64 [ %13, %.lr.ph.preheader ], [ %indvars.iv.next32, %.lr.ph ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, -1
  %14 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = load ptr, ptr %1, align 8, !tbaa !15
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv.next32
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !12
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 154, ptr noundef null, i32 noundef %16, i32 noundef %20) #4
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %21 = load i32, ptr %10, align 4, !tbaa !13
  %22 = add nsw i32 %21, -2
  %23 = sext i32 %22 to i64
  %24 = icmp sgt i64 %indvars.iv31, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !16
}

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

attributes #0 = { 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 #1 = { 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 #2 = { "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 }
attributes #5 = { 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 = !{!14, !11, i64 12}
!14 = !{!"ArrayList", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass