; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan (368)

; 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"

@n = external dso_local global i32, align 4
@A = external dso_local global i32, align 4
@B = external dso_local global i32, align 4
@C = external dso_local global i32, align 4
@f = external dso_local global [4194304 x i64], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @A, ptr noundef @B, ptr noundef @C)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %9

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

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

15:                                               ; preds = %9
  %16 = call noundef i32 @_Z5rng61v()
  %17 = zext i32 %16 to i64
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %19
  store i64 %17, ptr %20, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

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

25:                                               ; preds = %61, %24
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %64

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

31:                                               ; preds = %57, %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = shl i32 1, %33
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %60

37:                                               ; preds = %31
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = shl i32 1, %39
  %41 = and i32 %38, %40
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %56

43:                                               ; preds = %37
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = shl i32 1, %45
  %47 = sub nsw i32 %44, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = add nsw i64 %54, %50
  store i64 %55, ptr %53, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %43, %37
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !13

60:                                               ; preds = %36
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !14

64:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %78, %64
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = shl i32 1, %67
  %69 = icmp slt i32 %66, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %65
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %81

71:                                               ; preds = %65
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = load i64, ptr %6, align 8, !tbaa !9
  %77 = xor i64 %76, %75
  store i64 %77, ptr %6, align 8, !tbaa !9
  br label %78

78:                                               ; preds = %71
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %7, align 4, !tbaa !5
  br label %65, !llvm.loop !15

81:                                               ; preds = %70
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5rng61v() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { inlinehint 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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"

@n = external dso_local global i32, align 4
@A = external dso_local global i32, align 4
@B = external dso_local global i32, align 4
@C = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [4194304 x i64], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @A, ptr noundef nonnull @B, ptr noundef nonnull @C)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 31
  br i1 %.not, label %._crit_edge, label %.lr.ph

.preheader23:                                     ; preds = %.lr.ph
  %3 = icmp sgt i32 %40, 0
  br i1 %3, label %.preheader22.lr.ph, label %.preheader

.preheader22.lr.ph:                               ; preds = %.preheader23
  %.not59 = icmp eq i32 %40, 31
  br i1 %.not59, label %._crit_edge, label %.preheader22.us.preheader

.preheader22.us.preheader:                        ; preds = %.preheader22.lr.ph
  %wide.trip.count = zext i32 %41 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader22.us

.preheader22.us:                                  ; preds = %.preheader22.us.preheader, %._crit_edge.us
  %.02029.us = phi i32 [ %36, %._crit_edge.us ], [ 0, %.preheader22.us.preheader ]
  %4 = shl nuw i32 1, %.02029.us
  %5 = sext i32 %4 to i64
  br label %6

6:                                                ; preds = %26, %.preheader22.us
  %indvars.iv39 = phi i64 [ 0, %.preheader22.us ], [ %indvars.iv.next40.1, %26 ]
  %niter = phi i64 [ 0, %.preheader22.us ], [ %niter.next.1, %26 ]
  %7 = trunc nuw nsw i64 %indvars.iv39 to i32
  %8 = and i32 %4, %7
  %.not.us = icmp eq i32 %8, 0
  br i1 %.not.us, label %16, label %9

9:                                                ; preds = %6
  %10 = sub nsw i64 %indvars.iv39, %5
  %11 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %indvars.iv39
  %14 = load i64, ptr %13, align 16, !tbaa !9
  %15 = add nsw i64 %14, %12
  store i64 %15, ptr %13, align 16, !tbaa !9
  br label %16

16:                                               ; preds = %9, %6
  %indvars.iv.next40 = or disjoint i64 %indvars.iv39, 1
  %17 = trunc nuw nsw i64 %indvars.iv.next40 to i32
  %18 = and i32 %4, %17
  %.not.us.1 = icmp eq i32 %18, 0
  br i1 %.not.us.1, label %26, label %19

19:                                               ; preds = %16
  %20 = sub nsw i64 %indvars.iv.next40, %5
  %21 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %indvars.iv.next40
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = add nsw i64 %24, %22
  store i64 %25, ptr %23, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %19, %16
  %indvars.iv.next40.1 = add nuw nsw i64 %indvars.iv39, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %6, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %26
  %27 = trunc nuw nsw i64 %indvars.iv.next40.1 to i32
  %28 = and i32 %4, %27
  %.not.us.epil = icmp eq i32 %28, 0
  %or.cond = select i1 %lcmp.mod.not, i1 true, i1 %.not.us.epil
  br i1 %or.cond, label %._crit_edge.us, label %29

29:                                               ; preds = %._crit_edge.us.unr-lcssa
  %30 = sub nsw i64 %indvars.iv.next40.1, %5
  %31 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %indvars.iv.next40.1
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = add nsw i64 %34, %32
  store i64 %35, ptr %33, align 8, !tbaa !9
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %29, %._crit_edge.us.unr-lcssa
  %36 = add nuw nsw i32 %.02029.us, 1
  %exitcond42.not = icmp eq i32 %36, %40
  br i1 %exitcond42.not, label %.preheader, label %.preheader22.us, !llvm.loop !13

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %37 = tail call noundef i32 @_Z5rng61v()
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %indvars.iv
  store i64 %38, ptr %39, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = shl nuw i32 1, %40
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next, %42
  br i1 %43, label %.lr.ph, label %.preheader23, !llvm.loop !14

.preheader:                                       ; preds = %._crit_edge.us, %.preheader23
  %.not60 = icmp eq i32 %40, 31
  br i1 %.not60, label %._crit_edge, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %.preheader
  %wide.trip.count46 = zext nneg i32 %41 to i64
  %min.iters.check = icmp ult i32 %40, 2
  br i1 %min.iters.check, label %.lr.ph32, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph32.preheader
  %n.vec = and i64 %wide.trip.count46, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %46, %vector.body ]
  %vec.phi63 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %47, %vector.body ]
  %44 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %index
  %45 = getelementptr inbounds i8, ptr %44, i64 16
  %wide.load = load <2 x i64>, ptr %44, align 16, !tbaa !9
  %wide.load64 = load <2 x i64>, ptr %45, align 16, !tbaa !9
  %46 = xor <2 x i64> %wide.load, %vec.phi
  %47 = xor <2 x i64> %wide.load64, %vec.phi63
  %index.next = add nuw i64 %index, 4
  %48 = icmp eq i64 %index.next, %n.vec
  br i1 %48, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <2 x i64> %47, %46
  %49 = tail call i64 @llvm.vector.reduce.xor.v2i64(<2 x i64> %bin.rdx)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph32, %middle.block, %0, %.preheader22.lr.ph, %.preheader
  %.018.lcssa = phi i64 [ 0, %.preheader ], [ 0, %.preheader22.lr.ph ], [ 0, %0 ], [ %49, %middle.block ], [ %53, %.lr.ph32 ]
  %50 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.018.lcssa)
  ret i32 0

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.lr.ph32 ], [ 0, %.lr.ph32.preheader ]
  %.01830 = phi i64 [ %53, %.lr.ph32 ], [ 0, %.lr.ph32.preheader ]
  %51 = getelementptr inbounds [4194304 x i64], ptr @f, i64 0, i64 %indvars.iv43
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = xor i64 %52, %.01830
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !18
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5rng61v() local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.xor.v2i64(<2 x i64>) #3

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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !12, !17, !16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass