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

; 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 = type { %union.anon.0, i32 }
%union.anon.0 = type { %struct.GCRef }
%struct.GCRef = type { i32 }

@lj_obj_itypename = external hidden constant [14 x ptr], align 16

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

; Function Attrs: noinline noreturn nounwind uwtable
declare dso_local void @err_msgv(ptr noundef, i32 noundef, ...) #1

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_comp(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.anon, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp ule i32 %11, -65537
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %28

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = ashr i32 %17, 15
  %19 = icmp eq i32 %18, -2
  br i1 %19, label %20, label %21

20:                                               ; preds = %14
  br label %26

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = xor i32 %24, -1
  br label %26

26:                                               ; preds = %21, %20
  %27 = phi i32 [ 3, %20 ], [ %25, %21 ]
  br label %28

28:                                               ; preds = %26, %13
  %29 = phi i32 [ 13, %13 ], [ %27, %26 ]
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp ule i32 %35, -65537
  br i1 %36, label %37, label %38

37:                                               ; preds = %28
  br label %52

38:                                               ; preds = %28
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = ashr i32 %41, 15
  %43 = icmp eq i32 %42, -2
  br i1 %43, label %44, label %45

44:                                               ; preds = %38
  br label %50

45:                                               ; preds = %38
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.anon, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = xor i32 %48, -1
  br label %50

50:                                               ; preds = %45, %44
  %51 = phi i32 [ 3, %44 ], [ %49, %45 ]
  br label %52

52:                                               ; preds = %50, %37
  %53 = phi i32 [ 13, %37 ], [ %51, %50 ]
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  store ptr %56, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = icmp eq ptr %58, %59
  %61 = zext i1 %60 to i64
  %62 = select i1 %60, i32 331, i32 301
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, i32, ...) @err_msgv(ptr noundef %57, i32 noundef %62, ptr noundef %63, ptr noundef %64) #3
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn 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 }
attributes #3 = { 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 = !{!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"

@lj_obj_itypename = external hidden local_unnamed_addr constant [14 x ptr], align 16

; Function Attrs: noinline noreturn nounwind uwtable
declare dso_local void @err_msgv(ptr noundef, i32 noundef, ...) local_unnamed_addr #0

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_comp(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp ult i32 %5, -65536
  br i1 %6, label %12, label %7

7:                                                ; preds = %3
  %.mask = and i32 %5, -32768
  %8 = icmp eq i32 %.mask, -65536
  br i1 %8, label %12, label %9

9:                                                ; preds = %7
  %10 = xor i32 %5, -1
  %11 = zext nneg i32 %10 to i64
  br label %12

12:                                               ; preds = %9, %7, %3
  %13 = phi i64 [ 13, %3 ], [ %11, %9 ], [ 3, %7 ]
  %14 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !8
  %16 = getelementptr inbounds i8, ptr %2, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ult i32 %17, -65536
  br i1 %18, label %24, label %19

19:                                               ; preds = %12
  %.mask12 = and i32 %17, -32768
  %20 = icmp eq i32 %.mask12, -65536
  br i1 %20, label %24, label %21

21:                                               ; preds = %19
  %22 = xor i32 %17, -1
  %23 = zext nneg i32 %22 to i64
  br label %24

24:                                               ; preds = %21, %19, %12
  %25 = phi i64 [ 13, %12 ], [ %23, %21 ], [ 3, %19 ]
  %26 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !8
  %28 = icmp eq ptr %15, %27
  %29 = select i1 %28, i32 331, i32 301
  tail call void (ptr, i32, ...) @err_msgv(ptr noundef %0, i32 noundef %29, ptr noundef %15, ptr noundef %27) #1
  unreachable
}

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


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