; LLVM IR from upupming/algorithm :: acwing/日常刷题/kick-start/623. 投票.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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@f = external dso_local global [2010 x [2010 x double]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(4) @m)
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 0, i64 32320800, i1 false)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sitofp i32 %6 to double
  %8 = fmul double 1.000000e+00, %7
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = add nsw i32 %9, %10
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %8, %12
  store double %13, ptr getelementptr inbounds ([2010 x [2010 x double]], ptr @f, i64 0, i64 1), align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %90, %0
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %93

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %86, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %89

25:                                               ; preds = %20
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2010 x double], ptr %28, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = sitofp i32 %35 to double
  %37 = fmul double %32, %36
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = sub nsw i32 %40, %43
  %45 = sitofp i32 %44 to double
  %46 = fdiv double %37, %45
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2010 x double], ptr %50, i64 0, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !9
  %55 = fadd double %54, %46
  store double %55, ptr %53, align 8, !tbaa !9
  %56 = load i32, ptr %1, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %57
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [2010 x double], ptr %58, i64 0, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !9
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sub nsw i32 %63, %64
  %66 = sitofp i32 %65 to double
  %67 = fmul double %62, %66
  %68 = load i32, ptr @n, align 4, !tbaa !5
  %69 = load i32, ptr @m, align 4, !tbaa !5
  %70 = add nsw i32 %68, %69
  %71 = load i32, ptr %1, align 4, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %71, %72
  %74 = sub nsw i32 %70, %73
  %75 = sitofp i32 %74 to double
  %76 = fdiv double %67, %75
  %77 = load i32, ptr %1, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %78
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2010 x double], ptr %79, i64 0, i64 %82
  %84 = load double, ptr %83, align 8, !tbaa !9
  %85 = fadd double %84, %76
  store double %85, ptr %83, align 8, !tbaa !9
  br label %86

86:                                               ; preds = %25
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !11

89:                                               ; preds = %24
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %1, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %1, align 4, !tbaa !5
  br label %14, !llvm.loop !13

93:                                               ; preds = %18
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %95
  %97 = load i32, ptr @m, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [2010 x double], ptr %96, i64 0, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !9
  ret double %100
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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 = { "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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"}
!13 = distinct !{!13, !12}


; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [2010 x [2010 x double]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z5solvev() local_unnamed_addr #0 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 4 dereferenceable(4) @m)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32320800) @f, i8 0, i64 32320800, i1 false)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sitofp i32 %3 to double
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = add nsw i32 %5, %3
  %7 = sitofp i32 %6 to double
  %8 = fdiv double %4, %7
  store double %8, ptr getelementptr inbounds (i8, ptr @f, i64 16080), align 16, !tbaa !9
  %.not22 = icmp slt i32 %3, 1
  br i1 %.not22, label %.._crit_edge_crit_edge, label %.preheader.preheader

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre30 = sext i32 %3 to i64
  br label %._crit_edge

.preheader.preheader:                             ; preds = %0
  %9 = zext nneg i32 %3 to i64
  %10 = add nuw i32 %3, 1
  %wide.trip.count28 = zext i32 %10 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %16
  %indvars.iv25 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next26, %16 ]
  %11 = trunc i64 %indvars.iv25 to i32
  %12 = sub i32 %3, %11
  %13 = sitofp i32 %12 to double
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %.phi.trans.insert = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %indvars.iv25, i64 0
  %.pre = load double, ptr %.phi.trans.insert, align 16, !tbaa !9
  br label %17

._crit_edge:                                      ; preds = %16, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre30, %.._crit_edge_crit_edge ], [ %9, %16 ]
  %.pre-phi32 = sext i32 %5 to i64
  %14 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %.pre-phi, i64 %.pre-phi32
  %15 = load double, ptr %14, align 8, !tbaa !9
  ret double %15

16:                                               ; preds = %17
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %._crit_edge, label %.preheader, !llvm.loop !11

17:                                               ; preds = %.preheader, %17
  %18 = phi double [ %.pre, %.preheader ], [ %35, %17 ]
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %17 ]
  %19 = fmul double %18, %13
  %20 = add nuw nsw i64 %indvars.iv25, %indvars.iv
  %21 = trunc nuw i64 %20 to i32
  %22 = sub i32 %6, %21
  %23 = sitofp i32 %22 to double
  %24 = fdiv double %19, %23
  %25 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %indvars.iv.next26, i64 %indvars.iv
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fadd double %26, %24
  store double %27, ptr %25, align 8, !tbaa !9
  %28 = trunc i64 %indvars.iv to i32
  %29 = sub i32 %5, %28
  %30 = sitofp i32 %29 to double
  %31 = fmul double %18, %30
  %32 = fdiv double %31, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = getelementptr inbounds [2010 x [2010 x double]], ptr @f, i64 0, i64 %indvars.iv25, i64 %indvars.iv.next
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fadd double %32, %34
  store double %35, ptr %33, align 8, !tbaa !9
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv25
  br i1 %exitcond.not, label %16, label %17, !llvm.loop !13
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}
!13 = distinct !{!13, !12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass