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

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

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ffrecord_select_mode(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = and i32 %11, 520093696
  %13 = icmp eq i32 %12, 67108864
  br i1 %13, label %14, label %73

14:                                               ; preds = %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.GCRef, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  %21 = getelementptr inbounds %struct.GCstr, ptr %20, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 35
  br i1 %24, label %25, label %73

25:                                               ; preds = %14
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.anon, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.GCRef, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = zext i32 %29 to i64
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct.GCstr, ptr %31, i32 0, i32 6
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %50

35:                                               ; preds = %25
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = trunc i32 %37 to i16
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.GCRef, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = inttoptr i64 %44 to ptr
  %46 = call i32 @lj_ir_kgc(ptr noundef %39, ptr noundef %45, i32 noundef 4)
  %47 = trunc i32 %46 to i16
  call void @lj_ir_set_(ptr noundef %36, i16 noundef zeroext 2180, i16 noundef zeroext %38, i16 noundef zeroext %47)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call i32 @lj_opt_fold(ptr noundef %48)
  br label %72

50:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = trunc i32 %52 to i16
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call i32 @lj_ir_kint(ptr noundef %54, i32 noundef 0)
  %56 = trunc i32 %55 to i16
  call void @lj_ir_set_(ptr noundef %51, i16 noundef zeroext 16389, i16 noundef zeroext %53, i16 noundef zeroext %56)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = call i32 @lj_opt_fold(ptr noundef %57)
  store i32 %58, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = trunc i32 %60 to i16
  call void @lj_ir_set_(ptr noundef %59, i16 noundef zeroext 17936, i16 noundef zeroext %61, i16 noundef zeroext 1)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = call i32 @lj_opt_fold(ptr noundef %62)
  store i32 %63, ptr %9, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = trunc i32 %65 to i16
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = call i32 @lj_ir_kint(ptr noundef %67, i32 noundef 35)
  %69 = trunc i32 %68 to i16
  call void @lj_ir_set_(ptr noundef %64, i16 noundef zeroext 2195, i16 noundef zeroext %66, i16 noundef zeroext %69)
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = call i32 @lj_opt_fold(ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %72

72:                                               ; preds = %50, %35
  store i32 0, ptr %4, align 4
  br label %83

73:                                               ; preds = %14, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = call i32 @argv2int(ptr noundef %74, ptr noundef %75)
  store i32 %76, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = icmp eq i32 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %73
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %80, i32 noundef 11) #6
  unreachable

81:                                               ; preds = %73
  %82 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %82, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %83

83:                                               ; preds = %81, %72
  %84 = load i32, ptr %4, align 4
  ret i32 %84
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_ir_set_(ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) #1

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

declare hidden i32 @lj_opt_fold(ptr noundef) #2

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

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

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

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

; Function Attrs: noreturn
declare hidden void @lj_trace_err(ptr noundef, i32 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind }
attributes #6 = { 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, !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"

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ffrecord_select_mode(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = and i32 %1, 520093696
  %5 = icmp eq i32 %4, 67108864
  br i1 %5, label %6, label %30

6:                                                ; preds = %3
  %7 = load i32, ptr %2, align 8, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 35
  br i1 %12, label %13, label %30

13:                                               ; preds = %6
  %14 = getelementptr inbounds i8, ptr %9, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  %17 = trunc i32 %1 to i16
  br i1 %16, label %18, label %21

18:                                               ; preds = %13
  %19 = tail call i32 @lj_ir_kgc(ptr noundef %0, ptr noundef nonnull %9, i32 noundef 4) #4
  %20 = trunc i32 %19 to i16
  tail call void @lj_ir_set_(ptr noundef %0, i16 noundef zeroext 2180, i16 noundef zeroext %17, i16 noundef zeroext %20)
  br label %.sink.split

21:                                               ; preds = %13
  %22 = tail call i32 @lj_ir_kint(ptr noundef %0, i32 noundef 0) #4
  %23 = trunc i32 %22 to i16
  tail call void @lj_ir_set_(ptr noundef %0, i16 noundef zeroext 16389, i16 noundef zeroext %17, i16 noundef zeroext %23)
  %24 = tail call i32 @lj_opt_fold(ptr noundef %0) #4
  %25 = trunc i32 %24 to i16
  tail call void @lj_ir_set_(ptr noundef %0, i16 noundef zeroext 17936, i16 noundef zeroext %25, i16 noundef zeroext 1)
  %26 = tail call i32 @lj_opt_fold(ptr noundef %0) #4
  %27 = trunc i32 %26 to i16
  %28 = tail call i32 @lj_ir_kint(ptr noundef %0, i32 noundef 35) #4
  %29 = trunc i32 %28 to i16
  tail call void @lj_ir_set_(ptr noundef %0, i16 noundef zeroext 2195, i16 noundef zeroext %27, i16 noundef zeroext %29)
  br label %.sink.split

30:                                               ; preds = %6, %3
  %31 = tail call i32 @argv2int(ptr noundef %0, ptr noundef %2)
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %30
  tail call void @lj_trace_err(ptr noundef %0, i32 noundef 11) #5
  unreachable

.sink.split:                                      ; preds = %21, %18
  %34 = tail call i32 @lj_opt_fold(ptr noundef %0) #4
  br label %35

35:                                               ; preds = %.sink.split, %30
  %.0 = phi i32 [ %31, %30 ], [ 0, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_ir_set_(ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

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

declare hidden i32 @lj_opt_fold(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: noreturn
declare hidden void @lj_trace_err(ptr noundef, i32 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 = { 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 = { 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 #4 = { nounwind }
attributes #5 = { noreturn 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,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass