; LLVM IR from tangjz/acm-icpc :: lydsy/4522.ll (Z13decompositionx)

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

@cnt = external dso_local global i32, align 4
@pp = external dso_local global [16 x i64], 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z12miller_rabinx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z11pollard_rhox(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13decompositionx(i64 noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = call noundef zeroext i1 @_Z12miller_rabinx(i64 noundef %7)
  br i1 %8, label %9, label %39

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %25, %9
  %11 = load i32, ptr %4, align 4, !tbaa !11
  %12 = load i32, ptr @cnt, align 4, !tbaa !11
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %28

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = srem i64 %19, %20
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %15
  store i8 1, ptr %3, align 1, !tbaa !9
  store i32 2, ptr %5, align 4
  br label %28

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %4, align 4, !tbaa !11
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !11
  br label %10, !llvm.loop !13

28:                                               ; preds = %23, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %29

29:                                               ; preds = %28
  %30 = load i8, ptr %3, align 1, !tbaa !9, !range !15, !noundef !16
  %31 = trunc i8 %30 to i1
  br i1 %31, label %38, label %32

32:                                               ; preds = %29
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = load i32, ptr @cnt, align 4, !tbaa !11
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @cnt, align 4, !tbaa !11
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %36
  store i64 %33, ptr %37, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %32, %29
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  br label %51

39:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  br label %40

40:                                               ; preds = %45, %39
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = call noundef i64 @_Z11pollard_rhox(i64 noundef %41)
  store i64 %42, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = icmp eq i64 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  br label %40, !llvm.loop !17

46:                                               ; preds = %40
  %47 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z13decompositionx(i64 noundef %47)
  %48 = load i64, ptr %2, align 8, !tbaa !5
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = sdiv i64 %48, %49
  call void @_Z13decompositionx(i64 noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %51

51:                                               ; preds = %46, %38
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


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

@cnt = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local local_unnamed_addr global [16 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z12miller_rabinx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z11pollard_rhox(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13decompositionx(i64 noundef %0) local_unnamed_addr #1 {
  %2 = tail call noundef zeroext i1 @_Z12miller_rabinx(i64 noundef %0)
  br i1 %2, label %.preheader, label %.preheader15

.preheader15:                                     ; preds = %1, %tailrecurse
  %.tr18 = phi i64 [ %16, %tailrecurse ], [ %0, %1 ]
  br label %13

.preheader:                                       ; preds = %tailrecurse, %1
  %.tr.lcssa = phi i64 [ %0, %1 ], [ %16, %tailrecurse ]
  %3 = load i32, ptr @cnt, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %5 ]
  %6 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = srem i64 %7, %.tr.lcssa
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %.loopexit, label %5

.critedge:                                        ; preds = %5, %.preheader
  %10 = add nsw i32 %3, 1
  store i32 %10, ptr @cnt, align 4, !tbaa !5
  %11 = sext i32 %3 to i64
  %12 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %11
  store i64 %.tr.lcssa, ptr %12, align 8, !tbaa !11
  br label %.loopexit

13:                                               ; preds = %.preheader15, %13
  %14 = tail call noundef i64 @_Z11pollard_rhox(i64 noundef %.tr18)
  %15 = icmp eq i64 %14, %.tr18
  br i1 %15, label %13, label %tailrecurse, !llvm.loop !13

tailrecurse:                                      ; preds = %13
  tail call void @_Z13decompositionx(i64 noundef %14)
  %16 = sdiv i64 %.tr18, %14
  %17 = tail call noundef zeroext i1 @_Z12miller_rabinx(i64 noundef %16)
  br i1 %17, label %.preheader, label %.preheader15

.loopexit:                                        ; preds = %.lr.ph, %.critedge
  ret void
}

attributes #0 = { 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 #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" }

!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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}


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