; LLVM IR from tangjz/acm-icpc :: codeforces/complete (797A)

; 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
@tot = external dso_local global i32, align 4
@pr = external dso_local global [100001 x i32], align 16
@d = external dso_local global [100001 x i32], align 16
@ans = external dso_local global [21 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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 @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %63, %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
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %66

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %28, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @tot, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %26
  store i32 %20, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %19, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %29

29:                                               ; preds = %58, %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %30, %34
  store i32 %35, ptr %5, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %29
  store i32 5, ptr %3, align 4
  br label %61

39:                                               ; preds = %29
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp eq i32 %50, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %39
  store i32 5, ptr %3, align 4
  br label %61

57:                                               ; preds = %39
  br label %58

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

61:                                               ; preds = %56, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

66:                                               ; preds = %12
  %67 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %67, ptr @tot, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %77, %66
  %69 = load i32, ptr @tot, align 4, !tbaa !5
  %70 = icmp sgt i32 %69, 1
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr @n, align 4, !tbaa !5
  %73 = icmp sgt i32 %72, 1
  br label %74

74:                                               ; preds = %71, %68
  %75 = phi i1 [ false, %68 ], [ %73, %71 ]
  br i1 %75, label %76, label %92

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = load i32, ptr @tot, align 4, !tbaa !5
  %83 = add nsw i32 %82, -1
  store i32 %83, ptr @tot, align 4, !tbaa !5
  %84 = sext i32 %82 to i64
  %85 = getelementptr inbounds [21 x i32], ptr @ans, i64 0, i64 %84
  store i32 %81, ptr %85, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = sdiv i32 %90, %89
  store i32 %91, ptr @n, align 4, !tbaa !5
  br label %68, !llvm.loop !12

92:                                               ; preds = %74
  %93 = load i32, ptr @tot, align 4, !tbaa !5
  %94 = icmp eq i32 %93, 1
  br i1 %94, label %95, label %122

95:                                               ; preds = %92
  %96 = load i32, ptr @n, align 4, !tbaa !5
  %97 = icmp sgt i32 %96, 1
  br i1 %97, label %98, label %122

98:                                               ; preds = %95
  %99 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %99, ptr getelementptr inbounds ([21 x i32], ptr @ans, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %118, %98
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = load i32, ptr @m, align 4, !tbaa !5
  %103 = icmp sle i32 %101, %102
  br i1 %103, label %105, label %104

104:                                              ; preds = %100
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %121

105:                                              ; preds = %100
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [21 x i32], ptr @ans, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = load i32, ptr %6, align 4, !tbaa !5
  %111 = load i32, ptr @m, align 4, !tbaa !5
  %112 = icmp eq i32 %110, %111
  %113 = zext i1 %112 to i64
  %114 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %113
  %115 = load i8, ptr %114, align 1, !tbaa !13
  %116 = sext i8 %115 to i32
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %109, i32 noundef %116)
  br label %118

118:                                              ; preds = %105
  %119 = load i32, ptr %6, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %6, align 4, !tbaa !5
  br label %100, !llvm.loop !14

121:                                              ; preds = %104
  br label %124

122:                                              ; preds = %95, %92
  %123 = call i32 @puts(ptr noundef @.str.3)
  br label %124

124:                                              ; preds = %122, %121
  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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

declare i32 @puts(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 = { 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}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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
@m = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@pr = external dso_local local_unnamed_addr global [100001 x i32], align 16
@d = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global [21 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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)
  %2 = load i32, ptr @n, align 4
  %.not31 = icmp slt i32 %2, 2
  br i1 %.not31, label %.thread, label %.lr.ph34.preheader

.thread:                                          ; preds = %0
  %3 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %3, ptr @tot, align 4, !tbaa !5
  br label %54

.lr.ph34.preheader:                               ; preds = %0
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %4 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %4 to i64
  br label %.lr.ph34

._crit_edge35:                                    ; preds = %._crit_edge
  %5 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %5, ptr @tot, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph38.preheader, label %39

.lr.ph38.preheader:                               ; preds = %._crit_edge35
  %7 = zext nneg i32 %5 to i64
  br label %.lr.ph38

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %._crit_edge
  %indvars.iv52 = phi i64 [ 2, %.lr.ph34.preheader ], [ %indvars.iv.next53, %._crit_edge ]
  %8 = phi i32 [ %tot.promoted, %.lr.ph34.preheader ], [ %16, %._crit_edge ]
  %9 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %indvars.iv52
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not24 = icmp eq i32 %10, 0
  %11 = trunc nuw nsw i64 %indvars.iv52 to i32
  br i1 %.not24, label %12, label %.lr.ph34._crit_edge

12:                                               ; preds = %.lr.ph34
  store i32 %11, ptr %9, align 4, !tbaa !5
  %13 = add nsw i32 %8, 1
  %14 = sext i32 %8 to i64
  %15 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  br label %.lr.ph34._crit_edge

.lr.ph34._crit_edge:                              ; preds = %.lr.ph34, %12
  %16 = phi i32 [ %13, %12 ], [ %8, %.lr.ph34 ]
  %17 = load i32, ptr @pr, align 16, !tbaa !5
  %18 = mul nsw i32 %17, %11
  %.not2528 = icmp sgt i32 %18, %2
  br i1 %.not2528, label %._crit_edge, label %.lr.ph

19:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [100001 x i32], ptr @pr, i64 0, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %11
  %.not25 = icmp sgt i32 %22, %2
  br i1 %.not25, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph34._crit_edge, %19
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %.lr.ph34._crit_edge ]
  %23 = phi i32 [ %22, %19 ], [ %18, %.lr.ph34._crit_edge ]
  %24 = phi i32 [ %21, %19 ], [ %17, %.lr.ph34._crit_edge ]
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %25
  store i32 %24, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = icmp eq i32 %27, %24
  br i1 %28, label %._crit_edge, label %19

._crit_edge:                                      ; preds = %19, %.lr.ph, %.lr.ph34._crit_edge
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !11

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.lr.ph38
  %indvars.iv55 = phi i64 [ %7, %.lr.ph38.preheader ], [ %indvars.iv.next56, %.lr.ph38 ]
  %29 = phi i32 [ %2, %.lr.ph38.preheader ], [ %34, %.lr.ph38 ]
  %30 = zext nneg i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, -1
  %33 = getelementptr inbounds [21 x i32], ptr @ans, i64 0, i64 %indvars.iv55
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = sdiv i32 %29, %32
  %35 = icmp ugt i64 %indvars.iv55, 2
  %36 = icmp sgt i32 %34, 1
  %37 = and i1 %35, %36
  br i1 %37, label %.lr.ph38, label %._crit_edge39, !llvm.loop !12

._crit_edge39:                                    ; preds = %.lr.ph38
  %38 = trunc nuw nsw i64 %indvars.iv.next56 to i32
  store i32 %38, ptr @tot, align 4, !tbaa !5
  store i32 %34, ptr @n, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %._crit_edge39, %._crit_edge35
  %.lcssa27 = phi i32 [ %38, %._crit_edge39 ], [ %5, %._crit_edge35 ]
  %.lcssa26 = phi i32 [ %34, %._crit_edge39 ], [ %2, %._crit_edge35 ]
  %.lcssa = phi i1 [ %36, %._crit_edge39 ], [ true, %._crit_edge35 ]
  %40 = icmp eq i32 %.lcssa27, 1
  %or.cond = and i1 %40, %.lcssa
  br i1 %or.cond, label %41, label %54

41:                                               ; preds = %39
  store i32 %.lcssa26, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !5
  %.not2344 = icmp slt i32 %5, 1
  br i1 %.not2344, label %.loopexit, label %.lr.ph47

.lr.ph47:                                         ; preds = %41, %.lr.ph47
  %indvars.iv58 = phi i64 [ %indvars.iv.next59, %.lr.ph47 ], [ 1, %41 ]
  %42 = phi i32 [ %52, %.lr.ph47 ], [ %5, %41 ]
  %43 = getelementptr inbounds [21 x i32], ptr @ans, i64 0, i64 %indvars.iv58
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = zext i32 %42 to i64
  %46 = icmp eq i64 %indvars.iv58, %45
  %47 = zext i1 %46 to i64
  %48 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = sext i8 %49 to i32
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %44, i32 noundef %50)
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %52 = load i32, ptr @m, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %.not23.not = icmp slt i64 %indvars.iv58, %53
  br i1 %.not23.not, label %.lr.ph47, label %.loopexit, !llvm.loop !14

54:                                               ; preds = %.thread, %39
  %55 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph47, %41, %54
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }

!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}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}


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