; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1216D. Swords (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 i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = 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 i64, align 8
  %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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  br label %9

9:                                                ; preds = %69, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %75

12:                                               ; preds = %9
  store i64 0, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %33, %12
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %36

17:                                               ; preds = %13
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %19)
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %21, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %17
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  store i64 %31, ptr %6, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %27, %17
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !11

36:                                               ; preds = %13
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %66, %36
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %41, label %69

41:                                               ; preds = %37
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = icmp eq i64 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  br label %66

49:                                               ; preds = %41
  %50 = load i64, ptr %6, align 8, !tbaa !5
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = sub nsw i64 %50, %54
  %56 = load i64, ptr %8, align 8, !tbaa !5
  %57 = add nsw i64 %56, %55
  store i64 %57, ptr %8, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = sub nsw i64 %59, %63
  %65 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %58, i64 noundef %64)
  store i64 %65, ptr %7, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %49, %48
  %67 = load i64, ptr %5, align 8, !tbaa !5
  %68 = add nsw i64 %67, 1
  store i64 %68, ptr %5, align 8, !tbaa !5
  br label %37, !llvm.loop !13

69:                                               ; preds = %37
  %70 = load i64, ptr %8, align 8, !tbaa !5
  %71 = load i64, ptr %7, align 8, !tbaa !5
  %72 = sdiv i64 %70, %71
  %73 = load i64, ptr %7, align 8, !tbaa !5
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %72, i64 noundef %73)
  br label %9, !llvm.loop !14

75:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) #3

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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@arr = external dso_local global [200005 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress 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) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not36 = icmp eq i32 %2, -1
  br i1 %.not36, label %._crit_edge37, label %.preheader27

.preheader27:                                     ; preds = %0, %._crit_edge
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %5 = icmp sgt i64 %11, 0
  br i1 %5, label %.lr.ph33, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader27, %.lr.ph
  %.02129 = phi i64 [ %spec.select, %.lr.ph ], [ 0, %.preheader27 ]
  %.02328 = phi i64 [ %10, %.lr.ph ], [ 0, %.preheader27 ]
  %6 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %.02328
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %spec.select = call i64 @llvm.smax.i64(i64 %.02129, i64 %9)
  %10 = add nuw nsw i64 %.02328, 1
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = icmp slt i64 %10, %11
  br i1 %12, label %.lr.ph, label %.preheader, !llvm.loop !11

.lr.ph33:                                         ; preds = %.preheader, %22
  %13 = phi i64 [ %23, %22 ], [ %11, %.preheader ]
  %.032 = phi i64 [ %.1, %22 ], [ 0, %.preheader ]
  %.01931 = phi i64 [ %.120, %22 ], [ 0, %.preheader ]
  %.12430 = phi i64 [ %24, %22 ], [ 0, %.preheader ]
  %14 = getelementptr inbounds [200005 x i32], ptr @arr, i64 0, i64 %.12430
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = icmp eq i64 %spec.select, %16
  br i1 %17, label %22, label %18

18:                                               ; preds = %.lr.ph33
  %19 = sub nsw i64 %spec.select, %16
  %20 = add nsw i64 %19, %.032
  %21 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %.01931, i64 noundef %19)
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %.lr.ph33, %18
  %23 = phi i64 [ %13, %.lr.ph33 ], [ %.pre, %18 ]
  %.120 = phi i64 [ %.01931, %.lr.ph33 ], [ %21, %18 ]
  %.1 = phi i64 [ %.032, %.lr.ph33 ], [ %20, %18 ]
  %24 = add nuw nsw i64 %.12430, 1
  %25 = icmp slt i64 %24, %23
  br i1 %25, label %.lr.ph33, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %22, %.preheader27, %.preheader
  %.019.lcssa = phi i64 [ 0, %.preheader ], [ 0, %.preheader27 ], [ %.120, %22 ]
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ 0, %.preheader27 ], [ %.1, %22 ]
  %26 = sdiv i64 %.0.lcssa, %.019.lcssa
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %26, i64 noundef %.019.lcssa)
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %28, -1
  br i1 %.not, label %._crit_edge37, label %.preheader27, !llvm.loop !14

._crit_edge37:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #3

; 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

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

attributes #0 = { mustprogress 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 = { 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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