; LLVM IR from kmilo17pet/qlibs :: qffmath (qFFMath_ATan2)

; 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 uwtable
declare dso_local float @qFFMath_Abs(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
declare dso_local float @qFFMath_ATan(float noundef) #1

; Function Attrs: nounwind uwtable
define dso_local float @qFFMath_ATan2(float noundef %0, float noundef %1) #1 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  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 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = load float, ptr %3, align 4, !tbaa !5
  %8 = fcmp olt float %7, 0.000000e+00
  %9 = zext i1 %8 to i64
  %10 = select i1 %8, float 0x401921FB60000000, float 0.000000e+00
  %11 = fsub float 0x400921FB60000000, %10
  store float %11, ptr %5, align 4, !tbaa !5
  %12 = load float, ptr %4, align 4, !tbaa !5
  %13 = call float @qFFMath_Abs(float noundef %12)
  %14 = fcmp ole float %13, 0x3810000000000000
  %15 = zext i1 %14 to i64
  %16 = select i1 %14, float 1.000000e+00, float 0.000000e+00
  store float %16, ptr %6, align 4, !tbaa !5
  %17 = load float, ptr %3, align 4, !tbaa !5
  %18 = load float, ptr %4, align 4, !tbaa !5
  %19 = load float, ptr %6, align 4, !tbaa !5
  %20 = fadd float %18, %19
  %21 = fdiv float %17, %20
  %22 = call float @qFFMath_ATan(float noundef %21)
  %23 = load float, ptr %4, align 4, !tbaa !5
  %24 = fcmp olt float %23, 0.000000e+00
  br i1 %24, label %25, label %27

25:                                               ; preds = %2
  %26 = load float, ptr %5, align 4, !tbaa !5
  br label %28

27:                                               ; preds = %2
  br label %28

28:                                               ; preds = %27, %25
  %29 = phi float [ %26, %25 ], [ 0.000000e+00, %27 ]
  %30 = fadd float %22, %29
  store float %30, ptr %3, align 4, !tbaa !5
  %31 = load float, ptr %3, align 4, !tbaa !5
  %32 = load float, ptr %6, align 4, !tbaa !5
  %33 = load float, ptr %5, align 4, !tbaa !5
  %34 = load float, ptr %3, align 4, !tbaa !5
  %35 = fneg float %34
  %36 = call float @llvm.fmuladd.f32(float 5.000000e-01, float %33, float %35)
  %37 = call float @llvm.fmuladd.f32(float %32, float %36, float %31)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

; Function Attrs: nounwind uwtable
define dso_local float @qFFMath_ATan2(float noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = fcmp olt float %0, 0.000000e+00
  %4 = select i1 %3, float 0xC00921FB60000000, float 0x400921FB60000000
  %5 = tail call float @qFFMath_Abs(float noundef %1)
  %6 = fcmp ole float %5, 0x3810000000000000
  %7 = select i1 %6, float 1.000000e+00, float 0.000000e+00
  %8 = fadd float %7, %1
  %9 = fdiv float %0, %8
  %10 = tail call float @qFFMath_ATan(float noundef %9)
  %11 = fcmp olt float %1, 0.000000e+00
  %12 = select i1 %11, float %4, float 0.000000e+00
  %13 = fadd float %12, %10
  %14 = fneg float %13
  %15 = tail call float @llvm.fmuladd.f32(float %4, float 5.000000e-01, float %14)
  %16 = tail call float @llvm.fmuladd.f32(float %7, float %15, float %13)
  ret float %16
}

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 = { mustprogress 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass