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

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

%union.anon = type { [2 x i32] }

@s_values = external hidden constant %union.anon, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFFMath_FPClassify(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
declare dso_local float @qFFMath_Abs(float noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @qFFMath_IsEqual(float noundef, float noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Trunc(float noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Sin(float noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Log(float noundef) #0

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

13:                                               ; preds = %1
  %14 = load float, ptr getelementptr (i8, ptr @s_values, i64 4), align 4, !tbaa !5
  store float %14, ptr %3, align 4, !tbaa !5
  br label %64

15:                                               ; preds = %1
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = icmp eq i32 0, %16
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp eq i32 3, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %18, %15
  %22 = load float, ptr @s_values, align 4, !tbaa !5
  store float %22, ptr %3, align 4, !tbaa !5
  br label %63

23:                                               ; preds = %18
  %24 = load float, ptr %2, align 4, !tbaa !5
  %25 = fcmp olt float %24, 0.000000e+00
  br i1 %25, label %26, label %59

26:                                               ; preds = %23
  %27 = load float, ptr %2, align 4, !tbaa !5
  %28 = fcmp ole float %27, 0xC330000000000000
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = load float, ptr @s_values, align 4, !tbaa !5
  store float %30, ptr %3, align 4, !tbaa !5
  br label %58

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %32 = load float, ptr %2, align 4, !tbaa !5
  %33 = fneg float %32
  store float %33, ptr %5, align 4, !tbaa !5
  %34 = load float, ptr %5, align 4, !tbaa !5
  %35 = call float @qFFMath_Trunc(float noundef %34)
  store float %35, ptr %6, align 4, !tbaa !5
  %36 = load float, ptr %5, align 4, !tbaa !5
  %37 = load float, ptr %6, align 4, !tbaa !5
  %38 = fsub float %36, %37
  store float %38, ptr %7, align 4, !tbaa !5
  %39 = load float, ptr %7, align 4, !tbaa !5
  %40 = call zeroext i1 @qFFMath_IsEqual(float noundef 0.000000e+00, float noundef %39)
  br i1 %40, label %41, label %43

41:                                               ; preds = %31
  %42 = load float, ptr @s_values, align 4, !tbaa !5
  store float %42, ptr %3, align 4, !tbaa !5
  br label %57

43:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %44 = load float, ptr %7, align 4, !tbaa !5
  %45 = fmul float 0x400921FB60000000, %44
  %46 = call float @qFFMath_Sin(float noundef %45)
  store float %46, ptr %8, align 4, !tbaa !5
  %47 = load float, ptr %8, align 4, !tbaa !5
  %48 = load float, ptr %2, align 4, !tbaa !5
  %49 = fmul float %47, %48
  %50 = call float @qFFMath_Abs(float noundef %49)
  %51 = fdiv float 0x400921FB60000000, %50
  %52 = call float @qFFMath_Log(float noundef %51)
  %53 = load float, ptr %2, align 4, !tbaa !5
  %54 = fneg float %53
  %55 = call float @lgamma_positive(float noundef %54)
  %56 = fsub float %52, %55
  store float %56, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %57

57:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %58

58:                                               ; preds = %57, %29
  br label %62

59:                                               ; preds = %23
  %60 = load float, ptr %2, align 4, !tbaa !5
  %61 = call float @lgamma_positive(float noundef %60)
  store float %61, ptr %3, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %59, %58
  br label %63

63:                                               ; preds = %62, %21
  br label %64

64:                                               ; preds = %63, %13
  %65 = load float, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret float %65
}

; Function Attrs: nounwind uwtable
declare hidden float @lgamma_positive(float noundef) #0

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 = !{!"int", !7, i64 0}


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

%union.anon = type { [2 x i32] }

@s_values = external hidden local_unnamed_addr constant %union.anon, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFFMath_FPClassify(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Abs(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @qFFMath_IsEqual(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Trunc(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Sin(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @qFFMath_Log(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @qFFMath_LGamma(float noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @qFFMath_FPClassify(float noundef %0)
  switch i32 %2, label %7 [
    i32 4, label %3
    i32 3, label %5
    i32 0, label %5
  ]

3:                                                ; preds = %1
  %4 = load float, ptr getelementptr inbounds (i8, ptr @s_values, i64 4), align 4, !tbaa !5
  br label %31

5:                                                ; preds = %1, %1
  %6 = load float, ptr @s_values, align 4, !tbaa !5
  br label %31

7:                                                ; preds = %1
  %8 = fcmp olt float %0, 0.000000e+00
  br i1 %8, label %9, label %29

9:                                                ; preds = %7
  %10 = fcmp ugt float %0, 0xC330000000000000
  br i1 %10, label %13, label %11

11:                                               ; preds = %9
  %12 = load float, ptr @s_values, align 4, !tbaa !5
  br label %31

13:                                               ; preds = %9
  %14 = fneg float %0
  %15 = tail call float @qFFMath_Trunc(float noundef %14)
  %16 = fsub float %14, %15
  %17 = tail call zeroext i1 @qFFMath_IsEqual(float noundef 0.000000e+00, float noundef %16)
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  %19 = load float, ptr @s_values, align 4, !tbaa !5
  br label %31

20:                                               ; preds = %13
  %21 = fmul float %16, 0x400921FB60000000
  %22 = tail call float @qFFMath_Sin(float noundef %21)
  %23 = fmul float %22, %0
  %24 = tail call float @qFFMath_Abs(float noundef %23)
  %25 = fdiv float 0x400921FB60000000, %24
  %26 = tail call float @qFFMath_Log(float noundef %25)
  %27 = tail call float @lgamma_positive(float noundef %14)
  %28 = fsub float %26, %27
  br label %31

29:                                               ; preds = %7
  %30 = tail call float @lgamma_positive(float noundef %0)
  br label %31

31:                                               ; preds = %18, %20, %5, %11, %29, %3
  %.1 = phi float [ %4, %3 ], [ %6, %5 ], [ %12, %11 ], [ %30, %29 ], [ %19, %18 ], [ %28, %20 ]
  ret float %.1
}

; Function Attrs: nounwind uwtable
declare hidden float @lgamma_positive(float noundef) local_unnamed_addr #0

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 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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