; LLVM IR from tangjz/acm-icpc :: lydsy (3687)

; 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::bitset<2000001>::reference" = type { ptr, i64 }
%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [31251 x i64] }

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@cnt = external dso_local global { [31251 x i64] }, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.std::bitset<2000001>::reference", align 8
  %3 = alloca i32, align 4
  %4 = alloca %"class.std::bitset", align 8
  %5 = alloca i32, align 4
  %6 = alloca %"class.std::bitset<2000001>::reference", align 8
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #4
  call void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<2000001>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef 0)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm2000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %2, i1 noundef zeroext true) #4
  call void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %22, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %25

14:                                               ; preds = %9
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %16 = load i32, ptr @x, align 4, !tbaa !5
  %17 = load i32, ptr @sum, align 4, !tbaa !5
  %18 = add nsw i32 %17, %16
  store i32 %18, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 250008, ptr %4) #4
  %19 = load i32, ptr @x, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  call void @_ZNKSt6bitsetILm2000001EElsEm(ptr dead_on_unwind writable sret(%"class.std::bitset") align 8 %4, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef %20) #4
  %21 = call noundef nonnull align 8 dereferenceable(250008) ptr @_ZNSt6bitsetILm2000001EEeOERKS0_(ptr noundef nonnull align 8 dereferenceable(250008) @cnt, ptr noundef nonnull align 8 dereferenceable(250008) %4) #4
  call void @llvm.lifetime.end.p0(i64 250008, ptr %4) #4
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !9

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

26:                                               ; preds = %40, %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr @sum, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %43

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  call void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<2000001>::reference") align 8 %6, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef %33)
  %34 = call noundef zeroext i1 @_ZNKSt6bitsetILm2000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  call void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  br i1 %34, label %35, label %39

35:                                               ; preds = %31
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr @ans, align 4, !tbaa !5
  %38 = xor i32 %37, %36
  store i32 %38, ptr @ans, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %35, %31
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !5
  br label %26, !llvm.loop !11

43:                                               ; preds = %30
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %44)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<2000001>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(250008), i64 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm2000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt6bitsetILm2000001EElsEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset") align 8, ptr noundef nonnull align 8 dereferenceable(250008), i64 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(250008) ptr @_ZNSt6bitsetILm2000001EEeOERKS0_(ptr noundef nonnull align 8 dereferenceable(250008), ptr noundef nonnull align 8 dereferenceable(250008)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm2000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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"}
!11 = distinct !{!11, !10}


; 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::bitset<2000001>::reference" = type { ptr, i64 }
%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [31251 x i64] }

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local global { [31251 x i64] }, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %"class.std::bitset<2000001>::reference", align 8
  %2 = alloca %"class.std::bitset", align 8
  %3 = alloca %"class.std::bitset<2000001>::reference", align 8
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  call void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<2000001>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef 0)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm2000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %1, i1 noundef zeroext true) #4
  call void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  %8 = load i32, ptr @sum, align 4, !tbaa !5
  %.not8 = icmp slt i32 %8, 1
  br i1 %.not8, label %._crit_edge, label %.lr.ph10

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.067 = phi i32 [ %15, %.lr.ph ], [ 0, %0 ]
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %10 = load i32, ptr @x, align 4, !tbaa !5
  %11 = load i32, ptr @sum, align 4, !tbaa !5
  %12 = add nsw i32 %11, %10
  store i32 %12, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 250008, ptr nonnull %2) #4
  %13 = sext i32 %10 to i64
  call void @_ZNKSt6bitsetILm2000001EElsEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset") align 8 %2, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef %13) #4
  %14 = call noundef nonnull align 8 dereferenceable(250008) ptr @_ZNSt6bitsetILm2000001EEeOERKS0_(ptr noundef nonnull align 8 dereferenceable(250008) @cnt, ptr noundef nonnull align 8 dereferenceable(250008) %2) #4
  call void @llvm.lifetime.end.p0(i64 250008, ptr nonnull %2) #4
  %15 = add nuw nsw i32 %.067, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %25, %.preheader
  %18 = load i32, ptr @ans, align 4, !tbaa !5
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %18)
  ret i32 0

.lr.ph10:                                         ; preds = %.preheader, %25
  %indvars.iv = phi i64 [ %indvars.iv.next, %25 ], [ 1, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<2000001>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(250008) @cnt, i64 noundef %indvars.iv)
  %20 = call noundef zeroext i1 @_ZNKSt6bitsetILm2000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #4
  call void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  br i1 %20, label %21, label %25

21:                                               ; preds = %.lr.ph10
  %22 = load i32, ptr @ans, align 4, !tbaa !5
  %23 = trunc nuw nsw i64 %indvars.iv to i32
  %24 = xor i32 %22, %23
  store i32 %24, ptr @ans, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %.lr.ph10, %21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @sum, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not.not = icmp slt i64 %indvars.iv, %27
  br i1 %.not.not, label %.lr.ph10, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm2000001EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<2000001>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(250008), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm2000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm2000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt6bitsetILm2000001EElsEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset") align 8, ptr noundef nonnull align 8 dereferenceable(250008), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(250008) ptr @_ZNSt6bitsetILm2000001EEeOERKS0_(ptr noundef nonnull align 8 dereferenceable(250008), ptr noundef nonnull align 8 dereferenceable(250008)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm2000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress norecurse 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 #1 = { nofree nounwind "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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"}
!11 = distinct !{!11, !10}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass