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

@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [3 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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @buzzdebug_backtrace_entry(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.buzzdebug_fep_entry_s, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  %13 = load ptr, ptr %8, align 8, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.14, i32 noundef %14) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #5
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 32, i1 false)
  %16 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %9, i32 0, i32 0
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  store i64 %18, ptr %16, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %9, i32 0, i32 1
  %20 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %9, i32 0, i32 2
  %21 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %9, i32 0, i32 3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.buzzdebug_s, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = call i32 @buzzdarray_find(ptr noundef %24, ptr noundef @buzzdebug_backtrace_feps_cmp, ptr noundef %9)
  store i32 %25, ptr %10, align 4, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %32

28:                                               ; preds = %4
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.15, i32 noundef %30) #5
  store i32 1, ptr %11, align 4
  br label %92

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.buzzdebug_s, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.buzzdarray_s, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sub i32 %38, 1
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %37, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  store ptr %42, ptr %12, align 8, !tbaa !9
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.16, ptr noundef %46) #5
  %48 = load ptr, ptr %12, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = getelementptr inbounds %struct.buzzdarray_s, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !20
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %89, label %54

54:                                               ; preds = %32
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = load ptr, ptr %12, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = getelementptr inbounds %struct.buzzdarray_s, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = getelementptr inbounds ptr, ptr %60, i64 0
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.17, ptr noundef %62) #5
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %85, %54
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = zext i32 %65 to i64
  %67 = load ptr, ptr %12, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = getelementptr inbounds %struct.buzzdarray_s, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !20
  %72 = icmp slt i64 %66, %71
  br i1 %72, label %73, label %88

73:                                               ; preds = %64
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = load ptr, ptr %12, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.buzzdebug_fep_entry_s, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = getelementptr inbounds %struct.buzzdarray_s, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.17, ptr noundef %83) #5
  br label %85

85:                                               ; preds = %73
  %86 = load i32, ptr %10, align 4, !tbaa !5
  %87 = add i32 %86, 1
  store i32 %87, ptr %10, align 4, !tbaa !5
  br label %64, !llvm.loop !21

88:                                               ; preds = %64
  br label %89

89:                                               ; preds = %88, %32
  %90 = load ptr, ptr %8, align 8, !tbaa !9
  %91 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %90, ptr noundef @.str.18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  store i32 0, ptr %11, align 4
  br label %92

92:                                               ; preds = %89, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #5
  %93 = load i32, ptr %11, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
declare hidden i32 @buzzdebug_backtrace_feps_cmp(ptr noundef, ptr noundef) #3

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 "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"buzzdebug_fep_entry_s", !13, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 24}
!15 = !{!"buzzdebug_s", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!16 = !{!17, !10, i64 0}
!17 = !{!"buzzdarray_s", !10, i64 0, !13, i64 8, !6, i64 16, !6, i64 20, !10, i64 24}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !10, i64 24}
!20 = !{!17, !13, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.buzzdebug_fep_entry_s = type { i64, ptr, ptr, ptr }

@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [3 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

declare i32 @buzzdarray_find(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @buzzdebug_backtrace_entry(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.buzzdebug_fep_entry_s, align 8
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.14, i32 noundef %0) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %7, i8 0, i64 24, i1 false)
  %8 = zext i32 %2 to i64
  store i64 %8, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = call i32 @buzzdarray_find(ptr noundef %10, ptr noundef nonnull @buzzdebug_backtrace_feps_cmp, ptr noundef nonnull %5) #5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %4
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.15, i32 noundef %2) #5
  br label %51

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !11
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = add i32 %11, -1
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.16, ptr noundef %23) #5
  %25 = getelementptr inbounds i8, ptr %21, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load i64, ptr %27, align 8, !tbaa !19
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %15
  %31 = load ptr, ptr %26, align 8, !tbaa !13
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.17, ptr noundef %32) #5
  %34 = load ptr, ptr %25, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %34, i64 8
  %36 = load i64, ptr %35, align 8, !tbaa !19
  %37 = icmp sgt i64 %36, 1
  br i1 %37, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %30, %.lr.ph
  %38 = phi ptr [ %46, %.lr.ph ], [ %34, %30 ]
  %39 = phi i64 [ %45, %.lr.ph ], [ 1, %30 ]
  %.022 = phi i32 [ %44, %.lr.ph ], [ 1, %30 ]
  %40 = load ptr, ptr %38, align 8, !tbaa !13
  %41 = getelementptr inbounds ptr, ptr %40, i64 %39
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.17, ptr noundef %42) #5
  %44 = add i32 %.022, 1
  %45 = zext i32 %44 to i64
  %46 = load ptr, ptr %25, align 8, !tbaa !18
  %47 = getelementptr inbounds i8, ptr %46, i64 8
  %48 = load i64, ptr %47, align 8, !tbaa !19
  %49 = icmp sgt i64 %48, %45
  br i1 %49, label %.lr.ph, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph, %30, %15
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.18) #5
  br label %51

51:                                               ; preds = %.loopexit, %13
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
declare hidden i32 @buzzdebug_backtrace_feps_cmp(ptr noundef, ptr noundef) #3

attributes #0 = { mustprogress 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 = { nofree 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 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 0}
!6 = !{!"buzzdebug_fep_entry_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"buzzdebug_s", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!14, !10, i64 0}
!14 = !{!"buzzdarray_s", !10, i64 0, !7, i64 8, !15, i64 16, !15, i64 20, !10, i64 24}
!15 = !{!"int", !8, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!6, !10, i64 8}
!18 = !{!6, !10, i64 24}
!19 = !{!14, !7, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass