; 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_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_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_delegate_t = type { ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@gravity_class_instance = 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: nounwind uwtable
declare dso_local zeroext i1 @gravity_value_equals(ptr, i64, ptr, i64) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare ptr @gravity_vm_delegate(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @gravity_value_vm_equals(ptr noundef %0, ptr %1, i64 %2, ptr %3, i64 %4) #1 {
  %6 = alloca i1, align 1
  %7 = alloca %struct.gravity_value_t, align 8
  %8 = alloca %struct.gravity_value_t, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  store ptr %1, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  store i64 %2, ptr %16, align 8
  %17 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 0
  store ptr %3, ptr %17, align 8
  %18 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 1
  store i64 %4, ptr %18, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %19 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8
  %21 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %22 = load i64, ptr %21, align 8
  %23 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8
  %25 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 1
  %26 = load i64, ptr %25, align 8
  %27 = call zeroext i1 @gravity_value_equals(ptr %20, i64 %22, ptr %24, i64 %26)
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %10, align 1, !tbaa !9
  %29 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %30 = trunc i8 %29 to i1
  br i1 %30, label %34, label %31

31:                                               ; preds = %5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %37, label %34

34:                                               ; preds = %31, %5
  %35 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %36 = trunc i8 %35 to i1
  store i1 %36, ptr %6, align 1
  store i32 1, ptr %11, align 4
  br label %83

37:                                               ; preds = %31
  %38 = getelementptr inbounds %struct.gravity_value_t, ptr %7, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !5
  %41 = icmp eq ptr %39, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = getelementptr inbounds %struct.gravity_value_t, ptr %8, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !5
  %46 = icmp eq ptr %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %42, %37
  store i1 false, ptr %6, align 1
  store i32 1, ptr %11, align 4
  br label %83

48:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %49 = getelementptr inbounds %struct.gravity_value_t, ptr %7, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  store ptr %50, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %51 = getelementptr inbounds %struct.gravity_value_t, ptr %8, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  store ptr %52, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call ptr @gravity_vm_delegate(ptr noundef %53)
  store ptr %54, ptr %14, align 8, !tbaa !5
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.gravity_instance_t, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %81

59:                                               ; preds = %48
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.gravity_instance_t, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %81

64:                                               ; preds = %59
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gravity_delegate_t, ptr %65, i32 0, i32 21
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %81

69:                                               ; preds = %64
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gravity_delegate_t, ptr %70, i32 0, i32 21
  %72 = load ptr, ptr %71, align 8, !tbaa !19
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gravity_instance_t, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gravity_instance_t, ptr %77, i32 0, i32 3
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = call zeroext i1 %72(ptr noundef %73, ptr noundef %76, ptr noundef %79)
  store i1 %80, ptr %6, align 1
  store i32 1, ptr %11, align 4
  br label %82

81:                                               ; preds = %64, %59, %48
  store i1 false, ptr %6, align 1
  store i32 1, ptr %11, align 4
  br label %82

82:                                               ; preds = %81, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %83

83:                                               ; preds = %82, %47, %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %84 = load i1, ptr %6, align 1
  ret i1 %84
}

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 = { "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, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !7, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !6, i64 56}
!17 = !{!"", !6, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !6, i64 64}
!18 = !{!"gravity_gc_s", !10, i64 0, !10, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!20, !6, i64 160}
!20 = !{!"", !6, i64 0, !10, i64 8, !10, i64 9, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184}


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

@gravity_class_instance = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @gravity_value_equals(ptr, i64, ptr, i64) local_unnamed_addr #0

declare ptr @gravity_vm_delegate(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @gravity_value_vm_equals(ptr noundef %0, ptr %1, i64 %2, ptr %3, i64 %4) local_unnamed_addr #0 {
  %6 = tail call zeroext i1 @gravity_value_equals(ptr %1, i64 %2, ptr %3, i64 %4)
  %7 = icmp eq ptr %0, null
  %or.cond.not = or i1 %7, %6
  br i1 %or.cond.not, label %26, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !5
  %10 = icmp eq ptr %9, %1
  %11 = icmp eq ptr %9, %3
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %12, label %26

12:                                               ; preds = %8
  %13 = inttoptr i64 %2 to ptr
  %14 = tail call ptr @gravity_vm_delegate(ptr noundef nonnull %0) #2
  %15 = getelementptr inbounds i8, ptr %13, i64 56
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %26, label %17

17:                                               ; preds = %12
  %18 = inttoptr i64 %4 to ptr
  %19 = getelementptr inbounds i8, ptr %18, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %.not22 = icmp eq ptr %20, null
  br i1 %.not22, label %26, label %21

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %14, i64 160
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %.not23 = icmp eq ptr %23, null
  br i1 %.not23, label %26, label %24

24:                                               ; preds = %21
  %25 = tail call zeroext i1 %23(ptr noundef nonnull %0, ptr noundef nonnull %16, ptr noundef nonnull %20) #2
  br label %26

26:                                               ; preds = %24, %21, %17, %12, %8, %5
  %.1 = phi i1 [ %6, %5 ], [ false, %8 ], [ %25, %24 ], [ false, %21 ], [ false, %17 ], [ false, %12 ]
  ret i1 %.1
}

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 }

!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 56}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !6, 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 = !{!14, !6, i64 160}
!14 = !{!"", !6, i64 0, !12, i64 8, !12, i64 9, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184}


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