; LLVM IR from tangjz/acm-icpc :: 51nod/1227.ll (Z9calc_iphii)

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

@Hash = external dso_local global %"class.std::map", align 8
@f = external dso_local global [1000010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9calc_iphii(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1000010
  br i1 %11, label %12, label %17

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %2, align 4
  br label %75

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

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  store i64 %24, ptr %5, align 8, !tbaa !9
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %75

27:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = add nsw i64 %31, 1
  %33 = mul nsw i64 %29, %32
  %34 = srem i64 %33, 1000000007
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = shl i32 %35, 1
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %34, %38
  %40 = srem i64 %39, 1000000007
  %41 = mul nsw i64 %40, 166666668
  %42 = srem i64 %41, 1000000007
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %44

44:                                               ; preds = %67, %27
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %70

49:                                               ; preds = %44
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = sdiv i32 %51, %52
  %54 = sdiv i32 %50, %53
  store i32 %54, ptr %8, align 4, !tbaa !5
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = sdiv i32 %55, %56
  %58 = call noundef i32 @_Z9calc_iphii(i32 noundef %57)
  %59 = sext i32 %58 to i64
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = call noundef i32 @_Z4num1ii(i32 noundef %60, i32 noundef %61)
  %63 = sext i32 %62 to i64
  %64 = mul nsw i64 %59, %63
  %65 = srem i64 %64, 1000000007
  %66 = trunc i64 %65 to i32
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %66)
  br label %67

67:                                               ; preds = %49
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !5
  br label %44, !llvm.loop !11

70:                                               ; preds = %48
  %71 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  store i64 %73, ptr %9, align 8, !tbaa !9
  %74 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %9)
  store i32 %71, ptr %74, align 4, !tbaa !5
  store i32 %71, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %75

75:                                               ; preds = %70, %22, %12
  %76 = load i32, ptr %2, align 4
  ret i32 %76
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4num1ii(i32 noundef, i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress nounwind 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !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, int>, std::_Select1st<std::pair<const long long, int>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, int>, std::_Select1st<std::pair<const long long, int>>, 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 }

@Hash = external dso_local global %"class.std::map", align 8
@f = external dso_local local_unnamed_addr global [1000010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9calc_iphii(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = icmp slt i32 %0, 1000010
  br i1 %6, label %7, label %11

7:                                                ; preds = %1
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  br label %39

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %12 = zext nneg i32 %0 to i64
  store i64 %12, ptr %2, align 8, !tbaa !9
  %13 = call noundef i64 @_ZNKSt3mapIxiSt4lessIxESaISt4pairIKxiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.not = icmp eq i64 %13, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br i1 %.not, label %.lr.ph.preheader, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 %12, ptr %3, align 8, !tbaa !9
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %16 = load i32, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %39

.lr.ph.preheader:                                 ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %17 = add nuw nsw i64 %12, 1
  %18 = mul nuw nsw i64 %17, %12
  %19 = urem i64 %18, 1000000007
  %20 = shl nuw i32 %0, 1
  %21 = or disjoint i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %19, %22
  %24 = srem i64 %23, 1000000007
  %25 = mul nsw i64 %24, 166666668
  %26 = srem i64 %25, 1000000007
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i64 %12, ptr %5, align 8, !tbaa !9
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %5)
  store i32 %.pre, ptr %28, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %39

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01923 = phi i32 [ %38, %.lr.ph ], [ 2, %.lr.ph.preheader ]
  %29 = sdiv i32 %0, %.01923
  %30 = sdiv i32 %0, %29
  %31 = call noundef i32 @_Z9calc_iphii(i32 noundef %29)
  %32 = sext i32 %31 to i64
  %33 = call noundef i32 @_Z4num1ii(i32 noundef %.01923, i32 noundef %30)
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %34, %32
  %36 = srem i64 %35, 1000000007
  %37 = trunc nsw i64 %36 to i32
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %37)
  %38 = add nsw i32 %30, 1
  %.not21.not = icmp slt i32 %30, %0
  br i1 %.not21.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

39:                                               ; preds = %._crit_edge, %14, %7
  %.0 = phi i32 [ %10, %7 ], [ %16, %14 ], [ %.pre, %._crit_edge ]
  ret i32 %.0
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4num1ii(i32 noundef, i32 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress nounwind 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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