; LLVM IR from tangjz/acm-icpc :: projecteuler/550.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: 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 void @_Z11FWT_iteratePiii(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3FWTPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %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 %72

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

30:                                               ; preds = %38, %27
  %31 = load i32, ptr %9, 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 %9) #2
  br label %46

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 %9, 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 %9, align 4, !tbaa !9
  %40 = ashr i32 %39, 1
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = mul nsw i64 %42, 493827161
  %44 = srem i64 %43, 987654321
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr %8, align 4, !tbaa !9
  br label %30, !llvm.loop !13

46:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %68, %46
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

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

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

68:                                               ; preds = %52
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !9
  br label %47, !llvm.loop !14

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

72:                                               ; preds = %71, %26
  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 = { 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 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.ph32, label %.loopexit

.lr.ph32:                                         ; preds = %.preheader, %.lr.ph32
  %.02331 = phi i32 [ %6, %.lr.ph32 ], [ 1, %.preheader ]
  tail call void @_Z11FWT_iteratePiii(ptr noundef %0, i32 noundef %1, i32 noundef %.02331)
  %6 = shl i32 %.02331, 1
  %7 = icmp slt i32 %6, %1
  br i1 %7, label %.lr.ph32, 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 %.preheader25

.preheader25:                                     ; preds = %.lr.ph, %8
  %.022.lcssa = phi i64 [ 1, %8 ], [ %15, %.lr.ph ]
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %.preheader25
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %1, 1
  br i1 %12, label %.loopexit.loopexit37.unr-lcssa, label %.lr.ph30.new

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

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.02128 = phi i32 [ %13, %.lr.ph ], [ %9, %8 ]
  %.02227 = phi i64 [ %15, %.lr.ph ], [ 1, %8 ]
  tail call void @_Z11FWT_iteratePiii(ptr noundef %0, i32 noundef %1, i32 noundef %.02128)
  %13 = lshr i32 %.02128, 1
  %14 = mul nuw nsw i64 %.02227, 493827161
  %15 = urem i64 %14, 987654321
  %.not = icmp ult i32 %.02128, 2
  br i1 %.not, label %.preheader25, label %.lr.ph, !llvm.loop !7

16:                                               ; preds = %16, %.lr.ph30.new
  %indvars.iv = phi i64 [ 0, %.lr.ph30.new ], [ %indvars.iv.next.1, %16 ]
  %niter = phi i64 [ 0, %.lr.ph30.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 %.022.lcssa, %19
  %21 = srem i64 %20, 987654321
  %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 %.022.lcssa, %25
  %27 = srem i64 %26, 987654321
  %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.loopexit37.unr-lcssa, label %16, !llvm.loop !12

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

.loopexit.loopexit37.epilog-lcssa:                ; preds = %.loopexit.loopexit37.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 %.022.lcssa, %31
  %33 = srem i64 %32, 987654321
  %34 = trunc nsw i64 %33 to i32
  store i32 %34, ptr %29, align 4, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit37.epilog-lcssa, %.loopexit.loopexit37.unr-lcssa, %.lr.ph32, %.preheader25, %.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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass