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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

23:                                               ; preds = %5
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = and i32 %24, -134217728
  %26 = icmp eq i32 %25, 134217728
  br i1 %26, label %44, label %27

27:                                               ; preds = %23
  %28 = load i32, ptr %12, align 4, !tbaa !9
  %29 = and i32 %28, -67108864
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %27
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CType, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = icmp ugt i32 %34, 4
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %92

37:                                               ; preds = %31, %27
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call ptr @ctype_get(ptr noundef %39, i32 noundef 14)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  call void @lj_cconv_ct_ct(ptr noundef %38, ptr noundef %40, ptr noundef %41, ptr noundef %42, ptr noundef %43, i32 noundef 0)
  br label %73

44:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.CType, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %44
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !16
  %52 = zext i8 %51 to i32
  %53 = icmp ne i32 %52, 0
  %54 = zext i1 %53 to i32
  br label %60

55:                                               ; preds = %44
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  %59 = zext i1 %58 to i32
  br label %60

60:                                               ; preds = %55, %49
  %61 = phi i32 [ %54, %49 ], [ %59, %55 ]
  store i32 %61, ptr %13, align 4, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = sub i32 -2, %62
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 1
  store i32 %63, ptr %65, align 4, !tbaa !16
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = sub i32 -2, %66
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.CTState, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = getelementptr inbounds %struct.global_State, ptr %70, i32 0, i32 16
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 1
  store i32 %67, ptr %72, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %73

73:                                               ; preds = %60, %37
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %118

74:                                               ; preds = %5
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = and i32 %75, -67108864
  %77 = icmp eq i32 %76, 805306368
  br i1 %77, label %82, label %78

78:                                               ; preds = %74
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = lshr i32 %79, 28
  %81 = icmp eq i32 %80, 1
  br i1 %81, label %82, label %91

82:                                               ; preds = %78, %74
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.CTState, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = call ptr @lj_cdata_newref(ptr noundef %87, ptr noundef %88, i32 noundef %89)
  call void @setcdataV(ptr noundef %85, ptr noundef %86, ptr noundef %90)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %118

91:                                               ; preds = %78
  br label %92

92:                                               ; preds = %91, %36
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.CType, ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 4, !tbaa !15
  store i32 %95, ptr %16, align 4, !tbaa !9
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.CTState, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !21
  %101 = ptrtoint ptr %97 to i64
  %102 = ptrtoint ptr %100 to i64
  %103 = sub i64 %101, %102
  %104 = sdiv exact i64 %103, 16
  %105 = trunc i64 %104 to i32
  %106 = load i32, ptr %16, align 4, !tbaa !9
  %107 = call ptr @lj_cdata_new(ptr noundef %96, i32 noundef %105, i32 noundef %106)
  store ptr %107, ptr %15, align 8, !tbaa !5
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.CTState, ptr %108, i32 0, i32 3
  %110 = load ptr, ptr %109, align 8, !tbaa !20
  %111 = load ptr, ptr %10, align 8, !tbaa !5
  %112 = load ptr, ptr %15, align 8, !tbaa !5
  call void @setcdataV(ptr noundef %110, ptr noundef %111, ptr noundef %112)
  %113 = load ptr, ptr %15, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.GCcdata, ptr %113, i64 1
  %115 = load ptr, ptr %11, align 8, !tbaa !5
  %116 = load i32, ptr %16, align 4, !tbaa !9
  %117 = zext i32 %116 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %114, ptr align 1 %115, i64 %117, i1 false)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %118

118:                                              ; preds = %92, %82, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %119 = load i32, ptr %6, align 4
  ret i32 %119
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setcdataV(ptr noundef, ptr noundef, ptr noundef) #3

declare hidden ptr @lj_cdata_newref(ptr noundef, ptr noundef, i32 noundef) #4

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

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 #5 = { 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 = !{!12, !10, i64 4}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !6, i64 24}
!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 16}
!21 = !{!18, !6, 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"

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define hidden range(i32 0, 2) i32 @lj_cconv_tv_ct(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 268435456
  br i1 %7, label %8, label %33

8:                                                ; preds = %5
  %.not = icmp ult i32 %6, 134217728
  br i1 %.not, label %9, label %17

9:                                                ; preds = %8
  %10 = icmp ult i32 %6, 67108864
  br i1 %10, label %11, label %15

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = icmp ugt i32 %13, 4
  br i1 %14, label %41, label %15

15:                                               ; preds = %11, %9
  %16 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef 14)
  tail call void @lj_cconv_ct_ct(ptr noundef %0, ptr noundef %16, ptr noundef nonnull %1, ptr noundef %3, ptr noundef %4, i32 noundef 0)
  br label %54

17:                                               ; preds = %8
  %18 = getelementptr inbounds i8, ptr %1, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = load i8, ptr %4, align 1, !tbaa !13
  %23 = icmp ne i8 %22, 0
  br label %27

24:                                               ; preds = %17
  %25 = load i32, ptr %4, align 4, !tbaa !14
  %26 = icmp ne i32 %25, 0
  br label %27

27:                                               ; preds = %24, %21
  %.in = phi i1 [ %23, %21 ], [ %26, %24 ]
  %28 = select i1 %.in, i32 -3, i32 -2
  %29 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %28, ptr %29, align 4, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %31, i64 156
  store i32 %28, ptr %32, align 4, !tbaa !13
  br label %54

33:                                               ; preds = %5
  %34 = and i32 %6, -67108864
  %35 = icmp eq i32 %34, 805306368
  %.mask = and i32 %6, -268435456
  %36 = icmp eq i32 %.mask, 268435456
  %or.cond = or i1 %35, %36
  br i1 %or.cond, label %37, label %._crit_edge

._crit_edge:                                      ; preds = %33
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !12
  br label %41

37:                                               ; preds = %33
  %38 = getelementptr inbounds i8, ptr %0, i64 16
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = tail call ptr @lj_cdata_newref(ptr noundef %0, ptr noundef %4, i32 noundef %2) #4
  tail call void @setcdataV(ptr noundef %39, ptr noundef %3, ptr noundef %40)
  br label %54

41:                                               ; preds = %._crit_edge, %11
  %42 = phi i32 [ %.pre, %._crit_edge ], [ %13, %11 ]
  %43 = load ptr, ptr %0, align 8, !tbaa !20
  %44 = ptrtoint ptr %1 to i64
  %45 = ptrtoint ptr %43 to i64
  %46 = sub i64 %44, %45
  %47 = lshr exact i64 %46, 4
  %48 = trunc i64 %47 to i32
  %49 = tail call ptr @lj_cdata_new(ptr noundef nonnull %0, i32 noundef %48, i32 noundef %42)
  %50 = getelementptr inbounds i8, ptr %0, i64 16
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  tail call void @setcdataV(ptr noundef %51, ptr noundef %3, ptr noundef %49)
  %52 = getelementptr inbounds i8, ptr %49, i64 8
  %53 = zext i32 %42 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %52, ptr align 1 %4, i64 %53, i1 false)
  br label %54

54:                                               ; preds = %15, %27, %41, %37
  %.0 = phi i32 [ 1, %41 ], [ 1, %37 ], [ 0, %27 ], [ 0, %15 ]
  ret i32 %.0
}

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

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

declare hidden ptr @lj_cdata_newref(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

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


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