; LLVM IR from DionysiosB/CodeForces :: 0800-0899 (870B-MaximumOfMaximumsOfMinimums)

; 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 [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
  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
  %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) #3
  store i64 2000000000, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 -2000000000, 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
  br label %11

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

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %52

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %9)
  %18 = load i64, ptr %8, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %21, ptr %6, align 8, !tbaa !5
  br label %30

22:                                               ; preds = %16
  %23 = load i64, ptr %8, align 8, !tbaa !5
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = sub nsw i64 %24, 1
  %26 = icmp eq i64 %23, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %28, ptr %7, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %27, %22
  br label %30

30:                                               ; preds = %29, %20
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = load i64, ptr %4, align 8, !tbaa !5
  br label %38

36:                                               ; preds = %30
  %37 = load i64, ptr %9, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %36, %34
  %39 = phi i64 [ %35, %34 ], [ %37, %36 ]
  store i64 %39, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !5
  %42 = icmp sgt i64 %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %38
  %44 = load i64, ptr %5, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %38
  %46 = load i64, ptr %9, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %43
  %48 = phi i64 [ %44, %43 ], [ %46, %45 ]
  store i64 %48, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %49

49:                                               ; preds = %47
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = add nsw i64 %50, 1
  store i64 %51, ptr %8, align 8, !tbaa !5
  br label %11, !llvm.loop !9

52:                                               ; preds = %15
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = icmp eq i64 %53, 1
  br i1 %54, label %55, label %58

55:                                               ; preds = %52
  %56 = load i64, ptr %4, align 8, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %56)
  br label %76

58:                                               ; preds = %52
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = icmp eq i64 %59, 2
  br i1 %60, label %61, label %72

61:                                               ; preds = %58
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %7, align 8, !tbaa !5
  %64 = icmp sgt i64 %62, %63
  br i1 %64, label %65, label %67

65:                                               ; preds = %61
  %66 = load i64, ptr %6, align 8, !tbaa !5
  br label %69

67:                                               ; preds = %61
  %68 = load i64, ptr %7, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %67, %65
  %70 = phi i64 [ %66, %65 ], [ %68, %67 ]
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %70)
  br label %75

72:                                               ; preds = %58
  %73 = load i64, ptr %5, align 8, !tbaa !5
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %73)
  br label %75

75:                                               ; preds = %72, %69
  br label %76

76:                                               ; preds = %75, %55
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

; 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"}


; 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 [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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %7, label %._crit_edge

7:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %9 = load i64, ptr %3, align 8
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  %10 = call i64 @llvm.smin.i64(i64 %9, i64 2000000000)
  %11 = call i64 @llvm.smax.i64(i64 %9, i64 -2000000000)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %12 = icmp sgt i64 %.pre, 1
  br i1 %12, label %.lr.ph.peel.next, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %7, %0
  %.018.lcssa = phi i64 [ 2000000000, %0 ], [ %10, %7 ], [ %19, %.lr.ph.peel.next ]
  %.017.lcssa = phi i64 [ -2000000000, %0 ], [ %11, %7 ], [ %20, %.lr.ph.peel.next ]
  %.015.lcssa = phi i64 [ 0, %0 ], [ %9, %7 ], [ %9, %.lr.ph.peel.next ]
  %.014.lcssa = phi i64 [ 0, %0 ], [ 0, %7 ], [ %spec.select, %.lr.ph.peel.next ]
  %13 = load i64, ptr %2, align 8, !tbaa !5
  switch i64 %13, label %25 [
    i64 1, label %26
    i64 2, label %23
  ]

.lr.ph.peel.next:                                 ; preds = %7, %.lr.ph.peel.next
  %.024 = phi i64 [ %21, %.lr.ph.peel.next ], [ 1, %7 ]
  %.01423 = phi i64 [ %spec.select, %.lr.ph.peel.next ], [ 0, %7 ]
  %.01721 = phi i64 [ %20, %.lr.ph.peel.next ], [ %11, %7 ]
  %.01820 = phi i64 [ %19, %.lr.ph.peel.next ], [ %10, %7 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %15 = load i64, ptr %1, align 8, !tbaa !5
  %16 = add nsw i64 %15, -1
  %17 = icmp eq i64 %.024, %16
  %18 = load i64, ptr %3, align 8
  %spec.select = select i1 %17, i64 %18, i64 %.01423
  %19 = call i64 @llvm.smin.i64(i64 %.01820, i64 %18)
  %20 = call i64 @llvm.smax.i64(i64 %.01721, i64 %18)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %21 = add nuw nsw i64 %.024, 1
  %22 = icmp slt i64 %21, %15
  br i1 %22, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !9

23:                                               ; preds = %._crit_edge
  %24 = call i64 @llvm.smax.i64(i64 %.015.lcssa, i64 %.014.lcssa)
  br label %26

25:                                               ; preds = %._crit_edge
  br label %26

26:                                               ; preds = %._crit_edge, %23, %25
  %.sink = phi i64 [ %24, %23 ], [ %.017.lcssa, %25 ], [ %.018.lcssa, %._crit_edge ]
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.sink)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  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.smax.i64(i64, i64) #3

; 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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass