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

; 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.CType = type { i32, i32, i16, i16, %struct.GCRef }
%struct.GCRef = type { i32 }
%struct.CTState = type { ptr, i32, i32, ptr, ptr, ptr, ptr, %struct.CCallback, [128 x i16] }
%struct.CCallback = type { [8 x %union.FPRCBArg], [8 x i64], ptr, ptr, ptr, i32, i32, i32 }
%union.FPRCBArg = type { double }
%struct.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%union.TValue = type { i64 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.2, %struct.MRef, i32 }
%union.anon.2 = type { %union.TValue }
%struct.MRef = type { i32 }
%struct.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }

; 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: alwaysinline nounwind uwtable
declare hidden ptr @ctype_get(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define hidden ptr @lj_ctype_meta(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = call ptr @ctype_get(ptr noundef %11, i32 noundef %12)
  store ptr %13, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  br label %14

14:                                               ; preds = %28, %3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.CType, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = lshr i32 %17, 28
  %19 = icmp eq i32 %18, 8
  br i1 %19, label %26, label %20

20:                                               ; preds = %14
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.CType, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = and i32 %23, -260046848
  %25 = icmp eq i32 %24, 545259520
  br label %26

26:                                               ; preds = %20, %14
  %27 = phi i1 [ true, %14 ], [ %25, %20 ]
  br i1 %27, label %28, label %36

28:                                               ; preds = %26
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.CType, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = and i32 %31, 65535
  store i32 %32, ptr %6, align 4, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = call ptr @ctype_get(ptr noundef %33, i32 noundef %34)
  store ptr %35, ptr %8, align 8, !tbaa !5
  br label %14, !llvm.loop !15

36:                                               ; preds = %26
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.CType, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = lshr i32 %39, 28
  %41 = icmp eq i32 %40, 2
  br i1 %41, label %42, label %62

42:                                               ; preds = %36
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CType, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = and i32 %46, 65535
  %48 = call ptr @ctype_get(ptr noundef %43, i32 noundef %47)
  %49 = getelementptr inbounds %struct.CType, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = lshr i32 %50, 28
  %52 = icmp eq i32 %51, 6
  br i1 %52, label %53, label %62

53:                                               ; preds = %42
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.CTState, ptr %54, i32 0, i32 6
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.CTState, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  %60 = getelementptr inbounds %struct.global_State, ptr %59, i32 0, i32 8
  %61 = call ptr @lj_tab_getstr(ptr noundef %56, ptr noundef %60)
  store ptr %61, ptr %9, align 8, !tbaa !5
  br label %69

62:                                               ; preds = %42, %36
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.CTState, ptr %63, i32 0, i32 6
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sub nsw i32 0, %66
  %68 = call ptr @lj_tab_getinth(ptr noundef %65, i32 noundef %67)
  store ptr %68, ptr %9, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %62, %53
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %105

72:                                               ; preds = %69
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.anon, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !21
  %76 = icmp eq i32 %75, -12
  br i1 %76, label %77, label %105

77:                                               ; preds = %72
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.GCRef, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !21
  %82 = zext i32 %81 to i64
  %83 = inttoptr i64 %82 to ptr
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.CTState, ptr %84, i32 0, i32 4
  %86 = load ptr, ptr %85, align 8, !tbaa !20
  %87 = getelementptr inbounds %struct.global_State, ptr %86, i32 0, i32 29
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = add i32 0, %88
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds [38 x %struct.GCRef], ptr %87, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.GCRef, ptr %91, i32 0, i32 0
  %93 = load i32, ptr %92, align 4, !tbaa !22
  %94 = zext i32 %93 to i64
  %95 = inttoptr i64 %94 to ptr
  %96 = call ptr @lj_tab_getstr(ptr noundef %83, ptr noundef %95)
  store ptr %96, ptr %9, align 8, !tbaa !5
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %105

98:                                               ; preds = %77
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.anon, ptr %99, i32 0, i32 1
  %101 = load i32, ptr %100, align 4, !tbaa !21
  %102 = icmp eq i32 %101, -1
  br i1 %102, label %105, label %103

103:                                              ; preds = %98
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %104, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %106

105:                                              ; preds = %98, %77, %72, %69
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %106

106:                                              ; preds = %105, %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %107 = load ptr, ptr %4, align 8
  ret ptr %107
}

declare hidden ptr @lj_tab_getstr(ptr noundef, ptr noundef) #3

declare hidden ptr @lj_tab_getinth(ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = { "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 = !{!12, !10, i64 0}
!12 = !{!"CType", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 10, !14, i64 12}
!13 = !{!"short", !7, i64 0}
!14 = !{!"GCRef", !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 40}
!18 = !{!"CTState", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !19, i64 48, !7, i64 216}
!19 = !{!"CCallback", !7, i64 0, !7, i64 64, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !10, i64 156, !10, i64 160}
!20 = !{!18, !6, i64 24}
!21 = !{!7, !7, i64 0}
!22 = !{!14, !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"

%struct.GCRef = type { i32 }

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_ctype_meta(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %1)
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = lshr i32 %5, 28
  %7 = icmp eq i32 %6, 8
  %8 = and i32 %5, -260046848
  %9 = icmp eq i32 %8, 545259520
  %or.cond29 = or i1 %7, %9
  br i1 %or.cond29, label %.critedge, label %._crit_edge

.critedge:                                        ; preds = %3, %.critedge
  %10 = phi i32 [ %13, %.critedge ], [ %5, %3 ]
  %11 = and i32 %10, 65535
  %12 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %11)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = lshr i32 %13, 28
  %15 = icmp eq i32 %14, 8
  %16 = and i32 %13, -260046848
  %17 = icmp eq i32 %16, 545259520
  %or.cond = or i1 %15, %17
  br i1 %or.cond, label %.critedge, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.critedge, %3
  %.023.lcssa = phi i32 [ %1, %3 ], [ %11, %.critedge ]
  %.lcssa28 = phi i32 [ %5, %3 ], [ %13, %.critedge ]
  %.lcssa = phi i32 [ %6, %3 ], [ %14, %.critedge ]
  %18 = icmp eq i32 %.lcssa, 2
  br i1 %18, label %19, label %31

19:                                               ; preds = %._crit_edge
  %20 = and i32 %.lcssa28, 65535
  %21 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %20)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.mask = and i32 %22, -268435456
  %23 = icmp eq i32 %.mask, 1610612736
  br i1 %23, label %24, label %31

24:                                               ; preds = %19
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %28, i64 108
  %30 = tail call ptr @lj_tab_getstr(ptr noundef %26, ptr noundef nonnull %29) #3
  br label %36

31:                                               ; preds = %19, %._crit_edge
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = sub nsw i32 0, %.023.lcssa
  %35 = tail call ptr @lj_tab_getinth(ptr noundef %33, i32 noundef %34) #3
  br label %36

36:                                               ; preds = %31, %24
  %.0 = phi ptr [ %30, %24 ], [ %35, %31 ]
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %58, label %37

37:                                               ; preds = %36
  %38 = getelementptr inbounds i8, ptr %.0, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !19
  %40 = icmp eq i32 %39, -12
  br i1 %40, label %41, label %58

41:                                               ; preds = %37
  %42 = load i32, ptr %.0, align 8, !tbaa !19
  %43 = zext i32 %42 to i64
  %44 = inttoptr i64 %43 to ptr
  %45 = getelementptr inbounds i8, ptr %0, i64 24
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds i8, ptr %46, i64 260
  %48 = zext i32 %2 to i64
  %49 = getelementptr inbounds [38 x %struct.GCRef], ptr %47, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !20
  %51 = zext i32 %50 to i64
  %52 = inttoptr i64 %51 to ptr
  %53 = tail call ptr @lj_tab_getstr(ptr noundef %44, ptr noundef %52) #3
  %.not26 = icmp eq ptr %53, null
  br i1 %.not26, label %58, label %54

54:                                               ; preds = %41
  %55 = getelementptr inbounds i8, ptr %53, i64 4
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = icmp eq i32 %56, -1
  br i1 %57, label %58, label %59

58:                                               ; preds = %54, %41, %37, %36
  br label %59

59:                                               ; preds = %54, %58
  %.022 = phi ptr [ null, %58 ], [ %53, %54 ]
  ret ptr %.022
}

declare hidden ptr @lj_tab_getstr(ptr noundef, ptr noundef) local_unnamed_addr #2

declare hidden ptr @lj_tab_getinth(ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #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 = { 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, !7, i64 0}
!6 = !{!"CType", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 10, !11, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"GCRef", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 40}
!15 = !{!"CTState", !16, i64 0, !7, i64 8, !7, i64 12, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !17, i64 48, !8, i64 216}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"CCallback", !8, i64 0, !8, i64 64, !16, i64 128, !16, i64 136, !16, i64 144, !7, i64 152, !7, i64 156, !7, i64 160}
!18 = !{!15, !16, i64 24}
!19 = !{!8, !8, i64 0}
!20 = !{!11, !7, i64 0}


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