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

@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 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
define dso_local void @chunk_addcode(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %23

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.buzztok_s, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.buzztok_s, ptr %16, i32 0, i32 3
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.buzztok_s, ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %7, ptr noundef @.str.5, ptr noundef %12, i64 noundef %15, i64 noundef %18, ptr noundef %21) #5
  br label %26

23:                                               ; preds = %3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %7, ptr noundef @.str.6, ptr noundef %24) #5
  br label %26

26:                                               ; preds = %23, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 @strlen(ptr noundef %27) #6
  store i64 %28, ptr %8, align 8, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.chunk_s, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = load i64, ptr %8, align 8, !tbaa !15
  %33 = add i64 %31, %32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.chunk_s, ptr %34, i32 0, i32 4
  %36 = load i64, ptr %35, align 8, !tbaa !18
  %37 = icmp uge i64 %33, %36
  br i1 %37, label %38, label %64

38:                                               ; preds = %26
  br label %39

39:                                               ; preds = %44, %38
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.chunk_s, ptr %40, i32 0, i32 4
  %42 = load i64, ptr %41, align 8, !tbaa !18
  %43 = mul i64 %42, 2
  store i64 %43, ptr %41, align 8, !tbaa !18
  br label %44

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.chunk_s, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !16
  %48 = load i64, ptr %8, align 8, !tbaa !15
  %49 = add i64 %47, %48
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.chunk_s, ptr %50, i32 0, i32 4
  %52 = load i64, ptr %51, align 8, !tbaa !18
  %53 = icmp uge i64 %49, %52
  br i1 %53, label %39, label %54, !llvm.loop !19

54:                                               ; preds = %44
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.chunk_s, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !21
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.chunk_s, ptr %58, i32 0, i32 4
  %60 = load i64, ptr %59, align 8, !tbaa !18
  %61 = call ptr @realloc(ptr noundef %57, i64 noundef %60) #7
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.chunk_s, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !21
  br label %64

64:                                               ; preds = %54, %26
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.chunk_s, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.chunk_s, ptr %68, i32 0, i32 3
  %70 = load i64, ptr %69, align 8, !tbaa !16
  %71 = getelementptr inbounds i8, ptr %67, i64 %70
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load i64, ptr %8, align 8, !tbaa !15
  %74 = call ptr @strncpy(ptr noundef %71, ptr noundef %72, i64 noundef %73) #5
  %75 = load i64, ptr %8, align 8, !tbaa !15
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.chunk_s, ptr %76, i32 0, i32 3
  %78 = load i64, ptr %77, align 8, !tbaa !16
  %79 = add i64 %78, %75
  store i64 %79, ptr %77, align 8, !tbaa !16
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %80) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #1

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 = { nounwind willreturn memory(read) "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 allocsize(1) "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 }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind allocsize(1) }

!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, !12, i64 16}
!10 = !{!"buzztok_s", !11, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 24}
!14 = !{!10, !6, i64 32}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 24}
!17 = !{!"chunk_s", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 32}
!18 = !{!17, !12, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!17, !6, i64 8}


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

@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 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
define dso_local void @chunk_addcode(ptr nocapture noundef %0, ptr noundef %1, ptr noundef readonly %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %13, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %4, ptr noundef nonnull @.str.5, ptr noundef %1, i64 noundef %7, i64 noundef %9, ptr noundef %11) #7
  br label %15

13:                                               ; preds = %3
  %14 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %4, ptr noundef nonnull @.str.6, ptr noundef %1) #7
  br label %15

15:                                               ; preds = %13, %5
  %16 = load ptr, ptr %4, align 8, !tbaa !14
  %17 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %16) #8
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = add i64 %19, %17
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %.not21 = icmp ult i64 %20, %22
  br i1 %.not21, label %._crit_edge, label %.preheader

._crit_edge:                                      ; preds = %15
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !18
  br label %29

.preheader:                                       ; preds = %15, %.preheader
  %23 = phi i64 [ %24, %.preheader ], [ %22, %15 ]
  %24 = shl i64 %23, 1
  %.not22 = icmp ult i64 %20, %24
  br i1 %.not22, label %25, label %.preheader, !llvm.loop !19

25:                                               ; preds = %.preheader
  store i64 %24, ptr %21, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = call ptr @realloc(ptr noundef %27, i64 noundef %24) #9
  store ptr %28, ptr %26, align 8, !tbaa !18
  %.pre24 = load i64, ptr %18, align 8, !tbaa !15
  %.pre25 = load ptr, ptr %4, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %._crit_edge, %25
  %30 = phi ptr [ %16, %._crit_edge ], [ %.pre25, %25 ]
  %31 = phi i64 [ %19, %._crit_edge ], [ %.pre24, %25 ]
  %32 = phi ptr [ %.pre, %._crit_edge ], [ %28, %25 ]
  %33 = getelementptr inbounds i8, ptr %32, i64 %31
  %34 = call ptr @strncpy(ptr noundef %33, ptr noundef %30, i64 noundef %17) #7
  %35 = load i64, ptr %18, align 8, !tbaa !15
  %36 = add i64 %35, %17
  store i64 %36, ptr %18, align 8, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !14
  call void @free(ptr noundef %37) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #6

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #6 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(1) }

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass