; LLVM IR from kazunetakahashi/atcoder :: 2019/0817_AGC037 (E)

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z14initial_lengthxRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEc(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i8 noundef signext %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %44, %3
  %12 = load i64, ptr %8, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = icmp sle i64 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %17, ptr %10, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %39, %16
  %19 = load i64, ptr %10, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = mul nsw i64 2, %20
  %22 = icmp slt i64 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 5, ptr %9, align 4
  br label %42

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = load i64, ptr %10, align 8, !tbaa !5
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %25, i64 noundef %26) #3
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = load i8, ptr %6, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  %32 = icmp ne i32 %29, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  store i32 5, ptr %9, align 4
  br label %42

34:                                               ; preds = %24
  %35 = load i64, ptr %10, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  %37 = load i64, ptr %8, align 8, !tbaa !5
  %38 = sub nsw i64 %36, %37
  call void @_Z6ch_maxIxEvRT_S0_(ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %38)
  br label %39

39:                                               ; preds = %34
  %40 = load i64, ptr %10, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %10, align 8, !tbaa !5
  br label %18, !llvm.loop !12

42:                                               ; preds = %33, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load i64, ptr %8, align 8, !tbaa !5
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %8, align 8, !tbaa !5
  br label %11, !llvm.loop !14

47:                                               ; preds = %15
  %48 = load i64, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %48
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6ch_maxIxEvRT_S0_(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z14initial_lengthxRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEc(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i8 noundef signext %2) local_unnamed_addr #1 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  store i64 0, ptr %4, align 8, !tbaa !5
  %.not16 = icmp slt i64 %0, 0
  br i1 %.not16, label %._crit_edge18, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %5 = shl nuw nsw i64 %0, 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.01117 = phi i64 [ 0, %.preheader.lr.ph ], [ %14, %._crit_edge ]
  %6 = icmp ult i64 %.01117, %5
  br i1 %6, label %.lr.ph, label %._crit_edge

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

._crit_edge18:                                    ; preds = %._crit_edge18.loopexit, %3
  %7 = phi i64 [ %.pre, %._crit_edge18.loopexit ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %7

.lr.ph:                                           ; preds = %.preheader, %10
  %.014 = phi i64 [ %11, %10 ], [ %.01117, %.preheader ]
  %8 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %.014) #2
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %.not13 = icmp eq i8 %9, %2
  br i1 %.not13, label %10, label %._crit_edge

10:                                               ; preds = %.lr.ph
  %11 = add nuw nsw i64 %.014, 1
  %12 = sub nuw nsw i64 %11, %.01117
  call void @_Z6ch_maxIxEvRT_S0_(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %12)
  %13 = icmp ult i64 %11, %5
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %10, %.lr.ph, %.preheader
  %14 = add nuw i64 %.01117, 1
  %exitcond.not = icmp eq i64 %.01117, %0
  br i1 %exitcond.not, label %._crit_edge18.loopexit, label %.preheader, !llvm.loop !12
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6ch_maxIxEvRT_S0_(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1

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


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