; LLVM IR from brpapa/algorithms :: solutions/spoj/EDIST.ll (Z4edTDii)

; 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] }

@memo = external dso_local global [2020 x [2020 x i32]], align 16
@_Z1aB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1bB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4edTDii(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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %3, align 4
  br label %94

17:                                               ; preds = %2
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4
  br label %94

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

33:                                               ; preds = %23
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %93

36:                                               ; preds = %23
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1aB5cxx11, i64 noundef %38)
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1bB5cxx11, i64 noundef %43)
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %41, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %36
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = call noundef i32 @_Z4edTDii(i32 noundef %50, i32 noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %53, ptr %54, align 4, !tbaa !5
  store i32 %53, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %93

55:                                               ; preds = %36
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = call noundef i32 @_Z4edTDii(i32 noundef %57, i32 noundef %58)
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  %63 = call noundef i32 @_Z4edTDii(i32 noundef %60, i32 noundef %62)
  %64 = icmp slt i32 %59, %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  br i1 %64, label %65, label %77

65:                                               ; preds = %55
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sub nsw i32 %66, 1
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = call noundef i32 @_Z4edTDii(i32 noundef %67, i32 noundef %68)
  store i32 %69, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sub nsw i32 %72, 1
  %74 = call noundef i32 @_Z4edTDii(i32 noundef %71, i32 noundef %73)
  store i32 %74, ptr %9, align 4, !tbaa !5
  %75 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %76 = load i32, ptr %75, align 4, !tbaa !5
  br label %89

77:                                               ; preds = %55
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sub nsw i32 %79, 1
  %81 = call noundef i32 @_Z4edTDii(i32 noundef %78, i32 noundef %80)
  store i32 %81, ptr %10, align 4, !tbaa !5
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = sub nsw i32 %82, 1
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = sub nsw i32 %84, 1
  %86 = call noundef i32 @_Z4edTDii(i32 noundef %83, i32 noundef %85)
  store i32 %86, ptr %11, align 4, !tbaa !5
  %87 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %88 = load i32, ptr %87, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %77, %65
  %90 = phi i32 [ %76, %65 ], [ %88, %77 ]
  %91 = add nsw i32 1, %90
  %92 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %91, ptr %92, align 4, !tbaa !5
  store i32 %91, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  store i32 1, ptr %7, align 4
  br label %93

93:                                               ; preds = %89, %48, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %94

94:                                               ; preds = %93, %20, %14
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

; 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 noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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

@memo = external dso_local local_unnamed_addr global [2020 x [2020 x i32]], align 16
@_Z1aB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1bB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4edTDii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = icmp eq i32 %0, -1
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = add nsw i32 %1, 1
  br label %common.ret29

10:                                               ; preds = %2
  %11 = icmp eq i32 %1, -1
  br i1 %11, label %12, label %14

12:                                               ; preds = %10
  %13 = add nuw nsw i32 %0, 1
  br label %common.ret29

14:                                               ; preds = %10
  %15 = sext i32 %0 to i64
  %16 = sext i32 %1 to i64
  %17 = getelementptr inbounds [2020 x [2020 x i32]], ptr @memo, i64 0, i64 %15, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %18, -1
  br i1 %.not, label %19, label %common.ret29

19:                                               ; preds = %14
  %20 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1aB5cxx11, i64 noundef %15)
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1bB5cxx11, i64 noundef %16)
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp eq i8 %21, %23
  %25 = add nsw i32 %0, -1
  br i1 %24, label %26, label %29

common.ret29:                                     ; preds = %42, %14, %12, %8, %26
  %common.ret29.op = phi i32 [ %28, %26 ], [ %9, %8 ], [ %13, %12 ], [ %44, %42 ], [ %18, %14 ]
  ret i32 %common.ret29.op

26:                                               ; preds = %19
  %27 = add nsw i32 %1, -1
  %28 = tail call noundef i32 @_Z4edTDii(i32 noundef %25, i32 noundef %27)
  store i32 %28, ptr %17, align 4, !tbaa !5
  br label %common.ret29

29:                                               ; preds = %19
  %30 = tail call noundef i32 @_Z4edTDii(i32 noundef %25, i32 noundef %1)
  %31 = add nsw i32 %1, -1
  %32 = tail call noundef i32 @_Z4edTDii(i32 noundef %0, i32 noundef %31)
  %33 = icmp slt i32 %30, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  br i1 %33, label %34, label %38

34:                                               ; preds = %29
  %35 = tail call noundef i32 @_Z4edTDii(i32 noundef %25, i32 noundef %1)
  store i32 %35, ptr %3, align 4, !tbaa !5
  %36 = tail call noundef i32 @_Z4edTDii(i32 noundef %25, i32 noundef %31)
  store i32 %36, ptr %4, align 4, !tbaa !5
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %42

38:                                               ; preds = %29
  %39 = tail call noundef i32 @_Z4edTDii(i32 noundef %0, i32 noundef %31)
  store i32 %39, ptr %5, align 4, !tbaa !5
  %40 = tail call noundef i32 @_Z4edTDii(i32 noundef %25, i32 noundef %31)
  store i32 %40, ptr %6, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %42

42:                                               ; preds = %38, %34
  %.in = phi ptr [ %37, %34 ], [ %41, %38 ]
  %43 = load i32, ptr %.in, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %common.ret29
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!7, !7, i64 0}


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