; LLVM IR from VoidRune/Audio-engine :: src/minivorbis.ll (float32_pack)

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

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

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

; Function Attrs: nounwind
declare double @log(double noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @_float32_pack(float noundef %0) #3 {
  %2 = alloca float, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store float %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %6 = load float, ptr %2, align 4, !tbaa !5
  %7 = fcmp olt float %6, 0.000000e+00
  br i1 %7, label %8, label %11

8:                                                ; preds = %1
  store i32 -2147483648, ptr %3, align 4, !tbaa !9
  %9 = load float, ptr %2, align 4, !tbaa !5
  %10 = fneg float %9
  store float %10, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %8, %1
  %12 = load float, ptr %2, align 4, !tbaa !5
  %13 = fpext float %12 to double
  %14 = call double @log(double noundef %13) #4
  %15 = call double @log(double noundef 2.000000e+00) #4
  %16 = fdiv double %14, %15
  %17 = fadd double %16, 1.000000e-03
  %18 = call double @llvm.floor.f64(double %17)
  %19 = fptosi double %18 to i64
  store i64 %19, ptr %4, align 8, !tbaa !11
  %20 = load float, ptr %2, align 4, !tbaa !5
  %21 = fpext float %20 to double
  %22 = load i64, ptr %4, align 8, !tbaa !11
  %23 = sub nsw i64 20, %22
  %24 = trunc i64 %23 to i32
  %25 = call double @ldexp(double noundef %21, i32 noundef %24) #4
  %26 = call double @llvm.rint.f64(double %25)
  %27 = fptosi double %26 to i64
  store i64 %27, ptr %5, align 8, !tbaa !11
  %28 = load i64, ptr %4, align 8, !tbaa !11
  %29 = add nsw i64 %28, 768
  %30 = shl i64 %29, 21
  store i64 %30, ptr %4, align 8, !tbaa !11
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr %4, align 8, !tbaa !11
  %34 = or i64 %32, %33
  %35 = load i64, ptr %5, align 8, !tbaa !11
  %36 = or i64 %34, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i64 %36
}

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

; Function Attrs: nounwind
declare double @ldexp(double noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!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 = !{!12, !12, i64 0}
!12 = !{!"long", !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 nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local i64 @_float32_pack(float noundef %0) local_unnamed_addr #2 {
  %2 = fcmp olt float %0, 0.000000e+00
  %3 = fneg float %0
  %.08 = select i1 %2, i64 -2147483648, i64 0
  %.0 = select i1 %2, float %3, float %0
  %4 = fpext float %.0 to double
  %5 = tail call double @log(double noundef %4) #4
  %6 = fdiv double %5, 0x3FE62E42FEFA39EF
  %7 = fadd double %6, 1.000000e-03
  %8 = tail call double @llvm.floor.f64(double %7)
  %9 = fptosi double %8 to i64
  %10 = trunc i64 %9 to i32
  %11 = sub i32 20, %10
  %12 = tail call double @ldexp(double noundef %4, i32 noundef %11) #4
  %13 = tail call double @llvm.rint.f64(double %12)
  %14 = fptosi double %13 to i64
  %15 = shl i64 %9, 21
  %16 = add i64 %15, 1610612736
  %17 = or i64 %.08, %14
  %18 = or i64 %17, %16
  ret i64 %18
}

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

; Function Attrs: mustprogress nofree nounwind willreturn
declare double @ldexp(double noundef, i32 noundef) local_unnamed_addr #3

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


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