; 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.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }

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

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

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

18:                                               ; preds = %11, %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.GCRef, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  call void @gc_mark(ptr noundef %19, ptr noundef %25)
  br label %44

26:                                               ; preds = %11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 -8
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  %30 = load i8, ptr %29, align 1, !tbaa !19
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 248
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.global_State, ptr %33, i32 0, i32 5
  %35 = getelementptr inbounds %struct.GCState, ptr %34, i32 0, i32 2
  %36 = load i8, ptr %35, align 8, !tbaa !20
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 3
  %39 = or i32 %32, %38
  %40 = trunc i32 %39 to i8
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 -8
  %43 = getelementptr inbounds i8, ptr %42, i64 4
  store i8 %40, ptr %43, align 1, !tbaa !19
  br label %44

44:                                               ; preds = %26, %18
  ret void
}

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
declare hidden void @gc_mark(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_barrieruv(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 41
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.off = add i8 %4, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %5, label %9

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 8, !tbaa !18
  %7 = zext i32 %6 to i64
  %8 = inttoptr i64 %7 to ptr
  tail call void @gc_mark(ptr noundef nonnull %0, ptr noundef %8)
  br label %17

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

17:                                               ; preds = %9, %5
  ret void
}

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