; 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.fiber_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, i32, ptr, i32, i32, ptr, ptr, i8, ptr, %struct.gravity_value_t, i32, i64, double, double }
%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_callframe_t = type { ptr, i32, i16, ptr, ptr, ptr, i8 }
%struct.gravity_closure_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, ptr, ptr, i32 }
%struct.gravity_function_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, i16, i16, i16, i16, i32, %union.anon.4 }
%union.anon.4 = type { %struct.anon.5 }
%struct.anon.5 = type { %struct.gravity_value_r, %struct.gravity_value_r, %struct.gravity_value_r, i32, ptr, ptr, float, i8 }
%struct.gravity_value_r = type { i64, i64, ptr }

; 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
define dso_local void @gravity_fiber_reassign(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.fiber_s, ptr %8, i32 0, i32 5
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.gravity_callframe_t, ptr %10, i64 0
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_callframe_t, ptr %13, i32 0, i32 4
  store ptr %12, ptr %14, align 8, !tbaa !19
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gravity_closure_s, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds %struct.gravity_function_t, ptr %17, i32 0, i32 8
  %19 = load i32, ptr %18, align 8, !tbaa !23
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %28

21:                                               ; preds = %3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gravity_closure_s, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds %struct.gravity_function_t, ptr %24, i32 0, i32 9
  %26 = getelementptr inbounds %struct.anon.5, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !25
  br label %29

28:                                               ; preds = %3
  br label %29

29:                                               ; preds = %28, %21
  %30 = phi ptr [ %27, %21 ], [ null, %28 ]
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gravity_callframe_t, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !26
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gravity_callframe_t, ptr %33, i32 0, i32 1
  store i32 0, ptr %34, align 8, !tbaa !27
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.fiber_s, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !28
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gravity_callframe_t, ptr %38, i32 0, i32 5
  store ptr %37, ptr %39, align 8, !tbaa !29
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.fiber_s, ptr %40, i32 0, i32 6
  store i32 1, ptr %41, align 8, !tbaa !30
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.fiber_s, ptr %42, i32 0, i32 8
  store ptr null, ptr %43, align 8, !tbaa !31
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.gravity_closure_s, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !21
  %47 = getelementptr inbounds %struct.gravity_function_t, ptr %46, i32 0, i32 4
  %48 = load i16, ptr %47, align 8, !tbaa !32
  %49 = zext i16 %48 to i32
  %50 = load i16, ptr %6, align 2, !tbaa !9
  %51 = zext i16 %50 to i32
  %52 = icmp sgt i32 %49, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %29
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gravity_closure_s, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = getelementptr inbounds %struct.gravity_function_t, ptr %56, i32 0, i32 4
  %58 = load i16, ptr %57, align 8, !tbaa !32
  %59 = zext i16 %58 to i32
  br label %63

60:                                               ; preds = %29
  %61 = load i16, ptr %6, align 2, !tbaa !9
  %62 = zext i16 %61 to i32
  br label %63

63:                                               ; preds = %60, %53
  %64 = phi i32 [ %59, %53 ], [ %62, %60 ]
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gravity_closure_s, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = getelementptr inbounds %struct.gravity_function_t, ptr %67, i32 0, i32 5
  %69 = load i16, ptr %68, align 2, !tbaa !33
  %70 = zext i16 %69 to i32
  %71 = add nsw i32 %64, %70
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gravity_closure_s, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !21
  %75 = getelementptr inbounds %struct.gravity_function_t, ptr %74, i32 0, i32 6
  %76 = load i16, ptr %75, align 4, !tbaa !34
  %77 = zext i16 %76 to i32
  %78 = add nsw i32 %71, %77
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.fiber_s, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !35
  %82 = sext i32 %78 to i64
  %83 = getelementptr inbounds %struct.gravity_value_t, ptr %81, i64 %82
  store ptr %83, ptr %80, align 8, !tbaa !35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 72}
!12 = !{!"fiber_s", !6, i64 0, !13, i64 8, !6, i64 48, !6, i64 56, !15, i64 64, !6, i64 72, !15, i64 80, !15, i64 84, !6, i64 88, !6, i64 96, !14, i64 104, !6, i64 112, !16, i64 120, !15, i64 136, !17, i64 144, !18, i64 152, !18, i64 160}
!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 = !{!"int", !7, i64 0}
!16 = !{!"", !6, i64 0, !7, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!20, !6, i64 24}
!20 = !{!"", !6, i64 0, !15, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!21 = !{!22, !6, i64 56}
!22 = !{!"gravity_closure_s", !6, i64 0, !13, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !15, i64 80}
!23 = !{!24, !15, i64 72}
!24 = !{!"", !6, i64 0, !13, i64 8, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 66, !10, i64 68, !10, i64 70, !15, i64 72, !7, i64 80}
!25 = !{!7, !7, i64 0}
!26 = !{!20, !6, i64 0}
!27 = !{!20, !15, i64 8}
!28 = !{!12, !6, i64 48}
!29 = !{!20, !6, i64 32}
!30 = !{!12, !15, i64 80}
!31 = !{!12, !6, i64 88}
!32 = !{!24, !10, i64 64}
!33 = !{!24, !10, i64 66}
!34 = !{!24, !10, i64 68}
!35 = !{!12, !6, i64 56}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @gravity_fiber_reassign(ptr nocapture noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %1, ptr %6, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %1, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %8, i64 72
  %10 = load i32, ptr %9, align 8, !tbaa !21
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = getelementptr inbounds i8, ptr %8, i64 160
  %14 = load ptr, ptr %13, align 8, !tbaa !23
  br label %15

15:                                               ; preds = %3, %12
  %16 = phi ptr [ %14, %12 ], [ null, %3 ]
  store ptr %16, ptr %5, align 8, !tbaa !24
  %17 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 0, ptr %17, align 8, !tbaa !25
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  %19 = load ptr, ptr %18, align 8, !tbaa !26
  %20 = getelementptr inbounds i8, ptr %5, i64 32
  store ptr %19, ptr %20, align 8, !tbaa !27
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 1, ptr %21, align 8, !tbaa !28
  %22 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr null, ptr %22, align 8, !tbaa !29
  %23 = getelementptr inbounds i8, ptr %8, i64 64
  %24 = load i16, ptr %23, align 8, !tbaa !30
  %. = tail call i16 @llvm.umax.i16(i16 %24, i16 %2)
  %25 = zext i16 %. to i64
  %26 = getelementptr inbounds i8, ptr %8, i64 66
  %27 = load i16, ptr %26, align 2, !tbaa !31
  %28 = zext i16 %27 to i64
  %29 = getelementptr inbounds i8, ptr %8, i64 68
  %30 = load i16, ptr %29, align 4, !tbaa !32
  %31 = zext i16 %30 to i64
  %32 = getelementptr inbounds i8, ptr %0, i64 56
  %33 = load ptr, ptr %32, align 8, !tbaa !33
  %34 = getelementptr inbounds %struct.gravity_value_t, ptr %33, i64 %25
  %35 = getelementptr inbounds %struct.gravity_value_t, ptr %34, i64 %28
  %36 = getelementptr inbounds %struct.gravity_value_t, ptr %35, i64 %31
  store ptr %36, ptr %32, align 8, !tbaa !33
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umax.i16(i16, i16) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 72}
!6 = !{!"fiber_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !12, i64 64, !7, i64 72, !12, i64 80, !12, i64 84, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !13, i64 120, !12, i64 136, !14, i64 144, !15, i64 152, !15, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"gravity_gc_s", !11, i64 0, !11, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !7, i64 0, !8, i64 8}
!14 = !{!"long", !8, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!17, !7, i64 24}
!17 = !{!"", !7, i64 0, !12, i64 8, !18, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40}
!18 = !{!"short", !8, i64 0}
!19 = !{!20, !7, i64 56}
!20 = !{!"gravity_closure_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !12, i64 80}
!21 = !{!22, !12, i64 72}
!22 = !{!"", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !18, i64 64, !18, i64 66, !18, i64 68, !18, i64 70, !12, i64 72, !8, i64 80}
!23 = !{!8, !8, i64 0}
!24 = !{!17, !7, i64 0}
!25 = !{!17, !12, i64 8}
!26 = !{!6, !7, i64 48}
!27 = !{!17, !7, i64 32}
!28 = !{!6, !12, i64 80}
!29 = !{!6, !7, i64 88}
!30 = !{!22, !18, i64 64}
!31 = !{!22, !18, i64 66}
!32 = !{!22, !18, i64 68}
!33 = !{!6, !7, i64 56}


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