; LLVM IR from interpretml/interpret :: shared/libebm/Term.ll (ZN14NAMESPACE_MAIN4Term13AllocateTermsEm)

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

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@g_traceLevel = external global i32, align 4
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage = external hidden constant [28 x i8], align 16
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_0 = external hidden constant [68 x i8], align 16
@__func__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm = external hidden unnamed_addr constant [64 x i8], align 1
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_1 = external hidden constant [27 x i8], align 16

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

declare void @LogAssertFailure(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

; 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
define dso_local noundef ptr @_ZN14NAMESPACE_MAIN4Term13AllocateTermsEm(i64 noundef %0) #5 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 3, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr @g_traceLevel, align 4, !tbaa !9
  %12 = icmp sle i32 3, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  invoke void @InteralLogWithoutArguments(i32 noundef 3, ptr noundef @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage)
          to label %14 unwind label %68

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = call noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef 8, i64 noundef %18) #7
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 2, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr @g_traceLevel, align 4, !tbaa !9
  %23 = icmp sle i32 2, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  invoke void @InteralLogWithoutArguments(i32 noundef 2, ptr noundef @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_0)
          to label %25 unwind label %68

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  store ptr null, ptr %2, align 8
  br label %66

29:                                               ; preds = %17
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = icmp ule i64 1, %30
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  invoke void @LogAssertFailure(i64 noundef 40, ptr noundef @.str, ptr noundef @__func__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm, ptr noundef @.str.3)
          to label %33 unwind label %68

33:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str, i32 noundef 40, ptr noundef @__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm) #8
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %29
  %36 = phi i1 [ true, %29 ], [ false, %34 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = mul i64 8, %37
  %39 = call noalias ptr @malloc(i64 noundef %38) #9
  store ptr %39, ptr %6, align 8, !tbaa !11
  %40 = load ptr, ptr %6, align 8, !tbaa !11
  %41 = icmp ne ptr null, %40
  br i1 %41, label %42, label %56

42:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %43 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %43, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %44 = load ptr, ptr %6, align 8, !tbaa !11
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds ptr, ptr %44, i64 %45
  store ptr %46, ptr %8, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %51, %42
  %48 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr null, ptr %48, align 8, !tbaa !11
  %49 = load ptr, ptr %7, align 8, !tbaa !11
  %50 = getelementptr inbounds ptr, ptr %49, i32 1
  store ptr %50, ptr %7, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %47
  %52 = load ptr, ptr %8, align 8, !tbaa !11
  %53 = load ptr, ptr %7, align 8, !tbaa !11
  %54 = icmp ne ptr %52, %53
  br i1 %54, label %47, label %55, !llvm.loop !13

55:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %56

56:                                               ; preds = %55, %35
  br label %57

57:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 3, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr @g_traceLevel, align 4, !tbaa !9
  %59 = icmp sle i32 3, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %57
  invoke void @InteralLogWithoutArguments(i32 noundef 3, ptr noundef @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_1)
          to label %61 unwind label %68

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %65, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %66

66:                                               ; preds = %64, %28
  %67 = load ptr, ptr %2, align 8
  ret ptr %67

68:                                               ; preds = %60, %32, %24, %13
  %69 = landingpad { ptr, i32 }
          catch ptr null
  %70 = extractvalue { ptr, i32 } %69, 0
  call void @__clang_call_terminate(ptr %70) #8
  unreachable
}

declare void @InteralLogWithoutArguments(i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef, i64 noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noinline noreturn nounwind uwtable "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 = { 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 #4 = { 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 #5 = { 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 #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 [78 x i8], align 1
@g_traceLevel = external local_unnamed_addr global i32, align 4
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage = external hidden constant [28 x i8], align 16
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_0 = external hidden constant [68 x i8], align 16
@__func__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm = external hidden unnamed_addr constant [64 x i8], align 1
@_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_1 = external hidden constant [27 x i8], align 16

declare void @LogAssertFailure(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noalias noundef ptr @_ZN14NAMESPACE_MAIN4Term13AllocateTermsEm(i64 noundef %0) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = load i32, ptr @g_traceLevel, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 2
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  invoke void @InteralLogWithoutArguments(i32 noundef 3, ptr noundef nonnull @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage)
          to label %5 unwind label %19

5:                                                ; preds = %4, %1
  %6 = tail call noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef 8, i64 noundef %0) #6
  br i1 %6, label %7, label %11

7:                                                ; preds = %5
  %8 = load i32, ptr @g_traceLevel, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %10, label %18

10:                                               ; preds = %7
  invoke void @InteralLogWithoutArguments(i32 noundef 2, ptr noundef nonnull @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_0)
          to label %18 unwind label %19

11:                                               ; preds = %5
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %11
  invoke void @LogAssertFailure(i64 noundef 40, ptr noundef nonnull @.str, ptr noundef nonnull @__func__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm, ptr noundef nonnull @.str.3)
          to label %13 unwind label %19

13:                                               ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str, i32 noundef 40, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN4Term13AllocateTermsEm) #7
  unreachable

.loopexit:                                        ; preds = %11
  %14 = shl i64 %0, 3
  %calloc = tail call ptr @calloc(i64 1, i64 %14)
  %15 = load i32, ptr @g_traceLevel, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 2
  br i1 %16, label %17, label %18

17:                                               ; preds = %.loopexit
  invoke void @InteralLogWithoutArguments(i32 noundef 3, ptr noundef nonnull @_ZZN14NAMESPACE_MAIN4Term13AllocateTermsEmE13LOG__sMessage_1)
          to label %18 unwind label %19

18:                                               ; preds = %.loopexit, %17, %7, %10
  %.0 = phi ptr [ null, %10 ], [ null, %7 ], [ %calloc, %17 ], [ %calloc, %.loopexit ]
  ret ptr %.0

19:                                               ; preds = %17, %12, %10, %4
  %20 = landingpad { ptr, i32 }
          catch ptr null
  %21 = extractvalue { ptr, i32 } %20, 0
  tail call void @__clang_call_terminate(ptr %21) #7
  unreachable
}

declare void @InteralLogWithoutArguments(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef, i64 noundef) local_unnamed_addr #4

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

attributes #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 = { noinline noreturn nounwind uwtable "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 = { 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 #3 = { 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 #4 = { inlinehint 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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: DSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass