; LLVM IR from intel/qpl :: tools/utils/generators/deflate_generator (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"

%class.token_c = type { i8, i32 }
%"class.gz_generator::grammar_c" = type { %class.token_parser_c, ptr }
%class.token_parser_c = type { ptr, %class.token_c, i8, i32 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; 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 dso_local void @_ZN7token_cC2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12gz_generator9grammar_c7parse_mEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %class.token_c, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @_ZN7token_cC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %8 = getelementptr inbounds %"class.gz_generator::grammar_c", ptr %7, i32 0, i32 0
  %9 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef %3)
  store i8 %9, ptr %4, align 1, !tbaa !9
  %10 = load i8, ptr %4, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %17, label %13

13:                                               ; preds = %1
  %14 = load i8, ptr %4, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %13, %1
  %18 = getelementptr inbounds %"class.gz_generator::grammar_c", ptr %7, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  call void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336) %19)
  store i32 1, ptr %5, align 4
  br label %56

20:                                               ; preds = %13
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 24
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  br label %25

25:                                               ; preds = %24, %20
  %26 = getelementptr inbounds %"class.gz_generator::grammar_c", ptr %7, i32 0, i32 0
  %27 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %26, ptr noundef %3)
  store i8 %27, ptr %4, align 1, !tbaa !9
  %28 = load i8, ptr %4, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  br label %32

32:                                               ; preds = %31, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !17
  br label %33

33:                                               ; preds = %41, %32
  %34 = load i32, ptr %6, align 4, !tbaa !17
  %35 = call noundef i32 @_ZNK7token_c11get_m_valueEv(ptr noundef nonnull align 4 dereferenceable(8) %3)
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %44

38:                                               ; preds = %33
  %39 = getelementptr inbounds %"class.gz_generator::grammar_c", ptr %7, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  call void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336) %40)
  br label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %6, align 4, !tbaa !17
  %43 = add i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !17
  br label %33, !llvm.loop !18

44:                                               ; preds = %37
  %45 = getelementptr inbounds %"class.gz_generator::grammar_c", ptr %7, i32 0, i32 0
  %46 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %45, ptr noundef %3)
  store i8 %46, ptr %4, align 1, !tbaa !9
  %47 = load i8, ptr %4, align 1, !tbaa !9
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %48, 2
  br i1 %49, label %54, label %50

50:                                               ; preds = %44
  %51 = load i8, ptr %4, align 1, !tbaa !9
  %52 = zext i8 %51 to i32
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %50, %44
  store i32 1, ptr %5, align 4
  br label %56

55:                                               ; preds = %50
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  store i32 0, ptr %5, align 4
  br label %56

56:                                               ; preds = %55, %54, %17
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %57 = load i32, ptr %5, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

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

declare void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7token_c11get_m_valueEv(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

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 = { "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 #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 = !{!"_ZTS12token_type_t", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN12gz_generator9grammar_cE", !13, i64 0, !6, i64 24}
!13 = !{!"_ZTS14token_parser_c", !6, i64 0, !14, i64 8, !16, i64 16, !15, i64 20}
!14 = !{!"_ZTS7token_c", !10, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!15, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%class.token_c = type { i8, i32 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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 dso_local void @_ZN7token_cC2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12gz_generator9grammar_c7parse_mEv(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %class.token_c, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @_ZN7token_cC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %3 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %2)
  %4 = and i8 %3, -3
  %or.cond = icmp eq i8 %4, 0
  br i1 %or.cond, label %5, label %8

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336) %7)
  br label %24

8:                                                ; preds = %1
  %.not = icmp eq i8 %3, 24
  br i1 %.not, label %10, label %9

9:                                                ; preds = %8
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  br label %10

10:                                               ; preds = %9, %8
  %11 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %2)
  %.not14 = icmp eq i8 %11, 1
  br i1 %.not14, label %13, label %12

12:                                               ; preds = %10
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  br label %13

13:                                               ; preds = %12, %10
  %14 = call noundef i32 @_ZNK7token_c11get_m_valueEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %.not16 = icmp eq i32 %14, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  br label %18

._crit_edge:                                      ; preds = %18, %13
  %16 = call noundef zeroext i8 @_ZN14token_parser_c9get_tokenEP7token_c(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %2)
  %17 = and i8 %16, -3
  %or.cond5 = icmp eq i8 %17, 0
  br i1 %or.cond5, label %24, label %23

18:                                               ; preds = %.lr.ph, %18
  %.015 = phi i32 [ 0, %.lr.ph ], [ %20, %18 ]
  %19 = load ptr, ptr %15, align 8, !tbaa !5
  call void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336) %19)
  %20 = add nuw i32 %.015, 1
  %21 = call noundef i32 @_ZNK7token_c11get_m_valueEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %18, label %._crit_edge, !llvm.loop !15

23:                                               ; preds = %._crit_edge
  call void @_ZN12gz_generator9grammar_c12syntax_errorEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  br label %24

24:                                               ; preds = %._crit_edge, %23, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret void
}

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

declare void @_ZN12gz_generator5gen_c9proc_randEv(ptr noundef nonnull align 8 dereferenceable(178336)) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7token_c11get_m_valueEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

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 = { mustprogress 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 = { "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 #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, !8, i64 24}
!6 = !{!"_ZTSN12gz_generator9grammar_cE", !7, i64 0, !8, i64 24}
!7 = !{!"_ZTS14token_parser_c", !8, i64 0, !11, i64 8, !14, i64 16, !13, i64 20}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS7token_c", !12, i64 0, !13, i64 4}
!12 = !{!"_ZTS12token_type_t", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"bool", !9, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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