; LLVM IR from tangjz/acm-icpc :: lydsy/4253.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 %45

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 = %31, %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 %34

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 %30

23:                                               ; preds = %15
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = mul nsw i64 %28, %24
  store i64 %29, ptr %27, align 8, !tbaa !5
  store i8 1, ptr %3, align 1, !tbaa !9
  store i32 2, ptr %5, align 4
  br label %34

30:                                               ; preds = %15
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %4, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %4, align 4, !tbaa !11
  br label %10, !llvm.loop !13

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

35:                                               ; preds = %34
  %36 = load i8, ptr %3, align 1, !tbaa !9, !range !15, !noundef !16
  %37 = trunc i8 %36 to i1
  br i1 %37, label %44, label %38

38:                                               ; preds = %35
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr @cnt, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @cnt, align 4, !tbaa !11
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %42
  store i64 %39, ptr %43, align 8, !tbaa !5
  br label %44

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

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

46:                                               ; preds = %51, %45
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = call noundef i64 @_Z11pollard_rhox(i64 noundef %47)
  store i64 %48, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = icmp eq i64 %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %46, !llvm.loop !17

52:                                               ; preds = %46
  %53 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z13decompositionx(i64 noundef %53)
  %54 = load i64, ptr %2, align 8, !tbaa !5
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = sdiv i64 %54, %55
  call void @_Z13decompositionx(i64 noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %57

57:                                               ; preds = %52, %44
  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 %.preheader17

.preheader17:                                     ; preds = %1, %tailrecurse
  %.tr22 = phi i64 [ %19, %tailrecurse ], [ %0, %1 ]
  br label %16

.preheader:                                       ; preds = %tailrecurse, %1
  %.tr.lcssa = phi i64 [ %0, %1 ], [ %19, %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 %10, label %5

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %indvars.iv
  %12 = mul nsw i64 %7, %.tr.lcssa
  store i64 %12, ptr %11, align 8, !tbaa !11
  br label %21

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

16:                                               ; preds = %.preheader17, %16
  %17 = tail call noundef i64 @_Z11pollard_rhox(i64 noundef %.tr22)
  %18 = icmp eq i64 %17, %.tr22
  br i1 %18, label %16, label %tailrecurse, !llvm.loop !13

tailrecurse:                                      ; preds = %16
  tail call void @_Z13decompositionx(i64 noundef %17)
  %19 = sdiv i64 %.tr22, %17
  %20 = tail call noundef zeroext i1 @_Z12miller_rabinx(i64 noundef %19)
  br i1 %20, label %.preheader, label %.preheader17

21:                                               ; preds = %10, %.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