; 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.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 }

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

; Function Attrs: noreturn
declare hidden void @lj_err_caller(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define hidden void @lj_cconv_bf_tv(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %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 i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CType, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %19 = load i32, ptr %9, align 4, !tbaa !14
  %20 = and i32 %19, 134217728
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call ptr @ctype_get(ptr noundef %24, i32 noundef 3)
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  call void @lj_cconv_ct_tv(ptr noundef %23, ptr noundef %25, ptr noundef %14, ptr noundef %26, i32 noundef 0)
  %27 = load i8, ptr %14, align 1, !tbaa !15
  %28 = zext i8 %27 to i32
  store i32 %28, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #4
  br label %40

29:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %30 = load i32, ptr %9, align 4, !tbaa !14
  %31 = and i32 %30, 8388608
  %32 = icmp ne i32 %31, 0
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 10, i32 9
  store i32 %34, ptr %15, align 4, !tbaa !14
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %15, align 4, !tbaa !14
  %38 = call ptr @ctype_get(ptr noundef %36, i32 noundef %37)
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  call void @lj_cconv_ct_tv(ptr noundef %35, ptr noundef %38, ptr noundef %12, ptr noundef %39, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %40

40:                                               ; preds = %29, %22
  %41 = load i32, ptr %9, align 4, !tbaa !14
  %42 = lshr i32 %41, 0
  %43 = and i32 %42, 127
  store i32 %43, ptr %10, align 4, !tbaa !14
  %44 = load i32, ptr %9, align 4, !tbaa !14
  %45 = lshr i32 %44, 8
  %46 = and i32 %45, 127
  store i32 %46, ptr %11, align 4, !tbaa !14
  %47 = load i32, ptr %10, align 4, !tbaa !14
  %48 = load i32, ptr %11, align 4, !tbaa !14
  %49 = add i32 %47, %48
  %50 = load i32, ptr %9, align 4, !tbaa !14
  %51 = lshr i32 %50, 16
  %52 = and i32 %51, 127
  %53 = mul i32 8, %52
  %54 = icmp ugt i32 %49, %53
  br i1 %54, label %55, label %59

55:                                               ; preds = %40
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.CTState, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  call void @lj_err_caller(ptr noundef %58, i32 noundef 3687) #5
  unreachable

59:                                               ; preds = %40
  %60 = load i32, ptr %11, align 4, !tbaa !14
  %61 = shl i32 1, %60
  %62 = sub i32 %61, 1
  %63 = load i32, ptr %10, align 4, !tbaa !14
  %64 = shl i32 %62, %63
  store i32 %64, ptr %13, align 4, !tbaa !14
  %65 = load i32, ptr %12, align 4, !tbaa !14
  %66 = load i32, ptr %10, align 4, !tbaa !14
  %67 = shl i32 %65, %66
  %68 = load i32, ptr %13, align 4, !tbaa !14
  %69 = and i32 %67, %68
  store i32 %69, ptr %12, align 4, !tbaa !14
  %70 = load i32, ptr %9, align 4, !tbaa !14
  %71 = lshr i32 %70, 16
  %72 = and i32 %71, 127
  switch i32 %72, label %108 [
    i32 4, label %73
    i32 2, label %82
    i32 1, label %95
  ]

73:                                               ; preds = %59
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %74, align 4, !tbaa !14
  %76 = load i32, ptr %13, align 4, !tbaa !14
  %77 = xor i32 %76, -1
  %78 = and i32 %75, %77
  %79 = load i32, ptr %12, align 4, !tbaa !14
  %80 = or i32 %78, %79
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %80, ptr %81, align 4, !tbaa !14
  br label %109

82:                                               ; preds = %59
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = load i16, ptr %83, align 2, !tbaa !19
  %85 = zext i16 %84 to i32
  %86 = load i32, ptr %13, align 4, !tbaa !14
  %87 = xor i32 %86, -1
  %88 = and i32 %85, %87
  %89 = load i32, ptr %12, align 4, !tbaa !14
  %90 = trunc i32 %89 to i16
  %91 = zext i16 %90 to i32
  %92 = or i32 %88, %91
  %93 = trunc i32 %92 to i16
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 %93, ptr %94, align 2, !tbaa !19
  br label %109

95:                                               ; preds = %59
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load i8, ptr %96, align 1, !tbaa !15
  %98 = zext i8 %97 to i32
  %99 = load i32, ptr %13, align 4, !tbaa !14
  %100 = xor i32 %99, -1
  %101 = and i32 %98, %100
  %102 = load i32, ptr %12, align 4, !tbaa !14
  %103 = trunc i32 %102 to i8
  %104 = zext i8 %103 to i32
  %105 = or i32 %101, %104
  %106 = trunc i32 %105 to i8
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 %106, ptr %107, align 1, !tbaa !15
  br label %109

108:                                              ; preds = %59
  br label %109

109:                                              ; preds = %108, %95, %82, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

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 = { noreturn "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 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 = { nounwind }
attributes #5 = { noreturn }

!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 = !{!11, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !6, i64 16}
!17 = !{!"CTState", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !18, i64 48, !7, i64 216}
!18 = !{!"CCallback", !7, i64 0, !7, i64 64, !6, i64 128, !6, i64 136, !6, i64 144, !11, i64 152, !11, i64 156, !11, i64 160}
!19 = !{!12, !12, 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: 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: alwaysinline nounwind uwtable
declare hidden ptr @ctype_get(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare hidden void @lj_err_caller(ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define hidden void @lj_cconv_bf_tv(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %8 = and i32 %7, 134217728
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %13, label %9

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #4
  %10 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef 3)
  call void @lj_cconv_ct_tv(ptr noundef %0, ptr noundef %10, ptr noundef nonnull %6, ptr noundef %3, i32 noundef 0)
  %11 = load i8, ptr %6, align 1, !tbaa !12
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #4
  br label %17

13:                                               ; preds = %4
  %14 = and i32 %7, 8388608
  %.not29 = icmp eq i32 %14, 0
  %15 = select i1 %.not29, i32 9, i32 10
  %16 = tail call ptr @ctype_get(ptr noundef %0, i32 noundef %15)
  call void @lj_cconv_ct_tv(ptr noundef %0, ptr noundef %16, ptr noundef nonnull %5, ptr noundef %3, i32 noundef 0)
  br label %17

17:                                               ; preds = %13, %9
  %18 = and i32 %7, 127
  %19 = lshr i32 %7, 8
  %20 = and i32 %19, 127
  %21 = add nuw nsw i32 %20, %18
  %22 = lshr i32 %7, 16
  %23 = and i32 %22, 127
  %24 = shl nuw nsw i32 %23, 3
  %25 = icmp ugt i32 %21, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %17
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  call void @lj_err_caller(ptr noundef %28, i32 noundef 3687) #5
  unreachable

29:                                               ; preds = %17
  %notmask = shl nsw i32 -1, %20
  %30 = xor i32 %notmask, -1
  %31 = shl i32 %30, %18
  %32 = load i32, ptr %5, align 4, !tbaa !13
  %33 = and i32 %32, %30
  %34 = shl i32 %33, %18
  switch i32 %23, label %54 [
    i32 4, label %35
    i32 2, label %40
    i32 1, label %47
  ]

35:                                               ; preds = %29
  %36 = load i32, ptr %2, align 4, !tbaa !13
  %37 = xor i32 %31, -1
  %38 = and i32 %36, %37
  %39 = or i32 %38, %34
  store i32 %39, ptr %2, align 4, !tbaa !13
  br label %54

40:                                               ; preds = %29
  %41 = load i16, ptr %2, align 2, !tbaa !18
  %42 = zext i16 %41 to i32
  %43 = xor i32 %31, -1
  %44 = and i32 %42, %43
  %45 = or i32 %44, %34
  %46 = trunc i32 %45 to i16
  store i16 %46, ptr %2, align 2, !tbaa !18
  br label %54

47:                                               ; preds = %29
  %48 = load i8, ptr %2, align 1, !tbaa !12
  %49 = zext i8 %48 to i32
  %50 = xor i32 %31, -1
  %51 = and i32 %49, %50
  %52 = or i32 %51, %34
  %53 = trunc i32 %52 to i8
  store i8 %53, ptr %2, align 1, !tbaa !12
  br label %54

54:                                               ; preds = %29, %47, %40, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  ret void
}

attributes #0 = { mustprogress 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 = { noreturn "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 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 = { nounwind }
attributes #5 = { noreturn 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}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 16}
!15 = !{!"CTState", !16, i64 0, !7, i64 8, !7, i64 12, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !17, i64 48, !8, i64 216}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"CCallback", !8, i64 0, !8, i64 64, !16, i64 128, !16, i64 136, !16, i64 144, !7, i64 152, !7, i64 156, !7, i64 160}
!18 = !{!10, !10, i64 0}


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