; LLVM IR from kazunetakahashi/atcoder :: 2019/0511_diverta2019 (E)

; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@N = external dso_local global i32, align 4
@A = external dso_local global [500010 x i32], align 16
@X = external dso_local global [500010 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; 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
declare dso_local void @_Z6solve0v() #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6solve1v() #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @N, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %18

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %12
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %13)
  br label %15

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %9
  store i32 0, ptr @X, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %38, %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr @N, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %41

24:                                               ; preds = %19
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = xor i32 %28, %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %36
  store i32 %33, ptr %37, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %24
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !11

41:                                               ; preds = %23
  %42 = load i32, ptr @N, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  call void @_Z6solve0v()
  br label %49

48:                                               ; preds = %41
  call void @_Z6solve1v()
  br label %49

49:                                               ; preds = %48, %47
  %50 = load i32, ptr %1, align 4
  ret i32 %50
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #3

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 = { 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 #3 = { "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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@N = external dso_local global i32, align 4
@A = external dso_local global [500010 x i32], align 16
@X = external dso_local local_unnamed_addr global [500010 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6solve0v() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6solve1v() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  store i32 0, ptr @X, align 16, !tbaa !5
  br label %._crit_edge15

._crit_edge:                                      ; preds = %.lr.ph
  store i32 0, ptr @X, align 16, !tbaa !5
  %4 = icmp sgt i32 %8, 0
  br i1 %4, label %.lr.ph14.preheader, label %._crit_edge15

.lr.ph14.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %5 = icmp ult i32 %8, 4
  br i1 %5, label %._crit_edge15.loopexit.unr-lcssa, label %.lr.ph14.preheader.new

.lr.ph14.preheader.new:                           ; preds = %.lr.ph14.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph14

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv
  %7 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @N, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge15.loopexit.unr-lcssa:                 ; preds = %.lr.ph14, %.lr.ph14.preheader
  %.unr = phi i32 [ 0, %.lr.ph14.preheader ], [ %35, %.lr.ph14 ]
  %indvars.iv18.unr = phi i64 [ 0, %.lr.ph14.preheader ], [ %indvars.iv.next19.3, %.lr.ph14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge15, label %.lr.ph14.epil

.lr.ph14.epil:                                    ; preds = %._crit_edge15.loopexit.unr-lcssa, %.lr.ph14.epil
  %11 = phi i32 [ %14, %.lr.ph14.epil ], [ %.unr, %._crit_edge15.loopexit.unr-lcssa ]
  %indvars.iv18.epil = phi i64 [ %indvars.iv.next19.epil, %.lr.ph14.epil ], [ %indvars.iv18.unr, %._crit_edge15.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph14.epil ], [ 0, %._crit_edge15.loopexit.unr-lcssa ]
  %12 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv18.epil
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = xor i32 %11, %13
  %indvars.iv.next19.epil = add nuw nsw i64 %indvars.iv18.epil, 1
  %15 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %indvars.iv.next19.epil
  store i32 %14, ptr %15, align 4, !tbaa !5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge15, label %.lr.ph14.epil, !llvm.loop !11

._crit_edge15:                                    ; preds = %._crit_edge15.loopexit.unr-lcssa, %.lr.ph14.epil, %._crit_edge.thread, %._crit_edge
  %.lcssa22 = phi i32 [ %2, %._crit_edge.thread ], [ %8, %._crit_edge ], [ %8, %.lr.ph14.epil ], [ %8, %._crit_edge15.loopexit.unr-lcssa ]
  %16 = sext i32 %.lcssa22 to i64
  %17 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %37, label %38

.lr.ph14:                                         ; preds = %.lr.ph14, %.lr.ph14.preheader.new
  %20 = phi i32 [ 0, %.lr.ph14.preheader.new ], [ %35, %.lr.ph14 ]
  %indvars.iv18 = phi i64 [ 0, %.lr.ph14.preheader.new ], [ %indvars.iv.next19.3, %.lr.ph14 ]
  %niter = phi i64 [ 0, %.lr.ph14.preheader.new ], [ %niter.next.3, %.lr.ph14 ]
  %21 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv18
  %22 = load i32, ptr %21, align 16, !tbaa !5
  %23 = xor i32 %20, %22
  %indvars.iv.next19 = or disjoint i64 %indvars.iv18, 1
  %24 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %indvars.iv.next19
  store i32 %23, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv.next19
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = xor i32 %23, %26
  %indvars.iv.next19.1 = or disjoint i64 %indvars.iv18, 2
  %28 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %indvars.iv.next19.1
  store i32 %27, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv.next19.1
  %30 = load i32, ptr %29, align 8, !tbaa !5
  %31 = xor i32 %27, %30
  %indvars.iv.next19.2 = or disjoint i64 %indvars.iv18, 3
  %32 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %indvars.iv.next19.2
  store i32 %31, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds [500010 x i32], ptr @A, i64 0, i64 %indvars.iv.next19.2
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = xor i32 %31, %34
  %indvars.iv.next19.3 = add nuw nsw i64 %indvars.iv18, 4
  %36 = getelementptr inbounds [500010 x i32], ptr @X, i64 0, i64 %indvars.iv.next19.3
  store i32 %35, ptr %36, align 16, !tbaa !5
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge15.loopexit.unr-lcssa, label %.lr.ph14, !llvm.loop !13

37:                                               ; preds = %._crit_edge15
  tail call void @_Z6solve0v()
  br label %39

38:                                               ; preds = %._crit_edge15
  tail call void @_Z6solve1v()
  br label %39

39:                                               ; preds = %38, %37
  ret i32 0
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) 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 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 #2 = { "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"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass