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

; 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
@k = external dso_local global i32, align 4
@que = external dso_local global [100001 x i32], align 16
@L = external dso_local global i32, align 4
@R = external dso_local global i32, align 4
@s = external dso_local global [100001 x i64], align 16
@f = external dso_local global [100001 x i64], align 16
@g = external dso_local global [100001 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 nounwind uwtable
declare dso_local noundef i64 @_Z3maxxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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, ptr noundef @k)
  %4 = load i32, ptr @R, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @R, align 4, !tbaa !5
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %6
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

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

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

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i64, ptr @s, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %16)
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = add nsw i64 %26, %22
  store i64 %27, ptr %25, align 8, !tbaa !9
  %28 = load i32, ptr @L, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr @k, align 4, !tbaa !5
  %34 = sub nsw i32 %32, %33
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %13
  %37 = load i32, ptr @L, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @L, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %36, %13
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = load i32, ptr @L, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = add nsw i64 %43, %50
  %52 = load i32, ptr @L, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = sub nsw i64 %51, %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %61
  store i64 %59, ptr %62, align 8, !tbaa !9
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = call noundef i64 @_Z3maxxx(i64 noundef %67, i64 noundef %72)
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %75
  store i64 %73, ptr %76, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %111, %39
  %78 = load i32, ptr @L, align 4, !tbaa !5
  %79 = load i32, ptr @R, align 4, !tbaa !5
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %81, label %109

81:                                               ; preds = %77
  %82 = load i32, ptr @R, align 4, !tbaa !5
  %83 = sub nsw i32 %82, 1
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !9
  %90 = load i32, ptr @R, align 4, !tbaa !5
  %91 = sub nsw i32 %90, 1
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %95
  %97 = load i64, ptr %96, align 8, !tbaa !9
  %98 = sub nsw i64 %89, %97
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %100
  %102 = load i64, ptr %101, align 8, !tbaa !9
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %104
  %106 = load i64, ptr %105, align 8, !tbaa !9
  %107 = sub nsw i64 %102, %106
  %108 = icmp sle i64 %98, %107
  br label %109

109:                                              ; preds = %81, %77
  %110 = phi i1 [ false, %77 ], [ %108, %81 ]
  br i1 %110, label %111, label %114

111:                                              ; preds = %109
  %112 = load i32, ptr @R, align 4, !tbaa !5
  %113 = add nsw i32 %112, -1
  store i32 %113, ptr @R, align 4, !tbaa !5
  br label %77, !llvm.loop !11

114:                                              ; preds = %109
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = load i32, ptr @R, align 4, !tbaa !5
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr @R, align 4, !tbaa !5
  %118 = sext i32 %116 to i64
  %119 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %118
  store i32 %115, ptr %119, align 4, !tbaa !5
  br label %120

120:                                              ; preds = %114
  %121 = load i32, ptr %2, align 4, !tbaa !5
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !13

123:                                              ; preds = %12
  %124 = load i32, ptr @n, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %125
  %127 = load i64, ptr %126, align 8, !tbaa !9
  %128 = load i32, ptr @n, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %129
  %131 = load i64, ptr %130, align 8, !tbaa !9
  %132 = call noundef i64 @_Z3maxxx(i64 noundef %127, i64 noundef %131)
  %133 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %132)
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress 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 = { 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 = { "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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}


; 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
@k = external dso_local global i32, align 4
@que = external dso_local local_unnamed_addr global [100001 x i32], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@R = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [100001 x i64], align 16
@f = external dso_local local_unnamed_addr global [100001 x i64], align 16
@g = external dso_local local_unnamed_addr global [100001 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 nounwind uwtable
declare dso_local noundef i64 @_Z3maxxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %2 = load i32, ptr @R, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @R, align 4, !tbaa !5
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %4
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not20 = icmp slt i32 %6, 1
  br i1 %.not20, label %.._crit_edge_crit_edge, label %.lr.ph22

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre30 = sext i32 %6 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.critedge, %.._crit_edge_crit_edge
  %.pre-phi31 = phi i64 [ %.pre30, %.._crit_edge_crit_edge ], [ %67, %.critedge ]
  %7 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %.pre-phi31
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %.pre-phi31
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = tail call noundef i64 @_Z3maxxx(i64 noundef %8, i64 noundef %10)
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %11)
  ret i32 0

.lr.ph22:                                         ; preds = %0, %.critedge
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %.critedge ], [ 1, %0 ]
  %indvars28 = trunc i64 %indvars.iv26 to i32
  %13 = getelementptr inbounds i64, ptr @s, i64 %indvars.iv26
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %13)
  %15 = add nsw i64 %indvars.iv26, -1
  %16 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load i64, ptr %13, align 8, !tbaa !9
  %19 = add nsw i64 %18, %17
  store i64 %19, ptr %13, align 8, !tbaa !9
  %20 = load i32, ptr @L, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr @k, align 4, !tbaa !5
  %25 = sub nsw i32 %indvars28, %24
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %.lr.ph22
  %28 = add nsw i32 %20, 1
  store i32 %28, ptr @L, align 4, !tbaa !5
  %.pre = sext i32 %28 to i64
  %.phi.trans.insert = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %.pre
  %.pre29 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %27, %.lr.ph22
  %30 = phi i32 [ %.pre29, %27 ], [ %23, %.lr.ph22 ]
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = add nsw i64 %33, %19
  %35 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %31
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = sub i64 %34, %36
  %38 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv26
  store i64 %37, ptr %38, align 8, !tbaa !9
  %39 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %15
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %15
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = tail call noundef i64 @_Z3maxxx(i64 noundef %40, i64 noundef %42)
  %44 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %indvars.iv26
  store i64 %43, ptr %44, align 8, !tbaa !9
  %45 = load i32, ptr @L, align 4, !tbaa !5
  %R.promoted = load i32, ptr @R, align 4, !tbaa !5
  %46 = icmp slt i32 %45, %R.promoted
  br i1 %46, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %29
  %47 = load i64, ptr %13, align 8, !tbaa !9
  %48 = sub nsw i64 %43, %47
  %49 = sext i32 %R.promoted to i64
  %50 = sext i32 %45 to i64
  br label %51

51:                                               ; preds = %.lr.ph, %60
  %indvars.iv = phi i64 [ %49, %.lr.ph ], [ %indvars.iv.next, %60 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %52 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %indvars.iv.next
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i64], ptr @g, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds [100001 x i64], ptr @s, i64 0, i64 %54
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = sub nsw i64 %56, %58
  %.not16 = icmp sgt i64 %59, %48
  br i1 %.not16, label %.critedge.loopexit.split.loop.exit33, label %60

60:                                               ; preds = %51
  %61 = icmp sgt i64 %indvars.iv.next, %50
  br i1 %61, label %51, label %.critedge, !llvm.loop !11

.critedge.loopexit.split.loop.exit33:             ; preds = %51
  %62 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %60, %.critedge.loopexit.split.loop.exit33, %29
  %.lcssa = phi i32 [ %R.promoted, %29 ], [ %62, %.critedge.loopexit.split.loop.exit33 ], [ %45, %60 ]
  %63 = add nsw i32 %.lcssa, 1
  store i32 %63, ptr @R, align 4, !tbaa !5
  %64 = sext i32 %.lcssa to i64
  %65 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %64
  store i32 %indvars28, ptr %65, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %66 = load i32, ptr @n, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %.not.not = icmp slt i64 %indvars.iv26, %67
  br i1 %.not.not, label %.lr.ph22, label %._crit_edge, !llvm.loop !13
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #2 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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