; LLVM IR from jgaeddert/liquid-dsp :: sandbox (quasinewton_test)

; 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
declare ptr @llvm.stacksave.p0() #1

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

19:                                               ; preds = %32, %4
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %35

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %24, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds float, ptr %18, i64 %30
  store float %28, ptr %31, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %12, align 4, !tbaa !9
  br label %19, !llvm.loop !13

35:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = call float %36(ptr noundef %18, i32 noundef %37)
  store float %38, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store float 0.000000e+00, ptr %14, align 4, !tbaa !11
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %74, %35
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = icmp ult i32 %40, %41
  br i1 %42, label %43, label %77

43:                                               ; preds = %39
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %44, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !11
  %49 = load float, ptr %11, align 4, !tbaa !11
  %50 = fadd float %48, %49
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %18, i64 %52
  store float %50, ptr %53, align 4, !tbaa !11
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = call float %54(ptr noundef %18, i32 noundef %55)
  store float %56, ptr %14, align 4, !tbaa !11
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %57, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !11
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %18, i64 %63
  store float %61, ptr %64, align 4, !tbaa !11
  %65 = load float, ptr %14, align 4, !tbaa !11
  %66 = load float, ptr %13, align 4, !tbaa !11
  %67 = fsub float %65, %66
  %68 = load float, ptr %11, align 4, !tbaa !11
  %69 = fdiv float %67, %68
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds float, ptr %70, i64 %72
  store float %69, ptr %73, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %43
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = add i32 %75, 1
  store i32 %76, ptr %12, align 4, !tbaa !9
  br label %39, !llvm.loop !15

77:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %78 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %78)
  ret void
}

; 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 willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
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 = !{!"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: nounwind uwtable
define dso_local void @estimate_gradient(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = zext i32 %1 to i64
  %6 = alloca float, i64 %5, align 16
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph30.preheader

._crit_edge.thread:                               ; preds = %4
  %7 = call float %2(ptr noundef nonnull %6, i32 noundef %1) #2
  br label %._crit_edge31

.lr.ph30.preheader:                               ; preds = %4
  %8 = shl nuw nsw i64 %5, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr align 4 %0, i64 %8, i1 false), !tbaa !5
  %9 = call float %2(ptr noundef nonnull %6, i32 noundef %1) #2
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %.lr.ph30
  %indvars.iv = phi i64 [ 0, %.lr.ph30.preheader ], [ %indvars.iv.next, %.lr.ph30 ]
  %10 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fadd float %11, 0x3EB0C6F7A0000000
  %13 = getelementptr inbounds float, ptr %6, i64 %indvars.iv
  store float %12, ptr %13, align 4, !tbaa !5
  %14 = call float %2(ptr noundef nonnull %6, i32 noundef %1) #2
  %15 = load float, ptr %10, align 4, !tbaa !5
  store float %15, ptr %13, align 4, !tbaa !5
  %16 = fsub float %14, %9
  %17 = fdiv float %16, 0x3EB0C6F7A0000000
  %18 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  store float %17, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %5
  br i1 %exitcond.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !9

._crit_edge31:                                    ; preds = %.lr.ph30, %._crit_edge.thread
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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