; LLVM IR from brewlin/garbage-collect :: gc-golang/mgc (mark)

; 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.mspan = type { ptr, ptr, ptr, i64, i64, i64, i8, i8, i8, i16, i32, i64, i8, i16, i8, i8, i16, i64, i64, i64, ptr, ptr, i64 }

; 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 i64 @span_objIndex(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.mspan, ptr %9, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = sub i64 %8, %11
  store i64 %12, ptr %6, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %49

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mspan, ptr %17, i32 0, i32 13
  %19 = load i16, ptr %18, align 2, !tbaa !15
  %20 = zext i16 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %30

22:                                               ; preds = %16
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mspan, ptr %24, i32 0, i32 14
  %26 = load i8, ptr %25, align 4, !tbaa !16
  %27 = zext i8 %26 to i32
  %28 = zext i32 %27 to i64
  %29 = lshr i64 %23, %28
  store i64 %29, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %49

30:                                               ; preds = %16
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mspan, ptr %32, i32 0, i32 14
  %34 = load i8, ptr %33, align 4, !tbaa !16
  %35 = zext i8 %34 to i32
  %36 = zext i32 %35 to i64
  %37 = lshr i64 %31, %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mspan, ptr %38, i32 0, i32 16
  %40 = load i16, ptr %39, align 2, !tbaa !17
  %41 = zext i16 %40 to i64
  %42 = mul i64 %37, %41
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mspan, ptr %43, i32 0, i32 15
  %45 = load i8, ptr %44, align 1, !tbaa !18
  %46 = zext i8 %45 to i32
  %47 = zext i32 %46 to i64
  %48 = lshr i64 %42, %47
  store i64 %48, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %49

49:                                               ; preds = %30, %22, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %50 = load i64, ptr %3, align 8
  ret i64 %50
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"mspan", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 49, !7, i64 50, !13, i64 52, !14, i64 56, !10, i64 64, !7, i64 72, !13, i64 74, !7, i64 76, !7, i64 77, !13, i64 78, !10, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !6, i64 112, !10, i64 120}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !13, i64 74}
!16 = !{!12, !7, i64 76}
!17 = !{!12, !13, i64 78}
!18 = !{!12, !7, i64 77}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i64 @span_objIndex(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %4, %1
  br i1 %5, label %23, label %6

6:                                                ; preds = %2
  %7 = sub i64 %1, %4
  %8 = getelementptr inbounds i8, ptr %0, i64 74
  %9 = load i16, ptr %8, align 2, !tbaa !13
  %.not = icmp eq i16 %9, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 76
  %11 = load i8, ptr %10, align 4, !tbaa !14
  %12 = zext nneg i8 %11 to i64
  %13 = lshr i64 %7, %12
  br i1 %.not, label %14, label %23

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 78
  %16 = load i16, ptr %15, align 2, !tbaa !15
  %17 = zext i16 %16 to i64
  %18 = mul i64 %13, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 77
  %20 = load i8, ptr %19, align 1, !tbaa !16
  %21 = zext nneg i8 %20 to i64
  %22 = lshr i64 %18, %21
  br label %23

23:                                               ; preds = %6, %2, %14
  %.0 = phi i64 [ %22, %14 ], [ 0, %2 ], [ %13, %6 ]
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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, !10, i64 24}
!6 = !{!"mspan", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !8, i64 48, !8, i64 49, !8, i64 50, !11, i64 52, !12, i64 56, !10, i64 64, !8, i64 72, !11, i64 74, !8, i64 76, !8, i64 77, !11, i64 78, !10, i64 80, !10, i64 88, !10, i64 96, !7, i64 104, !7, i64 112, !10, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !11, i64 74}
!14 = !{!6, !8, i64 76}
!15 = !{!6, !11, i64 78}
!16 = !{!6, !8, i64 77}


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