; LLVM IR from Leet-Us-Code/DSA-A-Z-Practice :: Sid's Contests/Codechef contests/July Long Challenge (Optimal Denomination)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10precomputeSt6vectorIxSaIxEEPxS2_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  store i64 %12, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i64, ptr %13, i64 0
  store i64 0, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = sub nsw i64 %16, 1
  %18 = getelementptr inbounds i64, ptr %15, i64 %17
  store i64 0, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #3
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = sub nsw i64 %21, 1
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %22) #3
  %24 = load i64, ptr %23, align 8, !tbaa !9
  store i64 %24, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 1, ptr %10, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %41, %3
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %44

30:                                               ; preds = %25
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = sub nsw i64 %32, 1
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %33) #3
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = call noundef i64 @_Z3gcdxx(i64 noundef %31, i64 noundef %35)
  store i64 %36, ptr %8, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = getelementptr inbounds i64, ptr %38, i64 %39
  store i64 %37, ptr %40, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %30
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %10, align 8, !tbaa !9
  br label %25, !llvm.loop !11

44:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = sub nsw i64 %45, 2
  store i64 %46, ptr %11, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %62, %44
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = icmp sge i64 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %65

51:                                               ; preds = %47
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = add nsw i64 %53, 1
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %54) #3
  %56 = load i64, ptr %55, align 8, !tbaa !9
  %57 = call noundef i64 @_Z3gcdxx(i64 noundef %52, i64 noundef %56)
  store i64 %57, ptr %9, align 8, !tbaa !9
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = getelementptr inbounds i64, ptr %59, i64 %60
  store i64 %58, ptr %61, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %51
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = add nsw i64 %63, -1
  store i64 %64, ptr %11, align 8, !tbaa !9
  br label %47, !llvm.loop !13

65:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 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 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 = { 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 #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 = !{!"any pointer", !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}


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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10precomputeSt6vectorIxSaIxEEPxS2_(ptr noundef nonnull %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  store i64 0, ptr %1, align 8, !tbaa !5
  %5 = add nsw i64 %4, -1
  %6 = getelementptr inbounds i64, ptr %2, i64 %5
  store i64 0, ptr %6, align 8, !tbaa !5
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %5) #2
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = icmp sgt i64 %4, 1
  br i1 %11, label %.lr.ph, label %._crit_edge29

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %11, label %.lr.ph28.preheader, label %._crit_edge29

.lr.ph28.preheader:                               ; preds = %._crit_edge
  %12 = add nsw i64 %4, -2
  br label %.lr.ph28

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.01924 = phi i64 [ %18, %.lr.ph ], [ 1, %3 ]
  %.02123 = phi i64 [ %16, %.lr.ph ], [ %8, %3 ]
  %13 = add nsw i64 %.01924, -1
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %13) #2
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.02123, i64 noundef %15)
  %17 = getelementptr inbounds i64, ptr %1, i64 %.01924
  store i64 %16, ptr %17, align 8, !tbaa !5
  %18 = add nuw nsw i64 %.01924, 1
  %exitcond.not = icmp eq i64 %18, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge29:                                    ; preds = %.lr.ph28, %3, %._crit_edge
  ret void

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %.lr.ph28
  %.026 = phi i64 [ %24, %.lr.ph28 ], [ %12, %.lr.ph28.preheader ]
  %.02025 = phi i64 [ %22, %.lr.ph28 ], [ %10, %.lr.ph28.preheader ]
  %19 = add nuw nsw i64 %.026, 1
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #2
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.02025, i64 noundef %21)
  %23 = getelementptr inbounds i64, ptr %2, i64 %.026
  store i64 %22, ptr %23, align 8, !tbaa !5
  %24 = add nsw i64 %.026, -1
  %.not = icmp eq i64 %.026, 0
  br i1 %.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 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 #2 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass