; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (lsqe)

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

16:                                               ; preds = %55, %5
  %17 = load i32, ptr %15, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %58

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

55:                                               ; preds = %20
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %15, align 4, !tbaa !9
  br label %16, !llvm.loop !13

58:                                               ; preds = %16
  %59 = load double, ptr %14, align 8, !tbaa !11
  %60 = load double, ptr %11, align 8, !tbaa !11
  %61 = load double, ptr %12, align 8, !tbaa !11
  %62 = fmul double %60, %61
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = sitofp i32 %63 to double
  %65 = fdiv double %62, %64
  %66 = fsub double %59, %65
  %67 = load double, ptr %13, align 8, !tbaa !11
  %68 = load double, ptr %11, align 8, !tbaa !11
  %69 = call double @pow(double noundef %68, double noundef 2.000000e+00) #4
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = sitofp i32 %70 to double
  %72 = fdiv double %69, %71
  %73 = fsub double %67, %72
  %74 = fdiv double %66, %73
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store double %74, ptr %75, align 8, !tbaa !11
  %76 = load double, ptr %12, align 8, !tbaa !11
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = load double, ptr %11, align 8, !tbaa !11
  %80 = fneg double %78
  %81 = call double @llvm.fmuladd.f64(double %80, double %79, double %76)
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = sitofp i32 %82 to double
  %84 = fdiv double %81, %83
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  store double %84, ptr %85, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  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 double @pow(double noundef, double noundef) #2

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

; 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 = { 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 = !{!"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 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @lsqe(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %2, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %2, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02938 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %.03037 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %8 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %9 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = insertelement <2 x double> poison, double %12, i64 0
  %14 = insertelement <2 x double> %13, double %10, i64 1
  %15 = fadd <2 x double> %8, %14
  %square34 = fmul double %10, %10
  %16 = fadd double %.03037, %square34
  %17 = tail call double @llvm.fmuladd.f64(double %10, double %12, double %.02938)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = insertelement <2 x double> poison, double %21, i64 0
  %23 = insertelement <2 x double> %22, double %19, i64 1
  %24 = fadd <2 x double> %15, %23
  %square34.1 = fmul double %19, %19
  %25 = fadd double %16, %square34.1
  %26 = tail call double @llvm.fmuladd.f64(double %19, double %21, double %17)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph
  %27 = insertelement <2 x double> poison, double %26, i64 0
  %28 = insertelement <2 x double> %27, double %25, i64 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa53.ph = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %24, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.lcssa.ph = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %28, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.02938.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %26, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.03037.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %25, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %24, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %29 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = insertelement <2 x double> poison, double %32, i64 0
  %34 = insertelement <2 x double> %33, double %30, i64 1
  %35 = fadd <2 x double> %.unr, %34
  %square34.epil = fmul double %30, %30
  %36 = fadd double %.03037.unr, %square34.epil
  %37 = tail call double @llvm.fmuladd.f64(double %30, double %32, double %.02938.unr)
  %38 = insertelement <2 x double> poison, double %37, i64 0
  %39 = insertelement <2 x double> %38, double %36, i64 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %5
  %40 = phi <2 x double> [ zeroinitializer, %5 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %39, %.lr.ph.epil ]
  %41 = phi <2 x double> [ zeroinitializer, %5 ], [ %.lcssa53.ph, %._crit_edge.loopexit.unr-lcssa ], [ %35, %.lr.ph.epil ]
  %42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> <i32 1, i32 1>
  %43 = fmul <2 x double> %42, %41
  %44 = sitofp i32 %2 to double
  %45 = insertelement <2 x double> poison, double %44, i64 0
  %46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> zeroinitializer
  %47 = fdiv <2 x double> %43, %46
  %48 = fsub <2 x double> %40, %47
  %49 = extractelement <2 x double> %48, i64 0
  %50 = extractelement <2 x double> %48, i64 1
  %51 = fdiv double %49, %50
  store double %51, ptr %3, align 8, !tbaa !5
  %52 = fneg double %51
  %53 = extractelement <2 x double> %41, i64 0
  %54 = extractelement <2 x double> %41, i64 1
  %55 = tail call double @llvm.fmuladd.f64(double %52, double %54, double %53)
  %56 = fdiv double %55, %44
  store double %56, ptr %4, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass