; 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.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [2 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: nounwind uwtable
define dso_local void @printTensor(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.tensor, ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %15, label %10

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tensor, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %10, %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.tensor, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tensor, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i32 noundef %18, i32 noundef %21)
  store i32 1, ptr %5, align 4
  br label %70

23:                                               ; preds = %10
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tensor, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tensor, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i32 noundef %26, i32 noundef %29)
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %65, %23
  %33 = load i32, ptr %3, align 4, !tbaa !13
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tensor, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = icmp slt i32 %33, %36
  br i1 %37, label %38, label %68

38:                                               ; preds = %32
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %39

39:                                               ; preds = %60, %38
  %40 = load i32, ptr %4, align 4, !tbaa !13
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tensor, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %45, label %63

45:                                               ; preds = %39
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tensor, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load i32, ptr %3, align 4, !tbaa !13
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.tensor, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !12
  %53 = mul nsw i32 %49, %52
  %54 = load i32, ptr %4, align 4, !tbaa !13
  %55 = add nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %48, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !15
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, double noundef %58)
  br label %60

60:                                               ; preds = %45
  %61 = load i32, ptr %4, align 4, !tbaa !13
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !13
  br label %39, !llvm.loop !17

63:                                               ; preds = %39
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  br label %65

65:                                               ; preds = %63
  %66 = load i32, ptr %3, align 4, !tbaa !13
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %3, align 4, !tbaa !13
  br label %32, !llvm.loop !19

68:                                               ; preds = %32
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  store i32 0, ptr %5, align 4
  br label %70

70:                                               ; preds = %68, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %71 = load i32, ptr %5, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

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 = { 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, !11, i64 8}
!10 = !{!"tensor", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, 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.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @printTensor(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 12
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  br i1 %4, label %._crit_edge22, label %5

5:                                                ; preds = %1
  %6 = icmp eq i32 %.pre, 0
  br i1 %6, label %._crit_edge22, label %9

._crit_edge22:                                    ; preds = %1, %5
  %7 = phi i32 [ 0, %5 ], [ %.pre, %1 ]
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i32 noundef %3, i32 noundef %7)
  br label %32

9:                                                ; preds = %5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, i32 noundef %3, i32 noundef %.pre)
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %12 = load i32, ptr %2, align 8, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader, label %._crit_edge21

.preheader:                                       ; preds = %9, %._crit_edge
  %.01520 = phi i32 [ %28, %._crit_edge ], [ 0, %9 ]
  %14 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %16 = phi i32 [ %25, %.lr.ph ], [ %14, %.preheader ]
  %.019 = phi i32 [ %24, %.lr.ph ], [ 0, %.preheader ]
  %17 = load ptr, ptr %0, align 8, !tbaa !12
  %18 = mul nsw i32 %16, %.01520
  %19 = add nsw i32 %18, %.019
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %17, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !13
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, double noundef %22)
  %24 = add nuw nsw i32 %.019, 1
  %25 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  %28 = add nuw nsw i32 %.01520, 1
  %29 = load i32, ptr %2, align 8, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %.preheader, label %._crit_edge21, !llvm.loop !17

._crit_edge21:                                    ; preds = %._crit_edge, %9
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  br label %32

32:                                               ; preds = %._crit_edge21, %._crit_edge22
  ret void
}

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 = { 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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass