; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1553_C.ll/Z5solveRNSt7 (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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solveRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(32) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %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
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 5, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 5, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 10, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %73, %1
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 10
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %9, align 4
  br label %76

14:                                               ; preds = %10
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = srem i32 %15, 2
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %32

18:                                               ; preds = %14
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %4, align 4, !tbaa !9
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %21, i64 noundef %23)
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 49
  br i1 %27, label %28, label %31

28:                                               ; preds = %18
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %28, %18
  br label %46

32:                                               ; preds = %14
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %3, align 4, !tbaa !9
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %35, i64 noundef %37)
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 49
  br i1 %41, label %42, label %45

42:                                               ; preds = %32
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %42, %32
  br label %46

46:                                               ; preds = %45, %31
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = icmp sgt i32 %47, %48
  br i1 %49, label %50, label %61

50:                                               ; preds = %46
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = sub nsw i32 %52, %53
  %55 = call i32 @llvm.abs.i32(i32 %54, i1 true)
  %56 = icmp slt i32 %51, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %50
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !9
  store i32 2, ptr %9, align 4
  br label %76

60:                                               ; preds = %50
  br label %72

61:                                               ; preds = %46
  %62 = load i32, ptr %3, align 4, !tbaa !9
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sub nsw i32 %63, %64
  %66 = call i32 @llvm.abs.i32(i32 %65, i1 true)
  %67 = icmp slt i32 %62, %66
  br i1 %67, label %68, label %71

68:                                               ; preds = %61
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %7, align 4, !tbaa !9
  store i32 2, ptr %9, align 4
  br label %76

71:                                               ; preds = %61
  br label %72

72:                                               ; preds = %71, %60
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !12

76:                                               ; preds = %68, %57, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %77

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

; 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 speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, 11) i32 @_Z5solveRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 {
  %2 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 0)
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 49
  %5 = zext i1 %4 to i32
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  %8 = icmp sgt i32 %5, 5
  br i1 %8, label %.loopexit, label %11

9:                                                ; preds = %1
  %10 = icmp slt i32 %5, -4
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %7, %9
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 1)
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp eq i8 %13, 49
  %15 = zext i1 %14 to i32
  %16 = icmp sgt i32 %5, %15
  br i1 %16, label %19, label %17

17:                                               ; preds = %11
  %.neg.1 = sub nsw i32 %15, %5
  %18 = icmp sgt i32 %.neg.1, 4
  br i1 %18, label %.loopexit, label %22

19:                                               ; preds = %11
  %20 = sub nsw i32 %5, %15
  %21 = icmp sgt i32 %20, 4
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %19, %17
  %23 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 2)
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = icmp eq i8 %24, 49
  %26 = zext i1 %25 to i32
  %spec.select29.2 = add nsw i32 %5, %26
  %27 = icmp sgt i32 %spec.select29.2, %15
  br i1 %27, label %30, label %28

28:                                               ; preds = %22
  %.neg.2 = sub nsw i32 %15, %spec.select29.2
  %29 = icmp sgt i32 %.neg.2, 3
  br i1 %29, label %.loopexit, label %33

30:                                               ; preds = %22
  %31 = sub nsw i32 %spec.select29.2, %15
  %32 = icmp sgt i32 %31, 4
  br i1 %32, label %.loopexit, label %33

33:                                               ; preds = %30, %28
  %34 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 3)
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = icmp eq i8 %35, 49
  %37 = zext i1 %36 to i32
  %spec.select.3 = add nsw i32 %15, %37
  %38 = icmp sgt i32 %spec.select29.2, %spec.select.3
  br i1 %38, label %41, label %39

39:                                               ; preds = %33
  %.neg.3 = sub nsw i32 %spec.select.3, %spec.select29.2
  %40 = icmp sgt i32 %.neg.3, 3
  br i1 %40, label %.loopexit, label %44

41:                                               ; preds = %33
  %42 = sub nsw i32 %spec.select29.2, %spec.select.3
  %43 = icmp sgt i32 %42, 3
  br i1 %43, label %.loopexit, label %44

44:                                               ; preds = %41, %39
  %45 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 4)
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = icmp eq i8 %46, 49
  %48 = zext i1 %47 to i32
  %spec.select29.4 = add nsw i32 %spec.select29.2, %48
  %49 = icmp sgt i32 %spec.select29.4, %spec.select.3
  br i1 %49, label %52, label %50

50:                                               ; preds = %44
  %.neg.4 = sub nsw i32 %spec.select.3, %spec.select29.4
  %51 = icmp sgt i32 %.neg.4, 2
  br i1 %51, label %.loopexit, label %55

52:                                               ; preds = %44
  %53 = sub nsw i32 %spec.select29.4, %spec.select.3
  %54 = icmp sgt i32 %53, 3
  br i1 %54, label %.loopexit, label %55

55:                                               ; preds = %52, %50
  %56 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 5)
  %57 = load i8, ptr %56, align 1, !tbaa !5
  %58 = icmp eq i8 %57, 49
  %59 = zext i1 %58 to i32
  %spec.select.5 = add nsw i32 %spec.select.3, %59
  %60 = icmp sgt i32 %spec.select29.4, %spec.select.5
  br i1 %60, label %63, label %61

61:                                               ; preds = %55
  %.neg.5 = sub nsw i32 %spec.select.5, %spec.select29.4
  %62 = icmp sgt i32 %.neg.5, 2
  br i1 %62, label %.loopexit, label %66

63:                                               ; preds = %55
  %64 = sub nsw i32 %spec.select29.4, %spec.select.5
  %65 = icmp sgt i32 %64, 2
  br i1 %65, label %.loopexit, label %66

66:                                               ; preds = %63, %61
  %67 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 6)
  %68 = load i8, ptr %67, align 1, !tbaa !5
  %69 = icmp eq i8 %68, 49
  %70 = zext i1 %69 to i32
  %spec.select29.6 = add nsw i32 %spec.select29.4, %70
  %71 = icmp sgt i32 %spec.select29.6, %spec.select.5
  br i1 %71, label %74, label %72

72:                                               ; preds = %66
  %.neg.6 = sub nsw i32 %spec.select.5, %spec.select29.6
  %73 = icmp sgt i32 %.neg.6, 1
  br i1 %73, label %.loopexit, label %77

74:                                               ; preds = %66
  %75 = sub nsw i32 %spec.select29.6, %spec.select.5
  %76 = icmp sgt i32 %75, 2
  br i1 %76, label %.loopexit, label %77

77:                                               ; preds = %74, %72
  %78 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 7)
  %79 = load i8, ptr %78, align 1, !tbaa !5
  %80 = icmp eq i8 %79, 49
  %81 = zext i1 %80 to i32
  %spec.select.7 = add nsw i32 %spec.select.5, %81
  %82 = icmp sgt i32 %spec.select29.6, %spec.select.7
  br i1 %82, label %85, label %83

83:                                               ; preds = %77
  %.neg.7 = sub nsw i32 %spec.select.7, %spec.select29.6
  %84 = icmp sgt i32 %.neg.7, 1
  br i1 %84, label %.loopexit, label %88

85:                                               ; preds = %77
  %86 = sub nsw i32 %spec.select29.6, %spec.select.7
  %87 = icmp sgt i32 %86, 1
  br i1 %87, label %.loopexit, label %88

88:                                               ; preds = %85, %83
  %89 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 8)
  %90 = load i8, ptr %89, align 1, !tbaa !5
  %91 = icmp eq i8 %90, 49
  %92 = zext i1 %91 to i32
  %spec.select29.8 = add nsw i32 %spec.select29.6, %92
  %93 = icmp sgt i32 %spec.select29.8, %spec.select.7
  br i1 %93, label %96, label %94

94:                                               ; preds = %88
  %95 = icmp sgt i32 %spec.select.7, %spec.select29.8
  br i1 %95, label %.loopexit, label %99

96:                                               ; preds = %88
  %97 = sub nsw i32 %spec.select29.8, %spec.select.7
  %98 = icmp sgt i32 %97, 1
  br i1 %98, label %.loopexit, label %99

99:                                               ; preds = %96, %94
  %100 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 9)
  br label %.loopexit

.loopexit:                                        ; preds = %99, %9, %17, %28, %39, %50, %61, %72, %83, %94, %7, %19, %30, %41, %52, %63, %74, %85, %96
  %.021 = phi i32 [ 1, %7 ], [ 2, %19 ], [ 3, %30 ], [ 4, %41 ], [ 5, %52 ], [ 6, %63 ], [ 7, %74 ], [ 8, %85 ], [ 9, %96 ], [ 1, %9 ], [ 2, %17 ], [ 3, %28 ], [ 4, %39 ], [ 5, %50 ], [ 6, %61 ], [ 7, %72 ], [ 8, %83 ], [ 9, %94 ], [ 10, %99 ]
  ret i32 %.021
}

; 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: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass