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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_cdata_get(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.CType, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = lshr i32 %14, 28
  %16 = icmp eq i32 %15, 11
  br i1 %16, label %17, label %21

17:                                               ; preds = %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  call void @cdata_getconst(ptr noundef %18, ptr noundef %19, ptr noundef %20)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %75

21:                                               ; preds = %4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.CType, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = lshr i32 %24, 28
  %26 = icmp eq i32 %25, 10
  br i1 %26, label %27, label %33

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call i32 @lj_cconv_tv_bf(ptr noundef %28, ptr noundef %29, ptr noundef %30, ptr noundef %31)
  store i32 %32, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %75

33:                                               ; preds = %21
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CType, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = and i32 %37, 65535
  store i32 %38, ptr %10, align 4, !tbaa !14
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !14
  %41 = call ptr @ctype_get(ptr noundef %39, i32 noundef %40)
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.CType, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = and i32 %44, -260046848
  %46 = icmp eq i32 %45, 545259520
  br i1 %46, label %47, label %57

47:                                               ; preds = %34
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  store ptr %49, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CType, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = and i32 %52, 65535
  store i32 %53, ptr %10, align 4, !tbaa !14
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !14
  %56 = call ptr @ctype_get(ptr noundef %54, i32 noundef %55)
  store ptr %56, ptr %7, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %47, %34
  br label %58

58:                                               ; preds = %64, %57
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.CType, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = lshr i32 %61, 28
  %63 = icmp eq i32 %62, 8
  br i1 %63, label %64, label %68

64:                                               ; preds = %58
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = call ptr @ctype_child(ptr noundef %65, ptr noundef %66)
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %58, !llvm.loop !15

68:                                               ; preds = %58
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %10, align 4, !tbaa !14
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call i32 @lj_cconv_tv_ct(ptr noundef %69, ptr noundef %70, i32 noundef %71, ptr noundef %72, ptr noundef %73)
  store i32 %74, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %75

75:                                               ; preds = %68, %27, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %76 = load i32, ptr %5, align 4
  ret i32 %76
}

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

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

declare hidden i32 @lj_cconv_tv_ct(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr 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, !11, i64 0}
!10 = !{!"CType", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 10, !13, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"GCRef", !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_cdata_get(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = lshr i32 %5, 28
  switch i32 %6, label %10 [
    i32 11, label %7
    i32 10, label %8
  ]

7:                                                ; preds = %4
  tail call void @cdata_getconst(ptr noundef %0, ptr noundef %2, ptr noundef nonnull %1)
  br label %27

8:                                                ; preds = %4
  %9 = tail call i32 @lj_cconv_tv_bf(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %2, ptr noundef %3) #3
  br label %27

10:                                               ; preds = %4
  %11 = and i32 %5, 65535
  %12 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %11)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = and i32 %13, -260046848
  %15 = icmp eq i32 %14, 545259520
  br i1 %15, label %16, label %20

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !12
  %18 = and i32 %13, 65535
  %19 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %18)
  %.pre = load i32, ptr %19, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %16, %10
  %21 = phi i32 [ %.pre, %16 ], [ %13, %10 ]
  %.027 = phi ptr [ %19, %16 ], [ %12, %10 ]
  %.025 = phi ptr [ %17, %16 ], [ %3, %10 ]
  %.0 = phi i32 [ %18, %16 ], [ %11, %10 ]
  %.mask29 = and i32 %21, -268435456
  %22 = icmp eq i32 %.mask29, -2147483648
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.130 = phi ptr [ %23, %.lr.ph ], [ %.027, %20 ]
  %23 = tail call ptr @ctype_child(ptr noundef %0, ptr noundef nonnull %.130)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.mask = and i32 %24, -268435456
  %25 = icmp eq i32 %.mask, -2147483648
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %20
  %.1.lcssa = phi ptr [ %.027, %20 ], [ %23, %.lr.ph ]
  %26 = tail call i32 @lj_cconv_tv_ct(ptr noundef %0, ptr noundef nonnull %.1.lcssa, i32 noundef %.0, ptr noundef %2, ptr noundef %.025) #3
  br label %27

27:                                               ; preds = %._crit_edge, %8, %7
  %.026 = phi i32 [ 0, %7 ], [ %9, %8 ], [ %26, %._crit_edge ]
  ret i32 %.026
}

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

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

declare hidden i32 @lj_cconv_tv_ct(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr 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 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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