; 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 @eliminationStage1(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 %66

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

29:                                               ; preds = %62, %26
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tensor, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %35, label %65

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

52:                                               ; preds = %35
  br label %62

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

62:                                               ; preds = %53, %52
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !17

65:                                               ; preds = %29
  br label %109

66:                                               ; preds = %3
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %105, %66
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.tensor, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 8, !tbaa !16
  %74 = icmp slt i32 %70, %73
  br i1 %74, label %75, label %108

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

92:                                               ; preds = %75
  br label %105

93:                                               ; preds = %75
  %94 = load double, ptr %9, align 8, !tbaa !11
  %95 = load double, ptr %8, align 8, !tbaa !11
  %96 = fdiv double %95, %94
  store double %96, ptr %8, align 8, !tbaa !11
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load i32, ptr %7, align 4, !tbaa !9
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %97, i32 noundef %98, i32 noundef %99, double noundef %100)
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = load i32, ptr %7, align 4, !tbaa !9
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = load double, ptr %8, align 8, !tbaa !11
  call void @subRow(ptr noundef %101, i32 noundef %102, i32 noundef %103, double noundef %104)
  br label %105

105:                                              ; preds = %93, %92
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %7, align 4, !tbaa !9
  br label %69, !llvm.loop !19

108:                                              ; preds = %69
  br label %109

109:                                              ; preds = %108, %65
  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 = !{!14, !10, i64 8}
!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: 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 @eliminationStage1(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 = getelementptr inbounds i8, ptr %0, i64 8
  %.144 = add nsw i32 %2, 1
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = icmp slt i32 %.144, %15
  br i1 %13, label %.preheader, label %.preheader40

.preheader40:                                     ; preds = %3
  br i1 %16, label %.lr.ph, label %.loopexit

.preheader:                                       ; preds = %3
  br i1 %16, label %.lr.ph46, label %.loopexit

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

27:                                               ; preds = %.lr.ph
  tail call void @subRow(ptr noundef nonnull %0, i32 noundef %.043, i32 noundef %2, double noundef %24)
  tail call void @subRow(ptr noundef %1, i32 noundef %.043, i32 noundef %2, double noundef %24)
  %.pre = load i32, ptr %14, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %.lr.ph, %27
  %29 = phi i32 [ %17, %.lr.ph ], [ %.pre, %27 ]
  %.0 = add nsw i32 %.043, 1
  %30 = icmp slt i32 %.0, %29
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !15

.lr.ph46:                                         ; preds = %.preheader, %43
  %31 = phi i32 [ %44, %43 ], [ %15, %.preheader ]
  %.145 = phi i32 [ %.1, %43 ], [ %.144, %.preheader ]
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = mul nsw i32 %33, %.145
  %35 = add nsw i32 %34, %2
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %32, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !12
  %39 = tail call double @llvm.fabs.f64(double %38)
  %40 = fcmp olt double %39, 0x10000000000000
  br i1 %40, label %43, label %41

41:                                               ; preds = %.lr.ph46
  %42 = fdiv double %38, %11
  tail call void @subRow(ptr noundef nonnull %0, i32 noundef %.145, i32 noundef %2, double noundef %42)
  tail call void @subRow(ptr noundef %1, i32 noundef %.145, i32 noundef %2, double noundef %42)
  %.pre48 = load i32, ptr %14, align 8, !tbaa !14
  br label %43

43:                                               ; preds = %.lr.ph46, %41
  %44 = phi i32 [ %31, %.lr.ph46 ], [ %.pre48, %41 ]
  %.1 = add nsw i32 %.145, 1
  %45 = icmp slt i32 %.1, %44
  br i1 %45, label %.lr.ph46, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %28, %43, %.preheader40, %.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 = !{!6, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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