; LLVM IR from P-py/c-numerical-methods :: dichotomy (calculateValues)

; 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: nounwind
declare float @powf(float noundef, float noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @calculateValues(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %60, %5
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 3
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %63

20:                                               ; preds = %16
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %21, i64 %23
  store float 0.000000e+00, ptr %24, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %25, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %56, %20
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %59

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load i32, ptr %13, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %31, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !11
  store float %35, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sitofp i32 %40 to float
  store float %41, ptr %15, align 4, !tbaa !11
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %42, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = load float, ptr %15, align 4, !tbaa !11
  %48 = call float @powf(float noundef %46, float noundef %47) #4
  %49 = load float, ptr %14, align 4, !tbaa !11
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = call float @llvm.fmuladd.f32(float %48, float %49, float %54)
  store float %55, ptr %53, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %56

56:                                               ; preds = %30
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !13

59:                                               ; preds = %29
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !9
  br label %16, !llvm.loop !15

63:                                               ; preds = %19
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nofree nounwind willreturn memory(write)
declare float @powf(float noundef, float noundef) local_unnamed_addr #0

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

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

.split.preheader:                                 ; preds = %5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %4, i8 0, i64 12, i1 false), !tbaa !5
  br label %.split20.us

.lr.ph.us.preheader:                              ; preds = %5
  %7 = zext nneg i32 %3 to i64
  store float 0.000000e+00, ptr %4, align 4, !tbaa !5
  %8 = and i64 %7, 1
  %lcmp.mod.not.not = icmp eq i64 %8, 0
  br i1 %lcmp.mod.not.not, label %.prol.loopexit.unr-lcssa, label %.prol.loopexit

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph.us.preheader
  %9 = getelementptr inbounds float, ptr %2, i64 %7
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds i32, ptr %1, i64 %7
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sitofp i32 %12 to float
  %14 = load float, ptr %0, align 4, !tbaa !5
  %15 = tail call float @powf(float noundef %14, float noundef %13) #4
  %16 = load float, ptr %4, align 4, !tbaa !5
  %17 = tail call float @llvm.fmuladd.f32(float %15, float %10, float %16)
  store float %17, ptr %4, align 4, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %7, -1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph.us.preheader
  %indvars.iv.unr = phi i64 [ %7, %.lr.ph.us.preheader ], [ %indvars.iv.next.prol, %.prol.loopexit.unr-lcssa ]
  %18 = icmp eq i32 %3, 0
  br i1 %18, label %._crit_edge.us, label %.lr.ph.us.preheader.new

.lr.ph.us.preheader.new:                          ; preds = %.prol.loopexit, %.lr.ph.us.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.next.128, %.lr.ph.us.preheader.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %19 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %20 = load float, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sitofp i32 %22 to float
  %24 = load float, ptr %0, align 4, !tbaa !5
  %25 = tail call float @powf(float noundef %24, float noundef %23) #4
  %26 = load float, ptr %4, align 4, !tbaa !5
  %27 = tail call float @llvm.fmuladd.f32(float %25, float %20, float %26)
  store float %27, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %28 = getelementptr inbounds float, ptr %2, i64 %indvars.iv.next
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sitofp i32 %31 to float
  %33 = load float, ptr %0, align 4, !tbaa !5
  %34 = tail call float @powf(float noundef %33, float noundef %32) #4
  %35 = load float, ptr %4, align 4, !tbaa !5
  %36 = tail call float @llvm.fmuladd.f32(float %34, float %29, float %35)
  store float %36, ptr %4, align 4, !tbaa !5
  %indvars.iv.next.128 = add nsw i64 %indvars.iv, -2
  %.not.1 = icmp eq i64 %indvars.iv.next, 0
  br i1 %.not.1, label %._crit_edge.us, label %.lr.ph.us.preheader.new, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.lr.ph.us.preheader.new, %.prol.loopexit
  %37 = getelementptr inbounds i8, ptr %4, i64 4
  store float 0.000000e+00, ptr %37, align 4, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %0, i64 4
  %39 = and i64 %7, 1
  %lcmp.mod32.not.not = icmp eq i64 %39, 0
  br i1 %lcmp.mod32.not.not, label %.prol.loopexit30.unr-lcssa, label %.prol.loopexit30

.prol.loopexit30.unr-lcssa:                       ; preds = %._crit_edge.us
  %40 = getelementptr inbounds float, ptr %2, i64 %7
  %41 = load float, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds i32, ptr %1, i64 %7
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sitofp i32 %43 to float
  %45 = load float, ptr %38, align 4, !tbaa !5
  %46 = tail call float @powf(float noundef %45, float noundef %44) #4
  %47 = load float, ptr %37, align 4, !tbaa !5
  %48 = tail call float @llvm.fmuladd.f32(float %46, float %41, float %47)
  store float %48, ptr %37, align 4, !tbaa !5
  %indvars.iv.next.1.prol = add nsw i64 %7, -1
  br label %.prol.loopexit30

.prol.loopexit30:                                 ; preds = %.prol.loopexit30.unr-lcssa, %._crit_edge.us
  %indvars.iv.1.unr = phi i64 [ %7, %._crit_edge.us ], [ %indvars.iv.next.1.prol, %.prol.loopexit30.unr-lcssa ]
  %49 = icmp eq i32 %3, 0
  br i1 %49, label %._crit_edge.us.1, label %._crit_edge.us.new

._crit_edge.us.new:                               ; preds = %.prol.loopexit30, %._crit_edge.us.new
  %indvars.iv.1 = phi i64 [ %indvars.iv.next.1.1, %._crit_edge.us.new ], [ %indvars.iv.1.unr, %.prol.loopexit30 ]
  %50 = getelementptr inbounds float, ptr %2, i64 %indvars.iv.1
  %51 = load float, ptr %50, align 4, !tbaa !5
  %52 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sitofp i32 %53 to float
  %55 = load float, ptr %38, align 4, !tbaa !5
  %56 = tail call float @powf(float noundef %55, float noundef %54) #4
  %57 = load float, ptr %37, align 4, !tbaa !5
  %58 = tail call float @llvm.fmuladd.f32(float %56, float %51, float %57)
  store float %58, ptr %37, align 4, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv.1, -1
  %59 = getelementptr inbounds float, ptr %2, i64 %indvars.iv.next.1
  %60 = load float, ptr %59, align 4, !tbaa !5
  %61 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sitofp i32 %62 to float
  %64 = load float, ptr %38, align 4, !tbaa !5
  %65 = tail call float @powf(float noundef %64, float noundef %63) #4
  %66 = load float, ptr %37, align 4, !tbaa !5
  %67 = tail call float @llvm.fmuladd.f32(float %65, float %60, float %66)
  store float %67, ptr %37, align 4, !tbaa !5
  %indvars.iv.next.1.1 = add nsw i64 %indvars.iv.1, -2
  %68 = icmp sgt i64 %indvars.iv.1, 1
  br i1 %68, label %._crit_edge.us.new, label %._crit_edge.us.1, !llvm.loop !11

._crit_edge.us.1:                                 ; preds = %._crit_edge.us.new, %.prol.loopexit30
  %69 = getelementptr inbounds i8, ptr %4, i64 8
  store float 0.000000e+00, ptr %69, align 4, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %0, i64 8
  %71 = and i64 %7, 1
  %lcmp.mod36.not.not = icmp eq i64 %71, 0
  br i1 %lcmp.mod36.not.not, label %.prol.loopexit34.unr-lcssa, label %.prol.loopexit34

.prol.loopexit34.unr-lcssa:                       ; preds = %._crit_edge.us.1
  %72 = getelementptr inbounds float, ptr %2, i64 %7
  %73 = load float, ptr %72, align 4, !tbaa !5
  %74 = getelementptr inbounds i32, ptr %1, i64 %7
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = sitofp i32 %75 to float
  %77 = load float, ptr %70, align 4, !tbaa !5
  %78 = tail call float @powf(float noundef %77, float noundef %76) #4
  %79 = load float, ptr %69, align 4, !tbaa !5
  %80 = tail call float @llvm.fmuladd.f32(float %78, float %73, float %79)
  store float %80, ptr %69, align 4, !tbaa !5
  %indvars.iv.next.2.prol = add nsw i64 %7, -1
  br label %.prol.loopexit34

.prol.loopexit34:                                 ; preds = %.prol.loopexit34.unr-lcssa, %._crit_edge.us.1
  %indvars.iv.2.unr = phi i64 [ %7, %._crit_edge.us.1 ], [ %indvars.iv.next.2.prol, %.prol.loopexit34.unr-lcssa ]
  %81 = icmp eq i32 %3, 0
  br i1 %81, label %.split20.us, label %._crit_edge.us.1.new

._crit_edge.us.1.new:                             ; preds = %.prol.loopexit34, %._crit_edge.us.1.new
  %indvars.iv.2 = phi i64 [ %indvars.iv.next.2.1, %._crit_edge.us.1.new ], [ %indvars.iv.2.unr, %.prol.loopexit34 ]
  %82 = getelementptr inbounds float, ptr %2, i64 %indvars.iv.2
  %83 = load float, ptr %82, align 4, !tbaa !5
  %84 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.2
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = sitofp i32 %85 to float
  %87 = load float, ptr %70, align 4, !tbaa !5
  %88 = tail call float @powf(float noundef %87, float noundef %86) #4
  %89 = load float, ptr %69, align 4, !tbaa !5
  %90 = tail call float @llvm.fmuladd.f32(float %88, float %83, float %89)
  store float %90, ptr %69, align 4, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv.2, -1
  %91 = getelementptr inbounds float, ptr %2, i64 %indvars.iv.next.2
  %92 = load float, ptr %91, align 4, !tbaa !5
  %93 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.2
  %94 = load i32, ptr %93, align 4, !tbaa !9
  %95 = sitofp i32 %94 to float
  %96 = load float, ptr %70, align 4, !tbaa !5
  %97 = tail call float @powf(float noundef %96, float noundef %95) #4
  %98 = load float, ptr %69, align 4, !tbaa !5
  %99 = tail call float @llvm.fmuladd.f32(float %97, float %92, float %98)
  store float %99, ptr %69, align 4, !tbaa !5
  %indvars.iv.next.2.1 = add nsw i64 %indvars.iv.2, -2
  %100 = icmp sgt i64 %indvars.iv.2, 1
  br i1 %100, label %._crit_edge.us.1.new, label %.split20.us, !llvm.loop !11

.split20.us:                                      ; preds = %.prol.loopexit34, %._crit_edge.us.1.new, %.split.preheader
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(write, 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"float", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass