; LLVM IR from sgtlaugh/algovault :: code_library/freivalds_algorithm.ll (Z6verify6MatrixS_S_i)

; 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.Matrix = type { i32, i32, [101 x [101 x i64]] }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6verify6MatrixS_S_i(ptr noundef byval(%struct.Matrix) align 8 %0, ptr noundef byval(%struct.Matrix) align 8 %1, ptr noundef byval(%struct.Matrix) align 8 %2, i32 noundef %3) #0 {
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Matrix, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.Matrix, align 8
  %12 = alloca %struct.Matrix, align 8
  %13 = alloca %struct.Matrix, align 8
  store i32 %3, ptr %6, align 4, !tbaa !5
  %14 = getelementptr inbounds %struct.Matrix, ptr %0, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = getelementptr inbounds %struct.Matrix, ptr %1, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp ne i32 %15, %17
  br i1 %18, label %31, label %19

19:                                               ; preds = %4
  %20 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.Matrix, ptr %0, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp ne i32 %21, %23
  br i1 %24, label %31, label %25

25:                                               ; preds = %19
  %26 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = getelementptr inbounds %struct.Matrix, ptr %1, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp ne i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %25, %19, %4
  store i1 false, ptr %5, align 1
  br label %71

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %65, %32
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 2, ptr %8, align 4
  br label %68

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 81616, ptr %9) #3
  %39 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  call void @_ZN6MatrixC2Eiii(ptr noundef nonnull align 8 dereferenceable(81616) %9, i32 noundef %40, i32 noundef 1, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %55, %38
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = getelementptr inbounds %struct.Matrix, ptr %9, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = icmp slt i32 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %41
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %58

47:                                               ; preds = %41
  %48 = call i32 @rand() #3
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.Matrix, ptr %9, i32 0, i32 2
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [101 x [101 x i64]], ptr %50, i64 0, i64 %52
  %54 = getelementptr inbounds [101 x i64], ptr %53, i64 0, i64 0
  store i64 %49, ptr %54, align 8, !tbaa !12
  br label %55

55:                                               ; preds = %47
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !5
  br label %41, !llvm.loop !14

58:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 81616, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 81616, ptr %12) #3
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %12, ptr noundef nonnull align 8 dereferenceable(81616) %1, ptr noundef nonnull align 8 dereferenceable(81616) %9)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %11, ptr noundef nonnull align 8 dereferenceable(81616) %0, ptr noundef nonnull align 8 dereferenceable(81616) %12)
  call void @llvm.lifetime.end.p0(i64 81616, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 81616, ptr %13) #3
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %13, ptr noundef nonnull align 8 dereferenceable(81616) %2, ptr noundef nonnull align 8 dereferenceable(81616) %9)
  %59 = call noundef zeroext i1 @_ZNK6MatrixneERKS_(ptr noundef nonnull align 8 dereferenceable(81616) %11, ptr noundef nonnull align 8 dereferenceable(81616) %13)
  br i1 %59, label %60, label %61

60:                                               ; preds = %58
  store i1 false, ptr %5, align 1
  store i32 1, ptr %8, align 4
  br label %62

61:                                               ; preds = %58
  store i32 0, ptr %8, align 4
  br label %62

62:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 81616, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 81616, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 81616, ptr %9) #3
  %63 = load i32, ptr %8, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !5
  br label %33, !llvm.loop !16

68:                                               ; preds = %62, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %69 = load i32, ptr %8, align 4
  switch i32 %69, label %73 [
    i32 2, label %70
    i32 1, label %71
  ]

70:                                               ; preds = %68
  store i1 true, ptr %5, align 1
  br label %71

71:                                               ; preds = %70, %68, %31
  %72 = load i1, ptr %5, align 1
  ret i1 %72

73:                                               ; preds = %68
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixC2Eiii(ptr noundef nonnull align 8 dereferenceable(81616), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #0 align 2

; Function Attrs: nounwind
declare i32 @rand() #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(81616), ptr noundef nonnull align 8 dereferenceable(81616)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK6MatrixneERKS_(ptr noundef nonnull align 8 dereferenceable(81616), ptr noundef nonnull align 8 dereferenceable(81616)) #0 align 2

attributes #0 = { mustprogress 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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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"

%struct.Matrix = type { i32, i32, [101 x [101 x i64]] }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6verify6MatrixS_S_i(ptr noundef byval(%struct.Matrix) align 8 %0, ptr noundef byval(%struct.Matrix) align 8 %1, ptr noundef byval(%struct.Matrix) align 8 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.Matrix, align 8
  %6 = alloca %struct.Matrix, align 8
  %7 = alloca %struct.Matrix, align 8
  %8 = alloca %struct.Matrix, align 8
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr %1, align 8, !tbaa !10
  %.not = icmp eq i32 %10, %11
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %4
  %13 = load i32, ptr %2, align 8, !tbaa !10
  %14 = load i32, ptr %0, align 8, !tbaa !10
  %.not12 = icmp eq i32 %13, %14
  br i1 %.not12, label %15, label %.loopexit

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %2, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %1, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not13 = icmp eq i32 %17, %19
  br i1 %.not13, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %15
  %20 = icmp slt i32 %3, 1
  br i1 %20, label %.loopexit, label %.lr.ph16

.lr.ph16:                                         ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %5, i64 8
  br label %22

22:                                               ; preds = %._crit_edge, %.lr.ph16
  %.0915 = phi i32 [ 0, %.lr.ph16 ], [ %27, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 81616, ptr nonnull %5) #3
  %23 = load i32, ptr %16, align 4, !tbaa !5
  call void @_ZN6MatrixC2Eiii(ptr noundef nonnull align 8 dereferenceable(81616) %5, i32 noundef %23, i32 noundef 1, i32 noundef 0)
  %24 = load i32, ptr %5, align 8, !tbaa !10
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %22
  call void @llvm.lifetime.start.p0(i64 81616, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 81616, ptr nonnull %7) #3
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %7, ptr noundef nonnull align 8 dereferenceable(81616) %1, ptr noundef nonnull align 8 dereferenceable(81616) %5)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %6, ptr noundef nonnull align 8 dereferenceable(81616) %0, ptr noundef nonnull align 8 dereferenceable(81616) %7)
  call void @llvm.lifetime.end.p0(i64 81616, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 81616, ptr nonnull %8) #3
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %8, ptr noundef nonnull align 8 dereferenceable(81616) %2, ptr noundef nonnull align 8 dereferenceable(81616) %5)
  %26 = call noundef zeroext i1 @_ZNK6MatrixneERKS_(ptr noundef nonnull align 8 dereferenceable(81616) %6, ptr noundef nonnull align 8 dereferenceable(81616) %8)
  call void @llvm.lifetime.end.p0(i64 81616, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 81616, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 81616, ptr nonnull %5) #3
  %27 = add nuw nsw i32 %.0915, 1
  %exitcond = icmp eq i32 %27, %3
  %or.cond = select i1 %26, i1 true, i1 %exitcond
  br i1 %or.cond, label %.loopexit.loopexit, label %22, !llvm.loop !11

.lr.ph:                                           ; preds = %22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %22 ]
  %28 = call i32 @rand() #3
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [101 x [101 x i64]], ptr %21, i64 0, i64 %indvars.iv
  store i64 %29, ptr %30, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %5, align 8, !tbaa !10
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !15

.loopexit.loopexit:                               ; preds = %._crit_edge
  %.3.ph = xor i1 %26, true
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader, %4, %12, %15
  %.3 = phi i1 [ false, %15 ], [ false, %12 ], [ false, %4 ], [ true, %.preheader ], [ %.3.ph, %.loopexit.loopexit ]
  ret i1 %.3
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixC2Eiii(ptr noundef nonnull align 8 dereferenceable(81616), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #0 align 2

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(81616), ptr noundef nonnull align 8 dereferenceable(81616)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK6MatrixneERKS_(ptr noundef nonnull align 8 dereferenceable(81616), ptr noundef nonnull align 8 dereferenceable(81616)) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 4}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !8, i64 0}
!15 = distinct !{!15, !12}


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