; LLVM IR from sympiler/nasoq :: src/common/Norm.ll (ZN5nasoq9precisionEiPmPiPdS2_S2_)

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

@__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.alp = external hidden unnamed_addr constant [2 x double], align 16
@__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.bet = external hidden unnamed_addr constant [2 x double], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN5nasoq9precisionEiPmPiPdS2_S2_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca [2 x double], align 16
  %15 = alloca [2 x double], align 16
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  store double 0.000000e+00, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %14, ptr align 16 @__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.alp, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %15, ptr align 16 @__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.bet, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %21, i64 8)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = extractvalue { i64, i1 } %22, 0
  %25 = select i1 %23, i64 -1, i64 %24
  %26 = call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #8
  store ptr %26, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %43, %6
  %28 = load i32, ptr %17, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  br label %46

32:                                               ; preds = %27
  %33 = load ptr, ptr %12, align 8, !tbaa !9
  %34 = load i32, ptr %17, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = fneg double %37
  %39 = load ptr, ptr %16, align 8, !tbaa !9
  %40 = load i32, ptr %17, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  store double %38, ptr %42, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %32
  %44 = load i32, ptr %17, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %17, align 4, !tbaa !5
  br label %27, !llvm.loop !13

46:                                               ; preds = %31
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = getelementptr inbounds [2 x double], ptr %14, i64 0, i64 0
  %52 = getelementptr inbounds [2 x double], ptr %15, i64 0, i64 0
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = load ptr, ptr %16, align 8, !tbaa !9
  call void @_ZN5nasoq12spmv_csc_symEiPmPiPdiS2_S2_iS2_S2_(i32 noundef %47, ptr noundef %48, ptr noundef %49, ptr noundef %50, i32 noundef -1, ptr noundef %51, ptr noundef %52, i32 noundef 1, ptr noundef %53, ptr noundef %54)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #7
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load ptr, ptr %16, align 8, !tbaa !9
  %57 = call noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef %55, i32 noundef 1, ptr noundef %56, i32 noundef 2)
  store double %57, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #7
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load ptr, ptr %12, align 8, !tbaa !9
  %60 = call noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef %58, i32 noundef 1, ptr noundef %59, i32 noundef 2)
  store double %60, ptr %19, align 8, !tbaa !11
  %61 = load double, ptr %18, align 8, !tbaa !11
  %62 = load double, ptr %19, align 8, !tbaa !11
  %63 = fdiv double %61, %62
  store double %63, ptr %13, align 8, !tbaa !11
  %64 = load ptr, ptr %16, align 8, !tbaa !9
  %65 = icmp eq ptr %64, null
  br i1 %65, label %67, label %66

66:                                               ; preds = %46
  call void @_ZdaPv(ptr noundef %64) #9
  br label %67

67:                                               ; preds = %66, %46
  %68 = load double, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  ret double %68
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

declare void @_ZN5nasoq12spmv_csc_symEiPmPiPdiS2_S2_iS2_S2_(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #6

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 = { nobuiltin 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { "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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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"}


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

@__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.alp = external hidden unnamed_addr constant [2 x double], align 16
@__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.bet = external hidden unnamed_addr constant [2 x double], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN5nasoq9precisionEiPmPiPdS2_S2_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = alloca [2 x double], align 16
  %8 = alloca [2 x double], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %7, ptr noundef nonnull align 16 dereferenceable(16) @__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.alp, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %8, ptr noundef nonnull align 16 dereferenceable(16) @__const._ZN5nasoq9precisionEiPmPiPdS2_S2_.bet, i64 16, i1 false)
  %9 = zext i32 %0 to i64
  %10 = icmp slt i32 %0, 0
  %11 = shl nuw nsw i64 %9, 3
  %12 = select i1 %10, i64 -1, i64 %11
  %13 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %12) #7
  %14 = icmp sgt i32 %0, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %min.iters.check = icmp ult i32 %0, 4
  br i1 %min.iters.check, label %.lr.ph.preheader25, label %vector.ph

.lr.ph.preheader25:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %9, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds double, ptr %5, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %wide.load = load <2 x double>, ptr %15, align 8, !tbaa !5
  %wide.load24 = load <2 x double>, ptr %16, align 8, !tbaa !5
  %17 = fneg <2 x double> %wide.load
  %18 = fneg <2 x double> %wide.load24
  %19 = getelementptr inbounds double, ptr %13, i64 %index
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store <2 x double> %17, ptr %19, align 8, !tbaa !5
  store <2 x double> %18, ptr %20, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %9
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader25

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %6
  call void @_ZN5nasoq12spmv_csc_symEiPmPiPdiS2_S2_iS2_S2_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef -1, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef 1, ptr noundef %4, ptr noundef nonnull %13)
  %22 = call noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef %0, i32 noundef 1, ptr noundef nonnull %13, i32 noundef 2)
  %23 = call noundef double @_ZN5nasoq10norm_denseEiiPdi(i32 noundef %0, i32 noundef 1, ptr noundef %5, i32 noundef 2)
  call void @_ZdaPv(ptr noundef nonnull %13) #8
  %24 = fdiv double %22, %23
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #6
  ret double %24

.lr.ph:                                           ; preds = %.lr.ph.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader25 ]
  %25 = getelementptr inbounds double, ptr %5, i64 %indvars.iv
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fneg double %26
  %28 = getelementptr inbounds double, ptr %13, i64 %indvars.iv
  store double %27, ptr %28, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare void @_ZN5nasoq12spmv_csc_symEiPmPiPdiS2_S2_iS2_S2_(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 = { nobuiltin 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass