; LLVM IR from jgaeddert/liquid-dsp :: src/dotprod/bench (sumsqf_benchmark)

; 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: nounwind uwtable
define dso_local void @sumsqf_bench(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca float, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = mul i64 %14, 20
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = udiv i64 %15, %17
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %18, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ult i64 %21, 1
  br i1 %22, label %23, label %25

23:                                               ; preds = %4
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 1, ptr %24, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %23, %4
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = call ptr @llvm.stacksave.p0()
  store ptr %28, ptr %9, align 8
  %29 = alloca float, i64 %27, align 16
  store i64 %27, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store float 0.000000e+00, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %38, %25
  %31 = load i64, ptr %12, align 8, !tbaa !11
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = icmp ult i64 %31, %33
  br i1 %34, label %35, label %41

35:                                               ; preds = %30
  %36 = load i64, ptr %12, align 8, !tbaa !11
  %37 = getelementptr inbounds float, ptr %29, i64 %36
  store float 1.000000e+00, ptr %37, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %35
  %39 = load i64, ptr %12, align 8, !tbaa !11
  %40 = add i64 %39, 1
  store i64 %40, ptr %12, align 8, !tbaa !11
  br label %30, !llvm.loop !15

41:                                               ; preds = %30
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @getrusage(i32 noundef 0, ptr noundef %42) #5
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %72, %41
  %45 = load i64, ptr %12, align 8, !tbaa !11
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i64, ptr %46, align 8, !tbaa !11
  %48 = icmp ult i64 %45, %47
  br i1 %48, label %49, label %75

49:                                               ; preds = %44
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = call float @liquid_sumsqf(ptr noundef %29, i32 noundef %50)
  %52 = load float, ptr %11, align 4, !tbaa !13
  %53 = fadd float %52, %51
  store float %53, ptr %11, align 4, !tbaa !13
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = call float @liquid_sumsqf(ptr noundef %29, i32 noundef %54)
  %56 = load float, ptr %11, align 4, !tbaa !13
  %57 = fsub float %56, %55
  store float %57, ptr %11, align 4, !tbaa !13
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = call float @liquid_sumsqf(ptr noundef %29, i32 noundef %58)
  %60 = load float, ptr %11, align 4, !tbaa !13
  %61 = fadd float %60, %59
  store float %61, ptr %11, align 4, !tbaa !13
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = call float @liquid_sumsqf(ptr noundef %29, i32 noundef %62)
  %64 = load float, ptr %11, align 4, !tbaa !13
  %65 = fsub float %64, %63
  store float %65, ptr %11, align 4, !tbaa !13
  %66 = load float, ptr %11, align 4, !tbaa !13
  %67 = load i64, ptr %12, align 8, !tbaa !11
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = urem i64 %67, %69
  %71 = getelementptr inbounds float, ptr %29, i64 %70
  store float %66, ptr %71, align 4, !tbaa !13
  br label %72

72:                                               ; preds = %49
  %73 = load i64, ptr %12, align 8, !tbaa !11
  %74 = add i64 %73, 1
  store i64 %74, ptr %12, align 8, !tbaa !11
  br label %44, !llvm.loop !17

75:                                               ; preds = %44
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = call i32 @getrusage(i32 noundef 0, ptr noundef %76) #5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load i64, ptr %78, align 8, !tbaa !11
  %80 = mul i64 %79, 4
  store i64 %80, ptr %78, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %81 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %81)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) #3

declare float @liquid_sumsqf(ptr noundef, i32 noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { "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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: nounwind uwtable
define dso_local void @sumsqf_bench(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = mul i64 %5, 20
  %7 = zext i32 %3 to i64
  %8 = udiv i64 %6, %7
  %9 = icmp ult i64 %6, %7
  %spec.select = select i1 %9, i64 1, i64 %8
  store i64 %spec.select, ptr %2, align 8, !tbaa !5
  %10 = alloca float, i64 %7, align 16
  %umax = tail call i64 @llvm.umax.i64(i64 %7, i64 1)
  %min.iters.check = icmp ult i32 %3, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %4
  %n.vec = and i64 %umax, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %11 = getelementptr inbounds float, ptr %10, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, ptr %11, align 16, !tbaa !9
  store <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, ptr %12, align 16, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %7
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %4
  %.029.ph = phi i64 [ 0, %4 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.029 = phi i64 [ %15, %scalar.ph ], [ %.029.ph, %scalar.ph.preheader ]
  %14 = getelementptr inbounds float, ptr %10, i64 %.029
  store float 1.000000e+00, ptr %14, align 4, !tbaa !9
  %15 = add nuw nsw i64 %.029, 1
  %exitcond.not = icmp eq i64 %15, %umax
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %16 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #4
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.loopexit, %.lr.ph
  %.131 = phi i64 [ %28, %.lr.ph ], [ 0, %.loopexit ]
  %.02730 = phi float [ %25, %.lr.ph ], [ 0.000000e+00, %.loopexit ]
  %18 = call float @liquid_sumsqf(ptr noundef nonnull %10, i32 noundef %3) #4
  %19 = fadd float %.02730, %18
  %20 = call float @liquid_sumsqf(ptr noundef nonnull %10, i32 noundef %3) #4
  %21 = fsub float %19, %20
  %22 = call float @liquid_sumsqf(ptr noundef nonnull %10, i32 noundef %3) #4
  %23 = fadd float %21, %22
  %24 = call float @liquid_sumsqf(ptr noundef nonnull %10, i32 noundef %3) #4
  %25 = fsub float %23, %24
  %26 = urem i64 %.131, %7
  %27 = getelementptr inbounds float, ptr %10, i64 %26
  store float %25, ptr %27, align 4, !tbaa !9
  %28 = add nuw i64 %.131, 1
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.loopexit
  %31 = call i32 @getrusage(i32 noundef 0, ptr noundef %1) #4
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = shl i64 %32, 2
  store i64 %33, ptr %2, align 8, !tbaa !5
  ret void
}

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #1

declare float @liquid_sumsqf(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

attributes #0 = { 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 #1 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}
!16 = distinct !{!16, !12}


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