; LLVM IR from justinxu9905/bustub-2022-fall :: src/storage/page (header_page)

; 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.1 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6bustub10HeaderPage14GetRecordCountEv(ptr noundef nonnull align 8 dereferenceable(4168)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6bustub10HeaderPage10FindRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168), ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6bustub10HeaderPage14SetRecordCountEi(ptr noundef nonnull align 8 dereferenceable(4168), i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %11 = call noundef i32 @_ZN6bustub10HeaderPage14GetRecordCountEv(ptr noundef nonnull align 8 dereferenceable(4168) %10)
  store i32 %11, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %17

15:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 42, ptr noundef @__PRETTY_FUNCTION__._ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE) #6
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef i32 @_ZN6bustub10HeaderPage10FindRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168) %10, ptr noundef nonnull align 8 dereferenceable(32) %18)
  store i32 %19, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %44

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = mul nsw i32 %24, 36
  %26 = add nsw i32 %25, 4
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = call noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168) %10)
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  %31 = call noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168) %10)
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = getelementptr inbounds i8, ptr %34, i64 36
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = sub nsw i32 %36, %37
  %39 = sub nsw i32 %38, 1
  %40 = mul nsw i32 %39, 36
  %41 = sext i32 %40 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %30, ptr align 1 %35, i64 %41, i1 false)
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sub nsw i32 %42, 1
  call void @_ZN6bustub10HeaderPage14SetRecordCountEi(ptr noundef nonnull align 8 dereferenceable(4168) %10, i32 noundef %43)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %44

44:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %45 = load i1, ptr %3, align 1
  ret i1 %45
}

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

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@.str.1 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6bustub10HeaderPage14GetRecordCountEv(ptr noundef nonnull align 8 dereferenceable(4168)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6bustub10HeaderPage10FindRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6bustub10HeaderPage14SetRecordCountEi(ptr noundef nonnull align 8 dereferenceable(4168), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZN6bustub10HeaderPage14GetRecordCountEv(ptr noundef nonnull align 8 dereferenceable(4168) %0)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 42, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6bustub10HeaderPage12DeleteRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE) #4
  unreachable

6:                                                ; preds = %2
  %7 = tail call noundef i32 @_ZN6bustub10HeaderPage10FindRecordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(4168) %0, ptr noundef nonnull align 8 dereferenceable(32) %1)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %23

9:                                                ; preds = %6
  %10 = mul nsw i32 %7, 36
  %11 = add nsw i32 %10, 4
  %12 = tail call noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168) %0)
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %15 = tail call noundef ptr @_ZN6bustub4Page7GetDataEv(ptr noundef nonnull align 8 dereferenceable(4168) %0)
  %16 = getelementptr inbounds i8, ptr %15, i64 %13
  %17 = getelementptr inbounds i8, ptr %16, i64 36
  %18 = xor i32 %7, -1
  %19 = add i32 %3, %18
  %20 = mul nsw i32 %19, 36
  %21 = sext i32 %20 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %14, ptr nonnull align 1 %17, i64 %21, i1 false)
  %22 = add nsw i32 %3, -1
  tail call void @_ZN6bustub10HeaderPage14SetRecordCountEi(ptr noundef nonnull align 8 dereferenceable(4168) %0, i32 noundef %22)
  br label %23

23:                                               ; preds = %6, %9
  ret i1 %8
}

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

attributes #0 = { noreturn 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 #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass