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

; 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 { float }

; Function Attrs: nounwind uwtable
define dso_local float @scalbnf(float noundef %0, i32 noundef %1) #0 {
  %3 = alloca float, align 4
  %4 = alloca i32, align 4
  %5 = alloca %union.anon, align 4
  %6 = alloca float, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %7 = load float, ptr %3, align 4, !tbaa !5
  store float %7, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 127
  br i1 %9, label %10, label %27

10:                                               ; preds = %2
  %11 = load float, ptr %6, align 4, !tbaa !5
  %12 = fmul float %11, 0x47E0000000000000
  store float %12, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sub nsw i32 %13, 127
  store i32 %14, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 127
  br i1 %16, label %17, label %26

17:                                               ; preds = %10
  %18 = load float, ptr %6, align 4, !tbaa !5
  %19 = fmul float %18, 0x47E0000000000000
  store float %19, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 127
  store i32 %21, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = icmp sgt i32 %22, 127
  br i1 %23, label %24, label %25

24:                                               ; preds = %17
  store i32 127, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %24, %17
  br label %26

26:                                               ; preds = %25, %10
  br label %48

27:                                               ; preds = %2
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = icmp slt i32 %28, -126
  br i1 %29, label %30, label %47

30:                                               ; preds = %27
  %31 = load float, ptr %6, align 4, !tbaa !5
  %32 = fmul float %31, 0x3810000000000000
  store float %32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %33, 126
  store i32 %34, ptr %4, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp slt i32 %35, -126
  br i1 %36, label %37, label %46

37:                                               ; preds = %30
  %38 = load float, ptr %6, align 4, !tbaa !5
  %39 = fmul float %38, 0x3810000000000000
  store float %39, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = add nsw i32 %40, 126
  store i32 %41, ptr %4, align 4, !tbaa !9
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = icmp slt i32 %42, -126
  br i1 %43, label %44, label %45

44:                                               ; preds = %37
  store i32 -126, ptr %4, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %44, %37
  br label %46

46:                                               ; preds = %45, %30
  br label %47

47:                                               ; preds = %46, %27
  br label %48

48:                                               ; preds = %47, %26
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = add nsw i32 127, %49
  %51 = shl i32 %50, 23
  store i32 %51, ptr %5, align 4, !tbaa !11
  %52 = load float, ptr %6, align 4, !tbaa !5
  %53 = load float, ptr %5, align 4, !tbaa !11
  %54 = fmul float %52, %53
  store float %54, ptr %3, align 4, !tbaa !5
  %55 = load float, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret float %55
}

; 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

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}
!11 = !{!7, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local float @scalbnf(float noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 127
  br i1 %3, label %4, label %11

4:                                                ; preds = %2
  %5 = fmul float %0, 0x47E0000000000000
  %6 = add nsw i32 %1, -127
  %7 = icmp ugt i32 %1, 254
  br i1 %7, label %8, label %20

8:                                                ; preds = %4
  %9 = fmul float %5, 0x47E0000000000000
  %10 = tail call i32 @llvm.umin.i32(i32 %1, i32 381)
  %spec.store.select = add nsw i32 %10, -254
  br label %20

11:                                               ; preds = %2
  %12 = icmp slt i32 %1, -126
  br i1 %12, label %13, label %20

13:                                               ; preds = %11
  %14 = fmul float %0, 0x3810000000000000
  %15 = add nuw nsw i32 %1, 126
  %16 = icmp ult i32 %1, -252
  br i1 %16, label %17, label %20

17:                                               ; preds = %13
  %18 = fmul float %14, 0x3810000000000000
  %19 = tail call i32 @llvm.umax.i32(i32 %1, i32 -378)
  %spec.store.select1 = add nuw nsw i32 %19, 252
  br label %20

20:                                               ; preds = %11, %17, %13, %4, %8
  %.018 = phi i32 [ %spec.store.select, %8 ], [ %6, %4 ], [ %spec.store.select1, %17 ], [ %15, %13 ], [ %1, %11 ]
  %.0 = phi float [ %9, %8 ], [ %5, %4 ], [ %18, %17 ], [ %14, %13 ], [ %0, %11 ]
  %21 = shl nsw i32 %.018, 23
  %22 = add i32 %21, 1065353216
  %23 = bitcast i32 %22 to float
  %24 = fmul float %.0, %23
  ret float %24
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 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: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass