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

16:                                               ; preds = %3
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tensor, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp sge i32 %17, %20
  br i1 %21, label %22, label %32

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

32:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !13
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %33

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

39:                                               ; preds = %33
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tensor, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = mul nsw i32 %40, %43
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  store i32 %46, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tensor, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = mul nsw i32 %47, %50
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %51, %52
  store i32 %53, ptr %9, align 4, !tbaa !9
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.tensor, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !13
  store double %60, ptr %10, align 8, !tbaa !13
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tensor, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tensor, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  store double %67, ptr %73, align 8, !tbaa !13
  %74 = load double, ptr %10, align 8, !tbaa !13
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.tensor, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !16
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  store double %74, ptr %80, align 8, !tbaa !13
  br label %81

81:                                               ; preds = %39
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %7, align 4, !tbaa !9
  br label %33, !llvm.loop !17

84:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  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 = { 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 = { noreturn nounwind }
attributes #5 = { 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 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !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: nounwind uwtable
define dso_local void @swapRow(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
  %.not28 = icmp sgt i32 %5, %2
  %or.cond = and i1 %.not, %.not28
  br i1 %or.cond, label %.preheader, label %27

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

.lr.ph:                                           ; preds = %.preheader
  %9 = mul nsw i32 %7, %1
  %10 = mul nsw i32 %7, %2
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = sext i32 %9 to i64
  %13 = sext i32 %10 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  %invariant.gep = getelementptr double, ptr %11, i64 %12
  %invariant.gep31 = getelementptr double, ptr %11, i64 %13
  %min.iters.check = icmp ult i32 %7, 14
  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
  %14 = load double, ptr %gep.prol, align 8, !tbaa !13
  %gep32.prol = getelementptr double, ptr %invariant.gep31, i64 %indvars.iv.ph
  %15 = load double, ptr %gep32.prol, align 8, !tbaa !13
  store double %15, ptr %gep.prol, align 8, !tbaa !13
  store double %14, ptr %gep32.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 ]
  %16 = add nsw i64 %wide.trip.count, -1
  %17 = icmp eq i64 %indvars.iv.ph, %16
  br i1 %17, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %18 = add nsw i64 %12, %wide.trip.count
  %19 = shl nsw i64 %18, 3
  %scevgep = getelementptr i8, ptr %11, i64 %19
  %20 = add nsw i64 %13, %wide.trip.count
  %21 = shl nsw i64 %20, 3
  %scevgep33 = getelementptr i8, ptr %11, i64 %21
  %bound0 = icmp ult ptr %invariant.gep, %scevgep33
  %bound1 = icmp ult ptr %invariant.gep31, %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
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = getelementptr double, ptr %invariant.gep, i64 %index
  %23 = getelementptr i8, ptr %22, i64 16
  %wide.load = load <2 x double>, ptr %22, align 8, !tbaa !13, !alias.scope !15, !noalias !18
  %wide.load34 = load <2 x double>, ptr %23, align 8, !tbaa !13, !alias.scope !15, !noalias !18
  %24 = getelementptr double, ptr %invariant.gep31, i64 %index
  %25 = getelementptr i8, ptr %24, i64 16
  %wide.load35 = load <2 x double>, ptr %24, align 8, !tbaa !13, !alias.scope !18
  %wide.load36 = load <2 x double>, ptr %25, align 8, !tbaa !13, !alias.scope !18
  store <2 x double> %wide.load35, ptr %22, align 8, !tbaa !13, !alias.scope !15, !noalias !18
  store <2 x double> %wide.load36, ptr %23, align 8, !tbaa !13, !alias.scope !15, !noalias !18
  store <2 x double> %wide.load, ptr %24, align 8, !tbaa !13, !alias.scope !18
  store <2 x double> %wide.load34, ptr %25, align 8, !tbaa !13, !alias.scope !18
  %index.next = add nuw i64 %index, 4
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, 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

27:                                               ; preds = %3
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23)
  %29 = add nsw i32 %1, 1
  %30 = add nsw i32 %2, 1
  %31 = load i32, ptr %4, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i32 noundef %29, i32 noundef %30, i32 noundef %31)
  tail call void @exit(i32 noundef 0) #3
  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
  %33 = load double, ptr %gep, align 8, !tbaa !13
  %gep32 = getelementptr double, ptr %invariant.gep31, i64 %indvars.iv
  %34 = load double, ptr %gep32, align 8, !tbaa !13
  store double %34, ptr %gep, align 8, !tbaa !13
  store double %33, ptr %gep32, 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
  %35 = load double, ptr %gep.1, align 8, !tbaa !13
  %gep32.1 = getelementptr double, ptr %invariant.gep31, i64 %indvars.iv.next
  %36 = load double, ptr %gep32.1, align 8, !tbaa !13
  store double %36, ptr %gep.1, align 8, !tbaa !13
  store double %35, ptr %gep32.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
}

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 = { 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 = { 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