; LLVM IR from sympiler/nasoq :: src/triangularSolve/BLAS.ll (ZN5nasoq21lSolve_dense_col_syncEiiPdS0_)

; 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"

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN5nasoq21lSolve_dense_col_syncEiiPdS0_(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %68, %4
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %71

18:                                               ; preds = %13
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = mul nsw i32 %20, %21
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %19, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = fdiv double %32, %27
  store double %33, ptr %31, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %11, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %64, %18
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %67

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %42, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = fmul double %50, %55
  store double %56, ptr %12, align 8, !tbaa !11
  %57 = load double, ptr %12, align 8, !tbaa !11
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %58, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = fsub double %62, %57
  store double %63, ptr %61, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %64

64:                                               ; preds = %41
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %11, align 4, !tbaa !5
  br label %36, !llvm.loop !13

67:                                               ; preds = %40
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %9, align 4, !tbaa !5
  br label %13, !llvm.loop !15

71:                                               ; preds = %17
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN5nasoq21lSolve_dense_col_syncEiiPdS0_(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph25.preheader, label %._crit_edge

.lr.ph25.preheader:                               ; preds = %4
  %6 = sext i32 %0 to i64
  %7 = zext nneg i32 %1 to i64
  %wide.trip.count32 = zext nneg i32 %1 to i64
  %8 = shl nuw nsw i64 %wide.trip.count32, 3
  %scevgep34 = getelementptr i8, ptr %3, i64 %8
  %9 = shl nsw i64 %6, 3
  %10 = add nsw i64 %9, 8
  %11 = shl nsw i64 %6, 3
  %invariant.gep43 = getelementptr i8, ptr %3, i64 8
  %invariant.gep45 = getelementptr i8, ptr %2, i64 8
  %12 = getelementptr i8, ptr %2, i64 %8
  %13 = add nsw i64 %wide.trip.count32, -1
  br label %.lr.ph25

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %.lr.ph25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count32
  br i1 %exitcond33.not, label %._crit_edge, label %.lr.ph25, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit, %4
  ret void

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %.loopexit
  %indvars.iv29 = phi i64 [ 0, %.lr.ph25.preheader ], [ %indvars.iv.next30, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph25.preheader ], [ %indvars.iv.next, %.loopexit ]
  %14 = xor i64 %indvars.iv29, -1
  %15 = add nsw i64 %14, %wide.trip.count32
  %16 = shl nuw nsw i64 %indvars.iv29, 3
  %gep44 = getelementptr i8, ptr %invariant.gep43, i64 %16
  %17 = mul i64 %10, %indvars.iv29
  %gep46 = getelementptr i8, ptr %invariant.gep45, i64 %17
  %18 = mul i64 %11, %indvars.iv29
  %scevgep36 = getelementptr i8, ptr %12, i64 %18
  %indvars31 = trunc i64 %indvars.iv29 to i32
  %19 = mul nsw i32 %indvars31, %0
  %20 = sext i32 %19 to i64
  %21 = getelementptr double, ptr %2, i64 %indvars.iv29
  %22 = getelementptr double, ptr %21, i64 %20
  %23 = load double, ptr %22, align 8, !tbaa !7
  %24 = getelementptr inbounds double, ptr %3, i64 %indvars.iv29
  %25 = load double, ptr %24, align 8, !tbaa !7
  %26 = fdiv double %25, %23
  store double %26, ptr %24, align 8, !tbaa !7
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %27 = icmp ult i64 %indvars.iv.next30, %7
  br i1 %27, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.lr.ph25
  %28 = mul nsw i64 %indvars.iv29, %6
  %invariant.gep = getelementptr double, ptr %2, i64 %28
  %min.iters.check = icmp ult i64 %15, 4
  br i1 %min.iters.check, label %.lr.ph.preheader42, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %bound0 = icmp ult ptr %gep44, %scevgep36
  %bound1 = icmp ult ptr %gep46, %scevgep34
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader42, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %15, -4
  %ind.end = add i64 %indvars.iv, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %indvars.iv, %index
  %29 = getelementptr double, ptr %invariant.gep, i64 %offset.idx
  %30 = getelementptr i8, ptr %29, i64 16
  %wide.load = load <2 x double>, ptr %29, align 8, !tbaa !7, !alias.scope !11
  %wide.load37 = load <2 x double>, ptr %30, align 8, !tbaa !7, !alias.scope !11
  %31 = load double, ptr %24, align 8, !tbaa !7, !alias.scope !14
  %broadcast.splatinsert38 = insertelement <2 x double> poison, double %31, i64 0
  %broadcast.splat39 = shufflevector <2 x double> %broadcast.splatinsert38, <2 x double> poison, <2 x i32> zeroinitializer
  %32 = fmul <2 x double> %wide.load, %broadcast.splat39
  %33 = fmul <2 x double> %wide.load37, %broadcast.splat39
  %34 = getelementptr inbounds double, ptr %3, i64 %offset.idx
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %wide.load40 = load <2 x double>, ptr %34, align 8, !tbaa !7, !alias.scope !16, !noalias !11
  %wide.load41 = load <2 x double>, ptr %35, align 8, !tbaa !7, !alias.scope !16, !noalias !11
  %36 = fsub <2 x double> %wide.load40, %32
  %37 = fsub <2 x double> %wide.load41, %33
  store <2 x double> %36, ptr %34, align 8, !tbaa !7, !alias.scope !16, !noalias !11
  store <2 x double> %37, ptr %35, align 8, !tbaa !7, !alias.scope !16, !noalias !11
  %index.next = add nuw i64 %index, 4
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %15, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader42

.lr.ph.preheader42:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv26.ph = phi i64 [ %indvars.iv, %vector.memcheck ], [ %indvars.iv, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %39 = sub i64 %wide.trip.count32, %indvars.iv26.ph
  %xtraiter = and i64 %39, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader42
  %gep.prol = getelementptr double, ptr %invariant.gep, i64 %indvars.iv26.ph
  %40 = load double, ptr %gep.prol, align 8, !tbaa !7
  %41 = load double, ptr %24, align 8, !tbaa !7
  %42 = fmul double %40, %41
  %43 = getelementptr inbounds double, ptr %3, i64 %indvars.iv26.ph
  %44 = load double, ptr %43, align 8, !tbaa !7
  %45 = fsub double %44, %42
  store double %45, ptr %43, align 8, !tbaa !7
  %indvars.iv.next27.prol = add nuw nsw i64 %indvars.iv26.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader42
  %indvars.iv26.unr = phi i64 [ %indvars.iv26.ph, %.lr.ph.preheader42 ], [ %indvars.iv.next27.prol, %.lr.ph.prol ]
  %46 = icmp eq i64 %indvars.iv26.ph, %13
  br i1 %46, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv26 = phi i64 [ %indvars.iv.next27.1, %.lr.ph ], [ %indvars.iv26.unr, %.lr.ph.prol.loopexit ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv26
  %47 = load double, ptr %gep, align 8, !tbaa !7
  %48 = load double, ptr %24, align 8, !tbaa !7
  %49 = fmul double %47, %48
  %50 = getelementptr inbounds double, ptr %3, i64 %indvars.iv26
  %51 = load double, ptr %50, align 8, !tbaa !7
  %52 = fsub double %51, %49
  store double %52, ptr %50, align 8, !tbaa !7
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %gep.1 = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.next27
  %53 = load double, ptr %gep.1, align 8, !tbaa !7
  %54 = load double, ptr %24, align 8, !tbaa !7
  %55 = fmul double %53, %54
  %56 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next27
  %57 = load double, ptr %56, align 8, !tbaa !7
  %58 = fsub double %57, %55
  store double %58, ptr %56, align 8, !tbaa !7
  %indvars.iv.next27.1 = add nuw nsw i64 %indvars.iv26, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next27.1, %wide.trip.count32
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph, !llvm.loop !21
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = !{!17}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !6, !19, !20}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !6, !19}


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