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

; 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.32 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [53 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
define dso_local noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [200 x i8], align 16
  %7 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %13, label %10

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %1
  br label %15

14:                                               ; preds = %10
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.32, i32 noundef 58, ptr noundef @.str.33, ptr noundef null)
  br label %15

15:                                               ; preds = %14, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %16 = call noalias ptr @fopen(ptr noundef @.str.34, ptr noundef @.str.35)
  store ptr %16, ptr %4, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !11
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  br label %21

20:                                               ; preds = %15
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.32, i32 noundef 69, ptr noundef @.str.36, ptr noundef null)
  br label %21

21:                                               ; preds = %20, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 200, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 200, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %26

25:                                               ; preds = %21
  br label %26

26:                                               ; preds = %25, %24
  %27 = phi ptr [ @.str.37, %24 ], [ @.str.38, %25 ]
  %28 = getelementptr inbounds [12 x i8], ptr %27, i64 0, i64 0
  store ptr %28, ptr %7, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %45, %26
  %30 = getelementptr inbounds [200 x i8], ptr %6, i64 0, i64 0
  %31 = load ptr, ptr %4, align 8, !tbaa !11
  %32 = call ptr @fgets(ptr noundef %30, i32 noundef 200, ptr noundef %31)
  %33 = icmp ne ptr null, %32
  br i1 %33, label %34, label %46

34:                                               ; preds = %29
  %35 = getelementptr inbounds [200 x i8], ptr %6, i64 0, i64 0
  %36 = load ptr, ptr %7, align 8, !tbaa !11
  %37 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %35, ptr noundef %36, ptr noundef %3) #5
  %38 = icmp eq i32 1, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %34
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %44

43:                                               ; preds = %39
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.32, i32 noundef 75, ptr noundef @.str.39, ptr noundef @.str.40)
  br label %44

44:                                               ; preds = %43, %42
  br label %46

45:                                               ; preds = %34
  br label %29, !llvm.loop !15

46:                                               ; preds = %44, %29
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %52, label %49

49:                                               ; preds = %46
  %50 = call noundef i32 @_Z18LinuxKernelVersionv()
  %51 = icmp uge i32 %50, 2006015
  br i1 %51, label %52, label %58

52:                                               ; preds = %49, %46
  %53 = load i64, ptr %3, align 8, !tbaa !9
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  br label %57

56:                                               ; preds = %52
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.32, i32 noundef 81, ptr noundef @.str.39, ptr noundef @.str.41)
  br label %57

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

58:                                               ; preds = %57, %49
  %59 = load ptr, ptr %4, align 8, !tbaa !11
  %60 = call i32 @fclose(ptr noundef %59)
  %61 = load i64, ptr %3, align 8, !tbaa !9
  %62 = mul i64 %61, 1024
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i64 %62
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z18LinuxKernelVersionv() #4

declare i32 @fclose(ptr noundef) #2

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 = { "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 "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 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 = { 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 = !{!"_ZTS14MemoryStatType", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.32 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [53 x i8], align 1

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z14GetMemoryUsage14MemoryStatType(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %3 = alloca [200 x i8], align 16
  %4 = icmp eq i32 %0, 1
  %or.cond = icmp ult i32 %0, 2
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %1
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.32, i32 noundef 58, ptr noundef nonnull @.str.33, ptr noundef null)
  br label %6

6:                                                ; preds = %1, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  %7 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.34, ptr noundef nonnull @.str.35)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %9

8:                                                ; preds = %6
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.32, i32 noundef 69, ptr noundef nonnull @.str.36, ptr noundef null)
  br label %9

9:                                                ; preds = %6, %8
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %3) #4
  %.str.37..str.38 = select i1 %4, ptr @.str.37, ptr @.str.38
  br label %10

10:                                               ; preds = %12, %9
  %11 = call ptr @fgets(ptr noundef nonnull %3, i32 noundef 200, ptr noundef %7)
  %.not10 = icmp eq ptr %11, null
  br i1 %.not10, label %.loopexit, label %12

12:                                               ; preds = %10
  %13 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull %3, ptr noundef nonnull %.str.37..str.38, ptr noundef nonnull %2) #4
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %10, !llvm.loop !9

15:                                               ; preds = %12
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %.not11 = icmp eq i64 %16, 0
  br i1 %.not11, label %17, label %.loopexit

17:                                               ; preds = %15
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.32, i32 noundef 75, ptr noundef nonnull @.str.39, ptr noundef nonnull @.str.40)
  br label %.loopexit

.loopexit:                                        ; preds = %10, %17, %15
  br i1 %4, label %18, label %23

18:                                               ; preds = %.loopexit
  %19 = call noundef i32 @_Z18LinuxKernelVersionv()
  %20 = icmp ult i32 %19, 2006015
  %21 = load i64, ptr %2, align 8
  %22 = icmp ne i64 %21, 0
  %or.cond3 = select i1 %20, i1 true, i1 %22
  br i1 %or.cond3, label %25, label %24

23:                                               ; preds = %.loopexit
  %.old = load i64, ptr %2, align 8, !tbaa !5
  %.old2.not = icmp eq i64 %.old, 0
  br i1 %.old2.not, label %24, label %25

24:                                               ; preds = %18, %23
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.32, i32 noundef 81, ptr noundef nonnull @.str.39, ptr noundef nonnull @.str.41)
  br label %25

25:                                               ; preds = %24, %23, %18
  %26 = call i32 @fclose(ptr noundef %7)
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = shl i64 %27, 10
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i64 %28
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_sscanf(ptr nocapture noundef readonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z18LinuxKernelVersionv() local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { nofree 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 = { inlinehint 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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass