; LLVM IR from AlgoGenesis/C :: 2D Arrays/Determinant of a square matrix (program)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @determinant_recursive(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [10 x [10 x i32]], align 16
  %9 = alloca i32, align 4
  %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 %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %22

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds [10 x i32], ptr %18, i64 0
  %20 = getelementptr inbounds [10 x i32], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %94

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 400, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %89, %22
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %92

28:                                               ; preds = %23
  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 1, ptr %12, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %68, %28
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

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

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

35:                                               ; preds = %62, %34
  %36 = load i32, ptr %14, align 4, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %65

40:                                               ; preds = %35
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  br label %62

45:                                               ; preds = %40
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10 x i32], ptr %46, i64 %48
  %50 = load i32, ptr %14, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x i32], ptr %49, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10 x [10 x i32]], ptr %8, i64 0, i64 %55
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10 x i32], ptr %56, i64 0, i64 %58
  store i32 %53, ptr %59, align 4, !tbaa !9
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %13, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %45, %44
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %14, align 4, !tbaa !9
  br label %35, !llvm.loop !11

65:                                               ; preds = %39
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %68

68:                                               ; preds = %65
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %12, align 4, !tbaa !9
  br label %29, !llvm.loop !13

71:                                               ; preds = %33
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds [10 x i32], ptr %73, i64 0
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = mul nsw i32 %72, %78
  %80 = getelementptr inbounds [10 x [10 x i32]], ptr %8, i64 0, i64 0
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = sub nsw i32 %81, 1
  %83 = call i32 @determinant_recursive(ptr noundef %80, i32 noundef %82)
  %84 = mul nsw i32 %79, %83
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %6, align 4, !tbaa !9
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = sub nsw i32 0, %87
  store i32 %88, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %89

89:                                               ; preds = %71
  %90 = load i32, ptr %10, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !14

92:                                               ; preds = %27
  %93 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %93, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 400, ptr %8) #2
  br label %94

94:                                               ; preds = %92, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @determinant_recursive(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [10 x [10 x i32]], align 16
  %4 = icmp eq i32 %1, 1
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = load i32, ptr %0, align 4, !tbaa !5
  br label %40

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %3) #2
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.preheader35.us.preheader, label %._crit_edge

.preheader35.us.preheader:                        ; preds = %7
  %9 = add nsw i32 %1, -1
  %wide.trip.count58 = zext nneg i32 %1 to i64
  %wide.trip.count53 = zext i32 %9 to i64
  %xtraiter = and i64 %wide.trip.count58, 1
  %unroll_iter = and i64 %wide.trip.count58, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader35.us

.preheader35.us:                                  ; preds = %.preheader35.us.preheader, %._crit_edge40.split.us.us
  %indvars.iv55 = phi i64 [ 0, %.preheader35.us.preheader ], [ %indvars.iv.next56, %._crit_edge40.split.us.us ]
  %.03142.us = phi i32 [ 1, %.preheader35.us.preheader ], [ %39, %._crit_edge40.split.us.us ]
  %.03241.us = phi i32 [ 0, %.preheader35.us.preheader ], [ %38, %._crit_edge40.split.us.us ]
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %._crit_edge.us.us, %.preheader35.us
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %._crit_edge.us.us ], [ 0, %.preheader35.us ]
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %._crit_edge.us.us ], [ 1, %.preheader35.us ]
  br label %10

10:                                               ; preds = %26, %.preheader.us.us
  %indvars.iv = phi i64 [ 0, %.preheader.us.us ], [ %indvars.iv.next.1, %26 ]
  %.02736.us.us = phi i32 [ 0, %.preheader.us.us ], [ %.1.us.us.1, %26 ]
  %niter = phi i64 [ 0, %.preheader.us.us ], [ %niter.next.1, %26 ]
  %11 = icmp eq i64 %indvars.iv, %indvars.iv55
  br i1 %11, label %18, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv46, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %.02736.us.us to i64
  %16 = getelementptr inbounds [10 x [10 x i32]], ptr %3, i64 0, i64 %indvars.iv48, i64 %15
  store i32 %14, ptr %16, align 4, !tbaa !5
  %17 = add nsw i32 %.02736.us.us, 1
  br label %18

18:                                               ; preds = %12, %10
  %.1.us.us = phi i32 [ %.02736.us.us, %10 ], [ %17, %12 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = icmp eq i64 %indvars.iv.next, %indvars.iv55
  br i1 %19, label %26, label %20

20:                                               ; preds = %18
  %21 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv46, i64 %indvars.iv.next
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %.1.us.us to i64
  %24 = getelementptr inbounds [10 x [10 x i32]], ptr %3, i64 0, i64 %indvars.iv48, i64 %23
  store i32 %22, ptr %24, align 4, !tbaa !5
  %25 = add nsw i32 %.1.us.us, 1
  br label %26

26:                                               ; preds = %20, %18
  %.1.us.us.1 = phi i32 [ %.1.us.us, %18 ], [ %25, %20 ]
  %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.us.unr-lcssa, label %10, !llvm.loop !9

._crit_edge.us.us.unr-lcssa:                      ; preds = %26
  %27 = icmp eq i64 %indvars.iv.next.1, %indvars.iv55
  %or.cond = select i1 %lcmp.mod.not, i1 true, i1 %27
  br i1 %or.cond, label %._crit_edge.us.us, label %28

28:                                               ; preds = %._crit_edge.us.us.unr-lcssa
  %29 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv46, i64 %indvars.iv.next.1
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %.1.us.us.1 to i64
  %32 = getelementptr inbounds [10 x [10 x i32]], ptr %3, i64 0, i64 %indvars.iv48, i64 %31
  store i32 %30, ptr %32, align 4, !tbaa !5
  br label %._crit_edge.us.us

._crit_edge.us.us:                                ; preds = %28, %._crit_edge.us.us.unr-lcssa
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count53
  br i1 %exitcond54.not, label %._crit_edge40.split.us.us, label %.preheader.us.us, !llvm.loop !11

._crit_edge40.split.us.us:                        ; preds = %._crit_edge.us.us
  %33 = getelementptr inbounds [10 x i32], ptr %0, i64 0, i64 %indvars.iv55
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %34, %.03142.us
  %36 = call i32 @determinant_recursive(ptr noundef nonnull %3, i32 noundef %9)
  %37 = mul nsw i32 %35, %36
  %38 = add nsw i32 %37, %.03241.us
  %39 = sub nsw i32 0, %.03142.us
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count58
  br i1 %exitcond59.not, label %._crit_edge, label %.preheader35.us, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge40.split.us.us, %7
  %.032.lcssa = phi i32 [ 0, %7 ], [ %38, %._crit_edge40.split.us.us ]
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %3) #2
  br label %40

40:                                               ; preds = %._crit_edge, %5
  %.033 = phi i32 [ %6, %5 ], [ %.032.lcssa, %._crit_edge ]
  ret i32 %.033
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nosync nounwind memory(argmem: read) 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 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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