; LLVM IR from DanEngelbrecht/longtail :: lib/cacheblockstore (longtail_cacheblockstore)

; 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.CachedStoredBlock = type { %struct.Longtail_StoredBlock, ptr, i32 }
%struct.Longtail_StoredBlock = type { ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [104 x i8], align 1
@__func__.CachedStoredBlock_CreateBlock = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @CachedStoredBlock_Dispose(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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @CachedStoredBlock_CreateBlock(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = 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 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 48, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load i64, ptr %7, align 8, !tbaa !11
  %11 = call ptr @Longtail_Alloc(ptr noundef @.str, i64 noundef %10)
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.1, ptr noundef @__func__.CachedStoredBlock_CreateBlock, i32 noundef 94, ptr noundef %15, i32 noundef 3, ptr noundef @.str.2, i32 noundef 12)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %46

16:                                               ; preds = %2
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.CachedStoredBlock, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %18, i32 0, i32 0
  store ptr @CachedStoredBlock_Dispose, ptr %19, align 8, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.CachedStoredBlock, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %24, i32 0, i32 1
  store ptr %22, ptr %25, align 8, !tbaa !17
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.CachedStoredBlock, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %30, i32 0, i32 2
  store ptr %28, ptr %31, align 8, !tbaa !19
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !20
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CachedStoredBlock, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %36, i32 0, i32 3
  store i32 %34, ptr %37, align 8, !tbaa !21
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.CachedStoredBlock, ptr %39, i32 0, i32 1
  store ptr %38, ptr %40, align 8, !tbaa !22
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.CachedStoredBlock, ptr %42, i32 0, i32 2
  store volatile i32 %41, ptr %43, align 8, !tbaa !23
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CachedStoredBlock, ptr %44, i32 0, i32 0
  store ptr %45, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %46

46:                                               ; preds = %16, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %47 = load ptr, ptr %3, align 8
  ret ptr %47
}

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

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

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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"CachedStoredBlock", !15, i64 0, !6, i64 32, !10, i64 40}
!15 = !{!"Longtail_StoredBlock", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!16 = !{!15, !6, i64 8}
!17 = !{!14, !6, i64 8}
!18 = !{!15, !6, i64 16}
!19 = !{!14, !6, i64 16}
!20 = !{!15, !10, i64 24}
!21 = !{!14, !10, i64 24}
!22 = !{!14, !6, i64 32}
!23 = !{!14, !10, i64 40}


; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [104 x i8], align 1
@__func__.CachedStoredBlock_CreateBlock = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @CachedStoredBlock_Dispose(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @CachedStoredBlock_CreateBlock(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @Longtail_Alloc(ptr noundef nonnull @.str, i64 noundef 48) #2
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  tail call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.CachedStoredBlock_CreateBlock, i32 noundef 94, ptr noundef null, i32 noundef 3, ptr noundef nonnull @.str.2, i32 noundef 12) #2
  br label %14

5:                                                ; preds = %2
  store ptr @CachedStoredBlock_Dispose, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = load <2 x ptr>, ptr %6, align 8, !tbaa !12
  store <2 x ptr> %8, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 %10, ptr %11, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %3, i64 40
  store volatile i32 %1, ptr %13, align 8, !tbaa !16
  br label %14

14:                                               ; preds = %5, %4
  ret ptr %3
}

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

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

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 = { "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 = { 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, !8, i64 0}
!6 = !{!"CachedStoredBlock", !7, i64 0, !8, i64 32, !11, i64 40}
!7 = !{!"Longtail_StoredBlock", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !11, i64 24}
!14 = !{!6, !11, i64 24}
!15 = !{!6, !8, i64 32}
!16 = !{!6, !11, i64 40}


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