; LLVM IR from marcobambini/gravity :: src/shared (gravity_hash)

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

@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: nounwind uwtable
declare dso_local ptr @gravity_hash_lookup(ptr noundef, ptr, i64) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_hash_lookup_cstring(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.gravity_string_t, align 8
  %6 = alloca %struct.gravity_value_t, 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 72, ptr %5) #4
  %7 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 0
  %8 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %8, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 40, i1 false)
  %10 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 3
  store i32 0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #5
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %13, align 4, !tbaa !16
  %17 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 5
  store i32 0, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 4
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = call i32 @gravity_hash_compute_buffer(ptr noundef %19, i32 noundef %21)
  %23 = getelementptr inbounds %struct.gravity_string_t, ptr %5, i32 0, i32 3
  store i32 %22, ptr %23, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %24 = getelementptr inbounds %struct.gravity_value_t, ptr %6, i32 0, i32 0
  %25 = load ptr, ptr @gravity_class_string, align 8, !tbaa !5
  store ptr %25, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds %struct.gravity_value_t, ptr %6, i32 0, i32 1
  store ptr %5, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8
  %30 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %31 = load i64, ptr %30, align 8
  %32 = call ptr @gravity_hash_lookup(ptr noundef %27, ptr %29, i64 %31)
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %5) #4
  ret ptr %32
}

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @gravity_hash_compute_buffer(ptr noundef, i32 noundef) #1

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 = { 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 }
attributes #5 = { 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}


; 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: nounwind uwtable
declare dso_local ptr @gravity_hash_lookup(ptr noundef, ptr, i64) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_hash_lookup_cstring(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.gravity_string_t, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #4
  %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) #5
  %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)
  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 = call ptr @gravity_hash_lookup(ptr noundef %0, ptr %13, i64 %14)
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #4
  ret ptr %15
}

; 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

; Function Attrs: nounwind uwtable
declare dso_local 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 = { 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 = { 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 }
attributes #5 = { 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}


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