; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzparser)

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

%struct.buzzparser_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.buzztok_s = type { i32, ptr, i64, i64, ptr }
%struct.buzzdarray_s = type { ptr, i64, i32, i32, ptr }

@PARSE_ERROR = external hidden global i32, align 4
@PARSE_OK = external hidden global i32, align 4

declare ptr @buzzlex_nexttok(ptr noundef) #0

declare void @buzzlex_destroytok(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @parse_statlist(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = call i32 @parse_stat(ptr noundef %4)
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %9, label %7

7:                                                ; preds = %1
  %8 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %8, ptr %2, align 4
  br label %93

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %74, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.buzzparser_s, ptr %11, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.buzztok_s, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = icmp ne i32 %15, 31
  br i1 %16, label %17, label %24

17:                                               ; preds = %10
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.buzzparser_s, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.buzztok_s, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = icmp ne i32 %22, 21
  br label %24

24:                                               ; preds = %17, %10
  %25 = phi i1 [ false, %10 ], [ %23, %17 ]
  br i1 %25, label %26, label %75

26:                                               ; preds = %24
  br label %27

27:                                               ; preds = %43, %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.buzzparser_s, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.buzztok_s, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = icmp ne i32 %32, 31
  br i1 %33, label %34, label %41

34:                                               ; preds = %27
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.buzzparser_s, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.buzztok_s, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = icmp eq i32 %39, 26
  br label %41

41:                                               ; preds = %34, %27
  %42 = phi i1 [ false, %27 ], [ %40, %34 ]
  br i1 %42, label %43, label %52

43:                                               ; preds = %41
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.buzzparser_s, ptr %44, i32 0, i32 4
  call void @buzzlex_destroytok(ptr noundef %45)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.buzzparser_s, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = call ptr @buzzlex_nexttok(ptr noundef %48)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.buzzparser_s, ptr %50, i32 0, i32 4
  store ptr %49, ptr %51, align 8, !tbaa !11
  br label %27, !llvm.loop !17

52:                                               ; preds = %41
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.buzzparser_s, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.buzztok_s, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = icmp eq i32 %57, 31
  br i1 %58, label %59, label %68

59:                                               ; preds = %52
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.buzzparser_s, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = getelementptr inbounds %struct.buzzdarray_s, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !19
  %65 = icmp eq i64 %64, 0
  br i1 %65, label %68, label %66

66:                                               ; preds = %59
  %67 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %67, ptr %2, align 4
  br label %93

68:                                               ; preds = %59, %52
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = call i32 @parse_stat(ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %74, label %72

72:                                               ; preds = %68
  %73 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %73, ptr %2, align 4
  br label %93

74:                                               ; preds = %68
  br label %10, !llvm.loop !21

75:                                               ; preds = %24
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.buzzparser_s, ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !11
  %79 = getelementptr inbounds %struct.buzztok_s, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !13
  %81 = icmp eq i32 %80, 31
  br i1 %81, label %82, label %91

82:                                               ; preds = %75
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.buzzparser_s, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  %86 = getelementptr inbounds %struct.buzzdarray_s, ptr %85, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !19
  %88 = icmp eq i64 %87, 0
  br i1 %88, label %91, label %89

89:                                               ; preds = %82
  %90 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %90, ptr %2, align 4
  br label %93

91:                                               ; preds = %82, %75
  %92 = load i32, ptr @PARSE_OK, align 4, !tbaa !9
  store i32 %92, ptr %2, align 4
  br label %93

93:                                               ; preds = %91, %89, %72, %66, %7
  %94 = load i32, ptr %2, align 4
  ret i32 %94
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @parse_stat(ptr noundef) #1

attributes #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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"buzzparser_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !10, i64 80}
!13 = !{!14, !10, i64 0}
!14 = !{!"buzztok_s", !10, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !6, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !15, i64 8}
!20 = !{!"buzzdarray_s", !6, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!21 = distinct !{!21, !18}


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

@PARSE_ERROR = external hidden local_unnamed_addr global i32, align 4
@PARSE_OK = external hidden local_unnamed_addr global i32, align 4

declare ptr @buzzlex_nexttok(ptr noundef) local_unnamed_addr #0

declare void @buzzlex_destroytok(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @parse_statlist(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @parse_stat(ptr noundef %0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.loopexit23, label %.preheader21

.preheader21:                                     ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  br label %5

5:                                                ; preds = %.preheader21, %.loopexit
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 8, !tbaa !11
  switch i32 %7, label %.preheader [
    i32 31, label %18
    i32 21, label %.loopexit22
  ]

.preheader:                                       ; preds = %5, %9
  %8 = phi i32 [ %.pre, %9 ], [ %7, %5 ]
  switch i32 %8, label %.loopexit [
    i32 26, label %9
    i32 31, label %12
  ]

9:                                                ; preds = %.preheader
  tail call void @buzzlex_destroytok(ptr noundef nonnull %3) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !14
  %11 = tail call ptr @buzzlex_nexttok(ptr noundef %10) #2
  store ptr %11, ptr %3, align 8, !tbaa !5
  %.pre = load i32, ptr %11, align 8, !tbaa !11
  br label %.preheader, !llvm.loop !15

12:                                               ; preds = %.preheader
  %13 = load ptr, ptr %4, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %.loopexit, label %.loopexit23

.loopexit:                                        ; preds = %.preheader, %12
  %17 = tail call i32 @parse_stat(ptr noundef nonnull %0)
  %.not20 = icmp eq i32 %17, 0
  br i1 %.not20, label %.loopexit23, label %5, !llvm.loop !19

18:                                               ; preds = %5
  %19 = load ptr, ptr %4, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %.loopexit22, label %.loopexit23

.loopexit22:                                      ; preds = %5, %18
  br label %.loopexit23

.loopexit23:                                      ; preds = %.loopexit, %12, %18, %1, %.loopexit22
  %.0.in = phi ptr [ @PARSE_OK, %.loopexit22 ], [ @PARSE_ERROR, %1 ], [ @PARSE_ERROR, %18 ], [ @PARSE_ERROR, %12 ], [ @PARSE_ERROR, %.loopexit ]
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !20
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @parse_stat(ptr noundef) local_unnamed_addr #1

attributes #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 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, !7, i64 32}
!6 = !{!"buzzparser_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"buzztok_s", !10, i64 0, !7, i64 8, !13, i64 16, !13, i64 24, !7, i64 32}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !7, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !13, i64 8}
!18 = !{!"buzzdarray_s", !7, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!19 = distinct !{!19, !16}
!20 = !{!10, !10, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass