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

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

; Function Attrs: nounwind
declare double @log10(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @errorUnitMatrix(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %61, %1
  %8 = load i32, ptr %4, align 4, !tbaa !11
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.tensor, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %64

13:                                               ; preds = %7
  %14 = load i32, ptr %4, align 4, !tbaa !11
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tensor, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = mul nsw i32 %14, %17
  store i32 %18, ptr %6, align 4, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %57, %13
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tensor, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %60

25:                                               ; preds = %19
  %26 = load i32, ptr %4, align 4, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %25
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tensor, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !11
  %35 = add nsw i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %32, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fsub double 1.000000e+00, %38
  %40 = call double @llvm.fabs.f64(double %39)
  %41 = load double, ptr %3, align 8, !tbaa !9
  %42 = fadd double %41, %40
  store double %42, ptr %3, align 8, !tbaa !9
  br label %56

43:                                               ; preds = %25
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tensor, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load i32, ptr %6, align 4, !tbaa !11
  %48 = load i32, ptr %5, align 4, !tbaa !11
  %49 = add nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %46, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = call double @llvm.fabs.f64(double %52)
  %54 = load double, ptr %3, align 8, !tbaa !9
  %55 = fadd double %54, %53
  store double %55, ptr %3, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %43, %29
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %5, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !11
  br label %19, !llvm.loop !17

60:                                               ; preds = %19
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %4, align 4, !tbaa !11
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !11
  br label %7, !llvm.loop !19

64:                                               ; preds = %7
  %65 = load double, ptr %3, align 8, !tbaa !9
  %66 = call double @log10(double noundef %65) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"tensor", !6, i64 0, !12, i64 8, !12, i64 12, !6, i64 16}
!15 = !{!14, !12, i64 12}
!16 = !{!14, !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"

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log10(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local double @errorUnitMatrix(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph25, label %._crit_edge26

.lr.ph25:                                         ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph.us.preheader, label %._crit_edge26

.lr.ph.us.preheader:                              ; preds = %.lr.ph25
  %8 = zext nneg i32 %6 to i64
  %wide.trip.count33 = zext nneg i32 %3 to i64
  %xtraiter = and i64 %8, 1
  %9 = icmp eq i32 %6, 1
  %unroll_iter = and i64 %8, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv30 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next31, %._crit_edge.us ]
  %.01922.us = phi double [ 0.000000e+00, %.lr.ph.us.preheader ], [ %.2.us.lcssa, %._crit_edge.us ]
  %10 = mul nuw nsw i64 %indvars.iv30, %8
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %invariant.gep = getelementptr inbounds double, ptr %11, i64 %10
  %12 = getelementptr inbounds double, ptr %11, i64 %indvars.iv30
  %13 = getelementptr inbounds double, ptr %12, i64 %10
  %invariant.gep36 = getelementptr inbounds double, ptr %11, i64 %10
  %14 = getelementptr inbounds double, ptr %11, i64 %indvars.iv30
  %15 = getelementptr inbounds double, ptr %14, i64 %10
  br label %16

16:                                               ; preds = %31, %.lr.ph.us.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.us.new ], [ %indvars.iv.next.1, %31 ]
  %.120.us = phi double [ %.01922.us, %.lr.ph.us.new ], [ %.2.us.1, %31 ]
  %niter = phi i64 [ 0, %.lr.ph.us.new ], [ %niter.next.1, %31 ]
  %17 = icmp eq i64 %indvars.iv30, %indvars.iv
  br i1 %17, label %20, label %18

18:                                               ; preds = %16
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv
  %19 = load double, ptr %gep, align 8, !tbaa !13
  br label %23

20:                                               ; preds = %16
  %21 = load double, ptr %13, align 8, !tbaa !13
  %22 = fsub double 1.000000e+00, %21
  br label %23

23:                                               ; preds = %20, %18
  %.sink = phi double [ %22, %20 ], [ %19, %18 ]
  %24 = tail call double @llvm.fabs.f64(double %.sink)
  %.2.us = fadd double %.120.us, %24
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = icmp eq i64 %indvars.iv30, %indvars.iv.next
  br i1 %25, label %28, label %26

26:                                               ; preds = %23
  %gep37 = getelementptr inbounds double, ptr %invariant.gep36, i64 %indvars.iv.next
  %27 = load double, ptr %gep37, align 8, !tbaa !13
  br label %31

28:                                               ; preds = %23
  %29 = load double, ptr %15, align 8, !tbaa !13
  %30 = fsub double 1.000000e+00, %29
  br label %31

31:                                               ; preds = %28, %26
  %.sink.1 = phi double [ %30, %28 ], [ %27, %26 ]
  %32 = tail call double @llvm.fabs.f64(double %.sink.1)
  %.2.us.1 = fadd double %.2.us, %32
  %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 %16, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %31, %.lr.ph.us
  %.2.us.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %.2.us.1, %31 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.1, %31 ]
  %.120.us.unr = phi double [ %.01922.us, %.lr.ph.us ], [ %.2.us.1, %31 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %33 = icmp eq i64 %indvars.iv30, %indvars.iv.unr
  %34 = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %33, label %39, label %35

35:                                               ; preds = %.epil.preheader
  %36 = getelementptr inbounds double, ptr %34, i64 %indvars.iv.unr
  %37 = getelementptr inbounds double, ptr %36, i64 %10
  %38 = load double, ptr %37, align 8, !tbaa !13
  br label %._crit_edge.us.epilog-lcssa

39:                                               ; preds = %.epil.preheader
  %40 = getelementptr inbounds double, ptr %34, i64 %indvars.iv30
  %41 = getelementptr inbounds double, ptr %40, i64 %10
  %42 = load double, ptr %41, align 8, !tbaa !13
  %43 = fsub double 1.000000e+00, %42
  br label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %39, %35
  %.sink.epil = phi double [ %43, %39 ], [ %38, %35 ]
  %44 = tail call double @llvm.fabs.f64(double %.sink.epil)
  %.2.us.epil = fadd double %.120.us.unr, %44
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.2.us.lcssa = phi double [ %.2.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.2.us.epil, %._crit_edge.us.epilog-lcssa ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %._crit_edge26, label %.lr.ph.us, !llvm.loop !17

._crit_edge26:                                    ; preds = %._crit_edge.us, %.lr.ph25, %1
  %.019.lcssa = phi double [ 0.000000e+00, %1 ], [ 0.000000e+00, %.lr.ph25 ], [ %.2.us.lcssa, %._crit_edge.us ]
  %45 = tail call double @log10(double noundef %.019.lcssa) #3
  ret double %45
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(readwrite, inaccessiblemem: write) 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, !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