; LLVM IR from alexpizarroj/acm-icpc-trd :: src/math/deterministic-miller-rabin.ll (Z6mulmodyyy)

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

; 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
define dso_local noundef i64 @_Z6mulmodyyy(i64 noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %36, %3
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = icmp ugt i64 %12, 0
  br i1 %13, label %14, label %46

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = urem i64 %15, %16
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = urem i64 %18, 10
  %20 = mul i64 %17, %19
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = urem i64 %20, %21
  store i64 %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %33, %14
  %24 = load i64, ptr %10, align 8, !tbaa !5
  %25 = load i64, ptr %8, align 8, !tbaa !5
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %36

28:                                               ; preds = %23
  %29 = load i64, ptr %9, align 8, !tbaa !5
  %30 = mul i64 %29, 10
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = urem i64 %30, %31
  store i64 %32, ptr %9, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %28
  %34 = load i64, ptr %10, align 8, !tbaa !5
  %35 = add i64 %34, 1
  store i64 %35, ptr %10, align 8, !tbaa !5
  br label %23, !llvm.loop !9

36:                                               ; preds = %27
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !5
  %39 = add i64 %37, %38
  %40 = load i64, ptr %6, align 8, !tbaa !5
  %41 = urem i64 %39, %40
  store i64 %41, ptr %7, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !5
  %43 = add i64 %42, 1
  store i64 %43, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = udiv i64 %44, 10
  store i64 %45, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %11, !llvm.loop !11

46:                                               ; preds = %11
  %47 = load i64, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %47
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_Z6mulmodyyy(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not23 = icmp eq i64 %1, 0
  br i1 %.not23, label %._crit_edge29, label %.lr.ph28

.lr.ph28:                                         ; preds = %3
  %4 = urem i64 %0, %2
  br label %5

5:                                                ; preds = %.lr.ph28, %._crit_edge
  %.01726 = phi i64 [ 0, %.lr.ph28 ], [ %13, %._crit_edge ]
  %.01825 = phi i64 [ 0, %.lr.ph28 ], [ %12, %._crit_edge ]
  %.01924 = phi i64 [ %1, %.lr.ph28 ], [ %7, %._crit_edge ]
  %6 = urem i64 %.01924, 10
  %7 = udiv i64 %.01924, 10
  %8 = mul i64 %4, %6
  %.01620 = urem i64 %8, %2
  %.not31 = icmp eq i64 %.01726, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %xtraiter = and i64 %.01726, 3
  %9 = icmp ult i64 %.01726, 4
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %.01726, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.016.lcssa35.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %.016.3, %.lr.ph ]
  %.01622.unr = phi i64 [ %.01620, %.lr.ph.preheader ], [ %.016.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.01622.epil = phi i64 [ %.016.epil, %.lr.ph.epil ], [ %.01622.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %10 = mul i64 %.01622.epil, 10
  %.016.epil = urem i64 %10, %2
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !5

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %5
  %.016.lcssa = phi i64 [ %.01620, %5 ], [ %.016.lcssa35.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.016.epil, %.lr.ph.epil ]
  %11 = add i64 %.016.lcssa, %.01825
  %12 = urem i64 %11, %2
  %13 = add i64 %.01726, 1
  %.not = icmp ult i64 %.01924, 10
  br i1 %.not, label %._crit_edge29, label %5, !llvm.loop !7

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01622 = phi i64 [ %.01620, %.lr.ph.preheader.new ], [ %.016.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %14 = mul i64 %.01622, 10
  %.016 = urem i64 %14, %2
  %15 = mul i64 %.016, 10
  %.016.1 = urem i64 %15, %2
  %16 = mul i64 %.016.1, 10
  %.016.2 = urem i64 %16, %2
  %17 = mul i64 %.016.2, 10
  %.016.3 = urem i64 %17, %2
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge29:                                    ; preds = %._crit_edge, %3
  %.018.lcssa = phi i64 [ 0, %3 ], [ %12, %._crit_edge ]
  ret i64 %.018.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.unroll.disable"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.mustprogress"}
!9 = distinct !{!9, !8}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass