; LLVM IR from sympiler/nasoq :: src/common/Util.ll (ZN5nasoq30rhsInit_linearSolver_onlylowerEiPiS0_PdS1_)

; 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 noundef zeroext i1 @_ZN5nasoq30rhsInit_linearSolver_onlylowerEiPiS0_PdS1_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %25, %5
  %16 = load i32, ptr %11, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %28

20:                                               ; preds = %15
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  store double 0.000000e+00, ptr %24, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %11, align 4, !tbaa !5
  br label %15, !llvm.loop !13

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

29:                                               ; preds = %90, %28
  %30 = load i32, ptr %12, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %14, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %86, %34
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %42, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp slt i32 %41, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %40
  store i32 8, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %89

50:                                               ; preds = %40
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = load i32, ptr %14, 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 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load i32, ptr %14, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %56, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = fadd double %64, %55
  store double %65, ptr %63, align 8, !tbaa !11
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = load i32, ptr %14, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = icmp ne i32 %70, %71
  br i1 %72, label %73, label %85

73:                                               ; preds = %50
  %74 = load ptr, ptr %9, align 8, !tbaa !9
  %75 = load i32, ptr %14, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %74, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = load i32, ptr %12, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %79, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = fadd double %83, %78
  store double %84, ptr %82, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %73, %50
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %14, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %14, align 4, !tbaa !5
  br label %40, !llvm.loop !15

89:                                               ; preds = %49
  br label %90

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

93:                                               ; preds = %33
  ret i1 true
}

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}
!16 = distinct !{!16, !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 noundef zeroext i1 @_ZN5nasoq30rhsInit_linearSolver_onlylowerEiPiS0_PdS1_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %0, 0
  br i1 %6, label %.lr.ph32.preheader, label %._crit_edge

.lr.ph32.preheader:                               ; preds = %5
  %7 = zext nneg i32 %0 to i64
  %8 = shl nuw nsw i64 %7, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 %8, i1 false), !tbaa !5
  %wide.trip.count38 = zext nneg i32 %0 to i64
  %.pre = load i32, ptr %1, align 4, !tbaa !9
  br label %.lr.ph32

.loopexit:                                        ; preds = %29, %.lr.ph32
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %5
  ret i1 true

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.loopexit
  %9 = phi i32 [ %.pre, %.lr.ph32.preheader ], [ %11, %.loopexit ]
  %indvars.iv35 = phi i64 [ 0, %.lr.ph32.preheader ], [ %indvars.iv.next36, %.loopexit ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %10 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next36
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %.lr.ph32
  %13 = getelementptr inbounds double, ptr %4, i64 %indvars.iv35
  %14 = sext i32 %9 to i64
  %wide.trip.count = sext i32 %11 to i64
  br label %15

15:                                               ; preds = %.lr.ph30, %29
  %indvars.iv = phi i64 [ %14, %.lr.ph30 ], [ %indvars.iv.next, %29 ]
  %16 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %4, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fadd double %17, %22
  store double %23, ptr %21, align 8, !tbaa !5
  %24 = zext i32 %19 to i64
  %.not = icmp eq i64 %indvars.iv35, %24
  br i1 %.not, label %29, label %25

25:                                               ; preds = %15
  %26 = load double, ptr %16, align 8, !tbaa !5
  %27 = load double, ptr %13, align 8, !tbaa !5
  %28 = fadd double %26, %27
  store double %28, ptr %13, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %15, %25
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %15, !llvm.loop !13
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass