; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/container/src (alloc_lib)

; 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.malloc_state = type { i32, i32, i64, i64, ptr, ptr, ptr, i64, i64, i64, [66 x ptr], [32 x ptr], i64, i64, i64, i32, i32, %struct.malloc_segment, ptr, i64 }
%struct.malloc_segment = type { ptr, i64, ptr, i32 }

@_gm_ = external hidden global %struct.malloc_state, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @dlmalloc(i64 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
declare hidden ptr @internal_memalign(ptr noundef, i64 noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @dlposix_memalign(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 16
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = call ptr @dlmalloc(i64 noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  br label %52

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = udiv i64 %18, 8
  store i64 %19, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = urem i64 %20, 8
  store i64 %21, ptr %10, align 8, !tbaa !9
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %33, label %24

24:                                               ; preds = %17
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %33, label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = sub i64 %29, 1
  %31 = and i64 %28, %30
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %27, %24, %17
  store i32 22, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %49

34:                                               ; preds = %27
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = sub i64 -128, %36
  %38 = icmp ule i64 %35, %37
  br i1 %38, label %39, label %47

39:                                               ; preds = %34
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = icmp ult i64 %40, 32
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i64 32, ptr %6, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %42, %39
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = call ptr @internal_memalign(ptr noundef @_gm_, i64 noundef %44, i64 noundef %45)
  store ptr %46, ptr %8, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43, %34
  br label %48

48:                                               ; preds = %47
  store i32 0, ptr %11, align 4
  br label %49

49:                                               ; preds = %48, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %50 = load i32, ptr %11, align 4
  switch i32 %50, label %59 [
    i32 0, label %51
  ]

51:                                               ; preds = %49
  br label %52

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

55:                                               ; preds = %52
  store i32 12, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %59

56:                                               ; preds = %52
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %59

59:                                               ; preds = %56, %55, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

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 = { 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 = !{!"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"

%struct.malloc_state = type { i32, i32, i64, i64, ptr, ptr, ptr, i64, i64, i64, [66 x ptr], [32 x ptr], i64, i64, i64, i32, i32, %struct.malloc_segment, ptr, i64 }
%struct.malloc_segment = type { ptr, i64, ptr, i32 }

@_gm_ = external hidden global %struct.malloc_state, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 23) i32 @dlposix_memalign(ptr nocapture noundef writeonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 16
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call ptr @dlmalloc(i64 noundef %2)
  br label %.thread

7:                                                ; preds = %3
  %8 = and i64 %1, 7
  %9 = icmp ne i64 %8, 0
  %10 = icmp ult i64 %1, 8
  %or.cond = or i1 %10, %9
  br i1 %or.cond, label %.thread.thread, label %11

11:                                               ; preds = %7
  %12 = lshr exact i64 %1, 3
  %13 = tail call range(i64 0, 62) i64 @llvm.ctpop.i64(i64 %12)
  %.not = icmp ult i64 %13, 2
  br i1 %.not, label %14, label %.thread.thread

14:                                               ; preds = %11
  %15 = sub i64 -128, %1
  %.not24 = icmp ult i64 %15, %2
  br i1 %.not24, label %.thread.thread, label %16

16:                                               ; preds = %14
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %1, i64 32)
  %17 = tail call ptr @internal_memalign(ptr noundef nonnull @_gm_, i64 noundef %spec.store.select, i64 noundef %2)
  br label %.thread

.thread:                                          ; preds = %16, %5
  %.2 = phi ptr [ %6, %5 ], [ %17, %16 ]
  %18 = icmp eq ptr %.2, null
  br i1 %18, label %.thread.thread, label %19

19:                                               ; preds = %.thread
  store ptr %.2, ptr %0, align 8, !tbaa !5
  br label %.thread.thread

.thread.thread:                                   ; preds = %14, %11, %7, %.thread, %19
  %.1 = phi i32 [ 0, %19 ], [ 12, %.thread ], [ 22, %7 ], [ 22, %11 ], [ 12, %14 ]
  ret i32 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass