; LLVM IR from viveakrt/Competitive-programing :: CodeChef (MATCHES_Playing_With_Matches)

; 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.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @func() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  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 8, ptr %5) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %1, ptr noundef %2)
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = add nsw i64 %7, %8
  store i64 %9, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %65, %0
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp sgt i64 %11, 0
  br i1 %12, label %13, label %66

13:                                               ; preds = %10
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = srem i64 %14, 10
  store i64 %15, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = sdiv i64 %16, 10
  store i64 %17, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 1
  br i1 %19, label %20, label %23

20:                                               ; preds = %13
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = add nsw i64 %21, 2
  store i64 %22, ptr %4, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %20, %13
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = icmp eq i64 %24, 2
  br i1 %25, label %32, label %26

26:                                               ; preds = %23
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp eq i64 %27, 3
  br i1 %28, label %32, label %29

29:                                               ; preds = %26
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = icmp eq i64 %30, 5
  br i1 %31, label %32, label %35

32:                                               ; preds = %29, %26, %23
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = add nsw i64 %33, 5
  store i64 %34, ptr %4, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %32, %29
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %44, label %38

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

41:                                               ; preds = %38
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = icmp eq i64 %42, 9
  br i1 %43, label %44, label %47

44:                                               ; preds = %41, %38, %35
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = add nsw i64 %45, 6
  store i64 %46, ptr %4, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %44, %41
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = icmp eq i64 %48, 4
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = add nsw i64 %51, 4
  store i64 %52, ptr %4, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %50, %47
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = icmp eq i64 %54, 7
  br i1 %55, label %56, label %59

56:                                               ; preds = %53
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = add nsw i64 %57, 3
  store i64 %58, ptr %4, align 8, !tbaa !5
  br label %59

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

62:                                               ; preds = %59
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = add nsw i64 %63, 7
  store i64 %64, ptr %4, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %62, %59
  br label %10, !llvm.loop !9

66:                                               ; preds = %10
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @func() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = add nsw i64 %5, %4
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.029 = phi i64 [ %9, %.lr.ph ], [ %6, %0 ]
  %.02728 = phi i64 [ %.6, %.lr.ph ], [ 0, %0 ]
  %8 = urem i64 %.029, 10
  %9 = udiv i64 %.029, 10
  %10 = icmp eq i64 %8, 1
  %11 = add nsw i64 %.02728, 2
  %spec.select = select i1 %10, i64 %11, i64 %.02728
  %12 = and i64 %8, 14
  %or.cond = icmp eq i64 %12, 2
  %13 = icmp eq i64 %8, 5
  %or.cond3 = or i1 %13, %or.cond
  %14 = add nsw i64 %spec.select, 5
  %.2 = select i1 %or.cond3, i64 %14, i64 %spec.select
  %15 = icmp eq i64 %8, 0
  %16 = icmp eq i64 %8, 6
  %or.cond5 = or i1 %15, %16
  %17 = icmp eq i64 %8, 9
  %or.cond7 = or i1 %17, %or.cond5
  %18 = add nsw i64 %.2, 6
  %.3 = select i1 %or.cond7, i64 %18, i64 %.2
  %19 = icmp eq i64 %8, 4
  %20 = add nsw i64 %.3, 4
  %.4 = select i1 %19, i64 %20, i64 %.3
  %21 = icmp eq i64 %8, 7
  %22 = add nsw i64 %.4, 3
  %.5 = select i1 %21, i64 %22, i64 %.4
  %23 = icmp eq i64 %8, 8
  %24 = add nsw i64 %.5, 7
  %.6 = select i1 %23, i64 %24, i64 %.5
  %.not = icmp ult i64 %.029, 10
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.027.lcssa = phi i64 [ 0, %0 ], [ %.6, %.lr.ph ]
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.027.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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", !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: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass