; LLVM IR from ahr9n/psolving-paradigms :: 4.dynamic-programming/20.building-up/CodeForces 39J - Spelling Check.ll (Z2dpii)

; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1tB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@memo = external dso_local global [1000005 x [2 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11) #3
  %11 = icmp eq i64 %9, %10
  br i1 %11, label %12, label %19

12:                                               ; preds = %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000005 x [2 x i32]], ptr @memo, i64 0, i64 %14
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 %17
  store i32 1, ptr %18, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  br label %70

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

30:                                               ; preds = %19
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %69

33:                                               ; preds = %19
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %44, label %37

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = call noundef i32 @_Z2dpii(i32 noundef %39, i32 noundef 1)
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = or i32 %42, %40
  store i32 %43, ptr %41, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %37, %33
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %46)
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sub nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %53)
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %49, %56
  br i1 %57, label %58, label %66

58:                                               ; preds = %44
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = call noundef i32 @_Z2dpii(i32 noundef %60, i32 noundef %61)
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = or i32 %64, %62
  store i32 %65, ptr %63, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %58, %44
  %67 = load ptr, ptr %6, align 8, !tbaa !9
  %68 = load i32, ptr %67, align 4, !tbaa !5
  store i32 %68, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %69

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

70:                                               ; preds = %69, %12
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #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 noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1tB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@memo = external dso_local local_unnamed_addr global [1000005 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11) #1
  %5 = icmp eq i64 %4, %3
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [1000005 x [2 x i32]], ptr @memo, i64 0, i64 %3, i64 %6
  br i1 %5, label %8, label %9

8:                                                ; preds = %2
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %common.ret

9:                                                ; preds = %2
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %11, label %common.ret

11:                                               ; preds = %9
  store i32 0, ptr %7, align 4, !tbaa !5
  %.not20 = icmp eq i32 %1, 0
  br i1 %.not20, label %12, label %17

12:                                               ; preds = %11
  %13 = add nsw i32 %0, 1
  %14 = tail call noundef i32 @_Z2dpii(i32 noundef %13, i32 noundef 1)
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = or i32 %15, %14
  store i32 %16, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %12, %11
  %18 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sub nsw i32 %0, %1
  %21 = sext i32 %20 to i64
  %22 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %21)
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp eq i8 %19, %23
  br i1 %24, label %25, label %._crit_edge

._crit_edge:                                      ; preds = %17
  %.pre = load i32, ptr %7, align 4, !tbaa !5
  br label %common.ret

common.ret:                                       ; preds = %8, %9, %._crit_edge, %25
  %common.ret.op = phi i32 [ %29, %25 ], [ 1, %8 ], [ %10, %9 ], [ %.pre, %._crit_edge ]
  ret i32 %common.ret.op

25:                                               ; preds = %17
  %26 = add nsw i32 %0, 1
  %27 = tail call noundef i32 @_Z2dpii(i32 noundef %26, i32 noundef %1)
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = or i32 %28, %27
  store i32 %29, ptr %7, align 4, !tbaa !5
  br label %common.ret
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass