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

; 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_meqn_elem = type { ptr, ptr, ptr, ptr, i32, %union.libxsmm_meqn_info, i32, i32, %struct.libxsmm_meqn_tmp_info, i32, i32, i32, %union.libxsmm_meqn_fusion_info }
%union.libxsmm_meqn_info = type { %struct.libxsmm_meqn_arg }
%struct.libxsmm_meqn_arg = type { i32, i32, i32, i32, i32, i32, i32, %struct.libxsmm_matrix_arg_attributes }
%struct.libxsmm_matrix_arg_attributes = type { i32, i32, i32, i32 }
%struct.libxsmm_meqn_tmp_info = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%union.libxsmm_meqn_fusion_info = type { %struct.libxsmm_meqn_xgemm_fusion_info }
%struct.libxsmm_meqn_xgemm_fusion_info = type { i32, i32, i32, i32, i32 }
%struct.libxsmm_meqn_param = type { ptr, ptr, %struct.libxsmm_matrix_arg }
%struct.libxsmm_matrix_arg = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.libxsmm_meqn_unary_op = type { i32, i32, i32, i32 }

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [76 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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_matequation_setup_inp_ptrs(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10) #2 {
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  store ptr %0, ptr %12, align 8, !tbaa !5
  store ptr %1, ptr %13, align 8, !tbaa !5
  store ptr %2, ptr %14, align 8, !tbaa !5
  store ptr %3, ptr %15, align 8, !tbaa !5
  store i64 %4, ptr %16, align 8, !tbaa !9
  store ptr %5, ptr %17, align 8, !tbaa !5
  store ptr %6, ptr %18, align 8, !tbaa !5
  store ptr %7, ptr %19, align 8, !tbaa !5
  store ptr %8, ptr %20, align 8, !tbaa !5
  store ptr %9, ptr %21, align 8, !tbaa !5
  store ptr %10, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp eq i32 %26, 8
  br i1 %27, label %28, label %60

28:                                               ; preds = %11
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %29, i32 0, i32 5
  %31 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = icmp sge i32 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.libxsmm_meqn_param, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %37, i64 %42
  %44 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %45, ptr %46, align 8, !tbaa !5
  br label %59

47:                                               ; preds = %28
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %49, i32 0, i32 5
  %51 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = sub nsw i32 -1, %52
  %54 = sext i32 %53 to i64
  %55 = load i64, ptr %16, align 8, !tbaa !9
  %56 = mul i64 %54, %55
  %57 = getelementptr inbounds i8, ptr %48, i64 %56
  %58 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %47, %34
  br label %93

60:                                               ; preds = %11
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %61, i32 0, i32 8
  %63 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !11
  %65 = icmp sge i32 %64, 0
  br i1 %65, label %66, label %77

66:                                               ; preds = %60
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %68, i32 0, i32 8
  %70 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !11
  %72 = sext i32 %71 to i64
  %73 = load i64, ptr %16, align 8, !tbaa !9
  %74 = mul i64 %72, %73
  %75 = getelementptr inbounds i8, ptr %67, i64 %74
  %76 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %75, ptr %76, align 8, !tbaa !5
  br label %92

77:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %78, i32 0, i32 8
  %80 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !11
  %82 = sub nsw i32 -1, %81
  store i32 %82, ptr %23, align 4, !tbaa !16
  %83 = load ptr, ptr %14, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.libxsmm_meqn_param, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !12
  %86 = load i32, ptr %23, align 4, !tbaa !16
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  %91 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %90, ptr %91, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  br label %92

92:                                               ; preds = %77, %66
  br label %93

93:                                               ; preds = %92, %59
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %94, i32 0, i32 4
  %96 = load i32, ptr %95, align 8, !tbaa !11
  %97 = icmp eq i32 %96, 1
  br i1 %97, label %98, label %139

98:                                               ; preds = %93
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %99, i32 0, i32 5
  %101 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 4, !tbaa !11
  %103 = icmp eq i32 %102, 51
  br i1 %103, label %111, label %104

104:                                              ; preds = %98
  %105 = load ptr, ptr %13, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %105, i32 0, i32 5
  %107 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %107, align 4, !tbaa !11
  %109 = call i32 @libxsmm_meqn_is_unary_opcode_reduce_cols_idx_kernel(i32 noundef %108)
  %110 = icmp sgt i32 %109, 0
  br i1 %110, label %111, label %139

111:                                              ; preds = %104, %98
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %112, i32 0, i32 4
  %114 = load i32, ptr %113, align 8, !tbaa !11
  %115 = icmp eq i32 %114, 8
  br i1 %115, label %116, label %135

116:                                              ; preds = %111
  %117 = load ptr, ptr %12, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %117, i32 0, i32 5
  %119 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %118, i32 0, i32 3
  %120 = load i32, ptr %119, align 4, !tbaa !11
  %121 = icmp sge i32 %120, 0
  br i1 %121, label %122, label %135

122:                                              ; preds = %116
  %123 = load ptr, ptr %14, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.libxsmm_meqn_param, ptr %123, i32 0, i32 1
  %125 = load ptr, ptr %124, align 8, !tbaa !12
  %126 = load ptr, ptr %12, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %126, i32 0, i32 5
  %128 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %127, i32 0, i32 3
  %129 = load i32, ptr %128, align 4, !tbaa !11
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %125, i64 %130
  %132 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %131, i32 0, i32 1
  %133 = load ptr, ptr %132, align 8, !tbaa !18
  %134 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %133, ptr %134, align 8, !tbaa !5
  br label %138

135:                                              ; preds = %116, %111
  %136 = load ptr, ptr @stderr, align 8, !tbaa !5
  %137 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %136, ptr noundef @.str.3) #4
  br label %138

138:                                              ; preds = %135, %122
  br label %139

139:                                              ; preds = %138, %104, %93
  ret void
}

declare i32 @libxsmm_meqn_is_unary_opcode_reduce_cols_idx_kernel(i32 noundef) #3

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

!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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"libxsmm_meqn_param", !6, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"libxsmm_matrix_arg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!14, !6, i64 8}


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

%struct.libxsmm_matrix_arg = type { ptr, ptr, ptr, ptr, ptr, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [76 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_generator_matequation_setup_inp_ptrs(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr noundef %3, i64 noundef %4, ptr nocapture noundef writeonly %5, ptr nocapture noundef writeonly %6, ptr nocapture noundef readnone %7, ptr nocapture noundef readnone %8, ptr nocapture noundef readnone %9, ptr nocapture noundef readnone %10) local_unnamed_addr #1 {
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i32 %13, 8
  br i1 %14, label %15, label %30

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, -1
  br i1 %18, label %19, label %25

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %2, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !8
  %22 = zext nneg i32 %17 to i64
  %23 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %21, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  br label %45

25:                                               ; preds = %15
  %26 = xor i32 %17, -1
  %27 = zext nneg i32 %26 to i64
  %28 = mul i64 %27, %4
  %29 = getelementptr inbounds i8, ptr %3, i64 %28
  br label %45

30:                                               ; preds = %11
  %31 = getelementptr inbounds i8, ptr %0, i64 88
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = icmp sgt i32 %32, -1
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = zext nneg i32 %32 to i64
  %36 = mul i64 %35, %4
  %37 = getelementptr inbounds i8, ptr %3, i64 %36
  br label %45

38:                                               ; preds = %30
  %39 = xor i32 %32, -1
  %40 = getelementptr inbounds i8, ptr %2, i64 8
  %41 = load ptr, ptr %40, align 8, !tbaa !8
  %42 = zext nneg i32 %39 to i64
  %43 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  br label %45

45:                                               ; preds = %34, %38, %19, %25
  %.sink = phi ptr [ %37, %34 ], [ %44, %38 ], [ %24, %19 ], [ %29, %25 ]
  store ptr %.sink, ptr %5, align 8, !tbaa !13
  %46 = getelementptr inbounds i8, ptr %1, i64 32
  %47 = load i32, ptr %46, align 8, !tbaa !5
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %49, label %72

49:                                               ; preds = %45
  %50 = getelementptr inbounds i8, ptr %1, i64 36
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp eq i32 %51, 51
  br i1 %52, label %56, label %53

53:                                               ; preds = %49
  %54 = tail call i32 @libxsmm_meqn_is_unary_opcode_reduce_cols_idx_kernel(i32 noundef %51) #3
  %55 = icmp sgt i32 %54, 0
  br i1 %55, label %56, label %72

56:                                               ; preds = %53, %49
  %57 = load i32, ptr %12, align 8, !tbaa !5
  %58 = icmp eq i32 %57, 8
  br i1 %58, label %59, label %69

59:                                               ; preds = %56
  %60 = getelementptr inbounds i8, ptr %0, i64 48
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = icmp sgt i32 %61, -1
  br i1 %62, label %63, label %69

63:                                               ; preds = %59
  %64 = getelementptr inbounds i8, ptr %2, i64 8
  %65 = load ptr, ptr %64, align 8, !tbaa !8
  %66 = zext nneg i32 %61 to i64
  %67 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %65, i64 %66, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  store ptr %68, ptr %6, align 8, !tbaa !13
  br label %72

69:                                               ; preds = %59, %56
  %70 = load ptr, ptr @stderr, align 8, !tbaa !13
  %71 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef nonnull @.str.3) #4
  br label %72

72:                                               ; preds = %63, %69, %53, %45
  ret void
}

declare i32 @libxsmm_meqn_is_unary_opcode_reduce_cols_idx_kernel(i32 noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 = { 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 = { "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 }
attributes #4 = { cold 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, !10, i64 8}
!9 = !{!"libxsmm_meqn_param", !10, i64 0, !10, i64 8, !11, i64 16}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"libxsmm_matrix_arg", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!11, !10, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!11, !10, i64 8}


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