; LLVM IR from SOHNE/Dura2D :: src/math/d2MatMN.ll (ZN7d2MatMN16SolveGaussSeidelERKS_RK6d2VecN)

; 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.d2VecN = type { i32, ptr }
%struct.d2MatMN = type { i32, i32, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN6d2VecN4ZeroEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2

declare noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2MatMN16SolveGaussSeidelERKS_RK6d2VecN(ptr dead_on_unwind noalias writable sret(%struct.d2VecN) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i1, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.d2VecN, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !12
  store i1 false, ptr %8, align 1
  %18 = load i32, ptr %7, align 4, !tbaa !12
  call void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %18)
  invoke void @_ZN6d2VecN4ZeroEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
          to label %19 unwind label %25

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %90, %19
  %21 = load i32, ptr %11, align 4, !tbaa !12
  %22 = load i32, ptr %7, align 4, !tbaa !12
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %29, label %24

24:                                               ; preds = %20
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %93

25:                                               ; preds = %3
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %9, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %10, align 4
  br label %97

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !12
  br label %30

30:                                               ; preds = %86, %29
  %31 = load i32, ptr %13, align 4, !tbaa !12
  %32 = load i32, ptr %7, align 4, !tbaa !12
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %89

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !12
  %38 = invoke noundef float @_ZNK6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %37)
          to label %39 unwind label %81

39:                                               ; preds = %35
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.d2MatMN, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %13, align 4, !tbaa !12
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.d2VecN, ptr %42, i64 %44
  %46 = load i32, ptr %13, align 4, !tbaa !12
  %47 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %45, i32 noundef %46)
          to label %48 unwind label %81

48:                                               ; preds = %39
  %49 = load float, ptr %47, align 4, !tbaa !15
  %50 = fdiv float %38, %49
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.d2MatMN, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load i32, ptr %13, align 4, !tbaa !12
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.d2VecN, ptr %53, i64 %55
  %57 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %56, ptr noundef nonnull align 8 dereferenceable(16) %0)
          to label %58 unwind label %81

58:                                               ; preds = %48
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.d2MatMN, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i32, ptr %13, align 4, !tbaa !12
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %struct.d2VecN, ptr %61, i64 %63
  %65 = load i32, ptr %13, align 4, !tbaa !12
  %66 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %64, i32 noundef %65)
          to label %67 unwind label %81

67:                                               ; preds = %58
  %68 = load float, ptr %66, align 4, !tbaa !15
  %69 = fdiv float %57, %68
  %70 = fsub float %50, %69
  store float %70, ptr %14, align 4, !tbaa !15
  %71 = load float, ptr %14, align 4, !tbaa !15
  %72 = load float, ptr %14, align 4, !tbaa !15
  %73 = fcmp oeq float %71, %72
  br i1 %73, label %74, label %85

74:                                               ; preds = %67
  %75 = load float, ptr %14, align 4, !tbaa !15
  %76 = load i32, ptr %13, align 4, !tbaa !12
  %77 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %76)
          to label %78 unwind label %81

78:                                               ; preds = %74
  %79 = load float, ptr %77, align 4, !tbaa !15
  %80 = fadd float %79, %75
  store float %80, ptr %77, align 4, !tbaa !15
  br label %85

81:                                               ; preds = %74, %58, %48, %39, %35
  %82 = landingpad { ptr, i32 }
          cleanup
  %83 = extractvalue { ptr, i32 } %82, 0
  store ptr %83, ptr %9, align 8
  %84 = extractvalue { ptr, i32 } %82, 1
  store i32 %84, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %97

85:                                               ; preds = %78, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %13, align 4, !tbaa !12
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %13, align 4, !tbaa !12
  br label %30, !llvm.loop !17

89:                                               ; preds = %34
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %11, align 4, !tbaa !12
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !12
  br label %20, !llvm.loop !19

93:                                               ; preds = %24
  store i1 true, ptr %8, align 1
  store i32 1, ptr %12, align 4
  %94 = load i1, ptr %8, align 1
  br i1 %94, label %96, label %95

95:                                               ; preds = %93
  call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  br label %96

96:                                               ; preds = %95, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void

97:                                               ; preds = %81, %25
  call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %98

98:                                               ; preds = %97
  %99 = load ptr, ptr %9, align 8
  %100 = load i32, ptr %10, align 4
  %101 = insertvalue { ptr, i32 } poison, ptr %99, 0
  %102 = insertvalue { ptr, i32 } %101, i32 %100, 1
  resume { ptr, i32 } %102
}

declare noundef float @_ZNK6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS6d2VecN", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS7d2MatMN", !11, i64 0, !11, i64 4, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !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"

%struct.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

declare void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1

declare void @_ZN6d2VecN4ZeroEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1

declare noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2MatMN16SolveGaussSeidelERKS_RK6d2VecN(ptr dead_on_unwind noalias nonnull writable sret(%struct.d2VecN) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = load i32, ptr %2, align 8, !tbaa !5
  tail call void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %4)
  invoke void @_ZN6d2VecN4ZeroEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
          to label %.preheader29 unwind label %37

.preheader29:                                     ; preds = %3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge32

.preheader.lr.ph:                                 ; preds = %.preheader29
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph
  %.02431.us = phi i32 [ 0, %.preheader.lr.ph ], [ %35, %._crit_edge.us ]
  br label %7

7:                                                ; preds = %.preheader.us, %34
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %34 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = invoke noundef float @_ZNK6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %8)
          to label %10 unwind label %.split.us

10:                                               ; preds = %7
  %11 = load ptr, ptr %6, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.d2VecN, ptr %11, i64 %indvars.iv
  %13 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %12, i32 noundef %8)
          to label %14 unwind label %.split.us

14:                                               ; preds = %10
  %15 = load float, ptr %13, align 4, !tbaa !13
  %16 = fdiv float %9, %15
  %17 = load ptr, ptr %6, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.d2VecN, ptr %17, i64 %indvars.iv
  %19 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %0)
          to label %20 unwind label %.split.us

20:                                               ; preds = %14
  %21 = load ptr, ptr %6, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.d2VecN, ptr %21, i64 %indvars.iv
  %23 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %22, i32 noundef %8)
          to label %24 unwind label %.split.us

24:                                               ; preds = %20
  %25 = load float, ptr %23, align 4, !tbaa !13
  %26 = fdiv float %19, %25
  %27 = fsub float %16, %26
  %28 = fcmp ord float %27, 0.000000e+00
  br i1 %28, label %29, label %34

29:                                               ; preds = %24
  %30 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %8)
          to label %31 unwind label %.split.us

31:                                               ; preds = %29
  %32 = load float, ptr %30, align 4, !tbaa !13
  %33 = fadd float %27, %32
  store float %33, ptr %30, align 4, !tbaa !13
  br label %34

34:                                               ; preds = %31, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !15

._crit_edge.us:                                   ; preds = %34
  %35 = add nuw nsw i32 %.02431.us, 1
  %exitcond34.not = icmp eq i32 %35, %4
  br i1 %exitcond34.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !17

.split.us:                                        ; preds = %29, %20, %14, %10, %7
  %36 = landingpad { ptr, i32 }
          cleanup
  br label %39

37:                                               ; preds = %3
  %38 = landingpad { ptr, i32 }
          cleanup
  br label %39

._crit_edge32:                                    ; preds = %._crit_edge.us, %.preheader29
  ret void

39:                                               ; preds = %.split.us, %37
  %.pn = phi { ptr, i32 } [ %36, %.split.us ], [ %38, %37 ]
  tail call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  resume { ptr, i32 } %.pn
}

declare noundef float @_ZNK6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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 = { mustprogress 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, !7, i64 0}
!6 = !{!"_ZTS6d2VecN", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS7d2MatMN", !7, i64 0, !7, i64 4, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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