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

; 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: alwaysinline nounwind uwtable
declare hidden void @copyTV(ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_closeuv(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.global_State, ptr %7, i32 0, i32 13
  %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 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.GCupval, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.GCupval, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds %struct.MRef, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  call void @copyTV(ptr noundef %12, ptr noundef %14, ptr noundef %20)
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.GCupval, ptr %21, i32 0, i32 5
  %23 = ptrtoint ptr %22 to i64
  %24 = trunc i64 %23 to i32
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.GCupval, ptr %25, i32 0, i32 6
  %27 = getelementptr inbounds %struct.MRef, ptr %26, i32 0, i32 0
  store i32 %24, ptr %27, align 8, !tbaa !19
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.GCupval, ptr %28, i32 0, i32 3
  store i8 1, ptr %29, align 2, !tbaa !20
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.global_State, ptr %30, i32 0, i32 5
  %32 = getelementptr inbounds %struct.GCState, ptr %31, i32 0, i32 7
  %33 = getelementptr inbounds %struct.GCRef, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !21
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.GChead, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.GCRef, ptr %36, i32 0, i32 0
  store i32 %34, ptr %37, align 8, !tbaa !22
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  %40 = trunc i64 %39 to i32
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.global_State, ptr %41, i32 0, i32 5
  %43 = getelementptr inbounds %struct.GCState, ptr %42, i32 0, i32 7
  %44 = getelementptr inbounds %struct.GCRef, ptr %43, i32 0, i32 0
  store i32 %40, ptr %44, align 8, !tbaa !21
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.GChead, ptr %45, i32 0, i32 1
  %47 = load i8, ptr %46, align 4, !tbaa !22
  %48 = zext i8 %47 to i32
  %49 = and i32 %48, 7
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %119, label %51

51:                                               ; preds = %2
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.global_State, ptr %52, i32 0, i32 5
  %54 = getelementptr inbounds %struct.GCState, ptr %53, i32 0, i32 3
  %55 = load i8, ptr %54, align 1, !tbaa !23
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %65, label %58

58:                                               ; preds = %51
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.global_State, ptr %59, i32 0, i32 5
  %61 = getelementptr inbounds %struct.GCState, ptr %60, i32 0, i32 3
  %62 = load i8, ptr %61, align 1, !tbaa !23
  %63 = zext i8 %62 to i32
  %64 = icmp eq i32 %63, 2
  br i1 %64, label %65, label %102

65:                                               ; preds = %58, %51
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.GChead, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 4, !tbaa !22
  %69 = zext i8 %68 to i32
  %70 = or i32 %69, 4
  %71 = trunc i32 %70 to i8
  store i8 %71, ptr %67, align 4, !tbaa !22
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.GCupval, ptr %72, i32 0, i32 5
  %74 = getelementptr inbounds %struct.anon, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !22
  %76 = sub i32 %75, -4
  %77 = icmp ugt i32 %76, -10
  br i1 %77, label %78, label %101

78:                                               ; preds = %65
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.GCupval, ptr %79, i32 0, i32 5
  %81 = getelementptr inbounds %struct.anon, ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds %struct.GCRef, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 8, !tbaa !22
  %84 = zext i32 %83 to i64
  %85 = inttoptr i64 %84 to ptr
  %86 = getelementptr inbounds %struct.GChead, ptr %85, i32 0, i32 1
  %87 = load i8, ptr %86, align 4, !tbaa !22
  %88 = zext i8 %87 to i32
  %89 = and i32 %88, 3
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %101

91:                                               ; preds = %78
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.GCupval, ptr %94, i32 0, i32 5
  %96 = getelementptr inbounds %struct.anon, ptr %95, i32 0, i32 0
  %97 = getelementptr inbounds %struct.GCRef, ptr %96, i32 0, i32 0
  %98 = load i32, ptr %97, align 8, !tbaa !22
  %99 = zext i32 %98 to i64
  %100 = inttoptr i64 %99 to ptr
  call void @lj_gc_barrierf(ptr noundef %92, ptr noundef %93, ptr noundef %100)
  br label %101

101:                                              ; preds = %91, %78, %65
  br label %118

102:                                              ; preds = %58
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.GChead, ptr %103, i32 0, i32 1
  %105 = load i8, ptr %104, align 4, !tbaa !22
  %106 = zext i8 %105 to i32
  %107 = and i32 %106, 248
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.global_State, ptr %108, i32 0, i32 5
  %110 = getelementptr inbounds %struct.GCState, ptr %109, i32 0, i32 2
  %111 = load i8, ptr %110, align 8, !tbaa !24
  %112 = zext i8 %111 to i32
  %113 = and i32 %112, 3
  %114 = or i32 %107, %113
  %115 = trunc i32 %114 to i8
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.GChead, ptr %116, i32 0, i32 1
  store i8 %115, ptr %117, align 4, !tbaa !22
  br label %118

118:                                              ; preds = %102, %101
  br label %119

119:                                              ; preds = %118, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 #3 = { 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, !11, i64 128}
!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 = !{!18, !11, i64 16}
!20 = !{!18, !7, i64 6}
!21 = !{!10, !11, i64 48}
!22 = !{!7, !7, i64 0}
!23 = !{!10, !7, i64 41}
!24 = !{!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: alwaysinline nounwind uwtable
declare hidden void @copyTV(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define hidden void @lj_gc_closeuv(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 128
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = inttoptr i64 %5 to ptr
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !18
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  tail call void @copyTV(ptr noundef %6, ptr noundef nonnull %7, ptr noundef %11)
  %12 = ptrtoint ptr %7 to i64
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %8, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 1, ptr %14, align 2, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load i32, ptr %15, align 8, !tbaa !20
  store i32 %16, ptr %1, align 8, !tbaa !21
  %17 = ptrtoint ptr %1 to i64
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %15, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load i8, ptr %19, align 4, !tbaa !21
  %21 = and i8 %20, 7
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %22, label %44

22:                                               ; preds = %2
  %23 = getelementptr inbounds i8, ptr %0, i64 41
  %24 = load i8, ptr %23, align 1, !tbaa !22
  %.off = add i8 %24, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %25, label %39

25:                                               ; preds = %22
  %26 = or disjoint i8 %20, 4
  store i8 %26, ptr %19, align 4, !tbaa !21
  %27 = getelementptr inbounds i8, ptr %1, i64 12
  %28 = load i32, ptr %27, align 4, !tbaa !21
  %29 = add i32 %28, 13
  %30 = icmp ult i32 %29, 9
  br i1 %30, label %31, label %44

31:                                               ; preds = %25
  %32 = load i32, ptr %7, align 8, !tbaa !21
  %33 = zext i32 %32 to i64
  %34 = inttoptr i64 %33 to ptr
  %35 = getelementptr inbounds i8, ptr %34, i64 4
  %36 = load i8, ptr %35, align 4, !tbaa !21
  %37 = and i8 %36, 3
  %.not23 = icmp eq i8 %37, 0
  br i1 %.not23, label %44, label %38

38:                                               ; preds = %31
  tail call void @lj_gc_barrierf(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %34)
  br label %44

39:                                               ; preds = %22
  %40 = getelementptr inbounds i8, ptr %0, i64 40
  %41 = load i8, ptr %40, align 8, !tbaa !23
  %42 = and i8 %41, 3
  %43 = or disjoint i8 %42, %20
  store i8 %43, ptr %19, align 4, !tbaa !21
  br label %44

44:                                               ; preds = %39, %38, %31, %25, %2
  ret void
}

attributes #0 = { alwaysinline 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 #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" }

!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 128}
!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 = !{!17, !10, i64 16}
!19 = !{!17, !8, i64 6}
!20 = !{!6, !10, i64 48}
!21 = !{!8, !8, i64 0}
!22 = !{!6, !8, i64 41}
!23 = !{!6, !8, i64 40}


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