; 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_vm = type { ptr, ptr, ptr, ptr, i32, double, i8, i32, i32, i64, i64, i32, [64 x i8], ptr, ptr, ptr, i32, i64, i64, ptr, i64, i64, i64, double, i64, %struct.gravity_object_r, %struct.gravity_object_r }
%struct.gravity_object_r = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @gravity_vm_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  br label %46

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  call void @gravity_vm_cleanup(ptr noundef %7)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.gravity_vm, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %16

12:                                               ; preds = %6
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_vm, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  call void @gravity_hash_free(ptr noundef %15)
  br label %16

16:                                               ; preds = %12, %6
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_vm, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  call void @gravity_cache_free()
  br label %22

22:                                               ; preds = %21, %16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gravity_vm, ptr %23, i32 0, i32 26
  %25 = getelementptr inbounds %struct.gravity_object_r, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %33

28:                                               ; preds = %22
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gravity_vm, ptr %29, i32 0, i32 26
  %31 = getelementptr inbounds %struct.gravity_object_r, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  call void @free(ptr noundef %32) #3
  br label %33

33:                                               ; preds = %28, %22
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.gravity_vm, ptr %34, i32 0, i32 25
  %36 = getelementptr inbounds %struct.gravity_object_r, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %44

39:                                               ; preds = %33
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gravity_vm, ptr %40, i32 0, i32 25
  %42 = getelementptr inbounds %struct.gravity_object_r, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  call void @free(ptr noundef %43) #3
  br label %44

44:                                               ; preds = %39, %33
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %45) #3
  br label %46

46:                                               ; preds = %44, %5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_vm_cleanup(ptr noundef) #0

declare void @gravity_hash_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_cache_free() #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

attributes #0 = { 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 #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 "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 = { 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 = !{!"gravity_vm", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !13, i64 48, !11, i64 52, !11, i64 56, !14, i64 64, !14, i64 72, !11, i64 80, !7, i64 84, !6, i64 152, !6, i64 160, !6, i64 168, !11, i64 176, !14, i64 184, !14, i64 192, !6, i64 200, !14, i64 208, !14, i64 216, !14, i64 224, !12, i64 232, !14, i64 240, !15, i64 248, !15, i64 272}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 8, !6, i64 16}
!16 = !{!10, !6, i64 288}
!17 = !{!10, !6, i64 264}


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

; Function Attrs: nounwind uwtable
define dso_local void @gravity_vm_free(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %14, label %2

2:                                                ; preds = %1
  tail call void @gravity_vm_cleanup(ptr noundef nonnull %0)
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not13 = icmp eq ptr %3, null
  br i1 %.not13, label %.thread, label %4

4:                                                ; preds = %2
  tail call void @gravity_hash_free(ptr noundef nonnull %3) #3
  %.pr = load ptr, ptr %0, align 8, !tbaa !5
  %.not14 = icmp eq ptr %.pr, null
  br i1 %.not14, label %.thread, label %5

5:                                                ; preds = %4
  tail call void @gravity_cache_free()
  br label %.thread

.thread:                                          ; preds = %2, %5, %4
  %6 = getelementptr inbounds i8, ptr %0, i64 288
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %.not15 = icmp eq ptr %7, null
  br i1 %.not15, label %9, label %8

8:                                                ; preds = %.thread
  tail call void @free(ptr noundef nonnull %7) #3
  br label %9

9:                                                ; preds = %8, %.thread
  %10 = getelementptr inbounds i8, ptr %0, i64 264
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %.not16 = icmp eq ptr %11, null
  br i1 %.not16, label %13, label %12

12:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %11) #3
  br label %13

13:                                               ; preds = %12, %9
  tail call void @free(ptr noundef nonnull %0) #3
  br label %14

14:                                               ; preds = %1, %13
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_vm_cleanup(ptr noundef) local_unnamed_addr #0

declare void @gravity_hash_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_cache_free() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 #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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !7, i64 0}
!6 = !{!"gravity_vm", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !12, i64 48, !10, i64 52, !10, i64 56, !13, i64 64, !13, i64 72, !10, i64 80, !8, i64 84, !7, i64 152, !7, i64 160, !7, i64 168, !10, i64 176, !13, i64 184, !13, i64 192, !7, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !11, i64 232, !13, i64 240, !14, i64 248, !14, i64 272}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 8, !7, i64 16}
!15 = !{!6, !7, i64 288}
!16 = !{!6, !7, i64 264}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass