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

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_err_unwind_dwarf(i32 noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  store i32 3, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %112

19:                                               ; preds = %5
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load ptr, ptr %11, align 8, !tbaa !11
  %22 = call i64 @_Unwind_GetCFA(ptr noundef %21)
  %23 = inttoptr i64 %22 to ptr
  store ptr %23, ptr %12, align 8, !tbaa !11
  %24 = load ptr, ptr %12, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = getelementptr inbounds %struct.GCRef, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  store ptr %29, ptr %13, align 8, !tbaa !11
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = and i32 %30, 1
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %53

33:                                               ; preds = %19
  %34 = load ptr, ptr %13, align 8, !tbaa !11
  %35 = load ptr, ptr %12, align 8, !tbaa !11
  %36 = call ptr @err_unwind(ptr noundef %34, ptr noundef %35, i32 noundef 0)
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  store i32 8, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %112

39:                                               ; preds = %33
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = xor i64 %40, 5500374307216568832
  %42 = icmp ule i64 %41, 255
  br i1 %42, label %52, label %43

43:                                               ; preds = %39
  %44 = load ptr, ptr %13, align 8, !tbaa !11
  %45 = load ptr, ptr %13, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.anon.5, ptr %46, i32 0, i32 8
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = getelementptr inbounds %union.TValue, ptr %48, i32 1
  store ptr %49, ptr %47, align 8, !tbaa !15
  %50 = load ptr, ptr %13, align 8, !tbaa !11
  %51 = call ptr @lj_err_str(ptr noundef %50, i32 noundef 42)
  call void @setstrV(ptr noundef %44, ptr noundef %48, ptr noundef %51)
  br label %52

52:                                               ; preds = %43, %39
  store i32 6, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %112

53:                                               ; preds = %19
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = and i32 %54, 2
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %111

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = xor i64 %58, 5500374307216568832
  %60 = icmp ule i64 %59, 255
  br i1 %60, label %61, label %65

61:                                               ; preds = %57
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = and i64 %62, 255
  %64 = trunc i64 %63 to i32
  store i32 %64, ptr %15, align 4, !tbaa !5
  br label %72

65:                                               ; preds = %57
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = and i32 %66, 4
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %65
  %70 = load ptr, ptr %10, align 8, !tbaa !11
  call void @_Unwind_DeleteException(ptr noundef %70)
  br label %71

71:                                               ; preds = %69, %65
  store i32 2, ptr %15, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %71, %61
  %73 = load ptr, ptr %13, align 8, !tbaa !11
  %74 = load ptr, ptr %12, align 8, !tbaa !11
  %75 = load i32, ptr %15, align 4, !tbaa !5
  %76 = call ptr @err_unwind(ptr noundef %73, ptr noundef %74, i32 noundef %75)
  store ptr %76, ptr %12, align 8, !tbaa !11
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = and i32 %77, 8
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  store i32 8, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %108

81:                                               ; preds = %72
  %82 = load ptr, ptr %12, align 8, !tbaa !11
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %96

84:                                               ; preds = %81
  %85 = load ptr, ptr %11, align 8, !tbaa !11
  %86 = load i32, ptr %15, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  call void @_Unwind_SetGR(ptr noundef %85, i32 noundef 0, i64 noundef %87)
  %88 = load ptr, ptr %11, align 8, !tbaa !11
  %89 = load ptr, ptr %12, align 8, !tbaa !11
  %90 = ptrtoint ptr %89 to i64
  %91 = and i64 %90, 2
  %92 = icmp ne i64 %91, 0
  %93 = zext i1 %92 to i64
  %94 = select i1 %92, ptr @lj_vm_unwind_ff_eh, ptr @lj_vm_unwind_c_eh
  %95 = ptrtoint ptr %94 to i64
  call void @_Unwind_SetIP(ptr noundef %88, i64 noundef %95)
  store i32 7, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %108

96:                                               ; preds = %81
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = and i32 %97, 4
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %105

100:                                              ; preds = %96
  %101 = load ptr, ptr %11, align 8, !tbaa !11
  %102 = load i32, ptr %15, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  call void @_Unwind_SetGR(ptr noundef %101, i32 noundef 0, i64 noundef %103)
  %104 = load ptr, ptr %11, align 8, !tbaa !11
  call void @_Unwind_SetIP(ptr noundef %104, i64 noundef ptrtoint (ptr @lj_vm_unwind_rethrow to i64))
  store i32 7, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %108

105:                                              ; preds = %96
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106
  store i32 0, ptr %14, align 4
  br label %108

108:                                              ; preds = %107, %100, %84, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  %109 = load i32, ptr %14, align 4
  switch i32 %109, label %112 [
    i32 0, label %110
  ]

110:                                              ; preds = %108
  br label %111

111:                                              ; preds = %110, %53
  store i32 8, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %112

112:                                              ; preds = %111, %108, %52, %38, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %113 = load i32, ptr %6, align 4
  ret i32 %113
}

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

declare i64 @_Unwind_GetCFA(ptr noundef) #2

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

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

; Function Attrs: noinline nounwind uwtable
declare hidden ptr @lj_err_str(ptr noundef, i32 noundef) #4

