; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 01. Mathematics/get together.ll (Z4goodd)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@n = external dso_local global i64, align 8
@pos = external dso_local global %"class.std::vector", align 8
@speed = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z4goodd(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef 0) #3
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = sitofp i64 %9 to double
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef 0) #3
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = sitofp i64 %12 to double
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fneg double %13
  %16 = call double @llvm.fmuladd.f64(double %15, double %14, double %10)
  store double %16, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef 0) #3
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = sitofp i64 %18 to double
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef 0) #3
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = sitofp i64 %21 to double
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = call double @llvm.fmuladd.f64(double %22, double %23, double %19)
  store double %24, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 1, ptr %5, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %64, %1
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = load i64, ptr @n, align 8, !tbaa !9
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %67

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef %31) #3
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = sitofp i64 %33 to double
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef %35) #3
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = sitofp i64 %37 to double
  %39 = load double, ptr %2, align 8, !tbaa !5
  %40 = fneg double %38
  %41 = call double @llvm.fmuladd.f64(double %40, double %39, double %34)
  store double %41, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef %42) #3
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = sitofp i64 %44 to double
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef %46) #3
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = sitofp i64 %48 to double
  %50 = load double, ptr %2, align 8, !tbaa !5
  %51 = call double @llvm.fmuladd.f64(double %49, double %50, double %45)
  store double %51, ptr %7, align 8, !tbaa !5
  %52 = load double, ptr %4, align 8, !tbaa !5
  %53 = load double, ptr %7, align 8, !tbaa !5
  %54 = fcmp ogt double %52, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %30
  %56 = load double, ptr %7, align 8, !tbaa !5
  store double %56, ptr %4, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %55, %30
  %58 = load double, ptr %3, align 8, !tbaa !5
  %59 = load double, ptr %6, align 8, !tbaa !5
  %60 = fcmp olt double %58, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %57
  %62 = load double, ptr %6, align 8, !tbaa !5
  store double %62, ptr %3, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %61, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %5, align 8, !tbaa !9
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %5, align 8, !tbaa !9
  br label %25, !llvm.loop !11

67:                                               ; preds = %29
  %68 = load double, ptr %4, align 8, !tbaa !5
  %69 = load double, ptr %3, align 8, !tbaa !5
  %70 = fsub double %68, %69
  %71 = fcmp ogt double %70, 0x3E7AD7F29ABCAF48
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i1 %71
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = !{!"long long", !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@n = external dso_local local_unnamed_addr global i64, align 8
@pos = external dso_local global %"class.std::vector", align 8
@speed = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z4goodd(double noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef 0) #2
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = sitofp i64 %3 to double
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef 0) #2
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = sitofp i64 %6 to double
  %8 = fneg double %7
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %0, double %4)
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef 0) #2
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = sitofp i64 %11 to double
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef 0) #2
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = sitofp i64 %14 to double
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %0, double %12)
  %17 = load i64, ptr @n, align 8, !tbaa !5
  %18 = icmp sgt i64 %17, 1
  br i1 %18, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.017.lcssa = phi double [ %16, %1 ], [ %.118, %.lr.ph ]
  %.0.lcssa = phi double [ %9, %1 ], [ %.1, %.lr.ph ]
  %19 = fsub double %.017.lcssa, %.0.lcssa
  %20 = fcmp ogt double %19, 0x3E7AD7F29ABCAF48
  ret i1 %20

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.024 = phi double [ %.1, %.lr.ph ], [ %9, %1 ]
  %.01723 = phi double [ %.118, %.lr.ph ], [ %16, %1 ]
  %.01922 = phi i64 [ %38, %.lr.ph ], [ 1, %1 ]
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef %.01922) #2
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = sitofp i64 %22 to double
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef %.01922) #2
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = sitofp i64 %25 to double
  %27 = fneg double %26
  %28 = tail call double @llvm.fmuladd.f64(double %27, double %0, double %23)
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @pos, i64 noundef %.01922) #2
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = sitofp i64 %30 to double
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @speed, i64 noundef %.01922) #2
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = sitofp i64 %33 to double
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %0, double %31)
  %36 = fcmp ogt double %.01723, %35
  %.118 = select i1 %36, double %35, double %.01723
  %37 = fcmp olt double %.024, %28
  %.1 = select i1 %37, double %28, double %.024
  %38 = add nuw nsw i64 %.01922, 1
  %39 = load i64, ptr @n, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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