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

; 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.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%struct.GCRef = type { i32 }

; Function Attrs: nounwind uwtable
define hidden i32 @lj_record_constify(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.anon, ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = sub i32 %8, -4
  %10 = icmp ugt i32 %9, -10
  br i1 %10, label %11, label %22

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.GCRef, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @itype2irt(ptr noundef %19)
  %21 = call i32 @lj_ir_kgc(ptr noundef %12, ptr noundef %18, i32 noundef %20)
  store i32 %21, ptr %3, align 4
  br label %51

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp ult i32 %25, -65537
  br i1 %26, label %27, label %32

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = call i32 @lj_ir_knumint(ptr noundef %28, double noundef %30)
  store i32 %31, ptr %3, align 4
  br label %51

32:                                               ; preds = %22
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp eq i32 %35, -2
  br i1 %36, label %42, label %37

37:                                               ; preds = %32
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = icmp eq i32 %40, -3
  br i1 %41, label %42, label %50

42:                                               ; preds = %37, %32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call i32 @itype2irt(ptr noundef %43)
  %45 = sub i32 32767, %44
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call i32 @itype2irt(ptr noundef %46)
  %48 = shl i32 %47, 24
  %49 = add i32 %45, %48
  store i32 %49, ptr %3, align 4
  br label %51

50:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  br label %51

51:                                               ; preds = %50, %42, %27, %11
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

declare hidden i32 @lj_ir_kgc(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @itype2irt(ptr noundef) #2

declare hidden i32 @lj_ir_knumint(ptr noundef, double noundef) #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" }

!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 = !{!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 i32 @lj_record_constify(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add i32 %4, 13
  %6 = icmp ult i32 %5, 9
  br i1 %6, label %7, label %13

7:                                                ; preds = %2
  %8 = load i32, ptr %1, align 8, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = tail call i32 @itype2irt(ptr noundef nonnull %1)
  %12 = tail call i32 @lj_ir_kgc(ptr noundef %0, ptr noundef %10, i32 noundef %11) #3
  br label %24

13:                                               ; preds = %2
  %14 = icmp ult i32 %4, -65537
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = load double, ptr %1, align 8, !tbaa !5
  %17 = tail call i32 @lj_ir_knumint(ptr noundef %0, double noundef %16) #3
  br label %24

18:                                               ; preds = %13
  %.off = add nsw i32 %4, 3
  %switch = icmp ult i32 %.off, 2
  br i1 %switch, label %19, label %24

19:                                               ; preds = %18
  %20 = tail call i32 @itype2irt(ptr noundef nonnull %1)
  %21 = tail call i32 @itype2irt(ptr noundef nonnull %1)
  %22 = shl i32 %21, 24
  %reass.sub12 = sub i32 %22, %20
  %23 = add i32 %reass.sub12, 32767
  br label %24

24:                                               ; preds = %18, %19, %15, %7
  %.0 = phi i32 [ %12, %7 ], [ %17, %15 ], [ %23, %19 ], [ 0, %18 ]
  ret i32 %.0
}

declare hidden i32 @lj_ir_kgc(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @itype2irt(ptr noundef) local_unnamed_addr #2

declare hidden i32 @lj_ir_knumint(ptr noundef, double noundef) local_unnamed_addr #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 = { 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,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass