; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-24 (C)

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

@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@pos = external dso_local global [62501 x i32], align 16
@f = external dso_local global [62501 x i32], align 16
@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 [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %74, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @t, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 0, i64 250004, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @pos, i8 0, i64 250004, i1 false)
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p, ptr noundef @q)
  %17 = load i32, ptr @p, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @p, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  br label %19

19:                                               ; preds = %30, %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr @p, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [62501 x i32], ptr @pos, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %24
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %4, align 4, !tbaa !5
  br label %19, !llvm.loop !9

33:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  br label %34

34:                                               ; preds = %67, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr @q, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %34
  %40 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7)
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [62501 x i32], ptr @pos, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %39
  br label %67

48:                                               ; preds = %39
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load i32, ptr @ans, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr @f, i64 %51
  %53 = getelementptr inbounds i32, ptr %52, i64 1
  %54 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds (i32, ptr @f, i64 1), ptr noundef %53, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %55 = ptrtoint ptr %54 to i64
  %56 = sub i64 %55, ptrtoint (ptr @f to i64)
  %57 = sdiv exact i64 %56, 4
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %8, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [62501 x i32], ptr @f, i64 0, i64 %59
  store i32 %49, ptr %60, align 4, !tbaa !5
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %48
  %65 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %65, ptr @ans, align 4, !tbaa !5
  br label %66

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

67:                                               ; preds = %66, %47
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !11

70:                                               ; preds = %38
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = load i32, ptr @ans, align 4, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %71, i32 noundef %72)
  br label %74

74:                                               ; preds = %70
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !12

77:                                               ; preds = %14
  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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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"

@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@pos = external dso_local local_unnamed_addr global [62501 x i32], align 16
@f = external dso_local global [62501 x i32], align 16
@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 [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %.not24 = icmp slt i32 %4, 1
  br i1 %.not24, label %._crit_edge28, label %.lr.ph27

._crit_edge28:                                    ; preds = %._crit_edge23, %0
  ret i32 0

.lr.ph27:                                         ; preds = %0, %._crit_edge23
  %.025 = phi i32 [ %17, %._crit_edge23 ], [ 1, %0 ]
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(250004) @f, i8 0, i64 250004, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(250004) @pos, i8 0, i64 250004, i1 false)
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p, ptr noundef nonnull @q)
  %6 = load i32, ptr @p, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @p, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %.not1417 = icmp slt i32 %6, 0
  br i1 %.not1417, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %8 = load i32, ptr @q, align 4, !tbaa !5
  %.not1519 = icmp slt i32 %8, 0
  br i1 %.not1519, label %._crit_edge23, label %.lr.ph22

.lr.ph:                                           ; preds = %.lr.ph27, %.lr.ph
  %.01118 = phi i32 [ %13, %.lr.ph ], [ 1, %.lr.ph27 ]
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [62501 x i32], ptr @pos, i64 0, i64 %11
  store i32 %.01118, ptr %12, align 4, !tbaa !5
  %13 = add nuw nsw i32 %.01118, 1
  %14 = load i32, ptr @p, align 4, !tbaa !5
  %.not14.not = icmp slt i32 %.01118, %14
  br i1 %.not14.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge23:                                    ; preds = %37, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %15 = load i32, ptr @ans, align 4, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.025, i32 noundef %15)
  %17 = add nuw nsw i32 %.025, 1
  %18 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.025, %18
  br i1 %.not.not, label %.lr.ph27, label %._crit_edge28, !llvm.loop !11

.lr.ph22:                                         ; preds = %._crit_edge, %37
  %.01020 = phi i32 [ %38, %37 ], [ 0, %._crit_edge ]
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [62501 x i32], ptr @pos, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %2, align 4, !tbaa !5
  %.not16 = icmp eq i32 %23, 0
  br i1 %.not16, label %37, label %24

24:                                               ; preds = %.lr.ph22
  %25 = load i32, ptr @ans, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), i64 %26
  %27 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @f, i64 4), ptr noundef nonnull %gep, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %28 = ptrtoint ptr %27 to i64
  %29 = sub i64 %28, ptrtoint (ptr @f to i64)
  %30 = lshr exact i64 %29, 2
  %31 = trunc i64 %30 to i32
  %sext = shl i64 %29, 30
  %32 = ashr i64 %sext, 32
  %33 = getelementptr inbounds [62501 x i32], ptr @f, i64 0, i64 %32
  store i32 %23, ptr %33, align 4, !tbaa !5
  %34 = load i32, ptr @ans, align 4, !tbaa !5
  %35 = icmp slt i32 %34, %31
  br i1 %35, label %36, label %37

36:                                               ; preds = %24
  store i32 %31, ptr @ans, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %24, %36, %.lr.ph22
  %38 = add nuw nsw i32 %.01020, 1
  %39 = load i32, ptr @q, align 4, !tbaa !5
  %.not15.not = icmp slt i32 %.01020, %39
  br i1 %.not15.not, label %.lr.ph22, label %._crit_edge23, !llvm.loop !12
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass