; LLVM IR from turi-code/SFrame :: oss_src/fileio (fixed_size_cache_manager)

; 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.graphlab::fileio::cache_block" = type { %"class.std::__cxx11::basic_string", i64, i64, i64, ptr, %"class.std::__cxx11::basic_string", ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_ZN8graphlab6fileio29FILEIO_MAXIMUM_CACHE_CAPACITYE = external global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8graphlab6fileio11cache_block15extend_capacityEm(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %80

15:                                               ; preds = %2
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = icmp ule i64 %16, %18
  br i1 %19, label %20, label %80

20:                                               ; preds = %15
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !16
  %24 = icmp ule i64 %21, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i1 true, ptr %3, align 1
  br label %81

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %27 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %27, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %28 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !16
  %30 = mul i64 %29, 2
  store i64 %30, ptr %7, align 8, !tbaa !9
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %32 = load i64, ptr %31, align 8, !tbaa !9
  store i64 %32, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %33 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 1
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %33)
  %35 = load i64, ptr %34, align 8, !tbaa !9
  store i64 %35, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %36 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 6
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = call noundef i64 @_ZN8graphlab6fileio24fixed_size_cache_manager21get_cache_utilizationEv(ptr noundef nonnull align 8 dereferenceable(112) %37)
  store i64 %38, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = sub i64 %40, %42
  %44 = add i64 %39, %43
  %45 = load i64, ptr @_ZN8graphlab6fileio29FILEIO_MAXIMUM_CACHE_CAPACITYE, align 8, !tbaa !9
  %46 = icmp ugt i64 %44, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %26
  %48 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %48, ptr %5, align 8, !tbaa !9
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !16
  %53 = sub i64 %50, %52
  %54 = add i64 %49, %53
  %55 = load i64, ptr @_ZN8graphlab6fileio29FILEIO_MAXIMUM_CACHE_CAPACITYE, align 8, !tbaa !9
  %56 = icmp ugt i64 %54, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %47
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %79

58:                                               ; preds = %47
  br label %59

59:                                               ; preds = %58, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %60 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 4
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = load i64, ptr %5, align 8, !tbaa !9
  %63 = call ptr @realloc(ptr noundef %61, i64 noundef %62) #5
  store ptr %63, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %67

66:                                               ; preds = %59
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %78

67:                                               ; preds = %59
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 4
  store ptr %68, ptr %69, align 8, !tbaa !11
  %70 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load i64, ptr %5, align 8, !tbaa !9
  %73 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  %74 = load i64, ptr %73, align 8, !tbaa !16
  %75 = sub nsw i64 %72, %74
  call void @_ZN8graphlab6fileio24fixed_size_cache_manager21increment_utilizationEl(ptr noundef nonnull align 8 dereferenceable(112) %71, i64 noundef %75)
  %76 = load i64, ptr %5, align 8, !tbaa !9
  %77 = getelementptr inbounds %"struct.graphlab::fileio::cache_block", ptr %11, i32 0, i32 2
  store i64 %76, ptr %77, align 8, !tbaa !16
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %78

78:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %79

79:                                               ; preds = %78, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %81

80:                                               ; preds = %15, %2
  store i1 false, ptr %3, align 1
  br label %81

81:                                               ; preds = %80, %79, %25
  %82 = load i1, ptr %3, align 1
  ret i1 %82
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN8graphlab6fileio24fixed_size_cache_manager21get_cache_utilizationEv(ptr noundef nonnull align 8 dereferenceable(112)) #2 align 2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8graphlab6fileio24fixed_size_cache_manager21increment_utilizationEl(ptr noundef nonnull align 8 dereferenceable(112), i64 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(1) }

!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, !6, i64 56}
!12 = !{!"_ZTSN8graphlab6fileio11cache_blockE", !13, i64 0, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !13, i64 64, !6, i64 96}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !10, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !10, i64 40}
!17 = !{!12, !6, i64 96}


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

@_ZN8graphlab6fileio29FILEIO_MAXIMUM_CACHE_CAPACITYE = external local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8graphlab6fileio11cache_block15extend_capacityEm(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %1, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %42, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %.not8 = icmp ult i64 %9, %1
  br i1 %.not8, label %42, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %.not9 = icmp ult i64 %12, %1
  br i1 %.not9, label %13, label %42

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %14 = shl i64 %12, 1
  store i64 %14, ptr %4, align 8, !tbaa !5
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %16 = load i64, ptr %15, align 8, !tbaa !5
  store i64 %16, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %18 = load i64, ptr %17, align 8, !tbaa !5
  store i64 %18, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 96
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = call noundef i64 @_ZN8graphlab6fileio24fixed_size_cache_manager21get_cache_utilizationEv(ptr noundef nonnull align 8 dereferenceable(112) %20)
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %11, align 8, !tbaa !15
  %24 = add i64 %22, %21
  %25 = sub i64 %24, %23
  %26 = load i64, ptr @_ZN8graphlab6fileio29FILEIO_MAXIMUM_CACHE_CAPACITYE, align 8, !tbaa !5
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %13
  store i64 %1, ptr %3, align 8, !tbaa !5
  %29 = add i64 %21, %1
  %30 = sub i64 %29, %23
  %31 = icmp ugt i64 %30, %26
  br i1 %31, label %42, label %32

32:                                               ; preds = %28, %13
  %33 = phi i64 [ %1, %28 ], [ %22, %13 ]
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = call ptr @realloc(ptr noundef %34, i64 noundef %33) #5
  %.not10 = icmp eq ptr %35, null
  br i1 %.not10, label %42, label %36

36:                                               ; preds = %32
  store ptr %35, ptr %5, align 8, !tbaa !9
  %37 = load ptr, ptr %19, align 8, !tbaa !16
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %11, align 8, !tbaa !15
  %40 = sub nsw i64 %38, %39
  call void @_ZN8graphlab6fileio24fixed_size_cache_manager21increment_utilizationEl(ptr noundef nonnull align 8 dereferenceable(112) %37, i64 noundef %40)
  %41 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %41, ptr %11, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %2, %7, %28, %32, %36, %10
  %.2 = phi i1 [ true, %10 ], [ false, %28 ], [ false, %32 ], [ true, %36 ], [ false, %7 ], [ false, %2 ]
  ret i1 %.2
}

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

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

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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8graphlab6fileio24fixed_size_cache_manager21increment_utilizationEl(ptr noundef nonnull align 8 dereferenceable(112), 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 nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(1) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 56}
!10 = !{!"_ZTSN8graphlab6fileio11cache_blockE", !11, i64 0, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !11, i64 64, !13, i64 96}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !6, i64 8, !7, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 40}
!16 = !{!10, !13, i64 96}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass