; LLVM IR from tangjz/acm-icpc :: codeforces/complete (1091C)

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

5:                                                ; preds = %35, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = mul nsw i32 %6, %7
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = srem i32 %13, %14
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  br label %35

18:                                               ; preds = %12
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = call noundef i64 @_Z4calcii(i32 noundef %19, i32 noundef %20)
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @m, align 4, !tbaa !5
  %24 = sext i32 %22 to i64
  %25 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %24
  store i64 %21, ptr %25, align 8, !tbaa !9
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sdiv i32 %27, %28
  %30 = call noundef i64 @_Z4calcii(i32 noundef %26, i32 noundef %29)
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @m, align 4, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %33
  store i64 %30, ptr %34, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %18, %17
  %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 %5, !llvm.loop !11

38:                                               ; preds = %11
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i64, ptr @f, i64 %40
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @f, ptr noundef %41)
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr @f, i64 %43
  %45 = call noundef ptr @_ZSt6uniqueIPxET_S1_S1_(ptr noundef @f, ptr noundef %44)
  %46 = ptrtoint ptr %45 to i64
  %47 = sub i64 %46, ptrtoint (ptr @f to i64)
  %48 = sdiv exact i64 %47, 8
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %69, %38
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr @m, align 4, !tbaa !5
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %55, label %54

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

55:                                               ; preds = %50
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = load i32, ptr @m, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  %63 = icmp eq i32 %60, %62
  %64 = zext i1 %63 to i64
  %65 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = sext i8 %66 to i32
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %59, i32 noundef %67)
  br label %69

69:                                               ; preds = %55
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %3, align 4, !tbaa !5
  br label %50, !llvm.loop !14

72:                                               ; preds = %54
  %73 = call i32 @puts(ptr noundef @.str.3)
  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 nounwind uwtable
declare dso_local noundef i64 @_Z4calcii(i32 noundef, i32 noundef) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPxET_S1_S1_(ptr noundef, ptr noundef) #4

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 = { inlinehint 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 #4 = { 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 #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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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 local_unnamed_addr global i32, align 4
@f = external dso_local global [100001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress norecurse 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not13 = icmp slt i32 %2, 1
  br i1 %.not13, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %31, %0
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i64, ptr @f, i64 %4
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @f, ptr noundef nonnull %5)
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds i64, ptr @f, i64 %7
  %9 = tail call noundef ptr @_ZSt6uniqueIPxET_S1_S1_(ptr noundef nonnull @f, ptr noundef nonnull %8)
  %10 = ptrtoint ptr %9 to i64
  %11 = sub i64 %10, ptrtoint (ptr @f to i64)
  %12 = lshr exact i64 %11, 3
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr @m, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph17, label %._crit_edge18

.lr.ph:                                           ; preds = %0, %31
  %15 = phi i32 [ %32, %31 ], [ %2, %0 ]
  %.01014 = phi i32 [ %33, %31 ], [ 1, %0 ]
  %16 = srem i32 %15, %.01014
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %31, label %18

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef i64 @_Z4calcii(i32 noundef %15, i32 noundef %.01014)
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %22
  store i64 %19, ptr %23, align 8, !tbaa !9
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = sdiv i32 %24, %.01014
  %26 = tail call noundef i64 @_Z4calcii(i32 noundef %24, i32 noundef %25)
  %27 = load i32, ptr @m, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @m, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %29
  store i64 %26, ptr %30, align 8, !tbaa !9
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %.lr.ph, %18
  %32 = phi i32 [ %15, %.lr.ph ], [ %.pre, %18 ]
  %33 = add nuw nsw i32 %.01014, 1
  %34 = mul nuw nsw i32 %33, %33
  %.not = icmp sgt i32 %34, %32
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge
  %35 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  ret i32 0

.lr.ph17:                                         ; preds = %._crit_edge, %.lr.ph17
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph17 ], [ 0, %._crit_edge ]
  %36 = phi i32 [ %47, %.lr.ph17 ], [ %13, %._crit_edge ]
  %37 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = add nsw i32 %36, -1
  %40 = zext i32 %39 to i64
  %41 = icmp eq i64 %indvars.iv, %40
  %42 = zext i1 %41 to i64
  %43 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = sext i8 %44 to i32
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %38, i32 noundef %45)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %47 = load i32, ptr @m, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = icmp slt i64 %indvars.iv.next, %48
  br i1 %49, label %.lr.ph17, label %._crit_edge18, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4calcii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPxET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; 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 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 = { 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 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 = { 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" }

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


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