; LLVM IR from sbu-fsl/kernel-ml :: src/math (math)

; 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: nounwind uwtable
declare dso_local float @fast_sqrt_f(float noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local float @agm(float noundef %0, float noundef %1) #0 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i64, align 8
  store float %0, ptr %3, align 4, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store double 0x3E7AD7F29ABCAF48, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %12 = load float, ptr %3, align 4, !tbaa !5
  %13 = fpext float %12 to double
  store double %13, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %14 = load float, ptr %4, align 4, !tbaa !5
  %15 = fpext float %14 to double
  store double %15, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 4294967286, ptr %11, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %51, %2
  %17 = load double, ptr %6, align 8, !tbaa !9
  %18 = load double, ptr %5, align 8, !tbaa !9
  %19 = fcmp ogt double %17, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = load i64, ptr %11, align 8, !tbaa !11
  %22 = icmp ne i64 %21, 0
  br label %23

23:                                               ; preds = %20, %16
  %24 = phi i1 [ false, %16 ], [ %22, %20 ]
  br i1 %24, label %25, label %55

25:                                               ; preds = %23
  %26 = load double, ptr %9, align 8, !tbaa !9
  %27 = load double, ptr %10, align 8, !tbaa !9
  %28 = fadd double %26, %27
  store double %28, ptr %7, align 8, !tbaa !9
  %29 = load double, ptr %9, align 8, !tbaa !9
  %30 = load double, ptr %10, align 8, !tbaa !9
  %31 = fmul double %29, %30
  store double %31, ptr %8, align 8, !tbaa !9
  %32 = load double, ptr %7, align 8, !tbaa !9
  %33 = fdiv double %32, 2.000000e+00
  store double %33, ptr %9, align 8, !tbaa !9
  %34 = load double, ptr %8, align 8, !tbaa !9
  %35 = fptrunc double %34 to float
  %36 = call float @fast_sqrt_f(float noundef %35)
  %37 = fpext float %36 to double
  store double %37, ptr %10, align 8, !tbaa !9
  %38 = load double, ptr %9, align 8, !tbaa !9
  %39 = load double, ptr %10, align 8, !tbaa !9
  %40 = fsub double %38, %39
  %41 = fcmp oge double %40, 0.000000e+00
  br i1 %41, label %42, label %46

42:                                               ; preds = %25
  %43 = load double, ptr %9, align 8, !tbaa !9
  %44 = load double, ptr %10, align 8, !tbaa !9
  %45 = fsub double %43, %44
  br label %51

46:                                               ; preds = %25
  %47 = load double, ptr %9, align 8, !tbaa !9
  %48 = fneg double %47
  %49 = load double, ptr %10, align 8, !tbaa !9
  %50 = fsub double %48, %49
  br label %51

51:                                               ; preds = %46, %42
  %52 = phi double [ %45, %42 ], [ %50, %46 ]
  store double %52, ptr %6, align 8, !tbaa !9
  %53 = load i64, ptr %11, align 8, !tbaa !11
  %54 = add i64 %53, -1
  store i64 %54, ptr %11, align 8, !tbaa !11
  br label %16, !llvm.loop !13

55:                                               ; preds = %23
  %56 = load double, ptr %10, align 8, !tbaa !9
  %57 = fptrunc double %56 to float
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret float %57
}

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 nosync 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 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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: nounwind uwtable
declare dso_local float @fast_sqrt_f(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @agm(float noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = fpext float %0 to double
  %4 = fpext float %1 to double
  br label %5

5:                                                ; preds = %2, %5
  %.024 = phi i64 [ 4294967286, %2 ], [ %17, %5 ]
  %.01823 = phi double [ %4, %2 ], [ %11, %5 ]
  %.01922 = phi double [ %3, %2 ], [ %8, %5 ]
  %6 = fadd double %.01922, %.01823
  %7 = fmul double %.01922, %.01823
  %8 = fmul double %6, 5.000000e-01
  %9 = fptrunc double %7 to float
  %10 = tail call float @fast_sqrt_f(float noundef %9)
  %11 = fpext float %10 to double
  %12 = fsub double %8, %11
  %13 = fcmp ult double %12, 0.000000e+00
  %14 = fneg double %8
  %15 = fsub double %14, %11
  %16 = select i1 %13, double %15, double %12
  %17 = add nsw i64 %.024, -1
  %18 = fcmp ogt double %16, 0x3E7AD7F29ABCAF48
  %19 = icmp ne i64 %17, 0
  %20 = select i1 %18, i1 %19, i1 false
  br i1 %20, label %5, label %21, !llvm.loop !5

21:                                               ; preds = %5
  ret float %10
}

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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass