; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1156)

; 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 [1001 x i32], align 16
@b = external dso_local global [1001 x i32], align 16
@c = external dso_local global [10010 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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 i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %8

8:                                                ; preds = %110, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %111

11:                                               ; preds = %8
  call void @llvm.memset.p0.i64(ptr align 16 @c, i8 0, i64 40040, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %22, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %25

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @a, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %20)
  br label %22

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

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

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

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

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr @b, i64 %33
  %35 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %34)
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !11

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

40:                                               ; preds = %83, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

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

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

46:                                               ; preds = %79, %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 13, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %82

51:                                               ; preds = %46
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1001 x i32], ptr @b, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = add nsw i32 %55, %59
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = mul nsw i32 10, %61
  %63 = icmp sle i32 %60, %62
  br i1 %63, label %64, label %78

64:                                               ; preds = %51
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1001 x i32], ptr @b, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = add nsw i32 %68, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %75, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %64, %51
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !5
  br label %46, !llvm.loop !12

82:                                               ; preds = %50
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %4, align 4, !tbaa !5
  br label %40, !llvm.loop !13

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

87:                                               ; preds = %107, %86
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = load i32, ptr @n, align 4, !tbaa !5
  %90 = mul nsw i32 10, %89
  %91 = icmp sle i32 %88, %90
  br i1 %91, label %93, label %92

92:                                               ; preds = %87
  store i32 16, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %110

93:                                               ; preds = %87
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %99, label %106

99:                                               ; preds = %93
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %100, i32 noundef %104)
  br label %106

106:                                              ; preds = %99, %93
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %7, align 4, !tbaa !5
  br label %87, !llvm.loop !14

110:                                              ; preds = %92
  br label %8, !llvm.loop !15

111:                                              ; preds = %8
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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 [1001 x i32], align 16
@b = external dso_local global [1001 x i32], align 16
@c = external dso_local local_unnamed_addr global [10010 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree 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)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph40, label %._crit_edge

.loopexit:                                        ; preds = %56, %.preheader28
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.lr.ph40, label %._crit_edge, !llvm.loop !5

.lr.ph40:                                         ; preds = %0, %.loopexit
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40040) @c, i8 0, i64 40040, i1 false)
  %5 = load i32, ptr @n, align 4, !tbaa !7
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.preheader28

.preheader30:                                     ; preds = %.lr.ph
  %7 = icmp sgt i32 %10, 0
  br i1 %7, label %.lr.ph33, label %.preheader28

.lr.ph:                                           ; preds = %.lr.ph40, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph40 ]
  %8 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !7
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %.preheader30, !llvm.loop !11

.preheader29:                                     ; preds = %.lr.ph33
  %13 = icmp sgt i32 %46, 0
  br i1 %13, label %.preheader.lr.ph, label %.preheader28

.preheader.lr.ph:                                 ; preds = %.preheader29
  %14 = mul nuw nsw i32 %46, 10
  %wide.trip.count52 = zext nneg i32 %46 to i64
  %xtraiter = and i64 %wide.trip.count52, 1
  %15 = icmp eq i32 %46, 1
  %unroll_iter = and i64 %wide.trip.count52, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %16 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %indvars.iv49
  %17 = load i32, ptr %16, align 4, !tbaa !7
  br i1 %15, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %35
  %indvars.iv46 = phi i64 [ %indvars.iv.next47.1, %35 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %35 ], [ 0, %.preheader.us ]
  %18 = getelementptr inbounds [1001 x i32], ptr @b, i64 0, i64 %indvars.iv46
  %19 = load i32, ptr %18, align 8, !tbaa !7
  %20 = add nsw i32 %19, %17
  %.not27.us = icmp sgt i32 %20, %14
  br i1 %.not27.us, label %26, label %21

21:                                               ; preds = %.preheader.us.new
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !7
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !7
  br label %26

26:                                               ; preds = %21, %.preheader.us.new
  %indvars.iv.next47 = or disjoint i64 %indvars.iv46, 1
  %27 = getelementptr inbounds [1001 x i32], ptr @b, i64 0, i64 %indvars.iv.next47
  %28 = load i32, ptr %27, align 4, !tbaa !7
  %29 = add nsw i32 %28, %17
  %.not27.us.1 = icmp sgt i32 %29, %14
  br i1 %.not27.us.1, label %35, label %30

30:                                               ; preds = %26
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !7
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %32, align 4, !tbaa !7
  br label %35

35:                                               ; preds = %30, %26
  %indvars.iv.next47.1 = add nuw nsw i64 %indvars.iv46, 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 %.preheader.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %35, %.preheader.us
  %indvars.iv46.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next47.1, %35 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %36 = getelementptr inbounds [1001 x i32], ptr @b, i64 0, i64 %indvars.iv46.unr
  %37 = load i32, ptr %36, align 4, !tbaa !7
  %38 = add nsw i32 %37, %17
  %.not27.us.epil = icmp sgt i32 %38, %14
  br i1 %.not27.us.epil, label %._crit_edge.us, label %39

39:                                               ; preds = %.epil.preheader
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !7
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !7
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %39, %._crit_edge.us.unr-lcssa
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %.preheader28, label %.preheader.us, !llvm.loop !13

.lr.ph33:                                         ; preds = %.preheader30, %.lr.ph33
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.lr.ph33 ], [ 0, %.preheader30 ]
  %44 = getelementptr inbounds i32, ptr @b, i64 %indvars.iv43
  %45 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %44)
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %46 = load i32, ptr @n, align 4, !tbaa !7
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %indvars.iv.next44, %47
  br i1 %48, label %.lr.ph33, label %.preheader29, !llvm.loop !14

.preheader28:                                     ; preds = %._crit_edge.us, %.lr.ph40, %.preheader30, %.preheader29
  %49 = phi i32 [ %46, %.preheader29 ], [ %10, %.preheader30 ], [ %5, %.lr.ph40 ], [ %46, %._crit_edge.us ]
  %.not37 = icmp slt i32 %49, 0
  br i1 %.not37, label %.loopexit, label %.lr.ph39

.lr.ph39:                                         ; preds = %.preheader28, %56
  %50 = phi i32 [ %57, %56 ], [ %49, %.preheader28 ]
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %56 ], [ 0, %.preheader28 ]
  %51 = getelementptr inbounds [10010 x i32], ptr @c, i64 0, i64 %indvars.iv54
  %52 = load i32, ptr %51, align 4, !tbaa !7
  %.not26 = icmp eq i32 %52, 0
  br i1 %.not26, label %56, label %53

53:                                               ; preds = %.lr.ph39
  %54 = trunc nuw nsw i64 %indvars.iv54 to i32
  %55 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %54, i32 noundef %52)
  %.pre = load i32, ptr @n, align 4, !tbaa !7
  br label %56

56:                                               ; preds = %.lr.ph39, %53
  %57 = phi i32 [ %50, %.lr.ph39 ], [ %.pre, %53 ]
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %58 = mul nsw i32 %57, 10
  %59 = sext i32 %58 to i64
  %.not.not = icmp slt i64 %indvars.iv54, %59
  br i1 %.not.not, label %.lr.ph39, label %.loopexit, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { mustprogress nofree 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 nounwind willreturn memory(argmem: write) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}


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