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

; 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
@num = external dso_local global [50001 x i32], align 16
@tmp = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.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 uwtable
declare dso_local void @_Z3dfsi(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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  br label %3

3:                                                ; preds = %69, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br label %9

9:                                                ; preds = %6, %3
  %10 = phi i1 [ false, %3 ], [ %8, %6 ]
  br i1 %10, label %11, label %72

11:                                               ; preds = %9
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %21, %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 %16, label %24

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

21:                                               ; preds = %16
  %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 %12, !llvm.loop !9

24:                                               ; preds = %12
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %25

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

29:                                               ; preds = %25
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i32, ptr @tmp, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @tmp, align 4, !tbaa !5
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %36
  store i32 %33, ptr %37, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %55, %29
  %39 = load i32, ptr @tmp, align 4, !tbaa !5
  %40 = icmp sge i32 %39, 3
  br i1 %40, label %41, label %53

41:                                               ; preds = %38
  %42 = load i32, ptr @tmp, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 3
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr @tmp, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp sle i32 %46, %51
  br label %53

53:                                               ; preds = %41, %38
  %54 = phi i1 [ false, %38 ], [ %52, %41 ]
  br i1 %54, label %55, label %58

55:                                               ; preds = %53
  %56 = load i32, ptr @tmp, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 2
  call void @_Z3dfsi(i32 noundef %57)
  br label %38, !llvm.loop !11

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %25, !llvm.loop !12

62:                                               ; preds = %25
  br label %63

63:                                               ; preds = %66, %62
  %64 = load i32, ptr @tmp, align 4, !tbaa !5
  %65 = icmp sgt i32 %64, 1
  br i1 %65, label %66, label %69

66:                                               ; preds = %63
  %67 = load i32, ptr @tmp, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  call void @_Z3dfsi(i32 noundef %68)
  br label %63, !llvm.loop !13

69:                                               ; preds = %63
  %70 = load i32, ptr @ans, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %70)
  br label %3, !llvm.loop !14

72:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

declare i32 @printf(ptr noundef, ...) #3

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 = { "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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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
@num = external dso_local global [50001 x i32], align 16
@tmp = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.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 uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = icmp ne i32 %1, 0
  %3 = load i32, ptr @n, align 4
  %4 = icmp ne i32 %3, 0
  %5 = select i1 %2, i1 %4, i1 false
  br i1 %5, label %.preheader8, label %._crit_edge18

.preheader8:                                      ; preds = %0, %._crit_edge17
  %6 = phi i32 [ %48, %._crit_edge17 ], [ %3, %0 ]
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader8
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge17

.lr.ph:                                           ; preds = %.preheader8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader8 ]
  %8 = getelementptr inbounds i32, ptr @num, 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 !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  %13 = icmp sgt i32 %10, 1
  br i1 %13, label %.lr.ph15, label %._crit_edge17

.preheader:                                       ; preds = %.critedge
  %14 = icmp sgt i32 %37, 1
  br i1 %14, label %.lr.ph16, label %._crit_edge17

.lr.ph15:                                         ; preds = %._crit_edge, %.critedge
  %15 = phi i32 [ %36, %.critedge ], [ %10, %._crit_edge ]
  %16 = phi i32 [ %37, %.critedge ], [ 1, %._crit_edge ]
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %.critedge ], [ 1, %._crit_edge ]
  %17 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %indvars.iv20
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %16, 1
  store i32 %19, ptr @tmp, align 4, !tbaa !5
  %20 = sext i32 %16 to i64
  %21 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  %22 = icmp sgt i32 %16, 1
  br i1 %22, label %.lr.ph11, label %.critedge

.lr.ph11:                                         ; preds = %.lr.ph15, %32
  %23 = phi i32 [ %.pr, %32 ], [ %19, %.lr.ph15 ]
  %24 = add nsw i32 %23, -3
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %23, -1
  %29 = zext nneg i32 %28 to i64
  %30 = getelementptr inbounds [50001 x i32], ptr @num, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not = icmp sgt i32 %27, %31
  br i1 %.not, label %.critedge.loopexit, label %32

32:                                               ; preds = %.lr.ph11
  %33 = add nsw i32 %23, -2
  tail call void @_Z3dfsi(i32 noundef %33)
  %.pr = load i32, ptr @tmp, align 4, !tbaa !5
  %34 = icmp sgt i32 %.pr, 2
  br i1 %34, label %.lr.ph11, label %.critedge.loopexit, !llvm.loop !11

.critedge.loopexit:                               ; preds = %.lr.ph11, %32
  %35 = phi i32 [ %23, %.lr.ph11 ], [ %.pr, %32 ]
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph15
  %36 = phi i32 [ %.pre, %.critedge.loopexit ], [ %15, %.lr.ph15 ]
  %37 = phi i32 [ %35, %.critedge.loopexit ], [ %19, %.lr.ph15 ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %38 = sext i32 %36 to i64
  %39 = icmp slt i64 %indvars.iv.next21, %38
  br i1 %39, label %.lr.ph15, label %.preheader, !llvm.loop !12

.lr.ph16:                                         ; preds = %.preheader, %.lr.ph16
  %40 = phi i32 [ %42, %.lr.ph16 ], [ %37, %.preheader ]
  %41 = add nsw i32 %40, -1
  tail call void @_Z3dfsi(i32 noundef %41)
  %42 = load i32, ptr @tmp, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 1
  br i1 %43, label %.lr.ph16, label %._crit_edge17, !llvm.loop !13

._crit_edge17:                                    ; preds = %.lr.ph16, %._crit_edge.thread, %._crit_edge, %.preheader
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %44)
  %46 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %47 = icmp ne i32 %46, 0
  %48 = load i32, ptr @n, align 4
  %49 = icmp ne i32 %48, 0
  %50 = select i1 %47, i1 %49, i1 false
  br i1 %50, label %.preheader8, label %._crit_edge18, !llvm.loop !14

._crit_edge18:                                    ; preds = %._crit_edge17, %0
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 = { 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" }

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


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