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

; 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 }
%union.anon = type { %struct.anon, [320 x i8] }
%struct.anon = 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 }
%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.4, %struct.MRef, i32 }
%union.anon.4 = type { %union.TValue }
%struct.anon.0 = type { %union.anon.1, i32 }
%union.anon.1 = type { %struct.GCRef }

@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

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

52:                                               ; preds = %2
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.lua_State, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.anon, ptr %54, i32 0, i32 8
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds %union.TValue, ptr %56, i32 -1
  store ptr %57, ptr %55, align 8, !tbaa !11
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = call i32 @fputs(ptr noundef @.str.1, ptr noundef %58)
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.lua_State, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.anon, ptr %61, i32 0, i32 8
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.anon.0, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = icmp eq i32 %65, -5
  br i1 %66, label %67, label %78

67:                                               ; preds = %52
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lua_State, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds %struct.anon, ptr %69, i32 0, i32 8
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.anon.0, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.GCRef, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !11
  %75 = zext i32 %74 to i64
  %76 = inttoptr i64 %75 to ptr
  %77 = getelementptr inbounds %struct.GCstr, ptr %76, i64 1
  br label %79

78:                                               ; preds = %52
  br label %79

79:                                               ; preds = %78, %67
  %80 = phi ptr [ %77, %67 ], [ @.str.2, %78 ]
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 @fputs(ptr noundef %80, ptr noundef %81)
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = call i32 @fputc(i32 noundef 10, ptr noundef %83)
  br label %85

85:                                               ; preds = %79, %2
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.global_State, ptr %86, i32 0, i32 10
  %88 = load i8, ptr %87, align 1, !tbaa !22
  %89 = zext i8 %88 to i32
  %90 = and i32 %89, 15
  %91 = load i8, ptr %7, align 1, !tbaa !11
  %92 = zext i8 %91 to i32
  %93 = or i32 %90, %92
  %94 = trunc i32 %93 to i8
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.global_State, ptr %95, i32 0, i32 10
  store i8 %94, ptr %96, align 1, !tbaa !22
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.global_State, ptr %97, i32 0, i32 12
  %99 = load i8, ptr %98, align 1, !tbaa !12
  %100 = zext i8 %99 to i32
  %101 = icmp ne i32 %100, 255
  br i1 %101, label %102, label %106

102:                                              ; preds = %85
  %103 = load i8, ptr %6, align 1, !tbaa !11
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.global_State, ptr %104, i32 0, i32 12
  store i8 %103, ptr %105, align 1, !tbaa !12
  br label %106

106:                                              ; preds = %102, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare hidden i32 @lj_vm_pcall(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #2

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

declare i32 @fputs(ptr noundef, ptr noundef) #2

declare i32 @fputc(i32 noundef, ptr noundef) #2

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

@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define hidden void @lj_vmevent_call(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %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 %6, i64 127
  %8 = load i8, ptr %7, align 1, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %6, i64 125
  %10 = load i8, ptr %9, align 1, !tbaa !19
  %11 = and i8 %10, -16
  store i8 0, ptr %7, align 1, !tbaa !8
  %12 = or i8 %10, 48
  store i8 %12, ptr %9, align 1, !tbaa !19
  %13 = getelementptr inbounds i8, ptr %0, i64 36
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  %17 = getelementptr inbounds i8, ptr %16, i64 %1
  %18 = tail call i32 @lj_vm_pcall(ptr noundef %0, ptr noundef %17, i32 noundef 1, i64 noundef 0) #3
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %40, label %19, !prof !20

19:                                               ; preds = %2
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 -8
  store ptr %22, ptr %20, align 8, !tbaa !5
  %23 = load ptr, ptr @stderr, align 8, !tbaa !21
  %24 = tail call i32 @fputs(ptr noundef nonnull @.str.1, ptr noundef %23) #4
  %25 = load ptr, ptr %20, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -5
  br i1 %28, label %29, label %34

29:                                               ; preds = %19
  %30 = load i32, ptr %25, align 8, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = inttoptr i64 %31 to ptr
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  br label %34

34:                                               ; preds = %19, %29
  %35 = phi ptr [ %33, %29 ], [ @.str.2, %19 ]
  %36 = load ptr, ptr @stderr, align 8, !tbaa !21
  %37 = tail call i32 @fputs(ptr noundef nonnull %35, ptr noundef %36) #4
  %38 = load ptr, ptr @stderr, align 8, !tbaa !21
  %39 = tail call i32 @fputc(i32 noundef 10, ptr noundef %38)
  br label %40

40:                                               ; preds = %34, %2
  %41 = load i8, ptr %9, align 1, !tbaa !19
  %42 = and i8 %41, 15
  %43 = or disjoint i8 %42, %11
  store i8 %43, ptr %9, align 1, !tbaa !19
  %44 = load i8, ptr %7, align 1, !tbaa !8
  %.not17 = icmp eq i8 %44, -1
  br i1 %.not17, label %46, label %45

45:                                               ; preds = %40
  store i8 %8, ptr %7, align 1, !tbaa !8
  br label %46

46:                                               ; preds = %45, %40
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @fputs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

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 = { nofree nounwind "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 }
attributes #4 = { cold }

!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 127}
!9 = !{!"global_State", !10, i64 0, !11, i64 8, !11, i64 12, !10, i64 16, !10, i64 24, !12, i64 32, !11, i64 88, !15, i64 92, !16, i64 108, !6, i64 124, !6, i64 125, !6, i64 126, !6, i64 127, !13, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !17, i64 160, !18, i64 184, !11, i64 208, !11, i64 212, !10, i64 216, !10, i64 224, !10, i64 232, !11, i64 240, !11, i64 244, !13, i64 248, !14, i64 252, !14, i64 256, !6, i64 260}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"GCState", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 9, !6, i64 10, !6, 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, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !11, i64 8, !11, i64 12}
!17 = !{!"Node", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20}
!18 = !{!"GCupval", !13, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8, !14, i64 16, !11, i64 20}
!19 = !{!9, !6, i64 125}
!20 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!21 = !{!10, !10, i64 0}


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