; LLVM IR from DionysiosB/CodeForces :: 1400-1499 (1461D-DivideAndSummarize)

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

%"struct.std::pair" = type <{ %"struct.std::_Rb_tree_const_iterator", i8, [7 x i8] }>
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca %"struct.std::pair", align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp sge i64 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %87

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %20, ptr %10, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %33, %19
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %36

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28) #3
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %9, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %26
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %10, align 8, !tbaa !9
  br label %21, !llvm.loop !11

36:                                               ; preds = %25
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) %37, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %39 = getelementptr inbounds { ptr, i8 }, ptr %11, i32 0, i32 0
  %40 = extractvalue { ptr, i8 } %38, 0
  store ptr %40, ptr %39, align 8
  %41 = getelementptr inbounds { ptr, i8 }, ptr %11, i32 0, i32 1
  %42 = extractvalue { ptr, i8 } %38, 1
  store i8 %42, ptr %41, align 8
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %44) #3
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = sub nsw i64 %48, 1
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #3
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = icmp eq i64 %46, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %36
  store i32 1, ptr %12, align 4
  br label %86

54:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %55, i64 noundef %56) #3
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !9
  %61 = sub nsw i64 %60, 1
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %59, i64 noundef %61) #3
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = add nsw i64 %58, %63
  %65 = sdiv i64 %64, 2
  store i64 %65, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %66 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %66, ptr %14, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %74, %54
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !9
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %68, i64 noundef %69) #3
  %71 = load i64, ptr %70, align 8, !tbaa !9
  %72 = load i64, ptr %13, align 8, !tbaa !9
  %73 = icmp sle i64 %71, %72
  br i1 %73, label %74, label %77

74:                                               ; preds = %67
  %75 = load i64, ptr %14, align 8, !tbaa !9
  %76 = add nsw i64 %75, 1
  store i64 %76, ptr %14, align 8, !tbaa !9
  br label %67, !llvm.loop !13

77:                                               ; preds = %67
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %7, align 8, !tbaa !9
  %81 = load i64, ptr %14, align 8, !tbaa !9
  call void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %78, ptr noundef nonnull align 8 dereferenceable(48) %79, i64 noundef %80, i64 noundef %81)
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load i64, ptr %14, align 8, !tbaa !9
  %85 = load i64, ptr %8, align 8, !tbaa !9
  call void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %82, ptr noundef nonnull align 8 dereferenceable(48) %83, i64 noundef %84, i64 noundef %85)
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %86

86:                                               ; preds = %77, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %87

87:                                               ; preds = %86, %18
  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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 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: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %.not = icmp slt i64 %2, %3
  br i1 %.not, label %6, label %34

6:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  br label %15

7:                                                ; preds = %15
  %8 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %2) #3
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = add nsw i64 %3, -1
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #3
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i64 %10, %13
  br i1 %14, label %33, label %21

15:                                               ; preds = %6, %15
  %.02933 = phi i64 [ %2, %6 ], [ %20, %15 ]
  %16 = phi i64 [ 0, %6 ], [ %19, %15 ]
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.02933) #3
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = add nsw i64 %16, %18
  store i64 %19, ptr %5, align 8, !tbaa !5
  %20 = add i64 %.02933, 1
  %exitcond.not = icmp eq i64 %20, %3
  br i1 %exitcond.not, label %7, label %15, !llvm.loop !9

21:                                               ; preds = %7
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %2) #3
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #3
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = add nsw i64 %25, %23
  %27 = sdiv i64 %26, 2
  br label %28

28:                                               ; preds = %28, %21
  %.0 = phi i64 [ %2, %21 ], [ %31, %28 ]
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.0) #3
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %.not32 = icmp sgt i64 %30, %27
  %31 = add nsw i64 %.0, 1
  br i1 %.not32, label %32, label %28, !llvm.loop !11

32:                                               ; preds = %28
  call void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 noundef %2, i64 noundef %.0)
  call void @_Z7getSumsRKSt6vectorIxSaIxEERSt3setIxSt4lessIxES0_Exx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 noundef %.0, i64 noundef %3)
  br label %33

33:                                               ; preds = %7, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %34

34:                                               ; preds = %4, %33
  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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 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: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass