; LLVM IR from Thre4dripper/DSA-Programs :: 02. Matrix/07_MinorsMatrix.ll (Z5MinorPA5_iiii)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z11determinantPA5_ii(ptr noundef, 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: mustprogress uwtable
define dso_local noundef i32 @_Z5MinorPA5_iiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [5 x [5 x i32]], align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 100, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %59, %4
  %16 = load i32, ptr %12, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %62

20:                                               ; preds = %15
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp ne i32 %21, %22
  br i1 %23, label %24, label %58

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %52, %24
  %26 = load i32, ptr %14, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %25
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp ne i32 %31, %32
  br i1 %33, label %34, label %51

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5 x i32], ptr %35, i64 %37
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [5 x [5 x i32]], ptr %9, i64 0, i64 %44
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5 x i32], ptr %45, i64 0, i64 %47
  store i32 %42, ptr %48, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %34, %30
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %14, align 4, !tbaa !9
  br label %25, !llvm.loop !11

55:                                               ; preds = %29
  store i32 0, ptr %11, align 4, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %55, %20
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %12, align 4, !tbaa !9
  br label %15, !llvm.loop !13

62:                                               ; preds = %19
  %63 = getelementptr inbounds [5 x [5 x i32]], ptr %9, i64 0, i64 0
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  %66 = call noundef i32 @_Z11determinantPA5_ii(ptr noundef %63, i32 noundef %65)
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 100, ptr %9) #2
  ret i32 %66
}

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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z11determinantPA5_ii(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5MinorPA5_iiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [5 x [5 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %5) #2
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph30.split.us.preheader, label %._crit_edge31

.lr.ph30.split.us.preheader:                      ; preds = %4
  %7 = zext i32 %3 to i64
  %8 = zext i32 %2 to i64
  %wide.trip.count36 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count36, 1
  %9 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %wide.trip.count36, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph30.split.us

.lr.ph30.split.us:                                ; preds = %.lr.ph30.split.us.preheader, %24
  %indvars.iv33 = phi i64 [ 0, %.lr.ph30.split.us.preheader ], [ %indvars.iv.next34, %24 ]
  %.01926.us = phi i32 [ 0, %.lr.ph30.split.us.preheader ], [ %.120.us, %24 ]
  %.not.us = icmp eq i64 %indvars.iv33, %8
  br i1 %.not.us, label %24, label %.preheader.us

.preheader.us.new:                                ; preds = %.preheader.us, %23
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %23 ], [ 0, %.preheader.us ]
  %.124.us = phi i32 [ %.2.us.1, %23 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %23 ], [ 0, %.preheader.us ]
  %.not23.us = icmp eq i64 %indvars.iv, %7
  br i1 %.not23.us, label %16, label %10

10:                                               ; preds = %.preheader.us.new
  %11 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv33, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %.124.us to i64
  %14 = getelementptr inbounds [5 x [5 x i32]], ptr %5, i64 0, i64 %25, i64 %13
  store i32 %12, ptr %14, align 4, !tbaa !5
  %15 = add nsw i32 %.124.us, 1
  br label %16

16:                                               ; preds = %10, %.preheader.us.new
  %.2.us = phi i32 [ %15, %10 ], [ %.124.us, %.preheader.us.new ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not23.us.1 = icmp eq i64 %indvars.iv.next, %7
  br i1 %.not23.us.1, label %23, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv33, i64 %indvars.iv.next
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %.2.us to i64
  %21 = getelementptr inbounds [5 x [5 x i32]], ptr %5, i64 0, i64 %25, i64 %20
  store i32 %19, ptr %21, align 4, !tbaa !5
  %22 = add nsw i32 %.2.us, 1
  br label %23

23:                                               ; preds = %17, %16
  %.2.us.1 = phi i32 [ %22, %17 ], [ %.2.us, %16 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

24:                                               ; preds = %._crit_edge.us, %.lr.ph30.split.us
  %.120.us = phi i32 [ %31, %._crit_edge.us ], [ %.01926.us, %.lr.ph30.split.us ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge31, label %.lr.ph30.split.us, !llvm.loop !11

.preheader.us:                                    ; preds = %.lr.ph30.split.us
  %25 = sext i32 %.01926.us to i64
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

._crit_edge.us.unr-lcssa:                         ; preds = %23, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %23 ]
  %.124.us.unr = phi i32 [ 0, %.preheader.us ], [ %.2.us.1, %23 ]
  %.not23.us.epil = icmp eq i64 %indvars.iv.unr, %7
  %or.cond = select i1 %lcmp.mod.not, i1 true, i1 %.not23.us.epil
  br i1 %or.cond, label %._crit_edge.us, label %26

26:                                               ; preds = %._crit_edge.us.unr-lcssa
  %27 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv33, i64 %indvars.iv.unr
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %.124.us.unr to i64
  %30 = getelementptr inbounds [5 x [5 x i32]], ptr %5, i64 0, i64 %25, i64 %29
  store i32 %28, ptr %30, align 4, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %26, %._crit_edge.us.unr-lcssa
  %31 = add nsw i32 %.01926.us, 1
  br label %24

._crit_edge31:                                    ; preds = %24, %4
  %32 = add nsw i32 %1, -1
  %33 = call noundef i32 @_Z11determinantPA5_ii(ptr noundef nonnull %5, i32 noundef %32)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %5) #2
  ret i32 %33
}

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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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