; LLVM IR from tangjz/acm-icpc :: projecteuler/560.ll (Z3FWTPiii)

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11FWT_iteratePiii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3FWTPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %27

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %23, %13
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %26

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  call void @_Z11FWT_iteratePiii(ptr noundef %20, i32 noundef %21, i32 noundef %22)
  br label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = shl i32 %24, 1
  store i32 %25, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !11

26:                                               ; preds = %18
  br label %69

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %38, %27
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %41

34:                                               ; preds = %30
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z11FWT_iteratePiii(ptr noundef %35, i32 noundef %36, i32 noundef %37)
  br label %38

38:                                               ; preds = %34
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = ashr i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %30, !llvm.loop !13

41:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = call noundef i32 @_Z7mod_powii(i32 noundef %42, i32 noundef 1000000005)
  store i32 %43, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %65, %41
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %68

49:                                               ; preds = %44
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %55, %57
  %59 = srem i64 %58, 1000000007
  %60 = trunc i64 %59 to i32
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %49
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !9
  br label %44, !llvm.loop !14

68:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %69

69:                                               ; preds = %68, %26
  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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !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}
!14 = distinct !{!14, !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"

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11FWT_iteratePiii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3FWTPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.preheader, label %8

.preheader:                                       ; preds = %3
  %5 = icmp sgt i32 %1, 1
  br i1 %5, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %.preheader, %.lr.ph30
  %.02129 = phi i32 [ %6, %.lr.ph30 ], [ 1, %.preheader ]
  tail call void @_Z11FWT_iteratePiii(ptr noundef %0, i32 noundef %1, i32 noundef %.02129)
  %6 = shl i32 %.02129, 1
  %7 = icmp slt i32 %6, %1
  br i1 %7, label %.lr.ph30, label %.loopexit, !llvm.loop !5

8:                                                ; preds = %3
  %9 = ashr i32 %1, 1
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %8
  %11 = tail call noundef i32 @_Z7mod_powii(i32 noundef %1, i32 noundef 1000000005)
  %12 = icmp sgt i32 %1, 0
  br i1 %12, label %.lr.ph28, label %.loopexit

.lr.ph28:                                         ; preds = %._crit_edge
  %13 = sext i32 %11 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %14 = icmp eq i32 %1, 1
  br i1 %14, label %.loopexit.loopexit35.unr-lcssa, label %.lr.ph28.new

.lr.ph28.new:                                     ; preds = %.lr.ph28
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %16

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.02225 = phi i32 [ %15, %.lr.ph ], [ %9, %8 ]
  tail call void @_Z11FWT_iteratePiii(ptr noundef %0, i32 noundef %1, i32 noundef %.02225)
  %15 = lshr i32 %.02225, 1
  %.not = icmp ult i32 %.02225, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !7

16:                                               ; preds = %16, %.lr.ph28.new
  %indvars.iv = phi i64 [ 0, %.lr.ph28.new ], [ %indvars.iv.next.1, %16 ]
  %niter = phi i64 [ 0, %.lr.ph28.new ], [ %niter.next.1, %16 ]
  %17 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !8
  %19 = sext i32 %18 to i64
  %20 = mul nsw i64 %19, %13
  %21 = srem i64 %20, 1000000007
  %22 = trunc nsw i64 %21 to i32
  store i32 %22, ptr %17, align 4, !tbaa !8
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %24 = load i32, ptr %23, align 4, !tbaa !8
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %25, %13
  %27 = srem i64 %26, 1000000007
  %28 = trunc nsw i64 %27 to i32
  store i32 %28, ptr %23, align 4, !tbaa !8
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit35.unr-lcssa, label %16, !llvm.loop !12

.loopexit.loopexit35.unr-lcssa:                   ; preds = %16, %.lr.ph28
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph28 ], [ %indvars.iv.next.1, %16 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit35.epilog-lcssa

.loopexit.loopexit35.epilog-lcssa:                ; preds = %.loopexit.loopexit35.unr-lcssa
  %29 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.unr
  %30 = load i32, ptr %29, align 4, !tbaa !8
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %31, %13
  %33 = srem i64 %32, 1000000007
  %34 = trunc nsw i64 %33 to i32
  store i32 %34, ptr %29, align 4, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit35.epilog-lcssa, %.loopexit.loopexit35.unr-lcssa, %.lr.ph30, %._crit_edge, %.preheader
  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" }

!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.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}


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