; LLVM IR from tangjz/acm-icpc :: lanqiao (T122)

; 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
@s = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@f = external dso_local global [1001 x [1001 x i32]], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [9 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
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @s, ptr noundef @a, ptr noundef @b)
  store i32 1, ptr @f, align 16, !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 = %80, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %15
  %17 = getelementptr inbounds [1001 x i32], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %20
  %22 = getelementptr inbounds [1001 x i32], ptr %21, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %22, i64 4004, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  store i32 %25, ptr %5, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %77, %13
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1001 x i32], ptr %35, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1001 x i32], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, %39
  store i32 %47, ptr %45, align 4, !tbaa !5
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1001 x i32], ptr %50, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp sge i32 %54, 100000007
  br i1 %55, label %56, label %65

56:                                               ; preds = %31
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1001 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 100000007
  store i32 %64, ptr %62, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %56, %31
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !5
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %66
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  br label %77

76:                                               ; preds = %66
  br label %77

77:                                               ; preds = %76, %73
  %78 = phi i32 [ %75, %73 ], [ 0, %76 ]
  store i32 %78, ptr %5, align 4, !tbaa !5
  br label %26, !llvm.loop !9

79:                                               ; preds = %30
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

83:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %133, %83
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %136

89:                                               ; preds = %84
  %90 = load i32, ptr @a, align 4, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = mul nsw i32 %90, %91
  %93 = sext i32 %92 to i64
  %94 = load i32, ptr @b, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = load i32, ptr @n, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = load i32, ptr @n, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = sub nsw i64 %99, 1
  %101 = mul nsw i64 %97, %100
  %102 = ashr i64 %101, 1
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = sub nsw i64 %102, %104
  %106 = mul nsw i64 %95, %105
  %107 = sub nsw i64 %93, %106
  %108 = load i32, ptr @s, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = sub nsw i64 %107, %109
  %111 = load i32, ptr @n, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = srem i64 %110, %112
  %114 = icmp eq i64 %113, 0
  br i1 %114, label %115, label %132

115:                                              ; preds = %89
  %116 = load i32, ptr @n, align 4, !tbaa !5
  %117 = sub nsw i32 %116, 1
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %118
  %120 = load i32, ptr %6, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [1001 x i32], ptr %119, i64 0, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !5
  %124 = load i32, ptr @ans, align 4, !tbaa !5
  %125 = add nsw i32 %124, %123
  store i32 %125, ptr @ans, align 4, !tbaa !5
  %126 = load i32, ptr @ans, align 4, !tbaa !5
  %127 = icmp sge i32 %126, 100000007
  br i1 %127, label %128, label %131

128:                                              ; preds = %115
  %129 = load i32, ptr @ans, align 4, !tbaa !5
  %130 = sub nsw i32 %129, 100000007
  store i32 %130, ptr @ans, align 4, !tbaa !5
  br label %131

131:                                              ; preds = %128, %115
  br label %132

132:                                              ; preds = %131, %89
  br label %133

133:                                              ; preds = %132
  %134 = load i32, ptr %6, align 4, !tbaa !5
  %135 = add nsw i32 %134, 1
  store i32 %135, ptr %6, align 4, !tbaa !5
  br label %84, !llvm.loop !12

136:                                              ; preds = %88
  %137 = load i32, ptr @ans, align 4, !tbaa !5
  %138 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %137)
  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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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

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: 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 = 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
@s = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [9 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, ptr noundef nonnull @s, ptr noundef nonnull @a, ptr noundef nonnull @b)
  store i32 1, ptr @f, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph.us.preheader, label %.preheader

.lr.ph.us.preheader:                              ; preds = %0
  %wide.trip.count40 = zext nneg i32 %2 to i64
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv37 = phi i64 [ 1, %.lr.ph.us.preheader ], [ %indvars.iv.next38, %._crit_edge.us ]
  %4 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %indvars.iv37
  %5 = add nsw i64 %indvars.iv37, -1
  %6 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(4004) %4, ptr noundef nonnull align 4 dereferenceable(4004) %6, i64 4004, i1 false)
  %7 = trunc i64 %indvars.iv37 to i32
  %8 = sub i32 %2, %7
  br label %9

9:                                                ; preds = %.lr.ph.us, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next, %9 ]
  %.02231.us = phi i32 [ %8, %.lr.ph.us ], [ %20, %9 ]
  %10 = sext i32 %.02231.us to i64
  %11 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %5, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %indvars.iv37, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, %12
  %16 = icmp sgt i32 %15, 100000006
  %17 = add nsw i32 %15, -100000007
  %spec.select.us = select i1 %16, i32 %17, i32 %15
  store i32 %spec.select.us, ptr %13, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = add nsw i32 %.02231.us, 1
  %19 = icmp slt i32 %18, %2
  %20 = select i1 %19, i32 %18, i32 0
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count40
  br i1 %exitcond.not, label %._crit_edge.us, label %9, !llvm.loop !9

._crit_edge.us:                                   ; preds = %9
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count40
  br i1 %exitcond41.not, label %.preheader, label %.lr.ph.us, !llvm.loop !11

.preheader:                                       ; preds = %._crit_edge.us, %0
  %21 = icmp sgt i32 %2, 0
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %22 = load i32, ptr @a, align 4, !tbaa !5
  %23 = load i32, ptr @b, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = zext nneg i32 %2 to i64
  %26 = add nsw i64 %25, -1
  %27 = mul nuw nsw i64 %26, %25
  %28 = lshr i64 %27, 1
  %29 = load i32, ptr @s, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = add nsw i32 %2, -1
  %32 = zext nneg i32 %31 to i64
  %33 = sext i32 %22 to i64
  br label %36

._crit_edge:                                      ; preds = %50, %.preheader
  %34 = phi i32 [ %ans.promoted, %.preheader ], [ %51, %50 ]
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34)
  ret i32 0

36:                                               ; preds = %.lr.ph, %50
  %indvars.iv42 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next43, %50 ]
  %37 = phi i32 [ %ans.promoted, %.lr.ph ], [ %51, %50 ]
  %38 = mul nsw i64 %indvars.iv42, %33
  %.neg = sub nsw i64 %indvars.iv42, %28
  %.neg28 = mul i64 %.neg, %24
  %39 = add i64 %.neg28, %38
  %40 = sub i64 %39, %30
  %41 = srem i64 %40, %25
  %42 = icmp eq i64 %41, 0
  br i1 %42, label %43, label %50

43:                                               ; preds = %36
  %44 = getelementptr inbounds [1001 x [1001 x i32]], ptr @f, i64 0, i64 %32, i64 %indvars.iv42
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %37, %45
  store i32 %46, ptr @ans, align 4, !tbaa !5
  %47 = icmp sgt i32 %46, 100000006
  br i1 %47, label %48, label %50

48:                                               ; preds = %43
  %49 = add nsw i32 %46, -100000007
  store i32 %49, ptr @ans, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %36, %48, %43
  %51 = phi i32 [ %37, %36 ], [ %49, %48 ], [ %46, %43 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %25
  br i1 %exitcond46.not, label %._crit_edge, label %36, !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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

!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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass