; LLVM IR from marcobambini/gravity :: src/compiler (gravity_symboltable)

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

declare ptr @gravity_hash_lookup(ptr noundef, ptr, i64) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local ptr @symboltable_global_lookup(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.gravity_string_t, align 8
  %7 = alloca %struct.gravity_value_t, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.symboltable_t, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.ghash_r, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds ptr, ptr %13, i64 0
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr %6) #5
  %16 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 0
  %17 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %17, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 8 %18, i8 0, i64 40, i1 false)
  %19 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %20, ptr %19, align 8, !tbaa !20
  %21 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 3
  store i32 0, ptr %21, align 8, !tbaa !21
  %22 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 4
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call i64 @strlen(ptr noundef %23) #6
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %22, align 4, !tbaa !22
  %26 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 5
  store i32 0, ptr %26, align 8, !tbaa !23
  %27 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 4
  %30 = load i32, ptr %29, align 4, !tbaa !22
  %31 = call i32 @gravity_hash_compute_buffer(ptr noundef %28, i32 noundef %30)
  %32 = getelementptr inbounds %struct.gravity_string_t, ptr %6, i32 0, i32 3
  store i32 %31, ptr %32, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %33 = getelementptr inbounds %struct.gravity_value_t, ptr %7, i32 0, i32 0
  %34 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %34, ptr %33, align 8, !tbaa !24
  %35 = getelementptr inbounds %struct.gravity_value_t, ptr %7, i32 0, i32 1
  store ptr %6, ptr %35, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8
  %39 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %40 = load i64, ptr %39, align 8
  %41 = call ptr @gravity_hash_lookup(ptr noundef %36, ptr %38, i64 %40)
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %48

44:                                               ; preds = %2
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gravity_value_t, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !26
  br label %49

48:                                               ; preds = %2
  br label %49

49:                                               ; preds = %48, %44
  %50 = phi ptr [ %47, %44 ], [ null, %48 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 72, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %50
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind willreturn memory(read) "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 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"symboltable_t", !6, i64 0, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !12, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !18, i64 8, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64}
!18 = !{!"gravity_gc_s", !19, i64 0, !19, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!17, !6, i64 48}
!21 = !{!17, !12, i64 56}
!22 = !{!17, !12, i64 60}
!23 = !{!17, !12, i64 64}
!24 = !{!25, !6, i64 0}
!25 = !{!"", !6, i64 0, !7, i64 8}
!26 = !{!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

declare ptr @gravity_hash_lookup(ptr noundef, ptr, i64) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local ptr @symboltable_global_lookup(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %3 = alloca %struct.gravity_string_t, align 8
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #5
  %8 = load ptr, ptr @gravity_class_string, align 8, !tbaa !15
  store ptr %8, ptr %3, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %9, i8 0, i64 40, i1 false)
  %10 = getelementptr inbounds i8, ptr %3, i64 48
  store ptr %1, ptr %10, align 8, !tbaa !20
  %11 = getelementptr inbounds i8, ptr %3, i64 56
  %12 = getelementptr inbounds i8, ptr %3, i64 60
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %12, align 4, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %3, i64 64
  store i32 0, ptr %15, align 8, !tbaa !22
  %16 = tail call i32 @gravity_hash_compute_buffer(ptr noundef %1, i32 noundef %14) #5
  store i32 %16, ptr %11, align 8, !tbaa !23
  %17 = load ptr, ptr @gravity_class_string, align 8, !tbaa !15
  %18 = ptrtoint ptr %3 to i64
  %19 = call ptr @gravity_hash_lookup(ptr noundef %7, ptr %17, i64 %18) #5
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %23, label %20

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %19, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !24
  br label %23

23:                                               ; preds = %2, %20
  %24 = phi ptr [ %22, %20 ], [ null, %2 ]
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #5
  ret ptr %24
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"symboltable_t", !7, i64 0, !10, i64 8, !10, i64 10, !10, i64 12, !10, i64 14, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 16}
!13 = !{!"", !14, i64 0, !14, i64 8, !7, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !18, i64 8, !7, i64 48, !11, i64 56, !11, i64 60, !11, i64 64}
!18 = !{!"gravity_gc_s", !19, i64 0, !19, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!19 = !{!"_Bool", !8, i64 0}
!20 = !{!17, !7, i64 48}
!21 = !{!17, !11, i64 60}
!22 = !{!17, !11, i64 64}
!23 = !{!17, !11, i64 56}
!24 = !{!8, !8, i64 0}


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