; LLVM IR from DionysiosB/CodeForces :: 2085B-ServalAndFinalMEX (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 hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 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 i32, align 4
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %10

10:                                               ; preds = %72, %0
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = add nsw i64 %11, -1
  store i64 %12, ptr %2, align 8, !tbaa !5
  %13 = icmp ne i64 %11, 0
  br i1 %13, label %14, label %73

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %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
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, ptr %6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %36, %14
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = icmp sle i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 4, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %39

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  %23 = load i64, ptr %8, align 8, !tbaa !5
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 6, ptr %7, align 4
  br label %33

26:                                               ; preds = %21
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %31, label %29

29:                                               ; preds = %26
  %30 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %30, ptr %4, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %26
  %32 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %32, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %33

33:                                               ; preds = %31, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %34 = load i32, ptr %7, align 4
  switch i32 %34, label %75 [
    i32 0, label %35
    i32 6, label %36
  ]

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35, %33
  %37 = load i64, ptr %6, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %6, align 8, !tbaa !5
  br label %16, !llvm.loop !9

39:                                               ; preds = %20
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %43)
  br label %72

45:                                               ; preds = %39
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = icmp eq i64 %46, 1
  br i1 %47, label %48, label %55

48:                                               ; preds = %45
  %49 = load i64, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = icmp eq i64 %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %53)
  br label %71

55:                                               ; preds = %48, %45
  %56 = load i64, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = icmp ne i64 %56, %57
  br i1 %58, label %59, label %63

59:                                               ; preds = %55
  %60 = load i64, ptr %3, align 8, !tbaa !5
  %61 = sub nsw i64 %60, 1
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %61)
  br label %70

63:                                               ; preds = %55
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = icmp ne i64 %64, 1
  br i1 %65, label %66, label %69

66:                                               ; preds = %63
  %67 = load i64, ptr %3, align 8, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %67)
  br label %69

69:                                               ; preds = %66, %63
  br label %70

70:                                               ; preds = %69, %59
  br label %71

71:                                               ; preds = %70, %52
  br label %72

72:                                               ; preds = %71, %42
  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
  br label %10, !llvm.loop !11

73:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %74 = load i32, ptr %1, align 4
  ret i32 %74

75:                                               ; preds = %33
  unreachable
}

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 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
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = add nsw i64 %5, -1
  store i64 %6, ptr %1, align 8, !tbaa !5
  %.not29 = icmp eq i64 %5, 0
  br i1 %.not29, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %0, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %.not1723 = icmp slt i64 %8, 1
  br i1 %.not1723, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.not18 = icmp eq i64 %.1, 0
  br i1 %.not18, label %._crit_edge.thread, label %15

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %.026 = phi i64 [ %12, %.lr.ph ], [ 1, %.lr.ph31 ]
  %.01125 = phi i64 [ %.1, %.lr.ph ], [ 0, %.lr.ph31 ]
  %.01224 = phi i64 [ %.2, %.lr.ph ], [ 0, %.lr.ph31 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %.not21 = icmp eq i64 %10, 0
  %.not22 = icmp eq i64 %.01224, 0
  %11 = select i1 %.not21, i1 %.not22, i1 false
  %.2 = select i1 %11, i64 %.026, i64 %.01224
  %.1 = select i1 %.not21, i64 %.026, i64 %.01125
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %12 = add nuw nsw i64 %.026, 1
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %.not17.not = icmp slt i64 %.026, %13
  br i1 %.not17.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge.thread:                               ; preds = %.lr.ph31, %._crit_edge
  %.lcssa38 = phi i64 [ %13, %._crit_edge ], [ %8, %.lr.ph31 ]
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.lcssa38)
  br label %27

15:                                               ; preds = %._crit_edge
  %16 = icmp eq i64 %.2, 1
  %17 = icmp eq i64 %.1, %13
  %or.cond = and i1 %16, %17
  br i1 %or.cond, label %18, label %20

18:                                               ; preds = %15
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.1)
  br label %27

20:                                               ; preds = %15
  br i1 %17, label %24, label %21

21:                                               ; preds = %20
  %22 = add nsw i64 %13, -1
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %22)
  br label %27

24:                                               ; preds = %20
  br i1 %16, label %27, label %25

25:                                               ; preds = %24
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %.1)
  br label %27

27:                                               ; preds = %18, %24, %25, %21, %._crit_edge.thread
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = add nsw i64 %28, -1
  store i64 %29, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %28, 0
  br i1 %.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !11

._crit_edge32:                                    ; preds = %27, %0
  call void @llvm.lifetime.end.p0(i64 8, 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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 = !{!"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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass