; 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.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 }

@.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
define hidden ptr @lj_debug_uvname(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.GCproto, ptr %8, i32 0, i32 19
  %10 = getelementptr inbounds %struct.MRef, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  %13 = inttoptr i64 %12 to ptr
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %2
  store ptr @.str, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

17:                                               ; preds = %2
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %35

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %33, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load i8, ptr %22, align 1, !tbaa !16
  %25 = zext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %31, label %27

27:                                               ; preds = %21
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add i32 %28, -1
  store i32 %29, ptr %5, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br label %31

31:                                               ; preds = %27, %21
  %32 = phi i1 [ true, %21 ], [ %30, %27 ]
  br i1 %32, label %33, label %34

33:                                               ; preds = %31
  br label %21, !llvm.loop !17

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34, %17
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %35, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %38 = load ptr, ptr %3, align 8
  ret ptr %38
}

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define hidden ptr @lj_debug_uvname(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = zext i32 %4 to i64
  %7 = inttoptr i64 %6 to ptr
  %.not12 = icmp eq i32 %1, 0
  br i1 %.not12, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %5
  %xtraiter = and i32 %1, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.outer.prol.loopexit, label %.preheader.outer.prol

.preheader.outer.prol:                            ; preds = %.preheader.preheader, %10
  %.06.ph.prol = phi i32 [ %11, %10 ], [ %1, %.preheader.preheader ]
  %.0.ph.prol = phi ptr [ %8, %10 ], [ %7, %.preheader.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %10 ], [ 0, %.preheader.preheader ]
  br label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.prol, %.preheader.outer.prol
  %.0.prol = phi ptr [ %8, %.preheader.prol ], [ %.0.ph.prol, %.preheader.outer.prol ]
  %8 = getelementptr inbounds i8, ptr %.0.prol, i64 1
  %9 = load i8, ptr %.0.prol, align 1, !tbaa !13
  %.not13.prol = icmp eq i8 %9, 0
  br i1 %.not13.prol, label %10, label %.preheader.prol, !llvm.loop !14

10:                                               ; preds = %.preheader.prol
  %11 = add i32 %.06.ph.prol, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.preheader.outer.prol.loopexit, label %.preheader.outer.prol, !llvm.loop !16

.preheader.outer.prol.loopexit:                   ; preds = %10, %.preheader.preheader
  %.lcssa.lcssa.unr = phi ptr [ poison, %.preheader.preheader ], [ %8, %10 ]
  %.06.ph.unr = phi i32 [ %1, %.preheader.preheader ], [ %11, %10 ]
  %.0.ph.unr = phi ptr [ %7, %.preheader.preheader ], [ %8, %10 ]
  %12 = icmp ult i32 %1, 4
  br i1 %12, label %.loopexit, label %.preheader.outer

.preheader.outer:                                 ; preds = %.preheader.outer.prol.loopexit, %21
  %.06.ph = phi i32 [ %22, %21 ], [ %.06.ph.unr, %.preheader.outer.prol.loopexit ]
  %.0.ph = phi ptr [ %19, %21 ], [ %.0.ph.unr, %.preheader.outer.prol.loopexit ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.outer, %.preheader
  %.0 = phi ptr [ %13, %.preheader ], [ %.0.ph, %.preheader.outer ]
  %13 = getelementptr inbounds i8, ptr %.0, i64 1
  %14 = load i8, ptr %.0, align 1, !tbaa !13
  %.not13 = icmp eq i8 %14, 0
  br i1 %.not13, label %.preheader.1, label %.preheader, !llvm.loop !14

.preheader.1:                                     ; preds = %.preheader, %.preheader.1
  %.0.1 = phi ptr [ %15, %.preheader.1 ], [ %13, %.preheader ]
  %15 = getelementptr inbounds i8, ptr %.0.1, i64 1
  %16 = load i8, ptr %.0.1, align 1, !tbaa !13
  %.not13.1 = icmp eq i8 %16, 0
  br i1 %.not13.1, label %.preheader.2, label %.preheader.1, !llvm.loop !14

.preheader.2:                                     ; preds = %.preheader.1, %.preheader.2
  %.0.2 = phi ptr [ %17, %.preheader.2 ], [ %15, %.preheader.1 ]
  %17 = getelementptr inbounds i8, ptr %.0.2, i64 1
  %18 = load i8, ptr %.0.2, align 1, !tbaa !13
  %.not13.2 = icmp eq i8 %18, 0
  br i1 %.not13.2, label %.preheader.3, label %.preheader.2, !llvm.loop !14

.preheader.3:                                     ; preds = %.preheader.2, %.preheader.3
  %.0.3 = phi ptr [ %19, %.preheader.3 ], [ %17, %.preheader.2 ]
  %19 = getelementptr inbounds i8, ptr %.0.3, i64 1
  %20 = load i8, ptr %.0.3, align 1, !tbaa !13
  %.not13.3 = icmp eq i8 %20, 0
  br i1 %.not13.3, label %21, label %.preheader.3, !llvm.loop !14

21:                                               ; preds = %.preheader.3
  %22 = add i32 %.06.ph, -4
  %.not14.3 = icmp eq i32 %22, 0
  br i1 %.not14.3, label %.loopexit, label %.preheader.outer, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader.outer.prol.loopexit, %21, %5, %2
  %.08 = phi ptr [ @.str, %2 ], [ %7, %5 ], [ %.lcssa.lcssa.unr, %.preheader.outer.prol.loopexit ], [ %19, %21 ]
  ret ptr %.08
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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, !8, i64 56}
!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 = !{!9, !9, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass