; LLVM IR from tangjz/acm-icpc :: lydsy/5151.ll (Z4calcix)

; 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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<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 }
%"class.std::map" = type { %"class.std::_Rb_tree.0" }
%"class.std::_Rb_tree.0" = 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" }

@sp = external dso_local global %"class.std::set", align 8
@bit = external dso_local global [11 x i64], align 16
@f = external dso_local global [11 x %"class.std::map"], 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 i32 @_Z4calcix(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE5countERKx(ptr noundef nonnull align 8 dereferenceable(48) @sp, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %3, align 4
  br label %51

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [11 x %"class.std::map"], ptr @f, i64 0, i64 %15
  %17 = call noundef i64 @_ZNKSt3mapIxiSt4lessIxESaISt4pairIKxiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %16, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %13
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [11 x %"class.std::map"], ptr @f, i64 0, i64 %21
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %22, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %3, align 4
  br label %51

25:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %42, %25
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 10
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [11 x i64], ptr @bit, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = add nsw i64 %33, %37
  %39 = call noundef i32 @_Z4calcix(i32 noundef %32, i64 noundef %38)
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %30
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %7, align 4, !tbaa !5
  br label %26, !llvm.loop !11

45:                                               ; preds = %29
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [11 x %"class.std::map"], ptr @f, i64 0, i64 %48
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %49, ptr noundef nonnull align 8 dereferenceable(8) %5)
  store i32 %46, ptr %50, align 4, !tbaa !5
  store i32 %46, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %51

51:                                               ; preds = %45, %19, %10
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(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 = !{!"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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<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 }
%"class.std::map" = type { %"class.std::_Rb_tree.0" }
%"class.std::_Rb_tree.0" = 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" }

@sp = external dso_local global %"class.std::set", align 8
@bit = external dso_local local_unnamed_addr global [11 x i64], align 16
@f = external dso_local global [11 x %"class.std::map"], align 16

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

5:                                                ; preds = %2
  %6 = call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE5countERKx(ptr noundef nonnull align 8 dereferenceable(48) @sp, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = trunc i64 %6 to i32
  br label %66

8:                                                ; preds = %2
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [11 x %"class.std::map"], ptr @f, i64 0, i64 %9
  %11 = call noundef i64 @_ZNKSt3mapIxiSt4lessIxESaISt4pairIKxiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %10, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %.preheader, label %63

.preheader:                                       ; preds = %8
  %12 = add nsw i32 %0, -1
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr @bit, align 16, !tbaa !5
  %15 = add nsw i64 %14, %13
  %16 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %15)
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 8), align 8, !tbaa !5
  %19 = add nsw i64 %18, %17
  %20 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %19)
  %21 = add nsw i32 %20, %16
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 16), align 16, !tbaa !5
  %24 = add nsw i64 %23, %22
  %25 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %24)
  %26 = add nsw i32 %25, %21
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 24), align 8, !tbaa !5
  %29 = add nsw i64 %28, %27
  %30 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %29)
  %31 = add nsw i32 %30, %26
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 32), align 16, !tbaa !5
  %34 = add nsw i64 %33, %32
  %35 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %34)
  %36 = add nsw i32 %35, %31
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 40), align 8, !tbaa !5
  %39 = add nsw i64 %38, %37
  %40 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %39)
  %41 = add nsw i32 %40, %36
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 48), align 16, !tbaa !5
  %44 = add nsw i64 %43, %42
  %45 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %44)
  %46 = add nsw i32 %45, %41
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 56), align 8, !tbaa !5
  %49 = add nsw i64 %48, %47
  %50 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %49)
  %51 = add nsw i32 %50, %46
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 64), align 16, !tbaa !5
  %54 = add nsw i64 %53, %52
  %55 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %54)
  %56 = add nsw i32 %55, %51
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = load i64, ptr getelementptr inbounds (i8, ptr @bit, i64 72), align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  %60 = call noundef i32 @_Z4calcix(i32 noundef %12, i64 noundef %59)
  %61 = add nsw i32 %60, %56
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %10, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i32 %61, ptr %62, align 4, !tbaa !9
  br label %66

63:                                               ; preds = %8
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %10, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %65 = load i32, ptr %64, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %.preheader, %63, %5
  %.012 = phi i32 [ %7, %5 ], [ %65, %63 ], [ %61, %.preheader ]
  ret i32 %.012
}

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

; 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 uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass