; LLVM IR from TLE-MEC/Hack-CP-DSA :: Hackerearth/Alice and candies (solution)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %24, %0
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sitofp i32 %11 to double
  %13 = fcmp ole double %12, 1.000000e+05
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %27

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp sgt i32 %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  %22 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4, !tbaa !5
  store i32 2, ptr %5, align 4
  br label %27

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !9

27:                                               ; preds = %21, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %28

28:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = and i32 %29, 1
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %56

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

33:                                               ; preds = %52, %32
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %55

38:                                               ; preds = %33
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = mul nsw i32 %40, %41
  %43 = sub nsw i32 %39, %42
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = mul nsw i32 2, %44
  %46 = srem i32 %43, %45
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %38
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %48, %38
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, 2
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %33, !llvm.loop !11

55:                                               ; preds = %37
  br label %80

56:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 2, ptr %8, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %76, %56
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %79

62:                                               ; preds = %57
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = mul nsw i32 %64, %65
  %67 = sub nsw i32 %63, %66
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = mul nsw i32 2, %68
  %70 = srem i32 %67, %69
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %75

72:                                               ; preds = %62
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %6, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %72, %62
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = add nsw i32 %77, 2
  store i32 %78, ptr %8, align 4, !tbaa !5
  br label %57, !llvm.loop !12

79:                                               ; preds = %61
  br label %80

80:                                               ; preds = %79, %55
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %81)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %83 = load i32, ptr %1, align 4
  ret i32 %83
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 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 = !{!"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}


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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %23, %0
  %.02328 = phi i32 [ 1, %0 ], [ %24, %23 ]
  %5 = mul nuw nsw i32 %.02328, %.02328
  %6 = icmp sgt i32 %5, %3
  br i1 %6, label %25, label %7

7:                                                ; preds = %4
  %8 = add nuw nsw i32 %.02328, 1
  %9 = mul nuw nsw i32 %8, %8
  %10 = icmp sgt i32 %9, %3
  br i1 %10, label %25, label %11

11:                                               ; preds = %7
  %12 = add nuw nsw i32 %.02328, 2
  %13 = mul nuw nsw i32 %12, %12
  %14 = icmp sgt i32 %13, %3
  br i1 %14, label %25, label %15

15:                                               ; preds = %11
  %16 = add nuw nsw i32 %.02328, 3
  %17 = mul nuw nsw i32 %16, %16
  %18 = icmp sgt i32 %17, %3
  br i1 %18, label %25, label %19

19:                                               ; preds = %15
  %20 = add nuw nsw i32 %.02328, 4
  %21 = mul nuw nsw i32 %20, %20
  %22 = icmp sgt i32 %21, %3
  br i1 %22, label %25, label %23

23:                                               ; preds = %19
  %24 = add nuw nsw i32 %.02328, 5
  %exitcond.not.4 = icmp eq i32 %24, 100001
  br i1 %exitcond.not.4, label %.thread, label %4, !llvm.loop !9

25:                                               ; preds = %19, %15, %11, %7, %4
  %.02328.lcssa = phi i32 [ %.02328, %4 ], [ %8, %7 ], [ %12, %11 ], [ %16, %15 ], [ %20, %19 ]
  %26 = and i32 %3, 1
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %.preheader, label %.preheader26

.thread:                                          ; preds = %23
  %27 = and i32 %3, 1
  %.not37 = icmp eq i32 %27, 0
  br i1 %.not37, label %.lr.ph33.preheader, label %.lr.ph.preheader

.preheader26:                                     ; preds = %25
  %28 = icmp ugt i32 %.02328.lcssa, 1
  br i1 %28, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.thread, %.preheader26
  %.023.lcssa3841 = phi i32 [ %.02328.lcssa, %.preheader26 ], [ 100001, %.thread ]
  br label %.lr.ph

.preheader:                                       ; preds = %25
  %29 = icmp ugt i32 %.02328.lcssa, 2
  br i1 %29, label %.lr.ph33.preheader, label %.loopexit

.lr.ph33.preheader:                               ; preds = %.thread, %.preheader
  %.023.lcssa3943 = phi i32 [ %.02328.lcssa, %.preheader ], [ 100001, %.thread ]
  br label %.lr.ph33

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.02130 = phi i32 [ %36, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.02229 = phi i32 [ %spec.select, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %30 = mul nuw nsw i32 %.02130, %.02130
  %31 = sub nsw i32 %3, %30
  %32 = shl nuw nsw i32 %.02130, 1
  %33 = srem i32 %31, %32
  %34 = icmp eq i32 %33, 0
  %35 = zext i1 %34 to i32
  %spec.select = add nuw nsw i32 %.02229, %35
  %36 = add nuw nsw i32 %.02130, 2
  %37 = icmp ult i32 %36, %.023.lcssa3841
  br i1 %37, label %.lr.ph, label %.loopexit, !llvm.loop !11

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %.032 = phi i32 [ %44, %.lr.ph33 ], [ 2, %.lr.ph33.preheader ]
  %.231 = phi i32 [ %spec.select25, %.lr.ph33 ], [ 0, %.lr.ph33.preheader ]
  %38 = mul nuw nsw i32 %.032, %.032
  %39 = sub nsw i32 %3, %38
  %40 = shl nuw nsw i32 %.032, 1
  %41 = srem i32 %39, %40
  %42 = icmp eq i32 %41, 0
  %43 = zext i1 %42 to i32
  %spec.select25 = add nuw nsw i32 %.231, %43
  %44 = add nuw nsw i32 %.032, 2
  %45 = icmp ult i32 %44, %.023.lcssa3943
  br i1 %45, label %.lr.ph33, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph33, %.preheader26, %.preheader
  %.4 = phi i32 [ 0, %.preheader ], [ 0, %.preheader26 ], [ %spec.select25, %.lr.ph33 ], [ %spec.select, %.lr.ph ]
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) 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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #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 = { mustprogress 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 = !{!"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}


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