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

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_clib_index(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CLibrary, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call ptr @lj_tab_setstr(ptr noundef %15, ptr noundef %18, ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp eq i32 %23, -1
  %25 = xor i1 %24, true
  %26 = xor i1 %25, true
  %27 = zext i1 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = call i64 @llvm.expect.i64(i64 %28, i64 0)
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %98

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call ptr @ctype_cts(ptr noundef %32)
  store ptr %33, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call i32 @lj_ctype_getname(ptr noundef %34, ptr noundef %9, ptr noundef %35, i32 noundef 6208)
  store i32 %36, ptr %10, align 4, !tbaa !12
  %37 = load i32, ptr %10, align 4, !tbaa !12
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %43, label %39

39:                                               ; preds = %31
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.GCstr, ptr %41, i64 1
  call void (ptr, i32, ...) @lj_err_callerv(ptr noundef %40, i32 noundef 3619, ptr noundef %42) #8
  unreachable

43:                                               ; preds = %31
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CType, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = lshr i32 %46, 28
  %48 = icmp eq i32 %47, 11
  br i1 %48, label %49, label %75

49:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = call ptr @ctype_child(ptr noundef %50, ptr noundef %51)
  store ptr %52, ptr %11, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CType, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !14
  %56 = and i32 %55, 8388608
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %69

58:                                               ; preds = %49
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.CType, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !18
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %69

63:                                               ; preds = %58
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.CType, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !18
  %67 = uitofp i32 %66 to double
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  store double %67, ptr %68, align 8, !tbaa !11
  br label %74

69:                                               ; preds = %58, %49
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.CType, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !18
  call void @setintV(ptr noundef %70, i32 noundef %73)
  br label %74

74:                                               ; preds = %69, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %97

75:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = call ptr @clib_extsym(ptr noundef %76, ptr noundef %77, ptr noundef %78)
  store ptr %79, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = call ptr @clib_getsym(ptr noundef %80, ptr noundef %81)
  store ptr %82, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %87, label %85

85:                                               ; preds = %75
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  call void @clib_error_(ptr noundef %86) #8
  unreachable

87:                                               ; preds = %75
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %10, align 4, !tbaa !12
  %90 = call ptr @lj_cdata_new(ptr noundef %88, i32 noundef %89, i32 noundef 8)
  store ptr %90, ptr %14, align 8, !tbaa !5
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = load ptr, ptr %14, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.GCcdata, ptr %92, i64 1
  store ptr %91, ptr %93, align 8, !tbaa !5
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  call void @setcdataV(ptr noundef %94, ptr noundef %95, ptr noundef %96)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %97

97:                                               ; preds = %87, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %98

98:                                               ; preds = %97, %3
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  ret ptr %99
}

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

declare hidden ptr @lj_tab_setstr(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @ctype_cts(ptr noundef) #4

declare hidden i32 @lj_ctype_getname(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: noreturn
declare hidden void @lj_err_callerv(ptr noundef, i32 noundef, ...) #5

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @ctype_child(ptr noundef, ptr noundef) #4

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

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

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

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

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @clib_error_(ptr noundef) #6

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { 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 #5 = { 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 #6 = { noinline noreturn 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 #7 = { nounwind }
attributes #8 = { 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, !6, i64 8}
!10 = !{!"CLibrary", !6, i64 0, !6, i64 8}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"CType", !13, i64 0, !13, i64 4, !16, i64 8, !16, i64 10, !17, i64 12}
!16 = !{!"short", !7, i64 0}
!17 = !{!"GCRef", !13, i64 0}
!18 = !{!15, !13, 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 ptr @lj_clib_index(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @lj_tab_setstr(ptr noundef %0, ptr noundef %6, ptr noundef %2) #6
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %35, !prof !11

11:                                               ; preds = %3
  %12 = tail call ptr @ctype_cts(ptr noundef %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %13 = call i32 @lj_ctype_getname(ptr noundef %12, ptr noundef nonnull %4, ptr noundef %2, i32 noundef 6208) #6
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %16

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %2, i64 16
  call void (ptr, i32, ...) @lj_err_callerv(ptr noundef %0, i32 noundef 3619, ptr noundef nonnull %15) #7
  unreachable

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !12
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %.mask = and i32 %18, -268435456
  %19 = icmp eq i32 %.mask, -1342177280
  br i1 %19, label %20, label %27

20:                                               ; preds = %16
  %21 = call ptr @ctype_child(ptr noundef %12, ptr noundef nonnull %17)
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = and i32 %22, 8388608
  %.not30 = icmp ne i32 %23, 0
  %.pre = load ptr, ptr %4, align 8, !tbaa !12
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 4
  %.pre31 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !18
  %24 = icmp slt i32 %.pre31, 0
  %or.cond = select i1 %.not30, i1 %24, i1 false
  br i1 %or.cond, label %25, label %._crit_edge

25:                                               ; preds = %20
  %26 = uitofp i32 %.pre31 to double
  store double %26, ptr %7, align 8, !tbaa !10
  br label %34

._crit_edge:                                      ; preds = %20
  call void @setintV(ptr noundef nonnull %7, i32 noundef %.pre31)
  br label %34

27:                                               ; preds = %16
  %28 = call ptr @clib_extsym(ptr noundef %12, ptr noundef nonnull %17, ptr noundef %2)
  %29 = call ptr @clib_getsym(ptr noundef nonnull %1, ptr noundef %28)
  %.not29 = icmp eq ptr %29, null
  br i1 %.not29, label %30, label %31

30:                                               ; preds = %27
  call void @clib_error_(ptr noundef %0) #8
  unreachable

31:                                               ; preds = %27
  %32 = call ptr @lj_cdata_new(ptr noundef %12, i32 noundef %13, i32 noundef 8)
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  store ptr %29, ptr %33, align 8, !tbaa !12
  call void @setcdataV(ptr noundef %0, ptr noundef nonnull %7, ptr noundef %32)
  br label %34

34:                                               ; preds = %25, %._crit_edge, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %35

35:                                               ; preds = %34, %3
  ret ptr %7
}

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

declare hidden ptr @lj_tab_setstr(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @ctype_cts(ptr noundef) local_unnamed_addr #3

declare hidden i32 @lj_ctype_getname(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: noreturn
declare hidden void @lj_err_callerv(ptr noundef, i32 noundef, ...) local_unnamed_addr #4

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

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

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

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

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

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @clib_error_(ptr noundef) local_unnamed_addr #5

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

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

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 = { mustprogress 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 = { 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 #5 = { noinline noreturn 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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, !7, i64 8}
!6 = !{!"CLibrary", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"CType", !15, i64 0, !15, i64 4, !16, i64 8, !16, i64 10, !17, i64 12}
!15 = !{!"int", !8, i64 0}
!16 = !{!"short", !8, i64 0}
!17 = !{!"GCRef", !15, i64 0}
!18 = !{!14, !15, i64 4}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass