; LLVM IR from tangjz/acm-icpc :: uvalive/6135.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"

@K = external dso_local global i32, align 4
@p = external dso_local global [10 x [2 x double]], align 16
@q = external dso_local global [10 x [2 x double]], align 16
@M = external dso_local global double, align 8

; 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 double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store double 0.000000e+00, 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 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load i32, ptr @K, align 4, !tbaa !9
  store i32 %10, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %48, %1
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = load double, ptr %2, align 8, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x [2 x double]], ptr @p, i64 0, i64 %19
  %21 = getelementptr inbounds [2 x double], ptr %20, i64 0, i64 0
  %22 = load double, ptr %21, align 16, !tbaa !5
  %23 = call double @llvm.fmuladd.f64(double %16, double %17, double %22)
  store double %23, ptr %3, align 8, !tbaa !5
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = load double, ptr %2, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x [2 x double]], ptr @p, i64 0, i64 %27
  %29 = getelementptr inbounds [2 x double], ptr %28, i64 0, i64 1
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = call double @llvm.fmuladd.f64(double %24, double %25, double %30)
  store double %31, ptr %4, align 8, !tbaa !5
  %32 = load double, ptr %5, align 8, !tbaa !5
  %33 = load double, ptr %2, align 8, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x [2 x double]], ptr @q, i64 0, i64 %35
  %37 = getelementptr inbounds [2 x double], ptr %36, i64 0, i64 0
  %38 = load double, ptr %37, align 16, !tbaa !5
  %39 = call double @llvm.fmuladd.f64(double %32, double %33, double %38)
  store double %39, ptr %5, align 8, !tbaa !5
  %40 = load double, ptr %6, align 8, !tbaa !5
  %41 = load double, ptr %2, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10 x [2 x double]], ptr @q, i64 0, i64 %43
  %45 = getelementptr inbounds [2 x double], ptr %44, i64 0, i64 1
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = call double @llvm.fmuladd.f64(double %40, double %41, double %46)
  store double %47, ptr %6, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %15
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %9, align 4, !tbaa !9
  br label %11, !llvm.loop !11

51:                                               ; preds = %14
  %52 = load double, ptr %3, align 8, !tbaa !5
  %53 = load double, ptr %4, align 8, !tbaa !5
  %54 = fdiv double %52, %53
  %55 = load double, ptr @M, align 8, !tbaa !5
  %56 = fcmp ogt double %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %51
  %58 = load double, ptr %3, align 8, !tbaa !5
  %59 = load double, ptr %4, align 8, !tbaa !5
  %60 = fdiv double %58, %59
  br label %63

61:                                               ; preds = %51
  %62 = load double, ptr @M, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %61, %57
  %64 = phi double [ %60, %57 ], [ %62, %61 ]
  store double %64, ptr %7, align 8, !tbaa !5
  %65 = load double, ptr %5, align 8, !tbaa !5
  %66 = load double, ptr %6, align 8, !tbaa !5
  %67 = fdiv double %65, %66
  %68 = load double, ptr @M, align 8, !tbaa !5
  %69 = fcmp ogt double %67, %68
  br i1 %69, label %70, label %74

70:                                               ; preds = %63
  %71 = load double, ptr %5, align 8, !tbaa !5
  %72 = load double, ptr %6, align 8, !tbaa !5
  %73 = fdiv double %71, %72
  br label %76

74:                                               ; preds = %63
  %75 = load double, ptr @M, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %74, %70
  %77 = phi double [ %73, %70 ], [ %75, %74 ]
  store double %77, ptr %8, align 8, !tbaa !5
  %78 = load double, ptr %7, align 8, !tbaa !5
  %79 = load double, ptr %8, align 8, !tbaa !5
  %80 = fsub double %78, %79
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %80
}

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

@K = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [10 x [2 x double]], align 16
@q = external dso_local local_unnamed_addr global [10 x [2 x double]], align 16
@M = external dso_local local_unnamed_addr global double, align 8

; 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 @K, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, -1
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %4 = zext nneg i32 %2 to i64
  %5 = insertelement <2 x double> poison, double %0, i64 0
  %6 = shufflevector <2 x double> %5, <2 x double> poison, <2 x i32> zeroinitializer
  %7 = and i64 %4, 1
  %lcmp.mod.not.not = icmp eq i64 %7, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph.prol, label %.lr.ph.prol.loopexit

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %8 = getelementptr inbounds [10 x [2 x double]], ptr @p, i64 0, i64 %4
  %9 = load double, ptr %8, align 16, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds [10 x [2 x double]], ptr @q, i64 0, i64 %4
  %13 = load double, ptr %12, align 16, !tbaa !9
  %14 = insertelement <2 x double> poison, double %9, i64 0
  %15 = insertelement <2 x double> %14, double %13, i64 1
  %16 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %6, <2 x double> zeroinitializer, <2 x double> %15)
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = insertelement <2 x double> poison, double %11, i64 0
  %20 = insertelement <2 x double> %19, double %18, i64 1
  %21 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %6, <2 x double> zeroinitializer, <2 x double> %20)
  %indvars.iv.next.prol = add nsw i64 %4, -1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa45.unr = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %16, %.lr.ph.prol ]
  %.lcssa.unr = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %21, %.lr.ph.prol ]
  %indvars.iv.unr = phi i64 [ %4, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %16, %.lr.ph.prol ]
  %.unr46 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %21, %.lr.ph.prol ]
  %22 = icmp eq i32 %2, 0
  br i1 %22, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph, %.lr.ph.prol.loopexit
  %.lcssa45 = phi <2 x double> [ %.lcssa45.unr, %.lr.ph.prol.loopexit ], [ %56, %.lr.ph ]
  %.lcssa = phi <2 x double> [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %61, %.lr.ph ]
  %23 = fdiv <2 x double> %.lcssa45, %.lcssa
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %24 = phi <2 x double> [ <double 0x7FF8000000000000, double 0x7FF8000000000000>, %1 ], [ %23, %._crit_edge.loopexit ]
  %25 = load double, ptr @M, align 8
  %26 = insertelement <2 x double> poison, double %25, i64 0
  %27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
  %28 = fcmp ogt <2 x double> %24, %27
  %29 = select <2 x i1> %28, <2 x double> %24, <2 x double> %27
  %shift = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %30 = fsub <2 x double> %29, %shift
  %31 = extractelement <2 x double> %30, i64 0
  ret double %31

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %32 = phi <2 x double> [ %56, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %33 = phi <2 x double> [ %61, %.lr.ph ], [ %.unr46, %.lr.ph.prol.loopexit ]
  %34 = getelementptr inbounds [10 x [2 x double]], ptr @p, i64 0, i64 %indvars.iv
  %35 = load double, ptr %34, align 16, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 8
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds [10 x [2 x double]], ptr @q, i64 0, i64 %indvars.iv
  %39 = load double, ptr %38, align 16, !tbaa !9
  %40 = insertelement <2 x double> poison, double %35, i64 0
  %41 = insertelement <2 x double> %40, double %39, i64 1
  %42 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> %6, <2 x double> %41)
  %43 = getelementptr inbounds i8, ptr %38, i64 8
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = insertelement <2 x double> poison, double %37, i64 0
  %46 = insertelement <2 x double> %45, double %44, i64 1
  %47 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %6, <2 x double> %46)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %48 = getelementptr inbounds [10 x [2 x double]], ptr @p, i64 0, i64 %indvars.iv.next
  %49 = load double, ptr %48, align 16, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 8
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds [10 x [2 x double]], ptr @q, i64 0, i64 %indvars.iv.next
  %53 = load double, ptr %52, align 16, !tbaa !9
  %54 = insertelement <2 x double> poison, double %49, i64 0
  %55 = insertelement <2 x double> %54, double %53, i64 1
  %56 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %42, <2 x double> %6, <2 x double> %55)
  %57 = getelementptr inbounds i8, ptr %52, i64 8
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = insertelement <2 x double> poison, double %51, i64 0
  %60 = insertelement <2 x double> %59, double %58, i64 1
  %61 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %47, <2 x double> %6, <2 x double> %60)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %.not.1 = icmp eq i64 %indvars.iv.next, 0
  br i1 %.not.1, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass