; LLVM IR from DionysiosB/CodeForces :: 1500-1599 (1538A-StoneGame)

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

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

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

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

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %46

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %9)
  %29 = load i64, ptr %9, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %33, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %34, ptr %6, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %32, %27
  %36 = load i64, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = icmp sgt i64 %36, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %35
  %40 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %40, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %41, ptr %7, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %39, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %43

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

46:                                               ; preds = %26
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = icmp sgt i64 %47, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %51 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %51, ptr %10, align 8, !tbaa !5
  %52 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %52, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %53, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %54

54:                                               ; preds = %50, %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %55 = load i64, ptr %7, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !5
  %59 = sub nsw i64 %57, %58
  store i64 %59, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %60 = load i64, ptr %3, align 8, !tbaa !5
  %61 = load i64, ptr %7, align 8, !tbaa !5
  %62 = sub nsw i64 %60, %61
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %6, align 8, !tbaa !5
  %65 = add nsw i64 %63, %64
  store i64 %65, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %66 = load i64, ptr %11, align 8, !tbaa !5
  %67 = load i64, ptr %12, align 8, !tbaa !5
  %68 = icmp slt i64 %66, %67
  br i1 %68, label %69, label %71

69:                                               ; preds = %54
  %70 = load i64, ptr %11, align 8, !tbaa !5
  br label %73

71:                                               ; preds = %54
  %72 = load i64, ptr %12, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %71, %69
  %74 = phi i64 [ %70, %69 ], [ %72, %71 ]
  store i64 %74, ptr %14, align 8, !tbaa !5
  %75 = load i64, ptr %14, align 8, !tbaa !5
  %76 = load i64, ptr %13, align 8, !tbaa !5
  %77 = icmp slt i64 %75, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %73
  %79 = load i64, ptr %14, align 8, !tbaa !5
  br label %82

80:                                               ; preds = %73
  %81 = load i64, ptr %13, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %80, %78
  %83 = phi i64 [ %79, %78 ], [ %81, %80 ]
  store i64 %83, ptr %14, align 8, !tbaa !5
  %84 = load i64, ptr %14, align 8, !tbaa !5
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  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
  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 %16, !llvm.loop !11

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

; 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 [5 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) #4
  %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
  %.not45 = icmp eq i64 %5, 0
  br i1 %.not45, label %._crit_edge48, label %.lr.ph47

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

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph47
  %.029.lcssa = phi i64 [ -1, %.lr.ph47 ], [ %.130, %.lr.ph ]
  %.027.lcssa = phi i64 [ -1, %.lr.ph47 ], [ %spec.select36, %.lr.ph ]
  %.lcssa = phi i64 [ %8, %.lr.ph47 ], [ %24, %.lr.ph ]
  %spec.select = call i64 @llvm.smax.i64(i64 %.027.lcssa, i64 %.029.lcssa)
  %spec.select35 = call i64 @llvm.smin.i64(i64 %.027.lcssa, i64 %.029.lcssa)
  %10 = add nsw i64 %spec.select, 1
  %11 = sub nsw i64 %.lcssa, %spec.select35
  %reass.sub = sub i64 %spec.select35, %spec.select
  %12 = add i64 %reass.sub, 1
  %13 = add i64 %12, %.lcssa
  %14 = call i64 @llvm.smin.i64(i64 %10, i64 %11)
  %15 = call i64 @llvm.smin.i64(i64 %14, i64 %13)
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %15)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = add nsw i64 %17, -1
  store i64 %18, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %._crit_edge48, label %.lr.ph47, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph47, %.lr.ph
  %.042 = phi i64 [ %spec.select37, %.lr.ph ], [ 10000000, %.lr.ph47 ]
  %.02541 = phi i64 [ %.126, %.lr.ph ], [ -10000000, %.lr.ph47 ]
  %.02740 = phi i64 [ %spec.select36, %.lr.ph ], [ -1, %.lr.ph47 ]
  %.02939 = phi i64 [ %.130, %.lr.ph ], [ -1, %.lr.ph47 ]
  %.03238 = phi i64 [ %23, %.lr.ph ], [ 0, %.lr.ph47 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp slt i64 %20, %.042
  %spec.select36 = select i1 %21, i64 %.03238, i64 %.02740
  %spec.select37 = call i64 @llvm.smin.i64(i64 %20, i64 %.042)
  %22 = icmp sgt i64 %20, %.02541
  %.130 = select i1 %22, i64 %.03238, i64 %.02939
  %.126 = call i64 @llvm.smax.i64(i64 %20, i64 %.02541)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %23 = add nuw nsw i64 %.03238, 1
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !11

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

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