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

; 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 = external hidden unnamed_addr constant [97 x i8], align 1
@libxsmm_ninit = external global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512 = external hidden unnamed_addr constant [54 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

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 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 void @libxsmm_generator_transform_Xway_full_load_avx_avx512(ptr noundef %0, i8 noundef signext %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, i32 noundef %9) #2 {
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i8 %1, ptr %12, align 1, !tbaa !9
  store i32 %2, ptr %13, align 4, !tbaa !10
  store i32 %3, ptr %14, align 4, !tbaa !10
  store i32 %4, ptr %15, align 4, !tbaa !10
  store i32 %5, ptr %16, align 4, !tbaa !10
  store i32 %6, ptr %17, align 4, !tbaa !10
  store i32 %7, ptr %18, align 4, !tbaa !10
  store i32 %8, ptr %19, align 4, !tbaa !10
  store i32 %9, ptr %20, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !10
  %24 = load i32, ptr %17, align 4, !tbaa !10
  %25 = icmp ne i32 %24, 8
  br i1 %25, label %26, label %41

26:                                               ; preds = %10
  %27 = load i32, ptr %17, align 4, !tbaa !10
  %28 = icmp ne i32 %27, 16
  br i1 %28, label %29, label %41

29:                                               ; preds = %26
  %30 = load i32, ptr %17, align 4, !tbaa !10
  %31 = icmp ne i32 %30, 32
  br i1 %31, label %32, label %41

32:                                               ; preds = %29
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %35 = icmp ult i32 1, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %39

38:                                               ; preds = %32
  br label %39

39:                                               ; preds = %38, %36
  %40 = phi i32 [ %37, %36 ], [ 1, %38 ]
  call void @libxsmm_handle_error(ptr noundef %33, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512, ptr noundef @.str, i32 noundef 64, i32 noundef %40)
  store i32 1, ptr %22, align 4
  br label %102

41:                                               ; preds = %29, %26, %10
  %42 = load i32, ptr %14, align 4, !tbaa !10
  %43 = load i32, ptr %17, align 4, !tbaa !10
  %44 = urem i32 %42, %43
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %55

46:                                               ; preds = %41
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %49 = icmp ult i32 1, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %53

52:                                               ; preds = %46
  br label %53

53:                                               ; preds = %52, %50
  %54 = phi i32 [ %51, %50 ], [ 1, %52 ]
  call void @libxsmm_handle_error(ptr noundef %47, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512, ptr noundef @.str, i32 noundef 69, i32 noundef %54)
  store i32 1, ptr %22, align 4
  br label %102

55:                                               ; preds = %41
  %56 = load i32, ptr %18, align 4, !tbaa !10
  %57 = load i32, ptr %17, align 4, !tbaa !10
  %58 = icmp ugt i32 %56, %57
  br i1 %58, label %59, label %68

59:                                               ; preds = %55
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %62 = icmp ult i32 1, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %66

65:                                               ; preds = %59
  br label %66

66:                                               ; preds = %65, %63
  %67 = phi i32 [ %64, %63 ], [ 1, %65 ]
  call void @libxsmm_handle_error(ptr noundef %60, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512, ptr noundef @.str, i32 noundef 74, i32 noundef %67)
  store i32 1, ptr %22, align 4
  br label %102

68:                                               ; preds = %55
  store i32 0, ptr %21, align 4, !tbaa !10
  br label %69

69:                                               ; preds = %98, %68
  %70 = load i32, ptr %21, align 4, !tbaa !10
  %71 = load i32, ptr %17, align 4, !tbaa !10
  %72 = icmp ult i32 %70, %71
  br i1 %72, label %73, label %101

73:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  %74 = load i32, ptr %21, align 4, !tbaa !10
  %75 = load i32, ptr %14, align 4, !tbaa !10
  %76 = add i32 %74, %75
  store i32 %76, ptr %23, align 4, !tbaa !10
  %77 = load i32, ptr %21, align 4, !tbaa !10
  %78 = load i32, ptr %18, align 4, !tbaa !10
  %79 = icmp ult i32 %77, %78
  br i1 %79, label %80, label %91

80:                                               ; preds = %73
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = load i32, ptr %16, align 4, !tbaa !10
  %83 = load i32, ptr %13, align 4, !tbaa !10
  %84 = load i32, ptr %21, align 4, !tbaa !10
  %85 = load i32, ptr %15, align 4, !tbaa !10
  %86 = mul i32 %84, %85
  %87 = load i8, ptr %12, align 1, !tbaa !9
  %88 = load i32, ptr %23, align 4, !tbaa !10
  %89 = load i32, ptr %19, align 4, !tbaa !10
  %90 = load i32, ptr %20, align 4, !tbaa !10
  call void @libxsmm_x86_instruction_vex_evex_mask_mov(ptr noundef %81, i32 noundef %82, i32 noundef %83, i32 noundef 127, i32 noundef 0, i32 noundef %86, i8 noundef signext %87, i32 noundef %88, i32 noundef %89, i32 noundef %90, i32 noundef 0)
  br label %97

91:                                               ; preds = %73
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = load i8, ptr %12, align 1, !tbaa !9
  %94 = load i32, ptr %23, align 4, !tbaa !10
  %95 = load i32, ptr %23, align 4, !tbaa !10
  %96 = load i32, ptr %23, align 4, !tbaa !10
  call void @libxsmm_x86_instruction_vec_compute_3reg(ptr noundef %92, i32 noundef 805639919, i8 noundef signext %93, i32 noundef %94, i32 noundef %95, i32 noundef %96)
  br label %97

97:                                               ; preds = %91, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %21, align 4, !tbaa !10
  %100 = add i32 %99, 1
  store i32 %100, ptr %21, align 4, !tbaa !10
  br label %69, !llvm.loop !12

101:                                              ; preds = %69
  store i32 0, ptr %22, align 4
  br label %102

102:                                              ; preds = %101, %66, %53, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  %103 = load i32, ptr %22, align 4
  switch i32 %103, label %105 [
    i32 0, label %104
    i32 1, label %104
  ]

104:                                              ; preds = %102, %102
  ret void

105:                                              ; preds = %102
  unreachable
}

declare void @libxsmm_x86_instruction_vex_evex_mask_mov(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare void @libxsmm_x86_instruction_vec_compute_3reg(ptr noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 = external hidden unnamed_addr constant [97 x i8], align 1
@libxsmm_ninit = external local_unnamed_addr global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512 = external hidden unnamed_addr constant [54 x i8], align 1

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_transform_Xway_full_load_avx_avx512(ptr noundef %0, i8 noundef signext %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, i32 noundef %9) local_unnamed_addr #1 {
  switch i32 %6, label %.loopexit.sink.split [
    i32 32, label %11
    i32 16, label %11
    i32 8, label %11
  ]

11:                                               ; preds = %10, %10, %10
  %12 = urem i32 %3, %6
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %.loopexit.sink.split

13:                                               ; preds = %11
  %14 = icmp ugt i32 %7, %6
  br i1 %14, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %13, %20
  %.035 = phi i32 [ %21, %20 ], [ 0, %13 ]
  %15 = add i32 %.035, %3
  %16 = icmp ult i32 %.035, %7
  br i1 %16, label %17, label %19

17:                                               ; preds = %.preheader
  %18 = mul i32 %.035, %4
  tail call void @libxsmm_x86_instruction_vex_evex_mask_mov(ptr noundef %0, i32 noundef %5, i32 noundef %2, i32 noundef 127, i32 noundef 0, i32 noundef %18, i8 noundef signext %1, i32 noundef %15, i32 noundef %8, i32 noundef %9, i32 noundef 0) #2
  br label %20

19:                                               ; preds = %.preheader
  tail call void @libxsmm_x86_instruction_vec_compute_3reg(ptr noundef %0, i32 noundef 805639919, i8 noundef signext %1, i32 noundef %15, i32 noundef %15, i32 noundef %15) #2
  br label %20

20:                                               ; preds = %19, %17
  %21 = add nuw i32 %.035, 1
  %exitcond.not = icmp eq i32 %21, %6
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !5

.loopexit.sink.split:                             ; preds = %13, %11, %10
  %.sink = phi i32 [ 64, %10 ], [ 69, %11 ], [ 74, %13 ]
  %22 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !7
  %23 = icmp ugt i32 %22, 1
  %24 = load i32, ptr @libxsmm_verbosity, align 4
  %25 = select i1 %23, i32 %24, i32 1
  tail call void @libxsmm_handle_error(ptr noundef %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_generator_transform_Xway_full_load_avx_avx512, ptr noundef nonnull @.str, i32 noundef %.sink, i32 noundef %25) #2
  br label %.loopexit

.loopexit:                                        ; preds = %20, %.loopexit.sink.split
  ret void
}

declare void @libxsmm_x86_instruction_vex_evex_mask_mov(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @libxsmm_x86_instruction_vec_compute_3reg(ptr noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass