; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1109（难题）.ll (Z4fModPA60_iix)

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

@b = external dso_local global [60 x [60 x i32]], 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 void @_Z3mulPA60_iS0_i(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fModPA60_iix(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %36, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %39

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

16:                                               ; preds = %32, %15
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %35

21:                                               ; preds = %16
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp eq i32 %22, %23
  %25 = zext i1 %24 to i32
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [60 x [60 x i32]], ptr @b, i64 0, i64 %27
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [60 x i32], ptr %28, i64 0, i64 %30
  store i32 %25, ptr %31, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %21
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !13

35:                                               ; preds = %20
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

39:                                               ; preds = %14
  br label %40

40:                                               ; preds = %50, %39
  %41 = load i64, ptr %6, align 8, !tbaa !11
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %56

43:                                               ; preds = %40
  %44 = load i64, ptr %6, align 8, !tbaa !11
  %45 = and i64 %44, 1
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !9
  call void @_Z3mulPA60_iS0_i(ptr noundef @b, ptr noundef %48, i32 noundef %49)
  br label %50

50:                                               ; preds = %47, %43
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  call void @_Z3mulPA60_iS0_i(ptr noundef %51, ptr noundef %52, i32 noundef %53)
  %54 = load i64, ptr %6, align 8, !tbaa !11
  %55 = ashr i64 %54, 1
  store i64 %55, ptr %6, align 8, !tbaa !11
  br label %40, !llvm.loop !16

56:                                               ; preds = %40
  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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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"

@b = external dso_local global [60 x [60 x i32]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fModPA60_iix(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not26 = icmp slt i32 %1, 1
  br i1 %.not26, label %.preheader, label %.preheader23.preheader

.preheader23.preheader:                           ; preds = %3
  %4 = add nuw i32 %1, 1
  %wide.trip.count35 = zext i32 %4 to i64
  %5 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  %n.vec = and i64 %5, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %5
  br label %.preheader23

.preheader23:                                     ; preds = %.preheader23.preheader, %._crit_edge
  %indvars.iv32 = phi i64 [ 1, %.preheader23.preheader ], [ %indvars.iv.next33, %._crit_edge ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader23
  %indvars.iv.ph = phi i64 [ 1, %.preheader23 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader23
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %indvars.iv32, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 1, i64 2, i64 3, i64 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %offset.idx = or disjoint i64 %index, 1
  %6 = icmp eq <4 x i64> %broadcast.splat, %vec.ind
  %7 = icmp eq <4 x i64> %broadcast.splat, %step.add
  %8 = zext <4 x i1> %6 to <4 x i32>
  %9 = zext <4 x i1> %7 to <4 x i32>
  %10 = getelementptr inbounds [60 x [60 x i32]], ptr @b, i64 0, i64 %indvars.iv32, i64 %offset.idx
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %8, ptr %10, align 4, !tbaa !5
  store <4 x i32> %9, ptr %11, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8>
  %12 = icmp eq i64 %index.next, %n.vec
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

.preheader:                                       ; preds = %._crit_edge, %3
  %.not2028 = icmp eq i64 %2, 0
  br i1 %.not2028, label %._crit_edge30, label %.lr.ph

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count35
  br i1 %exitcond36.not, label %.preheader, label %.preheader23, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %13 = icmp eq i64 %indvars.iv32, %indvars.iv
  %14 = zext i1 %13 to i32
  %15 = getelementptr inbounds [60 x [60 x i32]], ptr @b, i64 0, i64 %indvars.iv32, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count35
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !14

.lr.ph:                                           ; preds = %.preheader, %18
  %.01829 = phi i64 [ %19, %18 ], [ %2, %.preheader ]
  %16 = and i64 %.01829, 1
  %.not21 = icmp eq i64 %16, 0
  br i1 %.not21, label %18, label %17

17:                                               ; preds = %.lr.ph
  tail call void @_Z3mulPA60_iS0_i(ptr noundef nonnull @b, ptr noundef %0, i32 noundef %1)
  br label %18

18:                                               ; preds = %17, %.lr.ph
  tail call void @_Z3mulPA60_iS0_i(ptr noundef %0, ptr noundef %0, i32 noundef %1)
  %19 = ashr i64 %.01829, 1
  %.not20 = icmp ult i64 %.01829, 2
  br i1 %.not20, label %._crit_edge30, label %.lr.ph, !llvm.loop !15

._crit_edge30:                                    ; preds = %18, %.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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass