; 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.sym_s = type { i64, i32, i32 }
%struct.buzzparser_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.buzzdarray_s = type { ptr, i64, i32, i32, ptr }
%struct.buzzdict_s = type { ptr, i32, i32, ptr, ptr, ptr, i32, i32 }

@SCOPE_AUTO = external hidden global i32, align 4
@TYPE_BASIC = external hidden global i32, align 4

; 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 uwtable
declare dso_local i32 @string_add(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

declare void @buzzdict_set(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @sym_add(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.sym_s, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noalias ptr @strdup(ptr noundef %11) #4
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr @SCOPE_AUTO, align 4, !tbaa !9
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %24

16:                                               ; preds = %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.buzzparser_s, ptr %17, i32 0, i32 7
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.buzzdarray_s, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp eq i64 %21, 1
  %23 = zext i1 %22 to i32
  store i32 %23, ptr %8, align 4, !tbaa !9
  br label %26

24:                                               ; preds = %3
  %25 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %25, ptr %8, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %24, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.buzzparser_s, ptr %30, i32 0, i32 9
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i32 @string_add(ptr noundef %32, ptr noundef %33)
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %41

35:                                               ; preds = %26
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.buzzparser_s, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = getelementptr inbounds %struct.buzzdict_s, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !18
  store i32 %40, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %35, %29
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %42 = getelementptr inbounds %struct.sym_s, ptr %10, i32 0, i32 0
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  store i64 %44, ptr %42, align 8, !tbaa !20
  %45 = getelementptr inbounds %struct.sym_s, ptr %10, i32 0, i32 1
  %46 = load i32, ptr @TYPE_BASIC, align 4, !tbaa !9
  store i32 %46, ptr %45, align 8, !tbaa !22
  %47 = getelementptr inbounds %struct.sym_s, ptr %10, i32 0, i32 2
  %48 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %48, ptr %47, align 4, !tbaa !23
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %59

51:                                               ; preds = %41
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.buzzparser_s, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.buzzdarray_s, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !24
  %57 = getelementptr inbounds ptr, ptr %56, i64 0
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  call void @buzzdict_set(ptr noundef %58, ptr noundef %7, ptr noundef %10)
  br label %63

59:                                               ; preds = %41
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.buzzparser_s, ptr %60, i32 0, i32 8
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  call void @buzzdict_set(ptr noundef %62, ptr noundef %7, ptr noundef %10)
  br label %63

63:                                               ; preds = %59, %51
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 56}
!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, !15, i64 8}
!14 = !{!"buzzdarray_s", !6, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 72}
!17 = !{!12, !6, i64 64}
!18 = !{!19, !10, i64 8}
!19 = !{!"buzzdict_s", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}
!20 = !{!21, !15, i64 0}
!21 = !{!"sym_s", !15, i64 0, !10, i64 8, !10, i64 12}
!22 = !{!21, !10, i64 8}
!23 = !{!21, !10, i64 12}
!24 = !{!14, !6, i64 0}


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

%struct.sym_s = type { i64, i32, i32 }

@SCOPE_AUTO = external hidden local_unnamed_addr global i32, align 4
@TYPE_BASIC = external hidden local_unnamed_addr global i32, align 4

; 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: nounwind uwtable
declare dso_local i32 @string_add(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

declare void @buzzdict_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @sym_add(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = alloca %struct.sym_s, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %6 = tail call noalias ptr @strdup(ptr noundef %1) #4
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load i32, ptr @SCOPE_AUTO, align 4, !tbaa !9
  %8 = icmp eq i32 %7, %2
  br i1 %8, label %9, label %16

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i64 %13, 1
  %15 = zext i1 %14 to i32
  br label %16

16:                                               ; preds = %3, %9
  %.012 = phi i32 [ %15, %9 ], [ %2, %3 ]
  %.not = icmp eq i32 %.012, 0
  br i1 %.not, label %29, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = tail call i32 @string_add(ptr noundef %19, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %5, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %5, i64 8
  %23 = load i32, ptr @TYPE_BASIC, align 4, !tbaa !9
  store i32 %23, ptr %22, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %.012, ptr %24, align 4, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %0, i64 56
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  br label %38

29:                                               ; preds = %16
  %30 = getelementptr inbounds i8, ptr %0, i64 64
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load i32, ptr %32, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %34 = zext i32 %33 to i64
  store i64 %34, ptr %5, align 8, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %5, i64 8
  %36 = load i32, ptr @TYPE_BASIC, align 4, !tbaa !9
  store i32 %36, ptr %35, align 8, !tbaa !19
  %37 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 0, ptr %37, align 4, !tbaa !20
  br label %38

38:                                               ; preds = %29, %17
  %.sink = phi ptr [ %31, %29 ], [ %28, %17 ]
  call void @buzzdict_set(ptr noundef %.sink, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn 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 #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 56}
!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, !15, i64 8}
!14 = !{!"buzzdarray_s", !6, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 72}
!17 = !{!18, !15, i64 0}
!18 = !{!"sym_s", !15, i64 0, !10, i64 8, !10, i64 12}
!19 = !{!18, !10, i64 8}
!20 = !{!18, !10, i64 12}
!21 = !{!14, !6, i64 0}
!22 = !{!12, !6, i64 64}
!23 = !{!24, !10, i64 8}
!24 = !{!"buzzdict_s", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}


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