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

; 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.LexState = type { ptr, ptr, %union.TValue, %union.TValue, ptr, ptr, i32, i32, i32, %struct.SBuf, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i32 }
%union.TValue = type { i64 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }
%struct.lua_State = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.3, [320 x i8] }
%struct.anon.3 = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.GCRef = type { i32 }
%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.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.4, %struct.MRef, i32 }
%union.anon.4 = type { %union.TValue }

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @lua_loadx(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.LexState, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 160, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 10
  store ptr %13, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 11
  store ptr %15, ptr %16, align 8, !tbaa !14
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  br label %22

21:                                               ; preds = %5
  br label %22

22:                                               ; preds = %21, %19
  %23 = phi ptr [ %20, %19 ], [ @.str, %21 ]
  %24 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 15
  store ptr %23, ptr %24, align 8, !tbaa !15
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 16
  store ptr %25, ptr %26, align 8, !tbaa !16
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 9
  call void @lj_buf_init(ptr noundef %27, ptr noundef %28)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i32 @lj_vm_cpcall(ptr noundef %29, ptr noundef null, ptr noundef %11, ptr noundef @cpparser)
  store i32 %30, ptr %12, align 4, !tbaa !17
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lj_lex_cleanup(ptr noundef %31, ptr noundef %11)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lua_State, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.anon.3, ptr %33, i32 0, i32 5
  %35 = getelementptr inbounds %struct.MRef, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = zext i32 %36 to i64
  %38 = inttoptr i64 %37 to ptr
  %39 = getelementptr inbounds %struct.global_State, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %struct.GCState, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.lua_State, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.anon.3, ptr %43, i32 0, i32 5
  %45 = getelementptr inbounds %struct.MRef, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !18
  %47 = zext i32 %46 to i64
  %48 = inttoptr i64 %47 to ptr
  %49 = getelementptr inbounds %struct.global_State, ptr %48, i32 0, i32 5
  %50 = getelementptr inbounds %struct.GCState, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !26
  %52 = icmp uge i32 %41, %51
  %53 = xor i1 %52, true
  %54 = xor i1 %53, true
  %55 = zext i1 %54 to i32
  %56 = sext i32 %55 to i64
  %57 = call i64 @llvm.expect.i64(i64 %56, i64 0)
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %22
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call i32 @lj_gc_step(ptr noundef %60)
  br label %62

62:                                               ; preds = %59, %22
  %63 = load i32, ptr %12, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr %11) #5
  ret i32 %63
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

declare hidden i32 @lj_vm_cpcall(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

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

declare hidden void @lj_lex_cleanup(ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #4

declare hidden i32 @lj_gc_step(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #5 = { 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, !6, i64 80}
!10 = !{!"LexState", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !12, i64 60, !6, i64 80, !6, i64 88, !11, i64 96, !11, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !11, i64 136, !11, i64 140, !6, i64 144, !11, i64 152, !11, i64 156}
!11 = !{!"int", !7, i64 0}
!12 = !{!"SBuf", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"MRef", !11, i64 0}
!14 = !{!10, !6, i64 88}
!15 = !{!10, !6, i64 112}
!16 = !{!10, !6, i64 120}
!17 = !{!11, !11, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !11, i64 32}
!20 = !{!"global_State", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !21, i64 32, !11, i64 88, !12, i64 92, !23, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !22, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !24, i64 160, !25, i64 184, !11, i64 208, !11, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !11, i64 240, !11, i64 244, !22, i64 248, !13, i64 252, !13, i64 256, !7, i64 260}
!21 = !{!"GCState", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !11, i64 12, !22, i64 16, !13, i64 20, !22, i64 24, !22, i64 28, !22, i64 32, !22, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!22 = !{!"GCRef", !11, i64 0}
!23 = !{!"GCstr", !22, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !11, i64 12}
!24 = !{!"Node", !7, i64 0, !7, i64 8, !13, i64 16, !13, i64 20}
!25 = !{!"GCupval", !22, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !13, i64 16, !11, i64 20}
!26 = !{!20, !11, i64 36}


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

%struct.LexState = type { ptr, ptr, %union.TValue, %union.TValue, ptr, ptr, i32, i32, i32, %struct.SBuf, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i32 }
%union.TValue = type { i64 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @lua_loadx(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.LexState, align 8
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %6) #4
  %7 = getelementptr inbounds i8, ptr %6, i64 80
  store ptr %1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 88
  store ptr %2, ptr %8, align 8, !tbaa !13
  %.not = icmp eq ptr %3, null
  %9 = select i1 %.not, ptr @.str, ptr %3
  %10 = getelementptr inbounds i8, ptr %6, i64 112
  store ptr %9, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %6, i64 120
  store ptr %4, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %6, i64 60
  call void @lj_buf_init(ptr noundef %0, ptr noundef nonnull %12)
  %13 = call i32 @lj_vm_cpcall(ptr noundef %0, ptr noundef null, ptr noundef nonnull %6, ptr noundef nonnull @cpparser) #4
  call void @lj_lex_cleanup(ptr noundef %0, ptr noundef nonnull %6) #4
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !16
  %16 = zext i32 %15 to i64
  %17 = inttoptr i64 %16 to ptr
  %18 = getelementptr inbounds i8, ptr %17, i64 32
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %17, i64 36
  %21 = load i32, ptr %20, align 4, !tbaa !24
  %.not11 = icmp ult i32 %19, %21
  br i1 %.not11, label %24, label %22, !prof !25

22:                                               ; preds = %5
  %23 = call i32 @lj_gc_step(ptr noundef nonnull %0) #4
  br label %24

24:                                               ; preds = %22, %5
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %6) #4
  ret i32 %13
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

declare hidden i32 @lj_vm_cpcall(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare hidden void @lj_lex_cleanup(ptr noundef, ptr noundef) local_unnamed_addr #3

declare hidden i32 @lj_gc_step(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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, !7, i64 80}
!6 = !{!"LexState", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !11, i64 60, !7, i64 80, !7, i64 88, !10, i64 96, !10, i64 100, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !10, i64 136, !10, i64 140, !7, i64 144, !10, i64 152, !10, i64 156}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"SBuf", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!12 = !{!"MRef", !10, i64 0}
!13 = !{!6, !7, i64 88}
!14 = !{!6, !7, i64 112}
!15 = !{!6, !7, i64 120}
!16 = !{!8, !8, i64 0}
!17 = !{!18, !10, i64 32}
!18 = !{!"global_State", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !19, i64 32, !10, i64 88, !11, i64 92, !21, i64 108, !8, i64 124, !8, i64 125, !8, i64 126, !8, i64 127, !20, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !22, i64 160, !23, i64 184, !10, i64 208, !10, i64 212, !7, i64 216, !7, i64 224, !7, i64 232, !10, i64 240, !10, i64 244, !20, i64 248, !12, i64 252, !12, i64 256, !8, i64 260}
!19 = !{!"GCState", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !10, i64 12, !20, i64 16, !12, i64 20, !20, i64 24, !20, i64 28, !20, i64 32, !20, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!20 = !{!"GCRef", !10, i64 0}
!21 = !{!"GCstr", !20, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !10, i64 8, !10, i64 12}
!22 = !{!"Node", !8, i64 0, !8, i64 8, !12, i64 16, !12, i64 20}
!23 = !{!"GCupval", !20, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !12, i64 16, !10, i64 20}
!24 = !{!18, !10, i64 36}
!25 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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