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

; 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.logf_data = type { [16 x %struct.anon], double, [3 x double] }
%struct.anon = type { double, double }
%union.anon = type { float }
%union.anon.0 = type { float }
%union.anon.1 = type { i32 }

@__logf_data = external hidden constant %struct.logf_data, align 8

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

28:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %17, align 4
  br label %118

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

37:                                               ; preds = %29
  %38 = load i32, ptr %11, align 4, !tbaa !10
  %39 = mul i32 %38, 2
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = call float @__math_divzerof(i32 noundef 1)
  store float %42, ptr %2, align 4
  store i32 1, ptr %17, align 4
  br label %118

43:                                               ; preds = %37
  %44 = load i32, ptr %11, align 4, !tbaa !10
  %45 = icmp eq i32 %44, 2139095040
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = load float, ptr %3, align 4, !tbaa !5
  store float %47, ptr %2, align 4
  store i32 1, ptr %17, align 4
  br label %118

48:                                               ; preds = %43
  %49 = load i32, ptr %11, align 4, !tbaa !10
  %50 = and i32 %49, -2147483648
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %56, label %52

52:                                               ; preds = %48
  %53 = load i32, ptr %11, align 4, !tbaa !10
  %54 = mul i32 %53, 2
  %55 = icmp uge i32 %54, -16777216
  br i1 %55, label %56, label %59

56:                                               ; preds = %52, %48
  %57 = load float, ptr %3, align 4, !tbaa !5
  %58 = call float @__math_invalidf(float noundef %57)
  store float %58, ptr %2, align 4
  store i32 1, ptr %17, align 4
  br label %118

59:                                               ; preds = %52
  %60 = load float, ptr %3, align 4, !tbaa !5
  %61 = fmul float %60, 0x4160000000000000
  store float %61, ptr %18, align 4, !tbaa !9
  %62 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %62, ptr %11, align 4, !tbaa !10
  %63 = load i32, ptr %11, align 4, !tbaa !10
  %64 = sub i32 %63, 192937984
  store i32 %64, ptr %11, align 4, !tbaa !10
  br label %65

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

118:                                              ; preds = %65, %56, %46, %41, %28
  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 4, 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
  %119 = load float, ptr %2, align 4
  ret float %119
}

; 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}
!17 = !{!18, !14, i64 256}
!18 = !{!"logf_data", !7, i64 0, !14, i64 256, !7, i64 264}


; 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.logf_data = type { [16 x %struct.anon], double, [3 x double] }
%struct.anon = type { double, double }

@__logf_data = external hidden local_unnamed_addr constant %struct.logf_data, align 8

; Function Attrs: nounwind uwtable
define dso_local float @logf(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
  %.035 = phi i32 [ %21, %18 ], [ %2, %4 ]
  %23 = add i32 %.035, -1060306944
  %24 = lshr i32 %23, 19
  %25 = and i32 %24, 15
  %26 = ashr i32 %23, 23
  %27 = and i32 %23, -8388608
  %28 = sub i32 %.035, %27
  %29 = zext nneg i32 %25 to i64
  %30 = getelementptr inbounds [16 x %struct.anon], ptr @__logf_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 %28 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 %26 to double
  %38 = load double, ptr getelementptr inbounds (i8, ptr @__logf_data, i64 256), align 8, !tbaa !12
  %39 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %33)
  %40 = fmul double %36, %36
  %41 = load double, ptr getelementptr inbounds (i8, ptr @__logf_data, i64 272), align 8, !tbaa !14
  %42 = load double, ptr getelementptr inbounds (i8, ptr @__logf_data, i64 280), align 8, !tbaa !14
  %43 = tail call double @llvm.fmuladd.f64(double %41, double %36, double %42)
  %44 = load double, ptr getelementptr inbounds (i8, ptr @__logf_data, i64 264), align 8, !tbaa !14
  %45 = tail call double @llvm.fmuladd.f64(double %44, double %40, double %43)
  %46 = fadd double %39, %36
  %47 = tail call double @llvm.fmuladd.f64(double %45, double %40, 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 = !{!13, !8, i64 256}
!13 = !{!"logf_data", !9, i64 0, !8, i64 256, !9, i64 264}
!14 = !{!8, !8, i64 0}


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