; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzdebug)

; 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.buzzvm_s = type { ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i16, ptr, ptr, ptr, ptr, i32, i32, ptr, i16, ptr, i32 }
%struct.buzzdarray_s = type { ptr, i64, i32, i32, ptr }
%struct.anon = type { i16, i16 }

@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@buzztype_desc = external global [0 x ptr], align 8

declare void @buzzdarray_insert(ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @buzzdebug_closure_call(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @buzzdebug_function_call(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.buzzvm_s, ptr %10, i32 0, i32 20
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp ne i32 %12, 1
  br i1 %13, label %14, label %32

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.buzzvm_s, ptr %15, i32 0, i32 20
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp eq i32 %17, 4
  br i1 %18, label %24, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.buzzvm_s, ptr %20, i32 0, i32 20
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %27

24:                                               ; preds = %19, %14
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.buzzvm_s, ptr %25, i32 0, i32 20
  store i32 1, ptr %26, align 8, !tbaa !11
  br label %31

27:                                               ; preds = %19
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.buzzvm_s, ptr %28, i32 0, i32 20
  %30 = load i32, ptr %29, align 8, !tbaa !11
  store i32 %30, ptr %5, align 4
  br label %120

31:                                               ; preds = %24
  br label %32

32:                                               ; preds = %31, %4
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.buzzvm_s, ptr %34, i32 0, i32 9
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call zeroext i16 @buzzstrman_register(ptr noundef %36, ptr noundef %37, i32 noundef 0)
  %39 = call i32 @buzzvm_pushs(ptr noundef %33, i16 noundef zeroext %38)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call i32 @buzzvm_gload(ptr noundef %40)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.buzzvm_s, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds %struct.buzzdarray_s, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.buzzvm_s, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.buzzdarray_s, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !19
  %52 = sub nsw i64 %51, 1
  %53 = getelementptr inbounds ptr, ptr %46, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.anon, ptr %54, i32 0, i32 0
  %56 = load i16, ptr %55, align 8, !tbaa !20
  %57 = zext i16 %56 to i32
  %58 = icmp ne i32 %57, 5
  br i1 %58, label %59, label %83

59:                                               ; preds = %32
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @buzztype_desc, i64 0, i64 5), align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.buzzvm_s, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = getelementptr inbounds %struct.buzzdarray_s, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.buzzvm_s, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = getelementptr inbounds %struct.buzzdarray_s, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !19
  %72 = sub nsw i64 %71, 1
  %73 = getelementptr inbounds ptr, ptr %66, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.anon, ptr %74, i32 0, i32 0
  %76 = load i16, ptr %75, align 8, !tbaa !20
  %77 = zext i16 %76 to i64
  %78 = getelementptr inbounds [0 x ptr], ptr @buzztype_desc, i64 0, i64 %77
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  call void (ptr, i32, ptr, ...) @buzzvm_seterror(ptr noundef %60, i32 noundef 6, ptr noundef @.str.3, ptr noundef %61, ptr noundef %79)
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.buzzvm_s, ptr %80, i32 0, i32 20
  %82 = load i32, ptr %81, align 8, !tbaa !11
  store i32 %82, ptr %5, align 4
  br label %120

83:                                               ; preds = %32
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = icmp ugt i32 %84, 0
  br i1 %85, label %86, label %115

86:                                               ; preds = %83
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.buzzvm_s, ptr %87, i32 0, i32 4
  %89 = load ptr, ptr %88, align 8, !tbaa !15
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.buzzvm_s, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  %93 = getelementptr inbounds %struct.buzzdarray_s, ptr %92, i32 0, i32 1
  %94 = load i64, ptr %93, align 8, !tbaa !19
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = zext i32 %95 to i64
  %97 = sub nsw i64 %94, %96
  %98 = sub nsw i64 %97, 1
  %99 = trunc i64 %98 to i32
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.buzzvm_s, ptr %100, i32 0, i32 4
  %102 = load ptr, ptr %101, align 8, !tbaa !15
  %103 = getelementptr inbounds %struct.buzzdarray_s, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !16
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.buzzvm_s, ptr %105, i32 0, i32 4
  %107 = load ptr, ptr %106, align 8, !tbaa !15
  %108 = getelementptr inbounds %struct.buzzdarray_s, ptr %107, i32 0, i32 1
  %109 = load i64, ptr %108, align 8, !tbaa !19
  %110 = sub nsw i64 %109, 1
  %111 = getelementptr inbounds ptr, ptr %104, i64 %110
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  call void @buzzdarray_insert(ptr noundef %89, i32 noundef %99, ptr noundef %112)
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = call i32 @buzzvm_pop(ptr noundef %113)
  br label %115

115:                                              ; preds = %86, %83
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = load i32, ptr %8, align 4, !tbaa !9
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = call i32 @buzzdebug_closure_call(ptr noundef %116, i32 noundef %117, ptr noundef %118)
  store i32 %119, ptr %5, align 4
  br label %120

120:                                              ; preds = %115, %59, %27
  %121 = load i32, ptr %5, align 4
  ret i32 %121
}

declare i32 @buzzvm_pushs(ptr noundef, i16 noundef zeroext) #0

declare zeroext i16 @buzzstrman_register(ptr noundef, ptr noundef, i32 noundef) #0

declare i32 @buzzvm_gload(ptr noundef) #0

declare void @buzzvm_seterror(ptr noundef, i32 noundef, ptr noundef, ...) #0

declare i32 @buzzvm_pop(ptr noundef) #0

attributes #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 #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" }

!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, !10, i64 152}
!12 = !{!"buzzvm_s", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !13, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !10, i64 156, !6, i64 160, !13, i64 168, !6, i64 176, !10, i64 184}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 64}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !6, i64 0}
!17 = !{!"buzzdarray_s", !6, i64 0, !18, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!18 = !{!"long", !7, i64 0}
!19 = !{!17, !18, i64 8}
!20 = !{!7, !7, 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"

@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@buzztype_desc = external local_unnamed_addr global [0 x ptr], align 8

declare void @buzzdarray_insert(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @buzzdebug_closure_call(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @buzzdebug_function_call(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 152
  %6 = load i32, ptr %5, align 8, !tbaa !5
  switch i32 %6, label %38 [
    i32 1, label %8
    i32 4, label %7
    i32 2, label %7
  ]

7:                                                ; preds = %4, %4
  store i32 1, ptr %5, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %4, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = tail call zeroext i16 @buzzstrman_register(ptr noundef %10, ptr noundef %1, i32 noundef 0) #2
  %12 = tail call i32 @buzzvm_pushs(ptr noundef nonnull %0, i16 noundef zeroext %11) #2
  %13 = tail call i32 @buzzvm_gload(ptr noundef nonnull %0) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %15, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %19 = getelementptr ptr, ptr %16, i64 %18
  %20 = getelementptr i8, ptr %19, i64 -8
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load i16, ptr %21, align 8, !tbaa !19
  %.not27 = icmp eq i16 %22, 5
  br i1 %.not27, label %29, label %23

23:                                               ; preds = %8
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @buzztype_desc, i64 40), align 8, !tbaa !18
  %25 = zext i16 %22 to i64
  %26 = getelementptr inbounds [0 x ptr], ptr @buzztype_desc, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  tail call void (ptr, i32, ptr, ...) @buzzvm_seterror(ptr noundef nonnull %0, i32 noundef 6, ptr noundef nonnull @.str.3, ptr noundef %24, ptr noundef %27) #2
  %28 = load i32, ptr %5, align 8, !tbaa !5
  br label %38

29:                                               ; preds = %8
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %36, label %30

30:                                               ; preds = %29
  %31 = zext i32 %2 to i64
  %32 = xor i64 %31, -1
  %33 = add i64 %18, %32
  %34 = trunc i64 %33 to i32
  tail call void @buzzdarray_insert(ptr noundef nonnull %15, i32 noundef %34, ptr noundef nonnull %21) #2
  %35 = tail call i32 @buzzvm_pop(ptr noundef nonnull %0) #2
  br label %36

36:                                               ; preds = %30, %29
  %37 = tail call i32 @buzzdebug_closure_call(ptr noundef nonnull %0, i32 noundef %2, ptr noundef %3)
  br label %38

38:                                               ; preds = %4, %36, %23
  %.0 = phi i32 [ %28, %23 ], [ %37, %36 ], [ %6, %4 ]
  ret i32 %.0
}

declare i32 @buzzvm_pushs(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i16 @buzzstrman_register(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @buzzvm_gload(ptr noundef) local_unnamed_addr #0

declare void @buzzvm_seterror(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

declare i32 @buzzvm_pop(ptr noundef) local_unnamed_addr #0

attributes #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 #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, !10, i64 152}
!6 = !{!"buzzvm_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !11, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152, !10, i64 156, !7, i64 160, !11, i64 168, !7, i64 176, !10, i64 184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !7, i64 64}
!13 = !{!6, !7, i64 24}
!14 = !{!15, !7, i64 0}
!15 = !{!"buzzdarray_s", !7, i64 0, !16, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!16 = !{!"long", !8, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{!7, !7, i64 0}
!19 = !{!8, !8, i64 0}


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