; LLVM IR from tangjz/acm-icpc :: poj (1363)

; 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
@stack = external dso_local global [1010 x i32], align 16
@top = external dso_local global i32, align 4
@nxt = external dso_local global i32, align 4
@seq = external dso_local global [1010 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 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
  store i32 0, ptr %1, align 4
  br label %5

5:                                                ; preds = %96, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %11

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

11:                                               ; preds = %8, %5
  %12 = phi i1 [ false, %5 ], [ %10, %8 ]
  br i1 %12, label %13, label %98

13:                                               ; preds = %11
  br label %14

14:                                               ; preds = %90, %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @seq)
  %16 = icmp ne i32 %15, -1
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load i32, ptr @seq, align 16, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br label %20

20:                                               ; preds = %17, %14
  %21 = phi i1 [ false, %14 ], [ %19, %17 ]
  br i1 %21, label %22, label %96

22:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %23

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

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

28:                                               ; preds = %23
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1010 x i32], ptr @seq, i64 0, i64 %30
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %31)
  br label %33

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %23, !llvm.loop !9

36:                                               ; preds = %27
  store i32 1, ptr @nxt, align 4, !tbaa !5
  store i32 -1, ptr @top, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %86, %36
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 9, ptr %4, align 4
  br label %89

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %64, %42
  %44 = load i32, ptr @top, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 0
  br i1 %45, label %62, label %46

46:                                               ; preds = %43
  %47 = load i32, ptr @nxt, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %60

50:                                               ; preds = %46
  %51 = load i32, ptr @top, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1010 x i32], ptr @seq, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp ne i32 %54, %58
  br label %60

60:                                               ; preds = %50, %46
  %61 = phi i1 [ false, %46 ], [ %59, %50 ]
  br label %62

62:                                               ; preds = %60, %43
  %63 = phi i1 [ true, %43 ], [ %61, %60 ]
  br i1 %63, label %64, label %71

64:                                               ; preds = %62
  %65 = load i32, ptr @nxt, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr @nxt, align 4, !tbaa !5
  %67 = load i32, ptr @top, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr @top, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %69
  store i32 %65, ptr %70, align 4, !tbaa !5
  br label %43, !llvm.loop !11

71:                                               ; preds = %62
  %72 = load i32, ptr @top, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1010 x i32], ptr @seq, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = icmp eq i32 %75, %79
  br i1 %80, label %81, label %84

81:                                               ; preds = %71
  %82 = load i32, ptr @top, align 4, !tbaa !5
  %83 = add nsw i32 %82, -1
  store i32 %83, ptr @top, align 4, !tbaa !5
  br label %85

84:                                               ; preds = %71
  store i32 9, ptr %4, align 4
  br label %89

85:                                               ; preds = %81
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %3, align 4, !tbaa !5
  br label %37, !llvm.loop !12

89:                                               ; preds = %84, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr @top, align 4, !tbaa !5
  %92 = icmp sge i32 %91, 0
  %93 = zext i1 %92 to i64
  %94 = select i1 %92, ptr @.str.1, ptr @.str.2
  %95 = call i32 @puts(ptr noundef %94)
  br label %14, !llvm.loop !13

96:                                               ; preds = %20
  %97 = call i32 @puts(ptr noundef @.str.3)
  br label %5, !llvm.loop !14

98:                                               ; preds = %11
  ret i32 0
}

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 @puts(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}
!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
@stack = external dso_local local_unnamed_addr global [1010 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@nxt = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local global [1010 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 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 ne i32 %1, -1
  %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 %.preheader12, label %._crit_edge24

.preheader12:                                     ; preds = %0, %._crit_edge23
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @seq)
  %7 = icmp ne i32 %6, -1
  %8 = load i32, ptr @seq, align 16
  %9 = icmp ne i32 %8, 0
  %10 = select i1 %7, i1 %9, i1 false
  br i1 %10, label %.preheader, label %._crit_edge23

.preheader:                                       ; preds = %.preheader12, %.critedge2._crit_edge.thread
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %11, %.preheader ], [ %16, %.lr.ph ]
  store i32 1, ptr @nxt, align 4, !tbaa !5
  store i32 -1, ptr @top, align 4, !tbaa !5
  %13 = icmp sgt i32 %.lcssa, 0
  br i1 %13, label %thread-pre-split.preheader, label %.critedge2._crit_edge.thread

thread-pre-split.preheader:                       ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %.lcssa to i64
  br label %thread-pre-split

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader ]
  %14 = getelementptr inbounds [1010 x i32], ptr @seq, i64 0, i64 %indvars.iv
  %15 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !9

thread-pre-split:                                 ; preds = %thread-pre-split.preheader, %35
  %indvars.iv31 = phi i64 [ 0, %thread-pre-split.preheader ], [ %indvars.iv.next32, %35 ]
  %.pr1520 = phi i32 [ -1, %thread-pre-split.preheader ], [ %37, %35 ]
  %nxt.promoted1819 = phi i32 [ 1, %thread-pre-split.preheader ], [ %nxt.promoted17, %35 ]
  %19 = getelementptr inbounds [1010 x i32], ptr @seq, i64 0, i64 %indvars.iv31
  %20 = sext i32 %.pr1520 to i64
  br label %21

21:                                               ; preds = %thread-pre-split, %.critedge
  %22 = phi i32 [ %.pr1520, %thread-pre-split ], [ %29, %.critedge ]
  %indvars.iv28 = phi i64 [ %20, %thread-pre-split ], [ %indvars.iv.next29, %.critedge ]
  %nxt.promoted17 = phi i32 [ %nxt.promoted1819, %thread-pre-split ], [ %28, %.critedge ]
  %23 = icmp slt i64 %indvars.iv28, 0
  br i1 %23, label %.critedge, label %24

24:                                               ; preds = %21
  %.not = icmp sgt i32 %nxt.promoted17, %.lcssa
  %.pre = load i32, ptr %19, align 4, !tbaa !5
  br i1 %.not, label %.critedge2, label %25

25:                                               ; preds = %24
  %26 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %indvars.iv28
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not11 = icmp eq i32 %27, %.pre
  br i1 %.not11, label %.critedge2, label %.critedge

.critedge:                                        ; preds = %21, %25
  %28 = add nsw i32 %nxt.promoted17, 1
  store i32 %28, ptr @nxt, align 4, !tbaa !5
  %indvars.iv.next29 = add nsw i64 %indvars.iv28, 1
  %29 = trunc nsw i64 %indvars.iv.next29 to i32
  store i32 %29, ptr @top, align 4, !tbaa !5
  %30 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %indvars.iv.next29
  store i32 %nxt.promoted17, ptr %30, align 4, !tbaa !5
  br label %21, !llvm.loop !11

.critedge2:                                       ; preds = %24, %25
  %31 = and i64 %indvars.iv28, 4294967295
  %32 = getelementptr inbounds [1010 x i32], ptr @stack, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, %.pre
  br i1 %34, label %35, label %.critedge2._crit_edge

35:                                               ; preds = %.critedge2
  %36 = trunc nsw i64 %indvars.iv28 to i32
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @top, align 4, !tbaa !5
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count
  br i1 %exitcond.not, label %.critedge2._crit_edge, label %thread-pre-split, !llvm.loop !12

.critedge2._crit_edge:                            ; preds = %35, %.critedge2
  %38 = phi i32 [ %22, %.critedge2 ], [ %37, %35 ]
  %.fr = freeze i32 %38
  %39 = icmp sgt i32 %.fr, -1
  %spec.select = select i1 %39, ptr @.str.1, ptr @.str.2
  br label %.critedge2._crit_edge.thread

.critedge2._crit_edge.thread:                     ; preds = %.critedge2._crit_edge, %._crit_edge
  %40 = phi ptr [ @.str.2, %._crit_edge ], [ %spec.select, %.critedge2._crit_edge ]
  %41 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %40)
  %42 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @seq)
  %43 = icmp ne i32 %42, -1
  %44 = load i32, ptr @seq, align 16
  %45 = icmp ne i32 %44, 0
  %46 = select i1 %43, i1 %45, i1 false
  br i1 %46, label %.preheader, label %._crit_edge23, !llvm.loop !13

._crit_edge23:                                    ; preds = %.critedge2._crit_edge.thread, %.preheader12
  %47 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  %48 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %49 = icmp ne i32 %48, -1
  %50 = load i32, ptr @n, align 4
  %51 = icmp ne i32 %50, 0
  %52 = select i1 %49, i1 %51, i1 false
  br i1 %52, label %.preheader12, label %._crit_edge24, !llvm.loop !14

._crit_edge24:                                    ; preds = %._crit_edge23, %0
  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 @puts(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" }

!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,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass