; 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 uwtable
declare dso_local void @subRow(ptr noundef, i32 noundef, i32 noundef, double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @eliminationStage2(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.tensor, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.tensor, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = mul nsw i32 %13, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = add nsw i32 %17, %18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %12, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  store double %22, ptr %9, align 8, !tbaa !11
  %23 = load double, ptr %9, align 8, !tbaa !11
  %24 = fsub double %23, 1.000000e+00
  %25 = fcmp ole double %24, 0x3CB0000000000000
  br i1 %25, label %26, label %63

26:                                               ; preds = %3
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  store i32 %28, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %59, %26
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, -1
  br i1 %31, label %32, label %62

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tensor, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tensor, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = mul nsw i32 %36, %39
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %35, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  store double %45, ptr %8, align 8, !tbaa !11
  %46 = load double, ptr %8, align 8, !tbaa !11
  %47 = call double @llvm.fabs.f64(double %46)
  %48 = fcmp olt double %47, 0x10000000000000
  br i1 %48, label %49, label %50

49:                                               ; preds = %32
  br label %59

50:                                               ; preds = %32
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %51, i32 noundef %52, i32 noundef %53, double noundef %54)
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %55, i32 noundef %56, i32 noundef %57, double noundef %58)
  br label %59

59:                                               ; preds = %50, %49
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !16

62:                                               ; preds = %29
  br label %103

63:                                               ; preds = %3
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %99, %63
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = icmp sgt i32 %67, -1
  br i1 %68, label %69, label %102

69:                                               ; preds = %66
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.tensor, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tensor, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 4, !tbaa !15
  %77 = mul nsw i32 %73, %76
  %78 = load i32, ptr %6, align 4, !tbaa !9
  %79 = add nsw i32 %77, %78
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds double, ptr %72, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !11
  store double %82, ptr %8, align 8, !tbaa !11
  %83 = load double, ptr %8, align 8, !tbaa !11
  %84 = call double @llvm.fabs.f64(double %83)
  %85 = fcmp olt double %84, 0x10000000000000
  br i1 %85, label %86, label %87

86:                                               ; preds = %69
  br label %99

87:                                               ; preds = %69
  %88 = load double, ptr %9, align 8, !tbaa !11
  %89 = load double, ptr %8, align 8, !tbaa !11
  %90 = fdiv double %89, %88
  store double %90, ptr %8, align 8, !tbaa !11
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %91, i32 noundef %92, i32 noundef %93, double noundef %94)
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = load i32, ptr %6, align 4, !tbaa !9
  %98 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %95, i32 noundef %96, i32 noundef %97, double noundef %98)
  br label %99

99:                                               ; preds = %87, %86
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = add nsw i32 %100, -1
  store i32 %101, ptr %7, align 4, !tbaa !9
  br label %66, !llvm.loop !18

102:                                              ; preds = %66
  br label %103

103:                                              ; preds = %102, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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


; 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: nounwind uwtable
declare dso_local void @subRow(ptr noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @eliminationStage2(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = add i32 %6, 1
  %8 = mul i32 %7, %2
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds double, ptr %4, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !12
  %12 = fadd double %11, -1.000000e+00
  %13 = fcmp ugt double %12, 0x3CB0000000000000
  %14 = icmp sgt i32 %2, 0
  br i1 %13, label %.preheader, label %.preheader38

.preheader38:                                     ; preds = %3
  br i1 %14, label %.lr.ph, label %.loopexit

.preheader:                                       ; preds = %3
  br i1 %14, label %.lr.ph44, label %.loopexit

.lr.ph:                                           ; preds = %.preheader38, %25
  %.041.in = phi i32 [ %.041, %25 ], [ %2, %.preheader38 ]
  %.041 = add nsw i32 %.041.in, -1
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !11
  %17 = mul nsw i32 %16, %.041
  %18 = add nsw i32 %17, %2
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %15, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !12
  %22 = tail call double @llvm.fabs.f64(double %21)
  %23 = fcmp olt double %22, 0x10000000000000
  br i1 %23, label %25, label %24

24:                                               ; preds = %.lr.ph
  tail call void @subRow(ptr noundef nonnull %0, i32 noundef %.041, i32 noundef %2, double noundef %21)
  tail call void @subRow(ptr noundef %1, i32 noundef %.041, i32 noundef %2, double noundef %21)
  br label %25

25:                                               ; preds = %.lr.ph, %24
  %26 = icmp ugt i32 %.041.in, 1
  br i1 %26, label %.lr.ph, label %.loopexit, !llvm.loop !14

.lr.ph44:                                         ; preds = %.preheader, %38
  %.143.in = phi i32 [ %.143, %38 ], [ %2, %.preheader ]
  %.143 = add nsw i32 %.143.in, -1
  %27 = load ptr, ptr %0, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = mul nsw i32 %28, %.143
  %30 = add nsw i32 %29, %2
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %27, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !12
  %34 = tail call double @llvm.fabs.f64(double %33)
  %35 = fcmp olt double %34, 0x10000000000000
  br i1 %35, label %38, label %36

36:                                               ; preds = %.lr.ph44
  %37 = fdiv double %33, %11
  tail call void @subRow(ptr noundef nonnull %0, i32 noundef %.143, i32 noundef %2, double noundef %37)
  tail call void @subRow(ptr noundef %1, i32 noundef %.143, i32 noundef %2, double noundef %37)
  br label %38

38:                                               ; preds = %.lr.ph44, %36
  %39 = icmp ugt i32 %.143.in, 1
  br i1 %39, label %.lr.ph44, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %25, %38, %.preheader38, %.preheader
  ret void
}

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

!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, !7, i64 0}
!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 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass