; LLVM IR from upupming/algorithm :: acwing/寒假每日一题（提高组）/week1/1402. 星空之夜.ll (Z8get_hashv)

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

%"struct.std::pair" = type { i32, i32 }

@top = external dso_local global i32, align 4
@q = external dso_local global [12100 x %"struct.std::pair"], 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
declare dso_local noundef double @_Z4distSt4pairIiiES0_(i64, i64) #1

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

7:                                                ; preds = %36, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = load i32, ptr @top, align 4, !tbaa !9
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %39

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %13 = load i32, ptr %2, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %32, %12
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr @top, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %35

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 8 %23, i64 8, i1 false)
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 8 %26, i64 8, i1 false)
  %27 = load i64, ptr %5, align 4
  %28 = load i64, ptr %6, align 4
  %29 = call noundef double @_Z4distSt4pairIiiES0_(i64 %27, i64 %28)
  %30 = load double, ptr %1, align 8, !tbaa !5
  %31 = fadd double %30, %29
  store double %31, ptr %1, align 8, !tbaa !5
  br label %32

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

35:                                               ; preds = %19
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %2, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !13

39:                                               ; preds = %11
  %40 = load double, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret double %40
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 nounwind willreturn memory(argmem: readwrite) }
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"}
!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"

%"struct.std::pair" = type { i32, i32 }

@top = external dso_local local_unnamed_addr global i32, align 4
@q = external dso_local local_unnamed_addr global [12100 x %"struct.std::pair"], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z8get_hashv() local_unnamed_addr #0 {
  %1 = load i32, ptr @top, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph15, label %._crit_edge

.loopexit.loopexit:                               ; preds = %9
  %.pre = sext i32 %13 to i64
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.lr.ph15
  %.pre-phi = phi i64 [ %.pre, %.loopexit.loopexit ], [ %6, %.lr.ph15 ]
  %3 = phi i32 [ %13, %.loopexit.loopexit ], [ %5, %.lr.ph15 ]
  %.1.lcssa = phi double [ %12, %.loopexit.loopexit ], [ %.014, %.lr.ph15 ]
  %4 = icmp slt i64 %indvars.iv.next21, %.pre-phi
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %4, label %.lr.ph15, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.loopexit, %0
  %.0.lcssa = phi double [ 0.000000e+00, %0 ], [ %.1.lcssa, %.loopexit ]
  ret double %.0.lcssa

.lr.ph15:                                         ; preds = %0, %.loopexit
  %5 = phi i32 [ %3, %.loopexit ], [ %1, %0 ]
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %.loopexit ], [ 0, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 1, %0 ]
  %.014 = phi double [ %.1.lcssa, %.loopexit ], [ 0.000000e+00, %0 ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %6 = sext i32 %5 to i64
  %7 = icmp slt i64 %indvars.iv.next21, %6
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph15
  %8 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %indvars.iv20
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv17 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next18, %9 ]
  %.112 = phi double [ %.014, %.lr.ph ], [ %12, %9 ]
  %.sroa.01.0.copyload = load i64, ptr %8, align 8
  %10 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %indvars.iv17
  %.sroa.0.0.copyload = load i64, ptr %10, align 8
  %11 = tail call noundef double @_Z4distSt4pairIiiES0_(i64 %.sroa.01.0.copyload, i64 %.sroa.0.0.copyload)
  %12 = fadd double %.112, %11
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %13 = load i32, ptr @top, align 4, !tbaa !5
  %14 = trunc nuw i64 %indvars.iv.next18 to i32
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %9, label %.loopexit.loopexit, !llvm.loop !11
}

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

!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"}
!11 = distinct !{!11, !10}


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