; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Numbers/Basic_Programs (strong_num)

; 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 [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [27 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %11 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %11, ptr %7, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %28, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %34

15:                                               ; preds = %12
  store i32 1, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = srem i32 %16, 10
  store i32 %17, ptr %5, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %22, %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = mul nsw i32 %23, %24
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !5
  br label %18, !llvm.loop !9

28:                                               ; preds = %18
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  store i32 %31, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sdiv i32 %32, 10
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !11

34:                                               ; preds = %12
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %39)
  br label %44

41:                                               ; preds = %34
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %42)
  br label %44

44:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  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

declare i32 @__isoc99_scanf(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 [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %.not19 = icmp eq i32 %5, 0
  br i1 %.not19, label %12, label %.lr.ph22

.lr.ph22:                                         ; preds = %0, %._crit_edge
  %.01120 = phi i32 [ %11, %._crit_edge ], [ 0, %0 ]
  %6 = phi i32 [ %8, %._crit_edge ], [ %5, %0 ]
  %7 = srem i32 %6, 10
  %8 = sdiv i32 %6, 10
  %.not1516 = icmp slt i32 %7, 1
  br i1 %.not1516, label %._crit_edge, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph22
  %n.rnd.up = add nuw nsw i32 %7, 3
  %n.vec = and i32 %n.rnd.up, 2147483644
  %trip.count.minus.1 = add nsw i32 %7, -1
  %broadcast.splatinsert31 = insertelement <4 x i32> poison, i32 %trip.count.minus.1, i64 0
  %broadcast.splat32 = shufflevector <4 x i32> %broadcast.splatinsert31, <4 x i32> poison, <4 x i32> zeroinitializer
  switch i32 %n.vec, label %vector.body.3 [
    i32 4, label %middle.block
    i32 8, label %middle.block.fold.split
    i32 12, label %middle.block.fold.split38
  ]

vector.body.3:                                    ; preds = %vector.ph
  br label %middle.block

middle.block.fold.split:                          ; preds = %vector.ph
  br label %middle.block

middle.block.fold.split38:                        ; preds = %vector.ph
  br label %middle.block

middle.block:                                     ; preds = %vector.ph, %middle.block.fold.split38, %middle.block.fold.split, %vector.body.3
  %index.lcssa = phi i32 [ 0, %vector.ph ], [ 12, %vector.body.3 ], [ 4, %middle.block.fold.split ], [ 8, %middle.block.fold.split38 ]
  %vec.phi.lcssa = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %vector.ph ], [ <i32 45, i32 120, i32 231, i32 384>, %vector.body.3 ], [ <i32 1, i32 2, i32 3, i32 4>, %middle.block.fold.split ], [ <i32 5, i32 12, i32 21, i32 32>, %middle.block.fold.split38 ]
  %.lcssa = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ <i32 585, i32 1680, i32 3465, i32 6144>, %vector.body.3 ], [ <i32 5, i32 12, i32 21, i32 32>, %middle.block.fold.split ], [ <i32 45, i32 120, i32 231, i32 384>, %middle.block.fold.split38 ]
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %index.lcssa, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %vec.iv = or disjoint <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3>
  %.not33 = icmp ugt <4 x i32> %vec.iv, %broadcast.splat32
  %9 = select <4 x i1> %.not33, <4 x i32> %vec.phi.lcssa, <4 x i32> %.lcssa
  %10 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %9)
  br label %._crit_edge

._crit_edge:                                      ; preds = %middle.block, %.lr.ph22
  %.012.lcssa = phi i32 [ 1, %.lr.ph22 ], [ %10, %middle.block ]
  %11 = add nuw nsw i32 %.012.lcssa, %.01120
  %.off = add i32 %6, 9
  %.not = icmp ult i32 %.off, 19
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !9

._crit_edge23:                                    ; preds = %._crit_edge
  store i32 %8, ptr %1, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %._crit_edge23, %0
  %.011.lcssa = phi i32 [ %11, %._crit_edge23 ], [ 0, %0 ]
  %13 = icmp eq i32 %.011.lcssa, %5
  %.str.3..str.4 = select i1 %13, ptr @.str.3, ptr @.str.4
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.3..str.4, i32 noundef %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32>) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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"}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass