; 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.lua_State = type { %union.anon.4 }
%union.anon.4 = type { %struct.anon.5, [320 x i8] }
%struct.anon.5 = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.GCRef = type { i32 }
%union.TValue = type { i64 }
%struct.anon.0 = type { %struct.GCRef, %union.FrameLink }
%union.FrameLink = type { i32 }
%struct.GCfuncC = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, ptr, [1 x %union.TValue] }
%struct.GCfuncL = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, [1 x %struct.GCRef] }
%struct.GCproto = type { %struct.GCRef, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.MRef, i32, i32, i32, i8, i8, i16, %struct.GCRef, i32, i32, %struct.MRef, %struct.MRef, %struct.MRef }

; Function Attrs: nounwind uwtable
declare hidden i32 @lj_gc_step(ptr noundef) #0

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_step_fixtop(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.lua_State, ptr %3, i32 0, i32 0
  %5 = getelementptr inbounds %struct.anon.5, ptr %4, i32 0, i32 7
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %union.TValue, ptr %6, i64 -1
  %8 = getelementptr inbounds %struct.anon.0, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds %struct.GCRef, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = inttoptr i64 %11 to ptr
  %13 = getelementptr inbounds %struct.GCfuncC, ptr %12, i32 0, i32 3
  %14 = load i8, ptr %13, align 2, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %46

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lua_State, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.anon.5, ptr %19, i32 0, i32 7
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon.5, ptr %23, i32 0, i32 7
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %union.TValue, ptr %25, i64 -1
  %27 = getelementptr inbounds %struct.anon.0, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.GCRef, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct.GCfuncL, ptr %31, i32 0, i32 7
  %33 = getelementptr inbounds %struct.MRef, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = inttoptr i64 %35 to ptr
  %37 = getelementptr inbounds i8, ptr %36, i64 -64
  %38 = getelementptr inbounds %struct.GCproto, ptr %37, i32 0, i32 4
  %39 = load i8, ptr %38, align 1, !tbaa !10
  %40 = zext i8 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %union.TValue, ptr %21, i64 %41
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lua_State, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.anon.5, ptr %44, i32 0, i32 8
  store ptr %42, ptr %45, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %17, %1
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = call i32 @lj_gc_step(ptr noundef %47)
  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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 7}
!11 = !{!"GCproto", !12, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !12, i64 12, !14, i64 16, !14, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !7, i64 36, !7, i64 37, !15, i64 38, !12, i64 40, !13, i64 44, !13, i64 48, !14, i64 52, !14, i64 56, !14, i64 60}
!12 = !{!"GCRef", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"MRef", !13, i64 0}
!15 = !{!"short", !7, i64 0}


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

%union.TValue = type { i64 }

; Function Attrs: nounwind uwtable
declare hidden i32 @lj_gc_step(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_step_fixtop(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 -8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 6
  %9 = load i8, ptr %8, align 2, !tbaa !5
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %21

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = getelementptr inbounds i8, ptr %15, i64 -57
  %17 = load i8, ptr %16, align 1, !tbaa !8
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds %union.TValue, ptr %3, i64 %18
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %19, ptr %20, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %11, %1
  %22 = tail call i32 @lj_gc_step(ptr noundef nonnull %0)
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 7}
!9 = !{!"GCproto", !10, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !11, i64 8, !10, i64 12, !12, i64 16, !12, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 36, !6, i64 37, !13, i64 38, !10, i64 40, !11, i64 44, !11, i64 48, !12, i64 52, !12, i64 56, !12, i64 60}
!10 = !{!"GCRef", !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"MRef", !11, i64 0}
!13 = !{!"short", !6, i64 0}


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