; LLVM IR from Tunghohin/Competitive_Coding :: Luogu (p1008)

; 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 [10 x i8], align 1

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

4:                                                ; preds = %20, %0
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp sle i32 %5, 9
  br i1 %6, label %7, label %23

7:                                                ; preds = %4
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = mul nsw i32 2, %8
  %10 = srem i32 %9, 10
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %19

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = mul nsw i32 2, %14
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = mul nsw i32 3, %16
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %13, i32 noundef %15, i32 noundef %17)
  br label %19

19:                                               ; preds = %12, %7
  br label %20

20:                                               ; preds = %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %4, !llvm.loop !9

23:                                               ; preds = %4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %66, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp sle i32 %25, 333
  br i1 %26, label %27, label %69

27:                                               ; preds = %24
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = srem i32 %28, 10
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %65

31:                                               ; preds = %27
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sdiv i32 %32, 10
  %34 = srem i32 %33, 10
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %65

36:                                               ; preds = %31
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = mul nsw i32 2, %37
  %39 = srem i32 %38, 10
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %65

41:                                               ; preds = %36
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = mul nsw i32 2, %42
  %44 = sdiv i32 %43, 10
  %45 = srem i32 %44, 10
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %65

47:                                               ; preds = %41
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = mul nsw i32 3, %48
  %50 = srem i32 %49, 10
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %65

52:                                               ; preds = %47
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = mul nsw i32 3, %53
  %55 = sdiv i32 %54, 10
  %56 = srem i32 %55, 10
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %65

58:                                               ; preds = %52
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = mul nsw i32 2, %60
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = mul nsw i32 3, %62
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %59, i32 noundef %61, i32 noundef %63)
  br label %65

65:                                               ; preds = %58, %52, %47, %41, %36, %31, %27
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %2, align 4, !tbaa !5
  br label %24, !llvm.loop !11

69:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader.preheader:
  %0 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 1, i32 noundef 2, i32 noundef 3)
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 2, i32 noundef 4, i32 noundef 6)
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 3, i32 noundef 6, i32 noundef 9)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 4, i32 noundef 8, i32 noundef 12)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 6, i32 noundef 12, i32 noundef 18)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 7, i32 noundef 14, i32 noundef 21)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 8, i32 noundef 16, i32 noundef 24)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 9, i32 noundef 18, i32 noundef 27)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %24
  %.01741 = phi i32 [ %25, %24 ], [ 1, %.preheader.preheader ]
  %.lhs.trunc = trunc nuw i32 %.01741 to i16
  %8 = urem i16 %.lhs.trunc, 10
  %9 = udiv i16 %.lhs.trunc, 10
  %.not = icmp eq i16 %8, 0
  %.lhs.trunc26 = trunc nuw i16 %9 to i8
  %10 = urem i8 %.lhs.trunc26, 10
  %.not18 = icmp eq i8 %10, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not18
  br i1 %or.cond, label %24, label %11

11:                                               ; preds = %.preheader
  %12 = shl nuw nsw i32 %.01741, 1
  %.lhs.trunc28 = trunc nuw i32 %12 to i16
  %13 = urem i16 %.lhs.trunc28, 10
  %.not19 = icmp eq i16 %13, 0
  br i1 %.not19, label %24, label %14

14:                                               ; preds = %11
  %15 = udiv i16 %.lhs.trunc, 5
  %.lhs.trunc32 = trunc nuw i16 %15 to i8
  %16 = urem i8 %.lhs.trunc32, 10
  %.not20 = icmp eq i8 %16, 0
  br i1 %.not20, label %24, label %17

17:                                               ; preds = %14
  %18 = mul nuw nsw i32 %.01741, 3
  %.lhs.trunc34 = trunc nuw i32 %18 to i16
  %19 = urem i16 %.lhs.trunc34, 10
  %20 = udiv i16 %.lhs.trunc34, 10
  %.not21 = icmp eq i16 %19, 0
  %.lhs.trunc38 = trunc nuw i16 %20 to i8
  %21 = urem i8 %.lhs.trunc38, 10
  %.not22 = icmp eq i8 %21, 0
  %or.cond49 = select i1 %.not21, i1 true, i1 %.not22
  br i1 %or.cond49, label %24, label %22

22:                                               ; preds = %17
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.01741, i32 noundef %12, i32 noundef %18)
  br label %24

24:                                               ; preds = %.preheader, %11, %14, %17, %22
  %25 = add nuw nsw i32 %.01741, 1
  %exitcond.not = icmp eq i32 %25, 334
  br i1 %exitcond.not, label %26, label %.preheader, !llvm.loop !5

26:                                               ; preds = %24
  ret i32 0
}

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

attributes #0 = { nofree 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass