; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1016A. Death Note (main)

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

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

5:                                                ; preds = %69, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %70

8:                                                ; preds = %5
  store i64 0, ptr @arr, align 16, !tbaa !5
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %17, %8
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %13, label %20

13:                                               ; preds = %9
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15)
  br label %17

17:                                               ; preds = %13
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !9

20:                                               ; preds = %9
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %66, %20
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = icmp sle i64 %22, %23
  br i1 %24, label %25, label %69

25:                                               ; preds = %21
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = sub nsw i64 %26, 1
  %28 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %29
  store i64 %33, ptr %31, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = icmp eq i64 %34, 1
  br i1 %35, label %36, label %43

36:                                               ; preds = %25
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = sdiv i64 %39, %40
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %41)
  br label %57

43:                                               ; preds = %25
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = sdiv i64 %46, %47
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = sub nsw i64 %49, 1
  %51 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = sdiv i64 %52, %53
  %55 = sub nsw i64 %48, %54
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %55)
  br label %57

57:                                               ; preds = %43, %36
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = icmp eq i64 %58, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %57
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %65

63:                                               ; preds = %57
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %65

65:                                               ; preds = %63, %61
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = add nsw i64 %67, 1
  store i64 %68, ptr %4, align 8, !tbaa !5
  br label %21, !llvm.loop !11

69:                                               ; preds = %21
  br label %5, !llvm.loop !12

70:                                               ; preds = %5
  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
  ret i32 0
}

; 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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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}
!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"

@arr = external dso_local global [200005 x i64], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not19 = icmp eq i32 %3, -1
  br i1 %.not19, label %._crit_edge, label %.lr.ph20

.loopexit:                                        ; preds = %.lr.ph18.peel.next, %.lr.ph20, %6, %.preheader
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not = icmp eq i32 %4, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph20, !llvm.loop !5

.lr.ph20:                                         ; preds = %0, %.loopexit
  store i64 0, ptr @arr, align 16, !tbaa !7
  %5 = load i64, ptr %1, align 8, !tbaa !7
  %.not1214 = icmp slt i64 %5, 1
  br i1 %.not1214, label %.loopexit, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1316 = icmp slt i64 %19, 1
  br i1 %.not1316, label %.loopexit, label %6

6:                                                ; preds = %.preheader
  %7 = load i64, ptr @arr, align 16, !tbaa !7
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @arr, i64 8), align 8, !tbaa !7
  %9 = add nsw i64 %8, %7
  store i64 %9, ptr getelementptr inbounds (i8, ptr @arr, i64 8), align 8, !tbaa !7
  %10 = load i64, ptr %2, align 8, !tbaa !7
  %11 = sdiv i64 %9, %10
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %11)
  %.pre = load i64, ptr %1, align 8, !tbaa !7
  %13 = icmp eq i64 %.pre, 1
  %.str.2..str.3 = select i1 %13, ptr @.str.2, ptr @.str.3
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.3)
  %15 = load i64, ptr %1, align 8, !tbaa !7
  %.not13.not.peel = icmp sgt i64 %15, 1
  br i1 %.not13.not.peel, label %.lr.ph18.peel.next, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph20, %.lr.ph
  %.015 = phi i64 [ %18, %.lr.ph ], [ 1, %.lr.ph20 ]
  %16 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %.015
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %16)
  %18 = add nuw nsw i64 %.015, 1
  %19 = load i64, ptr %1, align 8, !tbaa !7
  %.not12.not = icmp slt i64 %.015, %19
  br i1 %.not12.not, label %.lr.ph, label %.preheader, !llvm.loop !11

.lr.ph18.peel.next:                               ; preds = %6, %.lr.ph18.peel.next
  %.117 = phi i64 [ %33, %.lr.ph18.peel.next ], [ 2, %6 ]
  %20 = add nsw i64 %.117, -1
  %21 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !7
  %23 = getelementptr inbounds [200005 x i64], ptr @arr, i64 0, i64 %.117
  %24 = load i64, ptr %23, align 8, !tbaa !7
  %25 = add nsw i64 %24, %22
  store i64 %25, ptr %23, align 8, !tbaa !7
  %26 = load i64, ptr %2, align 8, !tbaa !7
  %27 = sdiv i64 %25, %26
  %28 = sdiv i64 %22, %26
  %29 = sub nsw i64 %27, %28
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %29)
  %.pre22 = load i64, ptr %1, align 8, !tbaa !7
  %31 = icmp eq i64 %.117, %.pre22
  %.str.2..str.325 = select i1 %31, ptr @.str.2, ptr @.str.3
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.325)
  %33 = add nuw nsw i64 %.117, 1
  %34 = load i64, ptr %1, align 8, !tbaa !7
  %.not13.not = icmp slt i64 %.117, %34
  br i1 %.not13.not, label %.lr.ph18.peel.next, label %.loopexit, !llvm.loop !12

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, 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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6, !13}
!13 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass