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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_cconv_multi_init(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.CType, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = and i32 %10, -67108864
  %12 = icmp eq i32 %11, 805306368
  br i1 %12, label %20, label %13

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

19:                                               ; preds = %13
  store i32 0, ptr %4, align 4
  br label %58

20:                                               ; preds = %13, %3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = icmp eq i32 %23, -12
  br i1 %24, label %36, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.anon, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = icmp eq i32 %28, -5
  br i1 %29, label %30, label %37

30:                                               ; preds = %25
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.CType, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = lshr i32 %33, 28
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %37, label %36

36:                                               ; preds = %30, %20
  store i32 0, ptr %4, align 4
  br label %58

37:                                               ; preds = %30, %25
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = icmp eq i32 %40, -11
  br i1 %41, label %42, label %57

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.GCRef, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !14
  %48 = zext i32 %47 to i64
  %49 = inttoptr i64 %48 to ptr
  %50 = getelementptr inbounds %struct.GCcdata, ptr %49, i32 0, i32 3
  %51 = load i16, ptr %50, align 2, !tbaa !14
  %52 = zext i16 %51 to i32
  %53 = call ptr @lj_ctype_rawref(ptr noundef %43, i32 noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = icmp eq ptr %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %42
  store i32 0, ptr %4, align 4
  br label %58

57:                                               ; preds = %42, %37
  store i32 1, ptr %4, align 4
  br label %58

58:                                               ; preds = %57, %56, %36, %19
  %59 = load i32, ptr %4, align 4
  ret i32 %59
}

declare hidden ptr @lj_ctype_rawref(ptr noundef, i32 noundef) #1

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 = { "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 = !{!"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 = !{!7, !7, 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
define hidden range(i32 0, 2) i32 @lj_cconv_multi_init(ptr noundef %0, ptr noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = and i32 %4, -67108864
  %6 = icmp eq i32 %5, 805306368
  %.mask = and i32 %4, -268435456
  %7 = icmp eq i32 %.mask, 268435456
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %8, label %21

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  switch i32 %10, label %.thread [
    i32 -12, label %21
    i32 -5, label %11
    i32 -11, label %12
  ]

11:                                               ; preds = %8
  br i1 %7, label %.thread, label %21

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 8, !tbaa !12
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = getelementptr inbounds i8, ptr %15, i64 6
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = zext i16 %17 to i32
  %19 = tail call ptr @lj_ctype_rawref(ptr noundef %0, i32 noundef %18) #2
  %20 = icmp eq ptr %19, %1
  br i1 %20, label %21, label %.thread

.thread:                                          ; preds = %8, %11, %12
  br label %21

21:                                               ; preds = %8, %12, %11, %3, %.thread
  %.0 = phi i32 [ 1, %.thread ], [ 0, %3 ], [ 0, %8 ], [ 0, %11 ], [ 0, %12 ]
  ret i32 %.0
}

declare hidden ptr @lj_ctype_rawref(ptr noundef, i32 noundef) local_unnamed_addr #1

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

!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 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass