; LLVM IR from xirc/cp-algorithm :: codeforces/1433/1433A/main.ll (Z5solvei)

; 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: mustprogress uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) #0 {
  %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
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %38, %1
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 10
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %6, align 4
  br label %41

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %14, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %27, %13
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 10000
  br i1 %17, label %18, label %34

18:                                               ; preds = %15
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = add nsw i32 %20, %19
  store i32 %21, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %26, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %35

27:                                               ; preds = %18
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = mul nsw i32 %28, 10
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  store i32 %31, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %8, align 4, !tbaa !5
  br label %15, !llvm.loop !9

34:                                               ; preds = %15
  store i32 0, ptr %6, align 4
  br label %35

35:                                               ; preds = %34, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %36 = load i32, ptr %6, align 4
  switch i32 %36, label %41 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !5
  br label %9, !llvm.loop !11

41:                                               ; preds = %35, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %42 = load i32, ptr %6, align 4
  switch i32 %42, label %44 [
    i32 2, label %43
  ]

43:                                               ; preds = %41
  call void @__cxa_rethrow() #3
  unreachable

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %45 = load i32, ptr %2, align 4
  ret i32 %45
}

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

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

declare void @__cxa_rethrow()

attributes #0 = { mustprogress 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 = { nounwind }
attributes #3 = { noreturn }

!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}
!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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) local_unnamed_addr #0 {
.preheader:
  switch i32 %0, label %.thread28 [
    i32 1, label %.loopexit
    i32 11, label %.loopexit.fold.split
    i32 111, label %.loopexit.fold.split53
    i32 1111, label %.loopexit.fold.split54
    i32 2, label %.loopexit.fold.split55
    i32 22, label %.loopexit.fold.split56
    i32 222, label %.loopexit.fold.split57
    i32 2222, label %.loopexit.fold.split58
    i32 3, label %.loopexit.fold.split59
    i32 33, label %.loopexit.fold.split60
    i32 333, label %.loopexit.fold.split61
    i32 3333, label %.loopexit.fold.split62
    i32 4, label %.loopexit.fold.split63
    i32 44, label %.loopexit.fold.split64
    i32 444, label %.loopexit.fold.split65
    i32 4444, label %.loopexit.fold.split66
    i32 5, label %.loopexit.fold.split67
    i32 55, label %.loopexit.fold.split68
    i32 555, label %.loopexit.fold.split69
    i32 5555, label %.loopexit.fold.split70
    i32 6, label %.loopexit.fold.split71
    i32 66, label %.loopexit.fold.split72
    i32 666, label %.loopexit.fold.split73
    i32 6666, label %.loopexit.fold.split74
    i32 7, label %.loopexit.fold.split75
    i32 77, label %.loopexit.fold.split76
    i32 777, label %.loopexit.fold.split77
    i32 7777, label %.loopexit.fold.split78
    i32 8, label %.loopexit.fold.split79
    i32 88, label %.loopexit.fold.split80
    i32 888, label %.loopexit.fold.split81
    i32 8888, label %.loopexit.fold.split82
    i32 9, label %.loopexit.fold.split83
    i32 99, label %.loopexit.fold.split84
    i32 999, label %.loopexit.fold.split85
    i32 9999, label %.loopexit.fold.split86
  ]

.thread28:                                        ; preds = %.preheader
  tail call void @__cxa_rethrow() #1
  unreachable

.loopexit.fold.split:                             ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split53:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split54:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split55:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split56:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split57:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split58:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split59:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split60:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split61:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split62:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split63:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split64:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split65:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split66:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split67:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split68:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split69:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split70:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split71:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split72:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split73:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split74:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split75:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split76:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split77:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split78:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split79:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split80:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split81:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split82:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split83:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split84:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split85:                           ; preds = %.preheader
  br label %.loopexit

.loopexit.fold.split86:                           ; preds = %.preheader
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.fold.split86, %.loopexit.fold.split85, %.loopexit.fold.split84, %.loopexit.fold.split83, %.loopexit.fold.split82, %.loopexit.fold.split81, %.loopexit.fold.split80, %.loopexit.fold.split79, %.loopexit.fold.split78, %.loopexit.fold.split77, %.loopexit.fold.split76, %.loopexit.fold.split75, %.loopexit.fold.split74, %.loopexit.fold.split73, %.loopexit.fold.split72, %.loopexit.fold.split71, %.loopexit.fold.split70, %.loopexit.fold.split69, %.loopexit.fold.split68, %.loopexit.fold.split67, %.loopexit.fold.split66, %.loopexit.fold.split65, %.loopexit.fold.split64, %.loopexit.fold.split63, %.loopexit.fold.split62, %.loopexit.fold.split61, %.loopexit.fold.split60, %.loopexit.fold.split59, %.loopexit.fold.split58, %.loopexit.fold.split57, %.loopexit.fold.split56, %.loopexit.fold.split55, %.loopexit.fold.split54, %.loopexit.fold.split53, %.loopexit.fold.split
  %.lcssa = phi i32 [ %0, %.preheader ], [ 3, %.loopexit.fold.split ], [ 6, %.loopexit.fold.split53 ], [ 10, %.loopexit.fold.split54 ], [ 11, %.loopexit.fold.split55 ], [ 13, %.loopexit.fold.split56 ], [ 16, %.loopexit.fold.split57 ], [ 20, %.loopexit.fold.split58 ], [ 21, %.loopexit.fold.split59 ], [ 23, %.loopexit.fold.split60 ], [ 26, %.loopexit.fold.split61 ], [ 30, %.loopexit.fold.split62 ], [ 31, %.loopexit.fold.split63 ], [ 33, %.loopexit.fold.split64 ], [ 36, %.loopexit.fold.split65 ], [ 40, %.loopexit.fold.split66 ], [ 41, %.loopexit.fold.split67 ], [ 43, %.loopexit.fold.split68 ], [ 46, %.loopexit.fold.split69 ], [ 50, %.loopexit.fold.split70 ], [ 51, %.loopexit.fold.split71 ], [ 53, %.loopexit.fold.split72 ], [ 56, %.loopexit.fold.split73 ], [ 60, %.loopexit.fold.split74 ], [ 61, %.loopexit.fold.split75 ], [ 63, %.loopexit.fold.split76 ], [ 66, %.loopexit.fold.split77 ], [ 70, %.loopexit.fold.split78 ], [ 71, %.loopexit.fold.split79 ], [ 73, %.loopexit.fold.split80 ], [ 76, %.loopexit.fold.split81 ], [ 80, %.loopexit.fold.split82 ], [ 81, %.loopexit.fold.split83 ], [ 83, %.loopexit.fold.split84 ], [ 86, %.loopexit.fold.split85 ], [ 90, %.loopexit.fold.split86 ]
  ret i32 %.lcssa
}

declare void @__cxa_rethrow() local_unnamed_addr

attributes #0 = { mustprogress 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 = { noreturn }

!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)"}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass