; 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.18 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [36 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

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

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

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

18:                                               ; preds = %3
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.18)
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tensor, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tensor, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, i32 noundef %23, i32 noundef %26, i32 noundef %28, i32 noundef %30)
  store i32 -1, ptr %4, align 4
  br label %85

32:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double -1.000000e+00, ptr %11, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %33, ptr %8, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %80, %32
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tensor, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = icmp slt i32 %35, %38
  br i1 %39, label %40, label %83

40:                                               ; preds = %34
  %41 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %41, ptr %9, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %76, %40
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tensor, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = icmp slt i32 %43, %46
  br i1 %47, label %48, label %79

48:                                               ; preds = %42
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tensor, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tensor, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = mul nsw i32 %52, %55
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %51, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !14
  %62 = call double @llvm.fabs.f64(double %61)
  store double %62, ptr %10, align 8, !tbaa !14
  %63 = load double, ptr %10, align 8, !tbaa !14
  %64 = load double, ptr %11, align 8, !tbaa !14
  %65 = fcmp ogt double %63, %64
  br i1 %65, label %66, label %75

66:                                               ; preds = %48
  %67 = load double, ptr %10, align 8, !tbaa !14
  store double %67, ptr %11, align 8, !tbaa !14
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.tensor, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 4, !tbaa !13
  %72 = mul nsw i32 %68, %71
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  store i32 %74, ptr %12, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %66, %48
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %9, align 4, !tbaa !9
  br label %42, !llvm.loop !17

79:                                               ; preds = %42
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %8, align 4, !tbaa !9
  br label %34, !llvm.loop !19

83:                                               ; preds = %34
  %84 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %84, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %85

85:                                               ; preds = %83, %18
  %86 = load i32, ptr %4, align 4
  ret i32 %86
}

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


; 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.18 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [36 x i8], align 1

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @maxAbsValSubMatrix(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp sgt i32 %5, %1
  br i1 %.not, label %.preheader35, label %37

.preheader35:                                     ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp sgt i32 %7, %2
  br i1 %8, label %.preheader35.split.us, label %.loopexit

.preheader35.split.us:                            ; preds = %.preheader35
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %10 = sext i32 %2 to i64
  %11 = sext i32 %7 to i64
  %12 = sext i32 %1 to i64
  %wide.trip.count48 = sext i32 %5 to i64
  %13 = sub nsw i64 %11, %10
  %xtraiter = and i64 %13, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %14 = mul nsw i64 %10, %11
  %indvars.iv.next.prol = add nsw i64 %10, 1
  %15 = add nsw i64 %11, -1
  %16 = icmp eq i64 %15, %10
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader35.split.us
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge.us ], [ %12, %.preheader35.split.us ]
  %.042.us = phi i32 [ %.2.us.lcssa, %._crit_edge.us ], [ 0, %.preheader35.split.us ]
  %.02541.us = phi double [ %.227.us.lcssa, %._crit_edge.us ], [ -1.000000e+00, %.preheader35.split.us ]
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.preheader.us
  %17 = add nsw i64 %14, %indvars.iv45
  %18 = getelementptr inbounds double, ptr %9, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !13
  %20 = tail call double @llvm.fabs.f64(double %19)
  %21 = fcmp ogt double %20, %.02541.us
  %.227.us.prol = select i1 %21, double %20, double %.02541.us
  %22 = trunc nsw i64 %17 to i32
  %.2.us.prol = select i1 %21, i32 %22, i32 %.042.us
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.preheader.us
  %.227.us.lcssa.unr = phi double [ poison, %.preheader.us ], [ %.227.us.prol, %.prol.loopexit.unr-lcssa ]
  %.2.us.lcssa.unr = phi i32 [ poison, %.preheader.us ], [ %.2.us.prol, %.prol.loopexit.unr-lcssa ]
  %indvars.iv.unr = phi i64 [ %10, %.preheader.us ], [ %indvars.iv.next.prol, %.prol.loopexit.unr-lcssa ]
  %.138.us.unr = phi i32 [ %.042.us, %.preheader.us ], [ %.2.us.prol, %.prol.loopexit.unr-lcssa ]
  %.12637.us.unr = phi double [ %.02541.us, %.preheader.us ], [ %.227.us.prol, %.prol.loopexit.unr-lcssa ]
  br i1 %16, label %._crit_edge.us, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.prol.loopexit, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %.138.us = phi i32 [ %.2.us.1, %.preheader.us.new ], [ %.138.us.unr, %.prol.loopexit ]
  %.12637.us = phi double [ %.227.us.1, %.preheader.us.new ], [ %.12637.us.unr, %.prol.loopexit ]
  %23 = mul nsw i64 %indvars.iv, %11
  %24 = add nsw i64 %23, %indvars.iv45
  %25 = getelementptr inbounds double, ptr %9, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = tail call double @llvm.fabs.f64(double %26)
  %28 = fcmp ogt double %27, %.12637.us
  %.227.us = select i1 %28, double %27, double %.12637.us
  %29 = trunc nsw i64 %24 to i32
  %.2.us = select i1 %28, i32 %29, i32 %.138.us
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %30 = mul nsw i64 %indvars.iv.next, %11
  %31 = add nsw i64 %30, %indvars.iv45
  %32 = getelementptr inbounds double, ptr %9, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !13
  %34 = tail call double @llvm.fabs.f64(double %33)
  %35 = fcmp ogt double %34, %.227.us
  %.227.us.1 = select i1 %35, double %34, double %.227.us
  %36 = trunc nsw i64 %31 to i32
  %.2.us.1 = select i1 %35, i32 %36, i32 %.2.us
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %11
  br i1 %exitcond.not.1, label %._crit_edge.us, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us:                                   ; preds = %.preheader.us.new, %.prol.loopexit
  %.227.us.lcssa = phi double [ %.227.us.lcssa.unr, %.prol.loopexit ], [ %.227.us.1, %.preheader.us.new ]
  %.2.us.lcssa = phi i32 [ %.2.us.lcssa.unr, %.prol.loopexit ], [ %.2.us.1, %.preheader.us.new ]
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count48
  br i1 %exitcond49.not, label %.loopexit, label %.preheader.us, !llvm.loop !17

37:                                               ; preds = %3
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18)
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  %40 = load i32, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %0, i64 12
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = add nsw i32 %1, 1
  %44 = add nsw i32 %2, 1
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, i32 noundef %40, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader35, %37
  %.030 = phi i32 [ -1, %37 ], [ 0, %.preheader35 ], [ %.2.us.lcssa, %._crit_edge.us ]
  ret i32 %.030
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree 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" }

!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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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