; LLVM IR from tangjz/acm-icpc :: 51nod (1007)

; 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
@x = external dso_local global i32, align 4
@f = external dso_local global [110 x [5010 x i32]], align 16
@.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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @f, align 16, !tbaa !5
  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 = %71, %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
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %74

12:                                               ; preds = %7
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %67, %12
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 5010
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [5010 x i32], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %18
  br label %67

29:                                               ; preds = %18
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @x, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = icmp slt i32 %32, 5010
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [5010 x i32], ptr %37, i64 0, i64 %41
  store i32 1, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %34, %29
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr @x, align 4, !tbaa !5
  %46 = sub nsw i32 %44, %45
  %47 = icmp sge i32 %46, 0
  br i1 %47, label %48, label %57

48:                                               ; preds = %43
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = load i32, ptr @x, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [5010 x i32], ptr %51, i64 0, i64 %55
  store i32 1, ptr %56, align 4, !tbaa !5
  br label %66

57:                                               ; preds = %43
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %59
  %61 = load i32, ptr @x, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sub nsw i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5010 x i32], ptr %60, i64 0, i64 %64
  store i32 1, ptr %65, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %57, %48
  br label %67

67:                                               ; preds = %66, %28
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !9

70:                                               ; preds = %17
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !11

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

75:                                               ; preds = %92, %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = icmp slt i32 %76, 5010
  br i1 %77, label %79, label %78

78:                                               ; preds = %75
  store i32 8, ptr %3, align 4
  br label %95

79:                                               ; preds = %75
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %81
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [5010 x i32], ptr %82, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %91

88:                                               ; preds = %79
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %89)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %95

91:                                               ; preds = %79
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %5, align 4, !tbaa !5
  br label %75, !llvm.loop !12

95:                                               ; preds = %88, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %96 = load i32, ptr %3, align 4
  switch i32 %96, label %100 [
    i32 8, label %97
    i32 1, label %98
  ]

97:                                               ; preds = %95
  store i32 0, ptr %1, align 4
  br label %98

98:                                               ; preds = %97, %95
  %99 = load i32, ptr %1, align 4
  ret i32 %99

100:                                              ; preds = %95
  unreachable
}

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: 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 = { 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}


; 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
@x = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [110 x [5010 x i32]], align 16
@.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 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)
  store i32 1, ptr @f, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not30 = icmp slt i32 %2, 1
  br i1 %.not30, label %..preheader_crit_edge, label %.lr.ph

..preheader_crit_edge:                            ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %.preheader

.preheader:                                       ; preds = %7, %..preheader_crit_edge
  %.pre-phi = phi i64 [ %.pre, %..preheader_crit_edge ], [ %9, %7 ]
  br label %21

.lr.ph:                                           ; preds = %0, %7
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %7 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %4 = add nsw i64 %indvars.iv36, -1
  %5 = load i32, ptr @x, align 4
  %6 = sext i32 %5 to i64
  br label %10

7:                                                ; preds = %20
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not.not = icmp slt i64 %indvars.iv36, %9
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

10:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %11 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %4, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not27 = icmp eq i32 %12, 0
  br i1 %.not27, label %20, label %13

13:                                               ; preds = %10
  %14 = add nsw i64 %indvars.iv, %6
  %15 = icmp slt i64 %14, 5010
  br i1 %15, label %16, label %.sink.split

16:                                               ; preds = %13
  %17 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %indvars.iv36, i64 %14
  store i32 1, ptr %17, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %16, %13
  %18 = sub nsw i64 %indvars.iv, %6
  %.sink44 = tail call i64 @llvm.abs.i64(i64 %18, i1 false)
  %19 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %indvars.iv36, i64 %.sink44
  store i32 1, ptr %19, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %.sink.split, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 5010
  br i1 %exitcond.not, label %7, label %10, !llvm.loop !11

21:                                               ; preds = %39, %.preheader
  %indvars.iv39 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next40.4, %39 ]
  %22 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %.pre-phi, i64 %indvars.iv39
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not26 = icmp eq i32 %23, 0
  br i1 %.not26, label %27, label %24

24:                                               ; preds = %36, %33, %30, %27, %21
  %indvars.iv39.lcssa = phi i64 [ %indvars.iv39, %21 ], [ %indvars.iv.next40, %27 ], [ %indvars.iv.next40.1, %30 ], [ %indvars.iv.next40.2, %33 ], [ %indvars.iv.next40.3, %36 ]
  %25 = trunc nuw nsw i64 %indvars.iv39.lcssa to i32
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %25)
  br label %.loopexit

27:                                               ; preds = %21
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %28 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %.pre-phi, i64 %indvars.iv.next40
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not26.1 = icmp eq i32 %29, 0
  br i1 %.not26.1, label %30, label %24

30:                                               ; preds = %27
  %indvars.iv.next40.1 = add nuw nsw i64 %indvars.iv39, 2
  %31 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %.pre-phi, i64 %indvars.iv.next40.1
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %.not26.2 = icmp eq i32 %32, 0
  br i1 %.not26.2, label %33, label %24

33:                                               ; preds = %30
  %indvars.iv.next40.2 = add nuw nsw i64 %indvars.iv39, 3
  %34 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %.pre-phi, i64 %indvars.iv.next40.2
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not26.3 = icmp eq i32 %35, 0
  br i1 %.not26.3, label %36, label %24

36:                                               ; preds = %33
  %indvars.iv.next40.3 = add nuw nsw i64 %indvars.iv39, 4
  %37 = getelementptr inbounds [110 x [5010 x i32]], ptr @f, i64 0, i64 %.pre-phi, i64 %indvars.iv.next40.3
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %.not26.4 = icmp eq i32 %38, 0
  br i1 %.not26.4, label %39, label %24

39:                                               ; preds = %36
  %indvars.iv.next40.4 = add nuw nsw i64 %indvars.iv39, 5
  %exitcond42.not.4 = icmp eq i64 %indvars.iv.next40.4, 5010
  br i1 %exitcond42.not.4, label %.loopexit, label %21, !llvm.loop !12

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

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

; 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.abs.i64(i64, i1 immarg) #2

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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