; LLVM IR from eyangch/competitive-programming :: Codeforces/1536/b.ll/Z3subxcccRNSt7 (cxx1112basic_stringIcSt11char_traitsIcESaIcEEE)

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

@N = external dso_local global i64, align 8

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

15:                                               ; preds = %69, %5
  %16 = load i64, ptr %12, align 8, !tbaa !5
  %17 = load i64, ptr @N, align 8, !tbaa !5
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = sub nsw i64 %17, %18
  %20 = add nsw i64 %19, 1
  %21 = icmp slt i64 %16, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %15
  store i32 2, ptr %13, align 4
  br label %72

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  store i8 1, ptr %14, align 1, !tbaa !12
  %24 = load ptr, ptr %11, align 8, !tbaa !10
  %25 = load i64, ptr %12, align 8, !tbaa !5
  %26 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %24, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = load i8, ptr %8, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = icmp ne i32 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %23
  store i8 0, ptr %14, align 1, !tbaa !12
  br label %33

33:                                               ; preds = %32, %23
  %34 = load i64, ptr %7, align 8, !tbaa !5
  %35 = icmp sgt i64 %34, 1
  br i1 %35, label %36, label %47

36:                                               ; preds = %33
  %37 = load ptr, ptr %11, align 8, !tbaa !10
  %38 = load i64, ptr %12, align 8, !tbaa !5
  %39 = add nsw i64 %38, 1
  %40 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %37, i64 noundef %39)
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = load i8, ptr %9, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp ne i32 %42, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %36
  store i8 0, ptr %14, align 1, !tbaa !12
  br label %47

47:                                               ; preds = %46, %36, %33
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = icmp sgt i64 %48, 2
  br i1 %49, label %50, label %61

50:                                               ; preds = %47
  %51 = load ptr, ptr %11, align 8, !tbaa !10
  %52 = load i64, ptr %12, align 8, !tbaa !5
  %53 = add nsw i64 %52, 2
  %54 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %51, i64 noundef %53)
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = load i8, ptr %10, align 1, !tbaa !9
  %58 = sext i8 %57 to i32
  %59 = icmp ne i32 %56, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %50
  store i8 0, ptr %14, align 1, !tbaa !12
  br label %61

61:                                               ; preds = %60, %50, %47
  %62 = load i8, ptr %14, align 1, !tbaa !12, !range !14, !noundef !15
  %63 = trunc i8 %62 to i1
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %66

65:                                               ; preds = %61
  store i32 0, ptr %13, align 4
  br label %66

66:                                               ; preds = %65, %64
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  %67 = load i32, ptr %13, align 4
  switch i32 %67, label %72 [
    i32 0, label %68
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %12, align 8, !tbaa !5
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %12, align 8, !tbaa !5
  br label %15, !llvm.loop !16

72:                                               ; preds = %66, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %73 = load i32, ptr %13, align 4
  switch i32 %73, label %77 [
    i32 2, label %74
    i32 1, label %75
  ]

74:                                               ; preds = %72
  store i1 true, ptr %6, align 1
  br label %75

75:                                               ; preds = %74, %72
  %76 = load i1, ptr %6, align 1
  ret i1 %76

77:                                               ; preds = %72
  unreachable
}

; 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: 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 = { 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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@N = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3subxcccRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(i64 noundef %0, i8 noundef signext %1, i8 noundef signext %2, i8 noundef signext %3, ptr noundef nonnull align 8 dereferenceable(32) %4) local_unnamed_addr #0 {
  %6 = load i64, ptr @N, align 8, !tbaa !5
  %.not31 = icmp slt i64 %6, %0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = icmp sgt i64 %0, 1
  br i1 %7, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %.not30 = icmp eq i64 %0, 2
  br i1 %.not30, label %.lr.ph.split.us.split.us, label %.thread.us

.lr.ph.split.us.split.us:                         ; preds = %.lr.ph.split.us
  %8 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef 0)
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %.not23.us.us41 = icmp eq i8 %9, %1
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef 1)
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %.not24.us.us42 = icmp eq i8 %11, %2
  %spec.select26.us.us43 = select i1 %.not24.us.us42, i1 %.not23.us.us41, i1 false
  br i1 %spec.select26.us.us43, label %._crit_edge, label %.lr.ph44

.thread.us.us:                                    ; preds = %.lr.ph44
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %17)
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %.not23.us.us = icmp eq i8 %13, %1
  %14 = add nuw nsw i64 %17, 1
  %15 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %14)
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %.not24.us.us = icmp eq i8 %16, %2
  %spec.select26.us.us = select i1 %.not24.us.us, i1 %.not23.us.us, i1 false
  br i1 %spec.select26.us.us, label %._crit_edge, label %.lr.ph44, !llvm.loop !10

.lr.ph44:                                         ; preds = %.lr.ph.split.us.split.us, %.thread.us.us
  %17 = phi i64 [ %14, %.thread.us.us ], [ 1, %.lr.ph.split.us.split.us ]
  %18 = load i64, ptr @N, align 8, !tbaa !5
  %19 = add nsw i64 %18, -2
  %.not.us.us = icmp sgt i64 %17, %19
  br i1 %.not.us.us, label %._crit_edge, label %.thread.us.us, !llvm.loop !10

.thread.us:                                       ; preds = %.lr.ph.split.us, %28
  %.01932.us = phi i64 [ %22, %28 ], [ 0, %.lr.ph.split.us ]
  %20 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %.01932.us)
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %.not23.us = icmp ne i8 %21, %1
  %22 = add nuw nsw i64 %.01932.us, 1
  %23 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %22)
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %.not24.us = icmp ne i8 %24, %2
  %25 = add nuw nsw i64 %.01932.us, 2
  %26 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %.not25.us = icmp ne i8 %27, %3
  %.not50 = select i1 %.not25.us, i1 true, i1 %.not24.us
  %spec.select27.us.not = select i1 %.not50, i1 true, i1 %.not23.us
  br i1 %spec.select27.us.not, label %28, label %._crit_edge

28:                                               ; preds = %.thread.us
  %29 = load i64, ptr @N, align 8, !tbaa !5
  %30 = sub nsw i64 %29, %0
  %.not.us.not = icmp slt i64 %.01932.us, %30
  br i1 %.not.us.not, label %.thread.us, label %._crit_edge, !llvm.loop !10

.lr.ph.split:                                     ; preds = %.lr.ph
  %31 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef 0)
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %.not2336 = icmp eq i8 %32, %1
  br i1 %.not2336, label %._crit_edge, label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph.split, %.thread
  %33 = phi i64 [ %38, %.thread ], [ 1, %.lr.ph.split ]
  %34 = load i64, ptr @N, align 8, !tbaa !5
  %35 = sub nsw i64 %34, %0
  %.not = icmp sgt i64 %33, %35
  br i1 %.not, label %._crit_edge, label %.thread, !llvm.loop !10

.thread:                                          ; preds = %.lr.ph37
  %36 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %4, i64 noundef %33)
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %.not23 = icmp eq i8 %37, %1
  %38 = add nuw nsw i64 %33, 1
  br i1 %.not23, label %._crit_edge, label %.lr.ph37, !llvm.loop !10

._crit_edge:                                      ; preds = %.thread, %.lr.ph37, %.thread.us, %28, %.thread.us.us, %.lr.ph44, %.lr.ph.split.us.split.us, %.lr.ph.split, %5
  %.not.lcssa = phi i1 [ true, %5 ], [ false, %.lr.ph.split.us.split.us ], [ false, %.lr.ph.split ], [ %.not.us.us, %.lr.ph44 ], [ %.not.us.us, %.thread.us.us ], [ %spec.select27.us.not, %28 ], [ %spec.select27.us.not, %.thread.us ], [ %.not, %.lr.ph37 ], [ %.not, %.thread ]
  ret i1 %.not.lcssa
}

; 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 = !{!"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: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass