; LLVM IR from DionysiosB/CodeForces :: 1786A2-AlternatingDeckHardVersion (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 [17 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
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %15

15:                                               ; preds = %82, %0
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = add nsw i64 %16, -1
  store i64 %17, ptr %2, align 8, !tbaa !5
  %18 = icmp ne i64 %16, 0
  br i1 %18, label %19, label %88

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

22:                                               ; preds = %79, %19
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load i64, ptr %10, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = icmp sle i64 %26, %27
  br label %29

29:                                               ; preds = %25, %22
  %30 = phi i1 [ false, %22 ], [ %28, %25 ]
  br i1 %30, label %32, label %31

31:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %82

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %10, align 8, !tbaa !5
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = load i64, ptr %4, align 8, !tbaa !5
  br label %40

38:                                               ; preds = %32
  %39 = load i64, ptr %10, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %38, %36
  %41 = phi i64 [ %37, %36 ], [ %39, %38 ]
  store i64 %41, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %42 = load i64, ptr %11, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !5
  %44 = add nsw i64 %42, %43
  %45 = sdiv i64 %44, 2
  store i64 %45, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %46 = load i64, ptr %11, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !5
  %48 = sub nsw i64 1, %47
  %49 = add nsw i64 %46, %48
  %50 = sdiv i64 %49, 2
  store i64 %50, ptr %13, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !5
  %52 = srem i64 %51, 2
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %57

54:                                               ; preds = %40
  %55 = load i64, ptr %9, align 8, !tbaa !5
  %56 = sub nsw i64 1, %55
  store i64 %56, ptr %9, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %54, %40
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = srem i64 %58, 4
  %60 = icmp sle i64 %59, 1
  br i1 %60, label %61, label %68

61:                                               ; preds = %57
  %62 = load i64, ptr %12, align 8, !tbaa !5
  %63 = load i64, ptr %5, align 8, !tbaa !5
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr %5, align 8, !tbaa !5
  %65 = load i64, ptr %13, align 8, !tbaa !5
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = add nsw i64 %66, %65
  store i64 %67, ptr %6, align 8, !tbaa !5
  br label %75

68:                                               ; preds = %57
  %69 = load i64, ptr %12, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !5
  %71 = add nsw i64 %70, %69
  store i64 %71, ptr %7, align 8, !tbaa !5
  %72 = load i64, ptr %13, align 8, !tbaa !5
  %73 = load i64, ptr %8, align 8, !tbaa !5
  %74 = add nsw i64 %73, %72
  store i64 %74, ptr %8, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %68, %61
  %76 = load i64, ptr %11, align 8, !tbaa !5
  %77 = load i64, ptr %4, align 8, !tbaa !5
  %78 = sub nsw i64 %77, %76
  store i64 %78, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %79

79:                                               ; preds = %75
  %80 = load i64, ptr %10, align 8, !tbaa !5
  %81 = add nsw i64 %80, 1
  store i64 %81, ptr %10, align 8, !tbaa !5
  br label %22, !llvm.loop !9

82:                                               ; preds = %31
  %83 = load i64, ptr %5, align 8, !tbaa !5
  %84 = load i64, ptr %6, align 8, !tbaa !5
  %85 = load i64, ptr %7, align 8, !tbaa !5
  %86 = load i64, ptr %8, align 8, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %83, i64 noundef %84, i64 noundef %85, i64 noundef %86)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  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
  br label %15, !llvm.loop !11

88:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %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 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 [17 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = add nsw i64 %4, -1
  store i64 %5, ptr %1, align 8, !tbaa !5
  %.not51 = icmp eq i64 %4, 0
  br i1 %.not51, label %._crit_edge54, label %.lr.ph53

.lr.ph53:                                         ; preds = %0, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %7 = load i64, ptr %2, align 8
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %26, %.lr.ph53
  %.037.lcssa = phi i64 [ 0, %.lr.ph53 ], [ %.138, %26 ]
  %.035.lcssa = phi i64 [ 0, %.lr.ph53 ], [ %.136, %26 ]
  %.030.lcssa = phi i64 [ 0, %.lr.ph53 ], [ %.131, %26 ]
  %.029.lcssa = phi i64 [ 0, %.lr.ph53 ], [ %.1, %26 ]
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.029.lcssa, i64 noundef %.030.lcssa, i64 noundef %.037.lcssa, i64 noundef %.035.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = add nsw i64 %10, -1
  store i64 %11, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge54, label %.lr.ph53, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph53, %26
  %.047 = phi i64 [ %27, %26 ], [ %7, %.lr.ph53 ]
  %.02946 = phi i64 [ %.1, %26 ], [ 0, %.lr.ph53 ]
  %.03045 = phi i64 [ %.131, %26 ], [ 0, %.lr.ph53 ]
  %.03244 = phi i64 [ %28, %26 ], [ 1, %.lr.ph53 ]
  %.03343 = phi i64 [ %spec.select, %26 ], [ 1, %.lr.ph53 ]
  %.03542 = phi i64 [ %.136, %26 ], [ 0, %.lr.ph53 ]
  %.03741 = phi i64 [ %.138, %26 ], [ 0, %.lr.ph53 ]
  %12 = call i64 @llvm.smin.i64(i64 %.047, i64 %.03244)
  %13 = add nsw i64 %12, %.03343
  %14 = sdiv i64 %13, 2
  %15 = sub nuw nsw i64 1, %.03343
  %16 = add nuw nsw i64 %12, %15
  %17 = lshr i64 %16, 1
  %18 = and i64 %.03244, 1
  %.not39 = icmp eq i64 %18, 0
  %spec.select = select i1 %.not39, i64 %.03343, i64 %15
  %19 = and i64 %.03244, 2
  %.not40.not = icmp eq i64 %19, 0
  br i1 %.not40.not, label %20, label %23

20:                                               ; preds = %.lr.ph
  %21 = add nsw i64 %14, %.02946
  %22 = add nuw nsw i64 %17, %.03045
  br label %26

23:                                               ; preds = %.lr.ph
  %24 = add nsw i64 %14, %.03741
  %25 = add nuw nsw i64 %17, %.03542
  br label %26

26:                                               ; preds = %23, %20
  %.138 = phi i64 [ %.03741, %20 ], [ %24, %23 ]
  %.136 = phi i64 [ %.03542, %20 ], [ %25, %23 ]
  %.131 = phi i64 [ %22, %20 ], [ %.03045, %23 ]
  %.1 = phi i64 [ %21, %20 ], [ %.02946, %23 ]
  %27 = sub nsw i64 %.047, %12
  %28 = add nuw nsw i64 %.03244, 1
  %29 = icmp sgt i64 %27, 0
  %30 = icmp slt i64 %.03244, %7
  %31 = and i1 %29, %30
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge54:                                    ; 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: 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, 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", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass