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

; 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.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%struct.GCudata = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, i32, %struct.GCRef, i32 }

; 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 @index2adr(ptr noundef, i32 noundef) #1

declare hidden ptr @lj_strfmt_number(ptr noundef, ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setstrV(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i64 @lua_objlen(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  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) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = call ptr @index2adr(ptr noundef %9, i32 noundef %10)
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.anon.0, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i32 %14, -5
  br i1 %15, label %16, label %26

16:                                               ; preds = %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.anon.0, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.GCRef, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = inttoptr i64 %21 to ptr
  %23 = getelementptr inbounds %struct.GCstr, ptr %22, i32 0, i32 6
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  store i64 %25, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

26:                                               ; preds = %2
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.anon.0, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = icmp eq i32 %29, -12
  br i1 %30, label %31, label %40

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.anon.0, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.GCRef, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = zext i32 %35 to i64
  %37 = inttoptr i64 %36 to ptr
  %38 = call i32 @lj_tab_len(ptr noundef %37)
  %39 = zext i32 %38 to i64
  store i64 %39, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

40:                                               ; preds = %26
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.anon.0, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = icmp eq i32 %43, -13
  br i1 %44, label %45, label %55

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.anon.0, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.GCRef, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = inttoptr i64 %50 to ptr
  %52 = getelementptr inbounds %struct.GCudata, ptr %51, i32 0, i32 6
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = zext i32 %53 to i64
  store i64 %54, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

55:                                               ; preds = %40
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.anon.0, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = icmp ule i32 %58, -65537
  br i1 %59, label %60, label %71

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = call ptr @lj_strfmt_number(ptr noundef %61, ptr noundef %62)
  store ptr %63, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  call void @setstrV(ptr noundef %64, ptr noundef %65, ptr noundef %66)
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.GCstr, ptr %67, i32 0, i32 6
  %69 = load i32, ptr %68, align 4, !tbaa !12
  %70 = zext i32 %69 to i64
  store i64 %70, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %72

71:                                               ; preds = %55
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

72:                                               ; preds = %71, %60, %45, %31, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %73 = load i64, ptr %3, align 8
  ret i64 %73
}

declare hidden i32 @lj_tab_len(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 = { 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 12}
!13 = !{!"GCstr", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12}
!14 = !{!"GCRef", !10, 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"

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

declare hidden ptr @lj_strfmt_number(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 4294967296) i64 @lua_objlen(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @index2adr(ptr noundef %0, i32 noundef %1)
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %5, label %23 [
    i32 -5, label %6
    i32 -12, label %12
    i32 -13, label %17
  ]

6:                                                ; preds = %2
  %7 = load i32, ptr %3, align 8, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !5
  br label %29

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 8, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = tail call i32 @lj_tab_len(ptr noundef %15) #3
  br label %29

17:                                               ; preds = %2
  %18 = load i32, ptr %3, align 8, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  %21 = getelementptr inbounds i8, ptr %20, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !5
  br label %29

23:                                               ; preds = %2
  %24 = icmp ult i32 %5, -65536
  br i1 %24, label %25, label %29

25:                                               ; preds = %23
  %26 = tail call ptr @lj_strfmt_number(ptr noundef %0, ptr noundef nonnull %3) #3
  tail call void @setstrV(ptr noundef %0, ptr noundef nonnull %3, ptr noundef %26)
  %27 = getelementptr inbounds i8, ptr %26, i64 12
  %28 = load i32, ptr %27, align 4, !tbaa !8
  br label %29

29:                                               ; preds = %23, %25, %17, %12, %6
  %.0.shrunk = phi i32 [ %11, %6 ], [ %16, %12 ], [ %22, %17 ], [ %28, %25 ], [ 0, %23 ]
  %.0 = zext i32 %.0.shrunk to i64
  ret i64 %.0
}

declare hidden i32 @lj_tab_len(ptr noundef) local_unnamed_addr #1

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 = { 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 12}
!9 = !{!"GCstr", !10, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !11, i64 8, !11, i64 12}
!10 = !{!"GCRef", !11, i64 0}
!11 = !{!"int", !6, i64 0}


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