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

; 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.FuncState = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, i8, i8, i8, i8, [200 x i16], [256 x i16], [256 x i16] }
%struct.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%struct.GCRef = 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.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 }

; Function Attrs: nounwind uwtable
define hidden ptr @lj_parse_keepstr(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.LexState, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = call ptr @lj_str_new(ptr noundef %13, ptr noundef %14, i64 noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LexState, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.FuncState, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @lj_tab_setstr(ptr noundef %17, ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.anon, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !19
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %32

29:                                               ; preds = %3
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 1
  store i32 -3, ptr %31, align 4, !tbaa !19
  br label %32

32:                                               ; preds = %29, %3
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.lua_State, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.anon.3, ptr %34, i32 0, i32 5
  %36 = getelementptr inbounds %struct.MRef, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = zext i32 %37 to i64
  %39 = inttoptr i64 %38 to ptr
  %40 = getelementptr inbounds %struct.global_State, ptr %39, i32 0, i32 5
  %41 = getelementptr inbounds %struct.GCState, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !20
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lua_State, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.anon.3, ptr %44, i32 0, i32 5
  %46 = getelementptr inbounds %struct.MRef, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !19
  %48 = zext i32 %47 to i64
  %49 = inttoptr i64 %48 to ptr
  %50 = getelementptr inbounds %struct.global_State, ptr %49, i32 0, i32 5
  %51 = getelementptr inbounds %struct.GCState, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !27
  %53 = icmp uge i32 %42, %52
  %54 = xor i1 %53, true
  %55 = xor i1 %54, true
  %56 = zext i1 %55 to i32
  %57 = sext i32 %56 to i64
  %58 = call i64 @llvm.expect.i64(i64 %57, i64 0)
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %63

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

63:                                               ; preds = %60, %32
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %64
}

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

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) #2

declare hidden ptr @lj_tab_setstr(ptr noundef, ptr noundef, ptr noundef) #2

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

declare hidden i32 @lj_gc_step(ptr noundef) #2

; 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"LexState", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !14, i64 60, !6, i64 80, !6, i64 88, !13, i64 96, !13, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !13, i64 136, !13, i64 140, !6, i64 144, !13, i64 152, !13, i64 156}
!13 = !{!"int", !7, i64 0}
!14 = !{!"SBuf", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!15 = !{!"MRef", !13, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"FuncState", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !6, i64 72, !13, i64 80, !13, i64 84, !7, i64 88, !7, i64 89, !7, i64 90, !7, i64 91, !7, i64 92, !7, i64 492, !7, i64 1004}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !13, i64 32}
!21 = !{!"global_State", !6, i64 0, !13, i64 8, !13, i64 12, !6, i64 16, !6, i64 24, !22, i64 32, !13, i64 88, !14, i64 92, !24, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !23, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !25, i64 160, !26, i64 184, !13, i64 208, !13, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !13, i64 240, !13, i64 244, !23, i64 248, !15, i64 252, !15, i64 256, !7, i64 260}
!22 = !{!"GCState", !13, i64 0, !13, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !13, i64 12, !23, i64 16, !15, i64 20, !23, i64 24, !23, i64 28, !23, i64 32, !23, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52}
!23 = !{!"GCRef", !13, i64 0}
!24 = !{!"GCstr", !23, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !13, i64 12}
!25 = !{!"Node", !7, i64 0, !7, i64 8, !15, i64 16, !15, i64 20}
!26 = !{!"GCupval", !23, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !15, i64 16, !13, i64 20}
!27 = !{!21, !13, 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"

; Function Attrs: nounwind uwtable
define hidden noundef ptr @lj_parse_keepstr(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call ptr @lj_str_new(ptr noundef %5, ptr noundef %1, i64 noundef %2) #2
  %7 = load ptr, ptr %0, align 8, !tbaa !13
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = tail call ptr @lj_tab_setstr(ptr noundef %5, ptr noundef %8, ptr noundef %6) #2
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !16
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 -3, ptr %10, align 4, !tbaa !16
  br label %14

14:                                               ; preds = %13, %3
  %15 = getelementptr inbounds i8, ptr %5, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  %19 = getelementptr inbounds i8, ptr %18, i64 32
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %18, i64 36
  %22 = load i32, ptr %21, align 4, !tbaa !24
  %.not = icmp ult i32 %20, %22
  br i1 %.not, label %25, label %23, !prof !25

23:                                               ; preds = %14
  %24 = tail call i32 @lj_gc_step(ptr noundef nonnull %5) #2
  br label %25

25:                                               ; preds = %23, %14
  ret ptr %6
}

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare hidden ptr @lj_tab_setstr(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare hidden i32 @lj_gc_step(ptr noundef) local_unnamed_addr #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 = { "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 }

!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 8}
!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 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"FuncState", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 80, !10, i64 84, !8, i64 88, !8, i64 89, !8, i64 90, !8, i64 91, !8, i64 92, !8, i64 492, !8, i64 1004}
!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,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass