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

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

@gravity_class_closure = external global ptr, align 8
@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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

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

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

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

34:                                               ; preds = %66, %2
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %67

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gravity_class_s, ptr %38, i32 0, i32 11
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8
  %43 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %44 = load i64, ptr %43, align 8
  %45 = call ptr @gravity_hash_lookup(ptr noundef %40, ptr %42, i64 %44)
  store ptr %45, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %60

48:                                               ; preds = %37
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gravity_value_t, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = getelementptr inbounds %struct.gravity_class_s, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !25
  %54 = load ptr, ptr @gravity_class_closure, align 8, !tbaa !5
  %55 = icmp eq ptr %53, %54
  br i1 %55, label %56, label %60

56:                                               ; preds = %48
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gravity_value_t, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  store ptr %59, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %64

60:                                               ; preds = %48, %37
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gravity_class_s, ptr %61, i32 0, i32 9
  %63 = load ptr, ptr %62, align 8, !tbaa !26
  store ptr %63, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %64

64:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %65 = load i32, ptr %10, align 4
  switch i32 %65, label %68 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %34, !llvm.loop !27

67:                                               ; preds = %34
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %68

68:                                               ; preds = %67, %64
  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
  %69 = load ptr, ptr %3, align 8
  ret ptr %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 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 = !{!"", !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 48}
!22 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !6, i64 64}
!23 = !{!24, !6, i64 96}
!24 = !{!"gravity_class_s", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !12, i64 64, !12, i64 65, !12, i64 66, !12, i64 67, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !13, i64 104, !6, i64 112}
!25 = !{!24, !6, i64 0}
!26 = !{!24, !6, i64 80}
!27 = distinct !{!27, !28}
!28 = !{!"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_closure = external local_unnamed_addr global ptr, align 8
@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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gravity_instance_lookup_event(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %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 = getelementptr inbounds i8, ptr %0, i64 48
  %.01118 = load ptr, ptr %15, align 8, !tbaa !5
  %.not19 = icmp eq ptr %.01118, null
  br i1 %.not19, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2, %25
  %.01120 = phi ptr [ %.011, %25 ], [ %.01118, %2 ]
  %16 = getelementptr inbounds i8, ptr %.01120, i64 96
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = call ptr @gravity_hash_lookup(ptr noundef %17, ptr %13, i64 %14) #5
  %.not14 = icmp eq ptr %18, null
  br i1 %.not14, label %25, label %19

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %23 = load ptr, ptr @gravity_class_closure, align 8, !tbaa !5
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %.thread, label %25

25:                                               ; preds = %.lr.ph, %19
  %26 = getelementptr inbounds i8, ptr %.01120, i64 80
  %.011 = load ptr, ptr %26, align 8, !tbaa !5
  %.not = icmp eq ptr %.011, null
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !22

.thread:                                          ; preds = %25, %19, %2
  %.2 = phi ptr [ null, %2 ], [ %21, %19 ], [ null, %25 ]
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #5
  ret ptr %.2
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { 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 = !{!"", !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 96}
!19 = !{!"gravity_class_s", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !12, i64 64, !12, i64 65, !12, i64 66, !12, i64 67, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !13, i64 104, !6, i64 112}
!20 = !{!7, !7, i64 0}
!21 = !{!19, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass