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

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

@half = external hidden constant [2 x float], align 4

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

14:                                               ; preds = %1
  %15 = load float, ptr %3, align 4, !tbaa !5
  store float %15, ptr %12, align 4, !tbaa !9
  %16 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %16, ptr %11, align 4, !tbaa !10
  br label %17

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %11, align 4, !tbaa !10
  %20 = lshr i32 %19, 31
  store i32 %20, ptr %10, align 4, !tbaa !10
  %21 = load i32, ptr %11, align 4, !tbaa !10
  %22 = and i32 %21, 2147483647
  store i32 %22, ptr %11, align 4, !tbaa !10
  %23 = load i32, ptr %11, align 4, !tbaa !10
  %24 = icmp uge i32 %23, 1118743632
  br i1 %24, label %25, label %49

25:                                               ; preds = %18
  %26 = load i32, ptr %11, align 4, !tbaa !10
  %27 = icmp uge i32 %26, 1118925336
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i32, ptr %10, align 4, !tbaa !10
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %35, label %31

31:                                               ; preds = %28
  %32 = load float, ptr %3, align 4, !tbaa !5
  %33 = fmul float %32, 0x47E0000000000000
  store float %33, ptr %3, align 4, !tbaa !5
  %34 = load float, ptr %3, align 4, !tbaa !5
  store float %34, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %123

35:                                               ; preds = %28, %25
  %36 = load i32, ptr %10, align 4, !tbaa !10
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %48

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  %40 = load float, ptr %3, align 4, !tbaa !5
  %41 = fdiv float 0xB6A0000000000000, %40
  call void @fp_force_evalf(float noundef %41)
  br label %42

42:                                               ; preds = %39
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %11, align 4, !tbaa !10
  %45 = icmp uge i32 %44, 1120924085
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %123

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %47, %35
  br label %49

49:                                               ; preds = %48, %18
  %50 = load i32, ptr %11, align 4, !tbaa !10
  %51 = icmp ugt i32 %50, 1051816472
  br i1 %51, label %52, label %80

52:                                               ; preds = %49
  %53 = load i32, ptr %11, align 4, !tbaa !10
  %54 = icmp ugt i32 %53, 1065686418
  br i1 %54, label %55, label %63

55:                                               ; preds = %52
  %56 = load float, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !10
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2 x float], ptr @half, i64 0, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !5
  %61 = call float @llvm.fmuladd.f32(float 0x3FF7154760000000, float %56, float %60)
  %62 = fptosi float %61 to i32
  store i32 %62, ptr %9, align 4, !tbaa !10
  br label %68

63:                                               ; preds = %52
  %64 = load i32, ptr %10, align 4, !tbaa !10
  %65 = sub nsw i32 1, %64
  %66 = load i32, ptr %10, align 4, !tbaa !10
  %67 = sub nsw i32 %65, %66
  store i32 %67, ptr %9, align 4, !tbaa !10
  br label %68

68:                                               ; preds = %63, %55
  %69 = load float, ptr %3, align 4, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !10
  %71 = sitofp i32 %70 to float
  %72 = fneg float %71
  %73 = call float @llvm.fmuladd.f32(float %72, float 0x3FE62E4000000000, float %69)
  store float %73, ptr %4, align 4, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !10
  %75 = sitofp i32 %74 to float
  %76 = fmul float %75, 0x3EB7F7D1C0000000
  store float %76, ptr %5, align 4, !tbaa !5
  %77 = load float, ptr %4, align 4, !tbaa !5
  %78 = load float, ptr %5, align 4, !tbaa !5
  %79 = fsub float %77, %78
  store float %79, ptr %3, align 4, !tbaa !5
  br label %94

80:                                               ; preds = %49
  %81 = load i32, ptr %11, align 4, !tbaa !10
  %82 = icmp ugt i32 %81, 956301312
  br i1 %82, label %83, label %85

83:                                               ; preds = %80
  store i32 0, ptr %9, align 4, !tbaa !10
  %84 = load float, ptr %3, align 4, !tbaa !5
  store float %84, ptr %4, align 4, !tbaa !5
  store float 0.000000e+00, ptr %5, align 4, !tbaa !5
  br label %93

85:                                               ; preds = %80
  br label %86

86:                                               ; preds = %85
  %87 = load float, ptr %3, align 4, !tbaa !5
  %88 = fadd float 0x47E0000000000000, %87
  call void @fp_force_evalf(float noundef %88)
  br label %89

89:                                               ; preds = %86
  br label %90

90:                                               ; preds = %89
  %91 = load float, ptr %3, align 4, !tbaa !5
  %92 = fadd float 1.000000e+00, %91
  store float %92, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %123

93:                                               ; preds = %83
  br label %94

94:                                               ; preds = %93, %68
  %95 = load float, ptr %3, align 4, !tbaa !5
  %96 = load float, ptr %3, align 4, !tbaa !5
  %97 = fmul float %95, %96
  store float %97, ptr %7, align 4, !tbaa !5
  %98 = load float, ptr %3, align 4, !tbaa !5
  %99 = load float, ptr %7, align 4, !tbaa !5
  %100 = load float, ptr %7, align 4, !tbaa !5
  %101 = call float @llvm.fmuladd.f32(float %100, float 0xBF66AA42A0000000, float 0x3FC55551E0000000)
  %102 = fneg float %99
  %103 = call float @llvm.fmuladd.f32(float %102, float %101, float %98)
  store float %103, ptr %6, align 4, !tbaa !5
  %104 = load float, ptr %3, align 4, !tbaa !5
  %105 = load float, ptr %6, align 4, !tbaa !5
  %106 = fmul float %104, %105
  %107 = load float, ptr %6, align 4, !tbaa !5
  %108 = fsub float 2.000000e+00, %107
  %109 = fdiv float %106, %108
  %110 = load float, ptr %5, align 4, !tbaa !5
  %111 = fsub float %109, %110
  %112 = load float, ptr %4, align 4, !tbaa !5
  %113 = fadd float %111, %112
  %114 = fadd float 1.000000e+00, %113
  store float %114, ptr %8, align 4, !tbaa !5
  %115 = load i32, ptr %9, align 4, !tbaa !10
  %116 = icmp eq i32 %115, 0
  br i1 %116, label %117, label %119

117:                                              ; preds = %94
  %118 = load float, ptr %8, align 4, !tbaa !5
  store float %118, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %123

119:                                              ; preds = %94
  %120 = load float, ptr %8, align 4, !tbaa !5
  %121 = load i32, ptr %9, align 4, !tbaa !10
  %122 = call float @scalbnf(float noundef %120, i32 noundef %121) #5
  store float %122, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %123

123:                                              ; preds = %119, %117, %90, %46, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %124 = load float, ptr %2, align 4
  ret float %124
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fp_force_evalf(float noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: nounwind
declare float @scalbnf(float noundef, i32 noundef) #4

; 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind "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 #5 = { 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}


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

@half = external hidden local_unnamed_addr constant [2 x float], align 4

; Function Attrs: nounwind uwtable
define dso_local float @expf(float noundef %0) local_unnamed_addr #0 {
  %2 = bitcast float %0 to i32
  %3 = lshr i32 %2, 31
  %4 = tail call float @llvm.fabs.f32(float %0)
  %5 = bitcast float %4 to i32
  %6 = icmp ugt i32 %5, 1118743631
  br i1 %6, label %7, label %16

7:                                                ; preds = %1
  %8 = icmp ult i32 %5, 1118925336
  %9 = icmp slt i32 %2, 0
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %12, label %10

10:                                               ; preds = %7
  %11 = fmul float %0, 0x47E0000000000000
  br label %53

12:                                               ; preds = %7
  br i1 %9, label %13, label %.thread47

13:                                               ; preds = %12
  %14 = fdiv float 0xB6A0000000000000, %0
  tail call void @fp_force_evalf(float noundef %14)
  %15 = icmp ugt i32 %5, 1120924084
  br i1 %15, label %53, label %.thread47

16:                                               ; preds = %1
  %17 = icmp ugt i32 %5, 1051816472
  br i1 %17, label %18, label %34

18:                                               ; preds = %16
  %19 = icmp ugt i32 %5, 1065686418
  br i1 %19, label %.thread47, label %25

.thread47:                                        ; preds = %12, %13, %18
  %20 = zext nneg i32 %3 to i64
  %21 = getelementptr inbounds [2 x float], ptr @half, i64 0, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !5
  %23 = tail call float @llvm.fmuladd.f32(float %0, float 0x3FF7154760000000, float %22)
  %24 = fptosi float %23 to i32
  br label %28

25:                                               ; preds = %18
  %26 = xor i32 %3, 1
  %27 = sub nsw i32 %26, %3
  br label %28

28:                                               ; preds = %25, %.thread47
  %.042 = phi i32 [ %24, %.thread47 ], [ %27, %25 ]
  %29 = sitofp i32 %.042 to float
  %30 = fneg float %29
  %31 = tail call float @llvm.fmuladd.f32(float %30, float 0x3FE62E4000000000, float %0)
  %32 = fmul float %29, 0x3EB7F7D1C0000000
  %33 = fsub float %31, %32
  br label %39

34:                                               ; preds = %16
  %35 = icmp ugt i32 %5, 956301312
  br i1 %35, label %39, label %36

36:                                               ; preds = %34
  %37 = fadd float %0, 0x47E0000000000000
  tail call void @fp_force_evalf(float noundef %37)
  %38 = fadd float %0, 1.000000e+00
  br label %53

39:                                               ; preds = %34, %28
  %.044 = phi float [ %32, %28 ], [ 0.000000e+00, %34 ]
  %.043 = phi float [ %31, %28 ], [ %0, %34 ]
  %.1 = phi i32 [ %.042, %28 ], [ 0, %34 ]
  %.041 = phi float [ %33, %28 ], [ %0, %34 ]
  %40 = fmul float %.041, %.041
  %41 = tail call float @llvm.fmuladd.f32(float %40, float 0xBF66AA42A0000000, float 0x3FC55551E0000000)
  %42 = fneg float %40
  %43 = tail call float @llvm.fmuladd.f32(float %42, float %41, float %.041)
  %44 = fmul float %.041, %43
  %45 = fsub float 2.000000e+00, %43
  %46 = fdiv float %44, %45
  %47 = fsub float %46, %.044
  %48 = fadd float %.043, %47
  %49 = fadd float %48, 1.000000e+00
  %50 = icmp eq i32 %.1, 0
  br i1 %50, label %53, label %51

51:                                               ; preds = %39
  %52 = tail call float @scalbnf(float noundef %49, i32 noundef %.1) #5
  br label %53

53:                                               ; preds = %39, %13, %51, %36, %10
  %.0 = phi float [ %52, %51 ], [ %38, %36 ], [ %11, %10 ], [ 0.000000e+00, %13 ], [ %49, %39 ]
  ret float %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fp_force_evalf(float noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare float @scalbnf(float noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #4

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind "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 = { 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"}


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