; LLVM IR from cruppstahl/upscaledb :: src/3blob_manager (blob_manager_inmem)

; 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.upscaledb::PBlobHeader" = type <{ i64, i32, i32, i32 }>
%struct.ups_record_t = type { i32, ptr, i32 }
%"struct.upscaledb::BlobManager" = type { ptr, ptr, ptr, ptr, i64, i64, i64, i64 }

; 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: mustprogress uwtable
define dso_local noundef i64 @_ZN9upscaledb19InMemoryBlobManager9overwriteEPNS_7ContextEmP12ups_record_tj(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4) unnamed_addr #1 align 2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !11
  %17 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = inttoptr i64 %18 to ptr
  store ptr %19, ptr %12, align 8, !tbaa !5
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.upscaledb::PBlobHeader", ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 1, !tbaa !13
  %23 = zext i32 %22 to i64
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ups_record_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = zext i32 %26 to i64
  %28 = add i64 %27, 20
  %29 = icmp eq i64 %23, %28
  br i1 %29, label %30, label %45

30:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %31, ptr %13, align 8, !tbaa !5
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 20
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ups_record_t, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ups_record_t, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = zext i32 %39 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %33, ptr align 1 %36, i64 %40, i1 false)
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.upscaledb::PBlobHeader", ptr %41, i32 0, i32 1
  store i32 0, ptr %42, align 1, !tbaa !18
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = ptrtoint ptr %43 to i64
  store i64 %44, ptr %6, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %62

45:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !11
  %49 = load ptr, ptr %17, align 8, !tbaa !19
  %50 = getelementptr inbounds ptr, ptr %49, i64 2
  %51 = load ptr, ptr %50, align 8
  %52 = call noundef i64 %51(ptr noundef nonnull align 8 dereferenceable(64) %17, ptr noundef %46, ptr noundef %47, i32 noundef %48)
  store i64 %52, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %53 = getelementptr inbounds %"struct.upscaledb::BlobManager", ptr %17, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !21
  store ptr %54, ptr %16, align 8, !tbaa !5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.upscaledb::PBlobHeader", ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 1, !tbaa !13
  %60 = zext i32 %59 to i64
  call void @_ZN9upscaledb14InMemoryDevice7releaseEPvm(ptr noundef nonnull align 8 dereferenceable(32) %55, ptr noundef %56, i64 noundef %60)
  %61 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %61, ptr %6, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %62

62:                                               ; preds = %45, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %63 = load i64, ptr %6, align 8
  ret i64 %63
}

; 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) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9upscaledb14InMemoryDevice7releaseEPvm(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 12}
!14 = !{!"_ZTSN9upscaledb11PBlobHeaderE", !10, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTS12ups_record_t", !12, i64 0, !6, i64 8, !12, i64 16}
!17 = !{!16, !6, i64 8}
!18 = !{!14, !12, i64 8}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!22, !6, i64 24}
!22 = !{!"_ZTSN9upscaledb11BlobManagerE", !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}


; 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: mustprogress uwtable
define dso_local noundef i64 @_ZN9upscaledb19InMemoryBlobManager9overwriteEPNS_7ContextEmP12ups_record_tj(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4) unnamed_addr #0 align 2 {
  %6 = inttoptr i64 %2 to ptr
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load i32, ptr %7, align 1, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = load i32, ptr %3, align 8, !tbaa !11
  %11 = zext i32 %10 to i64
  %12 = add nuw nsw i64 %11, 20
  %13 = icmp eq i64 %12, %9
  br i1 %13, label %14, label %19

14:                                               ; preds = %5
  %15 = getelementptr inbounds i8, ptr %6, i64 20
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %15, ptr align 1 %17, i64 %11, i1 false)
  %18 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 0, ptr %18, align 1, !tbaa !15
  br label %28

19:                                               ; preds = %5
  %20 = load ptr, ptr %0, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load ptr, ptr %21, align 8
  %23 = tail call noundef i64 %22(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, ptr noundef nonnull %3, i32 noundef %4)
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = load i32, ptr %7, align 1, !tbaa !5
  %27 = zext i32 %26 to i64
  tail call void @_ZN9upscaledb14InMemoryDevice7releaseEPvm(ptr noundef nonnull align 8 dereferenceable(32) %25, ptr noundef nonnull %6, i64 noundef %27)
  br label %28

28:                                               ; preds = %19, %14
  %.0 = phi i64 [ %2, %14 ], [ %23, %19 ]
  ret i64 %.0
}

; 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) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9upscaledb14InMemoryDevice7releaseEPvm(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i64 noundef) local_unnamed_addr #0 align 2

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

!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, !10, i64 12}
!6 = !{!"_ZTSN9upscaledb11PBlobHeaderE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS12ups_record_t", !10, i64 0, !13, i64 8, !10, i64 16}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!6, !10, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !9, i64 0}
!18 = !{!19, !13, i64 24}
!19 = !{!"_ZTSN9upscaledb11BlobManagerE", !13, i64 8, !13, i64 16, !13, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}


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