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

; 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.ProfileState = type { ptr, ptr, ptr, %struct.SBuf, i32, i32, i32, %struct.sigaction }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }
%struct.sigaction = type { %union.anon, %struct.__sigset_t, i32, ptr }
%union.anon = type { ptr }
%struct.__sigset_t = type { [16 x i64] }

@profile_state = external hidden global %struct.ProfileState, align 8

; 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 dso_local ptr @luaJIT_profile_dumpstack(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr @profile_state, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %11 = load ptr, ptr %9, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ProfileState, ptr %11, i32 0, i32 3
  store ptr %12, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = ptrtoint ptr %13 to i64
  %15 = trunc i64 %14 to i32
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SBuf, ptr %16, i32 0, i32 3
  %18 = getelementptr inbounds %struct.MRef, ptr %17, i32 0, i32 0
  store i32 %15, ptr %18, align 4, !tbaa !11
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  call void @lj_buf_reset(ptr noundef %19)
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  call void @lj_debug_dumpstack(ptr noundef %20, ptr noundef %21, ptr noundef %22, i32 noundef %23)
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SBuf, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.MRef, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SBuf, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.MRef, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = zext i32 %33 to i64
  %35 = inttoptr i64 %34 to ptr
  %36 = ptrtoint ptr %29 to i64
  %37 = ptrtoint ptr %35 to i64
  %38 = sub i64 %36, %37
  %39 = trunc i64 %38 to i32
  %40 = zext i32 %39 to i64
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %40, ptr %41, align 8, !tbaa !16
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.SBuf, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.MRef, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = zext i32 %45 to i64
  %47 = inttoptr i64 %46 to ptr
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret ptr %47
}

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

declare hidden void @lj_debug_dumpstack(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

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 = { 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"SBuf", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"MRef", !10, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !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"

%struct.ProfileState = type { ptr, ptr, ptr, %struct.SBuf, i32, i32, i32, %struct.sigaction }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }
%struct.sigaction = type { %union.anon, %struct.__sigset_t, i32, ptr }
%union.anon = type { ptr }
%struct.__sigset_t = type { [16 x i64] }

@profile_state = external hidden global %struct.ProfileState, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @luaJIT_profile_dumpstack(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %0 to i64
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr getelementptr inbounds (i8, ptr @profile_state, i64 36), align 4, !tbaa !5
  tail call void @lj_buf_reset(ptr noundef nonnull getelementptr inbounds (i8, ptr @profile_state, i64 24))
  tail call void @lj_debug_dumpstack(ptr noundef %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @profile_state, i64 24), ptr noundef %1, i32 noundef %2) #3
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @profile_state, i64 24), align 8, !tbaa !11
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @profile_state, i64 32), align 8, !tbaa !12
  %9 = sub i32 %7, %8
  %10 = zext i32 %9 to i64
  store i64 %10, ptr %3, align 8, !tbaa !13
  %11 = zext i32 %8 to i64
  %12 = inttoptr i64 %11 to ptr
  ret ptr %12
}

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

declare hidden void @lj_debug_dumpstack(ptr noundef, ptr noundef, ptr noundef, i32 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 = { 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 = { "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, !8, i64 12}
!6 = !{!"SBuf", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"MRef", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !8, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass