; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @r8mat_rref(i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @r8mat_nullspace_size(i32 noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = call ptr @r8mat_copy_new(i32 noundef %12, i32 noundef %13, ptr noundef %14)
  store ptr %15, ptr %11, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load ptr, ptr %11, align 8, !tbaa !9
  call void @r8mat_rref(i32 noundef %16, i32 noundef %17, ptr noundef %18)
  store i32 0, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %47, %3
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %50

23:                                               ; preds = %19
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %43, %23
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %46

28:                                               ; preds = %24
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = mul nsw i32 %31, %32
  %34 = add nsw i32 %30, %33
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %29, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = fcmp oeq double %37, 1.000000e+00
  br i1 %38, label %39, label %42

39:                                               ; preds = %28
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !5
  br label %46

42:                                               ; preds = %28
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %24, !llvm.loop !13

46:                                               ; preds = %39, %24
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !5
  br label %19, !llvm.loop !15

50:                                               ; preds = %19
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  store i32 %53, ptr %10, align 4, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !9
  call void @free(ptr noundef %54) #3
  %55 = load i32, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @r8mat_nullspace_size(i32 noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call ptr @r8mat_copy_new(i32 noundef %0, i32 noundef %1, ptr noundef %2)
  tail call void @r8mat_rref(i32 noundef %0, i32 noundef %1, ptr noundef %4)
  %5 = icmp sgt i32 %0, 0
  %6 = icmp sgt i32 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge

.preheader.us.preheader:                          ; preds = %3
  %7 = zext nneg i32 %0 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %7, 1
  %8 = icmp eq i32 %0, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i64 %7, 2147483646
  br label %.preheader.us

.preheader.us:                                    ; preds = %..loopexit_crit_edge.us.1, %.preheader.us.preheader.new
  %indvars.iv29 = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvars.iv.next30.1, %..loopexit_crit_edge.us.1 ]
  %.02124.us = phi i32 [ 0, %.preheader.us.preheader.new ], [ %.1.us.1, %..loopexit_crit_edge.us.1 ]
  %niter = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter.next.1, %..loopexit_crit_edge.us.1 ]
  %invariant.gep = getelementptr inbounds double, ptr %4, i64 %indvars.iv29
  br label %10

9:                                                ; preds = %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %..loopexit_crit_edge.us, label %10, !llvm.loop !5

10:                                               ; preds = %.preheader.us, %9
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %9 ]
  %11 = mul nuw nsw i64 %indvars.iv, %7
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %11
  %12 = load double, ptr %gep, align 8, !tbaa !7
  %13 = fcmp oeq double %12, 1.000000e+00
  br i1 %13, label %14, label %9

14:                                               ; preds = %10
  %15 = add nsw i32 %.02124.us, 1
  br label %..loopexit_crit_edge.us

..loopexit_crit_edge.us:                          ; preds = %9, %14
  %.1.us = phi i32 [ %15, %14 ], [ %.02124.us, %9 ]
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %invariant.gep.1 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next30
  br label %16

16:                                               ; preds = %20, %..loopexit_crit_edge.us
  %indvars.iv.1 = phi i64 [ 0, %..loopexit_crit_edge.us ], [ %indvars.iv.next.1, %20 ]
  %17 = mul nuw nsw i64 %indvars.iv.1, %7
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep.1, i64 %17
  %18 = load double, ptr %gep.1, align 8, !tbaa !7
  %19 = fcmp oeq double %18, 1.000000e+00
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %..loopexit_crit_edge.us.1, label %16, !llvm.loop !5

21:                                               ; preds = %16
  %22 = add nsw i32 %.1.us, 1
  br label %..loopexit_crit_edge.us.1

..loopexit_crit_edge.us.1:                        ; preds = %20, %21
  %.1.us.1 = phi i32 [ %22, %21 ], [ %.1.us, %20 ]
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 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.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %..loopexit_crit_edge.us.1, %.preheader.us.preheader
  %.1.us.lcssa.ph = phi i32 [ poison, %.preheader.us.preheader ], [ %.1.us.1, %..loopexit_crit_edge.us.1 ]
  %indvars.iv29.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next30.1, %..loopexit_crit_edge.us.1 ]
  %.02124.us.unr = phi i32 [ 0, %.preheader.us.preheader ], [ %.1.us.1, %..loopexit_crit_edge.us.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge.loopexit.unr-lcssa
  %invariant.gep.epil = getelementptr inbounds double, ptr %4, i64 %indvars.iv29.unr
  br label %23

23:                                               ; preds = %27, %.preheader.us.epil
  %indvars.iv.epil = phi i64 [ 0, %.preheader.us.epil ], [ %indvars.iv.next.epil, %27 ]
  %24 = mul nuw nsw i64 %indvars.iv.epil, %7
  %gep.epil = getelementptr inbounds double, ptr %invariant.gep.epil, i64 %24
  %25 = load double, ptr %gep.epil, align 8, !tbaa !7
  %26 = fcmp oeq double %25, 1.000000e+00
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %exitcond.not.epil = icmp eq i64 %indvars.iv.next.epil, %wide.trip.count
  br i1 %exitcond.not.epil, label %._crit_edge, label %23, !llvm.loop !5

28:                                               ; preds = %23
  %29 = add nsw i32 %.02124.us.unr, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %27, %28, %3
  %.021.lcssa = phi i32 [ 0, %3 ], [ %.1.us.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %29, %28 ], [ %.02124.us.unr, %27 ]
  %30 = sub nsw i32 %1, %.021.lcssa
  tail call void @free(ptr noundef %4) #2
  ret i32 %30
}

attributes #0 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}


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