; LLVM IR from kazunetakahashi/atcoder :: 2017/0320_RCO-final/B2.ll (Z5scorev)

; 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.Point = type { i32, i32 }

@K = external dso_local global i32, align 4
@Y = external dso_local global [450 x %class.Point], align 16
@L = external dso_local global i32, align 4
@now = external dso_local global [10010 x [450 x %class.Point]], align 16
@memo = external dso_local global [10010 x i32], align 16

; 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
define dso_local void @_Z5scorev() #1 {
  %1 = alloca double, align 8
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store double 2.000000e+01, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %23, %0
  %5 = load i32, ptr %2, align 4, !tbaa !9
  %6 = load i32, ptr @K, align 4, !tbaa !9
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %4
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [450 x %class.Point], ptr @Y, i64 0, i64 %11
  %13 = load i32, ptr @L, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10010 x [450 x %class.Point]], ptr @now, i64 0, i64 %14
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [450 x %class.Point], ptr %15, i64 0, i64 %17
  %19 = call noundef i32 @_ZNK5Point4distERKS_(ptr noundef nonnull align 4 dereferenceable(8) %12, ptr noundef nonnull align 4 dereferenceable(8) %18)
  %20 = sitofp i32 %19 to double
  %21 = load double, ptr %1, align 8, !tbaa !5
  %22 = fadd double %21, %20
  store double %22, ptr %1, align 8, !tbaa !5
  br label %23

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

26:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %27 = load i32, ptr @L, align 4, !tbaa !9
  %28 = sitofp i32 %27 to double
  %29 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %28, double 1.000000e+01)
  store double %29, ptr %3, align 8, !tbaa !5
  %30 = load double, ptr %1, align 8, !tbaa !5
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = fmul double %30, %31
  %33 = fdiv double 1.000000e+07, %32
  %34 = fptosi double %33 to i32
  %35 = load i32, ptr @L, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10010 x i32], ptr @memo, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5Point4distERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

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

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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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"

%class.Point = type { i32, i32 }

@K = external dso_local local_unnamed_addr global i32, align 4
@Y = external dso_local global [450 x %class.Point], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@now = external dso_local global [10010 x [450 x %class.Point]], align 16
@memo = external dso_local local_unnamed_addr global [10010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5scorev() local_unnamed_addr #0 {
  %1 = load i32, ptr @K, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.0.lcssa = phi double [ 2.000000e+01, %0 ], [ %17, %.lr.ph ]
  %3 = load i32, ptr @L, align 4, !tbaa !5
  %4 = sitofp i32 %3 to double
  %5 = tail call double @llvm.fmuladd.f64(double %4, double 1.000000e-02, double 1.000000e+01)
  %6 = fmul double %.0.lcssa, %5
  %7 = fdiv double 1.000000e+07, %6
  %8 = fptosi double %7 to i32
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds [10010 x i32], ptr @memo, i64 0, i64 %9
  store i32 %8, ptr %10, align 4, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %.08 = phi double [ %17, %.lr.ph ], [ 2.000000e+01, %0 ]
  %11 = getelementptr inbounds [450 x %class.Point], ptr @Y, i64 0, i64 %indvars.iv
  %12 = load i32, ptr @L, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10010 x [450 x %class.Point]], ptr @now, i64 0, i64 %13, i64 %indvars.iv
  %15 = tail call noundef i32 @_ZNK5Point4distERKS_(ptr noundef nonnull align 4 dereferenceable(8) %11, ptr noundef nonnull align 4 dereferenceable(8) %14)
  %16 = sitofp i32 %15 to double
  %17 = fadd double %.08, %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @K, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5Point4distERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) 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) }

!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.mustprogress"}


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