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

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ccall_ctid_vararg(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.anon, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp ule i32 %11, -65537
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 14, ptr %3, align 4
  br label %98

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, -11
  br i1 %18, label %19, label %80

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.GCRef, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  %26 = getelementptr inbounds %struct.GCcdata, ptr %25, i32 0, i32 3
  %27 = load i16, ptr %26, align 2, !tbaa !9
  %28 = zext i16 %27 to i32
  store i32 %28, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !10
  %31 = call ptr @ctype_get(ptr noundef %29, i32 noundef %30)
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CType, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !12
  %35 = and i32 %34, -67108864
  %36 = icmp eq i32 %35, 805306368
  br i1 %36, label %37, label %46

37:                                               ; preds = %19
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.CType, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = and i32 %41, 65535
  %43 = or i32 196608, %42
  %44 = add i32 536870912, %43
  %45 = call i32 @lj_ctype_intern(ptr noundef %38, i32 noundef %44, i32 noundef 8)
  store i32 %45, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

46:                                               ; preds = %19
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.CType, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = lshr i32 %49, 28
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %58, label %52

52:                                               ; preds = %46
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CType, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %56 = lshr i32 %55, 28
  %57 = icmp eq i32 %56, 6
  br i1 %57, label %58, label %64

58:                                               ; preds = %52, %46
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !10
  %61 = or i32 196608, %60
  %62 = add i32 536870912, %61
  %63 = call i32 @lj_ctype_intern(ptr noundef %59, i32 noundef %62, i32 noundef 8)
  store i32 %63, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

64:                                               ; preds = %52
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.CType, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 4, !tbaa !12
  %68 = and i32 %67, -201326592
  %69 = icmp eq i32 %68, 67108864
  br i1 %69, label %70, label %77

70:                                               ; preds = %64
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.CType, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !16
  %74 = zext i32 %73 to i64
  %75 = icmp eq i64 %74, 4
  br i1 %75, label %76, label %77

76:                                               ; preds = %70
  store i32 14, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

77:                                               ; preds = %70, %64
  %78 = load i32, ptr %6, align 4, !tbaa !10
  store i32 %78, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

79:                                               ; preds = %77, %76, %58, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %98

80:                                               ; preds = %14
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.anon, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = icmp eq i32 %83, -5
  br i1 %84, label %85, label %86

85:                                               ; preds = %80
  store i32 19, ptr %3, align 4
  br label %98

86:                                               ; preds = %80
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.anon, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = icmp eq i32 %89, -2
  br i1 %90, label %96, label %91

91:                                               ; preds = %86
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.anon, ptr %92, i32 0, i32 1
  %94 = load i32, ptr %93, align 4, !tbaa !9
  %95 = icmp eq i32 %94, -3
  br i1 %95, label %96, label %97

96:                                               ; preds = %91, %86
  store i32 3, ptr %3, align 4
  br label %98

97:                                               ; preds = %91
  store i32 17, ptr %3, align 4
  br label %98

98:                                               ; preds = %97, %96, %85, %79, %13
  %99 = load i32, ptr %3, align 4
  ret i32 %99
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"CType", !11, i64 0, !11, i64 4, !14, i64 8, !14, i64 10, !15, i64 12}
!14 = !{!"short", !7, i64 0}
!15 = !{!"GCRef", !11, i64 0}
!16 = !{!13, !11, i64 4}


; 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 i32 @lj_ccall_ctid_vararg(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp ult i32 %4, -65536
  br i1 %5, label %37, label %6

6:                                                ; preds = %2
  %trunc = trunc i32 %4 to i16
  switch i16 %trunc, label %36 [
    i16 -11, label %7
    i16 -5, label %37
    i16 -2, label %35
    i16 -3, label %35
  ]

7:                                                ; preds = %6
  %8 = load i32, ptr %1, align 8, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = getelementptr inbounds i8, ptr %10, i64 6
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %13)
  %15 = load i32, ptr %14, align 4, !tbaa !8
  %16 = and i32 %15, -67108864
  %17 = icmp eq i32 %16, 805306368
  br i1 %17, label %18, label %22

18:                                               ; preds = %7
  %19 = and i32 %15, 65535
  %20 = or disjoint i32 %19, 537067520
  %21 = tail call i32 @lj_ctype_intern(ptr noundef %0, i32 noundef %20, i32 noundef 8) #3
  br label %37

22:                                               ; preds = %7
  %23 = lshr i32 %15, 28
  switch i32 %23, label %27 [
    i32 1, label %24
    i32 6, label %24
  ]

24:                                               ; preds = %22, %22
  %25 = or disjoint i32 %13, 537067520
  %26 = tail call i32 @lj_ctype_intern(ptr noundef %0, i32 noundef %25, i32 noundef 8) #3
  br label %37

27:                                               ; preds = %22
  %28 = and i32 %15, -201326592
  %29 = icmp eq i32 %28, 67108864
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %14, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !13
  %33 = icmp eq i32 %32, 4
  br i1 %33, label %37, label %34

34:                                               ; preds = %30, %27
  br label %37

35:                                               ; preds = %6, %6
  br label %37

36:                                               ; preds = %6
  br label %37

37:                                               ; preds = %6, %18, %24, %34, %30, %2, %36, %35
  %.1 = phi i32 [ 3, %35 ], [ 17, %36 ], [ 14, %2 ], [ %21, %18 ], [ %26, %24 ], [ %13, %34 ], [ 14, %30 ], [ 19, %6 ]
  ret i32 %.1
}

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

declare hidden i32 @lj_ctype_intern(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 = { 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 = { "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 0}
!9 = !{!"CType", !10, i64 0, !10, i64 4, !11, i64 8, !11, i64 10, !12, i64 12}
!10 = !{!"int", !6, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = !{!"GCRef", !10, i64 0}
!13 = !{!9, !10, i64 4}


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