; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @buzzdict_rawget(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %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) #2
  %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) #2
  %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 ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %76

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

29:                                               ; preds = %72, %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 %75

42:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %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 %68

64:                                               ; preds = %42
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !22
  store ptr %67, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %69

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

69:                                               ; preds = %68, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %70 = load i32, ptr %8, align 4
  switch i32 %70, label %76 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %7, align 4, !tbaa !13
  %74 = add i32 %73, 1
  store i32 %74, ptr %7, align 4, !tbaa !13
  br label %29, !llvm.loop !23

75:                                               ; preds = %29
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %76

76:                                               ; preds = %75, %69, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %77 = load ptr, ptr %3, align 8
  ret ptr %77
}

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 = { 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 = !{!21, !6, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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 }

; Function Attrs: nounwind uwtable
define dso_local ptr @buzzdict_rawget(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %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) #1
  %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 %26

17:                                               ; preds = %26
  %18 = add i32 %.01822, 1
  %19 = zext i32 %18 to i64
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = getelementptr inbounds ptr, ptr %20, i64 %10
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %25 = icmp sgt i64 %24, %19
  br i1 %25, label %26, label %.loopexit, !llvm.loop !17

26:                                               ; preds = %.lr.ph, %17
  %27 = phi ptr [ %12, %.lr.ph ], [ %22, %17 ]
  %28 = phi i64 [ 0, %.lr.ph ], [ %19, %17 ]
  %.01822 = phi i32 [ 0, %.lr.ph ], [ %18, %17 ]
  %29 = load ptr, ptr %27, align 8, !tbaa !19
  %30 = getelementptr inbounds %struct.buzzdict_entry_s, ptr %29, i64 %28
  %31 = load ptr, ptr %16, align 8, !tbaa !20
  %32 = load ptr, ptr %30, align 8, !tbaa !21
  %33 = tail call i32 %31(ptr noundef %1, ptr noundef %32) #1
  %.not20 = icmp eq i32 %33, 0
  br i1 %.not20, label %.thread, label %17

.thread:                                          ; preds = %26
  %34 = getelementptr inbounds i8, ptr %30, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  br label %.loopexit

.loopexit:                                        ; preds = %17, %.preheader, %.thread, %2
  %.2 = phi ptr [ null, %2 ], [ %35, %.thread ], [ null, %.preheader ], [ null, %17 ]
  ret ptr %.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 = { 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 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!15, !7, i64 0}
!20 = !{!6, !7, i64 24}
!21 = !{!22, !7, i64 0}
!22 = !{!"buzzdict_entry_s", !7, i64 0, !7, i64 8}
!23 = !{!22, !7, i64 8}


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