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

; 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
@f = external dso_local global [51 x [51 x i64]], align 16
@sum = external dso_local global i64, align 8
@c = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  store i64 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %92, %0
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = load i32, ptr @n, align 4, !tbaa !9
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

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

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

12:                                               ; preds = %88, %11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  br label %18

18:                                               ; preds = %29, %17
  %19 = call i32 @getchar()
  %20 = trunc i32 %19 to i8
  store i8 %20, ptr @c, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, 42
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  %24 = load i8, ptr @c, align 1, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %25, 46
  br label %27

27:                                               ; preds = %23, %18
  %28 = phi i1 [ false, %18 ], [ %26, %23 ]
  br i1 %28, label %29, label %30

29:                                               ; preds = %27
  br label %18, !llvm.loop !12

30:                                               ; preds = %27
  %31 = load i8, ptr @c, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 42
  br i1 %33, label %34, label %68

34:                                               ; preds = %30
  %35 = load i32, ptr %2, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [51 x i64], ptr %37, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %44
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [51 x i64], ptr %45, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = add nsw i64 %49, %41
  store i64 %50, ptr %48, align 8, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %52
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [51 x i64], ptr %53, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %60
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [51 x i64], ptr %61, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !5
  %67 = add nsw i64 %66, %57
  store i64 %67, ptr %65, align 8, !tbaa !5
  br label %87

68:                                               ; preds = %30
  %69 = load i32, ptr %2, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %70
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [51 x i64], ptr %71, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !5
  %76 = shl i64 %75, 2
  %77 = load i32, ptr %2, align 4, !tbaa !9
  %78 = add nsw i32 %77, 2
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %79
  %81 = load i32, ptr %4, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [51 x i64], ptr %80, i64 0, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !5
  %86 = add nsw i64 %85, %76
  store i64 %86, ptr %84, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %68, %34
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %4, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !14

91:                                               ; preds = %16
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %2, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %2, align 4, !tbaa !9
  br label %6, !llvm.loop !15

95:                                               ; preds = %10
  %96 = load i32, ptr @n, align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = shl i64 1, %97
  store i64 %98, ptr @sum, align 8, !tbaa !5
  br label %99

99:                                               ; preds = %110, %95
  %100 = load i32, ptr @n, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %101
  %103 = load i32, ptr @m, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [51 x i64], ptr %102, i64 0, i64 %104
  %106 = load i64, ptr %105, align 8, !tbaa !5
  %107 = and i64 %106, 1
  %108 = icmp ne i64 %107, 0
  %109 = xor i1 %108, true
  br i1 %109, label %110, label %121

110:                                              ; preds = %99
  %111 = load i32, ptr @n, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %112
  %114 = load i32, ptr @m, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [51 x i64], ptr %113, i64 0, i64 %115
  %117 = load i64, ptr %116, align 8, !tbaa !5
  %118 = ashr i64 %117, 1
  store i64 %118, ptr %116, align 8, !tbaa !5
  %119 = load i64, ptr @sum, align 8, !tbaa !5
  %120 = ashr i64 %119, 1
  store i64 %120, ptr @sum, align 8, !tbaa !5
  br label %99, !llvm.loop !16

121:                                              ; preds = %99
  %122 = load i32, ptr @n, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %123
  %125 = load i32, ptr @m, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [51 x i64], ptr %124, i64 0, i64 %126
  %128 = load i64, ptr %127, align 8, !tbaa !5
  %129 = load i64, ptr @sum, align 8, !tbaa !5
  %130 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %128, i64 noundef %129)
  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: inlinehint mustprogress uwtable
declare i32 @getchar() #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 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


; 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
@f = external dso_local local_unnamed_addr global [51 x [51 x i64]], align 16
@sum = external dso_local local_unnamed_addr global i64, align 8
@c = external dso_local local_unnamed_addr global i8, align 1
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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 @m)
  store i64 1, ptr @f, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader21, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

.preheader21:                                     ; preds = %0, %11
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %11 ], [ 0, %0 ]
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %11 ], [ 1, %0 ]
  %4 = add nuw nsw i64 %indvars.iv44, 2
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  br label %.preheader

._crit_edge:                                      ; preds = %11, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %13, %11 ]
  %.lcssa23 = phi i32 [ %2, %.._crit_edge_crit_edge ], [ %12, %11 ]
  %5 = zext nneg i32 %.lcssa23 to i64
  %6 = shl nuw i64 1, %5
  %7 = load i32, ptr @m, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %.pre-phi, i64 %8
  %.promoted = load i64, ptr %9, align 8, !tbaa !5
  %10 = and i64 %.promoted, 1
  %.not27 = icmp eq i64 %10, 0
  br i1 %.not27, label %.lr.ph, label %38

.preheader:                                       ; preds = %.preheader21, %29
  %indvars.iv = phi i64 [ 0, %.preheader21 ], [ %30, %29 ]
  br label %15

11:                                               ; preds = %29
  %12 = load i32, ptr @n, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next45, %13
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  br i1 %14, label %.preheader21, label %._crit_edge, !llvm.loop !11

15:                                               ; preds = %.preheader, %15
  %16 = tail call i32 @getchar()
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr @c, align 1, !tbaa !13
  %18 = and i32 %16, 251
  %.not20 = icmp eq i32 %18, 42
  br i1 %.not20, label %19, label %15, !llvm.loop !14

19:                                               ; preds = %15
  %sext.mask = and i32 %16, 46
  %20 = icmp eq i32 %sext.mask, 42
  %21 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %indvars.iv44, i64 %indvars.iv
  %22 = load i64, ptr %21, align 8, !tbaa !5
  br i1 %20, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %indvars.iv.next45, i64 %indvars.iv
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = add nsw i64 %25, %22
  store i64 %26, ptr %24, align 8, !tbaa !5
  br label %29

27:                                               ; preds = %19
  %28 = shl i64 %22, 2
  br label %29

29:                                               ; preds = %23, %27
  %indvars.iv.next45.sink = phi i64 [ %indvars.iv.next45, %23 ], [ %4, %27 ]
  %.sink56 = phi i64 [ %22, %23 ], [ %28, %27 ]
  %30 = add nuw nsw i64 %indvars.iv, 1
  %31 = getelementptr inbounds [51 x [51 x i64]], ptr @f, i64 0, i64 %indvars.iv.next45.sink, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %.sink56
  store i64 %33, ptr %31, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %30, %indvars.iv42
  br i1 %exitcond.not, label %11, label %.preheader, !llvm.loop !15

.lr.ph:                                           ; preds = %._crit_edge, %.lr.ph
  %storemerge28 = phi i64 [ %36, %.lr.ph ], [ %6, %._crit_edge ]
  %34 = phi i64 [ %35, %.lr.ph ], [ %.promoted, %._crit_edge ]
  %35 = ashr exact i64 %34, 1
  %36 = ashr i64 %storemerge28, 1
  %37 = and i64 %34, 2
  %.not = icmp eq i64 %37, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge30, !llvm.loop !16

._crit_edge30:                                    ; preds = %.lr.ph
  store i64 %35, ptr %9, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %._crit_edge30, %._crit_edge
  %storemerge.lcssa26 = phi i64 [ %36, %._crit_edge30 ], [ %6, %._crit_edge ]
  %.lcssa = phi i64 [ %35, %._crit_edge30 ], [ %.promoted, %._crit_edge ]
  store i64 %storemerge.lcssa26, ptr @sum, align 8, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.lcssa, i64 noundef %storemerge.lcssa26)
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #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 = { inlinehint mustprogress nofree 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" }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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