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

; 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.anon.0 = type { %union.anon.1, i32 }
%union.anon.1 = type { %struct.GCRef }
%struct.GCRef = type { i32 }
%struct.GCfuncC = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, ptr, [1 x %union.TValue] }
%struct.MRef = type { i32 }
%union.TValue = type { i64 }
%struct.GCfuncL = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, [1 x %struct.GCRef] }
%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.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 [1 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
declare hidden ptr @lj_debug_uvname(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define hidden ptr @lj_debug_uvnamev(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.anon.0, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp eq i32 %13, -9
  br i1 %14, label %15, label %83

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.anon.0, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.GCRef, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = inttoptr i64 %20 to ptr
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.GCfuncC, ptr %22, i32 0, i32 3
  %24 = load i8, ptr %23, align 2, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %64

27:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.GCfuncL, ptr %28, i32 0, i32 7
  %30 = getelementptr inbounds %struct.MRef, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = inttoptr i64 %32 to ptr
  %34 = getelementptr inbounds i8, ptr %33, i64 -64
  store ptr %34, ptr %9, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.GCproto, ptr %36, i32 0, i32 12
  %38 = load i8, ptr %37, align 4, !tbaa !12
  %39 = zext i8 %38 to i32
  %40 = icmp ult i32 %35, %39
  br i1 %40, label %41, label %60

41:                                               ; preds = %27
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.GCfuncL, ptr %42, i32 0, i32 8
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [1 x %struct.GCRef], ptr %43, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.GCRef, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = inttoptr i64 %49 to ptr
  %51 = getelementptr inbounds %struct.GCupval, ptr %50, i32 0, i32 6
  %52 = getelementptr inbounds %struct.MRef, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = zext i32 %53 to i64
  %55 = inttoptr i64 %54 to ptr
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = call ptr @lj_debug_uvname(ptr noundef %57, i32 noundef %58)
  store ptr %59, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %61

60:                                               ; preds = %27
  store i32 0, ptr %10, align 4
  br label %61

61:                                               ; preds = %60, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %62 = load i32, ptr %10, align 4
  switch i32 %62, label %80 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %79

64:                                               ; preds = %15
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.GCfuncC, ptr %66, i32 0, i32 4
  %68 = load i8, ptr %67, align 1, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = icmp ult i32 %65, %69
  br i1 %70, label %71, label %78

71:                                               ; preds = %64
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.GCfuncC, ptr %72, i32 0, i32 9
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [1 x %union.TValue], ptr %73, i64 0, i64 %75
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %76, ptr %77, align 8, !tbaa !5
  store ptr @.str, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %80

78:                                               ; preds = %64
  br label %79

79:                                               ; preds = %78, %63
  store i32 0, ptr %10, align 4
  br label %80

80:                                               ; preds = %79, %71, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %81 = load i32, ptr %10, align 4
  switch i32 %81, label %86 [
    i32 0, label %82
    i32 1, label %84
  ]

82:                                               ; preds = %80
  br label %83

83:                                               ; preds = %82, %3
  store ptr null, ptr %4, align 8
  br label %84

84:                                               ; preds = %83, %80
  %85 = load ptr, ptr %4, align 8
  ret ptr %85

86:                                               ; preds = %80
  unreachable
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 36}
!13 = !{!"GCproto", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !14, i64 12, !15, i64 16, !15, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 36, !7, i64 37, !16, i64 38, !14, i64 40, !10, i64 44, !10, i64 48, !15, i64 52, !15, i64 56, !15, i64 60}
!14 = !{!"GCRef", !10, i64 0}
!15 = !{!"MRef", !10, i64 0}
!16 = !{!"short", !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.GCRef = type { i32 }
%union.TValue = type { i64 }

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

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_debug_uvnamev(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -9
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %3
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = getelementptr inbounds i8, ptr %10, i64 6
  %12 = load i8, ptr %11, align 2, !tbaa !5
  %13 = icmp eq i8 %12, 0
  br i1 %13, label %14, label %35

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %10, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  %19 = getelementptr inbounds i8, ptr %18, i64 -28
  %20 = load i8, ptr %19, align 4, !tbaa !8
  %21 = zext i8 %20 to i32
  %.not = icmp ugt i32 %21, %1
  br i1 %.not, label %22, label %.thread

22:                                               ; preds = %14
  %23 = getelementptr inbounds i8, ptr %18, i64 -64
  %24 = getelementptr inbounds i8, ptr %10, i64 20
  %25 = zext nneg i32 %1 to i64
  %26 = getelementptr inbounds [1 x %struct.GCRef], ptr %24, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = inttoptr i64 %32 to ptr
  store ptr %33, ptr %2, align 8, !tbaa !14
  %34 = tail call ptr @lj_debug_uvname(ptr noundef nonnull %23, i32 noundef %1)
  br label %.thread

35:                                               ; preds = %7
  %36 = getelementptr inbounds i8, ptr %10, i64 7
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  %39 = icmp ugt i32 %38, %1
  br i1 %39, label %40, label %.thread

40:                                               ; preds = %35
  %41 = getelementptr inbounds i8, ptr %10, i64 32
  %42 = zext nneg i32 %1 to i64
  %43 = getelementptr inbounds [1 x %union.TValue], ptr %41, i64 0, i64 %42
  store ptr %43, ptr %2, align 8, !tbaa !14
  br label %.thread

.thread:                                          ; preds = %14, %35, %3, %40, %22
  %.3 = phi ptr [ @.str, %40 ], [ %34, %22 ], [ null, %3 ], [ null, %35 ], [ null, %14 ]
  ret ptr %.3
}

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


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