; LLVM IR from tangjz/acm-icpc :: codeforces/complete (908A)

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

@pat = external dso_local global ptr, align 8
@ans = external dso_local global i32, align 4
@buf = external dso_local global [51 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

6:                                                ; preds = %67, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %70

13:                                               ; preds = %6
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp sge i32 %18, 48
  br i1 %19, label %20, label %37

20:                                               ; preds = %13
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = icmp sle i32 %25, 57
  br i1 %26, label %27, label %37

27:                                               ; preds = %20
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = sub nsw i32 %32, 48
  %34 = and i32 %33, 1
  %35 = load i32, ptr @ans, align 4, !tbaa !5
  %36 = add nsw i32 %35, %34
  store i32 %36, ptr @ans, align 4, !tbaa !5
  br label %66

37:                                               ; preds = %20, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %62, %37
  %39 = load ptr, ptr @pat, align 8, !tbaa !10
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %65

46:                                               ; preds = %38
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = sext i8 %50 to i32
  %52 = load ptr, ptr @pat, align 8, !tbaa !10
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = icmp eq i32 %51, %57
  %59 = zext i1 %58 to i32
  %60 = load i32, ptr @ans, align 4, !tbaa !5
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr @ans, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %46
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !12

65:                                               ; preds = %45
  br label %66

66:                                               ; preds = %65, %27
  br label %67

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

70:                                               ; preds = %12
  %71 = load i32, ptr @ans, align 4, !tbaa !5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %71)
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@pat = external dso_local local_unnamed_addr global ptr, align 8
@ans = external dso_local local_unnamed_addr global i32, align 4
@buf = external dso_local global [51 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @buf)
  %2 = load i8, ptr @buf, align 16, !tbaa !5
  %.not20 = icmp eq i8 %2, 0
  %.pre = load i32, ptr @ans, align 4, !tbaa !8
  br i1 %.not20, label %._crit_edge, label %.lr.ph23

.lr.ph23:                                         ; preds = %0
  %3 = load ptr, ptr @pat, align 8
  br label %6

._crit_edge:                                      ; preds = %.loopexit, %0
  %4 = phi i32 [ %.pre, %0 ], [ %ans.promoted17, %.loopexit ]
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %4)
  ret i32 0

6:                                                ; preds = %.lr.ph23, %.loopexit
  %indvars.iv24 = phi i64 [ 0, %.lr.ph23 ], [ %indvars.iv.next25, %.loopexit ]
  %7 = phi i8 [ %2, %.lr.ph23 ], [ %22, %.loopexit ]
  %ans.promoted1921 = phi i32 [ %.pre, %.lr.ph23 ], [ %ans.promoted17, %.loopexit ]
  %8 = add i8 %7, -48
  %or.cond = icmp ult i8 %8, 10
  br i1 %or.cond, label %10, label %.preheader

.preheader:                                       ; preds = %6
  %9 = load i8, ptr %3, align 1, !tbaa !5
  %.not1314 = icmp eq i8 %9, 0
  br i1 %.not1314, label %.loopexit, label %.lr.ph

10:                                               ; preds = %6
  %11 = and i8 %7, 1
  %12 = zext nneg i8 %11 to i32
  %13 = add nsw i32 %ans.promoted1921, %12
  store i32 %13, ptr @ans, align 4, !tbaa !8
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %14 = phi i8 [ %20, %.lr.ph ], [ %9, %.preheader ]
  %15 = phi i32 [ %18, %.lr.ph ], [ %ans.promoted1921, %.preheader ]
  %16 = icmp eq i8 %7, %14
  %17 = zext i1 %16 to i32
  %18 = add nsw i32 %15, %17
  store i32 %18, ptr @ans, align 4, !tbaa !8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv.next
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %.not13 = icmp eq i8 %20, 0
  br i1 %.not13, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %10
  %ans.promoted17 = phi i32 [ %13, %10 ], [ %ans.promoted1921, %.preheader ], [ %18, %.lr.ph ]
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %21 = getelementptr inbounds [51 x i8], ptr @buf, i64 0, i64 %indvars.iv.next25
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !12
}

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

; 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass