; LLVM IR from chdb-io/chdb :: base/glibc-compatibility/musl (log2f)

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

%struct.log2f_data = type { [16 x %struct.anon], [4 x double] }
%struct.anon = type { double, double }
%union.anon = type { float }
%union.anon.0 = type { float }
%union.anon.1 = type { i32 }

@__log2f_data = external hidden constant %struct.log2f_data, align 8

; Function Attrs: nounwind uwtable
define dso_local float @log2f(float noundef %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca double, align 8
  %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 double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %union.anon, align 4
  %19 = alloca i32, align 4
  %20 = alloca %union.anon.0, align 4
  %21 = alloca %union.anon.1, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %22 = load float, ptr %3, align 4, !tbaa !5
  store float %22, ptr %18, align 4, !tbaa !9
  %23 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %23, ptr %12, align 4, !tbaa !10
  %24 = load i32, ptr %12, align 4, !tbaa !10
  %25 = icmp eq i32 %24, 1065353216
  %26 = zext i1 %25 to i32
  %27 = sext i32 %26 to i64
  %28 = call i64 @llvm.expect.i64(i64 %27, i64 0)
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %19, align 4
  br label %122

31:                                               ; preds = %1
  %32 = load i32, ptr %12, align 4, !tbaa !10
  %33 = sub i32 %32, 8388608
  %34 = icmp uge i32 %33, 2130706432
  %35 = zext i1 %34 to i32
  %36 = sext i32 %35 to i64
  %37 = call i64 @llvm.expect.i64(i64 %36, i64 0)
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %67

39:                                               ; preds = %31
  %40 = load i32, ptr %12, align 4, !tbaa !10
  %41 = mul i32 %40, 2
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = call float @__math_divzerof(i32 noundef 1)
  store float %44, ptr %2, align 4
  store i32 1, ptr %19, align 4
  br label %122

45:                                               ; preds = %39
  %46 = load i32, ptr %12, align 4, !tbaa !10
  %47 = icmp eq i32 %46, 2139095040
  br i1 %47, label %48, label %50

48:                                               ; preds = %45
  %49 = load float, ptr %3, align 4, !tbaa !5
  store float %49, ptr %2, align 4
  store i32 1, ptr %19, align 4
  br label %122

50:                                               ; preds = %45
  %51 = load i32, ptr %12, align 4, !tbaa !10
  %52 = and i32 %51, -2147483648
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %58, label %54

54:                                               ; preds = %50
  %55 = load i32, ptr %12, align 4, !tbaa !10
  %56 = mul i32 %55, 2
  %57 = icmp uge i32 %56, -16777216
  br i1 %57, label %58, label %61

58:                                               ; preds = %54, %50
  %59 = load float, ptr %3, align 4, !tbaa !5
  %60 = call float @__math_invalidf(float noundef %59)
  store float %60, ptr %2, align 4
  store i32 1, ptr %19, align 4
  br label %122

61:                                               ; preds = %54
  %62 = load float, ptr %3, align 4, !tbaa !5
  %63 = fmul float %62, 0x4160000000000000
  store float %63, ptr %20, align 4, !tbaa !9
  %64 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %64, ptr %12, align 4, !tbaa !10
  %65 = load i32, ptr %12, align 4, !tbaa !10
  %66 = sub i32 %65, 192937984
  store i32 %66, ptr %12, align 4, !tbaa !10
  br label %67

67:                                               ; preds = %61, %31
  %68 = load i32, ptr %12, align 4, !tbaa !10
  %69 = sub i32 %68, 1060306944
  store i32 %69, ptr %15, align 4, !tbaa !10
  %70 = load i32, ptr %15, align 4, !tbaa !10
  %71 = lshr i32 %70, 19
  %72 = urem i32 %71, 16
  store i32 %72, ptr %17, align 4, !tbaa !10
  %73 = load i32, ptr %15, align 4, !tbaa !10
  %74 = and i32 %73, -8388608
  store i32 %74, ptr %14, align 4, !tbaa !10
  %75 = load i32, ptr %12, align 4, !tbaa !10
  %76 = load i32, ptr %14, align 4, !tbaa !10
  %77 = sub i32 %75, %76
  store i32 %77, ptr %13, align 4, !tbaa !10
  %78 = load i32, ptr %15, align 4, !tbaa !10
  %79 = ashr i32 %78, 23
  store i32 %79, ptr %16, align 4, !tbaa !10
  %80 = load i32, ptr %17, align 4, !tbaa !10
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [16 x %struct.anon], ptr @__log2f_data, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.anon, ptr %82, i32 0, i32 0
  %84 = load double, ptr %83, align 8, !tbaa !12
  store double %84, ptr %10, align 8, !tbaa !15
  %85 = load i32, ptr %17, align 4, !tbaa !10
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [16 x %struct.anon], ptr @__log2f_data, i64 0, i64 %86
  %88 = getelementptr inbounds %struct.anon, ptr %87, i32 0, i32 1
  %89 = load double, ptr %88, align 8, !tbaa !16
  store double %89, ptr %11, align 8, !tbaa !15
  %90 = load i32, ptr %13, align 4, !tbaa !10
  store i32 %90, ptr %21, align 4, !tbaa !9
  %91 = load float, ptr %21, align 4, !tbaa !9
  %92 = fpext float %91 to double
  store double %92, ptr %4, align 8, !tbaa !15
  %93 = load double, ptr %4, align 8, !tbaa !15
  %94 = load double, ptr %10, align 8, !tbaa !15
  %95 = call double @llvm.fmuladd.f64(double %93, double %94, double -1.000000e+00)
  store double %95, ptr %5, align 8, !tbaa !15
  %96 = load double, ptr %11, align 8, !tbaa !15
  %97 = load i32, ptr %16, align 4, !tbaa !10
  %98 = sitofp i32 %97 to double
  %99 = fadd double %96, %98
  store double %99, ptr %9, align 8, !tbaa !15
  %100 = load double, ptr %5, align 8, !tbaa !15
  %101 = load double, ptr %5, align 8, !tbaa !15
  %102 = fmul double %100, %101
  store double %102, ptr %6, align 8, !tbaa !15
  %103 = load double, ptr getelementptr inbounds ([4 x double], ptr getelementptr inbounds (%struct.log2f_data, ptr @__log2f_data, i32 0, i32 1), i64 0, i64 1), align 8, !tbaa !15
  %104 = load double, ptr %5, align 8, !tbaa !15
  %105 = load double, ptr getelementptr inbounds ([4 x double], ptr getelementptr inbounds (%struct.log2f_data, ptr @__log2f_data, i32 0, i32 1), i64 0, i64 2), align 8, !tbaa !15
  %106 = call double @llvm.fmuladd.f64(double %103, double %104, double %105)
  store double %106, ptr %8, align 8, !tbaa !15
  %107 = load double, ptr getelementptr inbounds (%struct.log2f_data, ptr @__log2f_data, i32 0, i32 1), align 8, !tbaa !15
  %108 = load double, ptr %6, align 8, !tbaa !15
  %109 = load double, ptr %8, align 8, !tbaa !15
  %110 = call double @llvm.fmuladd.f64(double %107, double %108, double %109)
  store double %110, ptr %8, align 8, !tbaa !15
  %111 = load double, ptr getelementptr inbounds ([4 x double], ptr getelementptr inbounds (%struct.log2f_data, ptr @__log2f_data, i32 0, i32 1), i64 0, i64 3), align 8, !tbaa !15
  %112 = load double, ptr %5, align 8, !tbaa !15
  %113 = load double, ptr %9, align 8, !tbaa !15
  %114 = call double @llvm.fmuladd.f64(double %111, double %112, double %113)
  store double %114, ptr %7, align 8, !tbaa !15
  %115 = load double, ptr %8, align 8, !tbaa !15
  %116 = load double, ptr %6, align 8, !tbaa !15
  %117 = load double, ptr %7, align 8, !tbaa !15
  %118 = call double @llvm.fmuladd.f64(double %115, double %116, double %117)
  store double %118, ptr %8, align 8, !tbaa !15
  %119 = load double, ptr %8, align 8, !tbaa !15
  %120 = fptrunc double %119 to float
  %121 = call float @eval_as_float(float noundef %120)
  store float %121, ptr %2, align 4
  store i32 1, ptr %19, align 4
  br label %122

122:                                              ; preds = %67, %58, %48, %43, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %123 = load float, ptr %2, align 4
  ret float %123
}

; 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(none)
declare i64 @llvm.expect.i64(i64, i64) #2

declare hidden float @__math_divzerof(i32 noundef) #3

declare hidden float @__math_invalidf(float noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @eval_as_float(float noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { inlinehint 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 #6 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 8}
!14 = !{!"double", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!13, !14, i64 8}


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

%struct.log2f_data = type { [16 x %struct.anon], [4 x double] }
%struct.anon = type { double, double }

@__log2f_data = external hidden local_unnamed_addr constant %struct.log2f_data, align 8

; Function Attrs: nounwind uwtable
define dso_local float @log2f(float noundef %0) local_unnamed_addr #0 {
  %2 = bitcast float %0 to i32
  %3 = icmp eq i32 %2, 1065353216
  br i1 %3, label %50, label %4, !prof !5

4:                                                ; preds = %1
  %5 = add i32 %2, -2139095040
  %6 = icmp ult i32 %5, -2130706432
  br i1 %6, label %7, label %22, !prof !5

7:                                                ; preds = %4
  %8 = shl i32 %2, 1
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = tail call float @__math_divzerof(i32 noundef 1) #4
  br label %50

12:                                               ; preds = %7
  %13 = icmp eq i32 %2, 2139095040
  br i1 %13, label %50, label %14

14:                                               ; preds = %12
  %.not = icmp slt i32 %2, 0
  %15 = icmp ugt i32 %8, -16777217
  %or.cond = or i1 %.not, %15
  br i1 %or.cond, label %16, label %18

16:                                               ; preds = %14
  %17 = tail call float @__math_invalidf(float noundef %0) #4
  br label %50

18:                                               ; preds = %14
  %19 = fmul float %0, 0x4160000000000000
  %20 = bitcast float %19 to i32
  %21 = add i32 %20, -192937984
  br label %22

22:                                               ; preds = %18, %4
  %.037 = phi i32 [ %21, %18 ], [ %2, %4 ]
  %23 = add i32 %.037, -1060306944
  %24 = lshr i32 %23, 19
  %25 = and i32 %24, 15
  %26 = and i32 %23, -8388608
  %27 = sub i32 %.037, %26
  %28 = ashr i32 %23, 23
  %29 = zext nneg i32 %25 to i64
  %30 = getelementptr inbounds [16 x %struct.anon], ptr @__log2f_data, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !6
  %32 = getelementptr inbounds i8, ptr %30, i64 8
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = bitcast i32 %27 to float
  %35 = fpext float %34 to double
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %31, double -1.000000e+00)
  %37 = sitofp i32 %28 to double
  %38 = fadd double %33, %37
  %39 = fmul double %36, %36
  %40 = load double, ptr getelementptr inbounds (i8, ptr @__log2f_data, i64 264), align 8, !tbaa !12
  %41 = load double, ptr getelementptr inbounds (i8, ptr @__log2f_data, i64 272), align 8, !tbaa !12
  %42 = tail call double @llvm.fmuladd.f64(double %40, double %36, double %41)
  %43 = load double, ptr getelementptr inbounds (i8, ptr @__log2f_data, i64 256), align 8, !tbaa !12
  %44 = tail call double @llvm.fmuladd.f64(double %43, double %39, double %42)
  %45 = load double, ptr getelementptr inbounds (i8, ptr @__log2f_data, i64 280), align 8, !tbaa !12
  %46 = tail call double @llvm.fmuladd.f64(double %45, double %36, double %38)
  %47 = tail call double @llvm.fmuladd.f64(double %44, double %39, double %46)
  %48 = fptrunc double %47 to float
  %49 = tail call float @eval_as_float(float noundef %48)
  br label %50

50:                                               ; preds = %12, %1, %22, %16, %10
  %.0 = phi float [ %11, %10 ], [ %17, %16 ], [ %49, %22 ], [ 0.000000e+00, %1 ], [ %0, %12 ]
  ret float %.0
}

declare hidden float @__math_divzerof(i32 noundef) local_unnamed_addr #1

declare hidden float @__math_invalidf(float noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @eval_as_float(float noundef) local_unnamed_addr #3

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 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !8, i64 0}
!7 = !{!"", !8, i64 0, !8, i64 8}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!7, !8, i64 8}
!12 = !{!8, !8, i64 0}


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