; 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
@libxsmm_target_archid = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_aligned = external hidden unnamed_addr constant [57 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 i32 @libxsmm_aligned(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %11 = load i32, ptr @libxsmm_target_archid, align 4, !tbaa !9
  %12 = call i32 @libxsmm_cpuid_vlen32(i32 noundef %11)
  %13 = mul nsw i32 4, %12
  store i32 %13, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  store i64 %15, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp ne i32 0, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = and i32 %19, %21
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  br label %26

25:                                               ; preds = %18, %3
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 89, ptr noundef @__PRETTY_FUNCTION__.libxsmm_aligned) #6
  unreachable

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

29:                                               ; preds = %26
  %30 = load i64, ptr %8, align 8, !tbaa !11
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = sub i64 %32, 1
  %34 = and i64 %30, %33
  %35 = icmp ne i64 %34, 0
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i32
  store i32 %37, ptr %9, align 4, !tbaa !9
  br label %60

38:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %39 = load i64, ptr %8, align 8, !tbaa !11
  %40 = icmp ne i64 0, %39
  %41 = zext i1 %40 to i32
  %42 = load i64, ptr %8, align 8, !tbaa !11
  %43 = call i64 @llvm.cttz.i64(i64 %42, i1 true)
  %44 = trunc i64 %43 to i32
  %45 = mul nsw i32 %41, %44
  store i32 %45, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp ugt i32 32, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %38
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = shl i32 1, %49
  br label %52

51:                                               ; preds = %38
  br label %52

52:                                               ; preds = %51, %48
  %53 = phi i32 [ %50, %48 ], [ 2147483647, %51 ]
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %53, ptr %54, align 4, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp sle i32 %55, %57
  %59 = zext i1 %58 to i32
  store i32 %59, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %60

60:                                               ; preds = %52, %29
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %77

63:                                               ; preds = %60
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = icmp eq ptr null, %64
  br i1 %65, label %75, label %66

66:                                               ; preds = %63
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = sub i64 %70, 1
  %72 = and i64 %68, %71
  %73 = icmp ne i64 %72, 0
  %74 = xor i1 %73, true
  br label %75

75:                                               ; preds = %66, %63
  %76 = phi i1 [ true, %63 ], [ %74, %66 ]
  br label %77

77:                                               ; preds = %75, %60
  %78 = phi i1 [ false, %60 ], [ %76, %75 ]
  %79 = zext i1 %78 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %79
}

declare i32 @libxsmm_cpuid_vlen32(i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.cttz.i64(i64, i1 immarg) #4

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 = { "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 nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 0}
!12 = !{!"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
@libxsmm_target_archid = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_aligned = external hidden unnamed_addr constant [57 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
define dso_local range(i32 0, 2) i32 @libxsmm_aligned(ptr noundef %0, ptr noundef readonly %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = load i32, ptr @libxsmm_target_archid, align 4, !tbaa !5
  %5 = tail call i32 @libxsmm_cpuid_vlen32(i32 noundef %4) #5
  %6 = shl nsw i32 %5, 2
  %7 = ptrtoint ptr %0 to i64
  %.not = icmp ne i32 %5, 0
  %8 = tail call range(i32 0, 31) i32 @llvm.ctpop.i32(i32 %6)
  %.not20 = icmp ult i32 %8, 2
  %or.cond = select i1 %.not, i1 %.not20, i1 false
  br i1 %or.cond, label %10, label %9

9:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 89, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_aligned) #6
  unreachable

10:                                               ; preds = %3
  %11 = icmp eq ptr %2, null
  br i1 %11, label %12, label %16

12:                                               ; preds = %10
  %13 = sext i32 %6 to i64
  %14 = add nsw i64 %13, -1
  %15 = and i64 %14, %7
  %.not22 = icmp eq i64 %15, 0
  br i1 %.not22, label %23, label %31

16:                                               ; preds = %10
  %.not21 = icmp eq ptr %0, null
  %17 = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %7, i1 true)
  %18 = trunc nuw nsw i64 %17 to i32
  %19 = select i1 %.not21, i32 0, i32 %18
  %20 = icmp ult i32 %19, 32
  %21 = shl nuw i32 1, %19
  %22 = select i1 %20, i32 %21, i32 2147483647
  store i32 %22, ptr %2, align 4, !tbaa !5
  %.not24 = icmp sgt i32 %6, %22
  br i1 %.not24, label %31, label %23

23:                                               ; preds = %12, %16
  %24 = icmp eq ptr %1, null
  br i1 %24, label %31, label %25

25:                                               ; preds = %23
  %26 = load i64, ptr %1, align 8, !tbaa !9
  %27 = sext i32 %6 to i64
  %28 = add nsw i64 %27, -1
  %29 = and i64 %26, %28
  %.not23 = icmp eq i64 %29, 0
  %30 = zext i1 %.not23 to i32
  br label %31

31:                                               ; preds = %12, %23, %25, %16
  %32 = phi i32 [ 0, %16 ], [ 1, %23 ], [ %30, %25 ], [ 0, %12 ]
  ret i32 %32
}

declare i32 @libxsmm_cpuid_vlen32(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.cttz.i64(i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #4

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 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


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