; LLVM IR from sympiler/nasoq :: src/common/Util.ll (ZN5nasoq7rhsInitEiPiS0_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 void @_ZN5nasoq7rhsInitEiPiS0_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 = %70, %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 %73

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 = %66, %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 %69

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
  br label %66

66:                                               ; preds = %50
  %67 = load i32, ptr %14, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %14, align 4, !tbaa !5
  br label %40, !llvm.loop !15

69:                                               ; preds = %49
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %12, align 4, !tbaa !5
  br label %29, !llvm.loop !16

73:                                               ; preds = %33
  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}
!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 void @_ZN5nasoq7rhsInitEiPiS0_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.ph25.preheader, label %._crit_edge

.lr.ph25.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.count31 = zext nneg i32 %0 to i64
  %.pre = load i32, ptr %1, align 4, !tbaa !9
  br label %.lr.ph25

.loopexit:                                        ; preds = %.lr.ph23.prol.loopexit, %.lr.ph23, %.lr.ph25
  %exitcond32.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count31
  br i1 %exitcond32.not, label %._crit_edge, label %.lr.ph25, !llvm.loop !11

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

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

.lr.ph23.preheader:                               ; preds = %.lr.ph25
  %13 = sext i32 %9 to i64
  %wide.trip.count = sext i32 %11 to i64
  %14 = sub nsw i64 %wide.trip.count, %13
  %xtraiter = and i64 %14, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph23.prol.loopexit, label %.lr.ph23.prol

.lr.ph23.prol:                                    ; preds = %.lr.ph23.preheader
  %15 = getelementptr inbounds double, ptr %3, i64 %13
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %2, i64 %13
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %4, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fadd double %16, %21
  store double %22, ptr %20, align 8, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %13, 1
  br label %.lr.ph23.prol.loopexit

.lr.ph23.prol.loopexit:                           ; preds = %.lr.ph23.prol, %.lr.ph23.preheader
  %indvars.iv.unr = phi i64 [ %13, %.lr.ph23.preheader ], [ %indvars.iv.next.prol, %.lr.ph23.prol ]
  %23 = add nsw i64 %wide.trip.count, -1
  %24 = icmp eq i64 %23, %13
  br i1 %24, label %.loopexit, label %.lr.ph23

.lr.ph23:                                         ; preds = %.lr.ph23.prol.loopexit, %.lr.ph23
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph23 ], [ %indvars.iv.unr, %.lr.ph23.prol.loopexit ]
  %25 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %4, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fadd double %26, %31
  store double %32, ptr %30, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %33 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %4, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = fadd double %34, %39
  store double %40, ptr %38, align 8, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph23, !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