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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @buzzinmsg_queue_extract(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.buzzvm_s, ptr %12, i32 0, i32 16
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.buzzdict_s, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %95

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !15
  br label %20

20:                                               ; preds = %63, %19
  %21 = load i32, ptr %9, align 4, !tbaa !15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.buzzvm_s, ptr %22, i32 0, i32 16
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.buzzdict_s, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = icmp ult i32 %21, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %20
  store i32 2, ptr %10, align 4
  br label %66

29:                                               ; preds = %20
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.buzzvm_s, ptr %30, i32 0, i32 16
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.buzzdict_s, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load i32, ptr %9, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %62

40:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.buzzvm_s, ptr %41, i32 0, i32 16
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.buzzdict_s, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i32, ptr %9, align 4, !tbaa !15
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.buzzdarray_s, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %51, i64 0
  store ptr %52, ptr %11, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = load i16, ptr %55, align 2, !tbaa !23
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  store i16 %56, ptr %57, align 2, !tbaa !23
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !24
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  store ptr %61, ptr %8, align 8, !tbaa !5
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %66

62:                                               ; preds = %29
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %9, align 4, !tbaa !15
  %65 = add i32 %64, 1
  store i32 %65, ptr %9, align 4, !tbaa !15
  br label %20, !llvm.loop !25

66:                                               ; preds = %40, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.buzzdarray_s, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !18
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.buzzdarray_s, ptr %71, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !27
  %74 = sub nsw i64 %73, 1
  %75 = getelementptr inbounds ptr, ptr %70, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %76, ptr %77, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.buzzdarray_s, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !27
  %82 = sub nsw i64 %81, 1
  %83 = trunc i64 %82 to i32
  call void @buzzdarray_remove(ptr noundef %78, i32 noundef %83)
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.buzzdarray_s, ptr %84, i32 0, i32 1
  %86 = load i64, ptr %85, align 8, !tbaa !27
  %87 = icmp eq i64 %86, 0
  br i1 %87, label %88, label %94

88:                                               ; preds = %67
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.buzzvm_s, ptr %89, i32 0, i32 16
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = call i32 @buzzdict_remove(ptr noundef %91, ptr noundef %92)
  br label %94

94:                                               ; preds = %88, %67
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %95

95:                                               ; preds = %94, %18
  %96 = load i32, ptr %4, align 4
  ret i32 %96
}

declare void @buzzdarray_remove(ptr noundef, i32 noundef) #2

declare i32 @buzzdict_remove(ptr noundef, ptr noundef) #2

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 = { "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, !6, i64 120}
!10 = !{!"buzzvm_s", !6, i64 0, !11, i64 8, !11, i64 12, !11, 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, !12, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !11, i64 152, !11, i64 156, !6, i64 160, !12, i64 168, !6, i64 176, !11, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"buzzdict_s", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 44}
!15 = !{!11, !11, i64 0}
!16 = !{!14, !11, i64 12}
!17 = !{!14, !6, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"buzzdarray_s", !6, i64 0, !20, i64 8, !11, i64 16, !11, i64 20, !6, i64 24}
!20 = !{!"long", !7, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"buzzdict_entry_s", !6, i64 0, !6, i64 8}
!23 = !{!12, !12, i64 0}
!24 = !{!22, !6, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!19, !20, 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @buzzinmsg_queue_extract(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %37, label %.preheader

.preheader:                                       ; preds = %3
  %9 = getelementptr inbounds i8, ptr %5, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = load ptr, ptr %5, align 8, !tbaa !15
  %12 = zext i32 %10 to i64
  br label %13

13:                                               ; preds = %13, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %13 ], [ 0, %.preheader ]
  %14 = icmp ult i64 %indvars.iv, %12
  tail call void @llvm.assume(i1 %14)
  %15 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %.not = icmp eq ptr %16, null
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  br i1 %.not, label %13, label %17, !llvm.loop !17

17:                                               ; preds = %13
  %18 = load ptr, ptr %16, align 8, !tbaa !19
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  %20 = load i16, ptr %19, align 2, !tbaa !24
  store i16 %20, ptr %1, align 2, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %18, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !25
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %23, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !26
  %27 = getelementptr ptr, ptr %24, i64 %26
  %28 = getelementptr i8, ptr %27, i64 -8
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  store ptr %29, ptr %2, align 8, !tbaa !16
  %30 = trunc i64 %26 to i32
  %31 = add i32 %30, -1
  tail call void @buzzdarray_remove(ptr noundef nonnull %23, i32 noundef %31) #3
  %32 = load i64, ptr %25, align 8, !tbaa !26
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %17
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = tail call i32 @buzzdict_remove(ptr noundef %35, ptr noundef nonnull %1) #3
  br label %37

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

declare void @buzzdarray_remove(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #2

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
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, !7, i64 120}
!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 = !{!13, !10, i64 8}
!13 = !{!"buzzdict_s", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44}
!14 = !{!13, !10, i64 12}
!15 = !{!13, !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !7, i64 0}
!20 = !{!"buzzdarray_s", !7, i64 0, !21, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!21 = !{!"long", !8, i64 0}
!22 = !{!23, !7, i64 0}
!23 = !{!"buzzdict_entry_s", !7, i64 0, !7, i64 8}
!24 = !{!11, !11, i64 0}
!25 = !{!23, !7, i64 8}
!26 = !{!20, !21, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass