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

; 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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@m = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i32], align 16
@sf = external dso_local global %"class.std::unordered_map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calci(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %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 %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %11, label %16

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

16:                                               ; preds = %1
  %17 = call noundef i64 @_ZNKSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEE5countERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %2, align 4
  br label %71

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %23, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 2, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  br label %24

24:                                               ; preds = %58, %22
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sdiv i32 %30, %31
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sdiv i32 %33, %34
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = sext i32 %41 to i64
  %43 = sub nsw i64 %42, 1
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sub nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %43, %47
  %49 = ashr i64 %48, 1
  %50 = srem i64 %49, 1000000007
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = call noundef i32 @_Z4calci(i32 noundef %51)
  %53 = sext i32 %52 to i64
  %54 = mul nsw i64 %50, %53
  %55 = sub nsw i64 %38, %54
  %56 = srem i64 %55, 1000000007
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %4, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %29
  %59 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %59, ptr %5, align 4, !tbaa !5
  br label %24, !llvm.loop !9

60:                                               ; preds = %28
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1000000007
  br label %68

66:                                               ; preds = %60
  %67 = load i32, ptr %4, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %66, %63
  %69 = phi i32 [ %65, %63 ], [ %67, %66 ]
  %70 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %3)
  store i32 %69, ptr %70, align 4, !tbaa !5
  store i32 %69, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %71

71:                                               ; preds = %68, %19, %11
  %72 = load i32, ptr %2, align 4
  ret i32 %72
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56), 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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@m = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@sf = external dso_local global %"class.std::unordered_map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calci(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %.not = icmp slt i32 %3, %0
  br i1 %.not, label %8, label %4

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

8:                                                ; preds = %1
  %9 = call noundef i64 @_ZNKSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEE5countERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %.not18 = icmp eq i64 %9, 0
  br i1 %.not18, label %13, label %10

10:                                               ; preds = %8
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %12 = load i32, ptr %11, align 4, !tbaa !5
  br label %39

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %.not1920 = icmp slt i32 %14, 2
  br i1 %.not1920, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.014.lcssa = phi i32 [ %14, %13 ], [ %37, %.lr.ph ]
  %15 = icmp slt i32 %.014.lcssa, 0
  %16 = add nsw i32 %.014.lcssa, 1000000007
  %17 = select i1 %15, i32 %16, i32 %.014.lcssa
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @sf, ptr noundef nonnull align 4 dereferenceable(4) %2)
  store i32 %17, ptr %18, align 4, !tbaa !5
  br label %39

.lr.ph:                                           ; preds = %13, %.lr.ph
  %19 = phi i32 [ %38, %.lr.ph ], [ %14, %13 ]
  %.01422 = phi i32 [ %37, %.lr.ph ], [ %14, %13 ]
  %.01521 = phi i32 [ %22, %.lr.ph ], [ 2, %13 ]
  %20 = udiv i32 %19, %.01521
  %21 = sdiv i32 %19, %20
  %22 = add nuw nsw i32 %21, 1
  %23 = sext i32 %.01422 to i64
  %24 = add nuw nsw i32 %22, %.01521
  %25 = zext nneg i32 %24 to i64
  %26 = add nsw i64 %25, -1
  %27 = sub nsw i32 %22, %.01521
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %26, %28
  %30 = ashr i64 %29, 1
  %31 = srem i64 %30, 1000000007
  %32 = call noundef i32 @_Z4calci(i32 noundef %20)
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %31, %33
  %35 = sub nsw i64 %23, %34
  %36 = srem i64 %35, 1000000007
  %37 = trunc nsw i64 %36 to i32
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %.not19.not = icmp slt i32 %21, %38
  br i1 %.not19.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

39:                                               ; preds = %._crit_edge, %10, %4
  %.0 = phi i32 [ %7, %4 ], [ %12, %10 ], [ %17, %._crit_edge ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEE5countERS5_(ptr noundef nonnull align 8 dereferenceable(56), 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 @_ZNSt13unordered_mapIiiSt4hashIiESt8equal_toIiESaISt4pairIKiiEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56), 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass