; LLVM IR from tangjz/acm-icpc :: codeforces/gym (103957A)

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

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

4:                                                ; preds = %58, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  %11 = load i64, ptr @n, align 8, !tbaa !9
  %12 = shl i64 %11, 1
  %13 = sitofp i64 %12 to double
  %14 = fadd double %13, 2.500000e-01
  %15 = call double @sqrt(double noundef %14) #5
  %16 = fsub double %15, 5.000000e-01
  %17 = call double @llvm.floor.f64(double %16)
  %18 = fptosi double %17 to i32
  store i32 %18, ptr @m, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %30, %9
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = add nsw i64 %23, 1
  %25 = mul nsw i64 %21, %24
  %26 = ashr i64 %25, 1
  %27 = load i64, ptr @n, align 8, !tbaa !9
  %28 = icmp sle i64 %26, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %19
  br label %30

30:                                               ; preds = %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
  br label %19, !llvm.loop !11

33:                                               ; preds = %19
  br label %34

34:                                               ; preds = %45, %33
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = add nsw i64 %38, 1
  %40 = mul nsw i64 %36, %39
  %41 = ashr i64 %40, 1
  %42 = load i64, ptr @n, align 8, !tbaa !9
  %43 = icmp sgt i64 %41, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr @m, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr @m, align 4, !tbaa !5
  br label %34, !llvm.loop !13

48:                                               ; preds = %34
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = load i32, ptr @m, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = add nsw i64 %53, 1
  %55 = mul nsw i64 %51, %54
  %56 = ashr i64 %55, 1
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %49, i64 noundef %56)
  br label %58

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

61:                                               ; preds = %8
  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: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #4

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

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

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 "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 nosync nounwind speculatable willreturn memory(none) }
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 = 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"

@t = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not7 = icmp slt i32 %2, 1
  br i1 %.not7, label %._crit_edge11, label %.lr.ph10

._crit_edge11:                                    ; preds = %28, %0
  ret i32 0

.lr.ph10:                                         ; preds = %0, %28
  %.08 = phi i32 [ %30, %28 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %4 = load i64, ptr @n, align 8, !tbaa !9
  %5 = shl i64 %4, 1
  %6 = sitofp i64 %5 to double
  %7 = fadd double %6, 2.500000e-01
  %8 = tail call double @sqrt(double noundef %7) #4
  %9 = fadd double %8, -5.000000e-01
  %10 = tail call double @llvm.floor.f64(double %9)
  %11 = fptosi double %10 to i32
  %12 = load i64, ptr @n, align 8, !tbaa !9
  %13 = sext i32 %11 to i64
  br label %14

14:                                               ; preds = %14, %.lr.ph10
  %indvars.iv = phi i64 [ %15, %14 ], [ %13, %.lr.ph10 ]
  %15 = add nsw i64 %indvars.iv, 1
  %16 = mul nsw i64 %15, %indvars.iv
  %17 = ashr i64 %16, 1
  %.not4 = icmp sgt i64 %17, %12
  br i1 %.not4, label %.preheader, label %14, !llvm.loop !11

.preheader:                                       ; preds = %14
  %18 = trunc nsw i64 %indvars.iv to i32
  store i32 %18, ptr @m, align 4, !tbaa !5
  %sext = shl i64 %indvars.iv, 32
  %19 = ashr exact i64 %sext, 32
  %20 = add nsw i64 %19, 1
  %21 = mul nsw i64 %20, %19
  %22 = ashr i64 %21, 1
  %23 = icmp sgt i64 %22, %12
  br i1 %23, label %.lr.ph, label %28

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv14 = phi i64 [ %indvars.iv.next15, %.lr.ph ], [ %indvars.iv, %.preheader ]
  %indvars.iv.next15 = add nsw i64 %indvars.iv14, -1
  %24 = mul nsw i64 %indvars.iv14, %indvars.iv.next15
  %25 = ashr i64 %24, 1
  %26 = icmp sgt i64 %25, %12
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph
  %27 = trunc nsw i64 %indvars.iv.next15 to i32
  store i32 %27, ptr @m, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge, %.preheader
  %.lcssa5 = phi i64 [ %25, %._crit_edge ], [ %22, %.preheader ]
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.08, i64 noundef %.lcssa5)
  %30 = add nuw nsw i32 %.08, 1
  %31 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.08, %31
  br i1 %.not.not, label %.lr.ph10, label %._crit_edge11, !llvm.loop !14
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #3

; 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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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