; LLVM IR from tangjz/acm-icpc :: 51nod/1035.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
@p = 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 %38

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 = %24, %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 %27

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 @p, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = icmp eq i64 %19, %20
  br i1 %21, label %22, label %23

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

23:                                               ; preds = %15
  br label %24

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

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

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

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

37:                                               ; preds = %31, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  br label %50

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

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

44:                                               ; preds = %39
  br label %39, !llvm.loop !17

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

50:                                               ; preds = %45, %37
  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
@p = 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 [ %15, %tailrecurse ], [ %0, %1 ]
  br label %12

.preheader:                                       ; preds = %tailrecurse, %1
  %.tr.lcssa = phi i64 [ %0, %1 ], [ %15, %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 @p, i64 0, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i64 %7, %.tr.lcssa
  br i1 %8, label %.loopexit, label %5

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

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

tailrecurse:                                      ; preds = %12
  tail call void @_Z13decompositionx(i64 noundef %13)
  %15 = sdiv i64 %.tr18, %13
  %16 = tail call noundef zeroext i1 @_Z12miller_rabinx(i64 noundef %15)
  br i1 %16, 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