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

@__func__.libxsmm_generator_transform_Xway_unpack_network_avx_avx512 = external hidden unnamed_addr constant [59 x i8], align 1
@.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

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

27:                                               ; preds = %9
  %28 = load i32, ptr %18, align 4, !tbaa !10
  %29 = icmp ne i32 %28, 4
  br i1 %29, label %30, label %45

30:                                               ; preds = %27
  %31 = load i32, ptr %18, align 4, !tbaa !10
  %32 = icmp ne i32 %31, 8
  br i1 %32, label %33, label %45

33:                                               ; preds = %30
  %34 = load i32, ptr %18, align 4, !tbaa !10
  %35 = icmp ne i32 %34, 16
  br i1 %35, label %36, label %45

36:                                               ; preds = %33
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %39 = icmp ult i32 1, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %36
  %41 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %43

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42, %40
  %44 = phi i32 [ %41, %40 ], [ 1, %42 ]
  call void @libxsmm_handle_error(ptr noundef %37, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_unpack_network_avx_avx512, ptr noundef @.str, i32 noundef 29, i32 noundef %44)
  store i32 1, ptr %20, align 4
  br label %103

45:                                               ; preds = %33, %30, %27, %9
  %46 = load i32, ptr %13, align 4, !tbaa !10
  %47 = load i32, ptr %18, align 4, !tbaa !10
  %48 = urem i32 %46, %47
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %55, label %50

50:                                               ; preds = %45
  %51 = load i32, ptr %14, align 4, !tbaa !10
  %52 = load i32, ptr %18, align 4, !tbaa !10
  %53 = urem i32 %51, %52
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %64

55:                                               ; preds = %50, %45
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %58 = icmp ult i32 1, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  %60 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %62

61:                                               ; preds = %55
  br label %62

62:                                               ; preds = %61, %59
  %63 = phi i32 [ %60, %59 ], [ 1, %61 ]
  call void @libxsmm_handle_error(ptr noundef %56, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_unpack_network_avx_avx512, ptr noundef @.str, i32 noundef 35, i32 noundef %63)
  store i32 1, ptr %20, align 4
  br label %103

64:                                               ; preds = %50
  store i32 0, ptr %19, align 4, !tbaa !10
  br label %65

65:                                               ; preds = %99, %64
  %66 = load i32, ptr %19, align 4, !tbaa !10
  %67 = load i32, ptr %18, align 4, !tbaa !10
  %68 = icmp ult i32 %66, %67
  br i1 %68, label %69, label %102

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %70 = load i32, ptr %19, align 4, !tbaa !10
  %71 = urem i32 %70, 2
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = load i32, ptr %16, align 4, !tbaa !10
  br label %77

75:                                               ; preds = %69
  %76 = load i32, ptr %17, align 4, !tbaa !10
  br label %77

77:                                               ; preds = %75, %73
  %78 = phi i32 [ %74, %73 ], [ %76, %75 ]
  store i32 %78, ptr %21, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load i32, ptr %19, align 4, !tbaa !10
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !9
  %84 = zext i8 %83 to i32
  %85 = load i32, ptr %13, align 4, !tbaa !10
  %86 = add i32 %84, %85
  store i32 %86, ptr %22, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  %87 = load i32, ptr %22, align 4, !tbaa !10
  %88 = load i32, ptr %15, align 4, !tbaa !10
  %89 = add i32 %87, %88
  store i32 %89, ptr %23, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  %90 = load i32, ptr %19, align 4, !tbaa !10
  %91 = load i32, ptr %14, align 4, !tbaa !10
  %92 = add i32 %90, %91
  store i32 %92, ptr %24, align 4, !tbaa !10
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load i32, ptr %21, align 4, !tbaa !10
  %95 = load i8, ptr %11, align 1, !tbaa !9
  %96 = load i32, ptr %23, align 4, !tbaa !10
  %97 = load i32, ptr %22, align 4, !tbaa !10
  %98 = load i32, ptr %24, align 4, !tbaa !10
  call void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef %93, i32 noundef %94, i8 noundef signext %95, i32 noundef %96, i32 noundef %97, i32 noundef %98, i32 noundef 0, i32 noundef 0, i8 noundef zeroext 0, i32 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %99

99:                                               ; preds = %77
  %100 = load i32, ptr %19, align 4, !tbaa !10
  %101 = add i32 %100, 1
  store i32 %101, ptr %19, align 4, !tbaa !10
  br label %65, !llvm.loop !12

102:                                              ; preds = %65
  store i32 0, ptr %20, align 4
  br label %103

103:                                              ; preds = %102, %62, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  %104 = load i32, ptr %20, align 4
  switch i32 %104, label %106 [
    i32 0, label %105
    i32 1, label %105
  ]

105:                                              ; preds = %103, %103
  ret void

106:                                              ; preds = %103
  unreachable
}

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

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

declare void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i32 noundef) #2

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

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

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

@__func__.libxsmm_generator_transform_Xway_unpack_network_avx_avx512 = external hidden unnamed_addr constant [59 x i8], align 1
@.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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_transform_Xway_unpack_network_avx_avx512(ptr noundef %0, i8 noundef signext %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = add i32 %8, -2
  %11 = tail call i32 @llvm.fshl.i32(i32 %10, i32 %10, i32 31)
  switch i32 %11, label %.loopexit.sink.split [
    i32 7, label %12
    i32 3, label %12
    i32 1, label %12
    i32 0, label %12
  ]

12:                                               ; preds = %9, %9, %9, %9
  %13 = urem i32 %3, %8
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %.loopexit.sink.split

14:                                               ; preds = %12
  %15 = urem i32 %4, %8
  %.not33 = icmp eq i32 %15, 0
  br i1 %.not33, label %.preheader.preheader, label %.loopexit.sink.split

.preheader.preheader:                             ; preds = %14
  %umax = tail call i32 @llvm.umax.i32(i32 %8, i32 1)
  %wide.trip.count = zext i32 %umax to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %.preheader ]
  %16 = trunc nuw i64 %indvars.iv to i32
  %17 = and i32 %16, 1
  %18 = icmp eq i32 %17, 0
  %19 = select i1 %18, i32 %6, i32 %7
  %20 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = add i32 %22, %3
  %24 = add i32 %23, %5
  %25 = add i32 %16, %4
  tail call void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef %0, i32 noundef %19, i8 noundef signext %1, i32 noundef %24, i32 noundef %23, i32 noundef %25, i32 noundef 0, i32 noundef 0, i8 noundef zeroext 0, i32 noundef 1024) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !8

.loopexit.sink.split:                             ; preds = %12, %14, %9
  %.sink = phi i32 [ 29, %9 ], [ 35, %14 ], [ 35, %12 ]
  %26 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %27 = icmp ugt i32 %26, 1
  %28 = load i32, ptr @libxsmm_verbosity, align 4
  %29 = select i1 %27, i32 %28, i32 1
  tail call void @libxsmm_handle_error(ptr noundef %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_generator_transform_Xway_unpack_network_avx_avx512, ptr noundef nonnull @.str, i32 noundef %.sink, i32 noundef %29) #3
  br label %.loopexit

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

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

declare void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef, i32 noundef, i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #1

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

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

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


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