; LLVM IR from ejoy/ejoy2d :: lua (lcode)

; 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.expdesc = type { i32, %union.anon.1, i32, i32 }
%union.anon.1 = type { double }
%struct.FuncState = type { ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i16, i8, i8, i8 }
%struct.Proto = type { ptr, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define hidden void @luaK_setreturns(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.expdesc, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp eq i32 %9, 13
  br i1 %10, label %11, label %39

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.FuncState, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %struct.Proto, ptr %14, i32 0, i32 15
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.expdesc, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %16, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = and i32 %22, -8372225
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  %26 = shl i32 %25, 14
  %27 = and i32 %26, 8372224
  %28 = or i32 %23, %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.FuncState, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.Proto, ptr %31, i32 0, i32 15
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.expdesc, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %33, i64 %37
  store i32 %28, ptr %38, align 4, !tbaa !9
  br label %103

39:                                               ; preds = %3
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.expdesc, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = icmp eq i32 %42, 14
  br i1 %43, label %44, label %102

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.FuncState, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = getelementptr inbounds %struct.Proto, ptr %47, i32 0, i32 15
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.expdesc, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 8, !tbaa !18
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %49, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = and i32 %55, 8388607
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  %59 = shl i32 %58, 23
  %60 = and i32 %59, -8388608
  %61 = or i32 %56, %60
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.FuncState, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = getelementptr inbounds %struct.Proto, ptr %64, i32 0, i32 15
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.expdesc, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !18
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %66, i64 %70
  store i32 %61, ptr %71, align 4, !tbaa !9
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.FuncState, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !13
  %75 = getelementptr inbounds %struct.Proto, ptr %74, i32 0, i32 15
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.expdesc, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !18
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %76, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = and i32 %82, -16321
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.FuncState, ptr %84, i32 0, i32 13
  %86 = load i8, ptr %85, align 4, !tbaa !19
  %87 = zext i8 %86 to i32
  %88 = shl i32 %87, 6
  %89 = and i32 %88, 16320
  %90 = or i32 %83, %89
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.FuncState, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  %94 = getelementptr inbounds %struct.Proto, ptr %93, i32 0, i32 15
  %95 = load ptr, ptr %94, align 8, !tbaa !16
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.expdesc, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 8, !tbaa !18
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i32, ptr %95, i64 %99
  store i32 %90, ptr %100, align 4, !tbaa !9
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  call void @luaK_reserveregs(ptr noundef %101, i32 noundef 1)
  br label %102

102:                                              ; preds = %44, %39
  br label %103

103:                                              ; preds = %102, %11
  ret void
}

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

!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 = !{!"expdesc", !10, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!14, !6, i64 0}
!14 = !{!"FuncState", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !15, i64 56, !7, i64 58, !7, i64 59, !7, i64 60}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !6, i64 56}
!17 = !{!"Proto", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !7, i64 60}


; 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 @luaK_reserveregs(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden void @luaK_setreturns(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %1, align 8, !tbaa !5
  switch i32 %4, label %42 [
    i32 13, label %5
    i32 14, label %19
  ]

5:                                                ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %6, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !16
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i32, ptr %8, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !17
  %14 = and i32 %13, -8372225
  %15 = shl i32 %2, 14
  %16 = add i32 %15, 16384
  %17 = and i32 %16, 8372224
  %18 = or disjoint i32 %14, %17
  store i32 %18, ptr %12, align 4, !tbaa !17
  br label %42

19:                                               ; preds = %3
  %20 = load ptr, ptr %0, align 8, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %20, i64 56
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %1, i64 8
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %22, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = and i32 %27, 8388607
  %29 = shl i32 %2, 23
  %30 = add i32 %29, 8388608
  %31 = or disjoint i32 %28, %30
  store i32 %31, ptr %26, align 4, !tbaa !17
  %32 = load i32, ptr %23, align 8, !tbaa !16
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %22, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !17
  %36 = and i32 %35, -16321
  %37 = getelementptr inbounds i8, ptr %0, i64 60
  %38 = load i8, ptr %37, align 4, !tbaa !18
  %39 = zext i8 %38 to i32
  %40 = shl nuw nsw i32 %39, 6
  %41 = or disjoint i32 %40, %36
  store i32 %41, ptr %34, align 4, !tbaa !17
  tail call void @luaK_reserveregs(ptr noundef nonnull %0, i32 noundef 1)
  br label %42

42:                                               ; preds = %3, %19, %5
  ret void
}

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

!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 = !{!"expdesc", !7, i64 0, !8, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"FuncState", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !13, i64 56, !8, i64 58, !8, i64 59, !8, i64 60}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!15, !12, i64 56}
!15 = !{!"Proto", !12, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112}
!16 = !{!8, !8, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!11, !8, i64 60}


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