; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu (gat)

; 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.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.GATParamSpec = type { i32, %struct.ActivationParamSpec }
%struct.ActivationParamSpec = type { i32, [4 x float] }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@stdout = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [18 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind
declare i64 @syscall(i64 noundef, ...) #2

declare i32 @printf(ptr noundef, ...) #3

declare i32 @fflush(ptr noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local ptr @ee2str(i32 noundef) #4

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #5

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) #6

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z31gat_infer_forward_tmp_bytes_cpu10TensorDescS_12GATParamSpecPj(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef byval(%struct.TensorDesc) align 8 %1, ptr noundef byval(%struct.GATParamSpec) align 8 %2, ptr noundef %3) #7 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.TensorDesc, align 8
  store ptr %3, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %29

13:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  store i32 1, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %28

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  %17 = call i64 (i64, ...) @syscall(i64 noundef 186) #8
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !11
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %19)
  %21 = load ptr, ptr @stdout, align 8, !tbaa !5
  %22 = call i32 @fflush(ptr noundef %21)
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call ptr @ee2str(i32 noundef %23)
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %24)
  %26 = load ptr, ptr @stdout, align 8, !tbaa !5
  %27 = call i32 @fflush(ptr noundef %26)
  call void @exit(i32 noundef 1) #9
  unreachable

28:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %29

29:                                               ; preds = %28, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %30 = getelementptr inbounds %struct.GATParamSpec, ptr %2, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !13
  store i32 %31, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %32 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 3
  %33 = getelementptr inbounds [20 x i32], ptr %32, i64 0, i64 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  store i32 %34, ptr %9, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %1, i64 92, i1 false), !tbaa.struct !17
  %35 = call noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %10)
  %36 = mul i32 %35, 4
  %37 = getelementptr inbounds %struct.TensorDesc, ptr %1, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !23
  %39 = call noundef i32 @_Z7bytesOf8DataType(i32 noundef %38)
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = mul i32 %39, %40
  %42 = load i32, ptr %8, align 4, !tbaa !11
  %43 = mul i32 %41, %42
  %44 = add i32 %36, %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %44, ptr %45, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z7bytesOf8DataType(i32 noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { inlinehint mustprogress 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 #5 = { noreturn 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 #6 = { inlinehint mustprogress 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 #7 = { mustprogress 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 #8 = { nounwind }
attributes #9 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS2EE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS12GATParamSpec", !12, i64 0, !15, i64 4}
!15 = !{!"_ZTS19ActivationParamSpec", !16, i64 0, !7, i64 4}
!16 = !{!"_ZTS14ActivationMode", !7, i64 0}
!17 = !{i64 0, i64 4, !18, i64 4, i64 4, !20, i64 8, i64 4, !11, i64 12, i64 80, !22}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTS8DataType", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"_ZTS10DataFormat", !7, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!24, !19, i64 0}
!24 = !{!"_ZTS10TensorDesc", !19, i64 0, !21, i64 4, !12, i64 8, !7, i64 12}


; 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.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.GATParamSpec = type { i32, %struct.ActivationParamSpec }
%struct.ActivationParamSpec = type { i32, [4 x float] }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind
declare i64 @syscall(i64 noundef, ...) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local ptr @ee2str(i32 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z31gat_infer_forward_tmp_bytes_cpu10TensorDescS_12GATParamSpecPj(ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %0, ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %1, ptr nocapture noundef readonly byval(%struct.GATParamSpec) align 8 %2, ptr noundef writeonly %3) local_unnamed_addr #5 {
  %5 = icmp eq ptr %3, null
  br i1 %5, label %6, label %16

6:                                                ; preds = %4
  %7 = tail call i64 (i64, ...) @syscall(i64 noundef 186) #6
  %8 = trunc i64 %7 to i32
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %8)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = tail call i32 @fflush(ptr noundef %10)
  %12 = tail call ptr @ee2str(i32 noundef 1)
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %12)
  %14 = load ptr, ptr @stdout, align 8, !tbaa !5
  %15 = tail call i32 @fflush(ptr noundef %14)
  tail call void @exit(i32 noundef 1) #7
  unreachable

16:                                               ; preds = %4
  %17 = load i32, ptr %2, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = tail call noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef nonnull byval(%struct.TensorDesc) align 8 %1)
  %21 = shl i32 %20, 2
  %22 = load i32, ptr %1, align 8, !tbaa !15
  %23 = tail call noundef i32 @_Z7bytesOf8DataType(i32 noundef %22)
  %24 = mul i32 %19, %17
  %25 = mul i32 %24, %23
  %26 = add i32 %25, %21
  store i32 %26, ptr %3, align 4, !tbaa !14
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z7bytesOf8DataType(i32 noundef) local_unnamed_addr #4

attributes #0 = { 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 = { 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 #2 = { inlinehint mustprogress 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 = { noreturn 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 #4 = { inlinehint mustprogress 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 #5 = { mustprogress 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 #6 = { nounwind }
attributes #7 = { noreturn 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS12GATParamSpec", !11, i64 0, !12, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS19ActivationParamSpec", !13, i64 0, !7, i64 4}
!13 = !{!"_ZTS14ActivationMode", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"_ZTS10TensorDesc", !17, i64 0, !18, i64 4, !11, i64 8, !7, i64 12}
!17 = !{!"_ZTS8DataType", !7, i64 0}
!18 = !{!"_ZTS10DataFormat", !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass