; LLVM IR from eyangch/competitive-programming :: Codeforces/1107/e.ll (Z3dpfxxx)

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

@A = external dso_local global [100 x i64], align 16
@dp = external dso_local global [100 x [100 x [100 x i64]]], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dpfxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = icmp sgt i64 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i64 0, ptr %4, align 8
  br label %89

15:                                               ; preds = %3
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds [100 x [100 x [100 x i64]]], ptr @dp, i64 0, i64 %16
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds [100 x [100 x i64]], ptr %17, i64 0, i64 %18
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds [100 x i64], ptr %19, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i64 %22, 0
  br i1 %23, label %24, label %32

24:                                               ; preds = %15
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds [100 x [100 x [100 x i64]]], ptr @dp, i64 0, i64 %25
  %27 = load i64, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds [100 x [100 x i64]], ptr %26, i64 0, i64 %27
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds [100 x i64], ptr %28, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  store i64 %31, ptr %4, align 8
  br label %89

32:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = icmp sgt i64 %33, 0
  br i1 %34, label %35, label %45

35:                                               ; preds = %32
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = sub nsw i64 %36, 1
  %38 = getelementptr inbounds [100 x i64], ptr @A, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = call noundef i64 @_Z3dpfxxx(i64 noundef %41, i64 noundef %42, i64 noundef 1)
  %44 = add nsw i64 %39, %43
  store i64 %44, ptr %8, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %35, %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %9, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %78, %45
  %49 = load i64, ptr %9, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !5
  %51 = icmp sle i64 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %81

53:                                               ; preds = %48
  %54 = load i64, ptr %9, align 8, !tbaa !5
  %55 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %54)
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = load i64, ptr %5, align 8, !tbaa !5
  %59 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %58)
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %57, %61
  br i1 %62, label %63, label %77

63:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %64 = load i64, ptr %5, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  %66 = load i64, ptr %9, align 8, !tbaa !5
  %67 = sub nsw i64 %66, 1
  %68 = call noundef i64 @_Z3dpfxxx(i64 noundef %65, i64 noundef %67, i64 noundef 1)
  %69 = load i64, ptr %9, align 8, !tbaa !5
  %70 = load i64, ptr %6, align 8, !tbaa !5
  %71 = load i64, ptr %7, align 8, !tbaa !5
  %72 = add nsw i64 %71, 1
  %73 = call noundef i64 @_Z3dpfxxx(i64 noundef %69, i64 noundef %70, i64 noundef %72)
  %74 = add nsw i64 %68, %73
  store i64 %74, ptr %10, align 8, !tbaa !5
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %76 = load i64, ptr %75, align 8, !tbaa !5
  store i64 %76, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %77

77:                                               ; preds = %63, %53
  br label %78

78:                                               ; preds = %77
  %79 = load i64, ptr %9, align 8, !tbaa !5
  %80 = add nsw i64 %79, 1
  store i64 %80, ptr %9, align 8, !tbaa !5
  br label %48, !llvm.loop !10

81:                                               ; preds = %52
  %82 = load i64, ptr %8, align 8, !tbaa !5
  %83 = load i64, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds [100 x [100 x [100 x i64]]], ptr @dp, i64 0, i64 %83
  %85 = load i64, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds [100 x [100 x i64]], ptr %84, i64 0, i64 %85
  %87 = load i64, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds [100 x i64], ptr %86, i64 0, i64 %87
  store i64 %82, ptr %88, align 8, !tbaa !5
  store i64 %82, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %89

89:                                               ; preds = %81, %24, %14
  %90 = load i64, ptr %4, align 8
  ret i64 %90
}

; 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 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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::__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] }

@A = external dso_local local_unnamed_addr global [100 x i64], align 16
@dp = external dso_local local_unnamed_addr global [100 x [100 x [100 x i64]]], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3dpfxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = icmp sgt i64 %0, %1
  br i1 %6, label %39, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds [100 x [100 x [100 x i64]]], ptr @dp, i64 0, i64 %0, i64 %1, i64 %2
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %39, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  %12 = icmp sgt i64 %2, 0
  br i1 %12, label %13, label %._crit_edge34

._crit_edge34:                                    ; preds = %11
  %.pre35 = add nsw i64 %0, 1
  br label %20

13:                                               ; preds = %11
  %14 = add nsw i64 %2, -1
  %15 = getelementptr inbounds [100 x i64], ptr @A, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %0, 1
  %18 = tail call noundef i64 @_Z3dpfxxx(i64 noundef %17, i64 noundef %1, i64 noundef 1)
  %19 = add nsw i64 %18, %16
  store i64 %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %._crit_edge34, %13
  %.pre-phi = phi i64 [ %.pre35, %._crit_edge34 ], [ %17, %13 ]
  %21 = phi i64 [ 0, %._crit_edge34 ], [ %19, %13 ]
  %.not32.not = icmp slt i64 %0, %1
  br i1 %.not32.not, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20
  %22 = add nsw i64 %2, 1
  br label %24

._crit_edge.loopexit:                             ; preds = %37
  %.pre = load i64, ptr %4, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %20
  %23 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %21, %20 ]
  store i64 %23, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %39

24:                                               ; preds = %.lr.ph, %37
  %.033 = phi i64 [ %.pre-phi, %.lr.ph ], [ %38, %37 ]
  %25 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %.033)
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %0)
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = icmp eq i8 %26, %28
  br i1 %29, label %30, label %37

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %31 = add nsw i64 %.033, -1
  %32 = call noundef i64 @_Z3dpfxxx(i64 noundef %.pre-phi, i64 noundef %31, i64 noundef 1)
  %33 = call noundef i64 @_Z3dpfxxx(i64 noundef %.033, i64 noundef %1, i64 noundef %22)
  %34 = add nsw i64 %33, %32
  store i64 %34, ptr %5, align 8, !tbaa !5
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %36 = load i64, ptr %35, align 8, !tbaa !5
  store i64 %36, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %37

37:                                               ; preds = %24, %30
  %38 = add i64 %.033, 1
  %exitcond.not = icmp eq i64 %.033, %1
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %24, !llvm.loop !10

39:                                               ; preds = %7, %3, %._crit_edge
  %.027 = phi i64 [ %23, %._crit_edge ], [ 0, %3 ], [ %9, %7 ]
  ret i64 %.027
}

; 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 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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