; 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.56 = 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_modulo(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = call i32 @parse_power(ptr noundef %5)
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %10, label %8

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

10:                                               ; preds = %1
  br label %11

11:                                               ; preds = %50, %10
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.buzzparser_s, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.buzztok_s, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp eq i32 %16, 15
  br i1 %17, label %18, label %60

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %42, %18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.buzzparser_s, ptr %20, i32 0, i32 4
  call void @buzzlex_destroytok(ptr noundef %21)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.buzzparser_s, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = call ptr @buzzlex_nexttok(ptr noundef %24)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.buzzparser_s, ptr %26, i32 0, i32 4
  store ptr %25, ptr %27, align 8, !tbaa !11
  br label %28

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

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

42:                                               ; preds = %35, %28
  %43 = phi i1 [ false, %28 ], [ %41, %35 ]
  br i1 %43, label %19, label %44, !llvm.loop !17

44:                                               ; preds = %42
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @parse_power(ptr noundef %45)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %50, label %48

48:                                               ; preds = %44
  %49 = load i32, ptr @PARSE_ERROR, align 4, !tbaa !9
  store i32 %49, ptr %2, align 4
  br label %62

50:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %51 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %4, ptr noundef @.str.56) #4
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.buzzparser_s, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.buzzparser_s, ptr %56, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  call void @chunk_addcode(ptr noundef %54, ptr noundef %55, ptr noundef %58)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %59) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %11, !llvm.loop !20

60:                                               ; preds = %11
  %61 = load i32, ptr @PARSE_OK, align 4, !tbaa !9
  store i32 %61, ptr %2, align 4
  br label %62

62:                                               ; preds = %60, %48, %8
  %63 = load i32, ptr %2, align 4
  ret i32 %63
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @parse_power(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 = !{!12, !6, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !6, i64 48}
!20 = distinct !{!20, !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
@.str.56 = 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_modulo(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = tail call i32 @parse_power(ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.loopexit, label %.preheader13

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

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

.preheader:                                       ; preds = %.preheader.backedge, %.preheader.lr.ph
  call void @buzzlex_destroytok(ptr noundef nonnull %4) #5
  %10 = load ptr, ptr %8, align 8, !tbaa !14
  %11 = call ptr @buzzlex_nexttok(ptr noundef %10) #5
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %cond = icmp eq i32 %12, 26
  br i1 %cond, label %.preheader.backedge, label %.critedge

.preheader.backedge:                              ; preds = %.preheader, %14
  br label %.preheader, !llvm.loop !15

.critedge:                                        ; preds = %.preheader
  %13 = call i32 @parse_power(ptr noundef nonnull %0)
  %.not12 = icmp eq i32 %13, 0
  br i1 %.not12, label %.loopexit, label %14

14:                                               ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %15 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %2, ptr noundef nonnull @.str.56) #5
  %16 = load ptr, ptr %9, align 8, !tbaa !17
  %17 = load ptr, ptr %2, align 8, !tbaa !18
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @chunk_addcode(ptr noundef %16, ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr %2, align 8, !tbaa !18
  call void @free(ptr noundef %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp eq i32 %21, 15
  br i1 %22, label %.preheader.backedge, label %.loopexit

.loopexit:                                        ; preds = %.critedge, %14, %.preheader13, %1
  %.0.in = phi ptr [ @PARSE_ERROR, %1 ], [ @PARSE_OK, %.preheader13 ], [ @PARSE_ERROR, %.critedge ], [ @PARSE_OK, %14 ]
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !19
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @parse_power(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 = !{!6, !7, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 48}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !10, i64 0}


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