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

; 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
@_ZN3pcf4prefE = external dso_local global [10000010 x i32], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3pcf2yoExi(i64 noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = icmp slt i64 %13, 10000010
  br i1 %14, label %15, label %20

15:                                               ; preds = %1
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds [10000010 x i32], ptr @_ZN3pcf4prefE, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  store i64 %19, ptr %2, align 8
  br label %113

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %21)
  %23 = fptosi double %22 to i32
  store i32 %23, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = call noundef double @_ZSt4cbrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %24)
  %26 = fptosi double %25 to i64
  %27 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %26)
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %29)
  %31 = fptosi double %30 to i64
  %32 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %31)
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %35)
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = call noundef i64 @_ZN3pcf2yoExi(i64 noundef %38, i32 noundef %39)
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add nsw i32 %41, %42
  %44 = sub nsw i32 %43, 2
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 1, %45
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %46, %51
  %53 = ashr i64 %52, 1
  %54 = add nsw i64 %40, %53
  store i64 %54, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %55 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %55, ptr %9, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %108, %20
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %111

61:                                               ; preds = %56
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = sdiv i64 %62, %67
  store i64 %68, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %69 = load i64, ptr %4, align 8, !tbaa !5
  %70 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %69)
  %71 = fptosi double %70 to i64
  %72 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %71)
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %11, align 4, !tbaa !9
  %74 = load i64, ptr %4, align 8, !tbaa !5
  %75 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %74)
  %76 = load i64, ptr %5, align 8, !tbaa !5
  %77 = sub nsw i64 %76, %75
  store i64 %77, ptr %5, align 8, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = icmp sle i32 %78, %79
  br i1 %80, label %81, label %107

81:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %82 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %82, ptr %12, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %103, %81
  %84 = load i32, ptr %12, align 4, !tbaa !9
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = icmp slt i32 %84, %85
  br i1 %86, label %88, label %87

87:                                               ; preds = %83
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %106

88:                                               ; preds = %83
  %89 = load i32, ptr %12, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = load i64, ptr %5, align 8, !tbaa !5
  %92 = add nsw i64 %91, %90
  store i64 %92, ptr %5, align 8, !tbaa !5
  %93 = load i64, ptr %4, align 8, !tbaa !5
  %94 = load i32, ptr %12, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = sdiv i64 %93, %98
  %100 = call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %99)
  %101 = load i64, ptr %5, align 8, !tbaa !5
  %102 = sub nsw i64 %101, %100
  store i64 %102, ptr %5, align 8, !tbaa !5
  br label %103

103:                                              ; preds = %88
  %104 = load i32, ptr %12, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %12, align 4, !tbaa !9
  br label %83, !llvm.loop !11

106:                                              ; preds = %87
  br label %107

107:                                              ; preds = %106, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %9, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %9, align 4, !tbaa !9
  br label %56, !llvm.loop !13

111:                                              ; preds = %60
  %112 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %112, ptr %2, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
  br label %113

113:                                              ; preds = %111, %15
  %114 = load i64, ptr %2, align 8
  ret i64 %114
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { 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}


; 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
@_ZN3pcf4prefE = external dso_local local_unnamed_addr global [10000010 x i32], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 10000010
  br i1 %2, label %3, label %7

3:                                                ; preds = %1
  %4 = getelementptr inbounds [10000010 x i32], ptr @_ZN3pcf4prefE, i64 0, i64 %0
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  br label %.loopexit40

7:                                                ; preds = %1
  %8 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %9 = fptosi double %8 to i32
  %10 = tail call noundef double @_ZSt4cbrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %11 = fptosi double %10 to i64
  %12 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %11)
  %13 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %9)
  %14 = fptosi double %13 to i64
  %15 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %14)
  %16 = trunc i64 %15 to i32
  %17 = sext i32 %9 to i64
  %18 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %17)
  %19 = trunc i64 %18 to i32
  %20 = tail call noundef i64 @_ZN3pcf2yoExi(i64 noundef %0, i32 noundef %16)
  %21 = add i64 %18, %15
  %22 = shl i64 %21, 32
  %sext = add i64 %22, -8589934592
  %23 = ashr exact i64 %sext, 32
  %24 = sub i64 %18, %15
  %25 = shl i64 %24, 32
  %sext39 = add i64 %25, 4294967296
  %26 = ashr exact i64 %sext39, 32
  %27 = mul nsw i64 %23, %26
  %28 = ashr i64 %27, 1
  %29 = add nsw i64 %28, %20
  %30 = icmp slt i32 %16, %19
  br i1 %30, label %.lr.ph46.preheader, label %.loopexit40

.lr.ph46.preheader:                               ; preds = %7
  %sext52 = shl i64 %15, 32
  %31 = ashr exact i64 %sext52, 32
  %sext53 = shl i64 %12, 32
  %32 = ashr exact i64 %sext53, 32
  %sext54 = shl i64 %18, 32
  %wide.trip.count = ashr exact i64 %sext54, 32
  br label %.lr.ph46

.lr.ph46:                                         ; preds = %.lr.ph46.preheader, %.loopexit
  %indvars.iv = phi i64 [ %31, %.lr.ph46.preheader ], [ %indvars.iv.next, %.loopexit ]
  %.03643 = phi i64 [ %29, %.lr.ph46.preheader ], [ %.2, %.loopexit ]
  %33 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = sdiv i64 %0, %35
  %37 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %36)
  %38 = fptosi double %37 to i64
  %39 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %38)
  %40 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %36)
  %41 = sub nsw i64 %.03643, %40
  %.not = icmp sle i64 %indvars.iv, %32
  %sext55 = shl i64 %39, 32
  %42 = ashr exact i64 %sext55, 32
  %43 = icmp slt i64 %indvars.iv, %42
  %or.cond = and i1 %.not, %43
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph46, %.lr.ph
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.lr.ph ], [ %indvars.iv, %.lr.ph46 ]
  %.141 = phi i64 [ %50, %.lr.ph ], [ %41, %.lr.ph46 ]
  %44 = add nsw i64 %.141, %indvars.iv48
  %45 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %indvars.iv48
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = sdiv i64 %36, %47
  %49 = tail call noundef i64 @_ZN3pcf6LehmerEx(i64 noundef %48)
  %50 = sub i64 %44, %49
  %indvars.iv.next49 = add nsw i64 %indvars.iv48, 1
  %51 = icmp slt i64 %indvars.iv.next49, %42
  br i1 %51, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph46
  %.2 = phi i64 [ %41, %.lr.ph46 ], [ %50, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit40, label %.lr.ph46, !llvm.loop !11

.loopexit40:                                      ; preds = %.loopexit, %7, %3
  %.034 = phi i64 [ %6, %3 ], [ %29, %7 ], [ %.2, %.loopexit ]
  ret i64 %.034
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4cbrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #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 = { inlinehint 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 = { 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" }

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


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