; 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 }
%struct.buzzlex_file_s = type { i64, i64, i64, i64, ptr, ptr }

@stderr = external global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [50 x i8], align 1
@buzztok_desc = external global [0 x ptr], align 8
@PARSE_ERROR = external hidden global i32, align 4
@.str.14 = external hidden unnamed_addr constant [49 x i8], align 1
@PARSE_OK = external hidden global i32, align 4

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @match(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.buzzparser_s, ptr %6, i32 0, i32 4
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %struct.buzztok_s, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp eq i32 %10, 31
  br i1 %11, label %12, label %23

12:                                               ; preds = %2
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.buzzparser_s, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.13, ptr noundef %16, ptr noundef %20) #2
  %22 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  br label %74

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.buzzparser_s, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.buzztok_s, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp ne i32 %28, %29
  br i1 %30, label %31, label %72

31:                                               ; preds = %23
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.buzzparser_s, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds %struct.buzzdarray_s, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.buzzparser_s, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = getelementptr inbounds %struct.buzzdarray_s, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = sub nsw i64 %42, 1
  %44 = getelementptr inbounds ptr, ptr %37, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.buzzlex_file_s, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.buzzparser_s, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.buzztok_s, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !23
  %53 = load ptr, ptr %4, 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 3
  %57 = load i64, ptr %56, align 8, !tbaa !24
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.buzzparser_s, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = getelementptr inbounds %struct.buzztok_s, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !13
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.14, ptr noundef %47, i64 noundef %52, i64 noundef %57, ptr noundef %61, ptr noundef %69) #2
  %71 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %71, ptr %3, align 4
  br label %74

72:                                               ; preds = %23
  %73 = load i32, ptr @PARSE_OK, align 4, !tbaa !9
  store i32 %73, ptr %3, align 4
  br label %74

74:                                               ; preds = %72, %31, %12
  %75 = load i32, ptr %3, align 4
  ret i32 %75
}

attributes #0 = { nounwind "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, !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 0}
!17 = !{!12, !6, i64 24}
!18 = !{!19, !6, i64 0}
!19 = !{!"buzzdarray_s", !6, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!20 = !{!19, !15, i64 8}
!21 = !{!22, !6, i64 40}
!22 = !{!"buzzlex_file_s", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !6, i64 32, !6, i64 40}
!23 = !{!14, !15, i64 16}
!24 = !{!14, !15, i64 24}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [50 x i8], align 1
@buzztok_desc = external local_unnamed_addr global [0 x ptr], align 8
@PARSE_ERROR = external hidden local_unnamed_addr global i32, align 4
@.str.14 = external hidden unnamed_addr constant [49 x i8], align 1
@PARSE_OK = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @match(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = icmp eq i32 %5, 31
  br i1 %6, label %7, label %14

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !14
  %9 = load ptr, ptr %0, align 8, !tbaa !15
  %10 = zext i32 %1 to i64
  %11 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.13, ptr noundef %9, ptr noundef %12) #2
  br label %38

14:                                               ; preds = %2
  %.not = icmp eq i32 %5, %1
  br i1 %.not, label %38, label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr @stderr, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = getelementptr ptr, ptr %19, i64 %21
  %23 = getelementptr i8, ptr %22, i64 -8
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %24, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %4, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !22
  %29 = getelementptr inbounds i8, ptr %4, i64 24
  %30 = load i64, ptr %29, align 8, !tbaa !23
  %31 = zext i32 %1 to i64
  %32 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = zext i32 %5 to i64
  %35 = getelementptr inbounds [0 x ptr], ptr @buzztok_desc, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.14, ptr noundef %26, i64 noundef %28, i64 noundef %30, ptr noundef %33, ptr noundef %36) #2
  br label %38

38:                                               ; preds = %14, %15, %7
  %.0.in = phi ptr [ @PARSE_ERROR, %7 ], [ @PARSE_ERROR, %15 ], [ @PARSE_OK, %14 ]
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !24
  ret i32 %.0
}

attributes #0 = { nofree nounwind "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 = { nofree 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 = { cold 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 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 24}
!17 = !{!18, !7, i64 0}
!18 = !{!"buzzdarray_s", !7, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!19 = !{!18, !13, i64 8}
!20 = !{!21, !7, i64 40}
!21 = !{!"buzzlex_file_s", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !7, i64 32, !7, i64 40}
!22 = !{!12, !13, i64 16}
!23 = !{!12, !13, i64 24}
!24 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass