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

; 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.libxsmm_gemm_shape = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_gemm_batch_flags = external hidden unnamed_addr constant [96 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@libxsmm_target_archid = external global i32, align 4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #2

declare zeroext i8 @libxsmm_typesize(i32 noundef) #3

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

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %21

20:                                               ; preds = %16, %4
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.1, i32 noundef 938, ptr noundef @__PRETTY_FUNCTION__.libxsmm_gemm_batch_flags) #6
  unreachable

21:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %22 = call ptr @getenv(ptr noundef @.str.19) #5
  store ptr %22, ptr %12, align 8, !tbaa !9
  %23 = load ptr, ptr %12, align 8, !tbaa !9
  %24 = icmp eq ptr null, %23
  br i1 %24, label %30, label %25

25:                                               ; preds = %21
  %26 = load ptr, ptr %12, align 8, !tbaa !9
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 48, %28
  br i1 %29, label %30, label %61

30:                                               ; preds = %25, %21
  %31 = load i32, ptr @libxsmm_target_archid, align 4, !tbaa !5
  %32 = call i32 @libxsmm_cpuid_vlen32(i32 noundef %31)
  %33 = mul nsw i32 4, %32
  store i32 %33, ptr %11, align 4, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = ptrtoint ptr %34 to i64
  %36 = load i32, ptr %11, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = sub i64 %37, 1
  %39 = and i64 %35, %38
  %40 = icmp eq i64 0, %39
  br i1 %40, label %41, label %60

41:                                               ; preds = %30
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.libxsmm_gemm_shape, ptr %42, i32 0, i32 8
  %44 = load i32, ptr %43, align 4, !tbaa !12
  %45 = call zeroext i8 @libxsmm_typesize(i32 noundef %44)
  %46 = zext i8 %45 to i32
  store i32 %46, ptr %10, align 4, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.libxsmm_gemm_shape, ptr %47, i32 0, i32 5
  %49 = load i32, ptr %48, align 4, !tbaa !14
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = mul nsw i32 %49, %50
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 1
  %54 = and i32 %51, %53
  %55 = icmp eq i32 0, %54
  br i1 %55, label %56, label %59

56:                                               ; preds = %41
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = or i32 %57, 48
  store i32 %58, ptr %9, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %56, %41
  br label %60

60:                                               ; preds = %59, %30
  br label %61

61:                                               ; preds = %60, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = icmp ne ptr null, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %61
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %64
  %69 = load i32, ptr %11, align 4, !tbaa !5
  br label %71

70:                                               ; preds = %64
  br label %71

71:                                               ; preds = %70, %68
  %72 = phi i32 [ %69, %68 ], [ 0, %70 ]
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 %72, ptr %73, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %71, %61
  %75 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %75
}

declare i32 @libxsmm_cpuid_vlen32(i32 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 32}
!13 = !{!"libxsmm_gemm_shape", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36}
!14 = !{!13, !6, i64 20}


; 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 [68 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_gemm_batch_flags = external hidden unnamed_addr constant [96 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@libxsmm_target_archid = external local_unnamed_addr global i32, align 4

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

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #1

declare zeroext i8 @libxsmm_typesize(i32 noundef) local_unnamed_addr #2

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

7:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.1, i32 noundef 938, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_gemm_batch_flags) #4
  unreachable

8:                                                ; preds = %4
  %9 = tail call ptr @getenv(ptr noundef nonnull @.str.19) #5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %13, label %11

11:                                               ; preds = %8
  %12 = load i8, ptr %9, align 1, !tbaa !5
  %.not = icmp eq i8 %12, 48
  br i1 %.not, label %34, label %13

13:                                               ; preds = %11, %8
  %14 = load i32, ptr @libxsmm_target_archid, align 4, !tbaa !8
  %15 = tail call i32 @libxsmm_cpuid_vlen32(i32 noundef %14) #5
  %16 = shl nsw i32 %15, 2
  %17 = ptrtoint ptr %2 to i64
  %18 = sext i32 %16 to i64
  %19 = add nsw i64 %18, -1
  %20 = and i64 %19, %17
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %34

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %1, i64 32
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = tail call zeroext i8 @libxsmm_typesize(i32 noundef %24) #5
  %26 = zext i8 %25 to i32
  %27 = getelementptr inbounds i8, ptr %1, i64 20
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = mul nsw i32 %28, %26
  %30 = add nsw i32 %16, -1
  %31 = and i32 %29, %30
  %32 = icmp eq i32 %31, 0
  %33 = or i32 %0, 48
  %spec.select = select i1 %32, i32 %33, i32 %0
  br label %34

34:                                               ; preds = %22, %13, %11
  %.019 = phi i32 [ 0, %13 ], [ 0, %11 ], [ %26, %22 ]
  %.018 = phi i32 [ %16, %13 ], [ 0, %11 ], [ %16, %22 ]
  %.0 = phi i32 [ %0, %13 ], [ %0, %11 ], [ %spec.select, %22 ]
  %.not24 = icmp eq ptr %3, null
  br i1 %.not24, label %38, label %35

35:                                               ; preds = %34
  %36 = icmp slt i32 %.019, %.018
  %37 = select i1 %36, i32 %.018, i32 0
  store i32 %37, ptr %3, align 4, !tbaa !8
  br label %38

38:                                               ; preds = %35, %34
  ret i32 %.0
}

declare i32 @libxsmm_cpuid_vlen32(i32 noundef) local_unnamed_addr #2

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 = { nofree nounwind memory(read) "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 = { 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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !9, i64 32}
!11 = !{!"libxsmm_gemm_shape", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36}
!12 = !{!11, !9, i64 20}


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