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

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

@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [10 x i8], align 1

; 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: nounwind uwtable
define dso_local ptr @hack_gemcore(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store ptr null, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call ptr @strstr(ptr noundef %13, ptr noundef @.str.6) #8
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %109

17:                                               ; preds = %2
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = mul i64 %18, 2
  %20 = add i64 %19, 32
  %21 = call noalias ptr @malloc(i64 noundef %20) #9
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = mul i64 %23, 2
  %25 = add i64 %24, 32
  call void @llvm.memset.p0.i64(ptr align 1 %22, i8 0, i64 %25, i1 false)
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %26, ptr %10, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %92, %59, %17
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @strstr(ptr noundef %28, ptr noundef @.str.7) #8
  store ptr %29, ptr %9, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %39, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = call ptr @strstr(ptr noundef %32, ptr noundef @.str.8) #8
  store ptr %33, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %39, label %35

35:                                               ; preds = %31
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call ptr @strstr(ptr noundef %36, ptr noundef @.str.9) #8
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br label %39

39:                                               ; preds = %35, %31, %27
  %40 = phi i1 [ true, %31 ], [ true, %27 ], [ %38, %35 ]
  br i1 %40, label %41, label %93

41:                                               ; preds = %39
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = ptrtoint ptr %44 to i64
  %47 = ptrtoint ptr %45 to i64
  %48 = sub i64 %46, %47
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %42, ptr align 1 %43, i64 %48, i1 false)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = ptrtoint ptr %49 to i64
  %52 = ptrtoint ptr %50 to i64
  %53 = sub i64 %51, %52
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 %53
  store ptr %55, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call i32 @memcmp(ptr noundef %56, ptr noundef @.str.10, i64 noundef 24) #8
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %66

59:                                               ; preds = %41
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 1 %61, i64 24, i1 false)
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 24
  store ptr %63, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 24
  store ptr %65, ptr %10, align 8, !tbaa !5
  br label %27, !llvm.loop !11

66:                                               ; preds = %41
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = call ptr @strstr(ptr noundef %67, ptr noundef @.str.11) #8
  store ptr %68, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %91

71:                                               ; preds = %66
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = ptrtoint ptr %74 to i64
  %77 = ptrtoint ptr %75 to i64
  %78 = sub i64 %76, %77
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %72, ptr align 1 %73, i64 %78, i1 false)
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = ptrtoint ptr %79 to i64
  %82 = ptrtoint ptr %80 to i64
  %83 = sub i64 %81, %82
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 %83
  store ptr %85, ptr %10, align 8, !tbaa !5
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %86, ptr align 1 @.str.12, i64 9, i1 false)
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 9
  store ptr %88, ptr %10, align 8, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 3
  store ptr %90, ptr %7, align 8, !tbaa !5
  br label %92

91:                                               ; preds = %66
  br label %93

92:                                               ; preds = %71
  br label %27, !llvm.loop !11

93:                                               ; preds = %91, %39
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %107

96:                                               ; preds = %93
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = load i64, ptr %5, align 8, !tbaa !9
  %101 = getelementptr inbounds i8, ptr %99, i64 %100
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = ptrtoint ptr %101 to i64
  %104 = ptrtoint ptr %102 to i64
  %105 = sub i64 %103, %104
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %97, ptr align 1 %98, i64 %105, i1 false)
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %106, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %109

107:                                              ; preds = %93
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %108) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %109

109:                                              ; preds = %107, %96, %16
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %110 = load ptr, ptr %3, align 8
  ret ptr %110
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind willreturn memory(read) "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 allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind "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 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @hack_gemcore(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.6) #6
  %4 = icmp eq ptr %3, null
  br i1 %4, label %36, label %5

5:                                                ; preds = %2
  %6 = shl i64 %1, 1
  %7 = add i64 %6, 32
  %calloc = tail call ptr @calloc(i64 1, i64 %7)
  br label %.outer

.outer:                                           ; preds = %24, %5
  %.044.ph = phi ptr [ %29, %24 ], [ %0, %5 ]
  %.042.ph = phi i1 [ false, %24 ], [ true, %5 ]
  %.0.ph = phi ptr [ %28, %24 ], [ %calloc, %5 ]
  br label %8

8:                                                ; preds = %.outer, %19
  %.044 = phi ptr [ %20, %19 ], [ %.044.ph, %.outer ]
  %.0 = phi ptr [ %21, %19 ], [ %.0.ph, %.outer ]
  %9 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %.044, ptr noundef nonnull dereferenceable(1) @.str.7) #6
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %.critedge

10:                                               ; preds = %8
  %11 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %.044, ptr noundef nonnull dereferenceable(1) @.str.8) #6
  %.not51 = icmp eq ptr %11, null
  br i1 %.not51, label %12, label %.critedge

12:                                               ; preds = %10
  %13 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %.044, ptr noundef nonnull dereferenceable(1) @.str.9) #6
  %.not52 = icmp eq ptr %13, null
  br i1 %.not52, label %30, label %.critedge

.critedge:                                        ; preds = %10, %8, %12
  %.041 = phi ptr [ %9, %8 ], [ %11, %10 ], [ %13, %12 ]
  %14 = ptrtoint ptr %.041 to i64
  %15 = ptrtoint ptr %.044 to i64
  %16 = sub i64 %14, %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.0, ptr align 1 %.044, i64 %16, i1 false)
  %17 = getelementptr inbounds i8, ptr %.0, i64 %16
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(24) %.041, ptr noundef nonnull dereferenceable(24) @.str.10, i64 24)
  %18 = icmp eq i32 %bcmp, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %.critedge
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(24) %17, ptr noundef nonnull align 1 dereferenceable(24) %.041, i64 24, i1 false)
  %20 = getelementptr inbounds i8, ptr %.041, i64 24
  %21 = getelementptr inbounds i8, ptr %17, i64 24
  br label %8, !llvm.loop !5

22:                                               ; preds = %.critedge
  %23 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %.041, ptr noundef nonnull dereferenceable(1) @.str.11) #6
  %.not53 = icmp eq ptr %23, null
  br i1 %.not53, label %.thread, label %24

24:                                               ; preds = %22
  %25 = ptrtoint ptr %23 to i64
  %26 = sub i64 %25, %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr nonnull align 1 %.041, i64 %26, i1 false)
  %27 = getelementptr inbounds i8, ptr %17, i64 %26
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %27, ptr noundef nonnull align 1 dereferenceable(9) @.str.12, i64 9, i1 false)
  %28 = getelementptr inbounds i8, ptr %27, i64 9
  %29 = getelementptr inbounds i8, ptr %23, i64 3
  br label %.outer, !llvm.loop !5

30:                                               ; preds = %12
  br i1 %.042.ph, label %.thread, label %31

31:                                               ; preds = %30
  %32 = getelementptr inbounds i8, ptr %0, i64 %1
  %33 = ptrtoint ptr %32 to i64
  %34 = ptrtoint ptr %.044 to i64
  %35 = sub i64 %33, %34
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.0, ptr align 1 %.044, i64 %35, i1 false)
  br label %36

.thread:                                          ; preds = %22, %30
  tail call void @free(ptr noundef %calloc) #7
  br label %36

36:                                               ; preds = %2, %.thread, %31
  %.045 = phi ptr [ %calloc, %31 ], [ null, %.thread ], [ null, %2 ]
  ret ptr %.045
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

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 nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass