; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src/ap.ll (ZN11alglib_impl14aligned_mallocEmm)

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

@_ZN11alglib_impl14_alloc_counterE = external dso_local global i64, align 8
@_ZN11alglib_impl20_alloc_counter_totalE = external dso_local global i64, align 8
@_ZN11alglib_impl18_use_alloc_counterE = external dso_local global i8, align 1
@_ZN11alglib_impl16_dbg_alloc_totalE = external dso_local global i64, align 8
@_ZN11alglib_impl17_use_dbg_countersE = external dso_local global i8, align 1
@_ZN11alglib_impl21_force_malloc_failureE = external dso_local global i8, align 1
@_ZN11alglib_impl21_malloc_failure_afterE = external dso_local global i64, 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN11alglib_impl8ae_alignEPvm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef, i64 noundef) #1

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

13:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

14:                                               ; preds = %2
  %15 = load i8, ptr @_ZN11alglib_impl21_force_malloc_failureE, align 1, !tbaa !11, !range !13, !noundef !14
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

18:                                               ; preds = %14
  %19 = load i64, ptr @_ZN11alglib_impl21_malloc_failure_afterE, align 8, !tbaa !5
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %18
  %22 = load i64, ptr @_ZN11alglib_impl20_alloc_counter_totalE, align 8, !tbaa !5
  %23 = load i64, ptr @_ZN11alglib_impl21_malloc_failure_afterE, align 8, !tbaa !5
  %24 = icmp sge i64 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

26:                                               ; preds = %21, %18
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp ule i64 %27, 1
  br i1 %28, label %29, label %45

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = add i64 8, %30
  %32 = call noalias ptr @malloc(i64 noundef %31) #4
  store ptr %32, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %42

36:                                               ; preds = %29
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %37, ptr %9, align 8, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %38, ptr %39, align 8, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %40, i64 8
  store ptr %41, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %42

42:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %43 = load i32, ptr %7, align 4
  switch i32 %43, label %78 [
    i32 0, label %44
  ]

44:                                               ; preds = %42
  br label %67

45:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = sub i64 %46, 1
  %48 = add i64 %47, 8
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = add i64 %48, %49
  %51 = call noalias ptr @malloc(i64 noundef %50) #4
  store ptr %51, ptr %10, align 8, !tbaa !9
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %45
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %64

55:                                               ; preds = %45
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = getelementptr inbounds i8, ptr %56, i64 8
  store ptr %57, ptr %6, align 8, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = call noundef ptr @_ZN11alglib_impl8ae_alignEPvm(ptr noundef %58, i64 noundef %59)
  store ptr %60, ptr %6, align 8, !tbaa !9
  %61 = load ptr, ptr %10, align 8, !tbaa !9
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i64 -8
  store ptr %61, ptr %63, align 8, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %64

64:                                               ; preds = %55, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %65 = load i32, ptr %7, align 4
  switch i32 %65, label %78 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %44
  %68 = load i8, ptr @_ZN11alglib_impl18_use_alloc_counterE, align 1, !tbaa !11, !range !13, !noundef !14
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %71

70:                                               ; preds = %67
  call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef @_ZN11alglib_impl14_alloc_counterE, i64 noundef 1)
  call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef @_ZN11alglib_impl20_alloc_counter_totalE, i64 noundef 1)
  br label %71

71:                                               ; preds = %70, %67
  %72 = load i8, ptr @_ZN11alglib_impl17_use_dbg_countersE, align 1, !tbaa !11, !range !13, !noundef !14
  %73 = trunc i8 %72 to i1
  br i1 %73, label %74, label %76

74:                                               ; preds = %71
  %75 = load i64, ptr %4, align 8, !tbaa !5
  call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef @_ZN11alglib_impl16_dbg_alloc_totalE, i64 noundef %75)
  br label %76

76:                                               ; preds = %74, %71
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %77, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

78:                                               ; preds = %76, %64, %42, %25, %17, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %79 = load ptr, ptr %3, align 8
  ret ptr %79
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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

@_ZN11alglib_impl14_alloc_counterE = external dso_local global i64, align 8
@_ZN11alglib_impl20_alloc_counter_totalE = external dso_local global i64, align 8
@_ZN11alglib_impl18_use_alloc_counterE = external dso_local local_unnamed_addr global i8, align 1
@_ZN11alglib_impl16_dbg_alloc_totalE = external dso_local global i64, align 8
@_ZN11alglib_impl17_use_dbg_countersE = external dso_local local_unnamed_addr global i8, align 1
@_ZN11alglib_impl21_force_malloc_failureE = external dso_local local_unnamed_addr global i8, align 1
@_ZN11alglib_impl21_malloc_failure_afterE = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN11alglib_impl14aligned_mallocEmm(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %0, 0
  br i1 %3, label %.thread, label %4

4:                                                ; preds = %2
  %5 = load i8, ptr @_ZN11alglib_impl21_force_malloc_failureE, align 1, !tbaa !5, !range !9, !noundef !10
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %.thread, label %7

7:                                                ; preds = %4
  %8 = load i64, ptr @_ZN11alglib_impl21_malloc_failure_afterE, align 8, !tbaa !11
  %9 = icmp slt i64 %8, 1
  %10 = load i64, ptr @_ZN11alglib_impl20_alloc_counter_totalE, align 8
  %.not = icmp slt i64 %10, %8
  %or.cond = select i1 %9, i1 true, i1 %.not
  br i1 %or.cond, label %11, label %.thread

11:                                               ; preds = %7
  %12 = icmp ult i64 %1, 2
  br i1 %12, label %13, label %18

13:                                               ; preds = %11
  %14 = add i64 %0, 8
  %15 = tail call noalias ptr @malloc(i64 noundef %14) #2
  %.not31 = icmp eq ptr %15, null
  br i1 %.not31, label %.thread, label %16

16:                                               ; preds = %13
  store ptr %15, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %15, i64 8
  br label %26

18:                                               ; preds = %11
  %19 = add i64 %0, 7
  %20 = add i64 %19, %1
  %21 = tail call noalias ptr @malloc(i64 noundef %20) #2
  %.not30 = icmp eq ptr %21, null
  br i1 %.not30, label %.thread, label %22

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %21, i64 8
  %24 = tail call noundef ptr @_ZN11alglib_impl8ae_alignEPvm(ptr noundef nonnull %23, i64 noundef %1)
  %25 = getelementptr inbounds i8, ptr %24, i64 -8
  store ptr %21, ptr %25, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %22, %16
  %.223 = phi ptr [ %17, %16 ], [ %24, %22 ]
  %27 = load i8, ptr @_ZN11alglib_impl18_use_alloc_counterE, align 1, !tbaa !5, !range !9, !noundef !10
  %28 = trunc nuw i8 %27 to i1
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  tail call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef nonnull @_ZN11alglib_impl14_alloc_counterE, i64 noundef 1)
  tail call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef nonnull @_ZN11alglib_impl20_alloc_counter_totalE, i64 noundef 1)
  br label %30

30:                                               ; preds = %29, %26
  %31 = load i8, ptr @_ZN11alglib_impl17_use_dbg_countersE, align 1, !tbaa !5, !range !9, !noundef !10
  %32 = trunc nuw i8 %31 to i1
  br i1 %32, label %33, label %.thread

33:                                               ; preds = %30
  tail call void @_ZN11alglib_impl24ae_optional_atomic_add_iEPll(ptr noundef nonnull @_ZN11alglib_impl16_dbg_alloc_totalE, i64 noundef %0)
  br label %.thread

.thread:                                          ; preds = %18, %13, %30, %33, %7, %4, %2
  %.2 = phi ptr [ null, %2 ], [ null, %4 ], [ null, %7 ], [ %.223, %33 ], [ %.223, %30 ], [ null, %13 ], [ null, %18 ]
  ret ptr %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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