; 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.internal_malloc_info_type = type { %union.libxsmm_free_function, ptr, ptr, ptr, i64, i32 }
%union.libxsmm_free_function = type { ptr }

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@libxsmm_verbosity = external global i32, align 4
@stderr = external global ptr, align 8
@libxsmm_get_malloc_xinfo.error_once = external hidden global i32, align 4
@.str.31 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_get_malloc_xinfo = external hidden unnamed_addr constant [69 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_get_malloc_xinfo(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr null, %12
  br i1 %13, label %17, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %80

17:                                               ; preds = %14, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %25, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = and i32 256, %22
  %24 = icmp eq i32 0, %23
  br label %25

25:                                               ; preds = %20, %17
  %26 = phi i1 [ true, %17 ], [ %24, %20 ]
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 2, i32 1
  store i32 %28, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = call ptr @internal_malloc_info(ptr noundef %29, i32 noundef %30)
  store ptr %31, ptr %11, align 8, !tbaa !5
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = icmp ne ptr null, %32
  br i1 %33, label %34, label %59

34:                                               ; preds = %25
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp ne ptr null, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %34
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %38, i32 0, i32 4
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %40, ptr %41, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %37, %34
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = icmp ne ptr null, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %42
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %46, i32 0, i32 5
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %48, ptr %49, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %45, %42
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = icmp ne ptr null, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.internal_malloc_info_type, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %56, ptr %57, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %53, %50
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %79

59:                                               ; preds = %25
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = icmp ne ptr null, %60
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, i32 1, i32 0
  store i32 %63, ptr %9, align 4, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = icmp ne ptr null, %64
  br i1 %65, label %66, label %68

66:                                               ; preds = %59
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %67, align 8, !tbaa !14
  br label %68

68:                                               ; preds = %66, %59
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = icmp ne ptr null, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %68
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %72, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %71, %68
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = icmp ne ptr null, %74
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %77, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %76, %73
  br label %79

79:                                               ; preds = %78, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %92

80:                                               ; preds = %14
  %81 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  %82 = icmp ne i32 0, %81
  br i1 %82, label %83, label %91

83:                                               ; preds = %80
  %84 = atomicrmw add ptr @libxsmm_get_malloc_xinfo.error_once, i32 1 seq_cst, align 4
  %85 = add i32 %84, 1
  %86 = icmp eq i32 1, %85
  br i1 %86, label %87, label %91

87:                                               ; preds = %83
  %88 = load ptr, ptr @stderr, align 8, !tbaa !5
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.31, ptr noundef %89) #5
  br label %91

91:                                               ; preds = %87, %83, %80
  call void @__assert_fail(ptr noundef @.str.32, ptr noundef @.str.1, i32 noundef 1592, ptr noundef @__PRETTY_FUNCTION__.libxsmm_get_malloc_xinfo) #6
  unreachable

92:                                               ; preds = %79
  %93 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 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 }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 32}
!12 = !{!"internal_malloc_info_type", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !10, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !10, i64 40}
!16 = !{!12, !6, i64 8}


; 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.1 = external hidden unnamed_addr constant [70 x i8], align 1
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@libxsmm_get_malloc_xinfo.error_once = external hidden global i32, align 4
@.str.31 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_get_malloc_xinfo = external hidden unnamed_addr constant [69 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @libxsmm_get_malloc_xinfo(ptr noundef %0, ptr noundef writeonly %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #3 {
  %5 = icmp ne ptr %1, null
  %6 = icmp ne ptr %3, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %7, label %35

7:                                                ; preds = %4
  %8 = icmp eq ptr %2, null
  br i1 %8, label %14, label %9

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

14:                                               ; preds = %9, %7
  %15 = phi i32 [ 2, %7 ], [ %13, %9 ]
  %16 = tail call ptr @internal_malloc_info(ptr noundef %0, i32 noundef %15)
  %.not31 = icmp eq ptr %16, null
  br i1 %.not31, label %29, label %17

17:                                               ; preds = %14
  br i1 %5, label %18, label %21

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %16, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %1, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %18, %17
  br i1 %8, label %25, label %22

22:                                               ; preds = %21
  %23 = getelementptr inbounds i8, ptr %16, i64 40
  %24 = load i32, ptr %23, align 8, !tbaa !14
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %22, %21
  br i1 %6, label %26, label %34

26:                                               ; preds = %25
  %27 = getelementptr inbounds i8, ptr %16, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  br label %.sink.split

29:                                               ; preds = %14
  %.not32 = icmp ne ptr %0, null
  br i1 %5, label %30, label %31

30:                                               ; preds = %29
  store i64 0, ptr %1, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %30, %29
  br i1 %8, label %33, label %32

32:                                               ; preds = %31
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %31
  br i1 %6, label %.sink.split, label %34

.sink.split:                                      ; preds = %33, %26
  %.sink = phi ptr [ %28, %26 ], [ null, %33 ]
  %.0.shrunk.ph = phi i1 [ false, %26 ], [ %.not32, %33 ]
  store ptr %.sink, ptr %3, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %.sink.split, %25, %33
  %.0.shrunk = phi i1 [ %.not32, %33 ], [ false, %25 ], [ %.0.shrunk.ph, %.sink.split ]
  %.0 = zext i1 %.0.shrunk to i32
  ret i32 %.0

35:                                               ; preds = %4
  %36 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !5
  %.not = icmp eq i32 %36, 0
  br i1 %.not, label %43, label %37

37:                                               ; preds = %35
  %38 = atomicrmw add ptr @libxsmm_get_malloc_xinfo.error_once, i32 1 seq_cst, align 4
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load ptr, ptr @stderr, align 8, !tbaa !16
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.31, ptr noundef %0) #4
  br label %43

43:                                               ; preds = %40, %37, %35
  tail call void @__assert_fail(ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.1, i32 noundef 1592, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_get_malloc_xinfo) #5
  unreachable
}

attributes #0 = { 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 #1 = { 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 #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 = { 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 = { cold nounwind }
attributes #5 = { 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/C++ TBAA"}
!9 = !{!10, !12, i64 32}
!10 = !{!"internal_malloc_info_type", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !6, i64 40}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !6, i64 40}
!15 = !{!10, !11, i64 8}
!16 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass