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

@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@gravity_class_class = external global ptr, align 8
@gravity_class_null = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.gravity_class_new_single = external hidden unnamed_addr constant [80 x i8], align 1

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

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare ptr @string_dup(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @gravity_value_hash(ptr, i64) #3

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

declare void @gravity_vm_transfer(ptr noundef, ptr noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_class_new_single(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.gravity_value_t, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %10 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 120)
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %15

14:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 155, ptr noundef @__PRETTY_FUNCTION__.gravity_class_new_single) #6
  unreachable

15:                                               ; preds = %13
  %16 = load ptr, ptr @gravity_class_class, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_class_s, ptr %17, i32 0, i32 0
  store ptr %16, ptr %18, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call ptr @string_dup(ptr noundef %19)
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gravity_class_s, ptr %21, i32 0, i32 3
  store ptr %20, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gravity_class_s, ptr %23, i32 0, i32 9
  store ptr null, ptr %24, align 8, !tbaa !16
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gravity_class_s, ptr %26, i32 0, i32 12
  store i32 %25, ptr %27, align 8, !tbaa !17
  %28 = call ptr @gravity_hash_create(i32 noundef 0, ptr noundef @gravity_value_hash, ptr noundef @gravity_value_equals, ptr noundef @gravity_hash_keyfree, ptr noundef null)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gravity_class_s, ptr %29, i32 0, i32 11
  store ptr %28, ptr %30, align 8, !tbaa !18
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %59

33:                                               ; preds = %15
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = mul i64 %35, 16
  %37 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef %36)
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gravity_class_s, ptr %38, i32 0, i32 13
  store ptr %37, ptr %39, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %55, %33
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = icmp ult i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %58

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gravity_class_s, ptr %46, i32 0, i32 13
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds %struct.gravity_value_t, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.gravity_value_t, ptr %9, i32 0, i32 0
  %53 = load ptr, ptr @gravity_class_null, align 8, !tbaa !5
  store ptr %53, ptr %52, align 8, !tbaa !20
  %54 = getelementptr inbounds %struct.gravity_value_t, ptr %9, i32 0, i32 1
  store i64 0, ptr %54, align 8, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !23
  br label %55

55:                                               ; preds = %45
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !24

58:                                               ; preds = %44
  br label %59

59:                                               ; preds = %58, %15
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gravity_vm_transfer(ptr noundef %63, ptr noundef %64)
  br label %65

65:                                               ; preds = %62, %59
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret ptr %66
}

declare void @gravity_hash_keyfree(ptr noundef, ptr, i64, ptr, i64, ptr 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 = { noreturn 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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"gravity_class_s", !6, i64 0, !13, i64 8, !6, i64 48, !6, i64 56, !14, i64 64, !14, i64 65, !14, i64 66, !14, i64 67, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !6, i64 112}
!13 = !{!"gravity_gc_s", !14, i64 0, !14, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !6, i64 56}
!16 = !{!12, !6, i64 80}
!17 = !{!12, !10, i64 104}
!18 = !{!12, !6, i64 96}
!19 = !{!12, !6, i64 112}
!20 = !{!21, !6, i64 0}
!21 = !{!"", !6, i64 0, !7, i64 8}
!22 = !{!7, !7, i64 0}
!23 = !{i64 0, i64 8, !5, i64 8, i64 8, !22}
!24 = distinct !{!24, !25}
!25 = !{!"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_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@gravity_class_class = external local_unnamed_addr global ptr, align 8
@gravity_class_null = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.gravity_class_new_single = external hidden unnamed_addr constant [80 x i8], align 1

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @string_dup(ptr noundef) local_unnamed_addr #0

declare ptr @gravity_hash_create(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gravity_value_hash(ptr, i64) #2

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

declare void @gravity_vm_transfer(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_class_new_single(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 120) #3
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 155, ptr noundef nonnull @__PRETTY_FUNCTION__.gravity_class_new_single) #4
  unreachable

6:                                                ; preds = %3
  %7 = load ptr, ptr @gravity_class_class, align 8, !tbaa !5
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = tail call ptr @string_dup(ptr noundef %1) #3
  %9 = getelementptr inbounds i8, ptr %4, i64 56
  store ptr %8, ptr %9, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %4, i64 80
  store ptr null, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %4, i64 104
  store i32 %2, ptr %11, align 8, !tbaa !16
  %12 = tail call ptr @gravity_hash_create(i32 noundef 0, ptr noundef nonnull @gravity_value_hash, ptr noundef nonnull @gravity_value_equals, ptr noundef nonnull @gravity_hash_keyfree, ptr noundef null) #3
  %13 = getelementptr inbounds i8, ptr %4, i64 96
  store ptr %12, ptr %13, align 8, !tbaa !17
  %.not22 = icmp eq i32 %2, 0
  br i1 %.not22, label %.loopexit, label %14

14:                                               ; preds = %6
  %15 = zext i32 %2 to i64
  %16 = shl nuw nsw i64 %15, 4
  %17 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef %16) #3
  %18 = getelementptr inbounds i8, ptr %4, i64 112
  store ptr %17, ptr %18, align 8, !tbaa !18
  %xtraiter = and i64 %15, 1
  %19 = icmp eq i32 %2, 1
  br i1 %19, label %.loopexit.loopexit.unr-lcssa, label %.new

.new:                                             ; preds = %14
  %unroll_iter = and i64 %15, 4294967294
  br label %20

20:                                               ; preds = %20, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.1, %20 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.1, %20 ]
  %21 = load ptr, ptr %18, align 8, !tbaa !18
  %22 = getelementptr inbounds %struct.gravity_value_t, ptr %21, i64 %indvars.iv
  %23 = load ptr, ptr @gravity_class_null, align 8, !tbaa !5
  store ptr %23, ptr %22, align 8, !tbaa !5
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  store i64 0, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %24 = load ptr, ptr %18, align 8, !tbaa !18
  %25 = getelementptr inbounds %struct.gravity_value_t, ptr %24, i64 %indvars.iv.next
  %26 = load ptr, ptr @gravity_class_null, align 8, !tbaa !5
  store ptr %26, ptr %25, align 8, !tbaa !5
  %.sroa.2.0..sroa_idx.1 = getelementptr inbounds i8, ptr %25, i64 8
  store i64 0, ptr %.sroa.2.0..sroa_idx.1, align 8, !tbaa !19
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %20, !llvm.loop !20

.loopexit.loopexit.unr-lcssa:                     ; preds = %20, %14
  %indvars.iv.unr = phi i64 [ 0, %14 ], [ %indvars.iv.next.1, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %27 = load ptr, ptr %18, align 8, !tbaa !18
  %28 = getelementptr inbounds %struct.gravity_value_t, ptr %27, i64 %indvars.iv.unr
  %29 = load ptr, ptr @gravity_class_null, align 8, !tbaa !5
  store ptr %29, ptr %28, align 8, !tbaa !5
  %.sroa.2.0..sroa_idx.epil = getelementptr inbounds i8, ptr %28, i64 8
  store i64 0, ptr %.sroa.2.0..sroa_idx.epil, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %6
  %.not23 = icmp eq ptr %0, null
  br i1 %.not23, label %31, label %30

30:                                               ; preds = %.loopexit
  tail call void @gravity_vm_transfer(ptr noundef nonnull %0, ptr noundef nonnull %4) #3
  br label %31

31:                                               ; preds = %30, %.loopexit
  ret ptr %4
}

declare void @gravity_hash_keyfree(ptr noundef, ptr, i64, ptr, i64, ptr noundef) #0

attributes #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 = { noreturn 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 #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 = { nounwind }
attributes #4 = { noreturn 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_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}
!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 56}
!15 = !{!10, !6, i64 80}
!16 = !{!10, !13, i64 104}
!17 = !{!10, !6, i64 96}
!18 = !{!10, !6, i64 112}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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