; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1083)

; 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
@m = external dso_local global i32, align 4
@a = external dso_local global [100010 x i32], align 16
@bit = external dso_local global [100010 x i32], align 16
@delta = external dso_local global i32, align 4
@f = external dso_local global [100010 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 [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [2 x i8], align 1
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %97, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %9, label %98

9:                                                ; preds = %6
  store i32 0, ptr @delta, align 4, !tbaa !5
  store i64 0, ptr @f, align 16, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @bit, i8 0, i64 400040, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %35, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr @a, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  call void @_Z3addi(i32 noundef %23)
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = call noundef i32 @_Z3sumi(i32 noundef %29)
  %31 = sub nsw i32 %24, %30
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr @f, align 16, !tbaa !9
  %34 = add nsw i64 %33, %32
  store i64 %34, ptr @f, align 16, !tbaa !9
  br label %35

35:                                               ; preds = %15
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

38:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %68, %38
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %71

44:                                               ; preds = %39
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sub nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  %57 = call noundef i32 @_Z3sumi(i32 noundef %56)
  %58 = mul nsw i32 %57, 2
  %59 = sext i32 %58 to i64
  %60 = add nsw i64 %49, %59
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = sub nsw i64 %60, %62
  %64 = add nsw i64 %63, 1
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %66
  store i64 %64, ptr %67, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %44
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !5
  br label %39, !llvm.loop !13

71:                                               ; preds = %43
  br label %72

72:                                               ; preds = %96, %71
  %73 = load i32, ptr @m, align 4, !tbaa !5
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr @m, align 4, !tbaa !5
  %75 = icmp ne i32 %73, 0
  br i1 %75, label %76, label %97

76:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %77 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %77)
  %79 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  %80 = load i8, ptr %79, align 1, !tbaa !14
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 81
  br i1 %82, label %83, label %89

83:                                               ; preds = %76
  %84 = load i32, ptr @delta, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %87)
  br label %96

89:                                               ; preds = %76
  %90 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %91 = load i32, ptr @delta, align 4, !tbaa !5
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = add nsw i32 %91, %92
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = srem i32 %93, %94
  store i32 %95, ptr @delta, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %89, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #5
  br label %72, !llvm.loop !15

97:                                               ; preds = %72
  br label %6, !llvm.loop !16

98:                                               ; preds = %6
  ret i32 0
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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
@m = external dso_local global i32, align 4
@a = external dso_local global [100010 x i32], align 16
@bit = external dso_local local_unnamed_addr global [100010 x i32], align 16
@delta = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [100010 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 [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca [2 x i8], align 1
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %.lr.ph19, label %._crit_edge

.loopexit:                                        ; preds = %59, %.preheader
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %.lr.ph19, label %._crit_edge, !llvm.loop !5

.lr.ph19:                                         ; preds = %0, %.loopexit
  store i32 0, ptr @delta, align 4, !tbaa !7
  store i64 0, ptr @f, align 16, !tbaa !11
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400040) @bit, i8 0, i64 400040, i1 false)
  %7 = load i32, ptr @n, align 4, !tbaa !7
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.preheader

.preheader13:                                     ; preds = %.lr.ph
  %9 = icmp sgt i32 %21, 1
  br i1 %9, label %.lr.ph16, label %.preheader

.lr.ph:                                           ; preds = %.lr.ph19, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph19 ]
  %10 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %12 = load i32, ptr %10, align 4, !tbaa !7
  call void @_Z3addi(i32 noundef %12)
  %13 = load i32, ptr %10, align 4, !tbaa !7
  %14 = add nsw i32 %13, -1
  %15 = call noundef i32 @_Z3sumi(i32 noundef %14)
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = sub nsw i32 %16, %15
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr @f, align 16, !tbaa !11
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr @f, align 16, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @n, align 4, !tbaa !7
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %.preheader13, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph16, %.lr.ph19, %.preheader13
  %24 = load i32, ptr @m, align 4, !tbaa !7
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr @m, align 4, !tbaa !7
  %.not17 = icmp eq i32 %24, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph18

.lr.ph16:                                         ; preds = %.preheader13, %.lr.ph16
  %26 = phi i64 [ %40, %.lr.ph16 ], [ %20, %.preheader13 ]
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %.lr.ph16 ], [ 1, %.preheader13 ]
  %27 = phi i32 [ %36, %.lr.ph16 ], [ %21, %.preheader13 ]
  %28 = sext i32 %27 to i64
  %29 = sub nsw i64 %28, %indvars.iv21
  %30 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !7
  %32 = add nsw i32 %31, -1
  %33 = call noundef i32 @_Z3sumi(i32 noundef %32)
  %34 = shl nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = load i32, ptr @n, align 4, !tbaa !7
  %37 = sext i32 %36 to i64
  %38 = add i64 %26, 1
  %39 = add i64 %38, %35
  %40 = sub i64 %39, %37
  %41 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %indvars.iv21
  store i64 %40, ptr %41, align 8, !tbaa !11
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %42 = icmp slt i64 %indvars.iv.next22, %37
  br i1 %42, label %.lr.ph16, label %.preheader, !llvm.loop !14

.lr.ph18:                                         ; preds = %.preheader, %59
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  %44 = load i8, ptr %1, align 1, !tbaa !15
  %45 = icmp eq i8 %44, 81
  br i1 %45, label %46, label %52

46:                                               ; preds = %.lr.ph18
  %47 = load i32, ptr @delta, align 4, !tbaa !7
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %50)
  br label %59

52:                                               ; preds = %.lr.ph18
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %54 = load i32, ptr @delta, align 4, !tbaa !7
  %55 = load i32, ptr %2, align 4, !tbaa !7
  %56 = add nsw i32 %55, %54
  %57 = load i32, ptr @n, align 4, !tbaa !7
  %58 = srem i32 %56, %57
  store i32 %58, ptr @delta, align 4, !tbaa !7
  br label %59

59:                                               ; preds = %52, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %1) #5
  %60 = load i32, ptr @m, align 4, !tbaa !7
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr @m, align 4, !tbaa !7
  %.not = icmp eq i32 %60, 0
  br i1 %.not, label %.loopexit, label %.lr.ph18, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %0
  ret i32 0
}

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

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !9, i64 0}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}
!15 = !{!9, !9, i64 0}
!16 = distinct !{!16, !6}


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