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

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

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

23:                                               ; preds = %8
  %24 = load i32, ptr %16, align 4, !tbaa !10
  %25 = icmp ne i32 %24, 4
  br i1 %25, label %26, label %41

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

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

32:                                               ; preds = %29
  %33 = load ptr, ptr %9, 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_byteshuffle_network_avx512, ptr noundef @.str, i32 noundef 68, i32 noundef %40)
  store i32 1, ptr %18, align 4
  br label %87

41:                                               ; preds = %29, %26, %23, %8
  %42 = load i32, ptr %13, align 4, !tbaa !10
  %43 = load i32, ptr %16, align 4, !tbaa !10
  %44 = urem i32 %42, %43
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %51, label %46

46:                                               ; preds = %41
  %47 = load i32, ptr %14, align 4, !tbaa !10
  %48 = load i32, ptr %16, align 4, !tbaa !10
  %49 = urem i32 %47, %48
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %60

51:                                               ; preds = %46, %41
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %54 = icmp ult i32 1, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %51
  %56 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !10
  br label %58

57:                                               ; preds = %51
  br label %58

58:                                               ; preds = %57, %55
  %59 = phi i32 [ %56, %55 ], [ 1, %57 ]
  call void @libxsmm_handle_error(ptr noundef %52, i32 noundef 90000, ptr noundef @__func__.libxsmm_generator_transform_Xway_byteshuffle_network_avx512, ptr noundef @.str, i32 noundef 74, i32 noundef %59)
  store i32 1, ptr %18, align 4
  br label %87

60:                                               ; preds = %46
  store i32 0, ptr %17, align 4, !tbaa !10
  br label %61

61:                                               ; preds = %83, %60
  %62 = load i32, ptr %17, align 4, !tbaa !10
  %63 = load i32, ptr %16, align 4, !tbaa !10
  %64 = icmp ult i32 %62, %63
  br i1 %64, label %65, label %86

65:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i32, ptr %17, align 4, !tbaa !10
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %71 = zext i8 %70 to i32
  %72 = load i32, ptr %13, align 4, !tbaa !10
  %73 = add i32 %71, %72
  store i32 %73, ptr %19, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %74 = load i32, ptr %17, align 4, !tbaa !10
  %75 = load i32, ptr %14, align 4, !tbaa !10
  %76 = add i32 %74, %75
  store i32 %76, ptr %20, align 4, !tbaa !10
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load i32, ptr %15, align 4, !tbaa !10
  %79 = load i8, ptr %10, align 1, !tbaa !9
  %80 = load i32, ptr %12, align 4, !tbaa !10
  %81 = load i32, ptr %19, align 4, !tbaa !10
  %82 = load i32, ptr %20, align 4, !tbaa !10
  call void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef %77, i32 noundef %78, i8 noundef signext %79, i32 noundef %80, i32 noundef %81, i32 noundef %82, i32 noundef 0, i32 noundef 0, i8 noundef zeroext 0, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %83

83:                                               ; preds = %65
  %84 = load i32, ptr %17, align 4, !tbaa !10
  %85 = add i32 %84, 1
  store i32 %85, ptr %17, align 4, !tbaa !10
  br label %61, !llvm.loop !12

86:                                               ; preds = %61
  store i32 0, ptr %18, align 4
  br label %87

87:                                               ; preds = %86, %58, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  %88 = load i32, ptr %18, align 4
  switch i32 %88, label %90 [
    i32 0, label %89
    i32 1, label %89
  ]

89:                                               ; preds = %87, %87
  ret void

90:                                               ; preds = %87
  unreachable
}

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 [93 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_byteshuffle_network_avx512 = external hidden unnamed_addr constant [60 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

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 #0

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_transform_Xway_byteshuffle_network_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) local_unnamed_addr #1 {
  %9 = add i32 %7, -2
  %10 = tail call i32 @llvm.fshl.i32(i32 %9, i32 %9, i32 31)
  switch i32 %10, label %.loopexit.sink.split [
    i32 7, label %11
    i32 3, label %11
    i32 1, label %11
    i32 0, label %11
  ]

11:                                               ; preds = %8, %8, %8, %8
  %12 = urem i32 %4, %7
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %.loopexit.sink.split

13:                                               ; preds = %11
  %14 = urem i32 %5, %7
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %.preheader.preheader, label %.loopexit.sink.split

.preheader.preheader:                             ; preds = %13
  %umax = tail call i32 @llvm.umax.i32(i32 %7, 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 ]
  %15 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = add i32 %17, %4
  %19 = trunc nuw i64 %indvars.iv to i32
  %20 = add i32 %19, %5
  tail call void @libxsmm_x86_instruction_vec_compute_3reg_mask_sae_imm8(ptr noundef %0, i32 noundef %6, i8 noundef signext %1, i32 noundef %3, i32 noundef %18, i32 noundef %20, i32 noundef 0, i32 noundef 0, i8 noundef zeroext 0, i32 noundef 0) #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 = %11, %13, %8
  %.sink = phi i32 [ 68, %8 ], [ 74, %13 ], [ 74, %11 ]
  %21 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !10
  %22 = icmp ugt i32 %21, 1
  %23 = load i32, ptr @libxsmm_verbosity, align 4
  %24 = select i1 %22, i32 %23, i32 1
  tail call void @libxsmm_handle_error(ptr noundef %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_generator_transform_Xway_byteshuffle_network_avx512, ptr noundef nonnull @.str, i32 noundef %.sink, i32 noundef %24) #3
  br label %.loopexit

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

; 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 = { "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 = { 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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass