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

@PARSE_ERROR = external hidden global i32, align 4
@PARSE_OK = external hidden global i32, align 4
@.str.62 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [5 x i8], align 1

; 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: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @chunk_addcode(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) #1

declare ptr @buzzlex_nexttok(ptr noundef) #3

declare void @buzzlex_destroytok(ptr noundef) #3

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

11:                                               ; preds = %1
  %12 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %12, ptr %2, align 4
  br label %97

13:                                               ; preds = %1
  br label %14

14:                                               ; preds = %94, %13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.buzzparser_s, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.buzztok_s, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp eq i32 %19, 18
  br i1 %20, label %21, label %95

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.buzzparser_s, ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.buzztok_s, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %26, i64 0
  %28 = load i8, ptr %27, align 1, !tbaa !17
  store i8 %28, ptr %4, align 1, !tbaa !17
  br label %29

29:                                               ; preds = %52, %21
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.buzzparser_s, ptr %30, i32 0, i32 4
  call void @buzzlex_destroytok(ptr noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.buzzparser_s, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = call ptr @buzzlex_nexttok(ptr noundef %34)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.buzzparser_s, ptr %36, i32 0, i32 4
  store ptr %35, ptr %37, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %29
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.buzzparser_s, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.buzztok_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !13
  %44 = icmp ne i32 %43, 31
  br i1 %44, label %45, label %52

45:                                               ; preds = %38
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.buzzparser_s, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds %struct.buzztok_s, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !13
  %51 = icmp eq i32 %50, 26
  br label %52

52:                                               ; preds = %45, %38
  %53 = phi i1 [ false, %38 ], [ %51, %45 ]
  br i1 %53, label %29, label %54, !llvm.loop !19

54:                                               ; preds = %52
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call i32 @parse_bitwisenot(ptr noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %60, label %58

58:                                               ; preds = %54
  %59 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %59, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %92

60:                                               ; preds = %54
  %61 = load i8, ptr %4, align 1, !tbaa !17
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 38
  br i1 %63, label %64, label %74

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %65 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %6, ptr noundef @.str.62) #4
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.buzzparser_s, ptr %66, i32 0, i32 6
  %68 = load ptr, ptr %67, align 8, !tbaa !21
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.buzzparser_s, ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  call void @chunk_addcode(ptr noundef %68, ptr noundef %69, ptr noundef %72)
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %73) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %91

74:                                               ; preds = %60
  %75 = load i8, ptr %4, align 1, !tbaa !17
  %76 = sext i8 %75 to i32
  %77 = icmp eq i32 %76, 124
  br i1 %77, label %78, label %88

78:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %79 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %7, ptr noundef @.str.63) #4
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.buzzparser_s, ptr %80, i32 0, i32 6
  %82 = load ptr, ptr %81, align 8, !tbaa !21
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.buzzparser_s, ptr %84, i32 0, i32 4
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  call void @chunk_addcode(ptr noundef %82, ptr noundef %83, ptr noundef %86)
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %87) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %90

88:                                               ; preds = %74
  %89 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %89, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %92

90:                                               ; preds = %78
  br label %91

91:                                               ; preds = %90, %64
  store i32 0, ptr %5, align 4
  br label %92

92:                                               ; preds = %91, %88, %58
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  %93 = load i32, ptr %5, align 4
  switch i32 %93, label %99 [
    i32 0, label %94
    i32 1, label %97
  ]

94:                                               ; preds = %92
  br label %14, !llvm.loop !22

95:                                               ; preds = %14
  %96 = load i32, ptr @PARSE_OK, align 4, !tbaa !9
  store i32 %96, ptr %2, align 4
  br label %97

97:                                               ; preds = %95, %92, %11
  %98 = load i32, ptr %2, align 4
  ret i32 %98

99:                                               ; preds = %92
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @parse_bitwisenot(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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/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 = !{!14, !6, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !6, i64 48}
!22 = distinct !{!22, !20}


; 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
@.str.62 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [5 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @chunk_addcode(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

declare ptr @buzzlex_nexttok(ptr noundef) local_unnamed_addr #4

declare void @buzzlex_destroytok(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i32 @parse_bitwiseandor(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = tail call i32 @parse_bitwisenot(ptr noundef %0)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.thread, label %.preheader

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 18
  br i1 %8, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  br label %11

11:                                               ; preds = %.lr.ph, %34
  %12 = phi ptr [ %6, %.lr.ph ], [ %35, %34 ]
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = load i8, ptr %14, align 1, !tbaa !15
  br label %16

16:                                               ; preds = %16, %11
  call void @buzzlex_destroytok(ptr noundef nonnull %5) #5
  %17 = load ptr, ptr %9, align 8, !tbaa !16
  %18 = call ptr @buzzlex_nexttok(ptr noundef %17) #5
  store ptr %18, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %cond = icmp eq i32 %19, 26
  br i1 %cond, label %16, label %.critedge

.critedge:                                        ; preds = %16
  %20 = call i32 @parse_bitwisenot(ptr noundef nonnull %0)
  %.not20 = icmp eq i32 %20, 0
  br i1 %.not20, label %.thread, label %21

21:                                               ; preds = %.critedge
  switch i8 %15, label %.thread [
    i8 38, label %22
    i8 124, label %28
  ]

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %23 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %2, ptr noundef nonnull @.str.62) #5
  %24 = load ptr, ptr %10, align 8, !tbaa !17
  %25 = load ptr, ptr %2, align 8, !tbaa !18
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  call void @chunk_addcode(ptr noundef %24, ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %2, align 8, !tbaa !18
  call void @free(ptr noundef %27) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %34

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %29 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.63) #5
  %30 = load ptr, ptr %10, align 8, !tbaa !17
  %31 = load ptr, ptr %3, align 8, !tbaa !18
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  call void @chunk_addcode(ptr noundef %30, ptr noundef %31, ptr noundef %32)
  %33 = load ptr, ptr %3, align 8, !tbaa !18
  call void @free(ptr noundef %33) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %34

34:                                               ; preds = %22, %28
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp eq i32 %36, 18
  br i1 %37, label %11, label %.thread

.thread:                                          ; preds = %.critedge, %21, %34, %.preheader, %1
  %.2.in = phi ptr [ @PARSE_ERROR, %1 ], [ @PARSE_OK, %.preheader ], [ @PARSE_ERROR, %.critedge ], [ @PARSE_ERROR, %21 ], [ @PARSE_OK, %34 ]
  %.2 = load i32, ptr %.2.in, align 4, !tbaa !19
  ret i32 %.2
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { 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 #4 = { "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 #5 = { 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 = !{!12, !7, i64 8}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !7, i64 48}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !10, i64 0}


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