; LLVM IR from codee-com/open-catalog :: Checks/PWR032 (solution)

; 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 @solution(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 i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  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 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %54, %6
  %17 = load i32, ptr %13, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %57

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = load i32, ptr %13, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = load ptr, ptr %10, align 8, !tbaa !9
  %28 = load i32, ptr %13, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !11
  %32 = fsub float %26, %31
  store float %32, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds float, ptr %33, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !11
  %38 = load ptr, ptr %11, align 8, !tbaa !9
  %39 = load i32, ptr %13, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = fsub float %37, %42
  store float %43, ptr %15, align 4, !tbaa !11
  %44 = load float, ptr %14, align 4, !tbaa !11
  %45 = call float @powf(float noundef %44, float noundef 2.000000e+00) #3
  %46 = load float, ptr %15, align 4, !tbaa !11
  %47 = call float @powf(float noundef %46, float noundef 2.000000e+00) #3
  %48 = fadd float %45, %47
  %49 = call float @sqrtf(float noundef %48) #3
  %50 = load ptr, ptr %12, align 8, !tbaa !9
  %51 = load i32, ptr %13, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  store float %49, ptr %53, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %54

54:                                               ; preds = %21
  %55 = load i32, ptr %13, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %13, align 4, !tbaa !5
  br label %16, !llvm.loop !13

57:                                               ; preds = %20
  ret void
}

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

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

; Function Attrs: nounwind
declare float @powf(float noundef, float noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @solution(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = ptrtoint ptr %4 to i64
  %8 = ptrtoint ptr %2 to i64
  %9 = ptrtoint ptr %3 to i64
  %10 = ptrtoint ptr %1 to i64
  %11 = ptrtoint ptr %5 to i64
  %12 = icmp sgt i32 %0, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %0 to i64
  %min.iters.check = icmp ult i32 %0, 8
  br i1 %min.iters.check, label %.lr.ph.preheader25, label %vector.memcheck

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

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %13 = sub i64 %11, %10
  %diff.check = icmp ult i64 %13, 16
  %14 = sub i64 %11, %9
  %diff.check17 = icmp ult i64 %14, 16
  %conflict.rdx = or i1 %diff.check, %diff.check17
  %15 = sub i64 %11, %8
  %diff.check18 = icmp ult i64 %15, 16
  %conflict.rdx19 = or i1 %conflict.rdx, %diff.check18
  %16 = sub i64 %11, %7
  %diff.check20 = icmp ult i64 %16, 16
  %conflict.rdx21 = or i1 %conflict.rdx19, %diff.check20
  br i1 %conflict.rdx21, label %.lr.ph.preheader25, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = getelementptr inbounds float, ptr %1, i64 %index
  %wide.load = load <4 x float>, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds float, ptr %3, i64 %index
  %wide.load22 = load <4 x float>, ptr %18, align 4, !tbaa !5
  %19 = fsub <4 x float> %wide.load, %wide.load22
  %20 = getelementptr inbounds float, ptr %2, i64 %index
  %wide.load23 = load <4 x float>, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds float, ptr %4, i64 %index
  %wide.load24 = load <4 x float>, ptr %21, align 4, !tbaa !5
  %22 = fsub <4 x float> %wide.load23, %wide.load24
  %23 = fmul <4 x float> %19, %19
  %24 = fmul <4 x float> %22, %22
  %25 = fadd <4 x float> %23, %24
  %26 = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> %25)
  %27 = getelementptr inbounds float, ptr %5, i64 %index
  store <4 x float> %26, ptr %27, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !9

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

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %6
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader25 ]
  %29 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  %32 = load float, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %34 = load float, ptr %33, align 4, !tbaa !5
  %35 = getelementptr inbounds float, ptr %4, i64 %indvars.iv
  %36 = load float, ptr %35, align 4, !tbaa !5
  %37 = insertelement <2 x float> poison, float %30, i64 0
  %38 = insertelement <2 x float> %37, float %34, i64 1
  %39 = insertelement <2 x float> poison, float %32, i64 0
  %40 = insertelement <2 x float> %39, float %36, i64 1
  %41 = fsub <2 x float> %38, %40
  %42 = fmul <2 x float> %41, %41
  %shift = shufflevector <2 x float> %42, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %43 = fadd <2 x float> %42, %shift
  %44 = extractelement <2 x float> %43, i64 0
  %sqrt = tail call float @llvm.sqrt.f32(float %44)
  %45 = getelementptr inbounds float, ptr %5, i64 %indvars.iv
  store float %sqrt, ptr %45, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #1

attributes #0 = { 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 nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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, !11}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass