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

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

%union.TValue = type { i64 }
%struct.anon.1 = type { %union.anon.2, i32 }
%union.anon.2 = type { %struct.GCRef }
%struct.GCRef = type { i32 }

@lj_bc_mode = external hidden constant [0 x i16], align 2

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

; Function Attrs: noreturn
declare hidden void @lj_err_optype(ptr noundef, ptr noundef, i32 noundef) #2

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

declare hidden void @lj_cont_ra() #3

; Function Attrs: nounwind uwtable
define hidden ptr @lj_meta_arith(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %union.TValue, align 8
  %14 = alloca %union.TValue, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [0 x i16], ptr @lj_bc_mode, i64 0, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !11
  %23 = zext i16 %22 to i32
  %24 = ashr i32 %23, 11
  store i32 %24, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = call ptr @str2num(ptr noundef %25, ptr noundef %13)
  store ptr %26, ptr %15, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %41

28:                                               ; preds = %5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = call ptr @str2num(ptr noundef %29, ptr noundef %14)
  store ptr %30, ptr %16, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %41

32:                                               ; preds = %28
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = load ptr, ptr %16, align 8, !tbaa !5
  %36 = load double, ptr %35, align 8, !tbaa !13
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 10
  %39 = call double @lj_vm_foldarith(double noundef %34, double noundef %36, i32 noundef %38)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  store double %39, ptr %40, align 8, !tbaa !13
  store ptr null, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %75

41:                                               ; preds = %28, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = call ptr @lj_meta_lookup(ptr noundef %42, ptr noundef %43, i32 noundef %44)
  store ptr %45, ptr %18, align 8, !tbaa !5
  %46 = load ptr, ptr %18, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.anon.1, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = icmp eq i32 %48, -1
  br i1 %49, label %50, label %69

50:                                               ; preds = %41
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = call ptr @lj_meta_lookup(ptr noundef %51, ptr noundef %52, i32 noundef %53)
  store ptr %54, ptr %18, align 8, !tbaa !5
  %55 = load ptr, ptr %18, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.anon.1, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !13
  %58 = icmp eq i32 %57, -1
  br i1 %58, label %59, label %68

59:                                               ; preds = %50
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = call ptr @str2num(ptr noundef %60, ptr noundef %13)
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %64, ptr %10, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %63, %59
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  call void @lj_err_optype(ptr noundef %66, ptr noundef %67, i32 noundef 409) #5
  unreachable

68:                                               ; preds = %50
  br label %69

69:                                               ; preds = %68, %41
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %18, align 8, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = call ptr @mmcall(ptr noundef %70, ptr noundef @lj_cont_ra, ptr noundef %71, ptr noundef %72, ptr noundef %73)
  store ptr %74, ptr %6, align 8
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %75

75:                                               ; preds = %69, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %76 = load ptr, ptr %6, align 8
  ret ptr %76
}

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

declare hidden double @lj_vm_foldarith(double noundef, double noundef, i32 noundef) #3

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 = { noreturn "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 = { "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 }
attributes #5 = { noreturn }

!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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !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"

%union.TValue = type { i64 }

@lj_bc_mode = external hidden local_unnamed_addr constant [0 x i16], align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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_meta_lookup(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare hidden void @lj_err_optype(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

declare hidden void @lj_cont_ra() #3

; Function Attrs: nounwind uwtable
define hidden ptr @lj_meta_arith(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %union.TValue, align 8
  %7 = alloca %union.TValue, align 8
  %8 = zext i32 %4 to i64
  %9 = getelementptr inbounds [0 x i16], ptr @lj_bc_mode, i64 0, i64 %8
  %10 = load i16, ptr %9, align 2, !tbaa !5
  %11 = lshr i16 %10, 11
  %12 = zext nneg i16 %11 to i32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %13 = call ptr @str2num(ptr noundef %2, ptr noundef nonnull %6)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %21, label %14

14:                                               ; preds = %5
  %15 = call ptr @str2num(ptr noundef %3, ptr noundef nonnull %7)
  %.not27 = icmp eq ptr %15, null
  br i1 %.not27, label %21, label %16

16:                                               ; preds = %14
  %17 = load double, ptr %13, align 8, !tbaa !9
  %18 = load double, ptr %15, align 8, !tbaa !9
  %19 = add nsw i32 %12, -10
  %20 = call double @lj_vm_foldarith(double noundef %17, double noundef %18, i32 noundef %19) #4
  store double %20, ptr %1, align 8, !tbaa !9
  br label %36

21:                                               ; preds = %14, %5
  %22 = call ptr @lj_meta_lookup(ptr noundef %0, ptr noundef %2, i32 noundef %12)
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %34

26:                                               ; preds = %21
  %27 = call ptr @lj_meta_lookup(ptr noundef %0, ptr noundef %3, i32 noundef %12)
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp eq i32 %29, -1
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = call ptr @str2num(ptr noundef %2, ptr noundef nonnull %6)
  %33 = icmp eq ptr %32, null
  %spec.select = select i1 %33, ptr %2, ptr %3
  call void @lj_err_optype(ptr noundef %0, ptr noundef %spec.select, i32 noundef 409) #5
  unreachable

34:                                               ; preds = %26, %21
  %.0 = phi ptr [ %27, %26 ], [ %22, %21 ]
  %35 = call ptr @mmcall(ptr noundef %0, ptr noundef nonnull @lj_cont_ra, ptr noundef nonnull %.0, ptr noundef %2, ptr noundef %3)
  br label %36

36:                                               ; preds = %34, %16
  %.023 = phi ptr [ null, %16 ], [ %35, %34 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret ptr %.023
}

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

declare hidden double @lj_vm_foldarith(double noundef, double noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { noreturn "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 = { "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 }
attributes #5 = { noreturn 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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