; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-19/F - PowMod - tjz.ll (Z1Gii)

; 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, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, 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 [10000001 x i32], align 16
@s = external dso_local global [10000001 x i32], align 16
@f = external dso_local global [256 x i32], align 16
@g = external dso_local global [256 x %"class.std::map"], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z1Gii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp sle i32 %8, 1
  br i1 %9, label %10, label %24

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %10
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  br label %22

21:                                               ; preds = %10
  br label %22

22:                                               ; preds = %21, %13
  %23 = phi i32 [ %20, %13 ], [ 0, %21 ]
  store i32 %23, ptr %3, align 4
  br label %101

24:                                               ; preds = %2
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %32, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %3, align 4
  br label %101

32:                                               ; preds = %24
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %34
  %36 = call noundef i64 @_ZNKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %35, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %32
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %40
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %41, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %3, align 4
  br label %101

44:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = call noundef i32 @_Z1Gii(i32 noundef 0, i32 noundef %53)
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 %52, %55
  %57 = srem i64 %56, 1000000007
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %59 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %59, ptr %7, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %90, %44
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %95

64:                                               ; preds = %60
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = xor i32 %67, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sdiv i32 %78, %82
  %84 = call noundef i32 @_Z1Gii(i32 noundef %77, i32 noundef %83)
  %85 = sext i32 %84 to i64
  %86 = mul nsw i64 %76, %85
  %87 = add nsw i64 %66, %86
  %88 = srem i64 %87, 1000000007
  %89 = trunc i64 %88 to i32
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %64
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = sub nsw i32 %91, 1
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = and i32 %92, %93
  store i32 %94, ptr %7, align 4, !tbaa !5
  br label %60, !llvm.loop !9

95:                                               ; preds = %63
  %96 = load i32, ptr %6, align 4, !tbaa !5
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %98
  %100 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %99, ptr noundef nonnull align 4 dereferenceable(4) %5)
  store i32 %96, ptr %100, align 4, !tbaa !5
  store i32 %96, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %101

101:                                              ; preds = %95, %38, %27, %22
  %102 = load i32, ptr %3, align 4
  ret i32 %102
}

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

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

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 = { 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 = distinct !{!9, !10}
!10 = !{!"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, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, 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 [10000001 x i32], align 16
@s = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@f = external dso_local local_unnamed_addr global [256 x i32], align 16
@g = external dso_local global [256 x %"class.std::map"], align 16

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

5:                                                ; preds = %2
  %.not23 = icmp eq i32 %1, 0
  br i1 %.not23, label %67, label %6

6:                                                ; preds = %5
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  br label %67

13:                                               ; preds = %2
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %14, label %18

14:                                               ; preds = %13
  %15 = zext nneg i32 %1 to i64
  %16 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  br label %67

18:                                               ; preds = %13
  %19 = sext i32 %0 to i64
  %20 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %19
  %21 = call noundef i64 @_ZNKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %20, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %.not21 = icmp eq i64 %21, 0
  br i1 %.not21, label %25, label %22

22:                                               ; preds = %18
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %20, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  br label %67

25:                                               ; preds = %18
  %26 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %19
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 2
  br i1 %33, label %34, label %39

34:                                               ; preds = %25
  %.not23.i = icmp eq i32 %32, 0
  br i1 %.not23.i, label %_Z1Gii.exit, label %35

35:                                               ; preds = %34
  %36 = load i32, ptr @f, align 16, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %37
  br label %_Z1Gii.exit.sink.split

39:                                               ; preds = %25
  %40 = zext nneg i32 %32 to i64
  %41 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %40
  br label %_Z1Gii.exit.sink.split

_Z1Gii.exit.sink.split:                           ; preds = %39, %35
  %.sink = phi ptr [ %38, %35 ], [ %41, %39 ]
  %42 = load i32, ptr %.sink, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  br label %_Z1Gii.exit

_Z1Gii.exit:                                      ; preds = %_Z1Gii.exit.sink.split, %34
  %.018.i = phi i64 [ 0, %34 ], [ %43, %_Z1Gii.exit.sink.split ]
  %44 = mul nsw i64 %.018.i, %31
  %.017.in24 = srem i64 %44, 1000000007
  br label %47

45:                                               ; preds = %47
  %.017 = trunc nsw i64 %.017.in to i32
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %20, ptr noundef nonnull align 4 dereferenceable(4) %3)
  store i32 %.017, ptr %46, align 4, !tbaa !5
  br label %67

47:                                               ; preds = %_Z1Gii.exit, %47
  %.017.in26 = phi i64 [ %.017.in24, %_Z1Gii.exit ], [ %.017.in, %47 ]
  %.025 = phi i32 [ %0, %_Z1Gii.exit ], [ %66, %47 ]
  %48 = xor i32 %.025, %0
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %.025 to i64
  %58 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sdiv i32 %56, %59
  %61 = call noundef i32 @_Z1Gii(i32 noundef %.025, i32 noundef %60)
  %62 = sext i32 %61 to i64
  %63 = mul nsw i64 %62, %55
  %64 = add nsw i64 %63, %.017.in26
  %65 = add nsw i32 %.025, -1
  %66 = and i32 %65, %0
  %.017.in = srem i64 %64, 1000000007
  %.not22 = icmp eq i32 %66, 0
  br i1 %.not22, label %45, label %47, !llvm.loop !9

67:                                               ; preds = %6, %5, %45, %22, %14
  %.018 = phi i32 [ %24, %22 ], [ %.017, %45 ], [ %17, %14 ], [ %12, %6 ], [ 0, %5 ]
  ret i32 %.018
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InlinerPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass