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

%union.libxsmm_malloc_function = type { ptr }
%union.libxsmm_free_function = type { ptr }

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [76 x i8], align 1
@__PRETTY_FUNCTION__.internal_xmalloc = external hidden unnamed_addr constant [132 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: nounwind uwtable
declare dso_local i32 @internal_xfree(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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

18:                                               ; preds = %6
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = icmp ne ptr null, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %18
  %22 = load ptr, ptr %7, align 8, !tbaa !11
  %23 = icmp ne ptr null, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %26

25:                                               ; preds = %21, %18, %6
  call void @__assert_fail(ptr noundef @.str.33, ptr noundef @.str.1, i32 noundef 1708, ptr noundef @__PRETTY_FUNCTION__.internal_xmalloc) #8
  unreachable

26:                                               ; preds = %24
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = icmp eq ptr null, %28
  br i1 %29, label %30, label %44

30:                                               ; preds = %26
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = icmp eq ptr null, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %30
  %34 = load ptr, ptr %7, align 8, !tbaa !11
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = call ptr %34(i64 noundef %35)
  br label %42

37:                                               ; preds = %30
  %38 = load ptr, ptr %7, align 8, !tbaa !11
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = call ptr %38(i64 noundef %39, ptr noundef %40)
  br label %42

42:                                               ; preds = %37, %33
  %43 = phi ptr [ %36, %33 ], [ %41, %37 ]
  store ptr %43, ptr %13, align 8, !tbaa !5
  br label %104

44:                                               ; preds = %26
  %45 = load ptr, ptr %8, align 8, !tbaa !11
  %46 = icmp ne ptr null, %45
  br i1 %46, label %47, label %53

47:                                               ; preds = %44
  %48 = load ptr, ptr %8, align 8, !tbaa !11
  %49 = icmp eq ptr @__real_free, %48
  br i1 %49, label %59, label %50

50:                                               ; preds = %47
  %51 = load ptr, ptr %8, align 8, !tbaa !11
  %52 = icmp eq ptr @free, %51
  br i1 %52, label %59, label %64

53:                                               ; preds = %44
  %54 = load ptr, ptr %7, align 8, !tbaa !11
  %55 = icmp eq ptr @__real_malloc, %54
  br i1 %55, label %59, label %56

56:                                               ; preds = %53
  %57 = load ptr, ptr %7, align 8, !tbaa !11
  %58 = icmp eq ptr @malloc, %57
  br i1 %58, label %59, label %64

59:                                               ; preds = %56, %53, %50, %47
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = call ptr @internal_xrealloc(ptr noundef %60, ptr noundef %61, i64 noundef %62, ptr noundef null, ptr noundef @__real_free)
  store ptr %63, ptr %13, align 8, !tbaa !5
  br label %103

64:                                               ; preds = %56, %50
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = icmp eq ptr null, %65
  br i1 %66, label %67, label %71

67:                                               ; preds = %64
  %68 = load ptr, ptr %7, align 8, !tbaa !11
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = call ptr %68(i64 noundef %69)
  br label %76

71:                                               ; preds = %64
  %72 = load ptr, ptr %7, align 8, !tbaa !11
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = call ptr %72(i64 noundef %73, ptr noundef %74)
  br label %76

76:                                               ; preds = %71, %67
  %77 = phi ptr [ %70, %67 ], [ %75, %71 ]
  store ptr %77, ptr %13, align 8, !tbaa !5
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = icmp eq ptr null, %78
  br i1 %79, label %80, label %102

80:                                               ; preds = %76
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = icmp ne ptr null, %82
  br i1 %83, label %84, label %90

84:                                               ; preds = %80
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  %89 = call i32 @internal_xfree(ptr noundef %86, ptr noundef %88)
  br label %100

90:                                               ; preds = %80
  %91 = load ptr, ptr %8, align 8, !tbaa !11
  %92 = icmp ne ptr null, %91
  br i1 %92, label %93, label %95

93:                                               ; preds = %90
  %94 = load ptr, ptr %8, align 8, !tbaa !11
  br label %96

95:                                               ; preds = %90
  br label %96

96:                                               ; preds = %95, %93
  %97 = phi ptr [ %94, %93 ], [ @__real_free, %95 ]
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load ptr, ptr %98, align 8, !tbaa !5
  call void %97(ptr noundef %99)
  br label %100

100:                                              ; preds = %96, %84
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %101, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %100, %76
  br label %103

103:                                              ; preds = %102, %59
  br label %104

104:                                              ; preds = %103, %42
  %105 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  ret ptr %105
}

declare void @__real_free(ptr noundef) #5

declare ptr @__real_malloc(i64 noundef) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @internal_xrealloc(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #6

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 = { 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 allocsize(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 = { "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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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}


; 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
@.str.33 = external hidden unnamed_addr constant [76 x i8], align 1
@__PRETTY_FUNCTION__.internal_xmalloc = external hidden unnamed_addr constant [132 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: nounwind uwtable
declare dso_local i32 @internal_xfree(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @internal_xmalloc(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr readonly %4, ptr readonly %5) local_unnamed_addr #1 {
  %7 = icmp ne ptr %0, null
  %8 = icmp ne ptr %1, null
  %or.cond = and i1 %7, %8
  %9 = icmp ne ptr %4, null
  %or.cond3 = select i1 %or.cond, i1 %9, i1 false
  br i1 %or.cond3, label %11, label %10

10:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.33, ptr noundef nonnull @.str.1, i32 noundef 1708, ptr noundef nonnull @__PRETTY_FUNCTION__.internal_xmalloc) #6
  unreachable

11:                                               ; preds = %6
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  %15 = icmp eq ptr %3, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = tail call ptr %4(i64 noundef %2) #7
  br label %47

18:                                               ; preds = %14
  %19 = tail call ptr %4(i64 noundef %2, ptr noundef nonnull %3) #7
  br label %47

20:                                               ; preds = %11
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %24, label %21

21:                                               ; preds = %20
  %22 = icmp eq ptr %5, @__real_free
  %23 = icmp eq ptr %5, @free
  %or.cond5 = or i1 %22, %23
  br i1 %or.cond5, label %27, label %29

24:                                               ; preds = %20
  %25 = icmp eq ptr %4, @__real_malloc
  %26 = icmp eq ptr %4, @malloc
  %or.cond7 = or i1 %25, %26
  br i1 %or.cond7, label %27, label %29

27:                                               ; preds = %24, %21
  %28 = tail call ptr @internal_xrealloc(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2, ptr noundef null, ptr noundef nonnull @__real_free)
  br label %47

29:                                               ; preds = %24, %21
  %30 = icmp eq ptr %3, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %29
  %32 = tail call ptr %4(i64 noundef %2) #7
  br label %35

33:                                               ; preds = %29
  %34 = tail call ptr %4(i64 noundef %2, ptr noundef nonnull %3) #7
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi ptr [ %32, %31 ], [ %34, %33 ]
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load ptr, ptr %1, align 8, !tbaa !5
  %.not46 = icmp eq ptr %39, null
  br i1 %.not46, label %43, label %40

40:                                               ; preds = %38
  %41 = load ptr, ptr %0, align 8, !tbaa !5
  %42 = tail call i32 @internal_xfree(ptr noundef %41, ptr noundef nonnull %39)
  br label %46

43:                                               ; preds = %38
  %44 = select i1 %.not, ptr @__real_free, ptr %5
  %45 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void %44(ptr noundef %45) #7
  br label %46

46:                                               ; preds = %43, %40
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %16, %18, %27, %46, %35
  %.0 = phi ptr [ %28, %27 ], [ null, %46 ], [ %36, %35 ], [ %17, %16 ], [ %19, %18 ]
  ret ptr %.0
}

declare void @__real_free(ptr noundef) #4

declare ptr @__real_malloc(i64 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @internal_xrealloc(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

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 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { 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 #6 = { noreturn nounwind }
attributes #7 = { 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"}


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