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

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

@resx = external dso_local global double, align 8

; 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: mustprogress uwtable
declare dso_local noundef double @_Z5solved(double noundef) #1

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

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

8:                                                ; preds = %33, %0
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 60
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %36

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

28:                                               ; preds = %12
  %29 = load double, ptr %5, align 8, !tbaa !5
  store double %29, ptr %2, align 8, !tbaa !5
  br label %32

30:                                               ; preds = %12
  %31 = load double, ptr %4, align 8, !tbaa !5
  store double %31, ptr %1, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %30, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !11

36:                                               ; preds = %11
  %37 = load double, ptr %1, align 8, !tbaa !5
  %38 = load double, ptr %2, align 8, !tbaa !5
  %39 = fadd double %37, %38
  %40 = fdiv double %39, 2.000000e+00
  store double %40, ptr @resx, align 8, !tbaa !5
  %41 = load double, ptr @resx, align 8, !tbaa !5
  %42 = call noundef double @_Z5solved(double noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret double %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"

@resx = external dso_local local_unnamed_addr global double, align 8

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

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

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

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

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

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