; 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.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.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 i32 @hashrot(i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ctype_getname(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 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 i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = 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 i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.CTState, ptr %13, i32 0, i32 8
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = ptrtoint ptr %15 to i64
  %17 = trunc i64 %16 to i32
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = ptrtoint ptr %18 to i64
  %20 = trunc i64 %19 to i32
  %21 = add i32 %20, -79764919
  %22 = call i32 @hashrot(i32 noundef %17, i32 noundef %21)
  %23 = and i32 %22, 127
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [128 x i16], ptr %14, i64 0, i64 %24
  %26 = load i16, ptr %25, align 2, !tbaa !11
  %27 = zext i16 %26 to i32
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %63, %4
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %64

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = call ptr @ctype_get(ptr noundef %32, i32 noundef %33)
  store ptr %34, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CType, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds %struct.GCRef, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = zext i32 %38 to i64
  %40 = inttoptr i64 %39 to ptr
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = icmp eq ptr %40, %41
  br i1 %42, label %43, label %56

43:                                               ; preds = %31
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.CType, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !16
  %48 = lshr i32 %47, 28
  %49 = lshr i32 %44, %48
  %50 = and i32 %49, 1
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %43
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %55, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %61

56:                                               ; preds = %43, %31
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.CType, ptr %57, i32 0, i32 3
  %59 = load i16, ptr %58, align 2, !tbaa !17
  %60 = zext i16 %59 to i32
  store i32 %60, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %61

61:                                               ; preds = %56, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %62 = load i32, ptr %12, align 4
  switch i32 %62, label %70 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %28, !llvm.loop !18

64:                                               ; preds = %28
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.CTState, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !20
  %68 = getelementptr inbounds %struct.CType, ptr %67, i64 0
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %68, ptr %69, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

70:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %71 = load i32, ptr %5, align 4
  ret i32 %71
}

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 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"CType", !10, i64 0, !10, i64 4, !12, i64 8, !12, i64 10, !15, i64 12}
!15 = !{!"GCRef", !10, i64 0}
!16 = !{!14, !10, i64 0}
!17 = !{!14, !12, i64 10}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !6, i64 0}
!21 = !{!"CTState", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !22, i64 48, !7, i64 216}
!22 = !{!"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}


; 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 i32 @hashrot(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define hidden noundef i32 @lj_ctype_getname(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 216
  %6 = ptrtoint ptr %2 to i64
  %7 = trunc i64 %6 to i32
  %8 = add i32 %7, -79764919
  %9 = tail call i32 @hashrot(i32 noundef %7, i32 noundef %8)
  %10 = and i32 %9, 127
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds [128 x i16], ptr %5, i64 0, i64 %11
  %.018.in26 = load i16, ptr %12, align 2, !tbaa !5
  %.not28 = icmp eq i16 %.018.in26, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %24
  %.01829.in = phi i16 [ %.018.in, %24 ], [ %.018.in26, %4 ]
  %.01829 = zext i16 %.01829.in to i32
  %13 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %.01829)
  %14 = getelementptr inbounds i8, ptr %13, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = inttoptr i64 %16 to ptr
  %18 = icmp eq ptr %17, %2
  br i1 %18, label %19, label %24

19:                                               ; preds = %.lr.ph
  %20 = load i32, ptr %13, align 4, !tbaa !13
  %21 = lshr i32 %20, 28
  %22 = shl nuw nsw i32 1, %21
  %23 = and i32 %22, %3
  %.not20 = icmp eq i32 %23, 0
  br i1 %.not20, label %24, label %.thread

24:                                               ; preds = %.lr.ph, %19
  %25 = getelementptr inbounds i8, ptr %13, i64 10
  %.018.in = load i16, ptr %25, align 2, !tbaa !5
  %.not = icmp eq i16 %.018.in, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %24, %4
  %26 = load ptr, ptr %0, align 8, !tbaa !16
  br label %.thread

.thread:                                          ; preds = %19, %._crit_edge
  %.01825 = phi i32 [ 0, %._crit_edge ], [ %.01829, %19 ]
  %storemerge = phi ptr [ %26, %._crit_edge ], [ %13, %19 ]
  store ptr %storemerge, ptr %1, align 8, !tbaa !20
  ret i32 %.01825
}

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

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


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