; LLVM IR from DionysiosB/CodeForces :: 0300-0399 (362B-PetyaAndStairCases)

; 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 hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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 ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 0, ptr %3, align 8, !tbaa !5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %11, i64 8)
  %13 = extractvalue { i64, i1 } %12, 1
  %14 = extractvalue { i64, i1 } %12, 0
  %15 = select i1 %13, i64 -1, i64 %14
  %16 = call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #7
  store ptr %16, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #6
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %36, %0
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  br label %39

22:                                               ; preds = %17
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds i64, ptr %25, i64 %26
  store i64 %24, ptr %27, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = icmp eq i64 %28, 1
  br i1 %29, label %34, label %30

30:                                               ; preds = %22
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = icmp eq i64 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %22
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 2, ptr %8, align 4
  br label %39

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %7, align 8, !tbaa !5
  br label %17, !llvm.loop !13

39:                                               ; preds = %34, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds i64, ptr %42, i64 %43
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef %41, ptr noundef %44)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %77, %40
  %46 = load i64, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = sub nsw i64 %47, 2
  %49 = icmp slt i64 %46, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  store i32 5, ptr %8, align 4
  br label %80

51:                                               ; preds = %45
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = load i64, ptr %9, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds i64, ptr %57, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !5
  %61 = add nsw i64 %60, 1
  %62 = icmp eq i64 %56, %61
  br i1 %62, label %63, label %76

63:                                               ; preds = %51
  %64 = load ptr, ptr %4, align 8, !tbaa !9
  %65 = load i64, ptr %9, align 8, !tbaa !5
  %66 = add nsw i64 %65, 2
  %67 = getelementptr inbounds i64, ptr %64, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = getelementptr inbounds i64, ptr %69, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !5
  %73 = add nsw i64 %72, 2
  %74 = icmp eq i64 %68, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %63
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 5, ptr %8, align 4
  br label %80

76:                                               ; preds = %63, %51
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %9, align 8, !tbaa !5
  %79 = add nsw i64 %78, 1
  store i64 %79, ptr %9, align 8, !tbaa !5
  br label %45, !llvm.loop !15

80:                                               ; preds = %75, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %83 = trunc i8 %82 to i1
  br i1 %83, label %84, label %86

84:                                               ; preds = %81
  %85 = call i32 @puts(ptr noundef @.str.2)
  br label %88

86:                                               ; preds = %81
  %87 = call i32 @puts(ptr noundef @.str.3)
  br label %88

88:                                               ; preds = %86, %84
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  %89 = load i32, ptr %1, align 4
  ret i32 %89
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) #5

declare i32 @puts(ptr noundef) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{i8 0, i8 2}
!17 = !{}


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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i64 0, ptr %2, align 8, !tbaa !5
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = icmp ugt i64 %5, 2305843009213693951
  %7 = shl i64 %5, 3
  %8 = select i1 %6, i64 -1, i64 %7
  %9 = call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  %.not21 = icmp sgt i64 %5, 0
  br i1 %.not21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01722 = phi i64 [ %16, %.lr.ph ], [ 0, %0 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds i64, ptr %9, i64 %.01722
  store i64 %11, ptr %12, align 8, !tbaa !5
  %13 = icmp eq i64 %11, 1
  %14 = load i64, ptr %1, align 8
  %15 = icmp eq i64 %11, %14
  %or.cond = select i1 %13, i1 true, i1 %15
  %.pre.pre = load i64, ptr %2, align 8, !tbaa !5
  %16 = add nuw nsw i64 %.01722, 1
  %.not = icmp sge i64 %16, %.pre.pre
  %or.cond31.not = select i1 %or.cond, i1 true, i1 %.not
  br i1 %or.cond31.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %17 = phi i64 [ %5, %0 ], [ %.pre.pre, %.lr.ph ]
  %.not.lcssa = phi i1 [ false, %0 ], [ %or.cond, %.lr.ph ]
  %18 = getelementptr inbounds i64, ptr %9, i64 %17
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef nonnull %9, ptr noundef nonnull %18)
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = icmp sgt i64 %19, 2
  br i1 %20, label %.lr.ph28.preheader, label %._crit_edge29

.lr.ph28.preheader:                               ; preds = %._crit_edge
  %.pre30 = load i64, ptr %9, align 8, !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %9, i64 16
  %21 = add nsw i64 %19, -3
  br label %.lr.ph28

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %32
  %22 = phi i64 [ %25, %32 ], [ %.pre30, %.lr.ph28.preheader ]
  %.026 = phi i64 [ %23, %32 ], [ 0, %.lr.ph28.preheader ]
  %23 = add nuw nsw i64 %.026, 1
  %24 = getelementptr inbounds i64, ptr %9, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = add nsw i64 %22, 1
  %27 = icmp eq i64 %25, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %.lr.ph28
  %gep = getelementptr inbounds i64, ptr %invariant.gep, i64 %.026
  %29 = load i64, ptr %gep, align 8, !tbaa !5
  %30 = add nsw i64 %22, 2
  %31 = icmp eq i64 %29, %30
  br i1 %31, label %.critedge, label %32

32:                                               ; preds = %.lr.ph28, %28
  %exitcond.not = icmp eq i64 %.026, %21
  br i1 %exitcond.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !11

._crit_edge29:                                    ; preds = %32, %._crit_edge
  br i1 %.not.lcssa, label %.critedge, label %33

.critedge:                                        ; preds = %28, %._crit_edge29
  br label %33

33:                                               ; preds = %._crit_edge29, %.critedge
  %.str.3.sink = phi ptr [ @.str.3, %.critedge ], [ @.str.2, %._crit_edge29 ]
  %34 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.3.sink)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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 = { 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 = { nobuiltin allocsize(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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

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


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