; LLVM IR from DionysiosB/CodeForces :: 1400-1499 (1468N-WasteSorting)

; 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 [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 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 i8, align 1
  %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 = %86, %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 %95

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

25:                                               ; preds = %19
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp sgt i64 %26, %27
  br i1 %28, label %33, label %29

29:                                               ; preds = %25
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = icmp sgt i64 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %29, %25, %19
  store i8 0, ptr %11, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %33, %29
  %35 = load i64, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = sub nsw i64 %36, %35
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = sub nsw i64 %39, %38
  store i64 %40, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = sub nsw i64 %42, %41
  store i64 %43, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %44 = load i64, ptr %3, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !5
  %46 = icmp slt i64 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %34
  %48 = load i64, ptr %3, align 8, !tbaa !5
  br label %51

49:                                               ; preds = %34
  %50 = load i64, ptr %9, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %47
  %52 = phi i64 [ %48, %47 ], [ %50, %49 ]
  store i64 %52, ptr %12, align 8, !tbaa !5
  %53 = load i64, ptr %12, align 8, !tbaa !5
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = sub nsw i64 %54, %53
  store i64 %55, ptr %3, align 8, !tbaa !5
  %56 = load i64, ptr %12, align 8, !tbaa !5
  %57 = load i64, ptr %9, align 8, !tbaa !5
  %58 = sub nsw i64 %57, %56
  store i64 %58, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = icmp slt i64 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %51
  store i8 0, ptr %11, align 1, !tbaa !9
  br label %63

63:                                               ; preds = %62, %51
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = load i64, ptr %5, align 8, !tbaa !5
  %66 = sub nsw i64 %65, %64
  store i64 %66, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = load i64, ptr %10, align 8, !tbaa !5
  %69 = icmp slt i64 %67, %68
  br i1 %69, label %70, label %72

70:                                               ; preds = %63
  %71 = load i64, ptr %4, align 8, !tbaa !5
  br label %74

72:                                               ; preds = %63
  %73 = load i64, ptr %10, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %72, %70
  %75 = phi i64 [ %71, %70 ], [ %73, %72 ]
  store i64 %75, ptr %13, align 8, !tbaa !5
  %76 = load i64, ptr %13, 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
  %79 = load i64, ptr %13, align 8, !tbaa !5
  %80 = load i64, ptr %10, align 8, !tbaa !5
  %81 = sub nsw i64 %80, %79
  store i64 %81, ptr %10, align 8, !tbaa !5
  %82 = load i64, ptr %5, align 8, !tbaa !5
  %83 = load i64, ptr %10, align 8, !tbaa !5
  %84 = icmp slt i64 %82, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %74
  store i8 0, ptr %11, align 1, !tbaa !9
  br label %86

86:                                               ; preds = %85, %74
  %87 = load i64, ptr %10, align 8, !tbaa !5
  %88 = load i64, ptr %5, align 8, !tbaa !5
  %89 = sub nsw i64 %88, %87
  store i64 %89, ptr %5, align 8, !tbaa !5
  %90 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %91 = trunc i8 %90 to i1
  %92 = zext i1 %91 to i64
  %93 = select i1 %91, ptr @.str.3, ptr @.str.4
  %94 = call i32 @puts(ptr noundef %93)
  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 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  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 !13

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

; 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 @puts(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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 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
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = add nsw i64 %11, -1
  store i64 %12, ptr %1, align 8, !tbaa !5
  %.not7 = icmp eq i64 %11, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9)
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = icmp sgt i64 %15, %16
  %.pre.pre = load i64, ptr %6, align 8, !tbaa !5
  %.pre8.pre = load i64, ptr %3, align 8, !tbaa !5
  br i1 %17, label %.lr.ph._crit_edge, label %18

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre9.pre = load i64, ptr %7, align 8, !tbaa !5
  %.pre10.pre = load i64, ptr %4, align 8, !tbaa !5
  br label %21

18:                                               ; preds = %.lr.ph
  %19 = icmp sle i64 %.pre.pre, %.pre8.pre
  %.pre9.pre11 = load i64, ptr %7, align 8, !tbaa !5
  %.pre10.pre13 = load i64, ptr %4, align 8, !tbaa !5
  %20 = icmp sle i64 %.pre9.pre11, %.pre10.pre13
  %spec.select16 = select i1 %19, i1 %20, i1 false
  br label %21

21:                                               ; preds = %18, %.lr.ph._crit_edge
  %22 = phi i64 [ %.pre10.pre, %.lr.ph._crit_edge ], [ %.pre10.pre13, %18 ]
  %23 = phi i64 [ %.pre9.pre, %.lr.ph._crit_edge ], [ %.pre9.pre11, %18 ]
  %.0 = phi i1 [ false, %.lr.ph._crit_edge ], [ %spec.select16, %18 ]
  %24 = sub nsw i64 %16, %15
  %25 = sub nsw i64 %.pre8.pre, %.pre.pre
  %26 = sub nsw i64 %22, %23
  %27 = load i64, ptr %8, align 8
  %28 = call i64 @llvm.smin.i64(i64 %24, i64 %27)
  %29 = sub nsw i64 %24, %28
  store i64 %29, ptr %2, align 8, !tbaa !5
  %30 = sub nsw i64 %27, %28
  store i64 %30, ptr %8, align 8, !tbaa !5
  %31 = icmp sge i64 %26, %30
  %spec.select = and i1 %.0, %31
  %32 = sub nsw i64 %26, %30
  %33 = load i64, ptr %9, align 8
  %34 = call i64 @llvm.smin.i64(i64 %25, i64 %33)
  %35 = sub nsw i64 %25, %34
  store i64 %35, ptr %3, align 8, !tbaa !5
  %36 = sub nsw i64 %33, %34
  store i64 %36, ptr %9, align 8, !tbaa !5
  %37 = icmp sge i64 %32, %36
  %spec.select6 = and i1 %spec.select, %37
  %38 = sub nsw i64 %32, %36
  store i64 %38, ptr %4, align 8, !tbaa !5
  %39 = select i1 %spec.select6, ptr @.str.3, ptr @.str.4
  %40 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %41 = load i64, ptr %1, align 8, !tbaa !5
  %42 = add nsw i64 %41, -1
  store i64 %42, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %41, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %21, %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: nofree nounwind
declare noundef i32 @puts(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: 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"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass