; LLVM IR from Tudor67/Competitive-Programming :: Codeforces/#615#div3/D (D_cstdio_N)

; 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"

@cnt_complete_seq = external dso_local global i32, align 4
@y_with_min_freq = external dso_local global i32, align 4
@distinct_values = external dso_local global i32, align 4
@modulo_freq = external dso_local global [400001 x i32], align 16
@dst_gt = external dso_local global [400001 x i32], align 16
@q = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef, ptr 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(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = getelementptr inbounds ptr, ptr %7, i64 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef %9, ptr noundef @.str)
  %11 = load ptr, ptr @stdin, align 8, !tbaa !9
  %12 = call ptr @freopen(ptr noundef %10, ptr noundef @.str.1, ptr noundef %11)
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds ptr, ptr %13, i64 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef %15, ptr noundef @.str.2)
  %17 = load ptr, ptr @stdout, align 8, !tbaa !9
  %18 = call ptr @freopen(ptr noundef %16, ptr noundef @.str.3, ptr noundef %17)
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @q, ptr noundef @x)
  br label %20

20:                                               ; preds = %95, %2
  %21 = load i32, ptr @q, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %98

23:                                               ; preds = %20
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef @y)
  %25 = load i32, ptr @x, align 4, !tbaa !5
  %26 = load i32, ptr @y, align 4, !tbaa !5
  %27 = srem i32 %26, %25
  store i32 %27, ptr @y, align 4, !tbaa !5
  %28 = load i32, ptr @y, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !5
  %33 = load i32, ptr @y, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !5
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %79

40:                                               ; preds = %23
  %41 = load i32, ptr @distinct_values, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @distinct_values, align 4, !tbaa !5
  %43 = load i32, ptr @distinct_values, align 4, !tbaa !5
  %44 = load i32, ptr @x, align 4, !tbaa !5
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %54

46:                                               ; preds = %40
  %47 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @cnt_complete_seq, align 4, !tbaa !5
  store i32 0, ptr @y_with_min_freq, align 4, !tbaa !5
  %49 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [400001 x i32], ptr @dst_gt, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr @distinct_values, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %46, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %55 = load i32, ptr @y_with_min_freq, align 4, !tbaa !5
  store i32 %55, ptr %6, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %69, %54
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = load i32, ptr @x, align 4, !tbaa !5
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %60, label %67

60:                                               ; preds = %56
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !5
  %66 = icmp ne i32 %64, %65
  br label %67

67:                                               ; preds = %60, %56
  %68 = phi i1 [ false, %56 ], [ %66, %60 ]
  br i1 %68, label %69, label %72

69:                                               ; preds = %67
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %56, !llvm.loop !11

72:                                               ; preds = %67
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr @x, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %78

76:                                               ; preds = %72
  %77 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %77, ptr @y_with_min_freq, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %88

79:                                               ; preds = %23
  %80 = load i32, ptr @y, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [400001 x i32], ptr @dst_gt, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %85, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %79, %78
  %89 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !5
  %90 = load i32, ptr @x, align 4, !tbaa !5
  %91 = mul nsw i32 %89, %90
  %92 = load i32, ptr @y_with_min_freq, align 4, !tbaa !5
  %93 = add nsw i32 %91, %92
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %93)
  br label %95

95:                                               ; preds = %88
  %96 = load i32, ptr @q, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr @q, align 4, !tbaa !5
  br label %20, !llvm.loop !13

98:                                               ; preds = %20
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

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 = { 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 = !{!"any pointer", !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"

@cnt_complete_seq = external dso_local local_unnamed_addr global i32, align 4
@y_with_min_freq = external dso_local local_unnamed_addr global i32, align 4
@distinct_values = external dso_local local_unnamed_addr global i32, align 4
@modulo_freq = external dso_local local_unnamed_addr global [400001 x i32], align 16
@dst_gt = external dso_local local_unnamed_addr global [400001 x i32], align 16
@q = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef %4, ptr noundef nonnull @.str)
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = tail call ptr @freopen(ptr noundef %5, ptr noundef nonnull @.str.1, ptr noundef %6)
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = tail call noundef ptr @_Z16get_new_c_stringPKcS0_(ptr noundef %8, ptr noundef nonnull @.str.2)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = tail call ptr @freopen(ptr noundef %9, ptr noundef nonnull @.str.3, ptr noundef %10)
  %12 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @q, ptr noundef nonnull @x)
  %.pr = load i32, ptr @q, align 4, !tbaa !9
  %13 = icmp sgt i32 %.pr, 0
  br i1 %13, label %.lr.ph8, label %._crit_edge

.lr.ph8:                                          ; preds = %2, %.critedge
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull @y)
  %15 = load i32, ptr @x, align 4, !tbaa !9
  %16 = load i32, ptr @y, align 4, !tbaa !9
  %17 = srem i32 %16, %15
  store i32 %17, ptr @y, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !9
  %22 = load i32, ptr @cnt_complete_seq, align 4, !tbaa !9
  %23 = icmp eq i32 %20, %22
  br i1 %23, label %24, label %44

24:                                               ; preds = %.lr.ph8
  %25 = load i32, ptr @distinct_values, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @distinct_values, align 4, !tbaa !9
  %27 = icmp eq i32 %26, %15
  br i1 %27, label %28, label %._crit_edge11

._crit_edge11:                                    ; preds = %24
  %.pre = load i32, ptr @y_with_min_freq, align 4, !tbaa !9
  br label %33

28:                                               ; preds = %24
  store i32 %21, ptr @cnt_complete_seq, align 4, !tbaa !9
  store i32 0, ptr @y_with_min_freq, align 4, !tbaa !9
  %29 = add nsw i32 %20, 2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [400001 x i32], ptr @dst_gt, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  store i32 %32, ptr @distinct_values, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %._crit_edge11, %28
  %34 = phi i32 [ %20, %._crit_edge11 ], [ %21, %28 ]
  %35 = phi i32 [ %.pre, %._crit_edge11 ], [ 0, %28 ]
  %36 = icmp slt i32 %35, %15
  br i1 %36, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %33
  %37 = sext i32 %35 to i64
  br label %38

38:                                               ; preds = %.lr.ph, %41
  %indvars.iv = phi i64 [ %37, %.lr.ph ], [ %indvars.iv.next, %41 ]
  %39 = getelementptr inbounds [400001 x i32], ptr @modulo_freq, i64 0, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %.not = icmp eq i32 %40, %34
  br i1 %.not, label %42, label %41

41:                                               ; preds = %38
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %15, %lftr.wideiv
  br i1 %exitcond.not, label %.critedge, label %38, !llvm.loop !11

42:                                               ; preds = %38
  %43 = trunc nsw i64 %indvars.iv to i32
  store i32 %43, ptr @y_with_min_freq, align 4, !tbaa !9
  br label %.critedge

44:                                               ; preds = %.lr.ph8
  %45 = sext i32 %21 to i64
  %46 = getelementptr inbounds [400001 x i32], ptr @dst_gt, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %46, align 4, !tbaa !9
  %.pre12 = load i32, ptr @y_with_min_freq, align 4, !tbaa !9
  br label %.critedge

.critedge:                                        ; preds = %41, %33, %42, %44
  %49 = phi i32 [ %35, %33 ], [ %43, %42 ], [ %.pre12, %44 ], [ %35, %41 ]
  %50 = phi i32 [ %34, %33 ], [ %34, %42 ], [ %22, %44 ], [ %34, %41 ]
  %51 = mul nsw i32 %50, %15
  %52 = add nsw i32 %51, %49
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %52)
  %54 = load i32, ptr @q, align 4, !tbaa !9
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr @q, align 4, !tbaa !9
  %56 = icmp sgt i32 %54, 1
  br i1 %56, label %.lr.ph8, label %._crit_edge, !llvm.loop !13

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; 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 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 = { 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 = !{!"any pointer", !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 = distinct !{!13, !12}


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