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

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [44 x i8], align 1
@internal_pmallocs = external dso_local global [16 x i32], align 64
@.str.86 = external hidden unnamed_addr constant [38 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_pmalloc = external hidden unnamed_addr constant [41 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.88 = external hidden unnamed_addr constant [22 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
declare void @llvm.x86.sse2.pause() #2

; Function Attrs: nounwind
declare i32 @sched_yield() #3

declare i32 @libxsmm_crc32_u64(i32 noundef, ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @libxsmm_pmalloc(ptr noundef %0, ptr noundef %1) #5 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  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 4, ptr %5) #2
  %10 = call i32 (i32, ptr, ...) @libxsmm_crc32_u64(i32 noundef 1051981, ptr noundef %3)
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = and i32 %11, 15
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr @internal_pmallocs, i64 %13
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = icmp ne ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17, %2
  call void @__assert_fail(ptr noundef @.str.86, ptr noundef @.str.1, i32 noundef 2691, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = ptrtoint ptr %23 to i64
  %25 = and i64 %24, 3
  %26 = icmp eq i64 0, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %29

28:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.22, ptr noundef @.str.1, i32 noundef 2692, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %62, %29
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = atomicrmw or ptr %31, i32 1 seq_cst, align 4
  %33 = icmp eq i32 0, %32
  %34 = xor i1 %33, true
  br i1 %34, label %35, label %63

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %55, %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %43, %37
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %38
  call void @llvm.x86.sse2.pause()
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %9, align 4, !tbaa !9
  br label %38, !llvm.loop !11

46:                                               ; preds = %38
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = icmp slt i32 %47, 4096
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = mul nsw i32 %50, 2
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %54

52:                                               ; preds = %46
  store i32 4096, ptr %8, align 4, !tbaa !9
  %53 = call i32 @sched_yield() #2
  br label %54

54:                                               ; preds = %52, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load volatile i32, ptr %56, align 4, !tbaa !9
  %58 = and i32 %57, 1
  %59 = icmp ne i32 0, %58
  br i1 %59, label %37, label %60, !llvm.loop !13

60:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %30, !llvm.loop !14

63:                                               ; preds = %30
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load volatile i32, ptr %64, align 4, !tbaa !9
  %66 = icmp ne i32 0, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  br label %69

68:                                               ; preds = %63
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.1, i32 noundef 2692, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

69:                                               ; preds = %67
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i64, ptr %70, align 8, !tbaa !15
  %72 = icmp ult i64 0, %71
  br i1 %72, label %73, label %78

73:                                               ; preds = %69
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load i64, ptr %74, align 8, !tbaa !15
  %76 = icmp ne i64 -1, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %73
  br label %79

78:                                               ; preds = %73, %69
  call void @__assert_fail(ptr noundef @.str.87, ptr noundef @.str.1, i32 noundef 2693, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

79:                                               ; preds = %77
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i64, ptr %81, align 8, !tbaa !15
  %83 = add i64 %82, -1
  store i64 %83, ptr %81, align 8, !tbaa !15
  %84 = getelementptr inbounds ptr, ptr %80, i64 %83
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  store ptr %85, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i64, ptr %87, align 8, !tbaa !15
  %89 = getelementptr inbounds ptr, ptr %86, i64 %88
  store ptr null, ptr %89, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load volatile i32, ptr %90, align 4, !tbaa !9
  %92 = icmp ne i32 0, %91
  br i1 %92, label %93, label %94

93:                                               ; preds = %79
  br label %95

94:                                               ; preds = %79
  call void @__assert_fail(ptr noundef @.str.25, ptr noundef @.str.1, i32 noundef 2698, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

95:                                               ; preds = %93
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  store atomic i32 0, ptr %96 release, align 4
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = icmp ne ptr null, %97
  br i1 %98, label %99, label %100

99:                                               ; preds = %95
  br label %101

100:                                              ; preds = %95
  call void @__assert_fail(ptr noundef @.str.88, ptr noundef @.str.1, i32 noundef 2699, ptr noundef @__PRETTY_FUNCTION__.libxsmm_pmalloc) #6
  unreachable

101:                                              ; preds = %99
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret ptr %102
}

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 }
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 = { "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 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 }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !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.23 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [44 x i8], align 1
@internal_pmallocs = external dso_local global [16 x i32], align 64
@.str.86 = external hidden unnamed_addr constant [38 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_pmalloc = external hidden unnamed_addr constant [41 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.88 = external hidden unnamed_addr constant [22 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
declare void @llvm.x86.sse2.pause() #1

; Function Attrs: nounwind
declare i32 @sched_yield() local_unnamed_addr #2

declare i32 @libxsmm_crc32_u64(i32 noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @libxsmm_pmalloc(ptr noundef %0, ptr noundef %1) local_unnamed_addr #4 {
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = call i32 (i32, ptr, ...) @libxsmm_crc32_u64(i32 noundef 1051981, ptr noundef nonnull %3) #1
  %5 = and i32 %4, 15
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds i32, ptr @internal_pmallocs, i64 %6
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  %10 = icmp ne ptr %1, null
  %or.cond = and i1 %10, %9
  br i1 %or.cond, label %.preheader29, label %12

.preheader29:                                     ; preds = %2
  %11 = atomicrmw or ptr %7, i32 1 seq_cst, align 4
  %.not31 = icmp eq i32 %11, 0
  br i1 %.not31, label %._crit_edge32, label %.preheader

12:                                               ; preds = %2
  call void @__assert_fail(ptr noundef nonnull @.str.86, ptr noundef nonnull @.str.1, i32 noundef 2691, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_pmalloc) #5
  unreachable

.preheader:                                       ; preds = %.preheader29, %.preheader.backedge
  %.019 = phi i32 [ %.019.be, %.preheader.backedge ], [ 1, %.preheader29 ]
  %13 = icmp sgt i32 %.019, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %.preheader
  %xtraiter = and i32 %.019, 7
  %14 = icmp ult i32 %.019, 8
  br i1 %14, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %.019, 2147483640
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  call void @llvm.x86.sse2.pause()
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  call void @llvm.x86.sse2.pause()
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %15 = icmp slt i32 %.019, 4096
  br i1 %15, label %._crit_edge.thread, label %17

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %16 = shl i32 %.019, 1
  br label %19

17:                                               ; preds = %._crit_edge
  %18 = call i32 @sched_yield() #1
  br label %19

19:                                               ; preds = %17, %._crit_edge.thread
  %.1 = phi i32 [ %16, %._crit_edge.thread ], [ 4096, %17 ]
  %20 = load volatile i32, ptr %7, align 4, !tbaa !13
  %21 = and i32 %20, 1
  %.not28 = icmp eq i32 %21, 0
  br i1 %.not28, label %22, label %.preheader.backedge

.preheader.backedge:                              ; preds = %19, %22
  %.019.be = phi i32 [ %.1, %19 ], [ 1, %22 ]
  br label %.preheader, !llvm.loop !15

22:                                               ; preds = %19
  %23 = atomicrmw or ptr %7, i32 1 seq_cst, align 4
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %._crit_edge32, label %.preheader.backedge

._crit_edge32:                                    ; preds = %22, %.preheader29
  %24 = load volatile i32, ptr %7, align 4, !tbaa !13
  %.not23 = icmp eq i32 %24, 0
  br i1 %.not23, label %25, label %26

25:                                               ; preds = %._crit_edge32
  call void @__assert_fail(ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.1, i32 noundef 2692, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_pmalloc) #5
  unreachable

26:                                               ; preds = %._crit_edge32
  %27 = load i64, ptr %1, align 8, !tbaa !16
  switch i64 %27, label %29 [
    i64 0, label %28
    i64 -1, label %28
  ]

28:                                               ; preds = %26, %26
  call void @__assert_fail(ptr noundef nonnull @.str.87, ptr noundef nonnull @.str.1, i32 noundef 2693, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_pmalloc) #5
  unreachable

29:                                               ; preds = %26
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = add i64 %27, -1
  store i64 %31, ptr %1, align 8, !tbaa !16
  %32 = getelementptr inbounds ptr, ptr %30, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr null, ptr %32, align 8, !tbaa !5
  %34 = load volatile i32, ptr %7, align 4, !tbaa !13
  %.not26 = icmp eq i32 %34, 0
  br i1 %.not26, label %35, label %36

35:                                               ; preds = %29
  call void @__assert_fail(ptr noundef nonnull @.str.25, ptr noundef nonnull @.str.1, i32 noundef 2698, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_pmalloc) #5
  unreachable

36:                                               ; preds = %29
  store atomic i32 0, ptr %7 release, align 4
  %.not27 = icmp eq ptr %33, null
  br i1 %.not27, label %37, label %38

37:                                               ; preds = %36
  call void @__assert_fail(ptr noundef nonnull @.str.88, ptr noundef nonnull @.str.1, i32 noundef 2699, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_pmalloc) #5
  unreachable

38:                                               ; preds = %36
  ret ptr %33
}

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 }
attributes #2 = { 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 = { "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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !10}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}


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