; 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.CTRepr = type { ptr, ptr, ptr, ptr, i32, i32, [512 x i8] }
%struct.lua_State = type { %union.anon.4 }
%union.anon.4 = type { %struct.anon.5, [320 x i8] }
%struct.anon.5 = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.GCRef = type { i32 }
%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 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; 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
define hidden ptr @lj_ctype_repr(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.CTRepr, 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 ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lua_State, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon.5, ptr %12, i32 0, i32 5
  %14 = getelementptr inbounds %struct.MRef, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = zext i32 %15 to i64
  %17 = inttoptr i64 %16 to ptr
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 552, ptr %9) #4
  %18 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 6
  %19 = getelementptr inbounds [512 x i8], ptr %18, i64 0, i64 256
  %20 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 1
  store ptr %19, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 0
  store ptr %19, ptr %21, align 8, !tbaa !14
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.global_State, ptr %22, i32 0, i32 28
  %24 = getelementptr inbounds %struct.MRef, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = zext i32 %25 to i64
  %27 = inttoptr i64 %26 to ptr
  %28 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 2
  store ptr %27, ptr %28, align 8, !tbaa !24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 3
  store ptr %29, ptr %30, align 8, !tbaa !25
  %31 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 5
  store i32 1, ptr %31, align 4, !tbaa !26
  %32 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 4
  store i32 0, ptr %32, align 8, !tbaa !27
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %41

35:                                               ; preds = %3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.GCstr, ptr %36, i64 1
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.GCstr, ptr %38, i32 0, i32 6
  %40 = load i32, ptr %39, align 4, !tbaa !28
  call void @ctype_prepstr(ptr noundef %9, ptr noundef %37, i32 noundef %40)
  br label %41

41:                                               ; preds = %35, %3
  %42 = load i32, ptr %6, align 4, !tbaa !9
  call void @ctype_repr(ptr noundef %9, i32 noundef %42)
  %43 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 5
  %44 = load i32, ptr %43, align 4, !tbaa !26
  %45 = icmp ne i32 %44, 0
  %46 = xor i1 %45, true
  %47 = xor i1 %46, true
  %48 = xor i1 %47, true
  %49 = zext i1 %48 to i32
  %50 = sext i32 %49 to i64
  %51 = call i64 @llvm.expect.i64(i64 %50, i64 0)
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %41
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call ptr @lj_str_new(ptr noundef %54, ptr noundef @.str, i64 noundef 1)
  store ptr %55, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %68

56:                                               ; preds = %41
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !12
  %62 = getelementptr inbounds %struct.CTRepr, ptr %9, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = ptrtoint ptr %61 to i64
  %65 = ptrtoint ptr %63 to i64
  %66 = sub i64 %64, %65
  %67 = call ptr @lj_str_new(ptr noundef %57, ptr noundef %59, i64 noundef %66)
  store ptr %67, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %68

68:                                               ; preds = %56, %53
  call void @llvm.lifetime.end.p0(i64 552, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %69 = load ptr, ptr %4, align 8
  ret ptr %69
}

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

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

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"CTRepr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40}
!14 = !{!13, !6, i64 0}
!15 = !{!16, !10, i64 256}
!16 = !{!"global_State", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !17, i64 32, !10, i64 88, !20, i64 92, !21, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !18, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !22, i64 160, !23, i64 184, !10, i64 208, !10, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !18, i64 248, !19, i64 252, !19, i64 256, !7, i64 260}
!17 = !{!"GCState", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !10, i64 12, !18, i64 16, !19, i64 20, !18, i64 24, !18, i64 28, !18, i64 32, !18, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!18 = !{!"GCRef", !10, i64 0}
!19 = !{!"MRef", !10, i64 0}
!20 = !{!"SBuf", !19, i64 0, !19, i64 4, !19, i64 8, !19, i64 12}
!21 = !{!"GCstr", !18, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12}
!22 = !{!"Node", !7, i64 0, !7, i64 8, !19, i64 16, !19, i64 20}
!23 = !{!"GCupval", !18, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !19, i64 16, !10, i64 20}
!24 = !{!13, !6, i64 16}
!25 = !{!13, !6, i64 24}
!26 = !{!13, !10, i64 36}
!27 = !{!13, !10, i64 32}
!28 = !{!21, !10, i64 12}


; 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.CTRepr = type { ptr, ptr, ptr, ptr, i32, i32, [512 x i8] }

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; 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
define hidden ptr @lj_ctype_repr(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.CTRepr, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = inttoptr i64 %7 to ptr
  call void @llvm.lifetime.start.p0(i64 552, ptr nonnull %4) #3
  %9 = getelementptr inbounds i8, ptr %4, i64 296
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !8
  store ptr %9, ptr %4, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %8, i64 256
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = zext i32 %12 to i64
  %14 = inttoptr i64 %13 to ptr
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %14, ptr %15, align 8, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %0, ptr %16, align 8, !tbaa !23
  %17 = getelementptr inbounds i8, ptr %4, i64 36
  store i32 1, ptr %17, align 4, !tbaa !24
  %18 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 0, ptr %18, align 8, !tbaa !25
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %23, label %19

19:                                               ; preds = %3
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = getelementptr inbounds i8, ptr %2, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !26
  call void @ctype_prepstr(ptr noundef nonnull %4, ptr noundef nonnull %20, i32 noundef %22)
  br label %23

23:                                               ; preds = %19, %3
  call void @ctype_repr(ptr noundef nonnull %4, i32 noundef %1)
  %24 = load i32, ptr %17, align 4, !tbaa !24
  %.not10 = icmp eq i32 %24, 0
  br i1 %.not10, label %25, label %27, !prof !27

25:                                               ; preds = %23
  %26 = call ptr @lj_str_new(ptr noundef nonnull %0, ptr noundef nonnull @.str, i64 noundef 1) #3
  br label %34

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !12
  %29 = load ptr, ptr %10, align 8, !tbaa !8
  %30 = ptrtoint ptr %29 to i64
  %31 = ptrtoint ptr %28 to i64
  %32 = sub i64 %30, %31
  %33 = call ptr @lj_str_new(ptr noundef nonnull %0, ptr noundef %28, i64 noundef %32) #3
  br label %34

34:                                               ; preds = %27, %25
  %.0 = phi ptr [ %26, %25 ], [ %33, %27 ]
  call void @llvm.lifetime.end.p0(i64 552, ptr nonnull %4) #3
  ret ptr %.0
}

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

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

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"CTRepr", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 36, !6, i64 40}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!9, !10, i64 0}
!13 = !{!14, !11, i64 256}
!14 = !{!"global_State", !10, i64 0, !11, i64 8, !11, i64 12, !10, i64 16, !10, i64 24, !15, i64 32, !11, i64 88, !18, i64 92, !19, i64 108, !6, i64 124, !6, i64 125, !6, i64 126, !6, i64 127, !16, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !20, i64 160, !21, i64 184, !11, i64 208, !11, i64 212, !10, i64 216, !10, i64 224, !10, i64 232, !11, i64 240, !11, i64 244, !16, i64 248, !17, i64 252, !17, i64 256, !6, i64 260}
!15 = !{!"GCState", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !11, i64 12, !16, i64 16, !17, i64 20, !16, i64 24, !16, i64 28, !16, i64 32, !16, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!16 = !{!"GCRef", !11, i64 0}
!17 = !{!"MRef", !11, i64 0}
!18 = !{!"SBuf", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12}
!19 = !{!"GCstr", !16, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !11, i64 8, !11, i64 12}
!20 = !{!"Node", !6, i64 0, !6, i64 8, !17, i64 16, !17, i64 20}
!21 = !{!"GCupval", !16, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8, !17, i64 16, !11, i64 20}
!22 = !{!9, !10, i64 16}
!23 = !{!9, !10, i64 24}
!24 = !{!9, !11, i64 36}
!25 = !{!9, !11, i64 32}
!26 = !{!19, !11, i64 12}
!27 = !{!"branch_weights", !"expected", i32 1, i32 2000}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass