; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libSimuTilts/library.ll (Z7nearestPffPii)

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z7nearestPffPii(ptr noundef %0, float noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %13 = load float, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds float, ptr %14, i64 0
  %16 = load float, ptr %15, align 4, !tbaa !9
  %17 = fsub float %13, %16
  %18 = call float @llvm.fabs.f32(float %17)
  store float %18, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds float, ptr %19, i64 0
  %21 = load float, ptr %20, align 4, !tbaa !9
  store float %21, ptr %10, align 4, !tbaa !9
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %26

24:                                               ; preds = %4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %25, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %24, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %58, %26
  %28 = load i32, ptr %11, align 4, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !11
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %61

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %33 = load float, ptr %6, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !9
  %39 = fsub float %33, %38
  %40 = call float @llvm.fabs.f32(float %39)
  store float %40, ptr %12, align 4, !tbaa !9
  %41 = load float, ptr %12, align 4, !tbaa !9
  %42 = load float, ptr %9, align 4, !tbaa !9
  %43 = fcmp olt float %41, %42
  br i1 %43, label %44, label %57

44:                                               ; preds = %32
  %45 = load float, ptr %12, align 4, !tbaa !9
  store float %45, ptr %9, align 4, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %46, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !9
  store float %50, ptr %10, align 4, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %56

53:                                               ; preds = %44
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %54, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %53, %44
  br label %57

57:                                               ; preds = %56, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %58

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

61:                                               ; preds = %31
  %62 = load float, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret float %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 float @llvm.fabs.f32(float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef float @_Z7nearestPffPii(ptr nocapture noundef readonly %0, float noundef %1, ptr noundef writeonly %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = load float, ptr %0, align 4, !tbaa !5
  %6 = fsub float %1, %5
  %7 = tail call float @llvm.fabs.f32(float %6)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %8, label %.thread

8:                                                ; preds = %4
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.lr.ph.split.us.preheader, label %._crit_edge

.thread:                                          ; preds = %4
  store i32 0, ptr %2, align 4, !tbaa !9
  %10 = icmp sgt i32 %3, 0
  br i1 %10, label %.lr.ph.split.preheader, label %._crit_edge

.lr.ph.split.preheader:                           ; preds = %.thread
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %3, 1
  br i1 %11, label %._crit_edge.loopexit38.unr-lcssa, label %.lr.ph.split.preheader.new

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

.lr.ph.split.us.preheader:                        ; preds = %8
  %wide.trip.count34 = zext nneg i32 %3 to i64
  %xtraiter40 = and i64 %wide.trip.count34, 1
  %12 = icmp eq i32 %3, 1
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.split.us.preheader.new

.lr.ph.split.us.preheader.new:                    ; preds = %.lr.ph.split.us.preheader
  %unroll_iter43 = and i64 %wide.trip.count34, 2147483646
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us, %.lr.ph.split.us.preheader.new
  %indvars.iv31 = phi i64 [ 0, %.lr.ph.split.us.preheader.new ], [ %indvars.iv.next32.1, %.lr.ph.split.us ]
  %.028.us = phi float [ %7, %.lr.ph.split.us.preheader.new ], [ %.0.mux.us.1, %.lr.ph.split.us ]
  %.02026.us = phi float [ %5, %.lr.ph.split.us.preheader.new ], [ %.020.mux.us.1, %.lr.ph.split.us ]
  %niter44 = phi i64 [ 0, %.lr.ph.split.us.preheader.new ], [ %niter44.next.1, %.lr.ph.split.us ]
  %13 = getelementptr inbounds float, ptr %0, i64 %indvars.iv31
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = fsub float %1, %14
  %16 = tail call float @llvm.fabs.f32(float %15)
  %17 = fcmp uge float %16, %.028.us
  %.020.mux.us = select i1 %17, float %.02026.us, float %14
  %.0.mux.us = select i1 %17, float %.028.us, float %16
  %indvars.iv.next32 = or disjoint i64 %indvars.iv31, 1
  %18 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next32
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = fsub float %1, %19
  %21 = tail call float @llvm.fabs.f32(float %20)
  %22 = fcmp uge float %21, %.0.mux.us
  %.020.mux.us.1 = select i1 %22, float %.020.mux.us, float %19
  %.0.mux.us.1 = select i1 %22, float %.0.mux.us, float %21
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31, 2
  %niter44.next.1 = add i64 %niter44, 2
  %niter44.ncmp.1 = icmp eq i64 %niter44.next.1, %unroll_iter43
  br i1 %niter44.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.split.us, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph.split.us, %.lr.ph.split.us.preheader
  %.020.mux.us.lcssa.ph = phi float [ poison, %.lr.ph.split.us.preheader ], [ %.020.mux.us.1, %.lr.ph.split.us ]
  %indvars.iv31.unr = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %indvars.iv.next32.1, %.lr.ph.split.us ]
  %.028.us.unr = phi float [ %7, %.lr.ph.split.us.preheader ], [ %.0.mux.us.1, %.lr.ph.split.us ]
  %.02026.us.unr = phi float [ %5, %.lr.ph.split.us.preheader ], [ %.020.mux.us.1, %.lr.ph.split.us ]
  %lcmp.mod41.not = icmp eq i64 %xtraiter40, 0
  br i1 %lcmp.mod41.not, label %._crit_edge, label %.lr.ph.split.us.epil

.lr.ph.split.us.epil:                             ; preds = %._crit_edge.loopexit.unr-lcssa
  %23 = getelementptr inbounds float, ptr %0, i64 %indvars.iv31.unr
  %24 = load float, ptr %23, align 4, !tbaa !5
  %25 = fsub float %1, %24
  %26 = tail call float @llvm.fabs.f32(float %25)
  %27 = fcmp uge float %26, %.028.us.unr
  %.020.mux.us.epil = select i1 %27, float %.02026.us.unr, float %24
  br label %._crit_edge

._crit_edge.loopexit38.unr-lcssa:                 ; preds = %49, %.lr.ph.split.preheader
  %.121.lcssa.ph = phi float [ poison, %.lr.ph.split.preheader ], [ %.121.1, %49 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.split.preheader ], [ %indvars.iv.next.1, %49 ]
  %.028.unr = phi float [ %7, %.lr.ph.split.preheader ], [ %.1.1, %49 ]
  %.02026.unr = phi float [ %5, %.lr.ph.split.preheader ], [ %.121.1, %49 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.split.epil

.lr.ph.split.epil:                                ; preds = %._crit_edge.loopexit38.unr-lcssa
  %28 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.unr
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = fsub float %1, %29
  %31 = tail call float @llvm.fabs.f32(float %30)
  %32 = fcmp uge float %31, %.028.unr
  br i1 %32, label %._crit_edge, label %33

33:                                               ; preds = %.lr.ph.split.epil
  %34 = trunc nuw nsw i64 %indvars.iv.unr to i32
  store i32 %34, ptr %2, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit38.unr-lcssa, %33, %.lr.ph.split.epil, %.lr.ph.split.us.epil, %._crit_edge.loopexit.unr-lcssa, %.thread, %8
  %.020.lcssa = phi float [ %5, %8 ], [ %5, %.thread ], [ %.020.mux.us.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.020.mux.us.epil, %.lr.ph.split.us.epil ], [ %.121.lcssa.ph, %._crit_edge.loopexit38.unr-lcssa ], [ %29, %33 ], [ %.02026.unr, %.lr.ph.split.epil ]
  ret float %.020.lcssa

.lr.ph.split:                                     ; preds = %49, %.lr.ph.split.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %indvars.iv.next.1, %49 ]
  %.028 = phi float [ %7, %.lr.ph.split.preheader.new ], [ %.1.1, %49 ]
  %.02026 = phi float [ %5, %.lr.ph.split.preheader.new ], [ %.121.1, %49 ]
  %niter = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %niter.next.1, %49 ]
  %35 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %36 = load float, ptr %35, align 4, !tbaa !5
  %37 = fsub float %1, %36
  %38 = tail call float @llvm.fabs.f32(float %37)
  %39 = fcmp uge float %38, %.028
  br i1 %39, label %.lr.ph.split.1, label %40

40:                                               ; preds = %.lr.ph.split
  %41 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %41, ptr %2, align 4, !tbaa !9
  br label %.lr.ph.split.1

.lr.ph.split.1:                                   ; preds = %.lr.ph.split, %40
  %.121 = phi float [ %36, %40 ], [ %.02026, %.lr.ph.split ]
  %.1 = phi float [ %38, %40 ], [ %.028, %.lr.ph.split ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %42 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next
  %43 = load float, ptr %42, align 4, !tbaa !5
  %44 = fsub float %1, %43
  %45 = tail call float @llvm.fabs.f32(float %44)
  %46 = fcmp uge float %45, %.1
  br i1 %46, label %49, label %47

47:                                               ; preds = %.lr.ph.split.1
  %48 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %48, ptr %2, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47, %.lr.ph.split.1
  %.121.1 = phi float [ %43, %47 ], [ %.121, %.lr.ph.split.1 ]
  %.1.1 = phi float [ %45, %47 ], [ %.1, %.lr.ph.split.1 ]
  %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.loopexit38.unr-lcssa, label %.lr.ph.split, !llvm.loop !11
}

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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