; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_gc)

; 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.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%union.TValue = type { i64 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.2, %struct.MRef, i32 }
%union.anon.2 = type { %union.TValue }
%struct.GCRef = type { i32 }
%struct.MRef = type { i32 }
%struct.GChead = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.GCRef }

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_barrierf(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.global_State, ptr %7, i32 0, i32 5
  %9 = getelementptr inbounds %struct.GCState, ptr %8, i32 0, i32 3
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %20, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.global_State, ptr %14, i32 0, i32 5
  %16 = getelementptr inbounds %struct.GCState, ptr %15, i32 0, i32 3
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %20, label %23

20:                                               ; preds = %13, %3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gc_mark(ptr noundef %21, ptr noundef %22)
  br label %39

23:                                               ; preds = %13
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.GChead, ptr %24, i32 0, i32 1
  %26 = load i8, ptr %25, align 4, !tbaa !19
  %27 = zext i8 %26 to i32
  %28 = and i32 %27, 248
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.global_State, ptr %29, i32 0, i32 5
  %31 = getelementptr inbounds %struct.GCState, ptr %30, i32 0, i32 2
  %32 = load i8, ptr %31, align 8, !tbaa !20
  %33 = zext i8 %32 to i32
  %34 = and i32 %33, 3
  %35 = or i32 %28, %34
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.GChead, ptr %37, i32 0, i32 1
  store i8 %36, ptr %38, align 4, !tbaa !19
  br label %39

39:                                               ; preds = %23, %20
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @gc_mark(ptr noundef, ptr noundef) #0

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

!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, !7, i64 41}
!10 = !{!"global_State", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !12, i64 32, !11, i64 88, !15, i64 92, !16, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !13, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !17, i64 160, !18, i64 184, !11, i64 208, !11, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !11, i64 240, !11, i64 244, !13, i64 248, !14, i64 252, !14, i64 256, !7, i64 260}
!11 = !{!"int", !7, i64 0}
!12 = !{!"GCState", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !11, i64 12, !13, i64 16, !14, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!13 = !{!"GCRef", !11, i64 0}
!14 = !{!"MRef", !11, i64 0}
!15 = !{!"SBuf", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!16 = !{!"GCstr", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !11, i64 12}
!17 = !{!"Node", !7, i64 0, !7, i64 8, !14, i64 16, !14, i64 20}
!18 = !{!"GCupval", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !14, i64 16, !11, i64 20}
!19 = !{!7, !7, i64 0}
!20 = !{!10, !7, i64 40}


; 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 hidden void @lj_gc_barrierf(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 41
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %.off = add i8 %5, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %6, label %7

6:                                                ; preds = %3
  tail call void @gc_mark(ptr noundef nonnull %0, ptr noundef %2)
  br label %15

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load i8, ptr %8, align 4, !tbaa !18
  %10 = and i8 %9, -8
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load i8, ptr %11, align 8, !tbaa !19
  %13 = and i8 %12, 3
  %14 = or disjoint i8 %13, %10
  store i8 %14, ptr %8, align 4, !tbaa !18
  br label %15

15:                                               ; preds = %7, %6
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @gc_mark(ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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, !8, i64 41}
!6 = !{!"global_State", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !11, i64 32, !10, i64 88, !14, i64 92, !15, i64 108, !8, i64 124, !8, i64 125, !8, i64 126, !8, i64 127, !12, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !16, i64 160, !17, i64 184, !10, i64 208, !10, i64 212, !7, i64 216, !7, i64 224, !7, i64 232, !10, i64 240, !10, i64 244, !12, i64 248, !13, i64 252, !13, i64 256, !8, i64 260}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"GCState", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !10, i64 12, !12, i64 16, !13, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!12 = !{!"GCRef", !10, i64 0}
!13 = !{!"MRef", !10, i64 0}
!14 = !{!"SBuf", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!15 = !{!"GCstr", !12, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !10, i64 8, !10, i64 12}
!16 = !{!"Node", !8, i64 0, !8, i64 8, !13, i64 16, !13, i64 20}
!17 = !{!"GCupval", !12, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !13, i64 16, !10, i64 20}
!18 = !{!8, !8, i64 0}
!19 = !{!6, !8, i64 40}


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