; LLVM IR from nde-jesu/Doom_Nukem :: srcs/utils (ft_power)

; 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: nounwind uwtable
define dso_local double @ft_power(double noundef %0, i32 noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store double 1.000000e+00, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

11:                                               ; preds = %2
  %12 = load double, ptr %4, align 8, !tbaa !5
  store double %12, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %26

15:                                               ; preds = %11
  br label %16

16:                                               ; preds = %19, %15
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = load double, ptr %6, align 8, !tbaa !5
  %22 = fmul double %20, %21
  store double %22, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %5, align 4, !tbaa !9
  br label %16, !llvm.loop !11

25:                                               ; preds = %16
  br label %41

26:                                               ; preds = %11
  %27 = load double, ptr %4, align 8, !tbaa !5
  %28 = fdiv double 1.000000e+00, %27
  store double %28, ptr %6, align 8, !tbaa !5
  %29 = load double, ptr %4, align 8, !tbaa !5
  %30 = fdiv double 1.000000e+00, %29
  store double %30, ptr %4, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %34, %26
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp slt i32 %32, -1
  br i1 %33, label %34, label %40

34:                                               ; preds = %31
  %35 = load double, ptr %4, align 8, !tbaa !5
  %36 = load double, ptr %6, align 8, !tbaa !5
  %37 = fmul double %35, %36
  store double %37, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %31, !llvm.loop !13

40:                                               ; preds = %31
  br label %41

41:                                               ; preds = %40, %25
  %42 = load double, ptr %4, align 8, !tbaa !5
  store double %42, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %41, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %44 = load double, ptr %3, align 8
  ret double %44
}

; 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 = !{!"double", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 double @ft_power(double noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.preheader, label %22

.preheader:                                       ; preds = %4
  %.not = icmp eq i32 %1, 1
  br i1 %.not, label %.loopexit, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %.preheader
  %6 = add nuw i32 %1, 7
  %7 = add nsw i32 %1, -2
  %xtraiter34 = and i32 %6, 7
  %lcmp.mod35.not = icmp eq i32 %xtraiter34, 0
  br i1 %lcmp.mod35.not, label %.lr.ph23.prol.loopexit, label %.lr.ph23.prol

.lr.ph23.prol:                                    ; preds = %.lr.ph23.preheader, %.lr.ph23.prol
  %.022.prol = phi i32 [ %9, %.lr.ph23.prol ], [ %1, %.lr.ph23.preheader ]
  %.01421.prol = phi double [ %8, %.lr.ph23.prol ], [ %0, %.lr.ph23.preheader ]
  %prol.iter36 = phi i32 [ %prol.iter36.next, %.lr.ph23.prol ], [ 0, %.lr.ph23.preheader ]
  %8 = fmul double %.01421.prol, %0
  %9 = add nsw i32 %.022.prol, -1
  %prol.iter36.next = add i32 %prol.iter36, 1
  %prol.iter36.cmp.not = icmp eq i32 %prol.iter36.next, %xtraiter34
  br i1 %prol.iter36.cmp.not, label %.lr.ph23.prol.loopexit, label %.lr.ph23.prol, !llvm.loop !5

.lr.ph23.prol.loopexit:                           ; preds = %.lr.ph23.prol, %.lr.ph23.preheader
  %.022.unr = phi i32 [ %1, %.lr.ph23.preheader ], [ %9, %.lr.ph23.prol ]
  %.01421.unr = phi double [ %0, %.lr.ph23.preheader ], [ %8, %.lr.ph23.prol ]
  %.lcssa.unr = phi double [ poison, %.lr.ph23.preheader ], [ %8, %.lr.ph23.prol ]
  %10 = icmp ult i32 %7, 7
  br i1 %10, label %.loopexit, label %.lr.ph23

.lr.ph23:                                         ; preds = %.lr.ph23.prol.loopexit, %.lr.ph23
  %.022 = phi i32 [ %19, %.lr.ph23 ], [ %.022.unr, %.lr.ph23.prol.loopexit ]
  %.01421 = phi double [ %18, %.lr.ph23 ], [ %.01421.unr, %.lr.ph23.prol.loopexit ]
  %11 = fmul double %.01421, %0
  %12 = fmul double %11, %0
  %13 = fmul double %12, %0
  %14 = fmul double %13, %0
  %15 = fmul double %14, %0
  %16 = fmul double %15, %0
  %17 = fmul double %16, %0
  %18 = fmul double %17, %0
  %19 = add nsw i32 %.022, -8
  %20 = add i32 %.022, -10
  %21 = icmp ult i32 %20, -3
  br i1 %21, label %.lr.ph23, label %.loopexit, !llvm.loop !7

22:                                               ; preds = %4
  %23 = fdiv double 1.000000e+00, %0
  %.not29 = icmp eq i32 %1, -1
  br i1 %.not29, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %22
  %24 = and i32 %1, 7
  %lcmp.mod.not = icmp eq i32 %24, 7
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.120.prol = phi i32 [ %26, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %.11519.prol = phi double [ %25, %.lr.ph.prol ], [ %23, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %25 = fmul double %23, %.11519.prol
  %26 = add nuw i32 %.120.prol, 1
  %prol.iter.next = add i32 %prol.iter, 1
  %27 = xor i32 %24, %prol.iter.next
  %prol.iter.cmp.not = icmp eq i32 %27, 7
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa33.unr = phi double [ poison, %.lr.ph.preheader ], [ %25, %.lr.ph.prol ]
  %.120.unr = phi i32 [ %1, %.lr.ph.preheader ], [ %26, %.lr.ph.prol ]
  %.11519.unr = phi double [ %23, %.lr.ph.preheader ], [ %25, %.lr.ph.prol ]
  %28 = add i32 %1, 8
  %29 = icmp ult i32 %28, 7
  br i1 %29, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.120 = phi i32 [ %38, %.lr.ph ], [ %.120.unr, %.lr.ph.prol.loopexit ]
  %.11519 = phi double [ %37, %.lr.ph ], [ %.11519.unr, %.lr.ph.prol.loopexit ]
  %30 = fmul double %23, %.11519
  %31 = fmul double %23, %30
  %32 = fmul double %23, %31
  %33 = fmul double %23, %32
  %34 = fmul double %23, %33
  %35 = fmul double %23, %34
  %36 = fmul double %23, %35
  %37 = fmul double %23, %36
  %38 = add nuw i32 %.120, 8
  %exitcond.not.7 = icmp eq i32 %38, -1
  br i1 %exitcond.not.7, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph23.prol.loopexit, %.lr.ph23, %22, %.preheader, %2
  %.016 = phi double [ 1.000000e+00, %2 ], [ %0, %.preheader ], [ %23, %22 ], [ %.lcssa.unr, %.lr.ph23.prol.loopexit ], [ %18, %.lr.ph23 ], [ %.lcssa33.unr, %.lr.ph.prol.loopexit ], [ %37, %.lr.ph ]
  ret double %.016
}

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

!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.unroll.disable"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.mustprogress"}
!9 = distinct !{!9, !6}
!10 = distinct !{!10, !8}


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