; LLVM IR from libxsmm/libxsmm :: src (libxsmm_malloc)

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

%struct.anon = type { i64, i64, i64, ptr, ptr, ptr, i32 }
%struct.internal_malloc_info_type = type { %union.libxsmm_free_function, ptr, ptr, ptr, i64, i32 }
%union.libxsmm_free_function = type { ptr }

@.str = external hidden unnamed_addr constant [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@__PRETTY_FUNCTION__.internal_scratch_free = external hidden unnamed_addr constant [70 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@libxsmm_scratch_scale = external global double, align 8
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@internal_scratch_free.error_once = external hidden global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [44 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: nounwind uwtable
define dso_local void @internal_scratch_free(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.anon, ptr %11, i32 0, i32 1
  %13 = atomicrmw sub ptr %12, i64 1 seq_cst, align 8
  %14 = sub i64 %13, 1
  store i64 %14, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ule ptr %19, %20
  br i1 %21, label %22, label %31

22:                                               ; preds = %2
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.anon, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %24, i64 %27
  %29 = icmp ult ptr %23, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  br label %32

31:                                               ; preds = %22, %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 607, ptr noundef @__PRETTY_FUNCTION__.internal_scratch_free) #6
  unreachable

32:                                               ; preds = %30
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = icmp ule ptr %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  br label %40

39:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 609, ptr noundef @__PRETTY_FUNCTION__.internal_scratch_free) #6
  unreachable

40:                                               ; preds = %38
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = icmp eq i64 0, %41
  br i1 %42, label %43, label %108

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call ptr @internal_malloc_info(ptr noundef %44, i32 noundef 0)
  store ptr %45, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %46 = load double, ptr @libxsmm_scratch_scale, align 8, !tbaa !12
  %47 = fcmp une double 1.000000e+00, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %43
  %49 = load double, ptr @libxsmm_scratch_scale, align 8, !tbaa !12
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %50, i32 0, i32 4
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = uitofp i64 %52 to double
  %54 = fmul double %49, %53
  br label %60

55:                                               ; preds = %43
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %56, i32 0, i32 4
  %58 = load i64, ptr %57, align 8, !tbaa !14
  %59 = uitofp i64 %58 to double
  br label %60

60:                                               ; preds = %55, %48
  %61 = phi double [ %54, %48 ], [ %59, %55 ]
  %62 = fptoui double %61 to i64
  store i64 %62, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.anon, ptr %66, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = add i64 %65, %68
  store i64 %69, ptr %10, align 8, !tbaa !9
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %70, i32 0, i32 5
  %72 = load i32, ptr %71, align 8, !tbaa !17
  %73 = and i32 256, %72
  %74 = icmp eq i32 0, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %60
  br label %77

76:                                               ; preds = %60
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 614, ptr noundef @__PRETTY_FUNCTION__.internal_scratch_free) #6
  unreachable

77:                                               ; preds = %75
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = load i64, ptr %9, align 8, !tbaa !9
  %80 = icmp ule i64 %78, %79
  br i1 %80, label %81, label %85

81:                                               ; preds = %77
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.anon, ptr %83, i32 0, i32 4
  store ptr %82, ptr %84, align 8, !tbaa !11
  br label %107

85:                                               ; preds = %77
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.anon, ptr %86, i32 0, i32 4
  store ptr null, ptr %87, align 8, !tbaa !11
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.anon, ptr %88, i32 0, i32 3
  store ptr null, ptr %89, align 8, !tbaa !11
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.anon, ptr %90, i32 0, i32 5
  store ptr null, ptr %91, align 8, !tbaa !11
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = call i32 @internal_xfree(ptr noundef %92, ptr noundef %93)
  %95 = icmp ne i32 0, %94
  br i1 %95, label %96, label %106

96:                                               ; preds = %85
  %97 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !18
  %98 = icmp ne i32 0, %97
  br i1 %98, label %99, label %106

99:                                               ; preds = %96
  %100 = atomicrmw add ptr @internal_scratch_free.error_once, i32 1 seq_cst, align 4
  %101 = add i32 %100, 1
  %102 = icmp eq i32 1, %101
  br i1 %102, label %103, label %106

103:                                              ; preds = %99
  %104 = load ptr, ptr @stderr, align 8, !tbaa !5
  %105 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %104, ptr noundef @.str.4) #5
  br label %106

106:                                              ; preds = %103, %99, %96, %85
  br label %107

107:                                              ; preds = %106, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %108

108:                                              ; preds = %107, %40
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @internal_malloc_info(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @internal_xfree(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { inlinehint 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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !10, i64 32}
!15 = !{!"internal_malloc_info_type", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !16, i64 40}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !16, i64 40}
!18 = !{!16, !16, i64 0}


; 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 [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@__PRETTY_FUNCTION__.internal_scratch_free = external hidden unnamed_addr constant [70 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@libxsmm_scratch_scale = external local_unnamed_addr global double, align 8
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@internal_scratch_free.error_once = external hidden global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @internal_scratch_free(ptr noundef readnone %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = atomicrmw sub ptr %3, i64 1 seq_cst, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp ugt ptr %6, %0
  br i1 %.not, label %11, label %7

7:                                                ; preds = %2
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 %8
  %10 = icmp ugt ptr %9, %0
  br i1 %10, label %12, label %11

11:                                               ; preds = %7, %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 607, ptr noundef nonnull @__PRETTY_FUNCTION__.internal_scratch_free) #5
  unreachable

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %1, i64 32
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not29 = icmp ugt ptr %6, %14
  br i1 %.not29, label %15, label %16

15:                                               ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 609, ptr noundef nonnull @__PRETTY_FUNCTION__.internal_scratch_free) #5
  unreachable

16:                                               ; preds = %12
  %17 = icmp eq i64 %4, 1
  br i1 %17, label %18, label %48

18:                                               ; preds = %16
  %19 = tail call ptr @internal_malloc_info(ptr noundef %6, i32 noundef 0)
  %20 = getelementptr inbounds i8, ptr %19, i64 40
  %21 = load i32, ptr %20, align 8, !tbaa !8
  %22 = and i32 %21, 256
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 614, ptr noundef nonnull @__PRETTY_FUNCTION__.internal_scratch_free) #5
  unreachable

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %19, i64 32
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = uitofp i64 %27 to double
  %29 = load double, ptr @libxsmm_scratch_scale, align 8, !tbaa !14
  %30 = fmul double %29, %28
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %1, i64 16
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add i64 %33, %31
  %35 = fptoui double %30 to i64
  %.not30 = icmp ugt i64 %34, %35
  br i1 %.not30, label %37, label %36

36:                                               ; preds = %25
  store ptr %6, ptr %13, align 8, !tbaa !5
  br label %48

37:                                               ; preds = %25
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, i8 0, i64 24, i1 false)
  %38 = tail call i32 @internal_xfree(ptr noundef %6, ptr noundef nonnull %19)
  %39 = icmp ne i32 %38, 0
  %40 = load i32, ptr @libxsmm_verbosity, align 4
  %41 = icmp ne i32 %40, 0
  %or.cond = select i1 %39, i1 %41, i1 false
  br i1 %or.cond, label %42, label %48

42:                                               ; preds = %37
  %43 = atomicrmw add ptr @internal_scratch_free.error_once, i32 1 seq_cst, align 4
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load ptr, ptr @stderr, align 8, !tbaa !16
  %47 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef nonnull @.str.4) #6
  br label %48

48:                                               ; preds = %36, %45, %42, %37, %16
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @internal_malloc_info(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @internal_xfree(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 = { 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 #2 = { inlinehint 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { noreturn nounwind }
attributes #6 = { cold 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !12, i64 40}
!9 = !{!"internal_malloc_info_type", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !12, i64 40}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!9, !11, i64 32}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !6, i64 0}
!16 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass