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

; 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
@cnt = external dso_local global [1000001 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)
  br label %7

7:                                                ; preds = %11, %0
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %18

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %13 = load i32, ptr @x, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000001 x i32], ptr @cnt, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 4, !tbaa !5
  br label %7, !llvm.loop !9

18:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1000000, ptr %2, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %55, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 1
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 4, ptr %3, align 4
  br label %58

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

25:                                               ; preds = %41, %23
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 1000001
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 2
  br label %31

31:                                               ; preds = %28, %25
  %32 = phi i1 [ false, %25 ], [ %30, %28 ]
  br i1 %32, label %34, label %33

33:                                               ; preds = %31
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %45

34:                                               ; preds = %31
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000001 x i32], ptr @cnt, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr %4, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %5, align 4, !tbaa !5
  br label %25, !llvm.loop !11

45:                                               ; preds = %33
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = icmp sge i32 %46, 2
  br i1 %47, label %48, label %51

48:                                               ; preds = %45
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %49)
  store i32 4, ptr %3, align 4
  br label %52

51:                                               ; preds = %45
  store i32 0, ptr %3, align 4
  br label %52

52:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %53 = load i32, ptr %3, align 4
  switch i32 %53, label %58 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr %2, align 4, !tbaa !5
  br label %19, !llvm.loop !12

58:                                               ; preds = %52, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %59

59:                                               ; preds = %58
  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 @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
@cnt = external dso_local local_unnamed_addr global [1000001 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %.lr.ph20.preheader.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %5 = load i32, ptr @x, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [1000001 x i32], ptr @cnt, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.lr.ph20.preheader.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph20.preheader.preheader:                     ; preds = %.lr.ph, %0
  br label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %.critedge.1, %.lr.ph20.preheader.preheader
  %indvars.iv = phi i64 [ 1000000, %.lr.ph20.preheader.preheader ], [ %indvars.iv.next.1, %.critedge.1 ]
  br label %.lr.ph20

._crit_edge:                                      ; preds = %.lr.ph20
  br i1 %16, label %.critedge, label %.split.loop.exit32

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %.lr.ph20
  %indvars.iv23 = phi i64 [ %indvars.iv, %.lr.ph20.preheader ], [ %indvars.iv.next24, %.lr.ph20 ]
  %.01218 = phi i32 [ 0, %.lr.ph20.preheader ], [ %14, %.lr.ph20 ]
  %12 = getelementptr inbounds [1000001 x i32], ptr @cnt, i64 0, i64 %indvars.iv23
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = add nsw i32 %13, %.01218
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, %indvars.iv
  %15 = icmp ult i64 %indvars.iv.next24, 1000001
  %16 = icmp slt i32 %14, 2
  %17 = select i1 %15, i1 %16, i1 false
  br i1 %17, label %.lr.ph20, label %._crit_edge, !llvm.loop !11

.split.loop.exit32:                               ; preds = %._crit_edge
  %indvars26.le = trunc i64 %indvars.iv to i32
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %._crit_edge.1, %.split.loop.exit32
  %indvars26.lcssa = phi i32 [ %indvars26.le, %.split.loop.exit32 ], [ %indvars26.1, %._crit_edge.1 ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %indvars26.lcssa)
  br label %.loopexit

.critedge:                                        ; preds = %._crit_edge
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %indvars26.1 = trunc i64 %indvars.iv.next to i32
  br label %.lr.ph20.1

.lr.ph20.1:                                       ; preds = %.lr.ph20.1, %.critedge
  %indvars.iv23.1 = phi i64 [ %indvars.iv.next, %.critedge ], [ %indvars.iv.next24.1, %.lr.ph20.1 ]
  %.01218.1 = phi i32 [ 0, %.critedge ], [ %21, %.lr.ph20.1 ]
  %19 = getelementptr inbounds [1000001 x i32], ptr @cnt, i64 0, i64 %indvars.iv23.1
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %.01218.1
  %indvars.iv.next24.1 = add nuw nsw i64 %indvars.iv23.1, %indvars.iv.next
  %22 = icmp ult i64 %indvars.iv.next24.1, 1000001
  %23 = icmp slt i32 %21, 2
  %24 = select i1 %22, i1 %23, i1 false
  br i1 %24, label %.lr.ph20.1, label %._crit_edge.1, !llvm.loop !11

._crit_edge.1:                                    ; preds = %.lr.ph20.1
  br i1 %23, label %.critedge.1, label %.split.loop.exit

.critedge.1:                                      ; preds = %._crit_edge.1
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %.not30 = icmp eq i32 %indvars26.1, 1
  br i1 %.not30, label %.loopexit, label %.lr.ph20.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %.critedge.1, %.split.loop.exit
  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

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}


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