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

; 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.lua_State = type { %union.anon }
%union.anon = type { %struct.anon, [320 x i8] }
%struct.anon = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.GCRef = type { i32 }
%union.TValue = type { i64 }
%struct.anon.0 = type { %union.anon.1, i32 }
%union.anon.1 = type { %struct.GCRef }

@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @luaL_fileresult(ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @luaL_execresult(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %60

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = and i32 %9, 127
  %11 = add nsw i32 %10, 1
  %12 = trunc i32 %11 to i8
  %13 = sext i8 %12 to i32
  %14 = ashr i32 %13, 1
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %8
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = and i32 %17, 127
  store i32 %18, ptr %5, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.lua_State, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 8
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %union.TValue, ptr %22, i32 1
  store ptr %23, ptr %21, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.anon.0, ptr %22, i32 0, i32 1
  store i32 -1, ptr %24, align 4, !tbaa !11
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lua_pushlstring(ptr noundef %25, ptr noundef @.str.2, i64 noundef 6)
  br label %53

26:                                               ; preds = %8
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = and i32 %27, 127
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %34

30:                                               ; preds = %26
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = and i32 %31, 65280
  %33 = ashr i32 %32, 8
  store i32 %33, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %30, %26
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %44

37:                                               ; preds = %34
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.lua_State, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 8
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %union.TValue, ptr %41, i32 1
  store ptr %42, ptr %40, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.anon.0, ptr %41, i32 0, i32 1
  store i32 -3, ptr %43, align 4, !tbaa !11
  br label %51

44:                                               ; preds = %34
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.anon, ptr %46, i32 0, i32 8
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds %union.TValue, ptr %48, i32 1
  store ptr %49, ptr %47, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.anon.0, ptr %48, i32 0, i32 1
  store i32 -1, ptr %50, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %44, %37
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lua_pushlstring(ptr noundef %52, ptr noundef @.str.3, i64 noundef 4)
  br label %53

53:                                               ; preds = %51, %16
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.lua_State, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds %struct.anon, ptr %55, i32 0, i32 8
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %union.TValue, ptr %57, i32 1
  store ptr %58, ptr %56, align 8, !tbaa !11
  %59 = load i32, ptr %5, align 4, !tbaa !9
  call void @setintV(ptr noundef %57, i32 noundef %59)
  store i32 3, ptr %3, align 4
  br label %63

60:                                               ; preds = %2
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = call i32 @luaL_fileresult(ptr noundef %61, i32 noundef 0, ptr noundef null)
  store i32 %62, ptr %3, align 4
  br label %63

63:                                               ; preds = %60, %53
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

declare void @lua_pushlstring(ptr noundef, ptr noundef, i64 noundef) #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" }

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

@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @luaL_fileresult(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @luaL_execresult(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, -1
  br i1 %.not, label %25, label %3

3:                                                ; preds = %2
  %4 = and i32 %1, 127
  %5 = shl nuw nsw i32 %4, 24
  %sext = add nuw i32 %5, 16777216
  %6 = icmp sgt i32 %sext, 33554431
  br i1 %6, label %7, label %12

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %10, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %9, i64 4
  store i32 -1, ptr %11, align 4, !tbaa !5
  tail call void @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.2, i64 noundef 6) #3
  br label %21

12:                                               ; preds = %3
  %13 = icmp eq i32 %4, 0
  %14 = lshr i32 %1, 8
  %15 = and i32 %14, 255
  %.0 = select i1 %13, i32 %15, i32 %1
  %16 = icmp eq i32 %.0, 0
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %19, ptr %17, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %18, i64 4
  %. = select i1 %16, i32 -3, i32 -1
  store i32 %., ptr %20, align 4, !tbaa !5
  tail call void @lua_pushlstring(ptr noundef nonnull %0, ptr noundef nonnull @.str.3, i64 noundef 4) #3
  br label %21

21:                                               ; preds = %12, %7
  %.1 = phi i32 [ %4, %7 ], [ %.0, %12 ]
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %24, ptr %22, align 8, !tbaa !5
  tail call void @setintV(ptr noundef %23, i32 noundef %.1)
  br label %27

25:                                               ; preds = %2
  %26 = tail call i32 @luaL_fileresult(ptr noundef %0, i32 noundef 0, ptr noundef null)
  br label %27

27:                                               ; preds = %25, %21
  %.014 = phi i32 [ 3, %21 ], [ %26, %25 ]
  ret i32 %.014
}

declare void @lua_pushlstring(ptr noundef, ptr noundef, i64 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"}


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