; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/3944（杜教筛）.ll (Z8calc_phix)

; 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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, long long>, std::_Select1st<std::pair<const int, long long>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, long long>, std::_Select1st<std::pair<const int, long long>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@phi = external dso_local global [5000000 x i64], align 16
@Phi = external dso_local global %"class.std::map", align 8

; 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 noundef i64 @_Z8calc_phix(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = icmp slt i64 %10, 5000000
  br i1 %11, label %12, label %16

12:                                               ; preds = %1
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds [5000000 x i64], ptr @phi, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %15, ptr %2, align 8
  br label %62

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %4, align 4, !tbaa !9
  %19 = call noundef i64 @_ZNKSt3mapIixSt4lessIiESaISt4pairIKixEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %20 = icmp ne i64 %19, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %5, align 4, !tbaa !9
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %25 = load i64, ptr %24, align 8, !tbaa !5
  store i64 %25, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %62

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  %30 = mul nsw i64 %27, %29
  %31 = ashr i64 %30, 1
  store i64 %31, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  br label %32

32:                                               ; preds = %54, %26
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = icmp sle i64 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %57

37:                                               ; preds = %32
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = sdiv i64 %39, %40
  %42 = sdiv i64 %38, %41
  store i64 %42, ptr %8, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = sub nsw i64 %43, %44
  %46 = add nsw i64 %45, 1
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = sdiv i64 %47, %48
  %50 = call noundef i64 @_Z8calc_phix(i64 noundef %49)
  %51 = mul nsw i64 %46, %50
  %52 = load i64, ptr %6, align 8, !tbaa !5
  %53 = sub nsw i64 %52, %51
  store i64 %53, ptr %6, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %37
  %55 = load i64, ptr %8, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %7, align 8, !tbaa !5
  br label %32, !llvm.loop !11

57:                                               ; preds = %36
  %58 = load i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %9, align 4, !tbaa !9
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %9)
  store i64 %58, ptr %61, align 8, !tbaa !5
  store i64 %58, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %62

62:                                               ; preds = %57, %21, %12
  %63 = load i64, ptr %2, align 8
  ret i64 %63
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIixSt4lessIiESaISt4pairIKixEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 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 = { 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 = !{!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.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, long long>, std::_Select1st<std::pair<const int, long long>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, long long>, std::_Select1st<std::pair<const int, long long>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@phi = external dso_local local_unnamed_addr global [5000000 x i64], align 16
@Phi = external dso_local global %"class.std::map", align 8

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

; Function Attrs: mustprogress 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 noundef i64 @_Z8calc_phix(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = icmp slt i64 %0, 5000000
  br i1 %5, label %6, label %9

6:                                                ; preds = %1
  %7 = getelementptr inbounds [5000000 x i64], ptr @phi, i64 0, i64 %0
  %8 = load i64, ptr %7, align 8, !tbaa !5
  br label %25

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %10 = trunc i64 %0 to i32
  store i32 %10, ptr %2, align 4, !tbaa !9
  %11 = call noundef i64 @_ZNKSt3mapIixSt4lessIiESaISt4pairIKixEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %.not = icmp eq i64 %11, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  br i1 %.not, label %.lr.ph.preheader, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 %10, ptr %3, align 4, !tbaa !9
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %14 = load i64, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  br label %25

.lr.ph.preheader:                                 ; preds = %9
  %15 = add nuw nsw i64 %0, 1
  %16 = mul nuw nsw i64 %15, %0
  %17 = lshr i64 %16, 1
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  store i32 %10, ptr %4, align 4, !tbaa !9
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Phi, ptr noundef nonnull align 4 dereferenceable(4) %4)
  store i64 %23, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  br label %25

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.02027 = phi i64 [ %24, %.lr.ph ], [ 2, %.lr.ph.preheader ]
  %.02126 = phi i64 [ %23, %.lr.ph ], [ %17, %.lr.ph.preheader ]
  %19 = udiv i64 %0, %.02027
  %20 = udiv i64 %0, %19
  %21 = xor i64 %20, -1
  %.neg = add i64 %.02027, %21
  %22 = call noundef i64 @_Z8calc_phix(i64 noundef %19)
  %.neg24 = mul i64 %.neg, %22
  %23 = add i64 %.neg24, %.02126
  %24 = add nuw nsw i64 %20, 1
  %.not23.not = icmp slt i64 %20, %0
  br i1 %.not23.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

25:                                               ; preds = %._crit_edge, %12, %6
  %.0 = phi i64 [ %8, %6 ], [ %14, %12 ], [ %23, %._crit_edge ]
  ret i64 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIixSt4lessIiESaISt4pairIKixEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass