; LLVM IR from ermig1979/Simd :: src/Simd (SimdBaseResizerBilinear)

; 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: mustprogress uwtable
define dso_local void @_ZN4Simd4Base19ResizerByteBilinear18EstimateIndexAlphaEmmmPiS2_(ptr noundef nonnull align 8 dereferenceable(160) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #0 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca float, align 4
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca float, align 4
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = uitofp i64 %21 to float
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = uitofp i64 %23 to float
  %25 = fdiv float %22, %24
  store float %25, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %86, %6
  %27 = load i64, ptr %14, align 8, !tbaa !9
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %89

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = uitofp i64 %32 to float
  %34 = fadd float %33, 5.000000e-01
  %35 = load float, ptr %13, align 4, !tbaa !11
  %36 = call float @llvm.fmuladd.f32(float %34, float %35, float -5.000000e-01)
  store float %36, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %37 = load float, ptr %16, align 4, !tbaa !11
  %38 = call noundef float @_ZSt5floorf(float noundef %37)
  %39 = fptosi float %38 to i64
  store i64 %39, ptr %17, align 8, !tbaa !9
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = sitofp i64 %40 to float
  %42 = load float, ptr %16, align 4, !tbaa !11
  %43 = fsub float %42, %41
  store float %43, ptr %16, align 4, !tbaa !11
  %44 = load i64, ptr %17, align 8, !tbaa !9
  %45 = icmp slt i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %31
  store i64 0, ptr %17, align 8, !tbaa !9
  store float 0.000000e+00, ptr %16, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %46, %31
  %48 = load i64, ptr %17, align 8, !tbaa !9
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = sub nsw i64 %49, 2
  %51 = icmp sgt i64 %48, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %47
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = sub i64 %53, 2
  store i64 %54, ptr %17, align 8, !tbaa !9
  store float 1.000000e+00, ptr %16, align 4, !tbaa !11
  br label %55

55:                                               ; preds = %52, %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %82, %55
  %57 = load i64, ptr %18, align 8, !tbaa !9
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = icmp ult i64 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %85

61:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %62 = load i64, ptr %14, align 8, !tbaa !9
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = mul i64 %62, %63
  %65 = load i64, ptr %18, align 8, !tbaa !9
  %66 = add i64 %64, %65
  store i64 %66, ptr %19, align 8, !tbaa !9
  %67 = load i64, ptr %10, align 8, !tbaa !9
  %68 = load i64, ptr %17, align 8, !tbaa !9
  %69 = mul i64 %67, %68
  %70 = load i64, ptr %18, align 8, !tbaa !9
  %71 = add i64 %69, %70
  %72 = trunc i64 %71 to i32
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load i64, ptr %19, align 8, !tbaa !9
  %75 = getelementptr inbounds i32, ptr %73, i64 %74
  store i32 %72, ptr %75, align 4, !tbaa !13
  %76 = load float, ptr %16, align 4, !tbaa !11
  %77 = call float @llvm.fmuladd.f32(float %76, float 1.600000e+01, float 5.000000e-01)
  %78 = fptosi float %77 to i32
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load i64, ptr %19, align 8, !tbaa !9
  %81 = getelementptr inbounds i32, ptr %79, i64 %80
  store i32 %78, ptr %81, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  br label %82

82:                                               ; preds = %61
  %83 = load i64, ptr %18, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %18, align 8, !tbaa !9
  br label %56, !llvm.loop !15

85:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %86

86:                                               ; preds = %85
  %87 = load i64, ptr %14, align 8, !tbaa !9
  %88 = add i64 %87, 1
  store i64 %88, ptr %14, align 8, !tbaa !9
  br label %26, !llvm.loop !17

89:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5floorf(float noundef) #3

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

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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base19ResizerByteBilinear18EstimateIndexAlphaEmmmPiS2_(ptr nocapture noundef nonnull readnone align 8 dereferenceable(160) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 align 2 {
  %7 = ptrtoint ptr %4 to i64
  %8 = ptrtoint ptr %5 to i64
  %9 = uitofp i64 %1 to float
  %10 = uitofp i64 %2 to float
  %11 = fdiv float %9, %10
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %6
  %12 = add nsw i64 %1, -2
  %.not40 = icmp eq i64 %3, 0
  br i1 %.not40, label %.lr.ph38.split, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph38
  %13 = sub i64 %8, %7
  %min.iters.check = icmp ult i64 %3, 8
  %diff.check = icmp ult i64 %13, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  %n.vec = and i64 %3, -8
  %cmp.n = icmp eq i64 %n.vec, %3
  %xtraiter = and i64 %3, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %14 = add i64 %3, -1
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.036.us = phi i64 [ %57, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %15 = uitofp i64 %.036.us to float
  %16 = fadd float %15, 5.000000e-01
  %17 = tail call float @llvm.fmuladd.f32(float %16, float %11, float -5.000000e-01)
  %18 = tail call noundef float @_ZSt5floorf(float noundef %17)
  %19 = fptosi float %18 to i64
  %20 = sitofp i64 %19 to float
  %21 = fsub float %17, %20
  %22 = icmp slt i64 %19, 0
  %.030.us = select i1 %22, float 0.000000e+00, float %21
  %.029.us = tail call i64 @llvm.smax.i64(i64 %19, i64 0)
  %23 = icmp sgt i64 %.029.us, %12
  %.131.us = select i1 %23, float 1.000000e+00, float %.030.us
  %.1.us = tail call i64 @llvm.smin.i64(i64 %.029.us, i64 %12)
  %24 = mul i64 %.036.us, %3
  %25 = mul i64 %.1.us, %3
  %26 = tail call float @llvm.fmuladd.f32(float %.131.us, float 1.600000e+01, float 5.000000e-01)
  %27 = fptosi float %26 to i32
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %25, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert47 = insertelement <4 x i32> poison, i32 %27, i64 0
  %broadcast.splat48 = shufflevector <4 x i32> %broadcast.splatinsert47, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %28 = add i64 %index, %24
  %29 = add <4 x i64> %vec.ind, %broadcast.splat
  %30 = add <4 x i64> %step.add, %broadcast.splat
  %31 = trunc <4 x i64> %29 to <4 x i32>
  %32 = trunc <4 x i64> %30 to <4 x i32>
  %33 = getelementptr inbounds i32, ptr %4, i64 %28
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <4 x i32> %31, ptr %33, align 4, !tbaa !5
  store <4 x i32> %32, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %5, i64 %28
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  store <4 x i32> %broadcast.splat48, ptr %35, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat48, ptr %36, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8>
  %37 = icmp eq i64 %index.next, %n.vec
  br i1 %37, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %.02835.us.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %38 = add i64 %.02835.us.ph, %24
  %39 = add i64 %.02835.us.ph, %25
  %40 = trunc i64 %39 to i32
  %41 = getelementptr inbounds i32, ptr %4, i64 %38
  store i32 %40, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds i32, ptr %5, i64 %38
  store i32 %27, ptr %42, align 4, !tbaa !5
  %43 = or disjoint i64 %.02835.us.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.02835.us.unr = phi i64 [ %.02835.us.ph, %scalar.ph.preheader ], [ %43, %scalar.ph.prol ]
  %44 = icmp eq i64 %.02835.us.ph, %14
  br i1 %44, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.02835.us = phi i64 [ %56, %scalar.ph ], [ %.02835.us.unr, %scalar.ph.prol.loopexit ]
  %45 = add i64 %.02835.us, %24
  %46 = add i64 %.02835.us, %25
  %47 = trunc i64 %46 to i32
  %48 = getelementptr inbounds i32, ptr %4, i64 %45
  store i32 %47, ptr %48, align 4, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %5, i64 %45
  store i32 %27, ptr %49, align 4, !tbaa !5
  %50 = add nuw i64 %.02835.us, 1
  %51 = add i64 %50, %24
  %52 = add i64 %50, %25
  %53 = trunc i64 %52 to i32
  %54 = getelementptr inbounds i32, ptr %4, i64 %51
  store i32 %53, ptr %54, align 4, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %5, i64 %51
  store i32 %27, ptr %55, align 4, !tbaa !5
  %56 = add nuw i64 %.02835.us, 2
  %exitcond.not.1 = icmp eq i64 %56, %3
  br i1 %exitcond.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %57 = add nuw i64 %.036.us, 1
  %exitcond42.not = icmp eq i64 %57, %2
  br i1 %exitcond42.not, label %._crit_edge39, label %.lr.ph.us, !llvm.loop !14

._crit_edge39:                                    ; preds = %._crit_edge.us, %.lr.ph38.split, %6
  ret void

.lr.ph38.split:                                   ; preds = %.lr.ph38, %.lr.ph38.split
  %.036 = phi i64 [ %62, %.lr.ph38.split ], [ 0, %.lr.ph38 ]
  %58 = uitofp i64 %.036 to float
  %59 = fadd float %58, 5.000000e-01
  %60 = tail call float @llvm.fmuladd.f32(float %59, float %11, float -5.000000e-01)
  %61 = tail call noundef float @_ZSt5floorf(float noundef %60)
  %62 = add nuw i64 %.036, 1
  %exitcond43.not = icmp eq i64 %62, %2
  br i1 %exitcond43.not, label %._crit_edge39, label %.lr.ph38.split, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5floorf(float noundef) local_unnamed_addr #2

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

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { inlinehint mustprogress 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 = { 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 = !{!"int", !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, !11}
!14 = distinct !{!14, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass