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

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

@mu = external dso_local global [5000000 x i64], align 16
@Mu = 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
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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z7calc_mux(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 @mu, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %15, ptr %2, align 8
  br label %57

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) @Mu, 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) @Mu, 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 %57

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 1, 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 %27

27:                                               ; preds = %49, %26
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = icmp sle i64 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !5
  %36 = sdiv i64 %34, %35
  %37 = sdiv i64 %33, %36
  store i64 %37, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = sub nsw i64 %38, %39
  %41 = add nsw i64 %40, 1
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = load i64, ptr %7, align 8, !tbaa !5
  %44 = sdiv i64 %42, %43
  %45 = call noundef i64 @_Z7calc_mux(i64 noundef %44)
  %46 = mul nsw i64 %41, %45
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = sub nsw i64 %47, %46
  store i64 %48, ptr %6, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %32
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = add nsw i64 %50, 1
  store i64 %51, ptr %7, align 8, !tbaa !5
  br label %27, !llvm.loop !11

52:                                               ; preds = %31
  %53 = load i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = trunc i64 %54 to i32
  store i32 %55, ptr %9, align 4, !tbaa !9
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Mu, ptr noundef nonnull align 4 dereferenceable(4) %9)
  store i64 %53, ptr %56, align 8, !tbaa !5
  store i64 %53, 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 %57

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

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 }

@mu = external dso_local local_unnamed_addr global [5000000 x i64], align 16
@Mu = 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
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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z7calc_mux(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 @mu, i64 0, i64 %0
  %8 = load i64, ptr %7, align 8, !tbaa !5
  br label %22

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) @Mu, 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, 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) @Mu, 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 %22

._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
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixEOi(ptr noundef nonnull align 8 dereferenceable(48) @Mu, ptr noundef nonnull align 4 dereferenceable(4) %4)
  store i64 %20, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  br label %22

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.01825 = phi i64 [ %21, %.lr.ph ], [ 2, %9 ]
  %.01924 = phi i64 [ %20, %.lr.ph ], [ 1, %9 ]
  %16 = udiv i64 %0, %.01825
  %17 = udiv i64 %0, %16
  %18 = xor i64 %17, -1
  %.neg = add i64 %.01825, %18
  %19 = call noundef i64 @_Z7calc_mux(i64 noundef %16)
  %.neg22 = mul i64 %.neg, %19
  %20 = add i64 %.neg22, %.01924
  %21 = add nuw nsw i64 %17, 1
  %.not21.not = icmp slt i64 %17, %0
  br i1 %.not21.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

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

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