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

; 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
@internal_diff_function = external dso_local global ptr, align 64
@internal_memcmp_function = external dso_local global ptr, align 64
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_memory_init = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_memory_init(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sle i32 1101, %3
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  store ptr @internal_diff_avx2, ptr @internal_diff_function, align 64, !tbaa !9
  store ptr @internal_memcmp_avx2, ptr @internal_memcmp_function, align 64, !tbaa !9
  br label %17

6:                                                ; preds = %1
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sle i32 1006, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  store ptr @internal_diff_avx2, ptr @internal_diff_function, align 64, !tbaa !9
  store ptr @internal_memcmp_avx2, ptr @internal_memcmp_function, align 64, !tbaa !9
  br label %16

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

13:                                               ; preds = %10
  store ptr @internal_diff_sse, ptr @internal_diff_function, align 64, !tbaa !9
  store ptr @internal_memcmp_sse, ptr @internal_memcmp_function, align 64, !tbaa !9
  br label %15

14:                                               ; preds = %10
  store ptr @internal_diff_sw, ptr @internal_diff_function, align 64, !tbaa !9
  store ptr @internal_memcmp_sw, ptr @internal_memcmp_function, align 64, !tbaa !9
  br label %15

15:                                               ; preds = %14, %13
  br label %16

16:                                               ; preds = %15, %9
  br label %17

17:                                               ; preds = %16, %5
  %18 = load ptr, ptr @internal_diff_function, align 64, !tbaa !9
  %19 = icmp ne ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 291, ptr noundef @__PRETTY_FUNCTION__.libxsmm_memory_init) #4
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr @internal_memcmp_function, align 64, !tbaa !9
  %24 = icmp ne ptr null, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  br label %27

26:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 292, ptr noundef @__PRETTY_FUNCTION__.libxsmm_memory_init) #4
  unreachable

27:                                               ; preds = %25
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_avx2(ptr noundef, ptr noundef, i8 noundef zeroext) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_sse(ptr noundef, ptr noundef, i8 noundef zeroext) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_sw(ptr noundef, ptr noundef, i8 noundef zeroext) #3

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

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 = { inlinehint nounwind uwtable "min-legal-vector-width"="256" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cmov,+crc32,+cx8,+fma,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #3 = { inlinehint nounwind uwtable "min-legal-vector-width"="128" "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 = { 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, !10, i64 0}
!10 = !{!"any pointer", !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"

@internal_diff_function = external dso_local local_unnamed_addr global ptr, align 64
@internal_memcmp_function = external dso_local local_unnamed_addr global ptr, align 64

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @libxsmm_memory_init(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, 1005
  %3 = icmp sgt i32 %0, 1001
  %internal_diff_sse.internal_diff_sw = select i1 %3, ptr @internal_diff_sse, ptr @internal_diff_sw
  %internal_memcmp_sse.internal_memcmp_sw = select i1 %3, ptr @internal_memcmp_sse, ptr @internal_memcmp_sw
  %internal_diff_avx2.sink = select i1 %2, ptr @internal_diff_avx2, ptr %internal_diff_sse.internal_diff_sw
  %internal_memcmp_avx2.sink = select i1 %2, ptr @internal_memcmp_avx2, ptr %internal_memcmp_sse.internal_memcmp_sw
  store ptr %internal_diff_avx2.sink, ptr @internal_diff_function, align 64, !tbaa !5
  store ptr %internal_memcmp_avx2.sink, ptr @internal_memcmp_function, align 64, !tbaa !5
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_avx2(ptr noundef, ptr noundef, i8 noundef zeroext) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_sse(ptr noundef, ptr noundef, i8 noundef zeroext) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @internal_diff_sw(ptr noundef, ptr noundef, i8 noundef zeroext) #2

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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 = { inlinehint nounwind uwtable "min-legal-vector-width"="256" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cmov,+crc32,+cx8,+fma,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="128" "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" }

!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: GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass