; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016复赛/1006.ll (Z3getx)

; 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<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_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 }

@M = external dso_local global %"class.std::map", align 8
@pre = external dso_local global [10000010 x i32], 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
define dso_local noundef i64 @_Z3getx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp sle i64 %7, 10000000
  br i1 %8, label %9, label %14

9:                                                ; preds = %1
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds [10000010 x i32], ptr @pre, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  store i64 %13, ptr %2, align 8
  br label %53

14:                                               ; preds = %1
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %20 = load i64, ptr %19, align 8, !tbaa !5
  store i64 %20, ptr %2, align 8
  br label %53

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 2, ptr %6, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %44, %21
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = icmp sle i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %47

27:                                               ; preds = %22
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = sdiv i64 %29, %30
  %32 = sdiv i64 %28, %31
  store i64 %32, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = sub nsw i64 %33, %34
  %36 = add nsw i64 %35, 1
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = sdiv i64 %37, %38
  %40 = call noundef i64 @_Z3getx(i64 noundef %39)
  %41 = mul nsw i64 %36, %40
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = add nsw i64 %42, %41
  store i64 %43, ptr %5, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %27
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %6, align 8, !tbaa !5
  br label %22, !llvm.loop !11

47:                                               ; preds = %26
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = sub nsw i64 1, %48
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i64 %49, ptr %50, align 8, !tbaa !5
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = sub nsw i64 1, %51
  store i64 %52, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %53

53:                                               ; preds = %47, %18, %9
  %54 = load i64, ptr %2, align 8
  ret i64 %54
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #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<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_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 }

@M = external dso_local global %"class.std::map", align 8
@pre = external dso_local local_unnamed_addr global [10000010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3getx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = icmp slt i64 %0, 10000001
  br i1 %3, label %4, label %8

4:                                                ; preds = %1
  %5 = getelementptr inbounds [10000010 x i32], ptr @pre, i64 0, i64 %0
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  br label %26

8:                                                ; preds = %1
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %.preheader, label %12

.preheader:                                       ; preds = %8
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %.not1415 = icmp slt i64 %11, 2
  br i1 %.not1415, label %._crit_edge, label %.lr.ph

12:                                               ; preds = %8
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %14 = load i64, ptr %13, align 8, !tbaa !5
  br label %26

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %15 = sub nsw i64 1, %23
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.010.lcssa = phi i64 [ 1, %.preheader ], [ %15, %._crit_edge.loopexit ]
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @M, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i64 %.010.lcssa, ptr %16, align 8, !tbaa !5
  br label %26

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %17 = phi i64 [ %25, %.lr.ph ], [ %11, %.preheader ]
  %.017 = phi i64 [ %24, %.lr.ph ], [ 2, %.preheader ]
  %.01016 = phi i64 [ %23, %.lr.ph ], [ 0, %.preheader ]
  %18 = udiv i64 %17, %.017
  %19 = sdiv i64 %17, %18
  %reass.sub = sub i64 %19, %.017
  %20 = add i64 %reass.sub, 1
  %21 = call noundef i64 @_Z3getx(i64 noundef %18)
  %22 = mul nsw i64 %20, %21
  %23 = add nsw i64 %22, %.01016
  %24 = add nuw nsw i64 %19, 1
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %.not14.not = icmp slt i64 %19, %25
  br i1 %.not14.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

26:                                               ; preds = %._crit_edge, %12, %4
  %.011 = phi i64 [ %7, %4 ], [ %14, %12 ], [ %.010.lcssa, %._crit_edge ]
  ret i64 %.011
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 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" }

!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,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass