; 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_params = type { i64, i64, i64, i64, i64, i32 }
%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 }

@mparams = external hidden global %struct.malloc_params, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @mspace_set_footprint_limit(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %6, align 8, !tbaa !5
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = load i64, ptr getelementptr inbounds (%struct.malloc_params, ptr @mparams, i32 0, i32 2), align 8, !tbaa !11
  %12 = sub i64 %11, 1
  %13 = add i64 1, %12
  %14 = load i64, ptr getelementptr inbounds (%struct.malloc_params, ptr @mparams, i32 0, i32 2), align 8, !tbaa !11
  %15 = sub i64 %14, 1
  %16 = xor i64 %15, -1
  %17 = and i64 %13, %16
  store i64 %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %10, %2
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = icmp eq i64 %19, -1
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %31

22:                                               ; preds = %18
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr getelementptr inbounds (%struct.malloc_params, ptr @mparams, i32 0, i32 2), align 8, !tbaa !11
  %25 = sub i64 %24, 1
  %26 = add i64 %23, %25
  %27 = load i64, ptr getelementptr inbounds (%struct.malloc_params, ptr @mparams, i32 0, i32 2), align 8, !tbaa !11
  %28 = sub i64 %27, 1
  %29 = xor i64 %28, -1
  %30 = and i64 %26, %29
  store i64 %30, ptr %5, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %22, %21
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.malloc_state, ptr %33, i32 0, i32 14
  store i64 %32, ptr %34, align 8, !tbaa !14
  %35 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %35
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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}
!11 = !{!12, !10, i64 16}
!12 = !{!"malloc_params", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !10, i64 872}
!15 = !{!"malloc_state", !13, i64 0, !13, i64 4, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !7, i64 600, !10, i64 856, !10, i64 864, !10, i64 872, !13, i64 880, !13, i64 884, !16, i64 888, !6, i64 920, !10, i64 928}
!16 = !{!"malloc_segment", !6, i64 0, !10, i64 8, !6, i64 16, !13, i64 24}


; 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_params = type { i64, i64, i64, i64, i64, i32 }

@mparams = external hidden local_unnamed_addr global %struct.malloc_params, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local i64 @mspace_set_footprint_limit(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %1, -1
  br i1 %3, label %10, label %4

4:                                                ; preds = %2
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @mparams, i64 16), align 8, !tbaa !5
  %6 = add i64 %1, -1
  %7 = add i64 %6, %5
  %8 = sub i64 0, %5
  %9 = and i64 %7, %8
  br label %10

10:                                               ; preds = %2, %4
  %.0 = phi i64 [ %9, %4 ], [ 0, %2 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 872
  store i64 %.0, ptr %11, align 8, !tbaa !11
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) 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" }

!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 16}
!6 = !{!"malloc_params", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 872}
!12 = !{!"malloc_state", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !8, i64 72, !8, i64 600, !7, i64 856, !7, i64 864, !7, i64 872, !10, i64 880, !10, i64 884, !14, i64 888, !13, i64 920, !7, i64 928}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"malloc_segment", !13, i64 0, !7, i64 8, !13, i64 16, !10, i64 24}


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