; LLVM IR from bonamarton/phys_num :: gauss_jordan_elim (gauss)

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

@.str.23 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [45 x i8], align 1

; 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: noreturn nounwind
declare void @exit(i32 noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: nounwind uwtable
define dso_local void @subRow(ptr noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = 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 double %3, ptr %8, align 8, !tbaa !11
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tensor, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp sge i32 %10, %13
  br i1 %14, label %21, label %15

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tensor, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp sge i32 %16, %19
  br i1 %20, label %21, label %31

21:                                               ; preds = %15, %4
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.23)
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tensor, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, i32 noundef %24, i32 noundef %26, i32 noundef %29)
  call void @exit(i32 noundef 0) #5
  unreachable

31:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %68, %31
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tensor, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = icmp slt i32 %33, %36
  br i1 %37, label %38, label %71

38:                                               ; preds = %32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.tensor, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tensor, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = mul nsw i32 %42, %45
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = add nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %41, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = load double, ptr %8, align 8, !tbaa !11
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tensor, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tensor, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !15
  %60 = mul nsw i32 %56, %59
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = add nsw i32 %60, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %55, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fneg double %51
  %67 = call double @llvm.fmuladd.f64(double %66, double %52, double %65)
  store double %67, ptr %64, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %38
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %9, align 4, !tbaa !9
  br label %32, !llvm.loop !17

71:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"tensor", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!15 = !{!14, !10, i64 12}
!16 = !{!14, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.23 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local void @subRow(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #3 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp sgt i32 %6, %1
  %.not22 = icmp sgt i32 %6, %2
  %or.cond = and i1 %.not, %.not22
  br i1 %or.cond, label %.preheader, label %34

.preheader:                                       ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %11 = mul nsw i32 %8, %2
  %12 = mul nsw i32 %8, %1
  %13 = sext i32 %11 to i64
  %14 = sext i32 %12 to i64
  %wide.trip.count = zext nneg i32 %8 to i64
  %invariant.gep = getelementptr double, ptr %10, i64 %13
  %invariant.gep25 = getelementptr double, ptr %10, i64 %14
  %min.iters.check = icmp ult i32 %8, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %gep.prol = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.ph
  %15 = load double, ptr %gep.prol, align 8, !tbaa !13
  %gep26.prol = getelementptr double, ptr %invariant.gep25, i64 %indvars.iv.ph
  %16 = load double, ptr %gep26.prol, align 8, !tbaa !13
  %17 = fneg double %15
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %3, double %16)
  store double %18, ptr %gep26.prol, align 8, !tbaa !13
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %19 = add nsw i64 %wide.trip.count, -1
  %20 = icmp eq i64 %indvars.iv.ph, %19
  br i1 %20, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %21 = add nsw i64 %14, %wide.trip.count
  %22 = shl nsw i64 %21, 3
  %scevgep = getelementptr i8, ptr %10, i64 %22
  %23 = add nsw i64 %13, %wide.trip.count
  %24 = shl nsw i64 %23, 3
  %scevgep27 = getelementptr i8, ptr %10, i64 %24
  %bound0 = icmp ult ptr %invariant.gep25, %scevgep27
  %bound1 = icmp ult ptr %invariant.gep, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  %broadcast.splatinsert = insertelement <2 x double> poison, double %3, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %25 = getelementptr double, ptr %invariant.gep, i64 %index
  %26 = getelementptr i8, ptr %25, i64 16
  %wide.load = load <2 x double>, ptr %25, align 8, !tbaa !13, !alias.scope !15
  %wide.load28 = load <2 x double>, ptr %26, align 8, !tbaa !13, !alias.scope !15
  %27 = getelementptr double, ptr %invariant.gep25, i64 %index
  %28 = getelementptr i8, ptr %27, i64 16
  %wide.load29 = load <2 x double>, ptr %27, align 8, !tbaa !13, !alias.scope !18, !noalias !15
  %wide.load30 = load <2 x double>, ptr %28, align 8, !tbaa !13, !alias.scope !18, !noalias !15
  %29 = fneg <2 x double> %wide.load
  %30 = fneg <2 x double> %wide.load28
  %31 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %29, <2 x double> %broadcast.splat, <2 x double> %wide.load29)
  %32 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %broadcast.splat, <2 x double> %wide.load30)
  store <2 x double> %31, ptr %27, align 8, !tbaa !13, !alias.scope !18, !noalias !15
  store <2 x double> %32, ptr %28, align 8, !tbaa !13, !alias.scope !18, !noalias !15
  %index.next = add nuw i64 %index, 4
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !20

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

34:                                               ; preds = %4
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23)
  %36 = add nsw i32 %1, 1
  %37 = add nsw i32 %2, 1
  %38 = load i32, ptr %5, align 8, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i32 noundef %36, i32 noundef %37, i32 noundef %38)
  tail call void @exit(i32 noundef 0) #5
  unreachable

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %40 = load double, ptr %gep, align 8, !tbaa !13
  %gep26 = getelementptr double, ptr %invariant.gep25, i64 %indvars.iv
  %41 = load double, ptr %gep26, align 8, !tbaa !13
  %42 = fneg double %40
  %43 = tail call double @llvm.fmuladd.f64(double %42, double %3, double %41)
  store double %43, ptr %gep26, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %gep.1 = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.next
  %44 = load double, ptr %gep.1, align 8, !tbaa !13
  %gep26.1 = getelementptr double, ptr %invariant.gep25, i64 %indvars.iv.next
  %45 = load double, ptr %gep26.1, align 8, !tbaa !13
  %46 = fneg double %44
  %47 = tail call double @llvm.fmuladd.f64(double %46, double %3, double %45)
  store double %47, ptr %gep26.1, align 8, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #4

attributes #0 = { noreturn 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 #1 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn 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, !10, i64 8}
!6 = !{!"tensor", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !17}
!17 = distinct !{!17, !"LVerDomain"}
!18 = !{!19}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !22}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass