; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (142A-HelpFarmer)

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

@.str = external hidden unnamed_addr constant [6 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 i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = add nsw i64 %10, 1
  %12 = mul nsw i64 9, %11
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = sub nsw i64 %12, %13
  store i64 %14, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %15 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %15, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 1, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %74, %0
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = mul nsw i64 %17, %18
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = mul nsw i64 %19, %20
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = icmp sle i64 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %16
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = srem i64 %26, %27
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  br label %74

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %70, %31
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %7, align 8, !tbaa !5
  %35 = mul nsw i64 %33, %34
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = mul nsw i64 %35, %36
  %38 = load i64, ptr %2, align 8, !tbaa !5
  %39 = icmp sle i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %32
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %73

41:                                               ; preds = %32
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = sdiv i64 %42, %43
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = srem i64 %44, %45
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  br label %70

49:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = add nsw i64 %50, 1
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = add nsw i64 %52, 2
  %54 = mul nsw i64 %51, %53
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = load i64, ptr %5, align 8, !tbaa !5
  %57 = sdiv i64 %55, %56
  %58 = load i64, ptr %7, align 8, !tbaa !5
  %59 = sdiv i64 %57, %58
  %60 = add nsw i64 %59, 2
  %61 = mul nsw i64 %54, %60
  %62 = load i64, ptr %2, align 8, !tbaa !5
  %63 = sub nsw i64 %61, %62
  store i64 %63, ptr %8, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %4, align 8, !tbaa !5
  %66 = icmp slt i64 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %49
  %68 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %68, ptr %4, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %67, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %70

70:                                               ; preds = %69, %48
  %71 = load i64, ptr %7, align 8, !tbaa !5
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %7, align 8, !tbaa !5
  br label %32, !llvm.loop !9

73:                                               ; preds = %40
  br label %74

74:                                               ; preds = %73, %30
  %75 = load i64, ptr %5, align 8, !tbaa !5
  %76 = add nsw i64 %75, 1
  store i64 %76, ptr %5, align 8, !tbaa !5
  br label %16, !llvm.loop !11

77:                                               ; preds = %24
  %78 = load i64, ptr %4, align 8, !tbaa !5
  %79 = load i64, ptr %3, align 8, !tbaa !5
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %78, i64 noundef %79)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %81 = load i32, ptr %1, align 4
  ret i32 %81
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

@.str = external hidden unnamed_addr constant [6 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 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %reass.sub = shl i64 %3, 3
  %4 = add i64 %reass.sub, 9
  %.not33 = icmp slt i64 %3, 1
  br i1 %.not33, label %._crit_edge, label %.lr.ph37

._crit_edge:                                      ; preds = %.loopexit, %0
  %.023.lcssa = phi i64 [ %4, %0 ], [ %.4, %.loopexit ]
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.023.lcssa, i64 noundef %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

.lr.ph37:                                         ; preds = %0, %.loopexit
  %.02235 = phi i64 [ %.pre-phi, %.loopexit ], [ 1, %0 ]
  %.02334 = phi i64 [ %.4, %.loopexit ], [ %4, %0 ]
  %6 = urem i64 %3, %.02235
  %7 = udiv i64 %3, %.02235
  %.not27 = icmp ne i64 %6, 0
  %.not2830 = icmp sgt i64 %.02235, %3
  %or.cond = or i1 %.not27, %.not2830
  br i1 %or.cond, label %.lr.ph37..loopexit_crit_edge, label %.lr.ph

.lr.ph37..loopexit_crit_edge:                     ; preds = %.lr.ph37
  %.pre = add nuw nsw i64 %.02235, 1
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph37
  %8 = add nuw nsw i64 %.02235, 1
  br label %9

9:                                                ; preds = %.lr.ph, %18
  %.032 = phi i64 [ 1, %.lr.ph ], [ %19, %18 ]
  %.131 = phi i64 [ %.02334, %.lr.ph ], [ %.3, %18 ]
  %10 = urem i64 %7, %.032
  %11 = udiv i64 %7, %.032
  %.not29 = icmp eq i64 %10, 0
  br i1 %.not29, label %12, label %18

12:                                               ; preds = %9
  %13 = add nuw nsw i64 %.032, 2
  %14 = mul nuw nsw i64 %13, %8
  %15 = add nuw nsw i64 %11, 2
  %16 = mul nuw nsw i64 %14, %15
  %17 = sub nsw i64 %16, %3
  %spec.select = call i64 @llvm.smin.i64(i64 %17, i64 %.131)
  br label %18

18:                                               ; preds = %9, %12
  %.3 = phi i64 [ %.131, %9 ], [ %spec.select, %12 ]
  %19 = add nuw nsw i64 %.032, 1
  %20 = mul nuw nsw i64 %19, %.02235
  %21 = mul nuw nsw i64 %20, %19
  %.not28 = icmp sgt i64 %21, %3
  br i1 %.not28, label %.loopexit, label %9, !llvm.loop !9

.loopexit:                                        ; preds = %18, %.lr.ph37..loopexit_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph37..loopexit_crit_edge ], [ %8, %18 ]
  %.4 = phi i64 [ %.02334, %.lr.ph37..loopexit_crit_edge ], [ %.3, %18 ]
  %22 = mul nuw nsw i64 %.pre-phi, %.pre-phi
  %23 = mul nuw nsw i64 %22, %.pre-phi
  %.not = icmp sgt i64 %23, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph37, !llvm.loop !11
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = !{!"long long", !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}


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