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

; 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

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

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

declare i32 @buzzvm_step(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @buzzdebug_closure_call(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, 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 %27

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, 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 %19, label %22

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

22:                                               ; preds = %14
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.buzzvm_s, ptr %23, i32 0, i32 20
  %25 = load i32, ptr %24, align 8, !tbaa !11
  store i32 %25, ptr %4, align 4
  br label %86

26:                                               ; preds = %19
  br label %27

27:                                               ; preds = %26, %3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.buzzvm_s, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.buzzvm_s, ptr %31, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = getelementptr inbounds %struct.buzzdarray_s, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = sub nsw i64 %35, %37
  %39 = sub nsw i64 %38, 1
  %40 = trunc i64 %39 to i32
  %41 = call ptr @buzzobj_new(i16 noundef zeroext 0)
  call void @buzzdarray_insert(ptr noundef %30, i32 noundef %40, ptr noundef %41)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = call i32 @buzzvm_pushi(ptr noundef %42, i32 noundef %43)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.buzzvm_s, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct.buzzdarray_s, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !15
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %8, align 4, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i32 @buzzvm_call(ptr noundef %51, i32 noundef 0)
  br label %53

53:                                               ; preds = %72, %27
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.buzzvm_s, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 4, !tbaa !19
  %58 = call i32 @buzzdebug_breakpoint_exists(ptr noundef %54, i32 noundef %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %53
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.buzzvm_s, ptr %61, i32 0, i32 20
  store i32 4, ptr %62, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %60, %53
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call i32 @buzzvm_step(ptr noundef %64)
  %66 = icmp ne i32 %65, 1
  br i1 %66, label %67, label %71

67:                                               ; preds = %63
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.buzzvm_s, ptr %68, i32 0, i32 20
  %70 = load i32, ptr %69, align 8, !tbaa !11
  store i32 %70, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

71:                                               ; preds = %63
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = zext i32 %73 to i64
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.buzzvm_s, ptr %75, i32 0, i32 5
  %77 = load ptr, ptr %76, align 8, !tbaa !18
  %78 = getelementptr inbounds %struct.buzzdarray_s, ptr %77, i32 0, i32 1
  %79 = load i64, ptr %78, align 8, !tbaa !15
  %80 = icmp slt i64 %74, %79
  br i1 %80, label %53, label %81, !llvm.loop !20

81:                                               ; preds = %72
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.buzzvm_s, ptr %82, i32 0, i32 20
  %84 = load i32, ptr %83, align 8, !tbaa !11
  store i32 %84, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %85

85:                                               ; preds = %81, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %86

86:                                               ; preds = %85, %22
  %87 = load i32, ptr %4, align 4
  ret i32 %87
}

declare ptr @buzzobj_new(i16 noundef zeroext) #1

declare i32 @buzzvm_pushi(ptr noundef, i32 noundef) #1

declare i32 @buzzvm_call(ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #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 }

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


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

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

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

declare i32 @buzzvm_step(ptr noundef) local_unnamed_addr #0

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

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

7:                                                ; preds = %3, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = zext i32 %1 to i64
  %13 = xor i64 %12, -1
  %14 = add i64 %11, %13
  %15 = trunc i64 %14 to i32
  %16 = tail call ptr @buzzobj_new(i16 noundef zeroext 0) #2
  tail call void @buzzdarray_insert(ptr noundef %9, i32 noundef %15, ptr noundef %16) #2
  %17 = tail call i32 @buzzvm_pushi(ptr noundef nonnull %0, i32 noundef %1) #2
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = tail call i32 @buzzvm_call(ptr noundef nonnull %0, i32 noundef 0) #2
  %23 = and i64 %21, 4294967295
  %24 = getelementptr inbounds i8, ptr %0, i64 12
  br label %25

25:                                               ; preds = %31, %7
  %26 = load i32, ptr %24, align 4, !tbaa !17
  %27 = tail call i32 @buzzdebug_breakpoint_exists(ptr noundef %2, i32 noundef %26)
  %.not20 = icmp eq i32 %27, 0
  br i1 %.not20, label %29, label %28

28:                                               ; preds = %25
  store i32 4, ptr %4, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %28, %25
  %30 = tail call i32 @buzzvm_step(ptr noundef nonnull %0) #2
  %.not21 = icmp eq i32 %30, 1
  br i1 %.not21, label %31, label %36

31:                                               ; preds = %29
  %32 = load ptr, ptr %18, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = icmp slt i64 %23, %34
  br i1 %35, label %25, label %36, !llvm.loop !18

36:                                               ; preds = %31, %29
  %.0 = load i32, ptr %4, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %3, %36
  %.1 = phi i32 [ %.0, %36 ], [ %5, %3 ]
  ret i32 %.1
}

declare ptr @buzzobj_new(i16 noundef zeroext) local_unnamed_addr #0

declare i32 @buzzvm_pushi(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @buzzvm_call(ptr noundef, i32 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 24}
!13 = !{!14, !15, i64 8}
!14 = !{!"buzzdarray_s", !7, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!15 = !{!"long", !8, i64 0}
!16 = !{!6, !7, i64 32}
!17 = !{!6, !10, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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