; LLVM IR from brpapa/algorithms :: solutions/spoj/CPCRC1C.ll (Z2dpiib)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@digs = external dso_local global %"class.std::vector", align 8
@memo = external dso_local global [10 x [91 x [2 x i64]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z2dpiib(i32 noundef %0, i32 noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  %11 = zext i1 %2 to i8
  store i8 %11, ptr %7, align 1, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @digs) #3
  %15 = icmp eq i64 %13, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %3
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %4, align 8
  br label %83

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10 x [91 x [2 x i64]]], ptr @memo, i64 0, i64 %21
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [91 x [2 x i64]], ptr %22, i64 0, i64 %24
  %26 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %27 = trunc i8 %26 to i1
  %28 = zext i1 %27 to i64
  %29 = getelementptr inbounds [2 x i64], ptr %25, i64 0, i64 %28
  store ptr %29, ptr %8, align 8, !tbaa !13
  %30 = load ptr, ptr %8, align 8, !tbaa !13
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = icmp ne i64 %31, -1
  br i1 %32, label %33, label %36

33:                                               ; preds = %19
  %34 = load ptr, ptr %8, align 8, !tbaa !13
  %35 = load i64, ptr %34, align 8, !tbaa !15
  store i64 %35, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %82

36:                                               ; preds = %19
  %37 = load ptr, ptr %8, align 8, !tbaa !13
  store i64 0, ptr %37, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %76, %36
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %47

42:                                               ; preds = %38
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %44) #3
  %46 = load i32, ptr %45, align 4, !tbaa !5
  br label %48

47:                                               ; preds = %38
  br label %48

48:                                               ; preds = %47, %42
  %49 = phi i32 [ %46, %42 ], [ 9, %47 ]
  %50 = icmp sle i32 %39, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %79

52:                                               ; preds = %48
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %60) #3
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = icmp eq i32 %58, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %52
  %65 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %66 = trunc i8 %65 to i1
  %67 = zext i1 %66 to i32
  br label %69

68:                                               ; preds = %52
  br label %69

69:                                               ; preds = %68, %64
  %70 = phi i32 [ %67, %64 ], [ 0, %68 ]
  %71 = icmp ne i32 %70, 0
  %72 = call noundef i64 @_Z2dpiib(i32 noundef %54, i32 noundef %57, i1 noundef zeroext %71)
  %73 = load ptr, ptr %8, align 8, !tbaa !13
  %74 = load i64, ptr %73, align 8, !tbaa !15
  %75 = add nsw i64 %74, %72
  store i64 %75, ptr %73, align 8, !tbaa !15
  br label %76

76:                                               ; preds = %69
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %10, align 4, !tbaa !5
  br label %38, !llvm.loop !17

79:                                               ; preds = %51
  %80 = load ptr, ptr %8, align 8, !tbaa !13
  %81 = load i64, ptr %80, align 8, !tbaa !15
  store i64 %81, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %82

82:                                               ; preds = %79, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %83

83:                                               ; preds = %82, %16
  %84 = load i64, ptr %4, align 8
  ret i64 %84
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !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 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@digs = external dso_local global %"class.std::vector", align 8
@memo = external dso_local local_unnamed_addr global [10 x [91 x [2 x i64]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z2dpiib(i32 noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @digs) #1
  %6 = icmp eq i64 %5, %4
  %7 = sext i32 %1 to i64
  br i1 %6, label %75, label %8

8:                                                ; preds = %3
  %9 = zext i1 %2 to i64
  %10 = getelementptr inbounds [10 x [91 x [2 x i64]]], ptr @memo, i64 0, i64 %4, i64 %7, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.not = icmp eq i64 %11, -1
  br i1 %.not, label %12, label %75

12:                                               ; preds = %8
  store i64 0, ptr %10, align 8, !tbaa !5
  %13 = add nsw i32 %0, 1
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  br i1 %2, label %.split.us, label %.split.preheader

.split.preheader:                                 ; preds = %12
  %15 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %1, i1 noundef zeroext false)
  %16 = load i64, ptr %10, align 8, !tbaa !5
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr %10, align 8, !tbaa !5
  %18 = add nsw i32 %1, 1
  %19 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %20 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %18, i1 noundef zeroext false)
  %21 = load i64, ptr %10, align 8, !tbaa !5
  %22 = add nsw i64 %21, %20
  store i64 %22, ptr %10, align 8, !tbaa !5
  %23 = add nsw i32 %1, 2
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %25 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %23, i1 noundef zeroext false)
  %26 = load i64, ptr %10, align 8, !tbaa !5
  %27 = add nsw i64 %26, %25
  store i64 %27, ptr %10, align 8, !tbaa !5
  %28 = add nsw i32 %1, 3
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %30 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %28, i1 noundef zeroext false)
  %31 = load i64, ptr %10, align 8, !tbaa !5
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %10, align 8, !tbaa !5
  %33 = add nsw i32 %1, 4
  %34 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %35 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %33, i1 noundef zeroext false)
  %36 = load i64, ptr %10, align 8, !tbaa !5
  %37 = add nsw i64 %36, %35
  store i64 %37, ptr %10, align 8, !tbaa !5
  %38 = add nsw i32 %1, 5
  %39 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %40 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %38, i1 noundef zeroext false)
  %41 = load i64, ptr %10, align 8, !tbaa !5
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr %10, align 8, !tbaa !5
  %43 = add nsw i32 %1, 6
  %44 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %45 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %43, i1 noundef zeroext false)
  %46 = load i64, ptr %10, align 8, !tbaa !5
  %47 = add nsw i64 %46, %45
  store i64 %47, ptr %10, align 8, !tbaa !5
  %48 = add nsw i32 %1, 7
  %49 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %50 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %48, i1 noundef zeroext false)
  %51 = load i64, ptr %10, align 8, !tbaa !5
  %52 = add nsw i64 %51, %50
  store i64 %52, ptr %10, align 8, !tbaa !5
  %53 = add nsw i32 %1, 8
  %54 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %55 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %53, i1 noundef zeroext false)
  %56 = load i64, ptr %10, align 8, !tbaa !5
  %57 = add nsw i64 %56, %55
  store i64 %57, ptr %10, align 8, !tbaa !5
  %58 = add nsw i32 %1, 9
  %59 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %60 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %58, i1 noundef zeroext false)
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr %10, align 8, !tbaa !5
  br label %.split25.us

.split.us:                                        ; preds = %12
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %.not23.us27 = icmp slt i32 %63, 0
  br i1 %.not23.us27, label %.split25.us, label %.lr.ph

.lr.ph:                                           ; preds = %.split.us, %.lr.ph
  %.0.us28 = phi i32 [ %71, %.lr.ph ], [ 0, %.split.us ]
  %64 = add nsw i32 %.0.us28, %1
  %65 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = icmp eq i32 %.0.us28, %66
  %68 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %64, i1 noundef zeroext %67)
  %69 = load i64, ptr %10, align 8, !tbaa !5
  %70 = add nsw i64 %69, %68
  store i64 %70, ptr %10, align 8, !tbaa !5
  %71 = add nuw nsw i32 %.0.us28, 1
  %72 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digs, i64 noundef %4) #1
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %.not23.us.not = icmp slt i32 %.0.us28, %73
  br i1 %.not23.us.not, label %.lr.ph, label %.split25.us, !llvm.loop !11

.split25.us:                                      ; preds = %.lr.ph, %.split.preheader, %.split.us
  %74 = load i64, ptr %10, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %3, %.split25.us, %8
  %.1 = phi i64 [ %74, %.split25.us ], [ %11, %8 ], [ %7, %3 ]
  ret i64 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass