; LLVM IR from brpapa/algorithms :: solutions/uri/1707.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 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z2dpiib(i32 noundef %0, i32 noundef %1, i1 noundef zeroext %2) #1 {
  %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 i64, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %7, align 1, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %18

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

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x [91 x i64]], ptr @memo, i64 0, i64 %20
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [91 x i64], ptr %21, i64 0, i64 %23
  store ptr %24, ptr %8, align 8, !tbaa !11
  %25 = load ptr, ptr %8, align 8, !tbaa !11
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = icmp ne i64 %26, -1
  br i1 %27, label %28, label %34

28:                                               ; preds = %18
  %29 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %30 = trunc i8 %29 to i1
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !11
  %33 = load i64, ptr %32, align 8, !tbaa !13
  store i64 %33, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %91

34:                                               ; preds = %28, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %78, %34
  %36 = load i32, ptr %11, align 4, !tbaa !5
  %37 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %41) #3
  %43 = load i32, ptr %42, align 4, !tbaa !5
  br label %45

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44, %39
  %46 = phi i32 [ %43, %39 ], [ 9, %44 ]
  %47 = icmp sle i32 %36, %46
  br i1 %47, label %49, label %48

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

49:                                               ; preds = %45
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %57

52:                                               ; preds = %49
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = srem i32 %53, 2
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %78

57:                                               ; preds = %52, %49
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %65) #3
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = icmp eq i32 %63, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %57
  %70 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %71 = trunc i8 %70 to i1
  br label %73

72:                                               ; preds = %57
  br label %73

73:                                               ; preds = %72, %69
  %74 = phi i1 [ %71, %69 ], [ false, %72 ]
  %75 = call noundef i64 @_Z2dpiib(i32 noundef %59, i32 noundef %62, i1 noundef zeroext %74)
  %76 = load i64, ptr %10, align 8, !tbaa !13
  %77 = add nsw i64 %76, %75
  store i64 %77, ptr %10, align 8, !tbaa !13
  br label %78

78:                                               ; preds = %73, %56
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !5
  br label %35, !llvm.loop !17

81:                                               ; preds = %48
  %82 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %83 = trunc i8 %82 to i1
  br i1 %83, label %84, label %86

84:                                               ; preds = %81
  %85 = load i64, ptr %10, align 8, !tbaa !13
  br label %89

86:                                               ; preds = %81
  %87 = load i64, ptr %10, align 8, !tbaa !13
  %88 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 %87, ptr %88, align 8, !tbaa !13
  br label %89

89:                                               ; preds = %86, %84
  %90 = phi i64 [ %85, %84 ], [ %87, %86 ]
  store i64 %90, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %91

91:                                               ; preds = %89, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %92

92:                                               ; preds = %91, %15
  %93 = load i64, ptr %4, align 8
  ret i64 %93
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!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 }

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

; 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 = icmp eq i32 %0, -1
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = sext i32 %1 to i64
  br label %common.ret

7:                                                ; preds = %3
  %8 = sext i32 %0 to i64
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [10 x [91 x i64]], ptr @memo, i64 0, i64 %8, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.not = icmp eq i64 %11, -1
  %brmerge = or i1 %.not, %2
  br i1 %brmerge, label %.preheader, label %common.ret

.preheader:                                       ; preds = %7
  %12 = icmp eq i32 %0, 0
  %13 = add nsw i32 %0, -1
  br i1 %2, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not29.us38 = icmp slt i32 %15, 0
  br i1 %.not29.us38, label %common.ret, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader.split.us
  br i1 %12, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.0.us40.us = phi i32 [ %22, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %.024.us39.us = phi i64 [ %21, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %16 = add nsw i32 %.0.us40.us, %1
  %17 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %.0.us40.us, %18
  %20 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %16, i1 noundef zeroext %19)
  %21 = add nsw i64 %20, %.024.us39.us
  %22 = add nuw nsw i32 %.0.us40.us, 1
  %23 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %.not29.us.us.not = icmp slt i32 %.0.us40.us, %24
  br i1 %.not29.us.us.not, label %.lr.ph.split.us, label %common.ret, !llvm.loop !11

.lr.ph.split:                                     ; preds = %.lr.ph, %34
  %.0.us40 = phi i32 [ %35, %34 ], [ 0, %.lr.ph ]
  %.024.us39 = phi i64 [ %.1.us, %34 ], [ 0, %.lr.ph ]
  %25 = and i32 %.0.us40, 1
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %34, label %27

27:                                               ; preds = %.lr.ph.split
  %28 = add nsw i32 %.0.us40, %1
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp eq i32 %.0.us40, %30
  %32 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %28, i1 noundef zeroext %31)
  %33 = add nsw i64 %32, %.024.us39
  br label %34

34:                                               ; preds = %27, %.lr.ph.split
  %.1.us = phi i64 [ %33, %27 ], [ %.024.us39, %.lr.ph.split ]
  %35 = add nuw nsw i32 %.0.us40, 1
  %36 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %.not29.us.not = icmp slt i32 %.0.us40, %37
  br i1 %.not29.us.not, label %.lr.ph.split, label %common.ret, !llvm.loop !11

.preheader.split:                                 ; preds = %.preheader
  br i1 %12, label %.thread.9, label %.thread.us.preheader

.thread.us.preheader:                             ; preds = %.preheader.split
  %38 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %39 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %1, i1 noundef zeroext false)
  %40 = add nsw i32 %1, 1
  %41 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %42 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %40, i1 noundef zeroext false)
  %43 = add nsw i64 %42, %39
  %44 = add nsw i32 %1, 2
  %45 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %46 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %44, i1 noundef zeroext false)
  %47 = add nsw i64 %46, %43
  %48 = add nsw i32 %1, 3
  %49 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %50 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %48, i1 noundef zeroext false)
  %51 = add nsw i64 %50, %47
  %52 = add nsw i32 %1, 4
  %53 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %54 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %52, i1 noundef zeroext false)
  %55 = add nsw i64 %54, %51
  %56 = add nsw i32 %1, 5
  %57 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %58 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %56, i1 noundef zeroext false)
  %59 = add nsw i64 %58, %55
  br label %.thread32

.thread.9:                                        ; preds = %.preheader.split
  %60 = add nsw i32 %1, 1
  %61 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %62 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %60, i1 noundef zeroext false)
  br label %.thread32

common.ret:                                       ; preds = %5, %7, %.preheader.split.us, %34, %.lr.ph.split.us, %.thread32
  %common.ret.op = phi i64 [ %78, %.thread32 ], [ %6, %5 ], [ %11, %7 ], [ 0, %.preheader.split.us ], [ %.1.us, %34 ], [ %21, %.lr.ph.split.us ]
  ret i64 %common.ret.op

.thread32:                                        ; preds = %.thread.us.preheader, %.thread.9
  %.sink57 = phi i32 [ 6, %.thread.us.preheader ], [ 3, %.thread.9 ]
  %.sink55 = phi i64 [ %59, %.thread.us.preheader ], [ %62, %.thread.9 ]
  %.sink53 = phi i32 [ 7, %.thread.us.preheader ], [ 5, %.thread.9 ]
  %.sink = phi i32 [ 8, %.thread.us.preheader ], [ 7, %.thread.9 ]
  %63 = add nsw i32 %.sink57, %1
  %64 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %65 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %63, i1 noundef zeroext false)
  %66 = add nsw i64 %65, %.sink55
  %67 = add nsw i32 %.sink53, %1
  %68 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %69 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %67, i1 noundef zeroext false)
  %70 = add nsw i64 %69, %66
  %71 = add nsw i32 %.sink, %1
  %72 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %73 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %71, i1 noundef zeroext false)
  %74 = add nsw i64 %73, %70
  %75 = add nsw i32 %1, 9
  %76 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @digits, i64 noundef %8) #1
  %77 = tail call noundef i64 @_Z2dpiib(i32 noundef %13, i32 noundef %75, i1 noundef zeroext false)
  %78 = add nsw i64 %77, %74
  store i64 %78, ptr %10, align 8, !tbaa !5
  br label %common.ret
}

; 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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass