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

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

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @generateIntPointerMT(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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

declare ptr @matrixInitialization(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #2

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

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

declare void @destroyMatrix(ptr noundef) #2

declare void @matrixInsert(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

declare void @CuAssertPtrEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @matrixGetSize(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @testClearMatrix(ptr noundef %0) #0 {
  %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
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = call ptr @matrixInitialization(i32 noundef 2, i32 noundef 2, ptr noundef @free, ptr noundef @compareIntPointersMT)
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @clearMatrix(ptr noundef null)
  %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 732, ptr noundef null, i32 noundef -83386157, i32 noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @clearMatrix(ptr noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call ptr @generateIntPointerMT(i32 noundef 10)
  call void @matrixInsert(ptr noundef %14, ptr noundef %15, i32 noundef 0, i32 noundef 0)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @generateIntPointerMT(i32 noundef 13)
  call void @matrixInsert(ptr noundef %16, ptr noundef %17, i32 noundef 0, i32 noundef 1)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call ptr @generateIntPointerMT(i32 noundef 11)
  call void @matrixInsert(ptr noundef %18, ptr noundef %19, i32 noundef 1, i32 noundef 0)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call ptr @generateIntPointerMT(i32 noundef 12)
  call void @matrixInsert(ptr noundef %20, ptr noundef %21, i32 noundef 1, i32 noundef 1)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i32 @matrixGetSize(ptr noundef %23)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %22, ptr noundef @.str, i32 noundef 741, ptr noundef null, i32 noundef 4, i32 noundef %24)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @clearMatrix(ptr noundef %25)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i32 @matrixGetSize(ptr noundef %27)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %26, ptr noundef @.str, i32 noundef 744, ptr noundef null, i32 noundef 0, i32 noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %29

29:                                               ; preds = %61, %1
  %30 = load i32, ptr %4, align 4, !tbaa !12
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Matrix, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %64

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %37

37:                                               ; preds = %57, %36
  %38 = load i32, ptr %7, align 4, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Matrix, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = icmp slt i32 %38, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %60

44:                                               ; preds = %37
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Matrix, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load i32, ptr %4, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !12
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  call void @CuAssertPtrEquals_LineMsg(ptr noundef %45, ptr noundef @.str, i32 noundef 750, ptr noundef null, ptr noundef null, ptr noundef %56)
  br label %57

57:                                               ; preds = %44
  %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 %37, !llvm.loop !17

60:                                               ; preds = %43
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %4, align 4, !tbaa !12
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !12
  br label %29, !llvm.loop !19

64:                                               ; preds = %35
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyMatrix(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare void @clearMatrix(ptr noundef) #2

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

!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 8}
!14 = !{!"Matrix", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32}
!15 = !{!14, !11, i64 16}
!16 = !{!14, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @generateIntPointerMT(i32 noundef) local_unnamed_addr #0

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

declare ptr @matrixInitialization(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

declare void @destroyMatrix(ptr noundef) local_unnamed_addr #1

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

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

declare i32 @matrixGetSize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @testClearMatrix(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @matrixInitialization(i32 noundef 2, i32 noundef 2, ptr noundef nonnull @free, ptr noundef nonnull @compareIntPointersMT) #3
  tail call void @clearMatrix(ptr noundef null) #3
  %3 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 732, ptr noundef null, i32 noundef -83386157, i32 noundef %4) #3
  tail call void @clearMatrix(ptr noundef %2) #3
  %5 = tail call ptr @generateIntPointerMT(i32 noundef 10)
  tail call void @matrixInsert(ptr noundef %2, ptr noundef %5, i32 noundef 0, i32 noundef 0) #3
  %6 = tail call ptr @generateIntPointerMT(i32 noundef 13)
  tail call void @matrixInsert(ptr noundef %2, ptr noundef %6, i32 noundef 0, i32 noundef 1) #3
  %7 = tail call ptr @generateIntPointerMT(i32 noundef 11)
  tail call void @matrixInsert(ptr noundef %2, ptr noundef %7, i32 noundef 1, i32 noundef 0) #3
  %8 = tail call ptr @generateIntPointerMT(i32 noundef 12)
  tail call void @matrixInsert(ptr noundef %2, ptr noundef %8, i32 noundef 1, i32 noundef 1) #3
  %9 = tail call i32 @matrixGetSize(ptr noundef %2) #3
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 741, ptr noundef null, i32 noundef 4, i32 noundef %9) #3
  tail call void @clearMatrix(ptr noundef %2) #3
  %10 = tail call i32 @matrixGetSize(ptr noundef %2) #3
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 744, ptr noundef null, i32 noundef 0, i32 noundef %10) #3
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader.lr.ph, label %._crit_edge24

.preheader.lr.ph:                                 ; preds = %1
  %14 = getelementptr inbounds i8, ptr %2, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.preheader, label %._crit_edge24

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %17 = phi i32 [ %20, %._crit_edge ], [ %12, %.preheader.lr.ph ]
  %18 = phi i32 [ %21, %._crit_edge ], [ %15, %.preheader.lr.ph ]
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %._crit_edge

._crit_edge24:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %1
  tail call void @destroyMatrix(ptr noundef nonnull %2) #3
  ret void

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %11, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %20 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %17, %.preheader ]
  %21 = phi i32 [ %29, %._crit_edge.loopexit ], [ %18, %.preheader ]
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %22 = sext i32 %20 to i64
  %23 = icmp slt i64 %indvars.iv.next28, %22
  br i1 %23, label %.preheader, label %._crit_edge24, !llvm.loop !15

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %24 = load ptr, ptr %2, align 8, !tbaa !18
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv27
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  tail call void @CuAssertPtrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 750, ptr noundef null, ptr noundef null, ptr noundef %28) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr %14, align 8, !tbaa !14
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !19
}

declare void @clearMatrix(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 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 #3 = { 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 = !{!"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 = !{!13, !11, i64 8}
!13 = !{!"Matrix", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32}
!14 = !{!13, !11, i64 16}
!15 = distinct !{!15, !16, !17}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.unswitch.partial.disable"}
!18 = !{!13, !6, i64 0}
!19 = distinct !{!19, !16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass