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

; 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
@l = external dso_local global i32, align 4
@q = external dso_local global [50001 x i32], align 16
@sum = external dso_local global [50001 x i64], align 16
@f = external dso_local global [50001 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5checkiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4calcii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @l)
  %7 = load i32, ptr @l, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @l, align 4, !tbaa !5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %27, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %13, label %30

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50001 x i64], ptr @sum, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = add nsw i64 %19, %21
  %23 = add nsw i64 %22, 1
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [50001 x i64], ptr @sum, i64 0, i64 %25
  store i64 %23, ptr %26, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %13
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

30:                                               ; preds = %9
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %97, %30
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %35, label %100

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %57, %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %55

40:                                               ; preds = %36
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call noundef i64 @_Z4calcii(i32 noundef %41, i32 noundef %45)
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = call noundef i64 @_Z4calcii(i32 noundef %47, i32 noundef %52)
  %54 = icmp sgt i64 %46, %53
  br label %55

55:                                               ; preds = %40, %36
  %56 = phi i1 [ false, %36 ], [ %54, %40 ]
  br i1 %56, label %57, label %60

57:                                               ; preds = %55
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !13

60:                                               ; preds = %55
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = call noundef i64 @_Z4calcii(i32 noundef %61, i32 noundef %65)
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [50001 x i64], ptr @f, i64 0, i64 %68
  store i64 %66, ptr %69, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %88, %60
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %74, label %86

74:                                               ; preds = %70
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = call noundef zeroext i1 @_Z5checkiii(i32 noundef %75, i32 noundef %80, i32 noundef %84)
  br label %86

86:                                               ; preds = %74, %70
  %87 = phi i1 [ false, %70 ], [ %85, %74 ]
  br i1 %87, label %88, label %91

88:                                               ; preds = %86
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %5, align 4, !tbaa !5
  br label %70, !llvm.loop !14

91:                                               ; preds = %86
  %92 = load i32, ptr %2, align 4, !tbaa !5
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %5, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %95
  store i32 %92, ptr %96, align 4, !tbaa !5
  br label %97

97:                                               ; preds = %91
  %98 = load i32, ptr %2, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %2, align 4, !tbaa !5
  br label %31, !llvm.loop !15

100:                                              ; preds = %31
  %101 = load i32, ptr @n, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [50001 x i64], ptr @f, i64 0, i64 %102
  %104 = load i64, ptr %103, align 8, !tbaa !9
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %104)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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
@l = external dso_local global i32, align 4
@q = external dso_local local_unnamed_addr global [50001 x i32], align 16
@sum = external dso_local local_unnamed_addr global [50001 x i64], align 16
@f = external dso_local local_unnamed_addr global [50001 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5checkiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4calcii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @l)
  %3 = load i32, ptr @l, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @l, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not33 = icmp slt i32 %5, 1
  br i1 %.not33, label %.preheader32.._crit_edge_crit_edge, label %.lr.ph

.preheader32:                                     ; preds = %.lr.ph
  %.not3135 = icmp slt i32 %16, 1
  br i1 %.not3135, label %.preheader32.._crit_edge_crit_edge, label %.preheader

.preheader32.._crit_edge_crit_edge:               ; preds = %0, %.preheader32
  %6 = phi i32 [ %16, %.preheader32 ], [ %5, %0 ]
  %.pre = sext i32 %6 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %8 = add nsw i64 %indvars.iv, -1
  %9 = getelementptr inbounds [50001 x i64], ptr @sum, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = add i64 %10, 1
  %14 = add i64 %13, %12
  %15 = getelementptr inbounds [50001 x i64], ptr @sum, i64 0, i64 %indvars.iv
  store i64 %14, ptr %15, align 8, !tbaa !9
  %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
  %.not.not = icmp slt i64 %indvars.iv, %17
  br i1 %.not.not, label %.lr.ph, label %.preheader32, !llvm.loop !11

.preheader:                                       ; preds = %.preheader32, %.critedge2
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %.critedge2 ], [ 1, %.preheader32 ]
  %.038 = phi i32 [ %46, %.critedge2 ], [ 1, %.preheader32 ]
  %.02637 = phi i32 [ %.127.lcssa, %.critedge2 ], [ 1, %.preheader32 ]
  %18 = sext i32 %.02637 to i64
  %19 = sext i32 %.038 to i64
  %smax = call i32 @llvm.smax.i32(i32 %.02637, i32 %.038)
  %20 = trunc nuw nsw i64 %indvars.iv47 to i32
  br label %21

21:                                               ; preds = %.preheader, %23
  %indvars.iv41 = phi i64 [ %18, %.preheader ], [ %indvars.iv.next42, %23 ]
  %22 = icmp slt i64 %indvars.iv41, %19
  br i1 %22, label %23, label %..critedge_crit_edge

..critedge_crit_edge:                             ; preds = %21
  %.pre50 = trunc nuw nsw i64 %indvars.iv47 to i32
  br label %.critedge

23:                                               ; preds = %21
  %24 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %indvars.iv41
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call noundef i64 @_Z4calcii(i32 noundef %20, i32 noundef %25)
  %indvars.iv.next42 = add nsw i64 %indvars.iv41, 1
  %27 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %indvars.iv.next42
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call noundef i64 @_Z4calcii(i32 noundef %20, i32 noundef %28)
  %30 = icmp sgt i64 %26, %29
  br i1 %30, label %21, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %23
  %31 = trunc nsw i64 %indvars.iv41 to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %..critedge_crit_edge
  %.pre-phi51 = phi i32 [ %.pre50, %..critedge_crit_edge ], [ %20, %.critedge.loopexit ]
  %.127.lcssa = phi i32 [ %smax, %..critedge_crit_edge ], [ %31, %.critedge.loopexit ]
  %32 = sext i32 %.127.lcssa to i64
  %33 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = call noundef i64 @_Z4calcii(i32 noundef %.pre-phi51, i32 noundef %34)
  %36 = getelementptr inbounds [50001 x i64], ptr @f, i64 0, i64 %indvars.iv47
  store i64 %35, ptr %36, align 8, !tbaa !9
  %smin = call i32 @llvm.smin.i32(i32 %.127.lcssa, i32 %.038)
  br label %37

37:                                               ; preds = %39, %.critedge
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %39 ], [ %19, %.critedge ]
  %38 = icmp sgt i64 %indvars.iv44, %32
  br i1 %38, label %39, label %.critedge2

39:                                               ; preds = %37
  %indvars.iv.next45 = add nsw i64 %indvars.iv44, -1
  %40 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %indvars.iv.next45
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %indvars.iv44
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = call noundef zeroext i1 @_Z5checkiii(i32 noundef %.pre-phi51, i32 noundef %41, i32 noundef %43)
  br i1 %44, label %37, label %.critedge2.split.loop.exit56, !llvm.loop !14

.critedge2.split.loop.exit56:                     ; preds = %39
  %45 = trunc nsw i64 %indvars.iv44 to i32
  br label %.critedge2

.critedge2:                                       ; preds = %37, %.critedge2.split.loop.exit56
  %.1.lcssa = phi i32 [ %45, %.critedge2.split.loop.exit56 ], [ %smin, %37 ]
  %46 = add nsw i32 %.1.lcssa, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [50001 x i32], ptr @q, i64 0, i64 %47
  store i32 %.pre-phi51, ptr %48, align 4, !tbaa !5
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %.not31.not = icmp slt i64 %indvars.iv47, %50
  br i1 %.not31.not, label %.preheader, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.critedge2, %.preheader32.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader32.._crit_edge_crit_edge ], [ %50, %.critedge2 ]
  %51 = getelementptr inbounds [50001 x i64], ptr @f, i64 0, i64 %.pre-phi
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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