; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Week of Code/Week 25/Problem E/E.ll (Z5solved)

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

@resy = external dso_local global double, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z4funcdd(double noundef, double noundef) #0

; 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: mustprogress uwtable
define dso_local noundef double @_Z5solved(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 double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store double -1.000000e+04, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store double 1.000000e+04, 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 %10

10:                                               ; preds = %37, %1
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 60
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %40

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = fmul double %16, 0x3FDD1745D1745D17
  %18 = call double @llvm.fmuladd.f64(double %15, double 0x3FE1745D1745D174, double %17)
  store double %18, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load double, ptr %4, align 8, !tbaa !5
  %20 = load double, ptr %3, align 8, !tbaa !5
  %21 = fmul double %20, 0x3FDD1745D1745D17
  %22 = call double @llvm.fmuladd.f64(double %19, double 0x3FE1745D1745D174, double %21)
  store double %22, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = load double, ptr %6, align 8, !tbaa !5
  %25 = call noundef double @_Z4funcdd(double noundef %23, double noundef %24)
  store double %25, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = load double, ptr %2, align 8, !tbaa !5
  %27 = load double, ptr %7, align 8, !tbaa !5
  %28 = call noundef double @_Z4funcdd(double noundef %26, double noundef %27)
  store double %28, ptr %9, align 8, !tbaa !5
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = load double, ptr %9, align 8, !tbaa !5
  %31 = fcmp ole double %29, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %14
  %33 = load double, ptr %7, align 8, !tbaa !5
  store double %33, ptr %4, align 8, !tbaa !5
  br label %36

34:                                               ; preds = %14
  %35 = load double, ptr %6, align 8, !tbaa !5
  store double %35, ptr %3, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %34, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %37

37:                                               ; preds = %36
  %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 %10, !llvm.loop !11

40:                                               ; preds = %13
  %41 = load double, ptr %3, align 8, !tbaa !5
  %42 = load double, ptr %4, align 8, !tbaa !5
  %43 = fadd double %41, %42
  %44 = fdiv double %43, 2.000000e+00
  store double %44, ptr @resy, align 8, !tbaa !5
  %45 = load double, ptr %2, align 8, !tbaa !5
  %46 = load double, ptr @resy, align 8, !tbaa !5
  %47 = call noundef double @_Z4funcdd(double noundef %45, double noundef %46)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %47
}

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

attributes #0 = { mustprogress 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"}


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

@resy = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z4funcdd(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z5solved(double noundef %0) local_unnamed_addr #0 {
  br label %6

2:                                                ; preds = %6
  %3 = fadd double %.016., %..0
  %4 = fmul double %3, 5.000000e-01
  store double %4, ptr @resy, align 8, !tbaa !5
  %5 = tail call noundef double @_Z4funcdd(double noundef %0, double noundef %4)
  ret double %5

6:                                                ; preds = %1, %6
  %.021 = phi double [ -1.000000e+04, %1 ], [ %..0, %6 ]
  %.01620 = phi double [ 1.000000e+04, %1 ], [ %.016., %6 ]
  %.01819 = phi i32 [ 0, %1 ], [ %14, %6 ]
  %7 = fmul double %.01620, 0x3FDD1745D1745D17
  %8 = tail call double @llvm.fmuladd.f64(double %.021, double 0x3FE1745D1745D174, double %7)
  %9 = fmul double %.021, 0x3FDD1745D1745D17
  %10 = tail call double @llvm.fmuladd.f64(double %.01620, double 0x3FE1745D1745D174, double %9)
  %11 = tail call noundef double @_Z4funcdd(double noundef %0, double noundef %8)
  %12 = tail call noundef double @_Z4funcdd(double noundef %0, double noundef %10)
  %13 = fcmp ugt double %11, %12
  %.016. = select i1 %13, double %.01620, double %10
  %..0 = select i1 %13, double %8, double %.021
  %14 = add nuw nsw i32 %.01819, 1
  %exitcond.not = icmp eq i32 %14, 60
  br i1 %exitcond.not, label %2, label %6, !llvm.loop !9
}

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

attributes #0 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass