; LLVM IR from ShahjalalShohag/code-library :: Number Theory/K Divisors.ll (ZN3pcf2yoExi)

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

@_ZN3pcf6primesE = external dso_local global [1000010 x i32], align 16
@_ZN3pcf2dpE = external dso_local global [100000 x [100 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN3pcf2yoExi(i64 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load i64, ptr %4, align 8, !tbaa !5
  %7 = icmp slt i64 %6, 100000
  br i1 %7, label %8, label %19

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 100
  br i1 %10, label %11, label %19

11:                                               ; preds = %8
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %12
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100 x i32], ptr %13, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %3, align 8
  br label %53

19:                                               ; preds = %8, %2
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  store i64 %24, ptr %4, align 8, !tbaa !5
  %25 = ashr i64 %24, 1
  store i64 %25, ptr %3, align 8
  br label %53

26:                                               ; preds = %19
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = icmp sge i64 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %26
  store i64 1, ptr %3, align 8
  br label %53

36:                                               ; preds = %26
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sub nsw i32 %38, 1
  %40 = call noundef i64 @_ZN3pcf2yoExi(i64 noundef %37, i32 noundef %39)
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = sdiv i64 %41, %47
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  %51 = call noundef i64 @_ZN3pcf2yoExi(i64 noundef %48, i32 noundef %50)
  %52 = sub nsw i64 %40, %51
  store i64 %52, ptr %3, align 8
  br label %53

53:                                               ; preds = %36, %35, %22, %11
  %54 = load i64, ptr %3, align 8
  ret i64 %54
}

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

!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}


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

@_ZN3pcf6primesE = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@_ZN3pcf2dpE = external dso_local local_unnamed_addr global [100000 x [100 x i32]], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZN3pcf2yoExi(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i64 %0, 100000
  %4 = icmp slt i32 %1, 100
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %10

5:                                                ; preds = %2
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  br label %common.ret18

10:                                               ; preds = %2
  %11 = icmp eq i32 %1, 1
  br i1 %11, label %12, label %15

12:                                               ; preds = %10
  %13 = add nsw i64 %0, 1
  %14 = ashr i64 %13, 1
  br label %common.ret18

15:                                               ; preds = %10
  %16 = add nsw i32 %1, -1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not = icmp slt i64 %20, %0
  br i1 %.not, label %21, label %common.ret18

common.ret18:                                     ; preds = %15, %12, %5, %21
  %common.ret18.op = phi i64 [ %25, %21 ], [ %9, %5 ], [ %14, %12 ], [ 1, %15 ]
  ret i64 %common.ret18.op

21:                                               ; preds = %15
  %22 = tail call noundef i64 @_ZN3pcf2yoExi(i64 noundef %0, i32 noundef %16)
  %23 = sdiv i64 %0, %20
  %24 = tail call noundef i64 @_ZN3pcf2yoExi(i64 noundef %23, i32 noundef %16)
  %25 = sub nsw i64 %22, %24
  br label %common.ret18
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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" }

!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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass