; LLVM IR from sbu-fsl/kernel-ml :: src/math (math)

; 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 uwtable
define dso_local float @power(float noundef %0, i32 noundef %1) #1 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store float %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !13
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  store i8 1, ptr %7, align 1, !tbaa !13
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = mul nsw i32 %12, -1
  store i32 %13, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %11, %2
  br label %15

15:                                               ; preds = %27, %14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %33

18:                                               ; preds = %15
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = and i32 %19, 1
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %18
  %23 = load float, ptr %4, align 4, !tbaa !5
  %24 = fpext float %23 to double
  %25 = load double, ptr %6, align 8, !tbaa !11
  %26 = fmul double %25, %24
  store double %26, ptr %6, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %22, %18
  %28 = load float, ptr %4, align 4, !tbaa !5
  %29 = load float, ptr %4, align 4, !tbaa !5
  %30 = fmul float %29, %28
  store float %30, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = ashr i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !15

33:                                               ; preds = %15
  %34 = load i8, ptr %7, align 1, !tbaa !13, !range !17, !noundef !18
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %40

36:                                               ; preds = %33
  %37 = load double, ptr %6, align 8, !tbaa !11
  %38 = fdiv double 1.000000e+00, %37
  %39 = fptrunc double %38 to float
  store float %39, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %43

40:                                               ; preds = %33
  %41 = load double, ptr %6, align 8, !tbaa !11
  %42 = fptrunc double %41 to float
  store float %42, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %40, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %44 = load float, ptr %3, align 4
  ret float %44
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}


; 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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local float @power(float noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not1920 = icmp eq i32 %1, 0
  br i1 %.not1920, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %spec.select = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01223 = phi double [ %.1, %.lr.ph ], [ 1.000000e+00, %.lr.ph.preheader ]
  %.11422 = phi i32 [ %7, %.lr.ph ], [ %spec.select, %.lr.ph.preheader ]
  %.01521 = phi float [ %6, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %3 = and i32 %.11422, 1
  %.not = icmp eq i32 %3, 0
  %4 = fpext float %.01521 to double
  %5 = fmul double %.01223, %4
  %.1 = select i1 %.not, double %.01223, double %5
  %6 = fmul float %.01521, %.01521
  %7 = lshr i32 %.11422, 1
  %.not19 = icmp ult i32 %.11422, 2
  br i1 %.not19, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.012.lcssa = phi double [ 1.000000e+00, %2 ], [ %.1, %.lr.ph ]
  %8 = icmp slt i32 %1, 0
  %9 = fdiv double 1.000000e+00, %.012.lcssa
  %.016.in = select i1 %8, double %9, double %.012.lcssa
  %.016 = fptrunc double %.016.in to float
  ret float %.016
}

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

attributes #0 = { nofree norecurse nosync nounwind 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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass