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

41:                                               ; preds = %71, %2
  %42 = load i32, ptr %9, align 4, !tbaa !28
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 2, ptr %10, align 4
  br label %74

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.symboltable_t, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = getelementptr inbounds %struct.ghash_r, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !29
  %51 = load i32, ptr %9, align 4, !tbaa !28
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8
  %58 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %59 = load i64, ptr %58, align 8
  %60 = call ptr @gravity_hash_lookup(ptr noundef %55, ptr %57, i64 %59)
  store ptr %60, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %67

63:                                               ; preds = %45
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.gravity_value_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  store ptr %66, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %68

67:                                               ; preds = %45
  store i32 0, ptr %10, align 4
  br label %68

68:                                               ; preds = %67, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %69 = load i32, ptr %10, align 4
  switch i32 %69, label %74 [
    i32 0, label %70
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %9, align 4, !tbaa !28
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %9, align 4, !tbaa !28
  br label %41, !llvm.loop !30

74:                                               ; preds = %68, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %75 = load i32, ptr %10, align 4
  switch i32 %75, label %77 [
    i32 2, label %76
  ]

76:                                               ; preds = %74
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %77

77:                                               ; preds = %76, %74
  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
  %78 = load ptr, ptr %3, align 8
  ret ptr %78
}

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

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 = !{!"", !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 56}
!16 = !{!10, !13, i64 60}
!17 = !{!10, !13, i64 64}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !7, i64 8}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"symboltable_t", !6, i64 0, !23, i64 8, !23, i64 10, !23, i64 12, !23, i64 14, !13, i64 16}
!23 = !{!"short", !7, i64 0}
!24 = !{!25, !26, i64 0}
!25 = !{!"", !26, i64 0, !26, i64 8, !6, i64 16}
!26 = !{!"long", !7, i64 0}
!27 = !{!26, !26, i64 0}
!28 = !{!13, !13, i64 0}
!29 = !{!25, !6, i64 16}
!30 = distinct !{!30, !31}
!31 = !{!"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.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: nounwind uwtable
define dso_local ptr @symboltable_lookup(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.gravity_string_t, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #5
  %4 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %4, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %5, i8 0, i64 40, i1 false)
  %6 = getelementptr inbounds i8, ptr %3, i64 48
  store ptr %1, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %3, i64 56
  %8 = getelementptr inbounds i8, ptr %3, i64 60
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %8, align 4, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %3, i64 64
  store i32 0, ptr %11, align 8, !tbaa !16
  %12 = tail call i32 @gravity_hash_compute_buffer(ptr noundef %1, i32 noundef %10) #5
  store i32 %12, ptr %7, align 8, !tbaa !17
  %13 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  %14 = ptrtoint ptr %3 to i64
  %15 = load ptr, ptr %0, align 8, !tbaa !18
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = and i64 %16, 4294967295
  br label %18

18:                                               ; preds = %21, %2
  %indvars.iv = phi i64 [ %22, %21 ], [ %17, %2 ]
  %19 = trunc nuw i64 %indvars.iv to i32
  %20 = icmp slt i32 %19, 1
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %18
  %22 = add nsw i64 %indvars.iv, -1
  %23 = load ptr, ptr %0, align 8, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !24
  %26 = getelementptr inbounds ptr, ptr %25, i64 %22
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = call ptr @gravity_hash_lookup(ptr noundef %27, ptr %13, i64 %14) #5
  %.not = icmp eq ptr %28, null
  br i1 %.not, label %18, label %.thread, !llvm.loop !25

.thread:                                          ; preds = %21
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !27
  br label %.loopexit

.loopexit:                                        ; preds = %18, %.thread
  %spec.select = phi ptr [ %30, %.thread ], [ null, %18 ]
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #5
  ret ptr %spec.select
}

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

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

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

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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 = !{!"", !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}
!18 = !{!19, !6, i64 0}
!19 = !{!"symboltable_t", !6, i64 0, !20, i64 8, !20, i64 10, !20, i64 12, !20, i64 14, !13, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!22, !23, i64 0}
!22 = !{!"", !23, i64 0, !23, i64 8, !6, i64 16}
!23 = !{!"long", !7, i64 0}
!24 = !{!22, !6, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!7, !7, i64 0}


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