; LLVM IR from lzyrapx/Competitive-Programming :: ACdream (1060（找循环节代码）)

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

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

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

9:                                                ; preds = %26, %0
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = mul nsw i64 3, %10
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = add nsw i64 %11, %12
  %14 = srem i64 %13, 1000000007
  store i64 %14, ptr %2, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 1
  br i1 %16, label %17, label %23

17:                                               ; preds = %9
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %21)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %29

23:                                               ; preds = %17, %9
  %24 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %24, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %25, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !11

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

30:                                               ; preds = %47, %29
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = mul nsw i64 3, %31
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = add nsw i64 %32, %33
  %35 = srem i64 %34, 222222224
  store i64 %35, ptr %2, align 8, !tbaa !5
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = icmp eq i64 %36, 1
  br i1 %37, label %38, label %44

38:                                               ; preds = %30
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %42)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %50

44:                                               ; preds = %38, %30
  %45 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %45, ptr %4, align 8, !tbaa !5
  %46 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %46, ptr %3, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %44
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %30, !llvm.loop !13

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

51:                                               ; preds = %68, %50
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = mul nsw i64 3, %52
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = add nsw i64 %53, %54
  %56 = srem i64 %55, 183120
  store i64 %56, ptr %2, align 8, !tbaa !5
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = icmp eq i64 %57, 1
  br i1 %58, label %59, label %65

59:                                               ; preds = %51
  %60 = load i64, ptr %3, align 8, !tbaa !5
  %61 = icmp eq i64 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %63)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %71

65:                                               ; preds = %59, %51
  %66 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %66, ptr %4, align 8, !tbaa !5
  %67 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %67, ptr %3, align 8, !tbaa !5
  br label %68

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

71:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

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

declare i32 @printf(ptr noundef, ...) #2

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

attributes #0 = { mustprogress norecurse 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 = { "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 = !{!"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"

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %1, %0
  %.032 = phi i64 [ 1, %0 ], [ %4, %1 ]
  %.031 = phi i64 [ 0, %0 ], [ %.032, %1 ]
  %.030 = phi i32 [ 1, %0 ], [ %7, %1 ]
  %2 = mul nsw i64 %.032, 3
  %3 = add nsw i64 %2, %.031
  %4 = srem i64 %3, 1000000007
  %5 = icmp eq i64 %4, 1
  %6 = icmp eq i64 %.032, 0
  %or.cond = and i1 %6, %5
  %7 = add nuw nsw i32 %.030, 1
  br i1 %or.cond, label %8, label %1, !llvm.loop !5

8:                                                ; preds = %1
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.030)
  br label %10

10:                                               ; preds = %10, %8
  %.133 = phi i64 [ 1, %8 ], [ %13, %10 ]
  %.1 = phi i64 [ 0, %8 ], [ %.133, %10 ]
  %.029 = phi i32 [ 1, %8 ], [ %16, %10 ]
  %11 = mul nsw i64 %.133, 3
  %12 = add nsw i64 %11, %.1
  %13 = srem i64 %12, 222222224
  %14 = icmp eq i64 %13, 1
  %15 = icmp eq i64 %.133, 0
  %or.cond3 = and i1 %15, %14
  %16 = add nuw nsw i32 %.029, 1
  br i1 %or.cond3, label %17, label %10, !llvm.loop !7

17:                                               ; preds = %10
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.029)
  br label %19

19:                                               ; preds = %19, %17
  %.234 = phi i64 [ 3, %17 ], [ %22, %19 ]
  %.2 = phi i64 [ 1, %17 ], [ %.234, %19 ]
  %.0 = phi i32 [ 2, %17 ], [ %25, %19 ]
  %20 = mul nsw i64 %.234, 3
  %21 = add nsw i64 %20, %.2
  %22 = srem i64 %21, 183120
  %23 = icmp eq i64 %22, 1
  %24 = icmp eq i64 %.234, 0
  %or.cond5 = and i1 %24, %23
  %25 = add nuw nsw i32 %.0, 1
  br i1 %or.cond5, label %26, label %19, !llvm.loop !8

26:                                               ; preds = %19
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.0)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 = { nofree nounwind "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 = distinct !{!8, !6}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass