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

; 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 @ldexp(double noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local float @_float32_unpack(i64 noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = and i64 %6, 2097151
  %8 = sitofp i64 %7 to double
  store double %8, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = and i64 %9, 2147483648
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = and i64 %12, 2145386496
  %14 = ashr i64 %13, 21
  store i64 %14, ptr %5, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !11
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  %18 = load double, ptr %3, align 8, !tbaa !9
  %19 = fneg double %18
  store double %19, ptr %3, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %17, %1
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = sub nsw i64 %21, 20
  %23 = sub nsw i64 %22, 768
  store i64 %23, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = icmp sgt i64 %24, 63
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i64 63, ptr %5, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %26, %20
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = icmp slt i64 %28, -63
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i64 -63, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %30, %27
  %32 = load double, ptr %3, align 8, !tbaa !9
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = trunc i64 %33 to i32
  %35 = call double @ldexp(double noundef %32, i32 noundef %34) #3
  %36 = fptrunc double %35 to float
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret float %36
}

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 = { 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

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

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local float @_float32_unpack(i64 noundef %0) local_unnamed_addr #1 {
  %2 = and i64 %0, 2097151
  %3 = uitofp nneg i64 %2 to double
  %4 = and i64 %0, 2147483648
  %.not = icmp eq i64 %4, 0
  %5 = fneg double %3
  %.0 = select i1 %.not, double %3, double %5
  %6 = lshr i64 %0, 21
  %7 = and i64 %6, 1023
  %8 = tail call i64 @llvm.umin.i64(i64 %7, i64 851)
  %9 = tail call i64 @llvm.umax.i64(i64 %8, i64 725)
  %10 = trunc nuw nsw i64 %9 to i32
  %11 = add nsw i32 %10, -788
  %12 = tail call double @ldexp(double noundef %.0, i32 noundef %11) #3
  %13 = fptrunc double %12 to float
  ret float %13
}

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

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

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass