; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_malloc_compliance.ll (Z16CheckReallocLeakv)

; 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 [98 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [36 x i8], align 1

; 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 uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z20InvariantDataReallocbmb(i1 noundef zeroext, i64 noundef, i1 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16CheckReallocLeakv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %13, %0
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %16

12:                                               ; preds = %8
  call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  br label %13

13:                                               ; preds = %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %17 = call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  store i64 %17, ptr %4, align 8, !tbaa !11
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %41, %16
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 10
  br i1 %20, label %21, label %44

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %27, %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 3
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %30

26:                                               ; preds = %22
  call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !5
  br label %22, !llvm.loop !13

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %31 = call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  store i64 %31, ptr %6, align 8, !tbaa !11
  %32 = load i64, ptr %4, align 8, !tbaa !11
  %33 = load i64, ptr %6, align 8, !tbaa !11
  %34 = icmp eq i64 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  store i32 5, ptr %7, align 4
  br label %38

36:                                               ; preds = %30
  %37 = load i64, ptr %6, align 8, !tbaa !11
  store i64 %37, ptr %4, align 8, !tbaa !11
  store i32 0, ptr %7, align 4
  br label %38

38:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %39 = load i32, ptr %7, align 4
  switch i32 %39, label %50 [
    i32 0, label %40
    i32 5, label %44
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %1, align 4, !tbaa !5
  br label %18, !llvm.loop !14

44:                                               ; preds = %38, %18
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = icmp slt i32 %45, 10
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  br label %49

48:                                               ; preds = %44
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str, i32 noundef 413, ptr noundef @.str.44, ptr noundef @.str.45)
  br label %49

49:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void

50:                                               ; preds = %38
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; 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 [98 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z20InvariantDataReallocbmb(i1 noundef zeroext, i64 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16CheckReallocLeakv() local_unnamed_addr #0 {
.preheader:
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %0 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %1 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %2 = icmp eq i64 %0, %1
  br i1 %2, label %.loopexit, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %3 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %4 = icmp eq i64 %1, %3
  br i1 %4, label %.loopexit, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %5 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %6 = icmp eq i64 %3, %5
  br i1 %6, label %.loopexit, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %7 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %8 = icmp eq i64 %5, %7
  br i1 %8, label %.loopexit, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %9 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %10 = icmp eq i64 %7, %9
  br i1 %10, label %.loopexit, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %11 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %12 = icmp eq i64 %9, %11
  br i1 %12, label %.loopexit, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %13 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %14 = icmp eq i64 %11, %13
  br i1 %14, label %.loopexit, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %15 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %16 = icmp eq i64 %13, %15
  br i1 %16, label %.loopexit, label %.preheader.8

.preheader.8:                                     ; preds = %.preheader.7
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %17 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %18 = icmp eq i64 %15, %17
  br i1 %18, label %.loopexit, label %.preheader.9

.preheader.9:                                     ; preds = %.preheader.8
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  tail call void @_Z20InvariantDataReallocbmb(i1 noundef zeroext false, i64 noundef 134217728, i1 noundef zeroext false)
  %19 = tail call noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef 1)
  %20 = icmp eq i64 %17, %19
  br i1 %20, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %.preheader.9
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str, i32 noundef 413, ptr noundef nonnull @.str.44, ptr noundef nonnull @.str.45)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %.preheader.9, %.critedge
  ret void
}

attributes #0 = { 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" }

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


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass