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

; 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 [100001 x i32], align 16
@c = external dso_local global [1000001 x i32], align 16
@lim = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printi(i32 noundef) #0

; 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

; 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %36, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %14
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %15)
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  %24 = load i32, ptr @lim, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp slt i32 %24, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %12
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr @lim, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %30, %12
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

39:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %40 = load i32, ptr @lim, align 4, !tbaa !5
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %69, %39
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %45, label %44

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

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %64, %45
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr @lim, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %68

54:                                               ; preds = %49
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = add nsw i32 %62, %58
  store i32 %63, ptr %61, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %54
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = add nsw i32 %66, %65
  store i32 %67, ptr %5, align 4, !tbaa !5
  br label %49, !llvm.loop !11

68:                                               ; preds = %53
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr %3, align 4, !tbaa !5
  br label %41, !llvm.loop !12

72:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %87, %72
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = icmp sle i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %90

78:                                               ; preds = %73
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  call void @_Z5printi(i32 noundef %86)
  br label %87

87:                                               ; preds = %78
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %73, !llvm.loop !13

90:                                               ; preds = %77
  ret i32 0
}

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 = { 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 = { 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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@n = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@c = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@lim = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not25 = icmp slt i32 %1, 1
  br i1 %.not25, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @lim, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge.loopexit:                             ; preds = %15
  %2 = icmp slt i32 %17, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.._crit_edge_crit_edge, %._crit_edge.loopexit
  %.not2336 = phi i1 [ true, %.._crit_edge_crit_edge ], [ %2, %._crit_edge.loopexit ]
  %3 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %16, %._crit_edge.loopexit ]
  %.not2232 = icmp eq i32 %3, 0
  br i1 %.not2232, label %.preheader, label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %._crit_edge
  %4 = shl i32 %3, 1
  %5 = sext i32 %3 to i64
  br label %.lr.ph35

.lr.ph:                                           ; preds = %0, %15
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 1, %0 ]
  %6 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %6)
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr @lim, align 4, !tbaa !5
  %13 = icmp slt i32 %12, %7
  br i1 %13, label %14, label %15

14:                                               ; preds = %.lr.ph
  store i32 %7, ptr @lim, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %.lr.ph, %14
  %16 = phi i32 [ %12, %.lr.ph ], [ %7, %14 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %.not.not = icmp slt i64 %indvars.iv, %18
  br i1 %.not.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

.preheader:                                       ; preds = %._crit_edge31, %._crit_edge
  br i1 %.not2336, label %._crit_edge39, label %.lr.ph38

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %._crit_edge31
  %indvars.iv43 = phi i64 [ %5, %.lr.ph35.preheader ], [ %indvars.iv.next44, %._crit_edge31 ]
  %indvars.iv41 = phi i32 [ %4, %.lr.ph35.preheader ], [ %indvars.iv.next42, %._crit_edge31 ]
  %19 = shl nsw i64 %indvars.iv43, 1
  %.not2427 = icmp sgt i64 %19, %5
  br i1 %.not2427, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph35
  %20 = sext i32 %indvars.iv41 to i64
  %21 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %indvars.iv43
  br label %22

._crit_edge31:                                    ; preds = %22, %.lr.ph35
  %indvars.iv.next44 = add nsw i64 %indvars.iv43, -1
  %.not22 = icmp eq i64 %indvars.iv.next44, 0
  %indvars.iv.next42 = add i32 %indvars.iv41, -2
  br i1 %.not22, label %.preheader, label %.lr.ph35, !llvm.loop !11

22:                                               ; preds = %.lr.ph30, %22
  %indvars.iv45 = phi i64 [ %20, %.lr.ph30 ], [ %indvars.iv.next46, %22 ]
  %23 = load i32, ptr %21, align 4, !tbaa !5
  %24 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %indvars.iv45
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, %23
  store i32 %26, ptr %24, align 4, !tbaa !5
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, %indvars.iv43
  %.not24 = icmp sgt i64 %indvars.iv.next46, %5
  br i1 %.not24, label %._crit_edge31, label %22, !llvm.loop !12

._crit_edge39:                                    ; preds = %.lr.ph38, %.preheader
  ret i32 0

.lr.ph38:                                         ; preds = %.preheader, %.lr.ph38
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %.lr.ph38 ], [ 1, %.preheader ]
  %27 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv49
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000001 x i32], ptr @c, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  tail call void @_Z5printi(i32 noundef %32)
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %.not23.not = icmp slt i64 %indvars.iv49, %34
  br i1 %.not23.not, label %.lr.ph38, label %._crit_edge39, !llvm.loop !13
}

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

!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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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