declare void @_Unwind_DeleteException(ptr noundef) #2

declare void @_Unwind_SetGR(ptr noundef, i32 noundef, i64 noundef) #2

declare void @_Unwind_SetIP(ptr noundef, i64 noundef) #2

declare hidden void @lj_vm_unwind_ff_eh() #2

declare hidden void @lj_vm_unwind_c_eh() #2

declare hidden void @lj_vm_unwind_rethrow() #2

; 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 = { "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 = { 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 #4 = { noinline 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"GCRef", !6, i64 0}
!15 = !{!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 noundef i32 @lj_err_unwind_dwarf(i32 noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 1
  br i1 %.not, label %6, label %.thread

6:                                                ; preds = %5
  %7 = tail call i64 @_Unwind_GetCFA(ptr noundef %4) #4
  %8 = inttoptr i64 %7 to ptr
  %9 = getelementptr inbounds i8, ptr %8, i64 24
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = inttoptr i64 %11 to ptr
  %13 = and i32 %1, 1
  %.not33 = icmp eq i32 %13, 0
  br i1 %.not33, label %25, label %14

14:                                               ; preds = %6
  %15 = tail call ptr @err_unwind(ptr noundef %12, ptr noundef nonnull %8, i32 noundef 0)
  %16 = icmp eq ptr %15, null
  br i1 %16, label %.thread, label %17

17:                                               ; preds = %14
  %18 = xor i64 %2, 5500374307216568832
  %19 = icmp ult i64 %18, 256
  br i1 %19, label %.thread, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %12, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %23, ptr %21, align 8, !tbaa !10
  %24 = tail call ptr @lj_err_str(ptr noundef %12, i32 noundef 42)
  tail call void @setstrV(ptr noundef %12, ptr noundef %22, ptr noundef %24)
  br label %.thread

25:                                               ; preds = %6
  %26 = and i32 %1, 2
  %.not34 = icmp eq i32 %26, 0
  br i1 %.not34, label %.thread, label %27

27:                                               ; preds = %25
  %28 = xor i64 %2, 5500374307216568832
  %29 = icmp ult i64 %28, 256
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = trunc i64 %2 to i32
  %32 = and i32 %31, 255
  br label %36

33:                                               ; preds = %27
  %34 = and i32 %1, 4
  %.not35 = icmp eq i32 %34, 0
  br i1 %.not35, label %36, label %35

35:                                               ; preds = %33
  tail call void @_Unwind_DeleteException(ptr noundef %3) #4
  br label %36

36:                                               ; preds = %33, %35, %30
  %.0 = phi i32 [ %32, %30 ], [ 2, %35 ], [ 2, %33 ]
  %37 = tail call ptr @err_unwind(ptr noundef %12, ptr noundef nonnull %8, i32 noundef %.0)
  %38 = and i32 %1, 8
  %.not36 = icmp eq i32 %38, 0
  br i1 %.not36, label %39, label %.thread

39:                                               ; preds = %36
  %.not37 = icmp eq ptr %37, null
  br i1 %.not37, label %45, label %40

40:                                               ; preds = %39
  %41 = zext nneg i32 %.0 to i64
  tail call void @_Unwind_SetGR(ptr noundef %4, i32 noundef 0, i64 noundef %41) #4
  %42 = ptrtoint ptr %37 to i64
  %43 = and i64 %42, 2
  %.not39 = icmp eq i64 %43, 0
  %44 = select i1 %.not39, i64 ptrtoint (ptr @lj_vm_unwind_c_eh to i64), i64 ptrtoint (ptr @lj_vm_unwind_ff_eh to i64)
  tail call void @_Unwind_SetIP(ptr noundef %4, i64 noundef %44) #4
  br label %.thread

45:                                               ; preds = %39
  %46 = and i32 %1, 4
  %.not38 = icmp eq i32 %46, 0
  br i1 %.not38, label %.thread, label %47

47:                                               ; preds = %45
  %48 = zext nneg i32 %.0 to i64
  tail call void @_Unwind_SetGR(ptr noundef %4, i32 noundef 0, i64 noundef %48) #4
  tail call void @_Unwind_SetIP(ptr noundef %4, i64 noundef ptrtoint (ptr @lj_vm_unwind_rethrow to i64)) #4
  br label %.thread

.thread:                                          ; preds = %36, %47, %40, %25, %45, %17, %20, %14, %5
  %.1 = phi i32 [ 3, %5 ], [ 8, %14 ], [ 6, %20 ], [ 6, %17 ], [ 8, %45 ], [ 8, %25 ], [ 8, %36 ], [ 7, %47 ], [ 7, %40 ]
  ret i32 %.1
}

declare i64 @_Unwind_GetCFA(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setstrV(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @_Unwind_DeleteException(ptr noundef) local_unnamed_addr #1

declare void @_Unwind_SetGR(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare void @_Unwind_SetIP(ptr noundef, i64 noundef) local_unnamed_addr #1

declare hidden void @lj_vm_unwind_ff_eh() #1

declare hidden void @lj_vm_unwind_c_eh() #1

declare hidden void @lj_vm_unwind_rethrow() #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 = { 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 = { noinline 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 }

!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 = !{!"GCRef", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


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