; LLVM IR from DanEngelbrecht/longtail :: lib/lrublockstore (longtail_lrublockstore)

; 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.Longtail_LogFieldFmt_Private = type { ptr, ptr, ptr }
%struct.Longtail_LogContextFmt_Private = type { ptr, ptr, i64 }

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.Longtail_CreateLRUBlockStoreAPI = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @LRU_GetSize(i32 noundef) #0

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

declare void @Longtail_CallLogger(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

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

declare void @Longtail_Free(ptr noundef) #2

declare ptr @Longtail_Alloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @Longtail_CreateLRUBlockStoreAPI(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [2 x %struct.Longtail_LogFieldFmt_Private], align 16
  %7 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #3
  %14 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 0
  store ptr @.str.8, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 1
  store ptr @.str.1, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = inttoptr i64 %18 to ptr
  store ptr %19, ptr %16, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i64 1
  %21 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %20, i32 0, i32 0
  store ptr @.str.9, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %20, i32 0, i32 1
  store ptr @.str.3, ptr %22, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %20, i32 0, i32 2
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = inttoptr i64 %25 to ptr
  store ptr %26, ptr %23, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  %27 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 0
  store ptr null, ptr %27, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 1
  %29 = getelementptr inbounds [2 x %struct.Longtail_LogFieldFmt_Private], ptr %6, i64 0, i64 0
  store ptr %29, ptr %28, align 8, !tbaa !18
  %30 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 2
  store i64 2, ptr %30, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr %7, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.4, ptr noundef @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 695, ptr noundef %31, i32 noundef 0, ptr noundef @.str.5, ptr noundef @.str.6)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %36, label %34

34:                                               ; preds = %2
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.4, ptr noundef @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 697, ptr noundef %35, i32 noundef 3, ptr noundef @.str.10, ptr noundef @.str.8)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %65

36:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = mul i64 56, %38
  %40 = add i64 296, %39
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = call i64 @LRU_GetSize(i32 noundef %41)
  %43 = add i64 %40, %42
  store i64 %43, ptr %10, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %44 = load i64, ptr %10, align 8, !tbaa !20
  %45 = call ptr @Longtail_Alloc(ptr noundef @.str.7, i64 noundef %44)
  store ptr %45, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %50, label %48

48:                                               ; preds = %36
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.4, ptr noundef @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 707, ptr noundef %49, i32 noundef 3, ptr noundef @.str.11, i32 noundef 12)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %64

50:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = call i32 @LRUBlockStore_Init(ptr noundef %51, ptr noundef %52, i32 noundef %53, ptr noundef %12)
  store i32 %54, ptr %13, align 4, !tbaa !9
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %61

57:                                               ; preds = %50
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %13, align 4, !tbaa !9
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.4, ptr noundef @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 718, ptr noundef %58, i32 noundef 3, ptr noundef @.str.12, i32 noundef %59)
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %60)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

61:                                               ; preds = %50
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %62, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %61, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %64

64:                                               ; preds = %63, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %65

65:                                               ; preds = %64, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #3
  %66 = load ptr, ptr %3, align 8
  ret ptr %66
}

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Longtail_LogFieldFmt_Private", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !6, i64 0}
!16 = !{!"Longtail_LogContextFmt_Private", !6, i64 0, !6, i64 8, !17, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !17, i64 16}
!20 = !{!17, !17, 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"

%struct.Longtail_LogFieldFmt_Private = type { ptr, ptr, ptr }
%struct.Longtail_LogContextFmt_Private = type { ptr, ptr, i64 }

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.Longtail_CreateLRUBlockStoreAPI = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @LRU_GetSize(i32 noundef) local_unnamed_addr #0

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

declare void @Longtail_CallLogger(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) 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

declare void @Longtail_Free(ptr noundef) local_unnamed_addr #2

declare ptr @Longtail_Alloc(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @Longtail_CreateLRUBlockStoreAPI(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [2 x %struct.Longtail_LogFieldFmt_Private], align 16
  %4 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #3
  store ptr @.str.8, ptr %3, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr @.str.1, ptr %6, align 8, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %0, ptr %7, align 16, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr @.str.9, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr @.str.3, ptr %9, align 16, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %3, i64 40
  %11 = zext i32 %1 to i64
  %12 = inttoptr i64 %11 to ptr
  store ptr %12, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 2, ptr %14, align 8, !tbaa !16
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 695, ptr noundef nonnull %4, i32 noundef 0, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6) #3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %15, label %16

15:                                               ; preds = %2
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 697, ptr noundef nonnull %4, i32 noundef 3, ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.8) #3
  br label %29

16:                                               ; preds = %2
  %17 = mul nuw nsw i64 %11, 56
  %18 = add nuw nsw i64 %17, 296
  %19 = call i64 @LRU_GetSize(i32 noundef %1)
  %20 = add i64 %18, %19
  %21 = call ptr @Longtail_Alloc(ptr noundef nonnull @.str.7, i64 noundef %20) #3
  %.not20 = icmp eq ptr %21, null
  br i1 %.not20, label %22, label %23

22:                                               ; preds = %16
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 707, ptr noundef nonnull %4, i32 noundef 3, ptr noundef nonnull @.str.11, i32 noundef 12) #3
  br label %29

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %24 = call i32 @LRUBlockStore_Init(ptr noundef nonnull %21, ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %5)
  %.not21 = icmp eq i32 %24, 0
  br i1 %.not21, label %26, label %25

25:                                               ; preds = %23
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.Longtail_CreateLRUBlockStoreAPI, i32 noundef 718, ptr noundef nonnull %4, i32 noundef 3, ptr noundef nonnull @.str.12, i32 noundef %24) #3
  call void @Longtail_Free(ptr noundef nonnull %21) #3
  br label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !17
  br label %28

28:                                               ; preds = %26, %25
  %.0 = phi ptr [ null, %25 ], [ %27, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %29

29:                                               ; preds = %22, %28, %15
  %.2 = phi ptr [ null, %15 ], [ %.0, %28 ], [ null, %22 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #3
  ret ptr %.2
}

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"Longtail_LogFieldFmt_Private", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !7, i64 0}
!13 = !{!"Longtail_LogContextFmt_Private", !7, i64 0, !7, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!13, !7, i64 8}
!16 = !{!13, !14, i64 16}
!17 = !{!7, !7, i64 0}


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