; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Codeforces Round #605 (Div. 3)/A. Three Friends.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 [3 x i64], align 16
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %11, %0
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = icmp slt i64 %4, 3
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %14

7:                                                ; preds = %3
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 %8
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %9)
  br label %11

11:                                               ; preds = %7
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr %2, align 8, !tbaa !5
  br label %3, !llvm.loop !9

14:                                               ; preds = %6
  %15 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %16 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 3
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef %15, ptr noundef %16)
  %17 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %18 = load i64, ptr %17, align 16, !tbaa !5
  %19 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %20 = load i64, ptr %19, align 16, !tbaa !5
  %21 = sub nsw i64 %18, %20
  %22 = icmp sgt i64 %21, 1
  br i1 %22, label %23, label %30

23:                                               ; preds = %14
  %24 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %25 = load i64, ptr %24, align 16, !tbaa !5
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %24, align 16, !tbaa !5
  %27 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %28 = load i64, ptr %27, align 16, !tbaa !5
  %29 = add nsw i64 %28, -1
  store i64 %29, ptr %27, align 16, !tbaa !5
  br label %42

30:                                               ; preds = %14
  %31 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %32 = load i64, ptr %31, align 16, !tbaa !5
  %33 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %34 = load i64, ptr %33, align 16, !tbaa !5
  %35 = sub nsw i64 %32, %34
  %36 = icmp eq i64 %35, 1
  br i1 %36, label %37, label %41

37:                                               ; preds = %30
  %38 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %39 = load i64, ptr %38, align 16, !tbaa !5
  %40 = add nsw i64 %39, -1
  store i64 %40, ptr %38, align 16, !tbaa !5
  br label %41

41:                                               ; preds = %37, %30
  br label %42

42:                                               ; preds = %41, %23
  %43 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %46 = load i64, ptr %45, align 16, !tbaa !5
  %47 = sub nsw i64 %44, %46
  %48 = icmp sgt i64 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %42
  %50 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = add nsw i64 %51, -1
  store i64 %52, ptr %50, align 8, !tbaa !5
  br label %65

53:                                               ; preds = %42
  %54 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %55 = load i64, ptr %54, align 16, !tbaa !5
  %56 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = sub nsw i64 %55, %57
  %59 = icmp sgt i64 %58, 0
  br i1 %59, label %60, label %64

60:                                               ; preds = %53
  %61 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %61, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %60, %53
  br label %65

65:                                               ; preds = %64, %49
  %66 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %67 = load i64, ptr %66, align 16, !tbaa !5
  %68 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = sub nsw i64 %67, %69
  %71 = icmp slt i64 %70, 0
  br i1 %71, label %72, label %79

72:                                               ; preds = %65
  %73 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %74 = load i64, ptr %73, align 16, !tbaa !5
  %75 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %76 = load i64, ptr %75, align 8, !tbaa !5
  %77 = sub nsw i64 %74, %76
  %78 = sub nsw i64 0, %77
  br label %85

79:                                               ; preds = %65
  %80 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %81 = load i64, ptr %80, align 16, !tbaa !5
  %82 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %83 = load i64, ptr %82, align 8, !tbaa !5
  %84 = sub nsw i64 %81, %83
  br label %85

85:                                               ; preds = %79, %72
  %86 = phi i64 [ %78, %72 ], [ %84, %79 ]
  %87 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %88 = load i64, ptr %87, align 8, !tbaa !5
  %89 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %90 = load i64, ptr %89, align 16, !tbaa !5
  %91 = sub nsw i64 %88, %90
  %92 = icmp slt i64 %91, 0
  br i1 %92, label %93, label %100

93:                                               ; preds = %85
  %94 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %95 = load i64, ptr %94, align 8, !tbaa !5
  %96 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %97 = load i64, ptr %96, align 16, !tbaa !5
  %98 = sub nsw i64 %95, %97
  %99 = sub nsw i64 0, %98
  br label %106

100:                                              ; preds = %85
  %101 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 1
  %102 = load i64, ptr %101, align 8, !tbaa !5
  %103 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %104 = load i64, ptr %103, align 16, !tbaa !5
  %105 = sub nsw i64 %102, %104
  br label %106

106:                                              ; preds = %100, %93
  %107 = phi i64 [ %99, %93 ], [ %105, %100 ]
  %108 = add nsw i64 %86, %107
  %109 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %110 = load i64, ptr %109, align 16, !tbaa !5
  %111 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %112 = load i64, ptr %111, align 16, !tbaa !5
  %113 = sub nsw i64 %110, %112
  %114 = icmp slt i64 %113, 0
  br i1 %114, label %115, label %122

115:                                              ; preds = %106
  %116 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %117 = load i64, ptr %116, align 16, !tbaa !5
  %118 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %119 = load i64, ptr %118, align 16, !tbaa !5
  %120 = sub nsw i64 %117, %119
  %121 = sub nsw i64 0, %120
  br label %128

122:                                              ; preds = %106
  %123 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 2
  %124 = load i64, ptr %123, align 16, !tbaa !5
  %125 = getelementptr inbounds [3 x i64], ptr %1, i64 0, i64 0
  %126 = load i64, ptr %125, align 16, !tbaa !5
  %127 = sub nsw i64 %124, %126
  br label %128

128:                                              ; preds = %122, %115
  %129 = phi i64 [ %121, %115 ], [ %127, %122 ]
  %130 = add nsw i64 %108, %129
  %131 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %130)
  %132 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %131, ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 24, ptr %1) #3
  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 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) #2

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

; 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

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 = { 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 #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"

%"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 [3 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #4
  %2 = 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)
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %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) %3)
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef nonnull %1, ptr noundef nonnull %7)
  %8 = load i64, ptr %5, align 16, !tbaa !5
  %9 = load i64, ptr %1, align 16, !tbaa !5
  %10 = sub nsw i64 %8, %9
  %11 = icmp sgt i64 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = add nsw i64 %9, 1
  store i64 %13, ptr %1, align 16, !tbaa !5
  br label %.sink.split

14:                                               ; preds = %0
  %15 = icmp eq i64 %10, 1
  br i1 %15, label %.sink.split, label %17

.sink.split:                                      ; preds = %14, %12
  %.ph10 = phi i64 [ %13, %12 ], [ %9, %14 ]
  %16 = add nsw i64 %8, -1
  store i64 %16, ptr %5, align 16, !tbaa !5
  br label %17

17:                                               ; preds = %.sink.split, %14
  %18 = phi i64 [ %8, %14 ], [ %16, %.sink.split ]
  %19 = phi i64 [ %9, %14 ], [ %.ph10, %.sink.split ]
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp sgt i64 %20, %19
  br i1 %21, label %.sink.split11, label %22

22:                                               ; preds = %17
  %23 = icmp sgt i64 %18, %20
  br i1 %23, label %.sink.split11, label %25

.sink.split11:                                    ; preds = %22, %17
  %.sink12 = phi i64 [ -1, %17 ], [ 1, %22 ]
  %24 = add nsw i64 %20, %.sink12
  store i64 %24, ptr %3, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %.sink.split11, %22
  %26 = phi i64 [ %20, %22 ], [ %24, %.sink.split11 ]
  %27 = sub nsw i64 %19, %26
  %28 = call i64 @llvm.abs.i64(i64 %27, i1 true)
  %29 = sub nsw i64 %26, %18
  %30 = call i64 @llvm.abs.i64(i64 %29, i1 true)
  %31 = sub nsw i64 %18, %19
  %32 = call i64 @llvm.abs.i64(i64 %31, i1 true)
  %33 = add nuw nsw i64 %30, %28
  %34 = add nuw nsw i64 %33, %32
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %34)
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %35, ptr noundef nonnull @.str)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #4
  ret void
}

; 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 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 #2

; 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 #2

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #3

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 = { 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 #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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass