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

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

declare void @buzzdarray_destroy(ptr noundef) #1

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

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

27:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %113

28:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %109, %28
  %30 = load i32, ptr %7, align 4, !tbaa !13
  %31 = zext i32 %30 to i64
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.buzzdict_s, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %6, align 4, !tbaa !13
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.buzzdarray_s, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = icmp slt i64 %31, %40
  br i1 %41, label %42, label %112

42:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.buzzdict_s, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %6, align 4, !tbaa !13
  %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 = load i32, ptr %7, align 4, !tbaa !13
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %51, i64 %53
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.buzzdict_s, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !20
  %62 = call i32 %57(ptr noundef %58, ptr noundef %61)
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %105

64:                                               ; preds = %42
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.buzzdict_s, ptr %65, i32 0, i32 5
  %67 = load ptr, ptr %66, align 8, !tbaa !22
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !20
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !23
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  call void %67(ptr noundef %70, ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.buzzdict_s, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = load i32, ptr %6, align 4, !tbaa !13
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %77, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !13
  call void @buzzdarray_remove(ptr noundef %81, i32 noundef %82)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.buzzdict_s, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !14
  %86 = load i32, ptr %6, align 4, !tbaa !13
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds ptr, ptr %85, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.buzzdarray_s, ptr %89, i32 0, i32 1
  %91 = load i64, ptr %90, align 8, !tbaa !15
  %92 = icmp eq i64 %91, 0
  br i1 %92, label %93, label %100

93:                                               ; preds = %64
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.buzzdict_s, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  %97 = load i32, ptr %6, align 4, !tbaa !13
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds ptr, ptr %96, i64 %98
  call void @buzzdarray_destroy(ptr noundef %99)
  br label %100

100:                                              ; preds = %93, %64
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.buzzdict_s, ptr %101, i32 0, i32 1
  %103 = load i32, ptr %102, align 8, !tbaa !24
  %104 = add i32 %103, -1
  store i32 %104, ptr %102, align 8, !tbaa !24
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %106

105:                                              ; preds = %42
  store i32 0, ptr %8, align 4
  br label %106

106:                                              ; preds = %105, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %107 = load i32, ptr %8, align 4
  switch i32 %107, label %113 [
    i32 0, label %108
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %7, align 4, !tbaa !13
  %111 = add i32 %110, 1
  store i32 %111, ptr %7, align 4, !tbaa !13
  br label %29, !llvm.loop !25

112:                                              ; preds = %29
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %113

113:                                              ; preds = %112, %106, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %114 = load i32, ptr %3, align 4
  ret i32 %114
}

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, !6, i64 16}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !17, i64 8}
!16 = !{!"buzzdarray_s", !6, i64 0, !17, i64 8, !11, i64 16, !11, i64 20, !6, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !6, i64 0}
!19 = !{!10, !6, i64 24}
!20 = !{!21, !6, i64 0}
!21 = !{!"buzzdict_entry_s", !6, i64 0, !6, i64 8}
!22 = !{!10, !6, i64 32}
!23 = !{!21, !6, i64 8}
!24 = !{!10, !11, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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.buzzdict_entry_s = type { ptr, ptr }

declare void @buzzdarray_destroy(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @buzzdict_remove(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 %4(ptr noundef %1) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = urem i32 %5, %7
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %10 = zext i32 %8 to i64
  %11 = getelementptr inbounds ptr, ptr %9, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  br label %17

17:                                               ; preds = %.lr.ph, %.critedge
  %18 = phi ptr [ %12, %.lr.ph ], [ %49, %.critedge ]
  %19 = phi i64 [ 0, %.lr.ph ], [ %46, %.critedge ]
  %.02933 = phi i32 [ 0, %.lr.ph ], [ %45, %.critedge ]
  %20 = load ptr, ptr %18, align 8, !tbaa !17
  %21 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %20, i64 %19
  %22 = load ptr, ptr %16, align 8, !tbaa !18
  %23 = load ptr, ptr %21, align 8, !tbaa !19
  %24 = tail call i32 %22(ptr noundef %1, ptr noundef %23) #2
  %.not31 = icmp eq i32 %24, 0
  br i1 %.not31, label %25, label %.critedge

25:                                               ; preds = %17
  %26 = getelementptr inbounds i8, ptr %0, i64 32
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = load ptr, ptr %21, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %21, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !22
  tail call void %27(ptr noundef %28, ptr noundef %30, ptr noundef nonnull %0) #2
  %31 = load ptr, ptr %0, align 8, !tbaa !12
  %32 = getelementptr inbounds ptr, ptr %31, i64 %10
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  tail call void @buzzdarray_remove(ptr noundef %33, i32 noundef %.02933) #2
  %34 = load ptr, ptr %0, align 8, !tbaa !12
  %35 = getelementptr inbounds ptr, ptr %34, i64 %10
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = load i64, ptr %37, align 8, !tbaa !14
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %25
  tail call void @buzzdarray_destroy(ptr noundef nonnull %35) #2
  br label %41

41:                                               ; preds = %40, %25
  %42 = getelementptr inbounds i8, ptr %0, i64 8
  %43 = load i32, ptr %42, align 8, !tbaa !23
  %44 = add i32 %43, -1
  store i32 %44, ptr %42, align 8, !tbaa !23
  br label %.loopexit

.critedge:                                        ; preds = %17
  %45 = add i32 %.02933, 1
  %46 = zext i32 %45 to i64
  %47 = load ptr, ptr %0, align 8, !tbaa !12
  %48 = getelementptr inbounds ptr, ptr %47, i64 %10
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = getelementptr inbounds i8, ptr %49, i64 8
  %51 = load i64, ptr %50, align 8, !tbaa !14
  %52 = icmp sgt i64 %51, %46
  br i1 %52, label %17, label %.loopexit, !llvm.loop !24

.loopexit:                                        ; preds = %.critedge, %.preheader, %41, %2
  %.2 = phi i32 [ 1, %41 ], [ 0, %2 ], [ 0, %.preheader ], [ 0, %.critedge ]
  ret i32 %.2
}

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, !7, i64 16}
!6 = !{!"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}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 8}
!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, !7, i64 0}
!18 = !{!6, !7, i64 24}
!19 = !{!20, !7, i64 0}
!20 = !{!"buzzdict_entry_s", !7, i64 0, !7, i64 8}
!21 = !{!6, !7, i64 32}
!22 = !{!20, !7, i64 8}
!23 = !{!6, !10, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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