; LLVM IR from marcobambini/gravity :: src/runtime (gravity_vm)

; 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.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%struct.gravity_string_t = type { ptr, %struct.gravity_gc_s, ptr, i32, i32, i32 }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }

@gravity_class_string = external global ptr, align 8

; 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: inlinehint nounwind uwtable
declare dso_local { ptr, i64 } @gravity_vm_lookup(ptr noundef, ptr, i64) #1

; Function Attrs: inlinehint nounwind uwtable
define dso_local { ptr, i64 } @gravity_vm_getvalue(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca %struct.gravity_value_t, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.gravity_string_t, align 8
  %9 = alloca %struct.gravity_value_t, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %8) #4
  %10 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 0
  %11 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %11, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 40, i1 false)
  %13 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 3
  store i32 0, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 4
  %17 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %17, ptr %16, align 4, !tbaa !17
  %18 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 5
  store i32 0, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !17
  %23 = call i32 @gravity_hash_compute_buffer(ptr noundef %20, i32 noundef %22)
  %24 = getelementptr inbounds %struct.gravity_string_t, ptr %8, i32 0, i32 3
  store i32 %23, ptr %24, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %25 = getelementptr inbounds %struct.gravity_value_t, ptr %9, i32 0, i32 0
  %26 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %26, ptr %25, align 8, !tbaa !19
  %27 = getelementptr inbounds %struct.gravity_value_t, ptr %9, i32 0, i32 1
  store ptr %8, ptr %27, align 8, !tbaa !21
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds { ptr, i64 }, ptr %9, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8
  %31 = getelementptr inbounds { ptr, i64 }, ptr %9, i32 0, i32 1
  %32 = load i64, ptr %31, align 8
  %33 = call { ptr, i64 } @gravity_vm_lookup(ptr noundef %28, ptr %30, i64 %32)
  %34 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  %35 = extractvalue { ptr, i64 } %33, 0
  store ptr %35, ptr %34, align 8
  %36 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  %37 = extractvalue { ptr, i64 } %33, 1
  store i64 %37, ptr %36, align 8
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %8) #4
  %38 = load { ptr, i64 }, ptr %4, align 8
  ret { ptr, i64 } %38
}

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

declare i32 @gravity_hash_compute_buffer(ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64}
!13 = !{!"gravity_gc_s", !14, i64 0, !14, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !6, i64 48}
!16 = !{!12, !10, i64 56}
!17 = !{!12, !10, i64 60}
!18 = !{!12, !10, i64 64}
!19 = !{!20, !6, i64 0}
!20 = !{!"", !6, i64 0, !7, i64 8}
!21 = !{!7, !7, i64 0}


; 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.gravity_string_t = type { ptr, %struct.gravity_gc_s, ptr, i32, i32, i32 }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }

@gravity_class_string = external local_unnamed_addr global ptr, align 8

; 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

; Function Attrs: inlinehint nounwind uwtable
declare dso_local { ptr, i64 } @gravity_vm_lookup(ptr noundef, ptr, i64) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
define dso_local { ptr, i64 } @gravity_vm_getvalue(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.gravity_string_t, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #4
  %5 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %5, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %6, i8 0, i64 40, i1 false)
  %7 = getelementptr inbounds i8, ptr %4, i64 48
  store ptr %1, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %4, i64 56
  %9 = getelementptr inbounds i8, ptr %4, i64 60
  store i32 %2, ptr %9, align 4, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %4, i64 64
  store i32 0, ptr %10, align 8, !tbaa !16
  %11 = tail call i32 @gravity_hash_compute_buffer(ptr noundef %1, i32 noundef %2) #4
  store i32 %11, ptr %8, align 8, !tbaa !17
  %12 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  %13 = ptrtoint ptr %4 to i64
  %14 = call { ptr, i64 } @gravity_vm_lookup(ptr noundef %0, ptr %12, i64 %13)
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #4
  ret { ptr, i64 } %14
}

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

declare i32 @gravity_hash_compute_buffer(ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !13, i64 56, !13, i64 60, !13, i64 64}
!11 = !{!"gravity_gc_s", !12, i64 0, !12, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 48}
!15 = !{!10, !13, i64 60}
!16 = !{!10, !13, i64 64}
!17 = !{!10, !13, i64 56}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass