; LLVM IR from weicao/cascadb :: src/serialize/layout.ll (ZN7cascadb6Layout20alloc_aligned_bufferEm)

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

%"class.cascadb::Slice" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm = external hidden unnamed_addr constant [52 x i8], align 1
@.str.66 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, 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: mustprogress uwtable
define dso_local { ptr, i32 } @_ZN7cascadb6Layout20alloc_aligned_bufferEm(ptr noundef nonnull align 8 dereferenceable(600) %0, i64 noundef %1) #2 align 2 {
  %3 = alloca %"class.cascadb::Slice", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %15

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.65, ptr noundef @.str.1, i32 noundef 937, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #5
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = add i64 %16, 4096
  %18 = sub i64 %17, 1
  %19 = and i64 %18, -4096
  store i64 %19, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = call i32 @posix_memalign(ptr noundef %7, i64 noundef 4096, i64 noundef %20) #6
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 942, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #5
  unreachable

24:                                               ; preds = %15
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %38

27:                                               ; preds = %24
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = and i64 %29, 4095
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  br label %35

33:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.66, ptr noundef @.str.1, i32 noundef 946, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #5
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !9
  call void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef %36, i64 noundef %37)
  store i32 1, ptr %8, align 4
  br label %39

38:                                               ; preds = %24
  call void @_ZN7cascadb5SliceC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %3)
  store i32 1, ptr %8, align 4
  br label %39

39:                                               ; preds = %38, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %40 = load { ptr, i32 }, ptr %3, align 8
  ret { ptr, i32 } %40
}

; Function Attrs: nounwind
declare i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i64 noundef) unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #4 align 2

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync 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 = { 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 #4 = { 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 #5 = { noreturn nounwind }
attributes #6 = { 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}


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

%"class.cascadb::Slice" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm = external hidden unnamed_addr constant [52 x i8], align 1
@.str.66 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { ptr, i32 } @_ZN7cascadb6Layout20alloc_aligned_bufferEm(ptr nocapture noundef nonnull readnone align 8 dereferenceable(600) %0, i64 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"class.cascadb::Slice", align 8
  %4 = alloca ptr, align 8
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.65, ptr noundef nonnull @.str.1, i32 noundef 937, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #4
  unreachable

6:                                                ; preds = %2
  %7 = add i64 %1, 4095
  %8 = and i64 %7, -4096
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %9 = call i32 @posix_memalign(ptr noundef nonnull %4, i64 noundef 4096, i64 noundef %8) #5
  %.not5 = icmp eq i32 %9, 0
  br i1 %.not5, label %11, label %10

10:                                               ; preds = %6
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 942, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #4
  unreachable

11:                                               ; preds = %6
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %.not6 = icmp eq ptr %12, null
  br i1 %.not6, label %19, label %13

13:                                               ; preds = %11
  %14 = ptrtoint ptr %12 to i64
  %15 = and i64 %14, 4095
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @__assert_fail(ptr noundef nonnull @.str.66, ptr noundef nonnull @.str.1, i32 noundef 946, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb6Layout20alloc_aligned_bufferEm) #4
  unreachable

18:                                               ; preds = %13
  call void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef nonnull %12, i64 noundef %8)
  br label %20

19:                                               ; preds = %11
  call void @_ZN7cascadb5SliceC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %3)
  br label %20

20:                                               ; preds = %19, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  %.fca.0.load = load ptr, ptr %3, align 8
  %.fca.0.insert = insertvalue { ptr, i32 } poison, ptr %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %3, i64 8
  %.fca.1.load = load i32, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { ptr, i32 } %.fca.0.insert, i32 %.fca.1.load, 1
  ret { ptr, i32 } %.fca.1.insert
}

; Function Attrs: nofree nounwind
declare i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #2 align 2

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass