; LLVM IR from DionysiosB/CodeForces :: 1300-1399 (1395B-BoboniuPlaysChess)

; 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 [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 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
  %9 = 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
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %73, %0
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = icmp sle i64 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = srem i64 %17, 2
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %46

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 1, ptr %8, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %42, %20
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = icmp sle i64 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load i64, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = add nsw i64 %27, %28
  %30 = sub nsw i64 %29, 2
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = srem i64 %30, %31
  %33 = add nsw i64 1, %32
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = add nsw i64 %34, %35
  %37 = sub nsw i64 %36, 2
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = srem i64 %37, %38
  %40 = add nsw i64 1, %39
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %33, i64 noundef %40)
  br label %42

42:                                               ; preds = %26
  %43 = load i64, ptr %8, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %8, align 8, !tbaa !5
  br label %21, !llvm.loop !9

45:                                               ; preds = %25
  br label %72

46:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %47 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %47, ptr %9, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %68, %46
  %49 = load i64, ptr %9, align 8, !tbaa !5
  %50 = icmp sge i64 %49, 1
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %71

52:                                               ; preds = %48
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = add nsw i64 %53, %54
  %56 = sub nsw i64 %55, 2
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = srem i64 %56, %57
  %59 = add nsw i64 1, %58
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = load i64, ptr %5, align 8, !tbaa !5
  %62 = add nsw i64 %60, %61
  %63 = sub nsw i64 %62, 2
  %64 = load i64, ptr %3, align 8, !tbaa !5
  %65 = srem i64 %63, %64
  %66 = add nsw i64 1, %65
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %59, i64 noundef %66)
  br label %68

68:                                               ; preds = %52
  %69 = load i64, ptr %9, align 8, !tbaa !5
  %70 = add nsw i64 %69, -1
  store i64 %70, ptr %9, align 8, !tbaa !5
  br label %48, !llvm.loop !11

71:                                               ; preds = %51
  br label %72

72:                                               ; preds = %71, %45
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %6, align 8, !tbaa !5
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !12

76:                                               ; preds = %15
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  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
  %77 = load i32, ptr %1, align 4
  ret i32 %77
}

; 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", !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}
!12 = distinct !{!12, !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 [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 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
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %.not22 = icmp slt i64 %6, 1
  br i1 %.not22, label %._crit_edge, label %.lr.ph25

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0

.lr.ph25:                                         ; preds = %0, %.loopexit
  %.01323 = phi i64 [ %43, %.loopexit ], [ 1, %0 ]
  %7 = and i64 %.01323, 1
  %.not15 = icmp eq i64 %7, 0
  %8 = load i64, ptr %2, align 8, !tbaa !5
  br i1 %.not15, label %25, label %.preheader

.preheader:                                       ; preds = %.lr.ph25
  %.not1618 = icmp slt i64 %8, 1
  br i1 %.not1618, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = add nsw i64 %.01323, -2
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %11 = phi i64 [ %8, %.lr.ph ], [ %24, %10 ]
  %.01219 = phi i64 [ 1, %.lr.ph ], [ %23, %10 ]
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = add i64 %9, %12
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %15 = srem i64 %13, %14
  %16 = add nsw i64 %15, 1
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = add nsw i64 %.01219, -2
  %19 = add i64 %18, %17
  %20 = srem i64 %19, %11
  %21 = add nsw i64 %20, 1
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %16, i64 noundef %21)
  %23 = add nuw nsw i64 %.01219, 1
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %.not16.not = icmp slt i64 %.01219, %24
  br i1 %.not16.not, label %10, label %.loopexit, !llvm.loop !9

25:                                               ; preds = %.lr.ph25
  %26 = icmp sgt i64 %8, 0
  br i1 %26, label %.lr.ph21, label %.loopexit

.lr.ph21:                                         ; preds = %25
  %27 = add nsw i64 %.01323, -2
  br label %28

28:                                               ; preds = %.lr.ph21, %28
  %.020 = phi i64 [ %8, %.lr.ph21 ], [ %41, %28 ]
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = add i64 %27, %29
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = srem i64 %30, %31
  %33 = add nsw i64 %32, 1
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = add nsw i64 %.020, -2
  %36 = add i64 %35, %34
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = srem i64 %36, %37
  %39 = add nsw i64 %38, 1
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %33, i64 noundef %39)
  %41 = add nsw i64 %.020, -1
  %42 = icmp ugt i64 %.020, 1
  br i1 %42, label %28, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %10, %28, %.preheader, %25
  %43 = add nuw nsw i64 %.01323, 1
  %44 = load i64, ptr %1, align 8, !tbaa !5
  %.not.not = icmp slt i64 %.01323, %44
  br i1 %.not.not, label %.lr.ph25, label %._crit_edge, !llvm.loop !12
}

; 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 = !{!"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}
!12 = distinct !{!12, !10}


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