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

; 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.GCproto = type { %struct.GCRef, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.MRef, i32, i32, i32, i8, i8, i16, %struct.GCRef, i32, i32, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCRef = type { i32 }
%struct.MRef = type { i32 }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.0, %struct.MRef, i32 }
%union.anon.0 = type { %union.TValue }
%union.TValue = type { i64 }
%struct.GCfuncL = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, [1 x %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: nounwind uwtable
define hidden ptr @lj_func_newL_empty(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call ptr @func_newL(ptr noundef %11, ptr noundef %12, ptr noundef %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.GCproto, ptr %15, i32 0, i32 12
  %17 = load i8, ptr %16, align 4, !tbaa !9
  %18 = zext i8 %17 to i32
  store i32 %18, ptr %9, align 4, !tbaa !15
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %53, %3
  %20 = load i32, ptr %8, align 4, !tbaa !15
  %21 = load i32, ptr %9, align 4, !tbaa !15
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %56

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call ptr @func_emptyuv(ptr noundef %24)
  store ptr %25, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = trunc i64 %27 to i32
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.GCproto, ptr %29, i32 0, i32 8
  %31 = getelementptr inbounds %struct.MRef, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = inttoptr i64 %33 to ptr
  %35 = load i32, ptr %8, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i16, ptr %34, i64 %36
  %38 = load i16, ptr %37, align 2, !tbaa !17
  %39 = zext i16 %38 to i32
  %40 = shl i32 %39, 24
  %41 = xor i32 %28, %40
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.GCupval, ptr %42, i32 0, i32 7
  store i32 %41, ptr %43, align 4, !tbaa !18
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = ptrtoint ptr %44 to i64
  %46 = trunc i64 %45 to i32
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.GCfuncL, ptr %47, i32 0, i32 8
  %49 = load i32, ptr %8, align 4, !tbaa !15
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [1 x %struct.GCRef], ptr %48, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.GCRef, ptr %51, i32 0, i32 0
  store i32 %46, ptr %52, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %53

53:                                               ; preds = %23
  %54 = load i32, ptr %8, align 4, !tbaa !15
  %55 = add i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !15
  br label %19, !llvm.loop !21

56:                                               ; preds = %19
  %57 = load i32, ptr %9, align 4, !tbaa !15
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.GCfuncL, ptr %59, i32 0, i32 4
  store i8 %58, ptr %60, align 1, !tbaa !20
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %61
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @func_emptyuv(ptr noundef) #1

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 = { 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, !7, i64 36}
!10 = !{!"GCproto", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !11, i64 12, !13, i64 16, !13, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !7, i64 36, !7, i64 37, !14, i64 38, !11, i64 40, !12, i64 44, !12, i64 48, !13, i64 52, !13, i64 56, !13, i64 60}
!11 = !{!"GCRef", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"MRef", !12, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 20}
!17 = !{!14, !14, i64 0}
!18 = !{!19, !12, i64 20}
!19 = !{!"GCupval", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !13, i64 16, !12, i64 20}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.GCRef = type { i32 }

; Function Attrs: nounwind uwtable
define hidden ptr @lj_func_newL_empty(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @func_newL(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %5 = getelementptr inbounds i8, ptr %1, i64 36
  %6 = load i8, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = ptrtoint ptr %1 to i64
  %8 = trunc i64 %7 to i32
  %9 = getelementptr inbounds i8, ptr %1, i64 20
  %10 = getelementptr inbounds i8, ptr %4, i64 20
  %wide.trip.count = zext i8 %6 to i64
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  %12 = tail call ptr @func_emptyuv(ptr noundef %0)
  %13 = load i32, ptr %9, align 4, !tbaa !13
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = getelementptr inbounds i16, ptr %15, i64 %indvars.iv
  %17 = load i16, ptr %16, align 2, !tbaa !14
  %18 = zext i16 %17 to i32
  %19 = shl i32 %18, 24
  %20 = xor i32 %19, %8
  %21 = getelementptr inbounds i8, ptr %12, i64 20
  store i32 %20, ptr %21, align 4, !tbaa !15
  %22 = ptrtoint ptr %12 to i64
  %23 = trunc i64 %22 to i32
  %24 = getelementptr inbounds [1 x %struct.GCRef], ptr %10, i64 0, i64 %indvars.iv
  store i32 %23, ptr %24, align 4, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !18

._crit_edge:                                      ; preds = %11, %3
  %25 = getelementptr inbounds i8, ptr %4, i64 7
  store i8 %6, ptr %25, align 1, !tbaa !17
  ret ptr %4
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @func_emptyuv(ptr noundef) local_unnamed_addr #0

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

!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, !9, i64 36}
!6 = !{!"GCproto", !7, i64 0, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7, !8, i64 8, !7, i64 12, !11, i64 16, !11, i64 20, !8, i64 24, !8, i64 28, !8, i64 32, !9, i64 36, !9, i64 37, !12, i64 38, !7, i64 40, !8, i64 44, !8, i64 48, !11, i64 52, !11, i64 56, !11, i64 60}
!7 = !{!"GCRef", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"MRef", !8, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!6, !8, i64 20}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !8, i64 20}
!16 = !{!"GCupval", !7, i64 0, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7, !9, i64 8, !11, i64 16, !8, i64 20}
!17 = !{!9, !9, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass