; LLVM IR from PymZoR/S-curve-Planner :: lib (bbpr)

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @deflate(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds double, ptr %14, i64 1
  %16 = load double, ptr %15, align 8, !tbaa !11
  store double %16, ptr %11, align 8, !tbaa !11
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds double, ptr %17, i64 0
  %19 = load double, ptr %18, align 8, !tbaa !11
  store double %19, ptr %12, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 1
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load double, ptr %11, align 8, !tbaa !11
  %24 = fsub double %22, %23
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i64 1
  store double %24, ptr %26, align 8, !tbaa !11
  store i32 2, ptr %13, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %59, %5
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %31, label %62

31:                                               ; preds = %27
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load double, ptr %11, align 8, !tbaa !11
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %38, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = fneg double %37
  %45 = call double @llvm.fmuladd.f64(double %44, double %43, double %36)
  %46 = load double, ptr %12, align 8, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 2
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %47, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = fneg double %46
  %54 = call double @llvm.fmuladd.f64(double %53, double %52, double %45)
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  store double %54, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %31
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %13, align 4, !tbaa !9
  br label %27, !llvm.loop !13

62:                                               ; preds = %27
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = call double @llvm.fabs.f64(double %67)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %69, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = call double @llvm.fabs.f64(double %74)
  %76 = fadd double %68, %75
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  store double %76, ptr %77, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @deflate(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fsub double %10, %7
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  store double %11, ptr %12, align 8, !tbaa !5
  %.not23 = icmp slt i32 %1, 2
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %13 = fneg double %7
  %14 = fneg double %8
  %15 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %15 to i64
  %scevgep = getelementptr i8, ptr %2, i64 8
  %load_initial = load double, ptr %scevgep, align 8
  %xtraiter = and i64 %wide.trip.count, 1
  %16 = icmp eq i32 %15, 3
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %17 = and i64 %wide.trip.count, 4294967294
  %18 = add nsw i64 %17, -4
  br label %19

19:                                               ; preds = %19, %.lr.ph.new
  %store_forwarded = phi double [ %load_initial, %.lr.ph.new ], [ %33, %19 ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.new ], [ %indvars.iv.next.1, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %19 ]
  %20 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = getelementptr double, ptr %2, i64 %indvars.iv
  %23 = tail call double @llvm.fmuladd.f64(double %13, double %store_forwarded, double %21)
  %24 = getelementptr i8, ptr %22, i64 -16
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = tail call double @llvm.fmuladd.f64(double %14, double %25, double %23)
  store double %26, ptr %22, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = getelementptr double, ptr %2, i64 %indvars.iv.next
  %30 = tail call double @llvm.fmuladd.f64(double %13, double %26, double %28)
  %31 = getelementptr i8, ptr %29, i64 -16
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = tail call double @llvm.fmuladd.f64(double %14, double %32, double %30)
  store double %33, ptr %29, align 8, !tbaa !5
  %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, %18
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %19, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %19, %.lr.ph
  %store_forwarded.unr = phi double [ %load_initial, %.lr.ph ], [ %33, %19 ]
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph ], [ %indvars.iv.next.1, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %34 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = getelementptr double, ptr %2, i64 %indvars.iv.unr
  %37 = tail call double @llvm.fmuladd.f64(double %13, double %store_forwarded.unr, double %35)
  %38 = getelementptr i8, ptr %36, i64 -16
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = tail call double @llvm.fmuladd.f64(double %14, double %39, double %37)
  store double %40, ptr %36, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %5
  %41 = sext i32 %1 to i64
  %42 = getelementptr inbounds double, ptr %2, i64 %41
  %43 = getelementptr i8, ptr %42, i64 -8
  %44 = load <2 x double>, ptr %43, align 8, !tbaa !5
  %45 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %44)
  %shift = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %46 = fadd <2 x double> %shift, %45
  %47 = extractelement <2 x double> %46, i64 0
  store double %47, ptr %4, align 8, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { 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,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass