; LLVM IR from ral99/knuckleball :: src (grammar)

; 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 i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7Grammar15is_string_valueERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(32) %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %8) #2
  %10 = icmp ult i64 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %120

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %13, i64 noundef 0) #2
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 34
  br i1 %17, label %29, label %18

18:                                               ; preds = %12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %20) #2
  %22 = trunc i64 %21 to i32
  %23 = sub nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %19, i64 noundef %24) #2
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 34
  br i1 %28, label %29, label %30

29:                                               ; preds = %18, %12
  store i1 false, ptr %2, align 1
  br label %120

30:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !10
  br label %31

31:                                               ; preds = %78, %30
  %32 = load i32, ptr %4, align 4, !tbaa !10
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %33) #2
  %35 = trunc i64 %34 to i32
  %36 = sub nsw i32 %35, 1
  %37 = icmp slt i32 %32, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  store i32 2, ptr %5, align 4
  br label %81

39:                                               ; preds = %31
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %40, i64 noundef %42) #2
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 34
  br i1 %46, label %47, label %77

47:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %48 = load i32, ptr %4, align 4, !tbaa !10
  %49 = sub nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !10
  br label %50

50:                                               ; preds = %71, %47
  %51 = load i32, ptr %6, align 4, !tbaa !10
  %52 = icmp sge i32 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  store i32 5, ptr %5, align 4
  br label %74

54:                                               ; preds = %50
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !10
  %57 = sext i32 %56 to i64
  %58 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %55, i64 noundef %57) #2
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = sext i8 %59 to i32
  %61 = icmp ne i32 %60, 92
  br i1 %61, label %62, label %70

62:                                               ; preds = %54
  %63 = load i32, ptr %4, align 4, !tbaa !10
  %64 = load i32, ptr %6, align 4, !tbaa !10
  %65 = sub nsw i32 %63, %64
  %66 = srem i32 %65, 2
  %67 = icmp eq i32 %66, 1
  br i1 %67, label %68, label %69

68:                                               ; preds = %62
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %74

69:                                               ; preds = %62
  store i32 5, ptr %5, align 4
  br label %74

70:                                               ; preds = %54
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %6, align 4, !tbaa !10
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %6, align 4, !tbaa !10
  br label %50, !llvm.loop !12

74:                                               ; preds = %69, %68, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %75 = load i32, ptr %5, align 4
  switch i32 %75, label %81 [
    i32 5, label %76
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %39
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %4, align 4, !tbaa !10
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %4, align 4, !tbaa !10
  br label %31, !llvm.loop !14

81:                                               ; preds = %74, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %82 = load i32, ptr %5, align 4
  switch i32 %82, label %122 [
    i32 2, label %83
    i32 1, label %120
  ]

83:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %84) #2
  %86 = trunc i64 %85 to i32
  %87 = sub nsw i32 %86, 2
  store i32 %87, ptr %7, align 4, !tbaa !10
  br label %88

88:                                               ; preds = %110, %83
  %89 = load i32, ptr %7, align 4, !tbaa !10
  %90 = icmp sgt i32 %89, 0
  br i1 %90, label %92, label %91

91:                                               ; preds = %88
  store i32 8, ptr %5, align 4
  br label %113

92:                                               ; preds = %88
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = load i32, ptr %7, align 4, !tbaa !10
  %95 = sext i32 %94 to i64
  %96 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %93, i64 noundef %95) #2
  %97 = load i8, ptr %96, align 1, !tbaa !9
  %98 = sext i8 %97 to i32
  %99 = icmp ne i32 %98, 92
  br i1 %99, label %100, label %109

100:                                              ; preds = %92
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %101) #2
  %103 = trunc i64 %102 to i32
  %104 = sub nsw i32 %103, 1
  %105 = load i32, ptr %7, align 4, !tbaa !10
  %106 = sub nsw i32 %104, %105
  %107 = srem i32 %106, 2
  %108 = icmp eq i32 %107, 1
  store i1 %108, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %113

109:                                              ; preds = %92
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %7, align 4, !tbaa !10
  %112 = add nsw i32 %111, -1
  store i32 %112, ptr %7, align 4, !tbaa !10
  br label %88, !llvm.loop !15

113:                                              ; preds = %100, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %114 = load i32, ptr %5, align 4
  switch i32 %114, label %122 [
    i32 8, label %115
    i32 1, label %120
  ]

