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

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

%"class.Harness::internal::Tracer" = type <{ i32, [4 x i8], ptr, ptr, i64, [8 x i8] }>
%class.CMemTest = type { i32, i8, ptr }

@__tbb_test_errno = external dso_local global i8, align 1
@_ZN7Harness8internalL6tracerE = external hidden global %"class.Harness::internal::Tracer", align 8
@.str = external hidden unnamed_addr constant [98 x i8], align 1
@Tfree = external dso_local global ptr, align 8
@error_occurred = external dso_local global i8, align 1
@.str.63 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZL8strError = external hidden constant [7 x i8], align 1
@_ZL5strOk = external hidden constant [5 x i8], align 1
@__FUNCTION__._ZN8CMemTest9Free_NULLEv = external hidden unnamed_addr constant [10 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [51 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef, ptr noundef, i64 noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ...) #2 align 2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

; 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 zeroext i1 @_ZN8CMemTest17ShouldReportErrorEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8CMemTest9Free_NULLEv(ptr noundef nonnull align 8 dereferenceable(16) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 0
  store i32 0, ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 1
  %7 = load i8, ptr %6, align 4, !tbaa !13, !range !14, !noundef !15
  %8 = trunc i8 %7 to i1
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  %10 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef @.str, i64 noundef 1016, ptr noundef @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %10, ptr noundef @.str.79)
  br label %11

11:                                               ; preds = %9, %1
  %12 = call ptr @__errno_location() #4
  store i32 0, ptr %12, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %13

13:                                               ; preds = %34, %11
  %14 = load i32, ptr %3, align 4, !tbaa !16
  %15 = icmp slt i32 %14, 10000
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  %18 = load ptr, ptr @Tfree, align 8, !tbaa !5
  call void %18(ptr noundef null)
  %19 = load i8, ptr @__tbb_test_errno, align 1, !tbaa !17, !range !14, !noundef !15
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %33

21:                                               ; preds = %17
  %22 = call ptr @__errno_location() #4
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %21
  %26 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %26, align 8, !tbaa !9
  %29 = call noundef zeroext i1 @_ZN8CMemTest17ShouldReportErrorEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  br i1 %29, label %30, label %32

30:                                               ; preds = %25
  %31 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef @.str, i64 noundef 1024, ptr noundef @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %31, ptr noundef @.str.80)
  br label %32

32:                                               ; preds = %30, %25
  br label %33

33:                                               ; preds = %32, %21, %17
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %3, align 4, !tbaa !16
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !16
  br label %13, !llvm.loop !18

37:                                               ; preds = %16
  %38 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef @.str, i64 noundef 1027, ptr noundef @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %42, ptr noundef @.str.63, ptr noundef @_ZL8strError)
  br label %50

43:                                               ; preds = %37
  %44 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 1
  %45 = load i8, ptr %44, align 4, !tbaa !13, !range !14, !noundef !15
  %46 = trunc i8 %45 to i1
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef @.str, i64 noundef 1028, ptr noundef @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %48, ptr noundef @.str.63, ptr noundef @_ZL5strOk)
  br label %49

49:                                               ; preds = %47, %43
  br label %50

50:                                               ; preds = %49, %41
  %51 = getelementptr inbounds %class.CMemTest, ptr %4, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = icmp ugt i32 %52, 0
  %54 = zext i1 %53 to i32
  %55 = load i8, ptr @error_occurred, align 1, !tbaa !17, !range !14, !noundef !15
  %56 = trunc i8 %55 to i1
  %57 = zext i1 %56 to i32
  %58 = or i32 %57, %54
  %59 = icmp ne i32 %58, 0
  %60 = zext i1 %59 to i8
  store i8 %60, ptr @error_occurred, align 1, !tbaa !17
  ret void
}

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 = { 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 #3 = { nounwind willreturn memory(none) "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 willreturn memory(none) }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS8CMemTest", !11, i64 0, !12, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !12, i64 4}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!11, !11, i64 0}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%"class.Harness::internal::Tracer" = type <{ i32, [4 x i8], ptr, ptr, i64, [8 x i8] }>

@__tbb_test_errno = external dso_local local_unnamed_addr global i8, align 1
@_ZN7Harness8internalL6tracerE = external hidden global %"class.Harness::internal::Tracer", align 8
@.str = external hidden unnamed_addr constant [98 x i8], align 1
@Tfree = external dso_local local_unnamed_addr global ptr, align 8
@error_occurred = external dso_local local_unnamed_addr global i8, align 1
@.str.63 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZL8strError = external hidden constant [7 x i8], align 1
@_ZL5strOk = external hidden constant [5 x i8], align 1
@__FUNCTION__._ZN8CMemTest9Free_NULLEv = external hidden unnamed_addr constant [10 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ...) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8CMemTest17ShouldReportErrorEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8CMemTest9Free_NULLEv(ptr noundef nonnull align 8 dereferenceable(16) %0) local_unnamed_addr #1 align 2 {
  store i32 0, ptr %0, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i8, ptr %2, align 4, !tbaa !12, !range !13, !noundef !14
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = tail call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef nonnull @.str, i64 noundef 1016, ptr noundef nonnull @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  tail call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %6, ptr noundef nonnull @.str.79)
  br label %7

7:                                                ; preds = %5, %1
  %8 = tail call ptr @__errno_location() #3
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %11

9:                                                ; preds = %23
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %25, label %.sink.split

11:                                               ; preds = %7, %23
  %.03 = phi i32 [ 0, %7 ], [ %24, %23 ]
  %12 = load ptr, ptr @Tfree, align 8, !tbaa !16
  tail call void %12(ptr noundef null)
  %13 = load i8, ptr @__tbb_test_errno, align 1, !tbaa !17, !range !13, !noundef !14
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %23

15:                                               ; preds = %11
  %16 = load i32, ptr %8, align 4, !tbaa !15
  %.not2 = icmp eq i32 %16, 0
  br i1 %.not2, label %23, label %17

17:                                               ; preds = %15
  %18 = load i32, ptr %0, align 8, !tbaa !5
  %19 = add i32 %18, 1
  store i32 %19, ptr %0, align 8, !tbaa !5
  %20 = tail call noundef zeroext i1 @_ZN8CMemTest17ShouldReportErrorEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = tail call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef nonnull @.str, i64 noundef 1024, ptr noundef nonnull @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  tail call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %22, ptr noundef nonnull @.str.80)
  br label %23

23:                                               ; preds = %11, %15, %21, %17
  %24 = add nuw nsw i32 %.03, 1
  %exitcond.not = icmp eq i32 %24, 10000
  br i1 %exitcond.not, label %9, label %11, !llvm.loop !18

25:                                               ; preds = %9
  %26 = load i8, ptr %2, align 4, !tbaa !12, !range !13, !noundef !14
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %.sink.split, label %29

.sink.split:                                      ; preds = %25, %9
  %.sink4 = phi i64 [ 1027, %9 ], [ 1028, %25 ]
  %_ZL5strOk.sink = phi ptr [ @_ZL8strError, %9 ], [ @_ZL5strOk, %25 ]
  %28 = tail call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef nonnull @.str, i64 noundef %.sink4, ptr noundef nonnull @__FUNCTION__._ZN8CMemTest9Free_NULLEv)
  tail call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %28, ptr noundef nonnull @.str.63, ptr noundef nonnull %_ZL5strOk.sink)
  br label %29

29:                                               ; preds = %.sink.split, %25
  %30 = load i32, ptr %0, align 8, !tbaa !5
  %31 = icmp ne i32 %30, 0
  %32 = load i8, ptr @error_occurred, align 1, !tbaa !17, !range !13, !noundef !14
  %33 = zext i1 %31 to i8
  %34 = or i8 %32, %33
  store i8 %34, ptr @error_occurred, align 1, !tbaa !17
  ret void
}

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 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 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, !7, i64 0}
!6 = !{!"_ZTS8CMemTest", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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