; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0611_ABC039/D.ll (Z4nuriii)

; 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 [110 x %"class.std::__cxx11::basic_string"], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5validii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4nuriii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -1, ptr %6, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %48, %2
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 1
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %51

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -1, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %42, %13
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = icmp sle i32 %15, 1
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %7, align 4
  br label %45

18:                                               ; preds = %14
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = add nsw i32 %19, %20
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = call noundef zeroext i1 @_Z5validii(i32 noundef %21, i32 noundef %24)
  br i1 %25, label %26, label %41

26:                                               ; preds = %18
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [110 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %31, i64 noundef %35)
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 35
  br i1 %39, label %40, label %41

40:                                               ; preds = %26
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %45

41:                                               ; preds = %26, %18
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !10

45:                                               ; preds = %40, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %46 = load i32, ptr %7, align 4
  switch i32 %46, label %51 [
    i32 5, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !5
  br label %9, !llvm.loop !12

51:                                               ; preds = %45, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %52 = load i32, ptr %7, align 4
  switch i32 %52, label %56 [
    i32 2, label %53
    i32 1, label %54
  ]

53:                                               ; preds = %51
  store i1 true, ptr %3, align 1
  br label %54

54:                                               ; preds = %53, %51
  %55 = load i1, ptr %3, align 1
  ret i1 %55

56:                                               ; preds = %51
  unreachable
}

; 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) #0 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 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 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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 [110 x %"class.std::__cxx11::basic_string"], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5validii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z4nuriii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
.preheader:
  %2 = sext i32 %1 to i64
  %3 = sext i32 %0 to i64
  %4 = add nsw i64 %3, -1
  %5 = getelementptr inbounds [110 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %4
  %6 = add nsw i64 %2, -1
  %7 = trunc nsw i64 %6 to i32
  %8 = trunc nsw i64 %4 to i32
  %9 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %8, i32 noundef %7)
  br i1 %9, label %10, label %13

10:                                               ; preds = %.preheader
  %11 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %5, i64 noundef %6)
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not = icmp eq i8 %12, 35
  br i1 %.not, label %13, label %.loopexit.loopexit

13:                                               ; preds = %.preheader, %10
  %14 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %8, i32 noundef %1)
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %5, i64 noundef %2)
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not.1 = icmp eq i8 %17, 35
  br i1 %.not.1, label %18, label %.loopexit.loopexit

18:                                               ; preds = %15, %13
  %19 = add nsw i64 %2, 1
  %20 = trunc nsw i64 %19 to i32
  %21 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %8, i32 noundef %20)
  br i1 %21, label %22, label %.preheader.1

22:                                               ; preds = %18
  %23 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %5, i64 noundef %19)
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %.not.2 = icmp eq i8 %24, 35
  br i1 %.not.2, label %.preheader.1, label %.loopexit.loopexit

.preheader.1:                                     ; preds = %22, %18
  %25 = getelementptr inbounds [110 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %3
  %26 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %0, i32 noundef %7)
  br i1 %26, label %27, label %30

27:                                               ; preds = %.preheader.1
  %28 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %25, i64 noundef %6)
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %.not.127 = icmp eq i8 %29, 35
  br i1 %.not.127, label %30, label %.loopexit.loopexit

30:                                               ; preds = %27, %.preheader.1
  %31 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %0, i32 noundef %1)
  br i1 %31, label %32, label %35

32:                                               ; preds = %30
  %33 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %25, i64 noundef %2)
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %.not.1.1 = icmp eq i8 %34, 35
  br i1 %.not.1.1, label %35, label %.loopexit.loopexit

35:                                               ; preds = %32, %30
  %36 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %0, i32 noundef %20)
  br i1 %36, label %37, label %.preheader.2

37:                                               ; preds = %35
  %38 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %25, i64 noundef %19)
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %.not.2.1 = icmp eq i8 %39, 35
  br i1 %.not.2.1, label %.preheader.2, label %.loopexit.loopexit

.preheader.2:                                     ; preds = %37, %35
  %40 = add nsw i64 %3, 1
  %41 = getelementptr inbounds [110 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %40
  %42 = trunc nsw i64 %40 to i32
  %43 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %42, i32 noundef %7)
  br i1 %43, label %44, label %47

44:                                               ; preds = %.preheader.2
  %45 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %41, i64 noundef %6)
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %.not.228 = icmp eq i8 %46, 35
  br i1 %.not.228, label %47, label %.loopexit.loopexit

47:                                               ; preds = %44, %.preheader.2
  %48 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %42, i32 noundef %1)
  br i1 %48, label %49, label %52

49:                                               ; preds = %47
  %50 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %41, i64 noundef %2)
  %51 = load i8, ptr %50, align 1, !tbaa !5
  %.not.1.2 = icmp eq i8 %51, 35
  br i1 %.not.1.2, label %52, label %.loopexit.loopexit

52:                                               ; preds = %49, %47
  %53 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %42, i32 noundef %20)
  br i1 %53, label %54, label %.loopexit

54:                                               ; preds = %52
  %55 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %41, i64 noundef %19)
  %56 = load i8, ptr %55, align 1, !tbaa !5
  %.not.2.2 = icmp eq i8 %56, 35
  br i1 %.not.2.2, label %.loopexit, label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %54, %49, %44, %37, %32, %27, %22, %15, %10
  br label %.loopexit

.loopexit:                                        ; preds = %52, %54, %.loopexit.loopexit
  %57 = phi i1 [ false, %.loopexit.loopexit ], [ true, %54 ], [ true, %52 ]
  ret i1 %57
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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