; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 978B. File Name (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"

@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = 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
  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
  br label %5

5:                                                ; preds = %44, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef @str)
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %47

8:                                                ; preds = %5
  store i32 0, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %41, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 2
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %44

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 120
  br i1 %20, label %21, label %40

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 120
  br i1 %28, label %29, label %40

29:                                               ; preds = %21
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 2
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 120
  br i1 %36, label %37, label %40

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

40:                                               ; preds = %37, %29, %21, %14
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !10

44:                                               ; preds = %9
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %45)
  br label %5, !llvm.loop !12

47:                                               ; preds = %5
  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 @__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 = !{!"int", !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"

@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = 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 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @str)
  %.not10 = icmp eq i32 %2, -1
  br i1 %.not10, label %._crit_edge11, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 2
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %5 = add nsw i32 %3, -2
  %wide.trip.count = zext i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph._crit_edge.1, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %24, %.lr.ph._crit_edge.1 ]
  %.09 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph._crit_edge.1 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph._crit_edge.1 ]
  %7 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv
  %8 = load i8, ptr %7, align 2, !tbaa !9
  %9 = icmp eq i8 %8, 120
  %10 = or disjoint i64 %indvars.iv, 1
  br i1 %9, label %11, label %.lr.ph._crit_edge

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %10
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp eq i8 %13, 120
  br i1 %14, label %15, label %.lr.ph._crit_edge

15:                                               ; preds = %11
  %16 = add nuw nsw i64 %indvars.iv, 2
  %17 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %16
  %18 = load i8, ptr %17, align 2, !tbaa !9
  %19 = icmp eq i8 %18, 120
  %20 = zext i1 %19 to i32
  %spec.select = add nsw i32 %.09, %20
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %15, %11
  %.1 = phi i32 [ %spec.select, %15 ], [ %.09, %11 ], [ %.09, %.lr.ph ]
  %21 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %10
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = icmp eq i8 %22, 120
  %24 = add nuw nsw i64 %indvars.iv, 2
  br i1 %23, label %25, label %.lr.ph._crit_edge.1

25:                                               ; preds = %.lr.ph._crit_edge
  %26 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %24
  %27 = load i8, ptr %26, align 2, !tbaa !9
  %28 = icmp eq i8 %27, 120
  br i1 %28, label %29, label %.lr.ph._crit_edge.1

29:                                               ; preds = %25
  %30 = add nuw nsw i64 %indvars.iv, 3
  %31 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = icmp eq i8 %32, 120
  %34 = zext i1 %33 to i32
  %spec.select.1 = add nsw i32 %.1, %34
  br label %.lr.ph._crit_edge.1

.lr.ph._crit_edge.1:                              ; preds = %29, %25, %.lr.ph._crit_edge
  %.1.1 = phi i32 [ %spec.select.1, %29 ], [ %.1, %25 ], [ %.1, %.lr.ph._crit_edge ]
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !10

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph._crit_edge.1, %.lr.ph.preheader
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.1.1, %.lr.ph._crit_edge.1 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %24, %.lr.ph._crit_edge.1 ]
  %.09.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %.1.1, %.lr.ph._crit_edge.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %35 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv.unr
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = icmp eq i8 %36, 120
  br i1 %37, label %38, label %._crit_edge

38:                                               ; preds = %.lr.ph.epil
  %39 = add nuw nsw i64 %indvars.iv.unr, 1
  %40 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = icmp eq i8 %41, 120
  br i1 %42, label %43, label %._crit_edge

43:                                               ; preds = %38
  %44 = add nuw nsw i64 %indvars.iv.unr, 2
  %45 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = icmp eq i8 %46, 120
  %48 = zext i1 %47 to i32
  %spec.select.epil = add nsw i32 %.09.unr, %48
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %43, %38, %.lr.ph.epil, %.preheader
  %.0.lcssa = phi i32 [ 0, %.preheader ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %43 ], [ %.09.unr, %38 ], [ %.09.unr, %.lr.ph.epil ]
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.0.lcssa)
  %50 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @str)
  %.not = icmp eq i32 %50, -1
  br i1 %.not, label %._crit_edge11, label %.preheader, !llvm.loop !12

._crit_edge11:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  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

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 = { 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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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