115:                                              ; preds = %113
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %116) #2
  %118 = urem i64 %117, 2
  %119 = icmp eq i64 %118, 0
  store i1 %119, ptr %2, align 1
  br label %120

120:                                              ; preds = %115, %113, %81, %29, %11
  %121 = load i1, ptr %2, align 1
  ret i1 %121

122:                                              ; preds = %113, %81
  unreachable
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !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 nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; 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 #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7Grammar15is_string_valueERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %3 = icmp ult i64 %2, 2
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 0) #1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 34
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %9 = shl i64 %8, 32
  %sext = add i64 %9, -4294967296
  %10 = ashr exact i64 %sext, 32
  %11 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %10) #1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not33 = icmp eq i8 %12, 34
  br i1 %.not33, label %.preheader51, label %.loopexit

.preheader51:                                     ; preds = %7
  %13 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %14 = trunc i64 %13 to i32
  %15 = icmp sgt i32 %14, 2
  br i1 %15, label %.lr.ph, label %.thread41

.lr.ph:                                           ; preds = %.preheader51, %.thread
  %indvars.iv = phi i64 [ %indvars.iv.next, %.thread ], [ 1, %.preheader51 ]
  %16 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv) #1
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = icmp eq i8 %17, 34
  br i1 %18, label %.preheader, label %.thread

.preheader:                                       ; preds = %.lr.ph, %20
  %indvars.iv58 = phi i64 [ %21, %20 ], [ %indvars.iv, %.lr.ph ]
  %19 = icmp sgt i64 %indvars.iv58, 0
  br i1 %19, label %20, label %.thread

20:                                               ; preds = %.preheader
  %21 = add nsw i64 %indvars.iv58, -1
  %22 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %21) #1
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %.not34 = icmp eq i8 %23, 92
  br i1 %.not34, label %.preheader, label %24, !llvm.loop !8

24:                                               ; preds = %20
  %25 = trunc i64 %21 to i32
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  %27 = sub nsw i32 %26, %25
  %28 = and i32 %27, -2147483647
  %.not50 = icmp eq i32 %28, 1
  br i1 %.not50, label %.loopexit, label %.thread

.thread:                                          ; preds = %.preheader, %.lr.ph, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %30 = shl i64 %29, 32
  %sext66 = add i64 %30, -4294967296
  %31 = ashr exact i64 %sext66, 32
  %32 = icmp slt i64 %indvars.iv.next, %31
  br i1 %32, label %.lr.ph, label %.thread41, !llvm.loop !10

.thread41:                                        ; preds = %.thread, %.preheader51
  %33 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %34 = trunc i64 %33 to i32
  %35 = icmp sgt i32 %34, 2
  br i1 %35, label %.lr.ph56.preheader, label %._crit_edge

.lr.ph56.preheader:                               ; preds = %.thread41
  %36 = add i64 %33, 4294967294
  %37 = and i64 %36, 4294967295
  br label %.lr.ph56

.lr.ph56:                                         ; preds = %.lr.ph56.preheader, %40
  %indvars.iv63 = phi i64 [ %37, %.lr.ph56.preheader ], [ %indvars.iv.next64, %40 ]
  %38 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv63) #1
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %.not35 = icmp eq i8 %39, 92
  br i1 %.not35, label %40, label %42

40:                                               ; preds = %.lr.ph56
  %indvars.iv.next64 = add nsw i64 %indvars.iv63, -1
  %41 = icmp sgt i64 %indvars.iv63, 1
  br i1 %41, label %.lr.ph56, label %._crit_edge, !llvm.loop !11

42:                                               ; preds = %.lr.ph56
  %43 = trunc nuw nsw i64 %indvars.iv63 to i32
  %44 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %45 = trunc i64 %44 to i32
  %46 = sub i32 %43, %45
  %47 = and i32 %46, -2147483647
  %48 = icmp eq i32 %47, -2147483648
  br label %.loopexit

._crit_edge:                                      ; preds = %40, %.thread41
  %49 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %50 = and i64 %49, 1
  %51 = icmp eq i64 %50, 0
  br label %.loopexit

.loopexit:                                        ; preds = %24, %42, %4, %7, %1, %._crit_edge
  %.5 = phi i1 [ %48, %42 ], [ %51, %._crit_edge ], [ false, %1 ], [ false, %7 ], [ false, %4 ], [ false, %24 ]
  ret i1 %.5
}

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass