; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Codeforces Round #822 (Div. 2)/A. Select Three Sticks.ll (Z5solvev)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %13 = call ptr @llvm.stacksave.p0()
  store ptr %13, ptr %2, align 8
  %14 = alloca i64, i64 %12, align 16
  store i64 %12, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %24, %0
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %27

20:                                               ; preds = %15
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %14, i64 %21
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %22)
  br label %24

24:                                               ; preds = %20
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %4, align 8, !tbaa !5
  br label %15, !llvm.loop !9

27:                                               ; preds = %19
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds i64, ptr %14, i64 %28
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef %14, ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 2000000000000000000, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %69, %27
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %1, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %72

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %8, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %65, %35
  %39 = load i64, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %1, align 8, !tbaa !5
  %41 = icmp slt i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %68

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %44 = load i64, ptr %8, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %9, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %61, %43
  %47 = load i64, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %1, align 8, !tbaa !5
  %49 = icmp slt i64 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %64

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %52 = load i64, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %14, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds i64, ptr %14, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = sub nsw i64 %54, %57
  store i64 %58, ptr %10, align 8, !tbaa !5
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %60 = load i64, ptr %59, align 8, !tbaa !5
  store i64 %60, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %61

61:                                               ; preds = %51
  %62 = load i64, ptr %9, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %9, align 8, !tbaa !5
  br label %46, !llvm.loop !11

64:                                               ; preds = %50
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %8, align 8, !tbaa !5
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %8, align 8, !tbaa !5
  br label %38, !llvm.loop !12

68:                                               ; preds = %42
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %6, align 8, !tbaa !5
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %6, align 8, !tbaa !5
  br label %30, !llvm.loop !13

72:                                               ; preds = %34
  %73 = load i64, ptr %5, align 8, !tbaa !5
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %73)
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %74, ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %76 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %76)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; 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) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { inlinehint mustprogress 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 #5 = { 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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() 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) #5
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = call ptr @llvm.stacksave.p0()
  %7 = alloca i64, i64 %5, align 16
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %8, %0 ], [ %16, %.lr.ph ]
  %10 = getelementptr inbounds i64, ptr %7, i64 %.lcssa
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef nonnull %7, ptr noundef nonnull %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i64 2000000000000000000, ptr %2, align 8, !tbaa !5
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = icmp sgt i64 %11, 0
  br i1 %12, label %.lr.ph27, label %._crit_edge28

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01518 = phi i64 [ %15, %.lr.ph ], [ 0, %0 ]
  %13 = getelementptr inbounds i64, ptr %7, i64 %.01518
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %13)
  %15 = add nuw nsw i64 %.01518, 1
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.loopexit17:                                      ; preds = %.loopexit, %.lr.ph27
  %18 = phi i64 [ %24, %.lr.ph27 ], [ %29, %.loopexit ]
  %19 = phi i64 [ %25, %.lr.ph27 ], [ %30, %.loopexit ]
  %20 = icmp slt i64 %26, %19
  br i1 %20, label %.lr.ph27, label %._crit_edge28, !llvm.loop !11

._crit_edge28:                                    ; preds = %.loopexit17, %._crit_edge
  %21 = phi i64 [ 2000000000000000000, %._crit_edge ], [ %18, %.loopexit17 ]
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %21)
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull @.str)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.stackrestore.p0(ptr %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret void

.lr.ph27:                                         ; preds = %._crit_edge, %.loopexit17
  %24 = phi i64 [ %18, %.loopexit17 ], [ 2000000000000000000, %._crit_edge ]
  %25 = phi i64 [ %19, %.loopexit17 ], [ %11, %._crit_edge ]
  %.01425 = phi i64 [ %26, %.loopexit17 ], [ 0, %._crit_edge ]
  %26 = add nuw nsw i64 %.01425, 1
  %27 = icmp slt i64 %26, %25
  br i1 %27, label %.lr.ph24, label %.loopexit17

.lr.ph24:                                         ; preds = %.lr.ph27
  %28 = getelementptr inbounds i64, ptr %7, i64 %.01425
  br label %33

.loopexit:                                        ; preds = %.lr.ph21, %33
  %29 = phi i64 [ %34, %33 ], [ %44, %.lr.ph21 ]
  %30 = phi i64 [ %35, %33 ], [ %46, %.lr.ph21 ]
  %31 = phi i64 [ %36, %33 ], [ %46, %.lr.ph21 ]
  %32 = icmp slt i64 %37, %31
  br i1 %32, label %33, label %.loopexit17, !llvm.loop !12

33:                                               ; preds = %.lr.ph24, %.loopexit
  %34 = phi i64 [ %24, %.lr.ph24 ], [ %29, %.loopexit ]
  %35 = phi i64 [ %25, %.lr.ph24 ], [ %30, %.loopexit ]
  %36 = phi i64 [ %25, %.lr.ph24 ], [ %31, %.loopexit ]
  %.01322 = phi i64 [ %26, %.lr.ph24 ], [ %37, %.loopexit ]
  %37 = add nuw nsw i64 %.01322, 1
  %38 = icmp slt i64 %37, %36
  br i1 %38, label %.lr.ph21, label %.loopexit

.lr.ph21:                                         ; preds = %33, %.lr.ph21
  %.019 = phi i64 [ %45, %.lr.ph21 ], [ %37, %33 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %39 = getelementptr inbounds i64, ptr %7, i64 %.019
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %28, align 8, !tbaa !5
  %42 = sub nsw i64 %40, %41
  store i64 %42, ptr %3, align 8, !tbaa !5
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %44 = load i64, ptr %43, align 8, !tbaa !5
  store i64 %44, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %45 = add nuw nsw i64 %.019, 1
  %46 = load i64, ptr %1, align 8, !tbaa !5
  %47 = icmp slt i64 %45, %46
  br i1 %47, label %.lr.ph21, label %.loopexit, !llvm.loop !13
}

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { inlinehint mustprogress 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 #5 = { 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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass