; LLVM IR from abeaumont/competitive-programming :: aceptaelreto/103.ll (Z1fd)

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

@p = external dso_local global [20 x i32], align 16
@n = external dso_local global i32, align 4

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

9:                                                ; preds = %36, %1
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %39

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 1.000000e+00, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %24, %14
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %27

20:                                               ; preds = %15
  %21 = load double, ptr %3, align 8, !tbaa !5
  %22 = load double, ptr %7, align 8, !tbaa !5
  %23 = fmul double %22, %21
  store double %23, ptr %7, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !11

27:                                               ; preds = %19
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sitofp i32 %32 to double
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = call double @llvm.fmuladd.f64(double %28, double %33, double %34)
  store double %35, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %36

36:                                               ; preds = %27
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !13

39:                                               ; preds = %13
  %40 = load double, ptr %4, align 8, !tbaa !5
  %41 = fcmp olt double %40, 0.000000e+00
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store double 0.000000e+00, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %49

43:                                               ; preds = %39
  %44 = load double, ptr %4, align 8, !tbaa !5
  %45 = fcmp ogt double %44, 1.000000e+00
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store double 1.000000e+00, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %49

47:                                               ; preds = %43
  %48 = load double, ptr %4, align 8, !tbaa !5
  store double %48, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %49

49:                                               ; preds = %47, %46, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %50 = load double, ptr %2, align 8
  ret double %50
}

; 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

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

attributes #0 = { mustprogress 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 = { 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"

@p = external dso_local local_unnamed_addr global [20 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef double @_Z1fd(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not19 = icmp slt i32 %2, 0
  br i1 %.not19, label %._crit_edge22, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %3 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %3 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %.01520 = phi double [ 0.000000e+00, %.preheader.preheader ], [ %11, %._crit_edge ]
  %.not24 = icmp eq i64 %indvars.iv, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %xtraiter = and i64 %indvars.iv, 7
  %4 = icmp ult i64 %indvars.iv, 8
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %indvars.iv, 9223372036854775800
  br label %.lr.ph

._crit_edge22:                                    ; preds = %._crit_edge, %1
  %.015.lcssa = phi double [ 0.000000e+00, %1 ], [ %11, %._crit_edge ]
  %5 = fcmp olt double %.015.lcssa, 0.000000e+00
  %6 = fcmp ogt double %.015.lcssa, 1.000000e+00
  %..015 = select i1 %6, double 1.000000e+00, double %.015.lcssa
  %.016 = select i1 %5, double 0.000000e+00, double %..015
  ret double %.016

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %.01317.unr = phi double [ 1.000000e+00, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.01317.epil = phi double [ %7, %.lr.ph.epil ], [ %.01317.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %7 = fmul double %.01317.epil, %0
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader
  %.013.lcssa = phi double [ 1.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %7, %.lr.ph.epil ]
  %8 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sitofp i32 %9 to double
  %11 = tail call double @llvm.fmuladd.f64(double %.013.lcssa, double %10, double %.01520)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond27.not, label %._crit_edge22, label %.preheader, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01317 = phi double [ 1.000000e+00, %.lr.ph.preheader.new ], [ %19, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %12 = fmul double %.01317, %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 = fmul double %18, %0
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: 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 = { mustprogress 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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