; LLVM IR from DionysiosB/CodeForces :: 0300-0399 (395A1-Skis)

; 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 ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  store i64 0, ptr %3, align 8, !tbaa !5
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %10, i64 8)
  %12 = extractvalue { i64, i1 } %11, 1
  %13 = extractvalue { i64, i1 } %11, 0
  %14 = select i1 %12, i64 -1, i64 %13
  %15 = call noalias noundef nonnull ptr @_Znam(i64 noundef %14) #8
  store ptr %15, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %28, %0
  %17 = load i32, ptr %5, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %31

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i64, ptr %23, i64 %25
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %26)
  br label %28

28:                                               ; preds = %22
  %29 = load i32, ptr %5, align 4, !tbaa !11
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !11
  br label %16, !llvm.loop !13

31:                                               ; preds = %21
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds i64, ptr %33, i64 %34
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef %32, ptr noundef %35)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = sub nsw i64 %36, 1
  store i64 %37, ptr %8, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %93, %31
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !5
  %41 = icmp slt i64 %39, %40
  br i1 %41, label %42, label %94

42:                                               ; preds = %38
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds i64, ptr %43, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = load i64, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds i64, ptr %47, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = add nsw i64 %46, %50
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = icmp eq i64 %51, %52
  br i1 %53, label %54, label %61

54:                                               ; preds = %42
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %8, align 8, !tbaa !5
  %60 = add nsw i64 %59, -1
  store i64 %60, ptr %8, align 8, !tbaa !5
  br label %93

61:                                               ; preds = %42
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = load i64, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds i64, ptr %62, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = load i64, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds i64, ptr %66, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = add nsw i64 %65, %69
  %71 = load i64, ptr %3, align 8, !tbaa !5
  %72 = icmp slt i64 %70, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %61
  %74 = load i64, ptr %7, align 8, !tbaa !5
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %7, align 8, !tbaa !5
  br label %92

76:                                               ; preds = %61
  %77 = load ptr, ptr %4, align 8, !tbaa !9
  %78 = load i64, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds i64, ptr %77, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  %82 = load i64, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds i64, ptr %81, i64 %82
  %84 = load i64, ptr %83, align 8, !tbaa !5
  %85 = add nsw i64 %80, %84
  %86 = load i64, ptr %3, align 8, !tbaa !5
  %87 = icmp sgt i64 %85, %86
  br i1 %87, label %88, label %91

88:                                               ; preds = %76
  %89 = load i64, ptr %8, align 8, !tbaa !5
  %90 = add nsw i64 %89, -1
  store i64 %90, ptr %8, align 8, !tbaa !5
  br label %91

91:                                               ; preds = %88, %76
  br label %92

92:                                               ; preds = %91, %73
  br label %93

93:                                               ; preds = %92, %54
  br label %38, !llvm.loop !15

94:                                               ; preds = %38
  %95 = load i64, ptr %6, align 8, !tbaa !5
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %95)
  %97 = load ptr, ptr %4, align 8, !tbaa !9
  %98 = icmp eq ptr %97, null
  br i1 %98, label %100, label %99

99:                                               ; preds = %94
  call void @_ZdaPv(ptr noundef %97) #9
  br label %100

100:                                              ; preds = %99, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) #5

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #6

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { inlinehint mustprogress 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 #6 = { nobuiltin 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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 norecurse 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) #6
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store i64 0, ptr %2, align 8, !tbaa !5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = icmp ugt i64 %4, 2305843009213693951
  %6 = shl i64 %4, 3
  %7 = select i1 %5, i64 -1, i64 %6
  %8 = call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #7
  %9 = icmp sgt i64 %4, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %4, %0 ], [ %17, %.lr.ph ]
  %10 = getelementptr inbounds i64, ptr %8, i64 %.lcssa
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef nonnull %8, ptr noundef nonnull %10)
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = icmp sgt i64 %11, 1
  br i1 %12, label %.lr.ph40, label %._crit_edge41

.lr.ph40:                                         ; preds = %._crit_edge
  %13 = add nsw i64 %11, -1
  %14 = load i64, ptr %2, align 8, !tbaa !5
  br label %19

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %15 = getelementptr inbounds i64, ptr %8, i64 %indvars.iv
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = icmp sgt i64 %17, %indvars.iv.next
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !9

19:                                               ; preds = %.lr.ph40, %37
  %.038 = phi i64 [ %13, %.lr.ph40 ], [ %.1, %37 ]
  %.02637 = phi i64 [ 0, %.lr.ph40 ], [ %.127, %37 ]
  %.02836 = phi i64 [ 0, %.lr.ph40 ], [ %.129, %37 ]
  %20 = getelementptr inbounds i64, ptr %8, i64 %.02637
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %8, i64 %.038
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = add nsw i64 %23, %21
  %25 = icmp eq i64 %24, %14
  br i1 %25, label %26, label %30

26:                                               ; preds = %19
  %27 = add nsw i64 %.02836, 1
  %28 = add nsw i64 %.02637, 1
  %29 = add nsw i64 %.038, -1
  br label %37

30:                                               ; preds = %19
  %31 = icmp slt i64 %24, %14
  br i1 %31, label %32, label %34

32:                                               ; preds = %30
  %33 = add nsw i64 %.02637, 1
  br label %37

34:                                               ; preds = %30
  %35 = icmp sgt i64 %24, %14
  %36 = sext i1 %35 to i64
  %spec.select = add nsw i64 %.038, %36
  br label %37

37:                                               ; preds = %34, %32, %26
  %.129 = phi i64 [ %27, %26 ], [ %.02836, %32 ], [ %.02836, %34 ]
  %.127 = phi i64 [ %28, %26 ], [ %33, %32 ], [ %.02637, %34 ]
  %.1 = phi i64 [ %29, %26 ], [ %.038, %32 ], [ %spec.select, %34 ]
  %38 = icmp slt i64 %.127, %.1
  br i1 %38, label %19, label %._crit_edge41, !llvm.loop !11

._crit_edge41:                                    ; preds = %37, %._crit_edge
  %.028.lcssa = phi i64 [ 0, %._crit_edge ], [ %.129, %37 ]
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.028.lcssa)
  call void @_ZdaPv(ptr noundef nonnull %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #5

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 = { 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 = { nobuiltin allocsize(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 #4 = { inlinehint mustprogress 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 #5 = { nobuiltin 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass