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

; 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 [100001 x i32], align 16
@pos = external dso_local global [100001 x i32], align 16
@f = external dso_local global [100001 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
  store i32 0, ptr %1, align 4
  %3 = 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 %4

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

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

9:                                                ; preds = %4
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i32, ptr @a, i64 %11
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %12)
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 2, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %40

28:                                               ; preds = %9
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  br label %41

40:                                               ; preds = %9
  br label %41

41:                                               ; preds = %40, %28
  %42 = phi i32 [ %39, %28 ], [ 0, %40 ]
  %43 = sub nsw i32 %19, %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp sge i32 %50, 1000000007
  br i1 %51, label %52, label %58

52:                                               ; preds = %41
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1000000007
  store i32 %57, ptr %55, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %52, %41
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = icmp slt i32 %62, 0
  br i1 %63, label %64, label %70

64:                                               ; preds = %58
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1000000007
  store i32 %69, ptr %67, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %64, %58
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %76
  store i32 %71, ptr %77, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %70
  %79 = load i32, ptr %2, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

81:                                               ; preds = %8
  %82 = load i32, ptr @f, align 16, !tbaa !5
  %83 = load i32, ptr @n, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = sub nsw i32 %86, %82
  store i32 %87, ptr %85, align 4, !tbaa !5
  %88 = load i32, ptr @n, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = icmp slt i32 %91, 0
  br i1 %92, label %93, label %99

93:                                               ; preds = %81
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1000000007
  store i32 %98, ptr %96, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %93, %81
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %103)
  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"}


; 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 [100001 x i32], align 16
@pos = external dso_local local_unnamed_addr global [100001 x i32], align 16
@f = external dso_local local_unnamed_addr global [100001 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
  %.not21 = icmp slt i32 %2, 1
  br i1 %.not21, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre25 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge.loopexit:                             ; preds = %25
  %.pre = load i32, ptr @f, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.._crit_edge_crit_edge, %._crit_edge.loopexit
  %.pre-phi = phi i64 [ %.pre25, %.._crit_edge_crit_edge ], [ %35, %._crit_edge.loopexit ]
  %3 = phi i32 [ 1, %.._crit_edge_crit_edge ], [ %.pre, %._crit_edge.loopexit ]
  %4 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %.pre-phi
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sub nsw i32 %5, %3
  %7 = icmp slt i32 %6, 0
  %8 = add nsw i32 %6, 1000000007
  %spec.select20 = select i1 %7, i32 %8, i32 %6
  store i32 %spec.select20, ptr %4, align 4, !tbaa !5
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %spec.select20)
  ret i32 0

.lr.ph:                                           ; preds = %0, %25
  %indvars.iv = phi i64 [ %indvars.iv.next, %25 ], [ 1, %0 ]
  %10 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %10)
  %12 = add nsw i64 %indvars.iv, -1
  %13 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = shl nsw i32 %14, 1
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not18 = icmp eq i32 %19, 0
  br i1 %.not18, label %25, label %20

20:                                               ; preds = %.lr.ph
  %21 = add nsw i32 %19, -1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %.lr.ph, %20
  %26 = phi i32 [ %24, %20 ], [ 0, %.lr.ph ]
  %27 = sub nsw i32 %15, %26
  %28 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %indvars.iv
  %29 = icmp sgt i32 %27, 1000000006
  %30 = add nsw i32 %27, -1000000007
  %spec.select = select i1 %29, i32 %30, i32 %27
  %31 = icmp slt i32 %spec.select, 0
  %32 = add nsw i32 %spec.select, 1000000007
  %storemerge19 = select i1 %31, i32 %32, i32 %spec.select
  store i32 %storemerge19, ptr %28, align 4, !tbaa !5
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %33, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %.not.not = icmp slt i64 %indvars.iv, %35
  br i1 %.not.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9
}

; 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"}


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