; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1017B. The Bits (main)

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

@a = external dso_local global [100005 x i8], align 16
@b = external dso_local global [100005 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

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

9:                                                ; preds = %68, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %80

12:                                               ; preds = %9
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @a, ptr noundef @b)
  store i64 0, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %65, %12
  %15 = load i64, ptr %8, align 8, !tbaa !5
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %18, label %68

18:                                               ; preds = %14
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i64, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %22, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %18
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 48
  br i1 %33, label %34, label %37

34:                                               ; preds = %28
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %3, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %34, %28, %18
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 49
  br i1 %42, label %43, label %46

43:                                               ; preds = %37
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %5, align 8, !tbaa !5
  br label %49

46:                                               ; preds = %37
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %4, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %46, %43
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = icmp eq i32 %53, 49
  br i1 %54, label %55, label %64

55:                                               ; preds = %49
  %56 = load i64, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 48
  br i1 %60, label %61, label %64

61:                                               ; preds = %55
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %6, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %61, %55, %49
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %8, align 8, !tbaa !5
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %8, align 8, !tbaa !5
  br label %14, !llvm.loop !10

68:                                               ; preds = %14
  %69 = load i64, ptr %3, align 8, !tbaa !5
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = mul nsw i64 %69, %70
  %72 = load i64, ptr %4, align 8, !tbaa !5
  %73 = load i64, ptr %3, align 8, !tbaa !5
  %74 = sub nsw i64 %72, %73
  %75 = load i64, ptr %6, align 8, !tbaa !5
  %76 = mul nsw i64 %74, %75
  %77 = add nsw i64 %71, %76
  store i64 %77, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %7, align 8, !tbaa !5
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %78)
  br label %9, !llvm.loop !12

80:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  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
  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 @__isoc99_scanf(ptr noundef, ...) #2

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


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

@a = external dso_local global [100005 x i8], align 16
@b = external dso_local global [100005 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not35 = icmp eq i32 %2, -1
  br i1 %.not35, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %0, %._crit_edge
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph37
  %min.iters.check = icmp ult i64 %4, 4
  br i1 %min.iters.check, label %.lr.ph.preheader55, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %4, 9223372036854775804
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %vec.phi39 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %vec.phi40 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %36, %vector.body ]
  %vec.phi41 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %37, %vector.body ]
  %vec.phi42 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %vec.phi43 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %31, %vector.body ]
  %vec.phi44 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %vec.phi45 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %25, %vector.body ]
  %6 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %index
  %7 = getelementptr inbounds i8, ptr %6, i64 2
  %wide.load = load <2 x i8>, ptr %6, align 4, !tbaa !9
  %wide.load46 = load <2 x i8>, ptr %7, align 2, !tbaa !9
  %8 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 2
  %wide.load47 = load <2 x i8>, ptr %8, align 4, !tbaa !9
  %wide.load48 = load <2 x i8>, ptr %9, align 2, !tbaa !9
  %10 = icmp eq <2 x i8> %wide.load, <i8 48, i8 48>
  %11 = icmp eq <2 x i8> %wide.load46, <i8 48, i8 48>
  %12 = icmp eq <2 x i8> %wide.load47, <i8 48, i8 48>
  %13 = icmp eq <2 x i8> %wide.load48, <i8 48, i8 48>
  %14 = and <2 x i1> %10, %12
  %15 = and <2 x i1> %11, %13
  %16 = zext <2 x i1> %14 to <2 x i64>
  %17 = zext <2 x i1> %15 to <2 x i64>
  %18 = add <2 x i64> %vec.phi, %16
  %19 = add <2 x i64> %vec.phi39, %17
  %20 = icmp ne <2 x i8> %wide.load, <i8 49, i8 49>
  %21 = icmp ne <2 x i8> %wide.load46, <i8 49, i8 49>
  %22 = zext <2 x i1> %20 to <2 x i64>
  %23 = zext <2 x i1> %21 to <2 x i64>
  %24 = add <2 x i64> %vec.phi44, %22
  %25 = add <2 x i64> %vec.phi45, %23
  %26 = xor <2 x i1> %20, <i1 true, i1 true>
  %27 = xor <2 x i1> %21, <i1 true, i1 true>
  %28 = zext <2 x i1> %26 to <2 x i64>
  %29 = zext <2 x i1> %27 to <2 x i64>
  %30 = add <2 x i64> %vec.phi42, %28
  %31 = add <2 x i64> %vec.phi43, %29
  %32 = select <2 x i1> %26, <2 x i1> %12, <2 x i1> zeroinitializer
  %33 = select <2 x i1> %27, <2 x i1> %13, <2 x i1> zeroinitializer
  %34 = zext <2 x i1> %32 to <2 x i64>
  %35 = zext <2 x i1> %33 to <2 x i64>
  %36 = add <2 x i64> %vec.phi40, %34
  %37 = add <2 x i64> %vec.phi41, %35
  %index.next = add nuw i64 %index, 4
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %19, %18
  %39 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %bin.rdx49 = add <2 x i64> %37, %36
  %40 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx49)
  %bin.rdx50 = add <2 x i64> %31, %30
  %41 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx50)
  %bin.rdx51 = add <2 x i64> %25, %24
  %42 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx51)
  %cmp.n = icmp eq i64 %4, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader55

.lr.ph.preheader55:                               ; preds = %middle.block, %.lr.ph.preheader
  %.031.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.01830.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %39, %middle.block ]
  %.01929.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %40, %middle.block ]
  %.02128.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %41, %middle.block ]
  %.02327.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %42, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader55, %.lr.ph
  %.031 = phi i64 [ %53, %.lr.ph ], [ %.031.ph, %.lr.ph.preheader55 ]
  %.01830 = phi i64 [ %.1, %.lr.ph ], [ %.01830.ph, %.lr.ph.preheader55 ]
  %.01929 = phi i64 [ %.120, %.lr.ph ], [ %.01929.ph, %.lr.ph.preheader55 ]
  %.02128 = phi i64 [ %.122, %.lr.ph ], [ %.02128.ph, %.lr.ph.preheader55 ]
  %.02327 = phi i64 [ %.124, %.lr.ph ], [ %.02327.ph, %.lr.ph.preheader55 ]
  %43 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %.031
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %.031
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = icmp eq i8 %44, 48
  %48 = icmp eq i8 %46, 48
  %or.cond = and i1 %47, %48
  %49 = zext i1 %or.cond to i64
  %.1 = add nuw nsw i64 %.01830, %49
  %50 = icmp ne i8 %44, 49
  %51 = zext i1 %50 to i64
  %.124 = add nuw nsw i64 %.02327, %51
  %not. = xor i1 %50, true
  %52 = zext i1 %not. to i64
  %.122 = add nuw nsw i64 %.02128, %52
  %narrow = select i1 %not., i1 %48, i1 false
  %spec.select = zext i1 %narrow to i64
  %.120 = add nuw nsw i64 %.01929, %spec.select
  %53 = add nuw nsw i64 %.031, 1
  %exitcond.not = icmp eq i64 %53, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.lr.ph37
  %.023.lcssa = phi i64 [ 0, %.lr.ph37 ], [ %42, %middle.block ], [ %.124, %.lr.ph ]
  %.021.lcssa = phi i64 [ 0, %.lr.ph37 ], [ %41, %middle.block ], [ %.122, %.lr.ph ]
  %.019.lcssa = phi i64 [ 0, %.lr.ph37 ], [ %40, %middle.block ], [ %.120, %.lr.ph ]
  %.018.lcssa = phi i64 [ 0, %.lr.ph37 ], [ %39, %middle.block ], [ %.1, %.lr.ph ]
  %54 = mul nsw i64 %.018.lcssa, %.021.lcssa
  %55 = sub nsw i64 %.023.lcssa, %.018.lcssa
  %56 = mul nsw i64 %55, %.019.lcssa
  %57 = add nsw i64 %56, %54
  %58 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %57)
  %59 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %59, -1
  br i1 %.not, label %._crit_edge38, label %.lr.ph37, !llvm.loop !15

._crit_edge38:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 8, 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 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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 i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !13, !12}
!15 = distinct !{!15, !11}


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