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

; 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_gp_reg_mapping_struct = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.libxsmm_gemm_descriptor = type <{ i32, i32, i32, i32, i32, i32, i32, i8, [3 x i8], i8, i64, i64, i8, i32, i32, i32, i16, i16, i8, i8, i8, i8, i16, i16, i16, i16, i16, i16, i32, i32, i32, i8 }>

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

declare void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef, i32 noundef, i32 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
declare dso_local void @libxsmm_generator_gemm_setval_stack_var_rv64(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_generator_gemm_setup_stack_frame_fill_ext_gemm_stack_vars_rv64(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef) #1

declare i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_gemm_setup_stack_frame_rv64(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.libxsmm_gp_reg_mapping_struct, ptr %11, i32 0, i32 23
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %9, align 4, !tbaa !12
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %14, i32 noundef 19, i32 noundef 2, i32 noundef 27, i32 noundef 0)
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %15, i32 noundef 19, i32 noundef 2, i32 noundef 2, i32 noundef -192)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %16, i32 0, i32 6
  %18 = load i32, ptr %17, align 1, !tbaa !13
  %19 = and i32 32768, %18
  %20 = icmp eq i32 %19, 32768
  br i1 %20, label %27, label %21

21:                                               ; preds = %4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %22, i32 0, i32 6
  %24 = load i32, ptr %23, align 1, !tbaa !13
  %25 = and i32 1, %24
  %26 = icmp ugt i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %21, %4
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  call void @libxsmm_generator_gemm_setup_stack_frame_fill_ext_gemm_stack_vars_rv64(ptr noundef %28, ptr noundef %29, ptr noundef %30, ptr noundef %31)
  br label %57

32:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %33, i32 0, i32 8
  %35 = getelementptr inbounds [3 x i8], ptr %34, i64 0, i64 0
  %36 = call i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef %35)
  %37 = icmp eq i32 12, %36
  br i1 %37, label %38, label %44

38:                                               ; preds = %32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %39, i32 0, i32 8
  %41 = getelementptr inbounds [3 x i8], ptr %40, i64 0, i64 0
  %42 = call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef %41)
  %43 = icmp eq i32 1, %42
  br label %44

44:                                               ; preds = %38, %32
  %45 = phi i1 [ false, %32 ], [ %43, %38 ]
  %46 = zext i1 %45 to i64
  %47 = select i1 %45, i32 1, i32 0
  store i32 %47, ptr %10, align 4, !tbaa !12
  %48 = load i32, ptr %10, align 4, !tbaa !12
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %56

50:                                               ; preds = %44
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !12
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.libxsmm_gp_reg_mapping_struct, ptr %53, i32 0, i32 20
  %55 = load i32, ptr %54, align 4, !tbaa !17
  call void @libxsmm_generator_gemm_setval_stack_var_rv64(ptr noundef %51, i32 noundef 5, i32 noundef %52, i32 noundef %55)
  br label %56

56:                                               ; preds = %50, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %57

57:                                               ; preds = %56, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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 = !{!10, !11, i64 92}
!10 = !{!"libxsmm_gp_reg_mapping_struct", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"libxsmm_gemm_descriptor", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !7, i64 28, !7, i64 29, !7, i64 32, !15, i64 33, !15, i64 41, !7, i64 49, !11, i64 50, !11, i64 54, !11, i64 58, !16, i64 62, !16, i64 64, !7, i64 66, !7, i64 67, !7, i64 68, !7, i64 69, !16, i64 70, !16, i64 72, !16, i64 74, !16, i64 76, !16, i64 78, !16, i64 80, !11, i64 82, !11, i64 86, !11, i64 90, !7, i64 94}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!10, !11, i64 80}


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

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

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_generator_gemm_setval_stack_var_rv64(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_generator_gemm_setup_stack_frame_fill_ext_gemm_stack_vars_rv64(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef) local_unnamed_addr #0

declare i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_gemm_setup_stack_frame_rv64(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %2, i64 92
  %6 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %0, i32 noundef 19, i32 noundef 2, i32 noundef 27, i32 noundef 0) #2
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %0, i32 noundef 19, i32 noundef 2, i32 noundef 2, i32 noundef -192) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = load i32, ptr %7, align 1, !tbaa !10
  %9 = and i32 %8, 32769
  %or.cond = icmp eq i32 %9, 0
  br i1 %or.cond, label %11, label %10

10:                                               ; preds = %4
  tail call void @libxsmm_generator_gemm_setup_stack_frame_fill_ext_gemm_stack_vars_rv64(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %3, ptr noundef nonnull %2)
  br label %.critedge

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %1, i64 29
  %13 = tail call i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef nonnull %12) #2
  %14 = icmp eq i32 %13, 12
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %11
  %16 = tail call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef nonnull %12) #2
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %2, i64 80
  %20 = load i32, ptr %19, align 4, !tbaa !14
  tail call void @libxsmm_generator_gemm_setval_stack_var_rv64(ptr noundef %0, i32 noundef 5, i32 noundef %6, i32 noundef %20)
  br label %.critedge

.critedge:                                        ; preds = %15, %18, %11, %10
  ret void
}

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 = !{!6, !7, i64 92}
!6 = !{!"libxsmm_gp_reg_mapping_struct", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 24}
!11 = !{!"libxsmm_gemm_descriptor", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !8, i64 28, !8, i64 29, !8, i64 32, !12, i64 33, !12, i64 41, !8, i64 49, !7, i64 50, !7, i64 54, !7, i64 58, !13, i64 62, !13, i64 64, !8, i64 66, !8, i64 67, !8, i64 68, !8, i64 69, !13, i64 70, !13, i64 72, !13, i64 74, !13, i64 76, !13, i64 78, !13, i64 80, !7, i64 82, !7, i64 86, !7, i64 90, !8, i64 94}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !7, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass