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

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

; Function Attrs: nounwind uwtable
define hidden void @lj_tab_free(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.GCtab, ptr %5, i32 0, i32 11
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp ugt i32 %7, 0
  br i1 %8, label %9, label %23

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.GCtab, ptr %11, i32 0, i32 9
  %13 = getelementptr inbounds %struct.MRef, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !14
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.GCtab, ptr %17, i32 0, i32 11
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = add i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 24
  call void @lj_mem_free(ptr noundef %10, ptr noundef %16, i64 noundef %22)
  br label %23

23:                                               ; preds = %9, %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.GCtab, ptr %24, i32 0, i32 10
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp ugt i32 %26, 0
  br i1 %27, label %28, label %47

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.GCtab, ptr %29, i32 0, i32 4
  %31 = load i8, ptr %30, align 1, !tbaa !16
  %32 = sext i8 %31 to i32
  %33 = icmp sle i32 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.GCtab, ptr %36, i32 0, i32 5
  %38 = getelementptr inbounds %struct.MRef, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = zext i32 %39 to i64
  %41 = inttoptr i64 %40 to ptr
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.GCtab, ptr %42, i32 0, i32 10
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = zext i32 %44 to i64
  %46 = mul i64 %45, 8
  call void @lj_mem_free(ptr noundef %35, ptr noundef %41, i64 noundef %46)
  br label %47

47:                                               ; preds = %34, %28, %23
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.GCtab, ptr %48, i32 0, i32 4
  %50 = load i8, ptr %49, align 1, !tbaa !16
  %51 = sext i8 %50 to i32
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %64

53:                                               ; preds = %47
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.GCtab, ptr %56, i32 0, i32 4
  %58 = load i8, ptr %57, align 1, !tbaa !16
  %59 = sext i8 %58 to i32
  %60 = and i32 %59, 127
  %61 = zext i32 %60 to i64
  %62 = mul i64 %61, 8
  %63 = add i64 %62, 48
  call void @lj_mem_free(ptr noundef %54, ptr noundef %55, i64 noundef %63)
  br label %67

64:                                               ; preds = %47
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lj_mem_free(ptr noundef %65, ptr noundef %66, i64 noundef 48)
  br label %67

67:                                               ; preds = %64, %53
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_mem_free(ptr noundef, ptr noundef, i64 noundef) #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 = { 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" }

!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, !12, i64 40}
!10 = !{!"GCtab", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !13, i64 32, !12, i64 36, !12, i64 40}
!11 = !{!"GCRef", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"MRef", !12, i64 0}
!14 = !{!10, !12, i64 32}
!15 = !{!10, !12, i64 36}
!16 = !{!10, !7, i64 7}
!17 = !{!10, !12, i64 8}


; 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
define hidden void @lj_tab_free(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 40
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %13, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !13
  %8 = zext i32 %7 to i64
  %9 = inttoptr i64 %8 to ptr
  %10 = add i32 %4, 1
  %11 = zext i32 %10 to i64
  %12 = mul nuw nsw i64 %11, 24
  tail call void @lj_mem_free(ptr noundef %0, ptr noundef %9, i64 noundef %12)
  br label %13

13:                                               ; preds = %5, %2
  %14 = getelementptr inbounds i8, ptr %1, i64 36
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %.not17 = icmp eq i32 %15, 0
  br i1 %.not17, label %27, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %1, i64 7
  %18 = load i8, ptr %17, align 1, !tbaa !15
  %19 = icmp slt i8 %18, 1
  br i1 %19, label %20, label %27

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = zext i32 %22 to i64
  %24 = inttoptr i64 %23 to ptr
  %25 = zext i32 %15 to i64
  %26 = shl nuw nsw i64 %25, 3
  tail call void @lj_mem_free(ptr noundef %0, ptr noundef %24, i64 noundef %26)
  br label %27

27:                                               ; preds = %20, %16, %13
  %28 = getelementptr inbounds i8, ptr %1, i64 7
  %29 = load i8, ptr %28, align 1, !tbaa !15
  %.not18 = icmp eq i8 %29, 0
  %30 = and i8 %29, 127
  %31 = zext nneg i8 %30 to i64
  %32 = shl nuw nsw i64 %31, 3
  %33 = add nuw nsw i64 %32, 48
  %.sink = select i1 %.not18, i64 48, i64 %33
  tail call void @lj_mem_free(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %.sink)
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_mem_free(ptr noundef, ptr noundef, i64 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 = { 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" }

!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 40}
!6 = !{!"GCtab", !7, i64 0, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7, !11, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !11, i64 32, !8, i64 36, !8, i64 40}
!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 = !{!"any pointer", !9, i64 0}
!13 = !{!6, !8, i64 32}
!14 = !{!6, !8, i64 36}
!15 = !{!6, !9, i64 7}
!16 = !{!6, !8, i64 8}


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