; LLVM IR from vczh/herodb :: Kernel/Source/Utility (FileBuffer)

; 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.vl::database::IdObject.10" = type { i32 }

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSourceC1ENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEi(ptr noundef nonnull align 8 dereferenceable(448), i32, ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSource21InitializeEmptySourceEv(ptr noundef nonnull align 8 dereferenceable(448)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSource24InitializeExistingSourceEv(ptr noundef nonnull align 8 dereferenceable(448)) #2 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2vl8database16CreateFileSourceENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEb(i32 %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(48) %3, i1 noundef zeroext %4) #2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca %"struct.vl::database::IdObject.10", align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca %"struct.vl::database::IdObject.10", align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = getelementptr inbounds %"struct.vl::database::IdObject.10", ptr %7, i32 0, i32 0
  store i32 %0, ptr %18, align 4
  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
  %19 = zext i1 %4 to i8
  store i8 %19, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !13
  %20 = load i8, ptr %11, align 1, !tbaa !11, !range !15, !noundef !16
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %25

22:                                               ; preds = %5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = call noundef i32 @_ZN2vl8database26CreateNewFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48) %23)
  store i32 %24, ptr %12, align 4, !tbaa !13
  br label %28

25:                                               ; preds = %5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = call noundef i32 @_ZN2vl8database29OpenExistingFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48) %26)
  store i32 %27, ptr %12, align 4, !tbaa !13
  br label %28

28:                                               ; preds = %25, %22
  %29 = load i32, ptr %12, align 4, !tbaa !13
  %30 = icmp eq i32 %29, -1
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %58

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %33 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 448) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %7, i64 4, i1 false), !tbaa.struct !17
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !13
  %38 = getelementptr inbounds %"struct.vl::database::IdObject.10", ptr %15, i32 0, i32 0
  %39 = load i32, ptr %38, align 4
  invoke void @_ZN2vl8database16FileBufferSourceC1ENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEi(ptr noundef nonnull align 8 dereferenceable(448) %33, i32 %39, ptr noundef %34, i64 noundef %35, ptr noundef nonnull align 8 dereferenceable(48) %36, i32 noundef %37)
          to label %40 unwind label %45

40:                                               ; preds = %32
  store ptr %33, ptr %14, align 8, !tbaa !5
  %41 = load i8, ptr %11, align 1, !tbaa !11, !range !15, !noundef !16
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %49

43:                                               ; preds = %40
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN2vl8database16FileBufferSource21InitializeEmptySourceEv(ptr noundef nonnull align 8 dereferenceable(448) %44)
  br label %51

45:                                               ; preds = %32
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %16, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %17, align 4
  call void @_ZdlPvm(ptr noundef %33, i64 noundef 448) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %60

49:                                               ; preds = %40
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN2vl8database16FileBufferSource24InitializeExistingSourceEv(ptr noundef nonnull align 8 dereferenceable(448) %50)
  br label %51

51:                                               ; preds = %49, %43
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = icmp eq ptr %52, null
  br i1 %53, label %56, label %54

54:                                               ; preds = %51
  %55 = getelementptr inbounds i8, ptr %52, i64 8
  br label %56

56:                                               ; preds = %54, %51
  %57 = phi ptr [ %55, %54 ], [ null, %51 ]
  store ptr %57, ptr %6, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %58

58:                                               ; preds = %56, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %59 = load ptr, ptr %6, align 8
  ret ptr %59

60:                                               ; preds = %45
  %61 = load ptr, ptr %16, align 8
  %62 = load i32, ptr %17, align 4
  %63 = insertvalue { ptr, i32 } poison, ptr %61, 0
  %64 = insertvalue { ptr, i32 } %63, i32 %62, 1
  resume { ptr, i32 } %64
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { nobuiltin 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 = { nobuiltin 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{i64 0, i64 4, !13}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSourceC1ENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEi(ptr noundef nonnull align 8 dereferenceable(448), i32, ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSource21InitializeEmptySourceEv(ptr noundef nonnull align 8 dereferenceable(448)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl8database16FileBufferSource24InitializeExistingSourceEv(ptr noundef nonnull align 8 dereferenceable(448)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2vl8database26CreateNewFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2vl8database29OpenExistingFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2vl8database16CreateFileSourceENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEb(i32 %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(48) %3, i1 noundef zeroext %4) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  br i1 %4, label %6, label %8

6:                                                ; preds = %5
  %7 = tail call noundef i32 @_ZN2vl8database26CreateNewFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48) %3)
  br label %10

8:                                                ; preds = %5
  %9 = tail call noundef i32 @_ZN2vl8database29OpenExistingFileForFileSourceERKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(48) %3)
  br label %10

10:                                               ; preds = %8, %6
  %.015 = phi i32 [ %7, %6 ], [ %9, %8 ]
  %11 = icmp eq i32 %.015, -1
  br i1 %11, label %21, label %12

12:                                               ; preds = %10
  %13 = tail call noalias noundef nonnull dereferenceable(448) ptr @_Znwm(i64 noundef 448) #3
  invoke void @_ZN2vl8database16FileBufferSourceC1ENS0_8IdObjectIiLl0EEEPVmmRKNS_12ObjectStringIwEEi(ptr noundef nonnull align 8 dereferenceable(448) %13, i32 %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(48) %3, i32 noundef %.015)
          to label %14 unwind label %16

14:                                               ; preds = %12
  br i1 %4, label %15, label %18

15:                                               ; preds = %14
  tail call void @_ZN2vl8database16FileBufferSource21InitializeEmptySourceEv(ptr noundef nonnull align 8 dereferenceable(448) %13)
  br label %19

16:                                               ; preds = %12
  %17 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 448) #4
  resume { ptr, i32 } %17

18:                                               ; preds = %14
  tail call void @_ZN2vl8database16FileBufferSource24InitializeExistingSourceEv(ptr noundef nonnull align 8 dereferenceable(448) %13)
  br label %19

19:                                               ; preds = %18, %15
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  br label %21

21:                                               ; preds = %10, %19
  %.0 = phi ptr [ %20, %19 ], [ null, %10 ]
  ret ptr %.0
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #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 = { nobuiltin 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 #2 = { nobuiltin 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 #3 = { builtin allocsize(0) }
attributes #4 = { builtin 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass